:root {
  color-scheme: dark;
  --bg: #161616;
  --surface-1: #1f1f1f;
  --surface-2: #2a2a29;
  --hairline: #333332;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --brand: #a01d2b;
  --brand-bright: #d0344a;
  --series-1: #3987e5;   /* categorical slot 1 (blue) */
  --series-2: #d95926;   /* categorical slot 2 (orange) */
  --baseline: #8f8e86;   /* reference line: neutral, not a series */
  --div-pos: #3987e5;    /* diverging: profit */
  --div-neg: #e66767;    /* diverging: loss */
  --div-mid: #383835;
  --good: #0ca30c;
  --critical: #d03b3b;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text-primary); }
body { font: 15px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif; }
a { color: var(--text-primary); text-decoration-color: var(--brand-bright); text-underline-offset: 3px; }
button { font: inherit; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }

/* header + tabs */
header.top { border-bottom: 3px solid var(--brand); background: #121212; }
header.top .bar { display: flex; align-items: center; gap: 14px; padding-top: 14px; padding-bottom: 10px; }
header.top img { width: 44px; height: auto; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand-name .camp { color: var(--brand-bright); }
.brand-sub { color: var(--text-secondary); font-size: 13px; }
.spacer { flex: 1; }
.lang { display: flex; border: 1px solid var(--hairline); border-radius: 999px; overflow: hidden; }
.lang button { background: none; border: 0; color: var(--text-secondary); padding: 6px 12px; font-size: 13px; cursor: pointer; }
.lang button[aria-pressed="true"] { background: var(--brand); color: #fff; }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; }
nav.tabs a { color: var(--text-secondary); text-decoration: none; padding: 8px 14px; border-radius: 8px 8px 0 0; font-size: 14px; font-weight: 500; white-space: nowrap; }
nav.tabs a[aria-current="page"] { color: #fff; background: var(--brand); }
nav.tabs a:hover:not([aria-current="page"]) { color: #fff; background: var(--surface-1); }

.hero { padding: 28px 0 8px; }
.hero h1 { font-size: clamp(24px, 4vw, 34px); line-height: 1.15; margin: 0 0 10px; max-width: 820px; }
.hero p { color: var(--text-secondary); max-width: 760px; margin: 0; }
.badge { display: inline-block; font-size: 12px; color: var(--text-secondary); border: 1px solid var(--hairline); border-radius: 999px; padding: 2px 10px; margin-bottom: 12px; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 22px 0 18px; padding: 12px; background: var(--surface-1); border-radius: var(--radius); position: sticky; top: 0; z-index: 5; border: 1px solid var(--hairline); }
.filters label, .field { display: flex; flex-direction: column; font-size: 12px; color: var(--text-muted); gap: 4px; }
select, input[type="search"], input[type="number"] { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--hairline); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 14px; min-width: 140px; }
.filters .chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-left: auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--hairline); color: var(--text-secondary); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.chip:hover { border-color: var(--brand-bright); color: #fff; }
.btn { background: none; color: var(--text-secondary); border: 1px solid var(--hairline); border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { color: #fff; border-color: var(--text-muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-bright); border-color: var(--brand-bright); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.kpi { background: var(--surface-1); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--text-secondary); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .note { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.findings { margin: 18px 0 0; background: var(--surface-1); border: 1px solid var(--hairline); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 14px 18px; }
.findings h2 { font-size: 15px; margin: 0 0 6px; }
.findings ul { margin: 0; padding-left: 18px; color: var(--text-secondary); }
.findings li { margin: 4px 0; }
.findings b { color: var(--text-primary); font-weight: 600; }

/* cards + charts */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.card { background: var(--surface-1); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card h2 { font-size: 16px; margin: 0; }
.card .sub { color: var(--text-secondary); font-size: 13px; margin: 2px 0 10px; }
.card .hint { color: var(--text-muted); font-size: 12px; margin: 6px 0 0; }
.card-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; flex-wrap: wrap; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend .ln { display: inline-block; width: 16px; height: 2px; margin-right: 6px; vertical-align: 3px; }
.legend .bar { display: inline-block; width: 36px; height: 10px; border-radius: 3px; margin: 0 6px; vertical-align: -1px; background: linear-gradient(90deg, var(--div-neg), var(--div-mid), var(--div-pos)); }
svg { display: block; width: 100%; height: auto; overflow: visible; }
svg text { fill: var(--text-muted); font-size: 11px; font-family: inherit; }
svg .grid-line { stroke: var(--hairline); stroke-width: 1; }
svg .axis-label { fill: var(--text-secondary); }
svg .cell-text { fill: var(--text-primary); font-size: 12px; font-weight: 600; }
svg .cell-n { fill: var(--text-secondary); font-size: 10px; }
svg .clickable { cursor: pointer; }

.stat-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.stat .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--text-secondary); }
.explain { color: var(--text-secondary); font-size: 13px; margin-top: 12px; }

/* tables */
.seg { display: inline-flex; }
.seg button { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--hairline); padding: 6px 12px; font-size: 13px; cursor: pointer; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface-1); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: #fff; }
th .dir { color: var(--brand-bright); margin-left: 4px; }
td.num, th.num { text-align: right; }
td.lookup { color: var(--text-secondary); }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: var(--surface-2); }
.pos { color: #6fb0ff; }
.neg { color: #ff8a8a; }

/* drill-down drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100%); background: var(--bg); border-left: 3px solid var(--brand); z-index: 31; overflow-y: auto; padding: 18px 20px 28px; }
.drawer h2 { margin: 0; font-size: 20px; line-height: 1.25; }
.drawer .meta { color: var(--text-secondary); font-size: 13px; margin: 4px 0 14px; }
.drawer .close { position: sticky; top: 0; float: right; background: var(--surface-1); border: 1px solid var(--hairline); color: var(--text-primary); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 18px; line-height: 1; }
.drawer section { margin-top: 18px; }
.drawer h3 { font-size: 14px; margin: 0 0 6px; }
.pnl { width: 100%; }
.pnl td { white-space: normal; }
.pnl tr.total td { font-weight: 700; border-top: 2px solid var(--hairline); }
.drawer .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* simulator */
.sim { display: grid; grid-template-columns: 340px 1fr; gap: 16px; margin-top: 20px; }
.sim > * { min-width: 0; }
.sim-form { display: flex; flex-direction: column; gap: 14px; }
.sim-form select { width: 100%; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--brand-bright); }
.range-row output { min-width: 48px; text-align: right; font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.verdict { display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600; }
.verdict.good { background: rgba(12,163,12,.15); color: #6bdc6b; }
.verdict.bad { background: rgba(208,59,59,.15); color: #ff8a8a; }
.sim-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.assumptions { color: var(--text-secondary); font-size: 13px; margin: 0; padding-left: 18px; }
.assumptions li { margin: 3px 0; }

/* data explorer */
.data-tables { display: flex; gap: 6px; flex-wrap: wrap; margin: 20px 0 12px; }
.pill { background: var(--surface-1); color: var(--text-secondary); border: 1px solid var(--hairline); border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.pill[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.data-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 12px; }
.data-tools .grow { flex: 1; min-width: 200px; }
.data-tools .grow input { width: 100%; }
.data-desc { color: var(--text-secondary); font-size: 13px; margin: 0 0 12px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 10px; color: var(--text-muted); font-size: 13px; flex-wrap: wrap; }
.dictionary { margin-top: 12px; }
.dictionary summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.dictionary dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; margin: 10px 0 0; }
.dictionary dt { font-family: ui-monospace, Menlo, monospace; color: var(--text-primary); }
.dictionary dd { margin: 0; color: var(--text-secondary); }

.tooltip { position: fixed; pointer-events: none; background: #0d0d0d; border: 1px solid var(--hairline); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--text-primary); max-width: 280px; z-index: 40; opacity: 0; transition: opacity .1s; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.tooltip .t { font-weight: 600; margin-bottom: 2px; }
.tooltip .r { color: var(--text-secondary); }

footer { color: var(--text-muted); font-size: 13px; padding: 28px 0 40px; border-top: 1px solid var(--hairline); margin-top: 28px; }
footer p { margin: 4px 0; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid, .sim { grid-template-columns: 1fr; }
  .filters { position: static; }
  .filters .chips { margin-left: 0; }
}
@media (max-width: 600px) {
  .chart-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
  .chart-scroll svg { min-width: 560px; }
  .sim-kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .filters label, .filters select { width: 100%; }
  .brand-sub { display: none; }
}

/* fill rate additions */
:root {
  --cause-capacity: #3987e5;
  --cause-forecast_error: #d95926;
  --cause-unannounced_promo: #199e70;
  --cause-quality_hold: #c98500;
  --cause-master_data: #d55181;
  --short: #e66767;      /* sequential end for shortfall magnitude */
}
.kpis { grid-template-columns: repeat(6, 1fr); }
.kpi .value.bad { color: #ff8a8a; }
.kpi .note .flag { color: #ff8a8a; font-weight: 600; }
.kpi .note .ok { color: #6bdc6b; font-weight: 600; }
.legend .dash { display: inline-block; width: 16px; height: 0; border-top: 2px dashed var(--baseline); margin-right: 6px; vertical-align: 3px; }
.legend .seq { display: inline-block; width: 60px; height: 10px; border-radius: 3px; margin: 0 6px; vertical-align: -1px; background: linear-gradient(90deg, var(--div-mid), var(--short)); }
.cause-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.matrix td.num { font-weight: 500; }
.matrix th:first-child, .matrix td:first-child { white-space: normal; }
.monitor-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 22px 0 18px; padding: 12px; background: var(--surface-1); border-radius: var(--radius); border: 1px solid var(--hairline); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.status-pill.bad { background: rgba(208,59,59,.15); color: #ff8a8a; }
.status-pill.ok { background: rgba(12,163,12,.15); color: #6bdc6b; }
td svg.spark { width: 90px; height: 26px; display: inline-block; vertical-align: middle; }
.cover-low { color: #ff8a8a; font-weight: 600; }
.util { display: inline-block; height: 8px; border-radius: 4px; background: var(--series-1); vertical-align: middle; margin-right: 8px; }
.util.full { background: var(--critical); }
.drawer .kpis { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) and (min-width: 901px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } .kpi { min-width: 0; } }
.matrix th, .matrix td { padding: 7px 6px; font-size: 12px; }
#alert-table td:nth-child(1), #alert-table td:nth-child(2) { white-space: normal; min-width: 140px; }
#alert-table th, #alert-table td { padding: 8px 7px; }
