/* =============================================================================
 * css/app.css — BuySignal design system (final, from DESIGNS mockups).
 * -----------------------------------------------------------------------------
 * Loaded by index.php, check.php and login.php. Page-specific styles stay in
 * each page's own <style> block; everything reusable lives here.
 *
 *   1. Tokens          colours, status hues, z-scale
 *   2. Base            type, scrollbar, entrance animation
 *   3. Header          brand + actions (.btn)
 *   4. Sections        "Price tracking" / "Stock watch" heads with count badge
 *   5. Cards           final card: spec rows + tinted status bar + product img
 *   6. Shared bits     icon-soft squares, keyword chip, Telegram icon, tags
 *   7. URL bar         U2: favicon + URL + copy/open icon-buttons
 *   8. Detail          title row, stat tiles, panels, history table
 *   9. Modal & form    new/edit check modal
 *  10. Dialog          destructive-action confirm
 *  11. Toasts          bottom-right stack (js/toast.js)
 *  12. Responsive
 *  13. Reduced motion
 * Light mode only. One accent (ink). Gradients only inside charts.
 * ============================================================================= */

/* ── 1. Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --ink: #171717;            /* neutral-900 — text & the ONE accent           */
  --muted: #737373;          /* neutral-500                                    */
  --faint: #a3a3a3;          /* neutral-400                                    */
  --border: #e5e5e5;         /* neutral-200                                    */
  --border-hover: #d4d4d4;   /* neutral-300                                    */
  --surface-hover: #fafafa;  /* neutral-50                                     */
  --hairline: #f5f5f5;       /* neutral-100 — internal dividers                */
  --danger: #dc2626;         /* red-600                                        */
  --danger-strong: #b91c1c;  /* red-700                                        */
  --danger-bg: #fef2f2;      /* red-50                                         */
  --ok: #16a34a;             /* green-600 — triggered/found only               */
  --ok-bg: #f0fdf4;          /* green-50                                       */
  --telegram: #26A5E4;       /* official Telegram blue                         */

  --z-modal: 70;
  --z-dialog: 80;
  --z-toast: 90;
}

/* ── 2. Base ───────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
}

a { color: inherit; }
.ti { font-size: 17px; line-height: 1; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Shared page footer (components/footer.php; login styles its own placement) */
.app-footer { text-align: center; padding: 2rem 1rem 2.5rem; color: var(--faint); font-size: .8125rem; }
.app-footer a { color: var(--muted); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.muted { color: var(--muted); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* Entrance ends at each element's natural opacity — a paused card (opacity
   .45) animates straight to .45 with no post-load jump. */
@keyframes enterUp {
  from { opacity: 0; transform: translateY(10px); filter: blur(4px); }
}
.anim { animation: enterUp .45s ease-out backwards; }

/* ── 3. Header ─────────────────────────────────────────────────────────────── */
.header {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand { display: flex; align-items: center; gap: .625rem; }
.brand-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
}
.brand h1 { font-size: 1.25rem; font-weight: 600; text-wrap: balance; }

.header-actions { display: flex; align-items: center; gap: .5rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: .5rem .875rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s ease-out, background .15s ease-out;
}
.btn:hover { border-color: var(--border-hover); background: var(--surface-hover); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: default; }

.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #000; border-color: #000; }

.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: #fecaca; background: var(--danger-bg); }

/* ── 4. Sections ───────────────────────────────────────────────────────────── */
.container { max-width: 72rem; margin: 0 auto; padding: 0 1.5rem 4rem; }

.sec-head {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
}
.sec-head + .grid { margin-bottom: 2.5rem; }
.sec-head h2 {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}
.sec-count {
  display: inline-grid;
  place-items: center;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--hairline);
  color: var(--muted);
  font-size: .6875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.sec-line { flex: 1; height: 1px; background: var(--hairline); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

/* Empty state — one clear next action */
.empty {
  border: 1.5px dashed var(--border);
  border-radius: 16px;
  padding: 4rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .875rem;
  text-align: center;
  grid-column: 1 / -1;
}
.empty .ti { font-size: 28px; color: var(--faint); }
.empty p { color: var(--muted); text-wrap: pretty; }

/* ── 5. Cards (final: spec rows + status bar) ──────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s ease-out, box-shadow .15s ease-out, opacity .15s ease-out;
}
.card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}
.card.pau { opacity: .45; }
.card.pau:hover { opacity: 1; }

.card-body { padding: 1.25rem 1.375rem 1rem; flex: 1; }

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 1.125rem;
}
.card-site {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--faint);
  font-size: .75rem;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fav { width: 16px; height: 16px; border-radius: 4px; flex: none; }

.card-idrow { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.prod {
  width: 72px; height: 72px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: none;
}
.prod img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.card-idtext { min-width: 0; }
.card-name {
  font-weight: 600;
  font-size: 1.0625rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-url {
  color: var(--faint);
  font-size: .75rem;
  margin-top: .15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kv {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 1rem;
  padding: .55rem 0;
  border-top: 1px solid var(--hairline);
  font-size: .875rem;
  align-items: baseline;
}
.kv dt { color: var(--faint); font-size: .75rem; }
.kv dd { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kx { color: var(--faint); font-size: .75rem; margin-left: .4rem; }

/* Tinted status bar — the ONE place the state lives on a card */
.statusbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .7rem 1.375rem;
  border-top: 1px solid var(--hairline);
  background: var(--surface-hover);
  font-size: .8125rem;
  color: var(--ink);
}
.statusbar b { font-weight: 600; }
.statusbar .ti { font-size: 15px; }
.statusbar span { margin-left: auto; color: var(--faint); font-size: .6875rem; }
.statusbar.ok { background: var(--ok-bg); color: var(--ok); border-color: rgb(22 163 74 / .1); }
.statusbar.ok span { color: rgb(22 163 74 / .65); }
.statusbar.err { background: var(--danger-bg); color: var(--danger); border-color: rgb(220 38 38 / .1); }
.statusbar.err span { color: rgb(220 38 38 / .6); }

/* ── 6. Shared bits ────────────────────────────────────────────────────────── */
/* The tag never repeats the state — always gray, always with an icon */
.tag {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .6875rem;
  font-weight: 600;
  color: var(--faint);
  flex: none;
}
.tag .ti { font-size: 12px; }

.icon-soft {
  width: 26px; height: 26px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  flex: none;
}
.icon-soft .ti { font-size: 13px; }
.icon-soft.ok   { background: var(--ok-bg); border: 1px solid rgb(22 163 74 / .35); color: var(--ok); }
.icon-soft.wait { background: var(--surface-hover); border: 1px solid var(--border); color: var(--muted); }
.icon-soft.err  { background: var(--danger-bg); border: 1px solid rgb(220 38 38 / .18); color: var(--danger); }

/* Watched keyword rendered as a chip, never in quotes */
.kw {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  border-radius: 6px;
  padding: .1rem .45rem;
  font-size: .8125rem;
  font-weight: 500;
}

/* Official Telegram plane (Simple Icons) on the brand-blue rounded square */
.tg {
  display: inline-grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 5px;
  background: var(--telegram);
  color: #fff;
  flex: none;
}
.tg svg { width: 13px; height: 13px; }

.arrow-soft { opacity: .5; }

/* ── 7. URL bar (U2) ───────────────────────────────────────────────────────── */
.urlbar {
  display: flex;
  align-items: center;
  gap: .625rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .5rem .625rem .5rem 1rem;
  margin-bottom: 1.25rem;
}
.urlbar .urltxt {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: .8125rem;
}
.urlbar .acts { margin-left: auto; display: flex; align-items: center; gap: .25rem; flex: none; }
.urlbar .ib {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  border: 0;
  background: none;
  transition: color .15s ease-out, background .15s ease-out;
}
.urlbar .ib:hover { background: var(--surface-hover); color: var(--ink); }
.urlbar .ib:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.urlbar .sep { width: 1px; height: 18px; background: var(--hairline); margin: 0 .25rem; }

/* ── 8. Detail (Console) ───────────────────────────────────────────────────── */
.title-row { display: flex; align-items: center; gap: .875rem; margin-bottom: 1rem; }
.t-prod { width: 52px; height: 52px; border-radius: 12px; }
.t-prod img { padding: 4px; }
.title-row h2 {
  font-size: 1.375rem;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title-actions { margin-left: auto; display: flex; gap: .5rem; flex: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat { border: 1px solid var(--border); border-radius: 16px; padding: 1.125rem 1.25rem; min-width: 0; }
.stat dt {
  color: var(--faint);
  font-size: .75rem;
  margin-bottom: .35rem;
  display: flex;
  align-items: center;
  gap: .35rem;
}
.stat dt .ti { font-size: 13px; }
.stat dd { font-size: 1.25rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat dd small { font-size: .75rem; font-weight: 400; color: var(--faint); margin-left: .3rem; }
.stat dd .kw {
  font-size: .9375rem;
  vertical-align: 2px;
  display: inline-block;
  max-width: calc(100% - 5.25rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selector-line {
  color: var(--faint);
  font-size: .75rem;
  margin: -0.5rem 0 1.25rem .25rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}

.panel { border: 1px solid var(--border); border-radius: 18px; overflow: hidden; margin-bottom: 1.25rem; }
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 1.25rem 1.375rem 0;
}
.panel h3 { font-size: .9375rem; font-weight: 600; }
.chart-range { color: var(--faint); font-size: .8125rem; }
.detail-chart { width: 100%; height: 210px; display: block; margin-top: .75rem; color: var(--ink); }

/* History: gray band header (same treatment as the cards' status bar) */
.hist-band {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: .8rem 1.375rem;
  background: var(--surface-hover);
  border-bottom: 1px solid var(--hairline);
}
.hist-band h3 { font-size: .9375rem; font-weight: 600; }
.hist-band span { color: var(--faint); font-size: .75rem; }

.table-scroll { overflow-x: auto; }
.htable { width: 100%; border-collapse: collapse; font-size: .875rem; margin-bottom: .75rem; }
.htable td { padding: .65rem .75rem; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
.htable tr:last-child td { border-bottom: 0; }
.htable td:first-child { padding-left: 1.375rem; }
.htable td:last-child { padding-right: 1.375rem; text-align: right; color: var(--faint); }
.htable td.det { white-space: normal; color: var(--muted); font-size: .8125rem; max-width: 24rem; }
.res { display: inline-flex; align-items: center; gap: .5rem; }
.res .icon-soft { width: 24px; height: 24px; border-radius: 7px; }
.res .icon-soft .ti { font-size: 12px; }
.fetch-tag {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .6875rem;
  font-weight: 500;
  color: var(--faint);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: .05rem .3rem;
  cursor: help;
}
.fetch-tag .ti { font-size: 11px; }

/* Hard-blocked site: centered error state that replaces the stat tiles.
   Solid border (not dashed), neutral (gray) glyph, sparkles CTA → prompt modal. */
.blocked-state {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 3rem 2rem;
  margin-bottom: 1.25rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
}
.blocked-state .bs-ico {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--muted);
  margin-bottom: .25rem;
}
.blocked-state .bs-ico .ti { font-size: 24px; }
.blocked-state h3 { font-size: 1.125rem; font-weight: 600; }
.blocked-state p { color: var(--muted); font-size: .875rem; max-width: 34rem; text-wrap: pretty; }
.blocked-state .bs-actions { display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; justify-content: center; }

/* Computer-use prompt modal: read-only textarea + copy */
.prompt-help { color: var(--muted); font-size: .8125rem; margin-bottom: 1rem; text-wrap: pretty; }
.prompt-area {
  width: 100%;
  min-height: 16rem;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .8125rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.125rem;
}
.prompt-area:focus { outline: none; border-color: var(--ink); }
.det-line { display: inline-flex; align-items: center; gap: .5rem; }

/* ── 9. Modal & form ───────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  z-index: var(--z-modal);
  display: grid; place-items: center;
  padding: 1.5rem;
  background: rgb(255 255 255 / 0.7);
  backdrop-filter: blur(0px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease-out, backdrop-filter .28s ease-out;
}
.overlay.open {
  opacity: 1;
  pointer-events: auto;
  backdrop-filter: blur(14px);
}

.modal {
  width: 100%;
  max-width: 34rem;
  max-height: calc(100dvh - 3rem);
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  padding: 1.75rem;
  transform: translateY(8px) scale(.96);
  opacity: 0;
  transition: transform .28s ease-out, opacity .28s ease-out;
}
.overlay.open .modal { transform: none; opacity: 1; }

.modal h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 1.25rem; text-wrap: balance; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-full { grid-column: 1 / -1; }

.field label {
  display: block;
  font-size: .8125rem;
  font-weight: 500;
  margin-bottom: .375rem;
}
.field input, .field select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .55rem .75rem;
  background: #fff;
  transition: border-color .18s ease-out;
}
.field input:hover, .field select:hover { border-color: var(--border-hover); }
.field input:focus, .field select:focus { outline: none; border-color: var(--ink); }
.field .hint { color: var(--faint); font-size: .75rem; margin-top: .3rem; }
.field-error {
  color: var(--danger);
  font-size: .8125rem;
  display: none;
  align-items: center;
  gap: .35rem;
}
.field-error.show { display: flex; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 8px;
  padding: .4rem 0;
  cursor: pointer;
  transition: background .15s ease-out, color .15s ease-out;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1.5rem;
}

/* ── 10. Dialog (destructive confirm) ──────────────────────────────────────── */
.dialog-overlay {
  position: fixed; inset: 0;
  z-index: var(--z-dialog);
  display: grid; place-items: center;
  padding: 1.5rem;
  background: rgb(255 255 255 / 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease-out;
}
.dialog-overlay.open { opacity: 1; pointer-events: auto; }
.dialog {
  width: 100%;
  max-width: 24rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  padding: 1.5rem;
  transform: translateY(6px) scale(.97);
  opacity: 0;
  transition: transform .2s ease-out, opacity .2s ease-out;
}
.dialog-overlay.open .dialog { transform: none; opacity: 1; }
.dialog h3 { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; }
.dialog p { color: var(--muted); font-size: .875rem; text-wrap: pretty; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.btn-destroy { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-destroy:hover { background: var(--danger-strong); border-color: var(--danger-strong); }

/* ── 11. Toasts ────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: 22rem;
}
.toast {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  padding: .875rem 1rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .2s ease-out, transform .2s ease-out;
  cursor: pointer;
}
.toast.show { opacity: 1; transform: none; }
.toast-title {
  font-weight: 600;
  font-size: .875rem;
  display: flex;
  align-items: center;
  gap: .45rem;
}
.toast-msg { color: var(--muted); font-size: .8125rem; margin-top: .25rem; text-wrap: pretty; }

/* ── 12. Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 767px) {
  .header { padding: 1.75rem 1rem 1.25rem; }
  .container { padding: 0 1rem 3rem; }
  .grid { grid-template-columns: 1fr; gap: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .title-row { flex-wrap: wrap; }
  .title-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
}

/* ── 13. Reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
