/* JL Price Tracker — Linear/Vercel-inspired, lightweight. */

@font-face {
  font-family: 'Inter var';
  src: url('/fonts/inter-var.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #a1a1aa;
  --good: #067a3d;
  --good-soft: rgba(6, 122, 61, 0.1);
  --bad: #b42318;
  --bad-soft: rgba(180, 35, 24, 0.08);
  /* Flat-leaning design: the only elevation shadow left is for elements that
     genuinely float over other content (dropdown menus, the drag ghost).
     Everything else separates with borders, scrims and backdrop blur. */
  --shadow-float: 0 4px 24px rgba(0,0,0,.08);
  --radius: 10px;
  --ease: cubic-bezier(.25,.75,.5,1);
  /* Type scale — every font-size in the app comes from this ramp:
       xs   11px  status pills, kbd hints
       sm   12px  field labels, captions, small meta
       md   13px  buttons, secondary text, dropdown options
       base 14px  body copy, inputs, card titles
       lg   16px  modal & section headings
       xl   18px  page/product titles
       2xl  22px  prices
     Weights: 400 body · 500 labels/buttons · 600 headings/prices/emphasis. */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-md: 13px;
  --fs-base: 14px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 22px;
  --accent: #0070f3;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, transparent);
  /* Card image scrim + overlaid text: fades to the surface tone of whichever
     theme is active, so cards read as part of the page in light AND dark. */
  --card-scrim-strong: color-mix(in srgb, var(--surface) 97%, transparent);
  --card-scrim-mid: color-mix(in srgb, var(--surface) 75%, transparent);
  --card-scrim-weak: color-mix(in srgb, var(--surface) 18%, transparent);
  --card-text: var(--text);
  --card-text-2: var(--text-2);
  --card-text-shadow: 0 1px 3px rgba(255,255,255,.6);
  color-scheme: light;
}

/* Dark theme. The <html data-theme> attribute is set by an inline script in
   <head> (before first paint) from the saved preference — System / Light /
   Dark, chosen in Settings — so there's no media query here; "System" is
   resolved to light/dark in JS, which also tracks live OS changes. */
:root[data-theme="dark"] {
  --bg: #0e0e11;
  --surface: #17171b;
  --surface-2: #222227;
  --border: #2a2a30;
  --border-strong: #3b3b43;
  --text: #f4f4f5;
  --text-2: #a1a1aa;
  --text-3: #6b6b74;
  --good: #40bf78;
  --good-soft: rgba(64, 191, 120, 0.14);
  --bad: #f0655a;
  --bad-soft: rgba(240, 101, 90, 0.12);
  --accent: #3b82f6;
  --shadow-float: 0 4px 24px rgba(0,0,0,.5);
  --card-text-shadow: 0 1px 3px rgba(0,0,0,.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter var', -apple-system, 'Segoe UI', sans-serif;
  font-size: var(--fs-base);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv11', 'ss01';
}
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.error { color: var(--bad); font-size: var(--fs-md); margin: 8px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 500; font-size: var(--fs-md);
  padding: 7px 14px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s var(--ease), border-color .15s var(--ease),
              color .15s var(--ease), transform .15s var(--ease), opacity .15s var(--ease);
  user-select: none;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover:not([disabled]) { background: color-mix(in srgb, var(--text) 85%, var(--bg)); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not([disabled]) { border-color: var(--text-3); }
.btn-secondary:active { background: var(--surface-2); }
/* Ghost = quieter than secondary, but still visibly a button: hairline
   border rather than the stronger secondary one. Never borderless text. */
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-icon { padding: 6px 9px; background: transparent; color: var(--text-3); border-radius: 7px; }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; justify-content: center; padding: 9px; }
.btn-danger { color: var(--bad); }
.btn-secondary.btn-danger { border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.btn-secondary.btn-danger:hover:not([disabled]) { border-color: var(--bad); background: var(--bad-soft); }
.btn .spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Lock screen ---------- */
.lock {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.lock-card {
  width: 340px; max-width: 100%; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 36px 28px;
  animation: rise .25s var(--ease);
}
.lock-logo { font-size: 30px; margin-bottom: 6px; }
.lock-card h1 { font-size: var(--fs-xl); font-weight: 600; margin: 0 0 2px; letter-spacing: -0.01em; }
.lock-card p { margin: 0 0 20px; font-size: var(--fs-md); }
.lock-card input {
  width: 100%; margin-bottom: 10px; text-align: center;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background .2s var(--ease), border-color .2s var(--ease);
}
.topbar.scrolled {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom-color: color-mix(in srgb, var(--border) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: var(--fs-base); letter-spacing: -0.01em; white-space: nowrap; }
.brand-mark { font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.topbar-search { position: relative; display: flex; align-items: center; flex: 0 1 300px; min-width: 120px; margin-left: 6px; }
.topbar-search .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.topbar-search #searchInput {
  width: 100%; font: inherit; font-size: var(--fs-md); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 30px 6px 34px; outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.topbar-search input:hover { border-color: var(--border-strong); }
.topbar-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-kbd {
  position: absolute; right: 8px; pointer-events: none;
  font-family: inherit; font-size: var(--fs-xs); font-weight: 500; color: var(--text-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; line-height: 1.4;
}
.topbar-search input:focus ~ .search-kbd { opacity: 0; }
.search-clear {
  position: absolute; right: 6px; border: 0; background: transparent; color: var(--text-3);
  display: inline-flex; align-items: center; cursor: pointer; padding: 4px 6px; border-radius: 5px;
}
.search-clear:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Layout ---------- */
.main { max-width: 1600px; margin: 0 auto; padding: 24px 20px 60px; }
.board { display: flex; flex-direction: column; gap: 8px; }
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* ---------- Cards ---------- */
/* The product photo is the card's full background — every edge touches the
   image, with title/price/status overlaid on top via the scrim + blur. */
.card {
  /* Narrower column (280px min) at roughly the same rendered height as the
     old 310px/16:11 card — hence the squarer 4:3 ratio. */
  position: relative; aspect-ratio: 4 / 3; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  transition: border-color .15s var(--ease), opacity .18s var(--ease);
  animation: rise .3s var(--ease) backwards;
  cursor: default;
  -webkit-touch-callout: none;
}
.card:hover { border-color: var(--border-strong); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.leaving { animation: card-out .18s var(--ease) forwards; }
@keyframes card-out { to { opacity: 0; transform: scale(.96); } }

.card-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  /* Y above 50% crops more off the top than the bottom, which shifts
     centered content up within the frame — so the title/price scrim
     overlaid on the bottom of the card covers less of the product photo. */
  object-fit: cover; object-position: 50% 58%; display: block;
  transition: transform .4s var(--ease), opacity .3s var(--ease);
}
/* Held invisible until the bitmap has actually loaded (see fadeInWhenLoaded)
   so images fade in rather than popping when the network delivers. */
.card-img.img-pending { opacity: 0; }
.card-img-empty { background: linear-gradient(135deg, var(--surface-2), var(--border)); }
.card:hover .card-img { transform: scale(1.045); }
/* Desktop (hover-capable, multi-column grid): rest the photos at half
   strength so the grid reads calmer — the card's --surface-2 backing shows
   through, which tones the image toward the page in both themes. Hovering a
   card fades its photo back to full. Kept off touch/mobile, where there's no
   hover to recover the image. The .img-pending rule is restated after the
   hover rule so a still-loading image stays fully hidden even under hover. */
@media (hover: hover) and (min-width: 561px) {
  .card-img { opacity: .5; }
  .card:hover .card-img, .card:focus-visible .card-img { opacity: 1; }
  .card-img.img-pending { opacity: 0; }
}
/* Progressive blur behind the overlaid title/price, on top of the color scrim. */
.card-banner-blur {
  position: absolute; left: 0; right: 0; bottom: 0; height: 44%;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  mask-image: linear-gradient(to bottom, transparent, black 75%);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 75%);
  pointer-events: none;
}
.card-banner-scrim {
  position: absolute; inset: 0;
  background: linear-gradient(to top,
    var(--card-scrim-strong) 0%, var(--card-scrim-strong) 18%,
    var(--card-scrim-mid) 40%, transparent 72%);
  pointer-events: none;
}

.card-banner-text {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 14px 11px;
  display: flex; flex-direction: column; gap: 4px;
}
.card-title {
  font-weight: 600; font-size: var(--fs-base); letter-spacing: -0.005em; line-height: 1.3;
  color: var(--card-text); text-shadow: var(--card-text-shadow);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.price-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.price-now { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--card-text); text-shadow: var(--card-text-shadow); }
.price-was { font-size: var(--fs-md); color: var(--card-text-2); text-decoration: line-through; font-variant-numeric: tabular-nums; }
.price-unavailable { font-size: var(--fs-base); color: var(--card-text-2); font-weight: 500; }
.card-pills {
  position: absolute; top: 10px; left: 10px;
  display: flex; align-items: center; gap: 6px;
}
/* Frosted surface pills (same glass treatment as the neutral status pill and
   the edit modal's floating close button) with the semantic color carried by
   the text — sits on the photo without the heavy solid-fill look. */
.pct-pill, .low-pill {
  font-size: var(--fs-xs); font-weight: 600; padding: 2.5px 9px; border-radius: 20px;
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.pct-pill { color: var(--good); }
.low-pill { color: var(--accent); }

/* Stock · last-checked pills, on one line, wrapping hidden if too long. */
.card-status-line {
  display: flex; align-items: center; gap: 5px; margin-top: 2px;
  overflow: hidden;
}

/* ---------- Status pills (stock / checked-ago) — shared by cards + the
   product detail modal. ---------- */
.status-pill {
  display: inline-flex; align-items: center; flex: none;
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .01em;
  padding: 2.5px 8px; border-radius: 20px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.status-pill.good { background: var(--good-soft); color: var(--good); }
.status-pill.bad { background: var(--bad-soft); color: var(--bad); }
.status-pill.neutral { background: var(--surface-2); color: var(--text-2); }
.card-status-line .status-pill.neutral { background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--card-text-2); }
/* Soften pure-white photo backgrounds against the dark grid. */
[data-theme="dark"] .card-img { filter: brightness(.88); }

/* ---------- Drag & drop ---------- */
body.dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }
body.dragging * { cursor: grabbing !important; }
.drag-ghost {
  position: fixed; z-index: 100; pointer-events: none;
  box-shadow: var(--shadow-float); opacity: .95;
  transform: scale(1.02) rotate(.6deg);
  transition: none; animation: none;
}
.drag-source { opacity: .35; }
.drag-source, .drag-source * { pointer-events: none; }
.flip-move { transition: transform .18s var(--ease); }

/* ---------- Empty, skeleton & no-results ---------- */
.empty { text-align: center; padding: 72px 20px; animation: rise .3s var(--ease); }
.empty-art { margin-bottom: 14px; }
.empty h2 { font-size: var(--fs-lg); font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.empty p { margin: 0 0 20px; }

.sk { position: relative; overflow: hidden; border-radius: 6px; background: var(--surface-2); }
.sk::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 40%, color-mix(in srgb, var(--text) 5%, transparent) 50%, transparent 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-banner { position: absolute; inset: 0; border-radius: 0; }

.no-results { text-align: center; padding: 64px 20px; color: var(--text-2); animation: rise .25s var(--ease); }
.no-results .search-icon-big { color: var(--text-3); margin-bottom: 10px; }
.no-results h2 { font-size: var(--fs-lg); font-weight: 600; margin: 0 0 4px; color: var(--text); }
.no-results p { margin: 0 0 16px; font-size: var(--fs-md); }

/* ---------- Modals ---------- */
.modal {
  /* Explicit fixed positioning, pinned to the viewport regardless of page
     scroll — mobile Safari's <dialog> UA stylesheet handles this by
     default, but that default only applies if nothing here overrides
     `position`, so it's spelled out rather than left implicit. */
  position: fixed;
  inset: 0;
  margin: auto;
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  width: 480px; max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  /* The modal's own box no longer scrolls — its single content child does
     (see .modal-body / .edit-layout) — so its rounded corners always clip
     cleanly and dropdown menus (which position via `fixed`, not relative to
     any scrolling ancestor) are never cut off. */
  overflow: hidden;
}
/* The dialog itself is focused on open (see showModal() call sites) so that
   no descendant button appears pre-selected — it doesn't need its own
   visible ring for that. */
.modal:focus { outline: none; }
.modal::backdrop { background: rgba(0,0,0,.35); backdrop-filter: blur(2px); }
[data-theme="dark"] .modal::backdrop { background: rgba(0,0,0,.55); }
/* While any modal is open, freeze the page behind it — otherwise iOS Safari
   rubber-bands the body instead of scrolling the modal's own content. */
body:has(dialog[open]) { overflow: hidden; }
.modal[open] { display: flex; flex-direction: column; animation: modal-in .2s var(--ease); }
.modal[open]::backdrop { animation: fade-in .2s var(--ease); }
.modal.closing { animation: modal-out .16s var(--ease) forwards; }
.modal.closing::backdrop { animation: fade-out .16s var(--ease) forwards; }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(4px) scale(.98); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* Staggered fade-in for a modal's content. Scoped to the [open] attribute so
   it replays automatically every time the dialog reopens — the same
   mechanism modal-in already relies on, no JS needed. Two passes: top-level
   rows (.field, .edit-summary, a settings column…) stagger against each
   other, then a handful of known inner rows (toggle pairs, the schedule +
   check-now row, the bottom action row…) restagger their own 2-3 children
   on top of that — so text/buttons/dropdowns cascade individually instead
   of each field just popping in as one block. */
.modal[open] .modal-body > *,
.modal-edit[open] .edit-content > *,
.modal[open] .settings-col > * {
  animation: content-in .22s var(--ease) backwards;
}
@keyframes content-in { from { opacity: 0; transform: translateY(3px); } }
.modal[open] .modal-body > *:nth-child(1), .modal-edit[open] .edit-content > *:nth-child(1), .modal[open] .settings-col > *:nth-child(1) { animation-delay: 0ms; }
.modal[open] .modal-body > *:nth-child(2), .modal-edit[open] .edit-content > *:nth-child(2), .modal[open] .settings-col > *:nth-child(2) { animation-delay: 30ms; }
.modal[open] .modal-body > *:nth-child(3), .modal-edit[open] .edit-content > *:nth-child(3), .modal[open] .settings-col > *:nth-child(3) { animation-delay: 60ms; }
.modal[open] .modal-body > *:nth-child(4), .modal-edit[open] .edit-content > *:nth-child(4), .modal[open] .settings-col > *:nth-child(4) { animation-delay: 90ms; }
.modal[open] .modal-body > *:nth-child(5), .modal-edit[open] .edit-content > *:nth-child(5), .modal[open] .settings-col > *:nth-child(5) { animation-delay: 120ms; }
.modal[open] .modal-body > *:nth-child(n+6), .modal-edit[open] .edit-content > *:nth-child(n+6), .modal[open] .settings-col > *:nth-child(n+6) { animation-delay: 150ms; }

.modal-edit[open] .edit-summary > *,
.modal[open] .edit-meta-row > *,
.modal-edit[open] .toggle-row > *,
.modal-edit[open] .schedule-row > *,
.modal-edit[open] .edit-actions > *,
.modal[open] .settings-section > * {
  animation: content-in .2s var(--ease) backwards;
}
.modal-edit[open] .edit-summary > *:nth-child(1), .modal[open] .edit-meta-row > *:nth-child(1),
.modal-edit[open] .toggle-row > *:nth-child(1), .modal-edit[open] .schedule-row > *:nth-child(1),
.modal-edit[open] .edit-actions > *:nth-child(1),
.modal[open] .settings-section > *:nth-child(1) { animation-delay: 0ms; }
.modal-edit[open] .edit-summary > *:nth-child(2), .modal[open] .edit-meta-row > *:nth-child(2),
.modal-edit[open] .toggle-row > *:nth-child(2), .modal-edit[open] .schedule-row > *:nth-child(2),
.modal-edit[open] .edit-actions > *:nth-child(2),
.modal[open] .settings-section > *:nth-child(2) { animation-delay: 45ms; }
.modal-edit[open] .edit-summary > *:nth-child(n+3), .modal[open] .edit-meta-row > *:nth-child(n+3),
.modal-edit[open] .edit-actions > *:nth-child(n+3),
.modal[open] .settings-section > *:nth-child(n+3) { animation-delay: 90ms; }

/* Fields revealed after a successful validate cascade in. More specific than
   the modal-open stagger above (which owns the same elements' `animation`),
   and a distinct keyframe name so adding the class always restarts it;
   per-element delay is set inline by revealStagger(). */
.modal-edit[open] .edit-content > .field-in, .field-in {
  animation: field-in .24s var(--ease) backwards;
}
@keyframes field-in { from { opacity: 0; transform: translateY(4px); } }
.modal-body {
  padding: 22px; display: flex; flex-direction: column; gap: 16px;
  /* flex-basis must be auto (not the `flex: 1` shorthand's 0%) — the modal
     itself has no explicit height (only max-height, sized via fit-content),
     so a 0%-basis child contributes nothing to that intrinsic-size
     calculation and the whole modal collapses to zero height. */
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: var(--fs-xl); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.modal-foot { display: flex; gap: 10px; justify-content: space-between; }
/* Desktop: keep the footer actions in view while the body scrolls. (On
   mobile the primary action is already pinned via position:fixed below.) */
@media (min-width: 641px) {
  .modal-foot {
    position: sticky; bottom: -22px; z-index: 5;
    margin: 0 -22px -22px; padding: 14px 22px 22px;
    background: var(--surface); border-top: 1px solid var(--border);
  }
}
.modal-foot .grow { flex: 1; justify-content: center; }

/* Close (✕) button — sits inline in .modal-head for boxed modals, or floats
   over the top-right corner for modals with no header row (e.g. modal-edit). */
.modal-close {
  display: flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0;
  background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), transform .15s var(--ease);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-close:active { transform: scale(.92); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-edit .modal-close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 30px; height: 30px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  color: var(--text);
}
.modal-edit .modal-close:hover { background: var(--surface); transform: scale(1.06); }

.modal-wide { width: 720px; max-width: calc(100vw - 32px); }

/* Close (✕) / back (‹) — both icons always in the DOM; only one shown per
   breakpoint (see the mobile media query below) so no JS is needed to swap. */
.modal-close .icon-back { display: none; }

/* Edit modal: the image is a full-bleed column touching the top/left/bottom
   edges of the dialog; only the content column is padded. The dialog itself
   stays overflow:visible so dropdown menus can open past its bounds without
   triggering a scrollbar (which would shift the modal's rendered size) —
   corner rounding is clipped locally on the image instead. */
.modal-edit { padding: 0; }
.edit-layout {
  display: grid; grid-template-columns: 260px 1fr; align-items: stretch;
  /* flex-basis: auto, not the `flex: 1` shorthand's 0% — see .modal-body. */
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
/* Add-product modal: the image column is a zero-width track until a product's
   been validated — same track count as the full layout, so removing the class
   animates the column open instead of snapping a new one into the grid. */
.edit-layout { transition: grid-template-columns .3s var(--ease); }
.edit-layout.single-col { grid-template-columns: 0px 1fr; }
.edit-media {
  position: relative; background: var(--surface-2); min-height: 100%;
  border-radius: 14px 0 0 14px; overflow: hidden;
}
.edit-media img {
  display: block; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 35%;
  opacity: 1;
  will-change: opacity; /* keep on its own compositor layer so the fade-in
    doesn't cause a subpixel snap when the animation hands off to the
    static layer at the end */
}
/* Staggered entrance: fades in once the modal's own scale/translate
   animation (.2s) has settled, added via JS so it replays on every open. */
.edit-media img.img-fade-in { animation: edit-img-in .45s var(--ease) .2s backwards; }
@keyframes edit-img-in { from { opacity: 0; } to { opacity: 1; } }
.edit-content { padding: 22px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.edit-summary { display: flex; flex-direction: column; gap: 3px; }
.edit-title {
  font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.01em; margin: 0; line-height: 1.3;
  /* Long titles wrap up to 2 lines and clip rather than run under the
     floating close button in the corner. */
  padding-right: 32px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.edit-price { font-size: var(--fs-2xl); font-weight: 400; letter-spacing: -0.01em; color: var(--text); margin: 3px 0 0; font-variant-numeric: tabular-nums; }
.edit-meta-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.check-meta-inline { font-size: var(--fs-sm); color: var(--text-3); font-variant-numeric: tabular-nums; }

/* Price-history chart (edit modal) — inline SVG step-line, no library. */
.history-chart {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px 8px; background: var(--surface);
}
.hist-plot { position: relative; }
.hist-plot svg { display: block; width: 100%; height: 56px; }
/* Markers sit as positioned HTML dots (not SVG circles) because the viewBox
   scales non-uniformly to fill the box, which would squash circle geometry. */
.hist-dot {
  position: absolute; width: 7px; height: 7px; box-sizing: border-box;
  border-radius: 50%; background: var(--accent); border: 1.5px solid var(--surface);
  transform: translate(-50%, -50%);
}
.hist-line {
  fill: none; stroke: var(--accent); stroke-width: 1.5;
  stroke-linejoin: round; stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.hist-area { fill: color-mix(in srgb, var(--accent) 9%, transparent); stroke: none; }
.history-meta {
  display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 7px;
  font-size: var(--fs-sm); color: var(--text-2); font-variant-numeric: tabular-nums;
}
/* Mobile product sheet: the photo is a hero pinned to the top of the scroll
   container, and the content panel — rounded top corners, grabber pill —
   scrolls OVER it, app-style. The hero fades/parallaxes away as the panel
   covers it (scroll-driven animation, with a JS fallback for iOS < 26). */
@media (max-width: 640px) {
  .edit-layout {
    grid-template-columns: 1fr;
    /* Matches the hero's backing so top rubber-banding never exposes a
       mismatched surface behind the sticky image. */
    background: var(--surface-2);
  }
  .edit-media {
    position: sticky; top: 0; z-index: 0;
    height: 44dvh; min-height: 0;
    border-radius: 0;
  }
  .edit-media img { height: 100%; }
  .edit-content {
    position: relative; z-index: 1;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    margin-top: -18px;
    padding-top: 24px;
  }
  /* Sheet grabber pill. */
  .edit-content::before {
    content: ''; position: absolute; top: 8px; left: 50%;
    width: 36px; height: 4px; border-radius: 2px;
    transform: translateX(-50%);
    background: var(--border-strong);
  }
  /* Add modal before validation: no hero yet — flat full-height sheet with
     clearance for the floating back button instead of the panel treatment. */
  .single-col .edit-media { position: static; height: 0; }
  .edit-layout.single-col { background: var(--surface); }
  .edit-layout.single-col .edit-content {
    margin-top: 0; border-radius: 0; padding-top: 56px;
  }
  .edit-layout.single-col .edit-content::before { display: none; }

  /* Hero scrub — modern path: scrolling the layout drives the image's fade +
     parallax directly (Safari 26+/iOS 26+). Second animation slot keeps the
     open fade-in intact. */
  @supports (animation-timeline: scroll()) {
    .modal-edit .edit-media img.img-fade-in {
      animation: edit-img-in .45s var(--ease) .2s backwards, hero-scrub linear both;
      animation-timeline: auto, scroll(nearest);
      animation-range: normal, 0 44dvh;
    }
  }
  /* Fallback path: app.js mirrors scroll progress into --hero-p (0→1). */
  @supports not (animation-timeline: scroll()) {
    .modal-edit .edit-media img {
      opacity: calc(1 - .7 * var(--hero-p, 0));
      transform: translateY(calc(var(--hero-p, 0) * 12dvh)) scale(calc(1 + .06 * var(--hero-p, 0)));
    }
  }
}
@keyframes hero-scrub { to { opacity: .3; transform: translateY(12dvh) scale(1.06); } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.field-label .muted { font-weight: 400; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"] {
  font: inherit; font-size: var(--fs-base); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; outline: none; width: 100%;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:hover { border-color: var(--border-strong); }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }

/* Animated reveal for conditional fields (e.g. target price).
   Grid-rows technique — smooth for unknown heights. */
.reveal {
  display: grid; grid-template-rows: 0fr; opacity: 0;
  transition: grid-template-rows .24s var(--ease), opacity .2s var(--ease);
}
.reveal.open { grid-template-rows: 1fr; opacity: 1; }
.reveal-inner { overflow: hidden; min-height: 0; }
.reveal .target-field { margin-top: 8px; padding: 2px; margin-left: -2px; margin-right: -2px; }

/* Alert-filter on/off pair (Ignoring/Including RTC · DFS). */
.toggle-row { display: flex; gap: 8px; }
.toggle-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-2);
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.toggle-btn:hover { border-color: var(--text-3); color: var(--text); }
.toggle-btn .toggle-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; flex: none;
  color: var(--text-3);
  background: var(--surface-2);
}
.toggle-btn .toggle-icon svg { display: block; }
.toggle-btn.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.toggle-btn.is-on .toggle-icon { background: var(--accent); color: #fff; }

/* Check frequency dropdown + icon-only "check now" button, one row. */
.schedule-row { display: flex; gap: 8px; align-items: center; }
.schedule-row .schedule-dd { flex: 1; min-width: 0; }
.schedule-row .btn-icon { flex: none; padding: 8px 10px; }
.btn-icon.btn-bordered { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); }
.btn-icon.btn-bordered:hover:not([disabled]) { border-color: var(--text-3); background: var(--surface-2); color: var(--text); }

/* View product / Delete / Save changes, one row. */
.edit-actions { display: flex; gap: 10px; }
.edit-actions .btn { flex: 1; justify-content: center; }

/* ---------- Custom dropdown ---------- */
.dd { position: relative; }
.dd-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  font: inherit; font-size: var(--fs-base); color: var(--text); text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; cursor: pointer;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease),
              background .15s var(--ease), color .15s var(--ease);
}
.dd-btn:hover { border-color: var(--border-strong); }
.dd.open .dd-btn, .dd-btn:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.dd-disabled .dd-btn { color: var(--text-3); cursor: default; background: var(--surface-2); }
.dd-disabled .dd-btn:hover { border-color: var(--border); }
.dd-disabled .dd-caret { opacity: .4; }
.dd-label { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Micro-crossfade when setOptions swaps the visible label (e.g. the edit
   modal's variant dropdown populating after its background fetch). */
.dd-label.dd-label-swap { animation: content-in .18s var(--ease); }
.dd-caret { color: var(--text-3); flex: none; transition: transform .18s var(--ease); }
.dd.open .dd-caret { transform: rotate(180deg); }
.dd-menu {
  /* Fixed (not absolute-under-the-button) so it's never clipped by a
     scrollable ancestor — modal bodies scroll internally on small screens,
     and an absolutely-positioned menu would be cut off there. Position is
     computed in JS from the button's own viewport rect. */
  position: fixed; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 4px; box-shadow: var(--shadow-float);
  max-height: 280px; overflow-y: auto;
  animation: dd-in .14s var(--ease);
}
.dd-menu.closing { animation: dd-out .1s var(--ease) forwards; }
@keyframes dd-in { from { opacity: 0; transform: translateY(-3px) scale(.99); } }
@keyframes dd-out { to { opacity: 0; transform: translateY(-3px) scale(.99); } }
.dd-opt {
  display: flex; align-items: center; gap: 8px; width: 100%;
  font: inherit; font-size: var(--fs-md); color: var(--text-2);
  background: transparent; border: 0; border-radius: 6px; padding: 7px 9px;
  cursor: pointer; text-align: left; white-space: nowrap;
}
.dd-opt:hover, .dd-opt:focus-visible { background: var(--surface-2); color: var(--text); outline: none; }
.dd-opt[disabled] { opacity: .45; cursor: default; }
.dd-opt[disabled]:hover { background: transparent; color: var(--text-2); }
.dd-opt[aria-selected="true"] { color: var(--text); font-weight: 500; }
/* Selected tick — inline SVG appended in renderMenu, not a text glyph. */
.dd-check { display: inline-flex; margin-left: auto; padding-left: 10px; color: var(--accent); }
.dd-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--dot); }
/* Sits directly after the option label (left-aligned), not pushed to the far
   right — the ✓ tick is the only element that claims the auto margin, so it
   alone floats to the right edge instead of colliding with the price. */
.dd-hint { color: var(--text-3); font-size: var(--fs-xs); }

/* ---------- Settings ---------- */
/* One column — sections stack with hairline dividers, so labels, values and
   buttons all share a single left edge (no cross-column drift). */
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 0; align-items: start; }
.settings-col { display: flex; flex-direction: column; min-width: 0; }
.settings-section { display: flex; flex-direction: column; gap: 12px; padding: 18px 0; }
.settings-col .settings-section:first-child { padding-top: 4px; }
.settings-col .settings-section + .settings-section { border-top: 1px solid var(--border); }
.section-label {
  font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em;
  color: var(--text); margin: 0;
}
.switch-field { flex-direction: row; align-items: center; justify-content: space-between; gap: 14px; }
.switch-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
/* Row title reads as the control's label (body-dark), caption stays small+muted. */
.switch-copy .field-label { font-size: var(--fs-base); color: var(--text); }
.switch-copy small { font-size: var(--fs-sm); }
.account-email { flex: 1; display: flex; align-items: center; font-size: var(--fs-base); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switch { appearance: none; width: 36px; height: 21px; border-radius: 20px; background: var(--border-strong);
  position: relative; cursor: pointer; transition: background .18s var(--ease); flex: none; margin: 0; }
.switch::after { content: ''; position: absolute; top: 2.5px; left: 2.5px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .18s var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(15px); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 40px);
}
.toast {
  display: flex; align-items: center; gap: 12px;
  background: var(--text); color: var(--bg); font-size: var(--fs-md); font-weight: 500;
  padding: 9px 16px; border-radius: 9px;
  animation: toast-in .22s var(--ease);
  pointer-events: auto;
  max-width: 100%;
}
.toast.hide { animation: toast-out .18s var(--ease) forwards; }
.toast-action {
  font: inherit; font-weight: 600; border: 0; background: transparent; cursor: pointer;
  color: color-mix(in srgb, var(--bg) 55%, var(--accent));
  padding: 2px 4px; border-radius: 5px; margin: -2px -4px;
}
.toast-action:hover { background: color-mix(in srgb, var(--bg) 12%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

@keyframes rise { from { opacity: 0; transform: translateY(6px) } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }

/* ---------- Mobile: full-screen modals ---------- */
@media (max-width: 640px) {
  .modal, .modal-wide {
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    border: 0; border-radius: 0; margin: 0;
  }
  .settings-grid { grid-template-columns: 1fr; gap: 20px; }

  /* Bottom-sheet motion instead of the desktop scale/fade — the whole
     dialog slides up from the bottom edge and back down on close.
     closeModal()'s animationend wait covers the exit with margin to spare. */
  .modal[open] { animation: sheet-in .34s cubic-bezier(.32,.72,.28,1); }
  .modal.closing { animation: sheet-out .24s var(--ease) forwards; }

  /* Back (‹) replaces ✕, moves to the leading edge, and clears the notch
     (viewport-fit=cover makes the safe-area env() live). */
  .modal-close .icon-x { display: none; }
  .modal-close .icon-back { display: block; }
  .modal-edit .modal-close { left: 10px; right: auto; top: max(10px, env(safe-area-inset-top)); }
  .modal-head { position: sticky; top: 0; z-index: 5; background: var(--surface); }
  .modal-head .modal-close {
    order: -1; position: static;
    background: transparent; backdrop-filter: none;
  }
  /* Centre the title between the back button and its 28px-wide phantom
     counterweight on the right, instead of letting it hug the far edge. */
  .modal-head h2 { flex: 1; text-align: center; margin-right: 28px; }

  /* The primary action (Save changes / Start tracking / Save) floats as a
     pill above the bottom edge, clear of the home indicator; everything
     else — including the other buttons on the same desktop row — scrolls
     normally underneath it. */
  #saveEditBtn, #confirmAddBtn, #saveSettingsBtn {
    position: fixed; left: 16px; right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 6; margin: 0;
    border-radius: 12px;
    padding: 14px 16px;
    font-size: var(--fs-base);
  }
  .edit-content, .modal-body { padding-bottom: 96px; }
}

@media (max-width: 760px) {
  .brand > span:last-child { display: none; }
  .search-kbd { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 14px; gap: 6px; flex-wrap: wrap; }
  .topbar .btn span:last-child { display: none; }
  .topbar .btn { padding: 7px 10px; }
  .topbar-search { order: 10; flex: 1 1 100%; margin-left: 0; }
  .main { padding: 16px 14px calc(48px + env(safe-area-inset-bottom)); }
  .grid { grid-template-columns: 1fr; }
  /* Single column: a wider-than-tall crop keeps each card from eating a
     whole screen, so the list stays scannable. */
  .card { aspect-ratio: 3 / 2; }
  .toasts { bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px)); }
}
/* Touch feedback on cards, mirroring .btn:active. */
@media (pointer: coarse) {
  .card { transition: border-color .15s var(--ease), opacity .18s var(--ease), transform .15s var(--ease); }
  .card:active { transform: scale(.985); }
}
/* iOS Safari zooms the page in on focus of any text input rendered under
   16px — bump every text-ish input to exactly that on small/touch viewports
   without changing the (smaller, intentional) desktop sizing. */
@media (max-width: 640px), (pointer: coarse) {
  input[type="text"], input[type="password"], input[type="email"], input[type="number"],
  .topbar-search #searchInput {
    font-size: 16px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
