:root {
  --bg: #f6f5f1; --surface: #fff; --ink: #1d2622; --muted: #66726c; --line: #e2e0d8;
  --accent: #1f6f50; --accent-ink: #fff; --accent-soft: #e3f1ea;
  --warn: #b7791f; --warn-soft: #fbf1dc; --bad: #b3372f; --bad-soft: #f9e3e0; --good: #1f6f50;
  --c1: #1f6f50; --c2: #d9822b; --c3: #3b6ea5; --c4: #9a5b8f; --c5: #7a8a3a; --c6: #b3372f;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,25,.06), 0 4px 14px rgba(20,30,25,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131815; --surface: #1b221e; --ink: #e8ede9; --muted: #93a099; --line: #2c3631;
    --accent: #4fb98a; --accent-ink: #0c1411; --accent-soft: #1d2f27;
    --warn: #e0a64a; --warn-soft: #33290f; --bad: #e57a70; --bad-soft: #3a1d1a;
    --c1: #4fb98a; --c2: #e69a52; --c3: #6fa3d9; --c4: #c487ba; --c5: #a6b85a; --c6: #e57a70;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.45;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); font-size: .9rem; }
.mono { font-variant-numeric: tabular-nums; }

/* layout */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 4px; min-height: 52px; }
.brand { font-weight: 700; margin-right: 12px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap; font-size: .95rem; }
.nav a:hover { background: var(--accent-soft); color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge { display: inline-block; min-width: 1.35em; padding: 0 .4em; margin-left: .3em; border-radius: 999px; background: var(--c2); color: #fff; font-size: .75rem; text-align: center; }
.who { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.who form { margin: 0; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

/* controls */
button, .btn, input, select, textarea { font: inherit; }
.btn, button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover, button:hover { border-color: var(--accent); }
.btn.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger, button.danger { color: var(--bad); }
.btn.small, button.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); min-height: 40px; }
input[type=checkbox] { width: auto; min-height: 0; }
.field { margin-bottom: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; }
.row > * { flex: 1 1 160px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters > div { min-width: 140px; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 14px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.delta { font-size: .85rem; }
.delta.up { color: var(--bad); } .delta.down { color: var(--good); }
.chart-box { position: relative; height: 260px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--accent-soft); }

/* status pills & alerts */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; background: var(--line); color: var(--ink); white-space: nowrap; }
.pill.submitted, .pill.needs_review { background: var(--warn-soft); color: var(--warn); }
.pill.reviewed, .pill.auto_approved { background: var(--accent-soft); color: var(--accent); }
.pill.rejected { background: var(--bad-soft); color: var(--bad); }
.alert { display: flex; gap: 12px; justify-content: space-between; align-items: start; padding: 10px 12px; border-radius: 8px; border-left: 4px solid var(--warn); background: var(--warn-soft); margin-bottom: 8px; }
.alert.critical { border-color: var(--bad); background: var(--bad-soft); }
.alert.info { border-color: var(--c3); background: var(--accent-soft); }
.alert strong { display: block; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); margin-bottom: 12px; }
.notice.error { background: var(--bad-soft); color: var(--bad); }
.insight { padding: 10px 0; border-bottom: 1px solid var(--line); } .insight:last-child { border: 0; }
.insight .t { font-weight: 600; }
.insight.warning .t::before { content: "▲ "; color: var(--warn); }
.insight.good .t::before { content: "▼ "; color: var(--good); }

/* auth */
.auth { max-width: 380px; margin: 12vh auto 0; }

/* capture */
.capture-wrap { max-width: 560px; margin: 0 auto; }
.camera { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4/3; }
.camera video, .camera img { width: 100%; height: 100%; object-fit: cover; display: block; }
.guide { position: absolute; inset: 0; pointer-events: none; }
.guide .box { position: absolute; border: 2px dashed rgba(255,255,255,.85); border-radius: 8px; color: #fff; font-size: .75rem; padding: 3px 6px; text-shadow: 0 1px 2px #000; }
.guide .tray { left: 6%; top: 12%; width: 56%; height: 76%; }
.guide .display { right: 5%; top: 12%; width: 30%; height: 28%; }
.camera .sent { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(31,111,80,.88); color: #fff; font-size: 1.6rem; font-weight: 700; }
.camera .hint { position: absolute; left: 8px; right: 8px; bottom: 8px; background: rgba(0,0,0,.65); color: #fff; padding: 6px 10px; border-radius: 8px; font-size: .85rem; }
.camera .hint.bad { background: rgba(179,55,47,.9); }
.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); gap: 8px; }
.seg.big { grid-template-columns: 1fr 1fr; }
.seg.big label { min-height: 64px; font-size: 1.05rem; }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg label { margin: 0; padding: 12px 8px; text-align: center; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; font-size: .9rem; min-height: 46px; display: flex; align-items: center; justify-content: center; }
.seg input:checked + label { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.weight-input { font-size: 1.6rem; font-weight: 700; text-align: center; min-height: 56px; }
.step-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 12px; }
.sticky-actions .btn, .sticky-actions button { width: 100%; min-height: 52px; font-size: 1.05rem; }
.queue-banner { background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: .9rem; }

/* review */
.review-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
.review-grid img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); }
.suggest { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.suggest b { color: var(--accent); }
.flag { color: var(--bad); font-size: .85rem; }
@media (max-width: 760px) { .review-grid { grid-template-columns: 1fr; } .who span { display: none; } }

/* admin & labels */
details.item { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--surface); }
details.item > summary { cursor: pointer; padding: 10px 12px; display: flex; justify-content: space-between; gap: 8px; }
details.item form { padding: 4px 12px 12px; }
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.label-card { border: 1px solid #000; border-radius: 6px; padding: 10px; text-align: center; break-inside: avoid; background: #fff; color: #000; }
.label-card img { width: 140px; height: 140px; }
@media print { .topbar, .no-print { display: none !important; } body { background: #fff; } }
