:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --border: #e6dfd3;
  --text: #1f1a14;
  --text-2: #5b5247;
  --muted: #6b6258; /* ≥5.2:1 on every light surface (WCAG AA) */
  --accent: #b45309;
  --accent-ink: #ffffff;
  --accent-soft: #fdf1e3;
  --chart: #c2620f;
  --grid: #ece6dc;
  --danger: #b42318;
  --good: #067647;
  --shadow: 0 1px 2px rgba(31, 26, 20, .06), 0 4px 16px rgba(31, 26, 20, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14110e;
    --surface: #1d1915;
    --surface-2: #26211b;
    --border: #352e26;
    --text: #f3ede4;
    --text-2: #c4b9aa;
    --muted: #a39889; /* ≥5.4:1 on every dark surface (WCAG AA) */
    --accent: #f59e0b;
    --accent-ink: #1f1a14;
    --accent-soft: #2e2416;
    --chart: #e8912b;
    --grid: #2b251f;
    --danger: #f97066;
    --good: #47cd89;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14110e;
  --surface: #1d1915;
  --surface-2: #26211b;
  --border: #352e26;
  --text: #f3ede4;
  --text-2: #c4b9aa;
  --muted: #a39889;
  --accent: #f59e0b;
  --accent-ink: #1f1a14;
  --accent-soft: #2e2416;
  --chart: #e8912b;
  --grid: #2b251f;
  --danger: #f97066;
  --good: #47cd89;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-family: Fraunces, Georgia, serif; font-weight: 600; font-size: 1.8rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--accent); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand span { color: var(--text); }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.nav a, .nav button {
  color: var(--text-2); text-decoration: none; background: none; border: 0; font: inherit;
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: .9rem;
}
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
@media (max-width: 600px) {
  /* Wrap rather than scroll sideways, so every menu item stays visible */
  .topbar { flex-wrap: wrap; row-gap: 6px; padding-bottom: 6px; }
  .nav { width: 100%; justify-content: flex-start; margin: 0 -6px; }
  .nav a, .nav button { white-space: nowrap; }
}

/* ---------- Accessibility helpers ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }
:is(h1, h2)[tabindex="-1"]:focus { outline: none; } /* headings get focus only so screen readers start reading there */
.skip-link {
  position: absolute; left: 16px; top: -100px; z-index: 100;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
  padding: 10px 16px; border-radius: 10px; text-decoration: none;
}
.skip-link:focus { top: 10px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  /* Windows High Contrast: keep chart marks, badges and buttons visible */
  .chart-wrap .bar { fill: CanvasText; }
  .hbars .fill { background: CanvasText; forced-color-adjust: none; }
  .hbars .track, .badge, .btn, .card, .tags li { border: 1px solid CanvasText; }
  .tooltip { border: 1px solid CanvasText; }
}

/* ---------- Layout ---------- */
.app { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; outline: none; }
.narrow { max-width: 440px; margin: 0 auto; }
.mid { max-width: 640px; margin: 0 auto; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* ---------- Forms & buttons ---------- */
label { display: block; font-size: .85rem; font-weight: 500; color: var(--text-2); margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"] {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px;
}
.field + .field { margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink);
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.block { width: 100%; }
.form-error { color: var(--danger); font-size: .88rem; min-height: 1.2em; margin-top: 8px; }
.demo-logins { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  font: inherit; font-size: .8rem; padding: 4px 10px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Scanner ---------- */
.scanner {
  position: relative; aspect-ratio: 1 / 1; width: 100%; border-radius: var(--radius);
  overflow: hidden; background: #0d0b09; display: grid; place-items: center;
}
.scanner #reader { position: absolute; inset: 0; }
.scanner #reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.scanner .placeholder { color: #c4b9aa; text-align: center; padding: 24px; z-index: 1; }
.scanner .frame {
  position: absolute; inset: 18%; border-radius: 16px; z-index: 2; pointer-events: none;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
  border: 2px solid rgba(255, 255, 255, .85);
}
.scanner .frame::after {
  content: ""; position: absolute; left: 8%; right: 8%; height: 2px; top: 50%;
  background: #f59e0b; box-shadow: 0 0 12px #f59e0b; animation: sweep 2.2s ease-in-out infinite;
}
@keyframes sweep { 0%, 100% { top: 12%; } 50% { top: 88%; } }
@media (prefers-reduced-motion: reduce) { .scanner .frame::after { animation: none; } }
.manual { display: flex; gap: 8px; }
.manual input { flex: 1; }

/* ---------- Bottle detail ---------- */
.bottle-hero { display: grid; grid-template-columns: 120px 1fr; gap: 20px; align-items: center; }
@media (max-width: 480px) { .bottle-hero { grid-template-columns: 84px 1fr; gap: 14px; } }
.bottle-art { width: 100%; height: auto; }
.eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 0; }
.facts div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.facts dt { font-size: .75rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0; list-style: none; }
.tags li { background: var(--accent-soft); color: var(--text); border-radius: 999px; padding: 4px 10px; font-size: .85rem; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--border); }
.list a { display: flex; gap: 12px; align-items: center; padding: 10px 4px; color: inherit; text-decoration: none; }
.list a:hover { background: var(--surface-2); }
.list .thumb { width: 28px; flex: none; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }

/* ---------- Sample codes ---------- */
.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.code-card { text-align: center; padding: 14px; }
.code-card .qr { background: #fff; border-radius: 8px; padding: 8px; display: inline-block; }
.code-card .qr img, .code-card .qr svg { display: block; width: 132px; height: 132px; }
.code-card .name { font-weight: 600; font-size: .9rem; margin-top: 8px; }

/* ---------- Admin ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { padding: 16px; }
.kpi .label { font-size: .8rem; color: var(--muted); }
.kpi .value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--text-2); }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-wrap .axis { fill: var(--muted); font-size: 11px; font-family: Inter, system-ui, sans-serif; }
.chart-wrap .gridline { stroke: var(--grid); stroke-width: 1; }
.chart-wrap .bar { fill: var(--chart); }
.chart-wrap .hit { fill: transparent; cursor: default; }
.chart-wrap .bar.hover { filter: brightness(1.15); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--text); color: var(--bg); font-size: .8rem; padding: 6px 10px; border-radius: 8px;
  white-space: nowrap; transform: translate(-50%, calc(-100% - 8px)); opacity: 0; transition: opacity .08s;
}
.tooltip.show { opacity: 1; }
.hbars { list-style: none; padding: 0; margin: 0; }
.hbars li { display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 4px 10px; align-items: center; padding: 6px 0; }
.hbars .name { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbars .num { font-size: .85rem; text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; grid-row: 1 / span 2; grid-column: 2; }
.hbars .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbars .fill { height: 100%; background: var(--chart); border-radius: 0 4px 4px 0; }
.table-wrap { position: relative; overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
th button { all: unset; cursor: pointer; }
th button:hover { color: var(--text); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge.admin { background: var(--accent-soft); color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { font: inherit; font-size: .82rem; padding: 6px 12px; border: 0; background: var(--surface); color: var(--text-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- Edit user dialog ---------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px; width: min(560px, calc(100% - 32px)); max-height: calc(100dvh - 32px); box-shadow: var(--shadow);
}
.sessions .sess { display: flex; gap: 12px; align-items: center; padding: 10px 0; }
.sessions .sess .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sessions .sess .title { font-weight: 600; }
.btn.danger-solid { background: var(--danger); color: var(--surface); }
.btn.danger-solid:disabled { opacity: .45; cursor: not-allowed; }
.danger-zone h2 { color: var(--danger); }
.danger-zone input { margin-top: 2px; }
.badge.failed { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
summary { cursor: pointer; }
dialog.modal::backdrop { background: rgba(20, 17, 14, .5); }
dialog.modal hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
select:disabled { color: var(--muted); background: var(--surface-2); }
.btn.small { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }

/* ---------- What's new ---------- */
.nav .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; vertical-align: 2px;
  background: var(--danger); box-shadow: 0 0 0 2px var(--surface);
}
.release-meta { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.release h2, .release h3 { font-size: 1.1rem; margin-bottom: 6px; }
.release-body p { margin: 0 0 .6rem; }
.release-body ul { margin: 0 0 .6rem; padding-left: 1.25rem; }
.release-body li + li { margin-top: 4px; }
.releases hr, .whats-new hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.whats-new .release + .release { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.badge.new { background: var(--accent); color: var(--accent-ink); }
.badge.published { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }

/* ---------- Admin tabs & release editor ---------- */
.subnav { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.subnav a {
  padding: 8px 12px; color: var(--text-2); text-decoration: none; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav a:hover { color: var(--text); }
.subnav a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.release-editor { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }
textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); resize: vertical;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 9rem;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.field.check { display: flex; gap: 8px; align-items: flex-start; }
.field.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); }
.field.check label { margin: 0; color: var(--text); font-weight: 400; }
.release-admin-list .rel-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px 0; }
.release-admin-list .grow { flex: 1; min-width: 200px; }
.release-admin-list .title { font-weight: 600; white-space: normal; overflow: visible; }
.rel-actions { gap: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
