/* userdatacenter dashboard - design tokens + layout.
   Themes: data-theme="light" | "dark" | "auto" on <html>; "auto" follows
   prefers-color-scheme live. Components use tokens only, never literal colours.
   Chart palette: the validated categorical palette of the dataviz reference
   (8 slots, light and dark steps, colour follows the product, never its rank). */

:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f1ee;
  --text: #0b0b0b;
  --text-muted: #52514e;
  --border: #e1e0d9;
  --axis: #c3c2b7;
  --grid: #e1e0d9;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --row-hover: #eaf1fb;
  --ok: #006300;
  --warn: #8a5a00;
  --bad: #b3261e;
  --chip: #eceae4;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text: #f0efec;
  --text-muted: #c3c2b7;
  --border: #2c2c2a;
  --axis: #383835;
  --grid: #2c2c2a;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --row-hover: #1f2a3a;
  --ok: #0ca30c;
  --warn: #fab219;
  --bad: #e66767;
  --chip: #2c2c2a;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #0ca30c;
  --series-7: #9085e9;
  --series-8: #e66767;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #f0efec;
    --text-muted: #c3c2b7;
    --border: #2c2c2a;
    --axis: #383835;
    --grid: #2c2c2a;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --row-hover: #1f2a3a;
    --ok: #0ca30c;
    --warn: #fab219;
    --bad: #e66767;
    --chip: #2c2c2a;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #0ca30c;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
h1 { font-size: 1.35rem; margin: 0 0 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--text-muted); }
.small { font-size: 0.86rem; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem;
  padding: 0.6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.45rem; font-weight: 650; color: var(--text); text-decoration: none; }
.mainnav { display: flex; flex-wrap: wrap; gap: 0.15rem; flex: 1 1 auto; }
.mainnav a { padding: 0.35rem 0.6rem; border-radius: 6px; color: var(--text-muted); text-decoration: none; }
.mainnav a:hover { background: var(--surface-2); color: var(--text); }
.mainnav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.topbar-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.utc-badge { font-size: 0.78rem; padding: 0.15rem 0.5rem; border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); }
.whoami { color: var(--text-muted); font-size: 0.86rem; }
.theme-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.theme-switch button { border: 0; border-radius: 0; background: transparent; padding: 0.25rem 0.6rem; }
.theme-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

button, .button, select, input {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.35rem 0.65rem;
}
button, .button { cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { background: var(--surface-2); }
.button.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- page layout (fills wide screens) */
.page { flex: 1 1 auto; padding: 1rem; display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); align-content: start; }
.stack { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.grid-tiles { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(520px, 100%), 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; min-width: 0; }
.card.narrow { max-width: 34rem; }
.card-head { display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.center-page { align-items: center; justify-content: center; padding: 1rem; }
.footer { padding: 0.5rem 1rem; color: var(--text-muted); font-size: 0.8rem; border-top: 1px solid var(--border); }

.filters { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.82rem; color: var(--text-muted); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------------------------------------------------------------- tiles */
.tile-value { font-size: 2rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--text-muted); font-size: 0.82rem; }
.tile-breakdown { list-style: none; margin: 0.4rem 0 0; padding: 0; font-size: 0.86rem; }
.tile-breakdown li { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- help icon */
.help-btn {
  width: 1.3rem; height: 1.3rem; padding: 0; border-radius: 50%; font-size: 0.75rem; line-height: 1;
  color: var(--text-muted); background: transparent; display: inline-flex; align-items: center; justify-content: center;
}
.help-text { flex-basis: 100%; margin: 0.25rem 0 0.4rem; padding: 0.5rem 0.7rem; background: var(--surface-2); border-radius: 6px; font-size: 0.86rem; font-weight: 400; color: var(--text); }
.help-text p { margin: 0.15rem 0; }
th .help-text { position: static; white-space: normal; min-width: 14rem; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th, table.data td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-weight: 600; color: var(--text-muted); white-space: nowrap; }
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--row-hover); }
.sort-btn { border: 0; background: transparent; padding: 0; font-weight: 600; color: var(--text-muted); }
.sort-btn:hover { background: transparent; color: var(--text); }
th[aria-sort="ascending"] .sort-btn::after { content: " \25B2"; }
th[aria-sort="descending"] .sort-btn::after { content: " \25BC"; }
.th-inner { display: inline-flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }
.chip { display: inline-block; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--chip); font-size: 0.8rem; }
.chip.actor-admin, .chip.actor-service { background: var(--accent); color: var(--accent-ink); }
.outcome-failed, .outcome-denied, .status-failed { color: var(--bad); font-weight: 600; }
.status-pending { color: var(--warn); font-weight: 600; }
.status-accepted, .status-deduped { color: var(--ok); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

/* ---------------------------------------------------------------- states */
.state { margin: 0; padding: 1rem; border-radius: 8px; border: 1px dashed var(--border); color: var(--text-muted); }
.state-error { border-style: solid; border-color: var(--bad); color: var(--text); }
.state-error strong { color: var(--bad); }
.state-loading { border-style: dotted; }
.pager { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.75rem; }
.notice { padding: 0.5rem 0.75rem; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 4px; font-size: 0.86rem; }

/* ---------------------------------------------------------------- chart */
.chart-wrap { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; }
.s-1 { stroke: var(--series-1); fill: var(--series-1); }
.s-2 { stroke: var(--series-2); fill: var(--series-2); }
.s-3 { stroke: var(--series-3); fill: var(--series-3); }
.s-4 { stroke: var(--series-4); fill: var(--series-4); }
.s-5 { stroke: var(--series-5); fill: var(--series-5); }
.s-6 { stroke: var(--series-6); fill: var(--series-6); }
.s-7 { stroke: var(--series-7); fill: var(--series-7); }
.s-8 { stroke: var(--series-8); fill: var(--series-8); }
.chart .line.s-1, .chart .line.s-2, .chart .line.s-3, .chart .line.s-4,
.chart .line.s-5, .chart .line.s-6, .chart .line.s-7, .chart .line.s-8 { fill: none; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; align-items: center; }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; }
.legend-item[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
.swatch { width: 0.8rem; height: 0.8rem; border-radius: 3px; display: inline-block; }
.swatch.s-1 { background: var(--series-1); } .swatch.s-2 { background: var(--series-2); }
.swatch.s-3 { background: var(--series-3); } .swatch.s-4 { background: var(--series-4); }
.swatch.s-5 { background: var(--series-5); } .swatch.s-6 { background: var(--series-6); }
.swatch.s-7 { background: var(--series-7); } .swatch.s-8 { background: var(--series-8); }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.35rem 0.55rem; font-size: 0.8rem; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tooltip .tt-row { display: flex; gap: 0.6rem; justify-content: space-between; align-items: center; }

/* ---------------------------------------------------------------- help page */
.help-page dt { font-weight: 600; margin-top: 0.75rem; }
.help-page dd { margin: 0.2rem 0 0 0; color: var(--text); }

@media (max-width: 640px) {
  .page { padding: 0.6rem; }
  .tile-value { font-size: 1.6rem; }
}
