/* MoneyPilot Admin dashboard. Reuses the reference design tokens declared in login.css (:root).
   Light and dark: every colour below is a light-dark() pair. The page follows the OS setting;
   <html data-theme="light|dark"> forces one. */
:root {
  color-scheme: light dark;

  /* Ink and surfaces */
  --ink: light-dark(#1f1424, #f3edf5);
  --ink-2: light-dark(#4b3f52, #cdc2d3);
  --ink-3: light-dark(#74697a, #a596ab);
  --surface: light-dark(#ffffff, #1e1922);
  --surface-2: light-dark(#fbf8fc, #251f2a);
  --canvas: light-dark(#f6f2f8, #140f17);
  --line: light-dark(#e6dcea, #3a3040);
  --brand-ink: light-dark(#4a0e4c, #e2b9ec);
  --btn-bg: light-dark(#4a0e4c, #7a2f7e);
  --btn-bg-hover: light-dark(#631664, #8e4ba8);
  --ghost-hover: light-dark(#f2e9f5, #2e2434);
  --track: light-dark(#efe7f2, #2e2734);
  --skel-a: light-dark(#efe7f2, #262029);
  --skel-b: light-dark(#f7f2f9, #312a36);
  --focus: #f5a300;

  /* Status (text on the matching -bg, all >= 4.5:1) */
  --ok: light-dark(#1d7a46, #6fd39b);
  --warn: light-dark(#9a5b00, #f2b65a);
  --bad: light-dark(#b3261e, #ff978d);
  --ok-bg: light-dark(#e9f6ee, #163324);
  --warn-bg: light-dark(#fff6e5, #3a2a10);
  --bad-bg: light-dark(#fdeceb, #3d1a19);
  --off-bg: light-dark(#f2eef4, #2a2330);
  --warn-line: light-dark(#f0c983, #6b4c17);
  --bad-line: light-dark(#f2b8b5, #6e2e2b);

  /* Charts. Categorical slots 1-4 and the ordinal ramp are the dataviz reference palette,
     validated against these surfaces (scripts/validate_palette.js, light #ffffff, dark #1e1922). */
  --chart-surface: var(--surface);
  --chart-grid: light-dark(#ece5ef, #2f2834);
  --chart-axis: light-dark(#c9bccf, #4b4151);
  --chart-text: var(--ink-3);
  --chart-hover: light-dark(rgba(74, 14, 76, 0.06), rgba(255, 255, 255, 0.06));
  --series-1: light-dark(#2a78d6, #3987e5);
  --series-2: light-dark(#eb6834, #d95926);
  --series-3: light-dark(#1baf7a, #199e70);
  --series-4: light-dark(#eda100, #c98500);
  --ord-1: light-dark(#86b6ef, #184f95);
  --ord-2: light-dark(#5598e7, #256abf);
  --ord-3: light-dark(#2a78d6, #3987e5);
  --ord-4: light-dark(#1c5cab, #6da7ec);
  --ord-5: light-dark(#104281, #9ec5f4);
  --meter-track: light-dark(#cde2fb, #0d366b);
  --meter-fill: var(--series-1);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

[hidden] { display: none !important; }
html, body { height: 100%; }
body { background: var(--canvas); color: var(--ink); font-size: 15px; line-height: 1.5; }

.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

.sidebar {
  background: linear-gradient(180deg, var(--brand) 0%, var(--bg-grad-a) 100%);
  color: var(--white-90);
  padding: 24px 16px;
  display: flex; flex-direction: column; gap: 24px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--bg-grad-a);
  color: var(--gold); display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 600; font-size: 22px;
  border: 1px solid rgba(255,255,255,0.18);
}
.brand-name { font-family: var(--font-display); font-size: 22px; color: var(--white); }
.brand-name em { color: var(--gold); font-style: italic; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: var(--white-70); text-decoration: none; padding: 10px 12px; border-radius: var(--r-sm);
  transition: var(--t-fast); min-height: 44px; display: flex; align-items: center;
}
.nav a:hover { background: rgba(255,255,255,0.08); color: var(--white); }
.nav a[aria-current="page"] { background: rgba(255,255,255,0.14); color: var(--white); box-shadow: inset 3px 0 0 var(--gold); }
.privacy-note { margin-top: auto; font-size: 12px; color: var(--white-50); padding: 0 8px; }

.main { padding: 24px 32px 48px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 24px; }
.topbar h1 { font-family: var(--font-display); font-weight: 400; font-size: 32px; color: var(--brand-ink); }
.who { display: flex; align-items: center; gap: 12px; color: var(--ink-2); }

.view { transition: opacity 0.15s var(--ease); }
.view.is-refreshing { opacity: 0.55; pointer-events: none; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: 24px; }
.grid-charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 24px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); margin-bottom: 24px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px 20px; box-shadow: 0 1px 2px rgba(74,14,76,0.04); min-width: 0; }
.card h2 { font-size: 13px; font-weight: 500; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.card h3 { font-size: 16px; font-weight: 500; margin-bottom: 4px; color: var(--ink); }
.card h3 + .card-sub { margin-top: -2px; }
.card-sub { font-size: 13px; color: var(--ink-3); margin-bottom: 12px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
/* Stat-tile values use proportional figures; tabular-nums is for aligned columns only. */
.metric { font-size: 30px; font-weight: 500; color: var(--ink); line-height: 1.2; overflow-wrap: anywhere; }
.metric-sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.metric-row { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.metric-row .metric { font-size: 26px; }
.metric-row .metric-k { font-size: 12px; color: var(--ink-3); }
.tile-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.section { margin-bottom: 28px; }
.section > h2 { font-size: 18px; font-weight: 500; margin-bottom: 12px; color: var(--ink); }
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.section-head > h2 { font-size: 18px; font-weight: 500; color: var(--ink); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; border: 1px solid currentColor; text-transform: none; letter-spacing: 0; white-space: nowrap; }
.badge-estimate { color: var(--warn); background: var(--warn-bg); }
.badge-actual { color: var(--ok); background: var(--ok-bg); }
.badge-off { color: var(--ink-3); background: var(--off-bg); }
.badge-on { color: var(--ok); background: var(--ok-bg); }
.badge-blocked { color: var(--bad); background: var(--bad-bg); }
.badge-consent { color: var(--brand-ink); background: var(--ghost-hover); }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-3); font-weight: 500; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; max-width: 100%; }
/* Codes, routes, numbers and dates stay on one line; the table scrolls inside its wrapper instead. */
td.nowrap, td.mono { white-space: nowrap; }
td.wrap { min-width: 14em; }
.table-scroll .table-wrap { max-height: 440px; overflow: auto; border-radius: var(--r-md); border: 1px solid var(--line); }
.table-scroll table { overflow: visible; border: none; }
.table-scroll th { position: sticky; top: 0; z-index: 1; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

.bar { height: 10px; background: var(--track); border-radius: 999px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--bg-grad-a), var(--bg-grad-b)); }

.btn { font: inherit; font-weight: 500; border-radius: var(--r-sm); padding: 9px 16px; min-height: 40px; cursor: pointer; border: 1px solid var(--btn-bg); background: var(--btn-bg); color: var(--white); transition: var(--t-fast); }
.btn:hover:not(:disabled) { background: var(--btn-bg-hover); border-color: var(--btn-bg-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--brand-ink); border-color: var(--brand-ink); }
.btn-ghost:hover:not(:disabled) { background: var(--ghost-hover); border-color: var(--brand-ink); }
.btn-danger { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn-sm { padding: 5px 12px; min-height: 32px; font-size: 13px; }

form.inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
form.inline > label { min-width: 0; flex: 1 1 160px; }
form.inline > .btn { flex: 0 0 auto; }
form.inline > label.grow-2 { flex: 2 1 260px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
input, select, textarea { font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); min-height: 40px; min-width: 0; max-width: 100%; }
input[type="file"] { padding: 6px 8px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .nav a:focus-visible,
.seg-btn:focus-visible, .plot:focus-visible, .switch input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.field-help { font-size: 12px; color: var(--ink-3); }
.form-msg { font-size: 14px; margin-top: 10px; }
.form-msg:empty { display: none; }
.form-msg.is-bad { color: var(--bad); }
.form-msg.is-ok { color: var(--ok); }
.actions { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 12px; }
.switch { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); min-height: 40px; }
.switch input { width: 20px; height: 20px; min-height: 0; accent-color: var(--btn-bg); }

.notice { padding: 12px 16px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); margin-bottom: 16px; }
.notice-warn { border-color: var(--warn-line); background: var(--warn-bg); color: var(--ink); }
.notice-bad { border-color: var(--bad-line); background: var(--bad-bg); color: var(--bad); }
.notice-ok { border-color: var(--ok); background: var(--ok-bg); color: var(--ink); }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.empty { padding: 28px; text-align: center; color: var(--ink-3); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r-md); }
.card .empty { padding: 20px; border-color: var(--line); }
.skeleton { height: 96px; border-radius: var(--r-md); background: linear-gradient(90deg, var(--skel-a) 25%, var(--skel-b) 37%, var(--skel-a) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .auth-card { animation: none; } .view { transition: none; } }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
dl.kv dt { color: var(--ink-3); }
dl.kv dd { min-width: 0; overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ── Filters: one row above the content they scope ───────────────── */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 20px; }
.filters-label { font-size: 13px; color: var(--ink-3); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); padding: 2px; gap: 2px; }
.seg-btn { color: var(--ink-2); text-decoration: none; font-size: 14px; padding: 6px 12px; border-radius: 6px; min-height: 36px; display: inline-flex; align-items: center; white-space: nowrap; }
.seg-btn:hover { background: var(--ghost-hover); color: var(--ink); }
.seg-btn[aria-current="true"] { background: var(--btn-bg); color: var(--white); font-weight: 500; }
.seg-btn[aria-current="true"]::before { content: "✓"; font-weight: 700; margin-right: 6px; }
.filters select { min-height: 40px; }

/* ── Charts (SVG; colours only from the tokens above) ─────────────── */
.chart { min-width: 0; }
.plot { position: relative; width: 100%; border-radius: 6px; }
.plot svg { display: block; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 10px; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
.sw-1, .key-1, .tile-swatch.sw-1 { background: var(--series-1); }
.sw-2, .key-2 { background: var(--series-2); }
.sw-3, .key-3 { background: var(--series-3); }
.sw-4, .key-4 { background: var(--series-4); }
.legend-note { color: var(--ink-3); }
.chart-foot { display: flex; justify-content: flex-end; margin-top: 6px; }
.chart-table { margin-top: 10px; max-height: 360px; overflow: auto; }
.chart-note { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

.grid-line { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.axis-line { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.tick { fill: var(--chart-text); font-size: 12px; font-variant-numeric: tabular-nums; }
.dlabel { fill: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.rlabel { fill: var(--ink-2); font-size: 13px; }
.rvalue { fill: var(--ink); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area { stroke: none; opacity: 0.1; }
.dot { stroke: var(--chart-surface); stroke-width: 2; }
.crosshair { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.hover-band { fill: var(--chart-hover); }
.hit { fill: transparent; }
.fill-1 { fill: var(--series-1); } .stroke-1 { stroke: var(--series-1); }
.fill-2 { fill: var(--series-2); } .stroke-2 { stroke: var(--series-2); }
.fill-3 { fill: var(--series-3); } .stroke-3 { stroke: var(--series-3); }
.fill-4 { fill: var(--series-4); } .stroke-4 { stroke: var(--series-4); }
.fill-o1 { fill: var(--ord-1); } .fill-o2 { fill: var(--ord-2); } .fill-o3 { fill: var(--ord-3); }
.fill-o4 { fill: var(--ord-4); } .fill-o5 { fill: var(--ord-5); }
.meter-track { fill: var(--meter-track); }
.meter-fill { fill: var(--meter-fill); }

.tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 140px; max-width: 260px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: 0 6px 24px rgba(20, 8, 24, 0.16); padding: 8px 10px; font-size: 13px;
}
.tip-head { color: var(--ink-3); font-size: 12px; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tip-row strong { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 2.5em; }
.tip-row span:last-child { color: var(--ink-2); }
.key { display: inline-block; width: 12px; height: 2px; border-radius: 1px; flex: none; }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; gap: 16px; padding: 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { min-height: 40px; padding: 8px 10px; }
  .privacy-note { margin-top: 0; }
  .main { padding: 20px 16px 40px; }
}
@media (max-width: 480px) {
  .topbar h1 { font-size: 28px; }
  .card { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .metric { font-size: 24px; }
  .tile-wide { grid-column: 1 / -1; }
  th, td { padding: 8px 10px; }
  .seg-btn { padding: 6px 10px; }
}
@media (forced-colors: active) {
  .line, .crosshair { stroke: CanvasText; }
  .fill-1, .fill-2, .fill-3, .fill-4, .meter-fill { fill: CanvasText; }
}
