/* FreightSetu Founder Console. Palette: dataviz reference instance (validated). */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --up: #006300;
  --down: #b42323;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-bg: #e6f4e6; --warn-bg: #fdf3dc; --bad-bg: #fbe7e7;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --up: #0ca30c; --down: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-bg: #13301a; --warn-bg: #36290b; --bad-bg: #3a1616;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --up: #0ca30c; --down: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-bg: #13301a; --warn-bg: #36290b; --bad-bg: #3a1616;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; margin: 0 6px 18px; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 7px; color: var(--ink-2); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.nav .count { font-size: 11px; background: var(--critical); color: #fff; border-radius: 9px; padding: 0 6px; font-weight: 600; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 6px; }
.sidebar form { margin: 0; }
.main { padding: 20px 28px 48px; min-width: 0; }
.topbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.topbar .meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--muted); font-size: 12px; }
.page-head { margin-bottom: 18px; }
.page-head p { margin: 0; color: var(--ink-2); }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.section { margin-top: 22px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile .label { color: var(--ink-2); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin: 2px 0; line-height: 1.2; overflow-wrap: anywhere; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile .spark { height: 34px; margin-top: 6px; }
.delta { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }

/* ---------- badges (status = icon + label, never color alone) ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 10px; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.badge::before { font-size: 10px; }
.badge.good { background: var(--good-bg); color: var(--up); }
.badge.good::before { content: "●"; color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--ink); }
.badge.warn::before { content: "▲"; color: var(--warning); }
.badge.bad { background: var(--bad-bg); color: var(--down); }
.badge.bad::before { content: "■"; color: var(--critical); }
.sev-1::before { content: "!!"; }
.health { display: inline-flex; gap: 6px; align-items: center; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
th a { color: inherit; }
td { padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:hover td { background: var(--surface-2); }
.empty { color: var(--muted); padding: 18px; text-align: center; }

/* ---------- charts ---------- */
.chart { position: relative; height: 240px; }
.chart.tall { height: 320px; }
.chart.short { height: 180px; }
.chart-table { margin-top: 8px; font-size: 12px; }
.chart-table summary { cursor: pointer; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.bar-row { display: grid; grid-template-columns: 180px 1fr 70px; gap: 10px; align-items: center; padding: 4px 0; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--s1); border-radius: 5px; }

.cohort td { text-align: center; font-variant-numeric: tabular-nums; font-size: 12px; }
.heat-0 { background: transparent; } .heat-1 { background: #cde2fb; } .heat-2 { background: #9ec5f4; }
.heat-3 { background: #6da7ec; color: #0b0b0b; } .heat-4 { background: #3987e5; color: #fff; } .heat-5 { background: #1c5cab; color: #fff; }

/* ---------- action items ---------- */
.action { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--grid); }
.action:last-child { border-bottom: 0; }
.action .title { font-weight: 600; }
.action .reason { color: var(--ink-2); font-size: 13px; }
.action .todo { font-size: 13px; margin-top: 2px; }
.action .todo::before { content: "→ "; color: var(--muted); }
.action .btns { display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; }

/* ---------- forms & buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); padding: 6px 12px; border-radius: 7px; font: inherit; font-size: 13px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
input, select, textarea { font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--axis); border-radius: 7px; padding: 7px 9px; width: 100%; }
textarea { min-height: 70px; }
label { display: block; font-size: 12px; color: var(--ink-2); font-weight: 600; }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; }
.stack { display: grid; gap: 12px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.toggle input { width: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters a { padding: 3px 10px; border-radius: 14px; border: 1px solid var(--border); color: var(--ink-2); font-size: 12px; }
.filters a.on { background: var(--ink); color: var(--surface); border-color: transparent; }

/* ---------- alerts ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-warn { background: var(--warn-bg); }
.alert-bad { background: var(--bad-bg); color: var(--down); }
.alert-info { background: var(--surface-2); color: var(--ink-2); }
.messages { list-style: none; padding: 0; margin: 0 0 14px; }
.messages li { padding: 8px 12px; border-radius: 8px; background: var(--good-bg); margin-bottom: 6px; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 4px 0; display: flex; justify-content: space-between; gap: 10px; }
.checklist .done > span:first-child::before { content: "✓ "; color: var(--good); font-weight: 700; }
.checklist .pending > span:first-child::before { content: "○ "; color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--grid); }
.timeline li { padding: 4px 0 10px 14px; position: relative; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--s1); border: 2px solid var(--surface); }

/* ---------- auth ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.auth-card .brand { margin: 0 0 18px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 9px; }
.qr { background: #fff; padding: 12px; border-radius: 8px; width: fit-content; margin: 12px auto; }
.qr svg { display: block; width: 200px; height: 200px; }
.secret { display: block; word-break: break-all; margin: 6px 0 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .nav { display: flex; overflow-x: auto; gap: 2px; }
  .nav a { white-space: nowrap; }
  .nav-sep, .sidebar .brand { display: none; }
  .main { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .bar-row { grid-template-columns: 110px 1fr 56px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile .value { font-size: 21px; }
  .action { grid-template-columns: 1fr; }
}

/* ---------- help ---------- */
.help-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 24px; align-items: start; }
.toc { position: sticky; top: 16px; font-size: 13px; max-height: calc(100vh - 32px); overflow-y: auto; }
.toc a { display: block; padding: 3px 8px; color: var(--ink-2); border-radius: 6px; }
.toc a:hover { background: var(--surface-2); text-decoration: none; }
.toc .toc-h { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; margin: 12px 8px 4px; }
.help h2 { font-size: 18px; margin: 34px 0 6px; padding-top: 6px; scroll-margin-top: 12px; }
.help h2:first-child { margin-top: 0; }
.help > p, .help .lead { color: var(--ink-2); max-width: 820px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; scroll-margin-top: 12px; }
.metric h3 { text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 14.5px; margin: 0 0 4px; }
.metric p { margin: 4px 0; }
.metric dl { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px 14px; margin: 10px 0 0; font-size: 13px; }
.metric dt { color: var(--muted); font-weight: 600; }
.metric dd { margin: 0; }
.formula { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); padding: 7px 10px; border-radius: 6px; white-space: pre-wrap; display: block; }
.example { background: var(--good-bg); padding: 7px 10px; border-radius: 6px; }
.caveat { background: var(--warn-bg); padding: 7px 10px; border-radius: 6px; }
.help table { margin: 8px 0; }
.help ul { margin: 6px 0; padding-left: 20px; }
.help-link { font-size: 12px; }
@media (max-width: 860px) { .help-layout { grid-template-columns: 1fr; } .toc { position: static; max-height: none; } .metric dl { grid-template-columns: 1fr; } }
