/* PSI Widget Analytics — one stylesheet, light + dark. Colours are tokens;
   chart series read the same tokens at draw time (app.js: token()). */
:root {
  color-scheme: light;
  --surface-0: #f4f4f1;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #272963;       /* PSI navy */
  --accent-ink: #ffffff;
  --brand-dot: #e25f26;    /* PSI orange */
  --grid: #e8e7e2;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --good: #1a7f37;
  --critical: #c62828;
  --focus: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #33332f;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #8f92e6;
    --accent-ink: #0b0b0b;
    --grid: #2c2c29;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --good: #4cc36a;
    --critical: #ef6b6b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #242422; --border: #33332f;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
  --accent: #8f92e6; --accent-ink: #0b0b0b; --grid: #2c2c29;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --good: #4cc36a; --critical: #ef6b6b;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-secondary); margin: 16px 0 6px; }
.muted, .hint { color: var(--text-secondary); }
.hint { font-size: 12.5px; margin: 0 0 10px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ── Top bar ── */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand-dot); }
.env-badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary);
}
.env-badge.prod { background: var(--accent); color: var(--accent-ink); }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs button {
  border: 0; background: none; color: var(--text-secondary); font: inherit; font-weight: 500;
  padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { background: var(--surface-2); }
.tabs button[aria-selected="true"] { color: var(--text-primary); background: var(--surface-2); }
.me { display: flex; align-items: center; gap: 10px; color: var(--text-secondary); font-size: 13px; }
.me form { margin: 0; }

/* ── Controls ── */
.btn {
  font: inherit; font-weight: 500; border-radius: 8px; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  text-decoration: none; display: inline-flex; align-items: center;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-ghost { background: none; }
.btn-ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.chip, .seg button {
  font: inherit; font-size: 13px; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary);
}
.chip[aria-pressed="true"], .seg button[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
}
.seg { display: inline-flex; gap: 4px; }
input, select {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}
label { color: var(--text-secondary); font-size: 13px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; }

.filterbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 12px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.filterbar label { display: inline-flex; align-items: center; gap: 6px; }
.presets { display: flex; gap: 6px; }
.status { color: var(--text-muted); font-size: 12.5px; margin-left: auto; }
.status.error { color: var(--critical); }

/* ── Layout ── */
main { padding: 20px 24px 48px; max-width: 1440px; margin: 0 auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; min-width: 0;
}
.tab > .card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin-right: auto; }
.card-head.standalone { margin-bottom: 14px; }
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 320px; }

/* ── Stat tiles ── */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.tile-label { color: var(--text-secondary); font-size: 12.5px; }
.tile-value { font-size: 26px; font-weight: 650; letter-spacing: -.01em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile-delta { font-size: 12px; color: var(--text-muted); }
.tile-delta.up::before { content: "▲ "; color: var(--good); }
.tile-delta.down::before { content: "▼ "; color: var(--critical); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
.table-wrap.short { max-height: 420px; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--text-secondary); font-weight: 500; font-size: 12.5px; position: sticky; top: 0; background: var(--surface-1); }
.table td.num, .table th.num { text-align: right; }
.table td.wrap { white-space: normal; max-width: 420px; overflow-wrap: anywhere; }
.table.compact th, .table.compact td { padding: 6px 8px; }
.table.mono td { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.table tbody tr:hover { background: var(--surface-2); }
.table .empty { color: var(--text-muted); text-align: center; padding: 24px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 10px; color: var(--text-secondary); }

/* ── Forms ── */
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; }
.form-msg { margin: 0; font-size: 13px; color: var(--text-secondary); }
.form-msg.error { color: var(--critical); }

/* ── Login ── */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px;
}
.login-card h1 { font-size: 22px; margin: 18px 0 4px; }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }
.login-card label { display: grid; gap: 4px; }
.login-error { color: var(--critical); margin: 12px 0 0; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .topbar, .filterbar { padding-left: 16px; padding-right: 16px; }
  main { padding: 16px 16px 40px; }
  .status { margin-left: 0; width: 100%; }
}
