/* Palette follows the Rev B architecture diagram: slate-blue app, red for the Lead, green for async. */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2a33;
  --muted: #66737f;
  --line: #d9e0e6;
  --accent: #2f6f8f;
  --accent-soft: #dde9f0;
  --lead: #a8423a;
  --lead-soft: #f5e1de;
  --ok: #2f7a4f;
  --ok-soft: #e0f0e6;
  --warn: #9a6a00;
  --warn-soft: #fbefcf;
  --bad: #b3261e;
  --bad-soft: #fbe1df;
  --none-soft: #eceff2;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 4px 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.error { color: var(--bad); font-weight: 600; }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 14px; font-weight: 600; color: var(--ink); min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 46px; width: auto; display: block; flex: none; }
.brand-app { padding-left: 14px; border-left: 1px solid var(--line); font-size: 14px; line-height: 1.2; color: var(--muted); white-space: nowrap; }
@media (max-width: 1280px) { .brand-app { display: none; } }
.top nav { flex: 1; }
.who { font-size: 12px; color: var(--muted); }
.switcher select { font: inherit; margin-left: 4px; }

.banner { padding: 6px 20px; font-size: 13px; }
.banner-dev { background: var(--none-soft); color: var(--muted); }
.banner-dry { background: var(--warn-soft); color: var(--warn); }
.banner-warn { background: var(--warn-soft); color: var(--warn); margin: 0 0 12px; border-radius: 4px; }
.banner-live { background: var(--ok-soft); color: var(--ok); }
.banner-kill { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.banner form { margin-left: 8px; }
pre.comment { white-space: pre-wrap; font: 12px/1.45 "Segoe UI", system-ui, sans-serif; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; margin: 4px 0; max-width: 420px; }
.pill-sent { background: var(--ok-soft); color: var(--ok); }
.pill-halted { background: var(--bad-soft); color: var(--bad); }

main { padding: 16px 20px 96px; max-width: 1600px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(20, 40, 60, 0.04); }

.upload-form { display: flex; gap: 12px; align-items: stretch; margin: 12px 0 8px; flex-wrap: wrap; }
.drop { flex: 1; min-width: 260px; border: 2px dashed var(--line); border-radius: 6px; padding: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 4px; padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-lead { background: var(--lead); border-color: var(--lead); color: #fff; font-weight: 600; padding: 8px 18px; }
.btn-quiet { border-color: transparent; color: var(--muted); }
.btn-xs { padding: 2px 8px; font-size: 12px; }
form.inline { display: inline; }

.grid { width: 100%; border-collapse: collapse; background: var(--panel); }
.grid th, .grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid thead th { position: sticky; top: 0; background: #eef2f5; font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; color: var(--muted); z-index: 1; }
.table-wrap { border: 1px solid var(--line); border-radius: 6px; overflow: auto; max-height: calc(100vh - 230px); }
.lines td.desc { min-width: 240px; max-width: 340px; }
.lines td.task { min-width: 220px; max-width: 320px; }
.lines td.eta { white-space: nowrap; }
.batch-head th { background: var(--accent-soft); font-size: 12px; color: var(--accent); border-bottom: 1px solid var(--line); }
tr.row-discard td { opacity: 0.5; }
tr.row-pending td { background: #fffaf0; }
.empty { text-align: center; padding: 24px; }

.run-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: var(--none-soft); color: var(--muted); }
.pill-lg { font-size: 14px; padding: 4px 12px; }
.pill-ready { background: var(--accent-soft); color: var(--accent); }
.pill-approved, .pill-applying { background: var(--lead-soft); color: var(--lead); }
.pill-applied, .pill-written { background: var(--ok-soft); color: var(--ok); }
.pill-failed { background: var(--bad-soft); color: var(--bad); }
.pill-dry_run { background: var(--warn-soft); color: var(--warn); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; color: var(--ink); display: flex; flex-direction: column; }
.card:hover { text-decoration: none; border-color: var(--accent); }
.card.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card b { font-size: 22px; }
.card span { color: var(--muted); }
.card small { display: block; font-size: 11px; }
.card-attn b { color: var(--warn); }
.card-risk b { color: var(--bad); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.tabs a { padding: 5px 10px; border-radius: 4px; color: var(--muted); }
.tabs a.on { background: var(--accent); color: #fff; }
.tabs a .count { font-size: 11px; opacity: 0.8; }
.tabs input { margin-left: auto; font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; min-width: 240px; }

.risk, .dec, .mode { display: inline-block; padding: 1px 7px; border-radius: 3px; font-size: 12px; white-space: nowrap; }
.risk-ok { background: var(--ok-soft); color: var(--ok); }
.risk-warn { background: var(--warn-soft); color: var(--warn); }
.risk-bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.risk-none { background: var(--none-soft); color: var(--muted); }
.mode { background: var(--none-soft); color: var(--muted); font-size: 11px; }
.mode-ocean { background: var(--accent-soft); color: var(--accent); }
.dec-include { background: var(--ok-soft); color: var(--ok); }
.dec-pending { background: var(--warn-soft); color: var(--warn); }
.dec-discard { background: var(--none-soft); color: var(--muted); text-decoration: line-through; }
.dec-info { color: var(--muted); }
.delta { margin-left: 4px; font-size: 11px; font-weight: 600; }
.delta.late { color: var(--bad); }
.delta.early { color: var(--ok); }
.actions { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }
details.notes, details.cands { font-size: 12px; margin-top: 2px; }
details summary { cursor: pointer; color: var(--muted); }
details ul { margin: 4px 0; padding-left: 16px; }
.skipped ul { margin: 8px 0 0; }

.approve-bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--panel); border-top: 2px solid var(--lead); padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; gap: 16px; box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06); }
.approve-bar.done { border-top-color: var(--ok); color: var(--ok); }
.approve-actions { display: flex; gap: 8px; }

.events { list-style: none; padding: 0; margin: 0; }
.events li { padding: 3px 0; border-bottom: 1px dotted var(--line); }

.waiting { display: flex; align-items: center; gap: 12px; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-panel pre { white-space: pre-wrap; color: var(--bad); }

dialog { border: 1px solid var(--line); border-radius: 8px; padding: 16px; width: min(640px, 92vw); }
dialog::backdrop { background: rgba(20, 30, 40, 0.35); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
#link-q { width: 100%; font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 4px; }
.results { list-style: none; padding: 0; margin: 10px 0 0; max-height: 50vh; overflow: auto; }
.results li { padding: 8px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.results li .btn { grid-row: 1 / 3; grid-column: 2; align-self: center; }

.login { max-width: 360px; margin: 48px auto; padding: 0 16px; }
.login-logo { display: block; width: 100%; height: auto; margin: 0 0 24px; }
.login h1 { font-size: 18px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.login input { font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 4px; }

/* ---- header: brand | centred tabs | user ------------------------------------------- */
.top { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center; padding: 10px 24px; }
.top nav { flex: none; }
.top .who { justify-self: end; }
.tabs-main { display: inline-flex; gap: 4px; padding: 4px; background: #eef2f5; border: 1px solid var(--line); border-radius: 10px; }
.tabs-main .tab { display: inline-flex; align-items: center; gap: 8px; padding: 7px 18px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.tabs-main .tab svg { width: 16px; height: 16px; fill: none; stroke: currentColor; }
.tabs-main .tab svg.ico-fill { fill: currentColor; stroke: none; }
.tabs-main .tab:hover { color: var(--ink); text-decoration: none; background: rgba(255, 255, 255, 0.6); }
.tabs-main .tab.on { background: var(--panel); color: var(--accent); box-shadow: 0 1px 3px rgba(20, 40, 60, 0.12); }
@media (max-width: 900px) { .top { grid-template-columns: 1fr; justify-items: center; } .top .who { justify-self: center; } }

/* ---- data-viz tokens (reference palette, light) ---------------------------------------- */
.viz-root {
  --surface-1: #ffffff;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --tick-ink: #898781;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-ocean: #2a78d6; --series-air: #eb6834; --muted-mark: #c3c2b7;
  --stage-quote: #b7d3f6; --stage-vendor: #2a78d6; --stage-transit: #104281; --stage-received: #1baf7a;
  --status-critical: #d03b3b; --status-warning: #fab219; --status-good: #0ca30c;
}

/* ---- dashboard frame ------------------------------------------------------------------- */
.dash { max-width: 1440px; margin: 0 auto; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin: 4px 0 18px; }
.dash-head h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.2px; }
.dash-sub { margin: 0; color: var(--muted); font-size: 13px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--status-good); margin-right: 6px; box-shadow: 0 0 0 3px rgba(12, 163, 12, 0.18); vertical-align: 1px; }
.btn-refresh { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; font-weight: 600; border-radius: 8px; background: var(--panel); }
.btn-refresh svg { width: 16px; height: 16px; fill: none; stroke: currentColor; }
.btn-refresh:disabled { opacity: 0.5; cursor: not-allowed; }

.card-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(20, 40, 60, 0.04); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-hint { color: var(--muted); font-size: 12px; }
.card-foot { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.empty-state { text-align: center; padding: 48px 20px; }

/* ---- KPI tiles ------------------------------------------------------------------------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 16px 18px 16px 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); overflow: hidden; transition: box-shadow 0.15s, transform 0.15s; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--accent); }
a.kpi:hover { text-decoration: none; box-shadow: 0 4px 14px rgba(20, 40, 60, 0.10); transform: translateY(-1px); }
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 34px; font-weight: 700; line-height: 1.1; letter-spacing: -0.5px; }
.kpi-note { color: var(--muted); font-size: 12px; }
.kpi-bad::before { background: #d03b3b; }
.kpi-bad .kpi-value { color: #b3261e; }
.kpi-warn::before { background: #fab219; }
.kpi-warn .kpi-value { color: #8a5a00; }
.kpi-meter { display: block; height: 6px; border-radius: 3px; background: #f5dcda; overflow: hidden; margin: 2px 0; }
.kpi-meter span { display: block; height: 100%; background: #d03b3b; border-radius: 3px; }
.kpi-row.small .kpi { padding: 12px 16px 12px 20px; }
.kpi-row.small .kpi::before { background: var(--line); }
.kpi-row.small .kpi-warn::before { background: #fab219; }
.kpi-row.small .kpi-value { font-size: 22px; }
.status-ico { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; background: #d03b3b; color: #fff; font-size: 11px; font-weight: 800; flex: none; }
.status-ico.warn { background: #fab219; color: #0b0b0b; }
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---- chart grid ------------------------------------------------------------------------ */
.viz-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.viz-grid .card-panel { margin-bottom: 0; }
.viz-grid .span-2 { grid-column: span 2; }
.viz-grid + .card-panel { margin-top: 18px; }
@media (max-width: 1100px) { .viz-grid { grid-template-columns: 1fr; } .viz-grid .span-2 { grid-column: auto; } }

.chart { display: block; width: 100%; height: auto; font-family: inherit; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--tick-ink); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .cap { fill: var(--ink); font-size: 11.5px; font-weight: 600; }
.chart .row-label { fill: var(--ink); font-size: 12px; }
.chart a:hover .row-label { fill: var(--accent); text-decoration: underline; }
.chart .mark { cursor: pointer; transition: opacity 0.12s; }
.chart:hover .mark { opacity: 0.55; }
.chart .mark:hover, .chart .mark:focus { opacity: 1; outline: none; }
.donut .donut-total { font-size: 34px; font-weight: 700; fill: var(--ink); }
.donut .donut-label { font-size: 12px; fill: var(--muted); }
.donut-wrap { display: grid; grid-template-columns: 180px 1fr; gap: 18px; align-items: center; }
.donut-wrap .donut { max-width: 180px; }
@media (max-width: 1300px) and (min-width: 1101px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } }
.meter .track { fill: #eceff2; }
.meter .target { stroke: var(--ink); stroke-width: 2; }

.legend { display: inline-flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; width: 100%; }
.legend-list a { display: grid; grid-template-columns: 14px 1fr auto 40px; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--ink); font-size: 13px; }
.legend-list a:hover { background: var(--bg); text-decoration: none; }
.legend-list b { font-variant-numeric: tabular-nums; }
.legend-list small { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.sw-quote { background: #b7d3f6; }
.sw-vendor { background: #2a78d6; }
.sw-transit { background: #104281; }
.sw-received { background: #1baf7a; }
.sw-exception { background: #d03b3b; }
.sw-other { background: #c3c2b7; }

.perf { display: flex; flex-direction: column; gap: 18px; padding-top: 6px; }
.perf-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
.perf-head span { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.perf-head b { font-size: 26px; letter-spacing: -0.3px; }
.perf-note { color: var(--muted); font-size: 12px; }

.callout { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 10px; background: #fff6e0; border: 1px solid #f5dfa6; color: var(--ink); margin-bottom: 14px; font-size: 13px; }
.callout b { font-size: 26px; color: #8a5a00; }
.callout:hover { text-decoration: none; border-color: #eda100; }
.mini-head { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 0 0 8px; }
.exc-list { list-style: none; padding: 0; margin: 0 0 8px; }
.exc-list li { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.exc-list li a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--none-soft); color: var(--muted); white-space: nowrap; }
.chip-bad, .chip-exception { background: #fbe1df; color: #b3261e; }
.chip-warn { background: #fff1cc; color: #8a5a00; }
.chip-ok, .chip-received { background: #dcf3ea; color: #0b6b48; }
.chip-vendor { background: #dde9f8; color: #1c5cab; }
.chip-transit { background: #d6e1f0; color: #104281; }
.chip-quote { background: #eef4fc; color: #3a6ea8; }
.mode-air { background: #fde6dc; color: #a5401a; }

.orders-wrap { max-height: none; border-radius: 10px; }
.orders td.task { min-width: 260px; max-width: 380px; font-weight: 500; }
.late-cell { white-space: nowrap; }
.late-bar { display: inline-block; height: 8px; border-radius: 0 4px 4px 0; background: #d03b3b; vertical-align: middle; margin-right: 6px; }
.late-cell b { color: #b3261e; font-variant-numeric: tabular-nums; }

.dq { display: grid; grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr); gap: 24px; align-items: start; }
.dq-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dq-totals a { display: flex; flex-direction: column; padding: 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 12px; }
.dq-totals a:hover { text-decoration: none; border-color: var(--accent); }
.dq-totals b { font-size: 24px; color: var(--ink); }
@media (max-width: 900px) { .dq { grid-template-columns: 1fr; } }

details.table-view { margin-top: 8px; font-size: 12px; }
.grid.compact th, .grid.compact td { padding: 4px 8px; }

.viz-tip { position: fixed; z-index: 50; pointer-events: none; padding: 6px 10px; border-radius: 6px; background: #1f2a33; color: #fff; font-size: 12px; white-space: nowrap; opacity: 0; transform: translateY(4px); transition: opacity 0.1s, transform 0.1s; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18); }
.viz-tip.on { opacity: 1; transform: none; }
