/* Brand palette approximates Cash Converters' own red/yellow/charcoal
   identity (see README.md). Light by default, with a dark variant that
   follows the device's light/dark setting (prefers-color-scheme) - there's
   no in-page toggle. The brand red header and yellow accents stay the same
   in both; dark mode only swaps the neutrals and lightens the red where
   it's used as text on a dark background (--blue, --link). --good/--critical
   stay semantic (price down/up), independent of the brand accents. */
:root {
  color-scheme: light dark;
  --brand-red: #B20838;
  --brand-red-dark: #8a0629;
  --brand-yellow: #FFD400;
  --page: #F3F3F3;
  --surface: #FFFFFF;
  --text-primary: #222222;
  --text-secondary: #55524f;
  --text-muted: #767676;
  --border: rgba(34,34,34,0.14);
  --good: #1a8f3c;
  --critical: #B20838;
  --blue: #B20838;
  --link: #B20838;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #121214;
    --surface: #1c1c1e;
    --text-primary: #ececec;
    --text-secondary: #b8b5b2;
    --text-muted: #9a9a9a;
    --border: rgba(255,255,255,0.14);
    /* #B20838 is too dark to read as text on a dark surface (~2.4:1);
       this lighter red is ~4.9:1. Solid red fills (header, CTA, critical
       pill) keep the brand red, where white text on it is ~7:1. */
    --blue: #ef4f75;
    --link: #ef4f75;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.brand-header {
  background: var(--brand-red); color: #fff;
  padding: calc(18px + env(safe-area-inset-top)) 16px 16px;
}
.brand-header-inner { max-width: 640px; margin: 0 auto; }
.brand-header h1 { font-size: 1.5rem; margin: 0 0 8px; color: #fff; }
.kofi-cta {
  display: inline-block; font-size: 0.85rem; font-weight: 700;
  color: var(--brand-red-dark); background: var(--brand-yellow);
  padding: 8px 20px; border-radius: 999px; text-decoration: none;
  margin-bottom: 6px;
}
.kofi-cta:active { opacity: 0.8; }
.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
header.page-head { padding: 0 4px 16px; }
header.page-head .updated { color: var(--text-muted); font-size: 0.85rem; }
.stats-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.stats-row .badge { font-size: 0.8rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.card-head h2 { font-size: 1.05rem; margin: 0; }
.badge {
  font-size: 0.8rem; color: var(--text-secondary); background: var(--page);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; white-space: nowrap;
}
.search-box-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-box {
  flex: 1; min-width: 0; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--page); color: var(--text-primary); font-size: 0.9rem;
}
.search-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.search-controls select {
  flex: 1; min-width: 0; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--page); color: var(--text-primary); font-size: 0.85rem;
}
.reset-btn {
  flex-shrink: 0; width: 38px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--page); color: var(--text-secondary);
  font-size: 1.1rem; cursor: pointer;
}
.reset-btn:active { opacity: 0.6; }
.sort-hint { color: var(--text-muted); font-size: 0.78rem; margin: -4px 0 10px; }
.price-filter { margin-bottom: 4px; }
.price-inputs { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.price-inputs input[type=number] {
  width: 100%; min-width: 0; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--page); color: var(--text-primary); font-size: 0.85rem;
}
.price-inputs span { color: var(--text-muted); flex-shrink: 0; }
.price-slider-wrap { position: relative; height: 32px; margin-bottom: 8px; }
.price-slider-track {
  position: absolute; top: 50%; left: 0; right: 0; height: 4px;
  background: var(--border); border-radius: 2px; transform: translateY(-50%);
}
.price-slider-fill {
  position: absolute; top: 50%; height: 4px; background: var(--blue);
  border-radius: 2px; transform: translateY(-50%);
}
.price-slider-wrap input[type=range] {
  position: absolute; top: 0; left: 0; width: 100%; height: 32px; margin: 0;
  background: transparent; appearance: none; -webkit-appearance: none; pointer-events: none;
}
.price-slider-wrap input[type=range]::-webkit-slider-runnable-track { background: transparent; }
.price-slider-wrap input[type=range]::-moz-range-track { background: transparent; }
.price-slider-wrap input[type=range]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none; width: 18px; height: 18px; margin-top: 7px;
  border-radius: 50%; background: var(--blue); border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.35); cursor: pointer; pointer-events: auto;
}
.price-slider-wrap input[type=range]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--blue);
  border: 2px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,0.35);
  cursor: pointer; pointer-events: auto;
}
.bulk-chatgpt-btn {
  width: 100%; margin-bottom: 10px; padding: 9px;
  border: 1px solid var(--blue); border-radius: 10px;
  background: var(--surface); color: var(--blue);
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.bulk-chatgpt-btn:active { opacity: 0.6; }
.bulk-chatgpt-btn:disabled { opacity: 0.6; cursor: default; }
.load-more-btn {
  width: 100%; margin-top: 10px; padding: 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--page); color: var(--text-secondary);
  font-size: 0.88rem; font-weight: 600; cursor: pointer;
}
.load-more-btn:active { opacity: 0.6; }
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  align-items: center; justify-content: center; padding: 16px; z-index: 1000;
}
.modal-backdrop.open { display: flex; }
.modal-card {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 420px;
  /* svh (smallest viewport, i.e. with Safari's URL/tab bars fully shown) is
     set after the vh fallback so the card's max-height doesn't jump around
     as those bars show/hide mid-scroll - the fixed-height glitch on iOS. */
  max-height: 88vh; max-height: 88svh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; justify-content: flex-end; flex-shrink: 0;
  background: var(--surface); padding: 10px 10px 0;
}
.modal-close {
  padding: 9px 18px; border-radius: 999px;
  border: 2px solid var(--blue); background: var(--surface); color: var(--blue);
  font-size: 0.88rem; font-weight: 700; cursor: pointer;
}
.modal-close:active { opacity: 0.7; }
.modal-scroll {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  /* Pre-establishes this as its own compositing layer rather than waiting
     for the first touch - the fix for iOS Safari sometimes needing 2-3
     scroll attempts before it "wakes up" a freshly-shown scroll container. */
  transform: translateZ(0);
}
.modal-nav-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px;
}
.modal-nav-btn {
  flex-shrink: 0; border: 1px solid var(--border); border-radius: 999px;
  background: var(--page); color: var(--text-secondary);
  font-size: 0.82rem; font-weight: 600; padding: 6px 12px; cursor: pointer;
}
.modal-nav-btn:active { opacity: 0.6; }
.modal-nav-btn:disabled { opacity: 0.35; cursor: default; }
.modal-position { color: var(--text-muted); font-size: 0.78rem; }
.modal-img {
  width: 100%; height: 240px; object-fit: contain; background: var(--page);
  display: block; touch-action: pan-y;
}
.modal-img-empty { height: 120px; opacity: 0.3; }
.modal-body { padding: 18px; }
.modal-body h3 { margin: 0 0 4px; font-size: 1.1rem; }
.modal-sub { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 12px; }
.modal-prices { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.modal-prices .item-price { font-size: 1.4rem; }
.modal-prices .price-stack { align-items: flex-start; }
.modal-prices .item-postage { font-size: 0.8rem; }
.modal-meta-row {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 0.85rem; padding: 7px 0; border-bottom: 1px solid var(--border);
}
.modal-meta-row:last-child { border-bottom: none; }
.modal-meta-row span:first-child { color: var(--text-muted); }
.modal-meta-row span:last-child { text-align: right; }
.modal-cta {
  display: block; text-align: center; margin-top: 16px; padding: 13px;
  border-radius: 12px; background: var(--brand-red); color: #fff;
  text-decoration: none; font-weight: 600; font-size: 0.95rem;
}
.modal-cta:active { opacity: 0.8; }
.modal-cta-secondary {
  display: block; text-align: center; margin-top: 10px; padding: 13px;
  border-radius: 12px; border: 2px solid var(--blue); background: var(--surface);
  color: var(--blue); text-decoration: none; font-weight: 600; font-size: 0.95rem;
}
.modal-cta-secondary:active { opacity: 0.7; }
.history-section { margin-top: 16px; }
.history-title { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.history-chart { width: 100%; height: auto; display: block; }
.history-chart .hc-line { fill: none; stroke: var(--blue); stroke-width: 2; }
.history-chart .hc-dot { fill: var(--surface); stroke: var(--blue); stroke-width: 2; }
.history-chart .hc-baseline { stroke: var(--border); stroke-width: 1; }
.history-chart .hc-label { fill: var(--text-secondary); font-size: 9px; font-family: system-ui, sans-serif; }
.history-chart .hc-axis { fill: var(--text-muted); font-size: 8px; font-family: system-ui, sans-serif; }
.history-empty { color: var(--text-muted); font-size: 0.82rem; margin: 0; }
.history-list { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.history-row { display: flex; justify-content: space-between; gap: 8px; font-size: 0.78rem; color: var(--text-secondary); }
.history-row .pill { flex-shrink: 0; }
.item-list { display: flex; flex-direction: column; }
.item-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.item-row:last-child { border-bottom: none; }
.item-thumb {
  width: 44px; height: 44px; border-radius: 8px; object-fit: contain;
  background: var(--page); border: 1px solid var(--border); flex-shrink: 0;
}
.item-thumb-empty { opacity: 0.4; }
.item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.item-title {
  font-size: 0.9rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.item-sub { font-size: 0.78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* AI tag pills under the title/store line (tagRowHtml in dashboard.js). */
.item-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.item-price-block { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.item-rrp { font-size: 0.78rem; color: var(--text-muted); text-decoration: line-through; }
.item-price { font-size: 0.92rem; font-weight: 600; }
/* Price with its postage line underneath (priceWithPostageHtml in
   dashboard.js). Right-aligned in the results list, left in the modal. */
.price-stack { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.item-postage { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }
.pill { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
/* A "% off RRP" pill is a promotional highlight, not just a status
   indicator - brand yellow fits that better than a generic green. */
.pill-good { color: var(--brand-red-dark); background: var(--brand-yellow); }
.pill-critical { color: #fff; background: var(--critical); }
/* AI "HOT"/"HOTTER" tag (scripts/hot_review.py). Brand red with yellow
   text, so it reads as the loudest pill on a row without bringing a new
   colour into the palette. */
.pill-hot { color: var(--brand-yellow); background: var(--brand-red); }
/* AI "FLIP" tag - charcoal (inverted to light grey in dark mode), so it
   reads as a different kind of signal from HOT when both sit on one row. */
.pill-flip { color: var(--surface); background: var(--text-primary); }
/* Haggle likelihood (hagglePillHtml in dashboard.js) - one green scale,
   from outlined grey (low) through outlined green to solid green (high),
   so the stronger the chance the more the pill stands out. */
.pill-haggle-low { color: var(--text-secondary); background: transparent; box-shadow: inset 0 0 0 1px currentColor; }
.pill-haggle-medium { color: var(--good); background: transparent; box-shadow: inset 0 0 0 1px currentColor; }
.pill-haggle-high { color: #fff; background: var(--good); }
.empty-msg { color: var(--text-muted); font-size: 0.88rem; text-align: center; padding: 16px 0; margin: 0; }
footer { text-align: center; color: var(--text-muted); font-size: 0.75rem; padding-top: 8px; }
footer .disclaimer { max-width: 460px; margin: 8px auto 0; line-height: 1.4; }
footer .legal-links { margin-top: 8px; }
footer .legal-links a { color: var(--text-secondary); }
footer a { color: var(--link); text-decoration: none; }
footer a:hover, footer a:active { text-decoration: underline; }
