/* ---------------------------------------------------------------
   Tokens. Light values on bare :root; dark redefined under both the
   OS media query and an explicit [data-theme] stamp so the toggle
   wins in either direction.
   --------------------------------------------------------------- */
:root {
  color-scheme: light;

  --surface-0: #f7f7f5;
  --surface-1: #fcfcfb;
  --surface-2: #f1f1ee;
  --border:    #e2e2dd;
  --border-strong: #cfcfc8;

  --text-primary:   #191917;
  --text-secondary: #5c5b56;
  --text-muted:     #8a8a82;

  /* Validated categorical palette. Adjacent-pair order is load-bearing:
     human -> preview -> bot -> uncertain. Reordering can reintroduce the
     aqua/gray CVD collision the validator caught. */
  --c-human:     #1baf7a;
  --c-preview:   #eb6834;
  --c-bot:       #2a78d6;
  --c-uncertain: #9a9a95;

  /* Detail hues for the eight-class breakdown, where direct labels carry
     identity and colour only groups. */
  --c-verified:   #2a78d6;
  --c-declared:   #6da7ec;
  --c-spoofed:    #e34948;
  --c-automation: #4a3aa7;
  --c-likely:     #7fcfae;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --shadow-1: 0 1px 2px rgba(20,20,18,.05), 0 1px 1px rgba(20,20,18,.04);
  --shadow-2: 0 4px 16px rgba(20,20,18,.08), 0 1px 3px rgba(20,20,18,.05);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #141413;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border:    #32322e;
    --border-strong: #45453f;
    --text-primary:   #f2f2ee;
    --text-secondary: #b4b3ab;
    --text-muted:     #83837b;
    --c-human: #199e70; --c-preview: #d95926; --c-bot: #3987e5; --c-uncertain: #8a8a85;
    --c-verified: #3987e5; --c-declared: #86b6ef; --c-spoofed: #e66767;
    --c-automation: #9085e9; --c-likely: #5cbf95;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 4px 16px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #141413;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border:    #32322e;
  --border-strong: #45453f;
  --text-primary:   #f2f2ee;
  --text-secondary: #b4b3ab;
  --text-muted:     #83837b;
  --c-human: #199e70; --c-preview: #d95926; --c-bot: #3987e5; --c-uncertain: #8a8a85;
  --c-verified: #3987e5; --c-declared: #86b6ef; --c-spoofed: #e66767;
  --c-automation: #9085e9; --c-likely: #5cbf95;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 4px 16px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--c-bot); }

/* ---------------- login ---------------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login {
  width: 100%; max-width: 380px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 32px; box-shadow: var(--shadow-2);
}
.login h1 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.01em; }
.login .sub { margin: 0 0 24px; color: var(--text-secondary); font-size: 13px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
input[type=email], input[type=password], input[type=text], input[type=url], select {
  width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
  color: var(--text-primary); background: var(--surface-0);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus {
  outline: none; border-color: var(--c-bot);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-bot) 18%, transparent);
}
button {
  font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-primary); transition: background .12s, border-color .12s;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--c-bot); border-color: var(--c-bot); color: #fff; width: 100%; }
button.primary:hover { filter: brightness(1.07); }
button:disabled { opacity: .55; cursor: not-allowed; }
.error {
  margin-top: 14px; padding: 9px 12px; font-size: 13px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--c-spoofed) 12%, transparent);
  color: var(--c-spoofed); border: 1px solid color-mix(in srgb, var(--c-spoofed) 30%, transparent);
}

/* ---------------- app shell ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; letter-spacing: -.01em; font-size: 15px; margin-right: auto; }
.brand span { color: var(--text-muted); font-weight: 400; margin-left: 8px; font-size: 13px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.controls select { width: auto; padding: 6px 10px; font-size: 13px; }

main { padding: 24px; max-width: 1240px; margin: 0 auto; }
section { margin-bottom: 32px; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 4px; }
.section-note { margin: 0 0 16px; font-size: 13px; color: var(--text-secondary); max-width: 68ch; }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-1);
}

/* ---------------- stat tiles ---------------- */
.tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.tile { composes: card; background: var(--surface-1); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-1); }
.tile .k { font-size: 12px; font-weight: 600; color: var(--text-secondary); display: flex; align-items: center; gap: 7px; }
.tile .v { font-size: 30px; font-weight: 640; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .m { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ---------------- charts ---------------- */
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); }
.legend .li { display: flex; align-items: center; gap: 6px; }
svg { display: block; width: 100%; overflow: visible; }
.grid-line { stroke: var(--border); stroke-width: 1; }
.axis-text { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.bar-label { fill: var(--text-primary); font-size: 12px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.bar-sub { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }

.tooltip {
  position: fixed; z-index: 60; pointer-events: none; opacity: 0;
  transition: opacity .1s; background: var(--surface-1);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2); padding: 9px 11px; font-size: 12px; min-width: 150px;
}
.tooltip.on { opacity: 1; }
.tooltip .tt-t { font-weight: 620; margin-bottom: 6px; }
.tooltip .tt-r { display: flex; align-items: center; gap: 7px; justify-content: space-between; }
.tooltip .tt-r span:last-child { font-variant-numeric: tabular-nums; color: var(--text-secondary); }

/* ---------------- table ---------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 600; padding: 10px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  position: sticky; top: 0;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.row-click { cursor: pointer; }
tr.row-click:hover td { background: var(--surface-2); }
.mono { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px;
  border-radius: 999px; font-size: 12px; font-weight: 550; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--surface-2);
}
.pill .swatch { width: 7px; height: 7px; border-radius: 50%; }

.reasons { margin: 8px 0 0; padding: 0 0 0 16px; font-size: 12px; color: var(--text-secondary); }
.reasons li { margin: 2px 0; }

.empty { padding: 48px 24px; text-align: center; color: var(--text-muted); font-size: 14px; }
.muted { color: var(--text-muted); }
.foot { font-size: 12px; color: var(--text-muted); padding: 8px 0 40px; max-width: 76ch; }

@media (max-width: 720px) {
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .tile .v { font-size: 25px; }
}
