/* Tokens. Light is the base definition; dark is redefined under both the OS
   media query and the explicit toggle so neither can strand a color. */
:root {
  color-scheme: light;

  --plane:          #f9f9f7;
  --surface:        #fcfcfb;
  --surface-sunk:   #f2f2ee;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);

  /* Ordinal confidence ramp — one hue, light->dark, validated for this surface. */
  --conf-exact:  #184f95;
  --conf-high:   #256abf;
  --conf-medium: #3987e5;
  --conf-low:    #86b6ef;
  --conf-none:   #898781;

  /* Status palette — fixed, never themed. Always paired with an icon + label. */
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --accent: #2a78d6;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface:        #1a1a19;
    --surface-sunk:   #141413;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);

    --conf-exact:  #9ec5f4;
    --conf-high:   #6da7ec;
    --conf-medium: #3987e5;
    --conf-low:    #256abf;

    --accent: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface:        #1a1a19;
  --surface-sunk:   #141413;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);

  --conf-exact:  #9ec5f4;
  --conf-high:   #6da7ec;
  --conf-medium: #3987e5;
  --conf-low:    #256abf;

  --accent: #3987e5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.wrap {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

/* --- header --------------------------------------------------------------- */

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

h1 {
  font-size: 20px;
  font-weight: 650;
  margin: 0 0 2px;
  letter-spacing: -0.01em;
}

.subtitle { color: var(--text-secondary); margin: 0; font-size: 13px; }

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.theme-toggle:hover { color: var(--text-primary); }

/* --- panels --------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel + .panel { margin-top: 16px; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

h2 {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.hint { color: var(--text-muted); font-size: 12px; }

/* --- upload dropzone ------------------------------------------------------ */

.dropzone {
  border: 1px dashed var(--axis);
  border-radius: var(--radius);
  background: var(--surface-sunk);
  padding: 18px 16px;
  margin-bottom: 14px;
  cursor: pointer;
  text-align: center;
  transition: border-color 120ms, background 120ms;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); }
.dropzone.dragover {
  border-color: var(--accent);
  border-style: solid;
  background: var(--surface);
}
.dropzone.busy { opacity: 0.6; pointer-events: none; }

.dz-idle { display: flex; flex-direction: column; gap: 3px; }
.dz-idle strong { font-size: 14px; }
.dz-idle span { color: var(--text-muted); font-size: 12px; }

.dz-loaded {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}
.dz-name { font-weight: 600; }
.dz-meta { color: var(--text-secondary); font-size: 12.5px; }

button.ghost.small { padding: 4px 10px; font-size: 12px; }

@media (prefers-reduced-motion: reduce) { .dropzone { transition: none; } }

/* --- controls ------------------------------------------------------------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

select, input[type="text"], input[type="number"] {
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  min-width: 0;
}
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.check { flex-direction: row; align-items: center; gap: 6px; }
.check > label { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text-secondary); }

button.primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button.primary:disabled { opacity: 0.45; cursor: not-allowed; }

button.ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
}
button.ghost:hover:not(:disabled) { color: var(--text-primary); }
button.ghost:disabled { opacity: 0.45; cursor: not-allowed; }

/* --- KPI row -------------------------------------------------------------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.tile .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.tile .value { font-size: 28px; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.tile .sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.tile.hero .value { font-size: 44px; }

/* --- progress ------------------------------------------------------------- */

.progress-track {
  height: 6px;
  background: var(--surface-sunk);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 120ms linear;
}

.now-scanning {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
  min-height: 20px;
}
.pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.scanning .pulse { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) {
  .scanning .pulse { animation: none; }
  .progress-fill { transition: none; }
}

/* --- split layout --------------------------------------------------------- */

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

/* --- live feed ------------------------------------------------------------ */

.feed {
  height: 340px;
  overflow-y: auto;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  border-top: 1px solid var(--grid);
}

.feed-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 2px;
  border-bottom: 1px solid var(--grid);
}
.feed-row .idx { color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.feed-row .model { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-row .verdict { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.exact  { background: var(--conf-exact); }
.dot.high   { background: var(--conf-high); }
.dot.medium { background: var(--conf-medium); }
.dot.low    { background: var(--conf-low); }
.dot.none   { background: var(--conf-none); }

.feed-empty { padding: 24px 4px; color: var(--text-muted); font-family: system-ui, sans-serif; }

/* --- breakdown bars ------------------------------------------------------- */

.breakdown + .breakdown { margin-top: 18px; }
.breakdown h3 {
  font-size: 12px; font-weight: 600; margin: 0 0 8px;
  color: var(--text-secondary);
}

/* 2px surface gap between adjacent fills, per mark spec. */
.stack {
  display: flex;
  gap: 2px;
  height: 22px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-sunk);
}
.stack > span { min-width: 2px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-item .count { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.status-good     { background: var(--status-good); }
.status-warning  { background: var(--status-warning); }
.status-serious  { background: var(--status-serious); }
.status-critical { background: var(--status-critical); }
.status-unknown  { background: var(--conf-none); }

.conf-exact  { background: var(--conf-exact); }
.conf-high   { background: var(--conf-high); }
.conf-medium { background: var(--conf-medium); }
.conf-low    { background: var(--conf-low); }
.conf-none   { background: var(--conf-none); }

.empty-note { color: var(--text-muted); font-size: 12px; padding: 6px 0; }

/* --- results table -------------------------------------------------------- */

.table-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.table-tools .spacer { flex: 1 1 auto; }

.table-scroll { overflow-x: auto; max-height: 560px; overflow-y: auto; }

table { border-collapse: collapse; width: 100%; font-size: 12.5px; }

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 10px;
  border-bottom: 1px solid var(--axis);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th .arrow { color: var(--text-muted); font-size: 10px; }

tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
}
tbody tr:hover { background: var(--surface-sunk); }

td.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
td.date { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.wrap-name { max-width: 320px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.muted { color: var(--text-muted); }

a { color: var(--accent); }

.banner {
  border: 1px solid var(--border);
  border-left: 3px solid var(--status-critical);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}
.banner strong { color: var(--text-primary); }
.banner.hidden { display: none; }
