/* Theme: every colour is light-dark(<light>, <dark>). Which one applies follows `color-scheme`:
   "auto" = OS setting, data-theme="light"/"dark" on <html> = user choice from the header toggle.
   Severity colours are the validated ordinal sets for each surface (light and dark selected separately). */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
:root {
  --page: light-dark(#f9f9f7, #0d0d0d);
  --surface-1: light-dark(#fcfcfb, #1a1a19);
  --surface-2: light-dark(#f3f2ef, #232321);
  --text-primary: light-dark(#0b0b0b, #f0efec);
  --text-secondary: light-dark(#52514e, #c3c2b7);
  --text-muted: #898781;
  --grid: light-dark(#e1e0d9, #2c2c2a);
  --axis: light-dark(#c3c2b7, #383835);
  --border: light-dark(rgba(11, 11, 11, 0.10), rgba(255, 255, 255, 0.10));
  --accent: light-dark(#2a78d6, #3987e5);
  --accent-ink: #ffffff;
  --ok: light-dark(#006300, #0ca30c);
  --err: light-dark(#d03b3b, #e66767);
  --series-1: light-dark(#2a78d6, #3987e5);
  --sev-LOW: light-dark(#2a78d6, #3987e5);
  --sev-MEDIUM: light-dark(#eda100, #c98500);
  --sev-HIGH: light-dark(#e34948, #d03b3b);
  --sev-CRITICAL: light-dark(#6250d6, #9085e9);
  --sev-UNKNOWN: light-dark(#a3a29b, #6b6a65);
  --sev-NONE: var(--sev-UNKNOWN);
  --shadow: 0 1px 2px light-dark(rgba(0,0,0,.04), transparent), 0 4px 16px light-dark(rgba(0,0,0,.05), transparent);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text-primary); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
small, .muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- header */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
header h1 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
header h1 .logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  display: inline-grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; }
nav { display: flex; gap: 4px; }
nav button { background: none; border: 0; padding: 7px 12px; border-radius: 8px; color: var(--text-secondary);
  font: inherit; cursor: pointer; }
nav button:hover { background: var(--surface-2); }
nav button.active { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
#sync-indicator { margin-left: auto; font-size: 12px; color: var(--text-muted); display: flex; gap: 8px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--text-muted); }
.dot.run { background: var(--accent); animation: pulse 1.2s infinite; }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }

main { padding: 20px 24px 60px; max-width: 1500px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 16px; }

/* ---------------------------------------------------------------- cards */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- forms */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=url], input[type=email], input[type=password], select, textarea {
  background: var(--surface-1); border: 1px solid var(--axis); border-radius: 7px; padding: 6px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 12px; }
.btn { background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px; padding: 6px 12px;
  cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--err); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }

/* filter bar (one row, wraps) */
.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--text-secondary); }
.field.grow { flex: 1 1 220px; }
.score-range { display: flex; gap: 4px; align-items: center; }
.score-range input { width: 64px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--axis); background: var(--surface-1); cursor: pointer; font-size: 13px; user-select: none; }
.chip[aria-pressed=true] { background: var(--surface-2); border-color: var(--text-secondary); font-weight: 600; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; border: 1px solid var(--axis);
  border-radius: 7px; padding: 3px 5px; background: var(--surface-1); min-height: 33px; }
.tags input { border: 0 !important; outline: none !important; padding: 3px 4px; flex: 1; min-width: 90px; background: transparent; }
.tag { background: var(--surface-2); border-radius: 5px; padding: 1px 4px 1px 8px; display: inline-flex; gap: 4px; align-items: center; font-size: 13px; }
.tag button { border: 0; background: none; cursor: pointer; color: var(--text-muted); padding: 0 3px; }
.opts { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }

/* ---------------------------------------------------------------- KPI / figures */
.overview { display: grid; grid-template-columns: minmax(180px, auto) 1fr; gap: 24px; align-items: center; }
@media (max-width: 800px) { .overview { grid-template-columns: 1fr; } }
.hero .label { color: var(--text-secondary); font-size: 13px; }
.hero .value { font-size: 52px; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
.hero .sub { color: var(--text-muted); font-size: 12px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 800px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); }
.tile .label { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 24px; font-weight: 600; }
.segbar { display: flex; gap: 2px; height: 28px; margin-top: 14px; }
.segbar div { border-radius: 4px; display: flex; align-items: center; padding: 0 8px; color: #fff; font-size: 12px;
  font-weight: 600; overflow: hidden; white-space: nowrap; min-width: 0; }
.segbar div.dark-ink { color: #0b0b0b; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin-top: 8px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }

/* charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + g rect, .chart g.col:hover rect { filter: brightness(1.06); }
.chart .vlabel { fill: var(--text-secondary); }
.chart .vname { fill: var(--text-primary); font-size: 12px; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.14);
  min-width: 140px; }
.tooltip .t-head { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tooltip .t-row span:first-child { display: inline-flex; gap: 6px; align-items: center; color: var(--text-secondary); }
.empty { color: var(--text-muted); padding: 30px 0; text-align: center; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-secondary); padding: 8px; border-bottom: 1px solid var(--axis);
  white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
td.nowrap { white-space: nowrap; }
.sev { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.sev b { font-variant-numeric: tabular-nums; min-width: 2.2em; }
.src { font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--axis); color: var(--text-secondary); white-space: nowrap; }
.kev { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--err); color: #fff; font-weight: 600; }
.prod { color: var(--text-secondary); font-size: 13px; }
.desc { max-width: 560px; }
.desc .t { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.badge-ok { color: var(--ok); font-weight: 600; }
.badge-err { color: var(--err); font-weight: 600; }

/* ---------------------------------------------------------------- dialogs */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface-1); color: var(--text-primary);
  width: min(860px, 94vw); max-height: 90vh; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog .d-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface-1); z-index: 1; }
dialog .d-head h2 { font-size: 16px; flex: 1; }
dialog .d-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
dialog .d-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border);
  position: sticky; bottom: 0; background: var(--surface-1); }
.form-grid { display: grid; grid-template-columns: 170px 1fr; gap: 10px 14px; align-items: center; }
.form-grid > label { color: var(--text-secondary); font-size: 13px; }
.form-grid .hint { grid-column: 2; font-size: 12px; color: var(--text-muted); margin-top: -6px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0; }
legend { padding: 0 6px; font-size: 13px; color: var(--text-secondary); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv > div:nth-child(odd) { color: var(--text-secondary); }
.pre { white-space: pre-wrap; }
.preview-box { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13px; }

#toast { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
#toast div { background: var(--text-primary); color: var(--surface-1); padding: 10px 14px; border-radius: 8px; max-width: 420px;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); font-size: 13px; }
#toast div.err { background: var(--err); color: #fff; }

.source-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

/* ---------------------------------------------------------------- Django/HTMX additions */
header .user { font-size: 12px; color: var(--text-muted); display: flex; gap: 10px; align-items: center; }
header .user form { margin: 0; }
header .user button { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
nav a { padding: 7px 12px; border-radius: 8px; color: var(--text-secondary); text-decoration: none; }
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.messages li { padding: 10px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.messages li.error { border-color: var(--err); color: var(--err); }
.messages li.success { border-color: var(--ok); }
.errorlist { color: var(--err); margin: 2px 0 0; padding: 0; list-style: none; font-size: 12px; }
.helptext { font-size: 12px; color: var(--text-muted); }
.form-grid > div.ctl { display: flex; flex-direction: column; gap: 3px; }
.form-grid input[type=text], .form-grid input[type=url], .form-grid input[type=password], .form-grid input[type=email],
.form-grid select, .form-grid textarea { width: 100%; max-width: 560px; }
.form-grid input[type=number] { width: 110px; }
.inline-list { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0; padding: 0; list-style: none; }
.inline-list label { display: inline-flex; align-items: center; gap: 6px; }
.inline-list div { display: contents; }
/* chips = styled checkboxes */
.chips label.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chips label.chip:has(input:checked) { background: var(--surface-2); border-color: var(--text-secondary); font-weight: 600; }
.chips label.chip:has(input:focus-visible) { outline: 2px solid var(--accent); }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
#results.htmx-request { opacity: .6; transition: opacity .15s; }
.job { font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.login-card { max-width: 380px; margin: 80px auto; }
.login-card input { width: 100%; }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--axis); color: var(--text-secondary); white-space: nowrap; }
.pill.ok { border-color: var(--ok); color: var(--ok); }
.pill.err { border-color: var(--err); color: var(--err); }
.chart-svg { width: 100%; height: auto; }
.chart .t-sum { border-top: 1px solid var(--grid); margin-top: 4px; padding-top: 4px; }
.tooltip .t-sum { border-top: 1px solid var(--grid); margin-top: 4px; padding-top: 4px; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
a.btn { color: var(--text-primary); text-decoration: none !important; display: inline-block; } a.btn.primary { color: var(--accent-ink); }

/* theme toggle */
.theme-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.theme-toggle button { background: none; border: 0; padding: 3px 8px; font: inherit; font-size: 12px; color: var(--text-secondary); cursor: pointer; }
.theme-toggle button + button { border-left: 1px solid var(--border); }
.theme-toggle button[aria-pressed="true"] { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
.theme-toggle button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
