:root {
  --bg: #f6f7f8; --surface: #ffffff; --text: #16202a; --muted: #5b6875; --border: #e2e6ea;
  --primary: #0f766e; --primary-strong: #0b5d57; --on-primary: #ffffff; --accent: #d9480f; --accent-bg: #fff1e8;
  --good: #15803d; --good-bg: #e7f6ec; --warn: #a16207; --warn-bg: #fdf3d8; --bad: #b42318; --bad-bg: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08); --radius: 14px;
  --chart-line: #0f766e; --chart-fill: rgba(15, 118, 110, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1418; --surface: #151d23; --text: #e8eef2; --muted: #93a1ad; --border: #26313a;
    --primary: #2dd4bf; --primary-strong: #5eead4; --on-primary: #06231f; --accent: #fb923c; --accent-bg: #3a2414;
    --good: #4ade80; --good-bg: #12301f; --warn: #facc15; --warn-bg: #33290d; --bad: #f87171; --bad-bg: #3a1a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --chart-line: #2dd4bf; --chart-fill: rgba(45, 212, 191, .14); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1418; --surface: #151d23; --text: #e8eef2; --muted: #93a1ad; --border: #26313a;
  --primary: #2dd4bf; --primary-strong: #5eead4; --on-primary: #06231f; --accent: #fb923c; --accent-bg: #3a2414;
  --good: #4ade80; --good-bg: #12301f; --warn: #facc15; --warn-bg: #33290d; --bad: #f87171; --bad-bg: #3a1a17;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --chart-line: #2dd4bf; --chart-fill: rgba(45, 212, 191, .14); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 1rem; }
.wrap-wide { max-width: 1100px; }
.beta-banner { background: var(--warn-bg); color: var(--warn); font-size: .85rem; padding: .45rem 1rem; text-align: center; border-bottom: 1px solid var(--border); }
.demo-banner { background: var(--bad-bg); color: var(--bad); font-weight: 600; text-align: center; padding: .5rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; padding-top: env(safe-area-inset-top); }
.header .wrap { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: .5rem; }
.logo { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.15rem; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo img { width: 28px; height: 28px; }
.badge-beta { font-size: .65rem; font-weight: 700; letter-spacing: .05em; background: var(--accent-bg); color: var(--accent); padding: .1rem .4rem; border-radius: 6px; }
.nav { display: flex; gap: .25rem; align-items: center; }
.nav a, .icon-btn { color: var(--muted); padding: .4rem .6rem; border-radius: 8px; font-size: .9rem; background: none; border: 0; cursor: pointer; }
.nav a:hover, .icon-btn:hover { background: var(--bg); text-decoration: none; color: var(--text); }
main { padding: 1.25rem 0 3rem; min-height: 70vh; }

.hero { text-align: center; padding: 1rem 0 1.25rem; }
.hero h1 { font-size: 1.7rem; }
.hero p { color: var(--muted); }
.search { display: flex; gap: .5rem; margin: 1rem 0 .75rem; }
.search input, .input, select, textarea {
  width: 100%; padding: .8rem 1rem; font: inherit; color: var(--text); background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 12px;
}
.search input:focus, .input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
textarea { min-height: 8rem; font-family: ui-monospace, monospace; font-size: .85rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; padding: .75rem 1.1rem; font: inherit; font-weight: 600; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.btn:hover { text-decoration: none; border-color: var(--primary); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-big { width: 100%; padding: 1.1rem; font-size: 1.1rem; }
.btn-sm { padding: .4rem .7rem; font-size: .85rem; border-radius: 9px; }

.section { margin-top: 1.75rem; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 .75rem; margin-bottom: .6rem; }
.section-head p { margin: 0; color: var(--muted); font-size: .85rem; }
.list { display: grid; gap: .6rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; }
a.card { color: inherit; } a.card:not(.deal) { display: block; } a.card:hover { text-decoration: none; border-color: var(--primary); }
.deal { display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem; align-items: center; }
.deal .name { font-weight: 600; } .deal .meta { color: var(--muted); font-size: .85rem; }
.price-col { text-align: right; }
.price { font-weight: 800; font-size: 1.2rem; }
.old-price { color: var(--muted); text-decoration: line-through; font-size: .85rem; margin-left: .4rem; }
.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; }
.pill-discount { background: var(--accent-bg); color: var(--accent); }
.pill-fresh { background: var(--good-bg); color: var(--good); } .pill-recent { background: var(--good-bg); color: var(--good); }
.pill-old { background: var(--warn-bg); color: var(--warn); } .pill-stale { background: var(--bad-bg); color: var(--bad); }
.pill-best { background: var(--primary); color: var(--on-primary); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { padding: .35rem .8rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .88rem; color: var(--text); cursor: pointer; font-family: inherit; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty strong { display: block; color: var(--text); margin-bottom: .25rem; }

.product-head { margin-bottom: 1rem; }
.product-head .sub { color: var(--muted); }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.offer { display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; align-items: center; padding: .85rem 0; border-top: 1px solid var(--border); }
.offer:first-child { border-top: 0; }
.offer .market { font-weight: 700; } .offer .fine { color: var(--muted); font-size: .8rem; }
.kv { display: grid; grid-template-columns: 9rem 1fr; gap: .4rem 1rem; font-size: .92rem; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
.chart { width: 100%; height: auto; display: block; }
.chart .line { fill: none; stroke: var(--chart-line); stroke-width: 2.5; stroke-linejoin: round; }
.chart .area { fill: var(--chart-fill); stroke: none; }
.chart .dot { fill: var(--chart-line); }
.chart .grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; }
.chart text { fill: var(--muted); font-size: 11px; }

.scanner { position: relative; overflow: hidden; border-radius: var(--radius); background: #000; aspect-ratio: 4 / 3; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 22% 10%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); pointer-events: none; }
.scan-hint { position: absolute; left: 0; right: 0; bottom: .6rem; text-align: center; color: #fff; font-size: .85rem; text-shadow: 0 1px 3px #000; }
.notice { padding: .8rem 1rem; border-radius: 12px; background: var(--warn-bg); color: var(--warn); margin: .75rem 0; }
.notice-info { background: var(--good-bg); color: var(--good); }
.notice-bad { background: var(--bad-bg); color: var(--bad); }
.notfound { border-left: 5px solid var(--warn); }

.footer { border-top: 1px solid var(--border); background: var(--surface); padding: 1.25rem 0 2rem; color: var(--muted); font-size: .85rem; }
.footer .links { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-bottom: .5rem; }
.prose h2 { margin-top: 1.25rem; } .prose ul { padding-left: 1.2rem; margin: 0 0 .75rem; } .prose li { margin-bottom: .3rem; }
.loading { text-align: center; color: var(--muted); padding: 2rem; }
.spinner { display: inline-block; width: 1.1rem; height: 1.1rem; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: .5rem; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(1rem + env(safe-area-inset-bottom)); display: grid; gap: .5rem; justify-items: center; z-index: 50; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: 90vw; }
.toast-error { background: var(--bad); color: #fff; } .toast-success { background: var(--good); color: #fff; }

/* ---------------- admin ---------------- */
.admin-tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.admin-tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: .6rem .9rem; font: inherit; color: var(--muted); cursor: pointer; }
.admin-tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }
.form-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--bg); }
.table-wrap { overflow-x: auto; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.spread { justify-content: space-between; }
.mono { font-family: ui-monospace, monospace; font-size: .82rem; }
.muted { color: var(--muted); }
.stack > * + * { margin-top: 1rem; }
.login-box { max-width: 380px; margin: 4rem auto; }

@media (min-width: 720px) { .hero h1 { font-size: 2.1rem; } .list.two { grid-template-columns: 1fr 1fr; } }

@media (max-width: 440px) {
  .header .badge-beta { display: none; }
  .nav a, .icon-btn { padding: .4rem .45rem; }
}

.icon-btn svg { width: 1.15rem; height: 1.15rem; display: block; }
.icon-btn svg circle { fill: none; stroke: currentColor; stroke-width: 2; }
.icon-btn svg path { fill: currentColor; }
.header .wrap { flex-wrap: wrap; height: auto; min-height: 56px; padding-top: .35rem; padding-bottom: .35rem; }
.nav { flex-wrap: wrap; justify-content: flex-end; }
