:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;  /* blue */
  --series-2: #1baf7a;  /* aqua */
  --series-orange: #eb6834;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --delta-good: #006300;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #199e70;
    --series-orange: #d95926;
    --delta-good: #0ca30c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; gap: 16px; flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar .sub { color: var(--text-secondary); font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.fetched { color: var(--muted); font-size: 12px; }
.btn {
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 14px; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--baseline); }
.btn[disabled] { opacity: 0.6; cursor: wait; }

.error-banner {
  margin: 0 24px 12px; padding: 10px 14px; border-radius: 8px;
  background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1));
  border: 1px solid var(--status-critical); font-size: 13px;
}

main { padding: 0 24px 40px; display: flex; flex-direction: column; gap: 16px; }

.kpi-row {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, 225px);
  justify-content: start;
}
.group-title {
  margin: 14px 0 8px; font-size: 12px; font-weight: 650; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.group-title:first-child { margin-top: 0; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.tile .label { color: var(--text-secondary); font-size: 12px; margin-bottom: 6px; }
.tile .value { font-size: 28px; font-weight: 650; line-height: 1.1; }
.tile .detail { color: var(--muted); font-size: 12px; margin-top: 6px; }
.tile .detail .good { color: var(--delta-good); }
.tile .detail .bad { color: var(--status-critical); }
a.tile-link { display: block; text-decoration: none; color: inherit; }
a.tile-link:hover { border-color: var(--series-1); }
.tile-hint { color: var(--series-1); font-size: 12px; margin-top: 6px; }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px; min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card h2 { margin: 0 0 2px; font-size: 15px; }
.card-sub { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }

.suggest-line { margin: 10px 0; }
.suggest-toggle {
  background: none; border: none; cursor: pointer; padding: 4px 0;
  color: var(--series-1); font-size: 13px; font-weight: 600;
  font-family: inherit;
}
.suggest-toggle:hover { text-decoration: underline; }
.suggest-list {
  margin: 6px 0 4px; padding: 10px 16px 10px 30px;
  background: color-mix(in srgb, var(--series-1) 5%, var(--surface-1));
  border-left: 3px solid var(--series-1); border-radius: 0 8px 8px 0;
  color: var(--text-secondary); font-size: 13px; line-height: 1.7;
}

.flow-row { display: flex; gap: 6px; align-items: stretch; margin-top: 10px; }
.flow-step {
  flex: 1; min-width: 0; border: 1.5px solid var(--series-1); border-radius: 10px;
  padding: 10px 12px; background: color-mix(in srgb, var(--series-1) 7%, var(--surface-1));
  font-size: 12.5px;
}
.flow-step b { color: var(--series-1); display: block; margin-bottom: 5px; font-size: 13px; }
.flow-tiles { color: var(--text-secondary); line-height: 1.5; }
.flow-tiles a { color: var(--delta-good); text-decoration: none; font-style: italic; }
.flow-tiles a:hover { text-decoration: underline; }
.flow-arrow { align-self: center; color: var(--muted); font-size: 20px; flex: 0 0 auto; }
/* Return connector between flow rows: down from the last step of row 1,
   left across, then an arrowhead dropping into the first step of row 2. */
/* Action Items tile: red outline, red text, light grey interior. */
.tile.action-tile {
  border: 2px solid var(--status-critical);
  background: color-mix(in srgb, var(--muted) 14%, var(--surface-1));
}
.tile.action-tile .label,
.tile.action-tile .value,
.tile.action-tile .detail,
.tile.action-tile .tile-hint { color: var(--status-critical); }

/* Flow reconciliation box (top right of the order-flow card) and the outline
   on any KPI tile that isn't represented in the flow. */
.flow-recon { white-space: nowrap; padding: 6px 14px; border-radius: 999px; font-weight: 650; font-size: 13px; }
.flow-recon.ok { background: color-mix(in srgb, var(--status-good) 14%, var(--surface-1)); color: var(--status-good); border: 1px solid var(--status-good); }
.flow-recon.bad { background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1)); color: var(--status-warning); border: 1px solid var(--status-warning); cursor: help; }
.tile.not-in-flow { outline: 2px solid var(--status-warning); outline-offset: -1px; }

/* Return connector between flow rows: one continuous line down from the last
   step of row 1, across, and an arrowhead landing on the first step of row 2. */
.flow-return {
  display: block;
  width: 100%;
  height: 56px;
  margin: 2px 0;
  color: var(--muted);
}
.flow-note { color: var(--muted); font-size: 12px; margin-top: 12px; font-style: italic; }
.flow-note a { color: var(--delta-good); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 500;
  padding: 6px 10px; border-bottom: 1px solid var(--baseline); white-space: nowrap;
}
td {
  padding: 6px 10px; border-bottom: 1px solid var(--grid);
  vertical-align: top;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.sort-asc::after { content: ' ▲'; font-size: 9px; }
th.sort-desc::after { content: ' ▼'; font-size: 9px; }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; border: 1px solid var(--border);
}
.pill.late { border-color: var(--status-critical); color: var(--status-critical); }
.pill.open { border-color: var(--status-warning); }
