:root {
  --bg: #f6f4ef; --surface: #ffffff; --surface-2: #faf9f6; --border: #e4e0d6; --border-strong: #cfc9bb;
  --text: #1d2321; --muted: #6b716d; --faint: #9aa09b;
  --brand: #1f3a34; --brand-2: #2f5a4f; --brand-ink: #f3efe6; --accent: #b8862f;
  --crit: #b42318; --crit-bg: #fde8e6; --high: #b54708; --high-bg: #fdf0e1; --med: #8a6a00; --med-bg: #fbf3d5;
  --info: #175cd3; --info-bg: #e6effc; --ok: #067647; --ok-bg: #e3f4ea; --muted-bg: #efede8;
  --c-hist: #2f5a4f; --c-fc: #b8862f; --c-fit: #9aa09b; --c-proj: #175cd3;
  --radius: 10px; --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1a1f1d; --surface-2: #161b19; --border: #2a312e; --border-strong: #3a4340;
    --text: #e8ebe9; --muted: #9ba39f; --faint: #6c7571;
    --brand: #8fc2b2; --brand-2: #a9d4c6; --brand-ink: #0f1f1a; --accent: #e0b05a;
    --crit: #ff8a80; --crit-bg: #3a1714; --high: #ffb169; --high-bg: #3a2412; --med: #e8c95a; --med-bg: #33290d;
    --info: #8ab4ff; --info-bg: #14233d; --ok: #6fd3a0; --ok-bg: #0f2b1e; --muted-bg: #232a27;
    --c-hist: #8fc2b2; --c-fc: #e0b05a; --c-fit: #6c7571; --c-proj: #8ab4ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 15px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; }
.loading, .empty, .error { padding: 40px; text-align: center; color: var(--muted); }
.error { color: var(--crit); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: var(--brand-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
@media (prefers-color-scheme: dark) { .side { background: #0d1311; color: var(--text); border-right: 1px solid var(--border); } }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; }
.brand strong { display: block; font-size: 15px; letter-spacing: .01em; }
.brand small { opacity: .7; font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #1d1a12; display: grid; place-items: center; font: 700 18px Georgia, serif; flex: none; }
.side nav { padding: 4px 10px; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; padding: 14px 10px 6px; }
.nav-sep { height: 1px; background: currentColor; opacity: .12; margin: 12px 10px; }
.side nav a { display: flex; align-items: center; gap: 10px; color: inherit; padding: 7px 10px; border-radius: 7px; opacity: .85; }
.side nav a:hover { background: rgba(255, 255, 255, .08); text-decoration: none; opacity: 1; }
.side nav a.active { background: rgba(255, 255, 255, .14); opacity: 1; font-weight: 600; }
.ico { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.side-foot { padding: 14px 18px; font-size: 12px; display: grid; gap: 4px; border-top: 1px solid rgba(255, 255, 255, .1); }
.side-foot .link { color: inherit; opacity: .75; text-align: left; }
.live { display: inline-flex; align-items: center; gap: 6px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .2); }
.live.off i { background: #f87171; box-shadow: none; } .live.off span::after { content: ' (reconnecting)'; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; gap: 12px; align-items: center; padding: 12px 28px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.quick { flex: 1; max-width: 520px; }
.quick input { width: 100%; }
.menu { display: none; }
#view { padding: 24px 28px 60px; outline: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 720px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card > .card-body { padding: 16px; }
.card + .card, .grid + .card, .card + .grid, .kpis + .card, .kpis + .grid { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 12px; }
.kpi-value { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.crit .kpi-value { color: var(--crit); } .kpi.high .kpi-value { color: var(--high); } .kpi.ok .kpi-value { color: var(--ok); }
a.kpi:hover { text-decoration: none; border-color: var(--border-strong); }

/* ---------- controls ---------- */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; padding: 7px 10px; min-height: 34px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand-2) 35%, transparent); border-color: var(--brand-2); }
input[type=number] { font-variant-numeric: tabular-nums; }
.btn { font: inherit; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; border-radius: 7px; padding: 7px 13px; min-height: 34px; cursor: pointer; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--crit); }
.btn.sm { padding: 3px 9px; min-height: 28px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: inherit; padding: 4px 8px; border-radius: 6px; }
.link { background: none; border: 0; padding: 0; color: var(--brand-2); cursor: pointer; font: inherit; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 550; }
.field small { color: var(--faint); font-size: 11.5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { min-width: 220px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; font: inherit; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--brand); color: var(--brand-ink); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; cursor: pointer; user-select: none; white-space: nowrap; }
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr[data-href] { cursor: pointer; }
table.data .num { text-align: right; }
table.data td.nowrap, .nowrap { white-space: nowrap; }
table.data input[type=number] { width: 78px; padding: 4px 6px; min-height: 28px; text-align: right; }
table.data tr.dirty { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.sku { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.sub { display: block; color: var(--muted); font-size: 12px; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.crit { color: var(--crit); background: var(--crit-bg); } .badge.high { color: var(--high); background: var(--high-bg); }
.badge.med { color: var(--med); background: var(--med-bg); } .badge.info { color: var(--info); background: var(--info-bg); }
.badge.ok { color: var(--ok); background: var(--ok-bg); } .badge.muted { color: var(--muted); background: var(--muted-bg); }
.neg { color: var(--crit); font-weight: 600; } .pos { color: var(--ok); }

.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.alerts li:last-child { border-bottom: 0; }
.alerts .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.dot.critical { background: var(--crit); } .dot.high { background: var(--high); } .dot.medium { background: var(--med); } .dot.low { background: var(--info); }

.meter { height: 8px; border-radius: 99px; background: var(--muted-bg); overflow: hidden; min-width: 80px; }
.meter > div { height: 100%; background: var(--brand-2); border-radius: 99px; }
.meter.warn > div { background: var(--accent); } .meter.bad > div { background: var(--crit); }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.stat-row { display: flex; gap: 24px; flex-wrap: wrap; }
.stat-row > div { display: grid; }
.stat-row b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat-row span { font-size: 12px; color: var(--muted); }
.formula { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 8px; padding: 10px 12px; line-height: 1.7; }
.callout { padding: 12px 14px; border-radius: 8px; background: var(--info-bg); color: var(--text); border: 1px solid color-mix(in srgb, var(--info) 30%, transparent); }
.callout.warn { background: var(--high-bg); border-color: color-mix(in srgb, var(--high) 30%, transparent); }
.callout.crit { background: var(--crit-bg); border-color: color-mix(in srgb, var(--crit) 30%, transparent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--brand-2); font-weight: 600; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--faint); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart .line.dashed { stroke-dasharray: 5 4; }
.chart .area { opacity: .12; stroke: none; }
.chart .hist { stroke: var(--c-hist); fill: var(--c-hist); } .chart .fc { stroke: var(--c-fc); fill: var(--c-fc); }
.chart .fit { stroke: var(--c-fit); } .chart .proj { stroke: var(--c-proj); fill: var(--c-proj); }
.chart .hline { stroke: var(--crit); stroke-dasharray: 3 3; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .hline.ss { stroke: var(--high); } .chart .hline.rop { stroke: var(--crit); } .chart .hline.zero { stroke: var(--faint); stroke-dasharray: none; }
.chart .hlabel { font-size: 11px; fill: var(--crit); } .chart .hlabel.ss { fill: var(--high); } .chart .hlabel.zero { fill: var(--faint); }
.chart .marker { stroke: var(--faint); stroke-dasharray: 2 3; vector-effect: non-scaling-stroke; }
.chart .mlabel { font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend .sw { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 6px; }
.sw.hist { border-color: var(--c-hist); } .sw.fc { border-color: var(--c-fc); } .sw.fit { border-color: var(--c-fit); } .sw.proj { border-color: var(--c-proj); }
.sw.dashed { border-top-style: dashed; } .sw.hl { border-top: 1px dashed var(--crit); } .sw.hl.ss { border-color: var(--high); } .sw.hl.zero { border-color: var(--faint); border-top-style: solid; }
.spark { display: block; } .spark polyline { fill: none; stroke-width: 1.5; }
.spark .s-hist { stroke: var(--c-hist); } .spark .s-fc { stroke: var(--c-fc); stroke-dasharray: 3 2; }
.bars { display: grid; gap: 8px; }
.bars .row { display: grid; grid-template-columns: 130px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; }
.bars .bar { height: 14px; background: var(--muted-bg); border-radius: 4px; position: relative; overflow: hidden; }
.bars .bar > i { position: absolute; inset: 0 auto 0 0; background: var(--brand-2); border-radius: 4px; }
.bars .bar > i.x { background: var(--accent); }

/* ---------- container viz ---------- */
.box-viz { display: flex; gap: 10px; flex-wrap: wrap; }
.box-viz .cont { flex: 1 1 220px; border: 2px solid var(--border-strong); border-radius: 6px; padding: 8px; background: var(--surface-2); }
.box-viz .cont .fill { height: 26px; border-radius: 3px; background: var(--muted-bg); position: relative; overflow: hidden; margin: 6px 0; }
.box-viz .cont .fill i { position: absolute; inset: 0 auto 0 0; background: var(--brand-2); }
.box-viz .cont .fill i.top { background: var(--accent); }

/* ---------- scan ---------- */
.scan-input { font-size: 20px; padding: 12px 14px; width: 100%; font-family: var(--mono); }
.scan-feed { display: grid; gap: 8px; }
.scan-feed .hit { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.scan-feed .hit.ok { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-bg); }
.scan-feed .hit.err { border-color: color-mix(in srgb, var(--crit) 40%, transparent); background: var(--crit-bg); }
.video-wrap { position: relative; border-radius: 10px; overflow: hidden; background: #000; aspect-ratio: 4/3; max-height: 50vh; }
.video-wrap video { width: 100%; height: 100%; object-fit: cover; }
.video-wrap::after { content: ''; position: absolute; left: 10%; right: 10%; top: 50%; height: 2px; background: #f87171; box-shadow: 0 0 8px #f87171; }
.ctx-chip { display: inline-flex; gap: 6px; align-items: center; background: var(--muted-bg); padding: 4px 10px; border-radius: 99px; font-size: 13px; }
.pick-line { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.pick-line.done { opacity: .55; background: var(--ok-bg); }
.pick-line.current { border-color: var(--brand-2); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand-2) 25%, transparent); }
.bin-tag { font-family: var(--mono); font-weight: 700; font-size: 15px; background: var(--brand); color: var(--brand-ink); padding: 2px 8px; border-radius: 5px; }

/* ---------- dialogs / toasts ---------- */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog.wide { width: min(920px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 20, 18, .45); }
dialog header, dialog footer { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; gap: 8px; }
dialog header { border-bottom: 1px solid var(--border); }
dialog footer { border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-body { padding: 16px 18px; display: grid; gap: 12px; max-height: 70vh; overflow: auto; }
#toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; max-width: 380px; }
.toast.err { background: var(--crit); color: #fff; } .toast.out { opacity: 0; transform: translateY(6px); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); padding: 24px; display: grid; gap: 14px; }
.login .brand { padding: 0 0 8px; }
.login .err { color: var(--crit); margin: 0; min-height: 1em; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .g3 { grid-template-columns: 1fr 1fr; } .g-2-1 { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .menu { display: block; }
  .top { padding: 10px 16px; }
  #view { padding: 16px 16px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .bars .row { grid-template-columns: 90px 1fr 70px; }
}
@media print { .side, .top, .actions, .toolbar { display: none !important; } .app { display: block; } .card { box-shadow: none; } }

/* fixes */
.chart path.line { fill: none; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; }
.form-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid > .card, .grid > .kpis { margin-top: 0 !important; }
.formula { overflow-wrap: anywhere; }
h1.mono { font-size: 21px; }
