/* Matchbox Security — UI stylesheet. No external fonts or frameworks (strict CSP). */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e3e6ea;
  --border-strong: #cfd4da;
  --text: #16191d;
  --text-2: #4a525c;
  --text-3: #636b76; /* ≥ 4.5:1 on white and on --surface-2 */
  --accent: #d9480f;
  --accent-ink: #ffffff;
  --link: #1f5fbf;

  --ok: #1f8a4c;       --ok-bg: #e5f5ec;
  --warn: #a15c00;     --warn-bg: #fdf1dc;
  --crit: #c4221f;     --crit-bg: #fde7e6;
  --low: #5a6b7d;      --low-bg: #eceff3;
  --info: #56606b;     --info-bg: #eef0f2;
  --progress: #1f5fbf; --progress-bg: #e6eefb;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #161a20; --surface-2: #1b2027; --border: #262c35; --border-strong: #353d48;
    --text: #e7eaee; --text-2: #aab2bd; --text-3: #7d8691; --link: #7fb0ff;
    --ok: #4cc27f; --ok-bg: #12291d; --warn: #f0b24a; --warn-bg: #2d2412; --crit: #ff6b64; --crit-bg: #331616;
    --low: #9aa9ba; --low-bg: #1f262e; --info: #9aa3ad; --info-bg: #1d2228; --progress: #7fb0ff; --progress-bg: #15233a;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #161a20; --surface-2: #1b2027; --border: #262c35; --border-strong: #353d48;
  --text: #e7eaee; --text-2: #aab2bd; --text-3: #7d8691; --link: #7fb0ff;
  --ok: #4cc27f; --ok-bg: #12291d; --warn: #f0b24a; --warn-bg: #2d2412; --crit: #ff6b64; --crit-bg: #331616;
  --low: #9aa9ba; --low-bg: #1f262e; --info: #9aa3ad; --info-bg: #1d2228; --progress: #7fb0ff; --progress-bg: #15233a;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
code, .mono, pre { font-family: var(--mono); font-size: 12.5px; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin: 0; max-height: 420px; overflow: auto; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; letter-spacing: .02em; }
.brand svg { flex: none; }
.brand small { display: block; font-weight: 500; color: var(--text-3); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; border-radius: var(--radius); color: var(--text-2); font-weight: 520; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav .count { font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 9px; background: var(--crit-bg); color: var(--crit); }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; font-size: 12.5px; color: var(--text-3); display: grid; gap: 8px; }
.sidebar-foot form { margin: 0; }
.main { min-width: 0; padding: 20px 28px 48px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .sub { color: var(--text-3); margin-top: 3px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn.menu-toggle { display: none; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .hd { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card > .bd { padding: 14px 16px; }
.card > .bd.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: grid; gap: 16px; align-content: start; }
.grid { align-items: start; }

/* KPI strip: one bordered row, not a pile of cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi { padding: 12px 16px; border-right: 1px solid var(--border); }
.kpi:last-child { border-right: 0; }
.kpi .label { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); }
.kpi .value { font-size: 24px; font-weight: 680; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .value.ok { color: var(--ok); } .kpi .value.warn { color: var(--warn); } .kpi .value.crit { color: var(--crit); }
.kpi .hint { font-size: 12px; color: var(--text-3); }

/* Critical banner — never hidden by healthy aggregates */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius); border: 1px solid; margin-bottom: 16px; }
.banner.crit { background: var(--crit-bg); border-color: color-mix(in srgb, var(--crit) 35%, transparent); color: var(--text); }
.banner.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.banner.info { background: var(--progress-bg); border-color: color-mix(in srgb, var(--progress) 30%, transparent); }
.banner strong { display: block; }
.banner .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--crit); margin-top: 6px; flex: none; }

/* ---------- Tables & lists ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px 16px; text-align: center; color: var(--text-3); }

.attention { list-style: none; margin: 0; padding: 0; }
.attention li { display: grid; grid-template-columns: 4px 1fr auto; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.attention li:last-child { border-bottom: 0; }
.attention .bar { align-self: stretch; border-radius: 2px; background: var(--border-strong); }
.attention .bar.critical { background: var(--crit); } .attention .bar.warning { background: var(--warn); }
.attention .site { font-weight: 600; }
.attention .reason { color: var(--text-2); font-size: 13px; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--text-3); font-size: 12.5px; }
dl.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.mono, code { overflow-wrap: anywhere; }
.grid > *, .stack > * { min-width: 0; }

/* Overview tiles on the site page */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tile { padding: 12px 16px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.tile .label { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); }
.tile .value { font-size: 16px; font-weight: 650; margin-top: 3px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline .day { padding: 12px 16px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .08em; color: var(--text-3); text-transform: uppercase; }
.timeline .ev { display: grid; grid-template-columns: 52px 10px 1fr; gap: 10px; padding: 6px 16px; align-items: baseline; }
.timeline .ev time { font-family: var(--mono); font-size: 12px; color: var(--text-3); }
.timeline .ev .mark { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); transform: translateY(1px); }
.timeline .ev .mark.sev-critical { background: var(--crit); } .timeline .ev .mark.sev-warning { background: var(--warn); } .timeline .ev .mark.sev-low { background: var(--low); }
.timeline .ev .detail { color: var(--text-3); font-size: 12.5px; white-space: pre-line; }
.timeline .ev .site-tag { color: var(--text-3); font-size: 12px; margin-left: 6px; }

/* ---------- Badges ---------- */
.badge, .pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 650; padding: 1px 8px; border-radius: 10px; white-space: nowrap; line-height: 18px; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.sev-critical { background: var(--crit-bg); color: var(--crit); }
.sev-warning  { background: var(--warn-bg); color: var(--warn); }
.sev-low      { background: var(--low-bg); color: var(--low); }
.sev-info     { background: var(--info-bg); color: var(--info); }
.health-healthy  { background: var(--ok-bg); color: var(--ok); }
.health-warning  { background: var(--warn-bg); color: var(--warn); }
.health-critical { background: var(--crit-bg); color: var(--crit); }
.health-unknown  { background: var(--info-bg); color: var(--info); }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-bad { background: var(--crit-bg); color: var(--crit); }
.pill-progress { background: var(--progress-bg); color: var(--progress); }
.pill-muted { background: var(--info-bg); color: var(--info); }
/* "open" is a workflow state, not a severity: keep it neutral so red keeps meaning. */
.pill-open { background: transparent; color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
.tag { font-size: 11px; font-weight: 600; padding: 0 6px; border: 1px solid var(--border-strong); border-radius: 4px; color: var(--text-2); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--text-2); font-weight: 560; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; gap: 6px; font: inherit; font-weight: 600; font-size: 13px; padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; line-height: 20px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, var(--border)); }
.btn.sm { padding: 3px 10px; font-size: 12.5px; min-height: 28px; }
@media (pointer: coarse) { .btn, .btn.sm { min-height: 44px; } }
.btn[aria-busy="true"] { cursor: progress; opacity: .75; }
.btn.link { border: 0; background: none; color: var(--link); padding: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; margin: 0; }
.form { display: grid; gap: 14px; max-width: 760px; }
.form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0; display: grid; gap: 12px; background: var(--surface); }
.form legend { font-weight: 650; padding: 0 6px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
label { display: grid; gap: 4px; font-weight: 560; font-size: 13px; }
/* Helper and error text render BELOW the control (CSS order), so inputs in one row stay aligned
   no matter how long each label's help text is. */
label .help { order: 3; font-weight: 400; color: var(--text-3); font-size: 12px; line-height: 1.4; }
label .error-text { order: 4; }
.row { align-items: start; }
.optional { font-weight: 400; color: var(--text-3); font-size: 12px; }
.actions select { width: auto; min-width: 150px; }
.scan-form { display: inline-flex; gap: 6px; align-items: center; }
.kv-list { display: flex; flex-wrap: wrap; gap: 4px; }
.kv-list .tag { font-family: var(--mono); font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 7px 10px; width: 100%;
}
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.error-text { color: var(--crit); font-size: 12px; font-weight: 500; }
.has-error input, .has-error textarea, .has-error select { border-color: var(--crit); }

/* ---------- Flash & misc ---------- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); }
.flash.success { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-bg); }
.flash.error { border-color: color-mix(in srgb, var(--crit) 40%, transparent); background: var(--crit-bg); }
.flash.info { border-color: color-mix(in srgb, var(--progress) 40%, transparent); background: var(--progress-bg); }
progress { width: 100%; height: 8px; appearance: none; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--progress); }
progress::-moz-progress-bar { background: var(--progress); }
.brand-mark { display: flex; gap: 10px; align-items: center; }
.auth .card.wide { max-width: 440px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.right { text-align: right; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.fingerprint { font-family: var(--mono); font-size: 13px; padding: 8px 10px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius); word-break: break-all; }
details > summary { cursor: pointer; color: var(--link); font-weight: 560; }
.pagination { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px; }
.sep { height: 1px; background: var(--border); margin: 12px 0; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; }
.auth .brand { justify-content: center; padding: 20px 0 4px; }

/* ---------- Report (print-friendly) ---------- */
.report { max-width: 900px; margin: 0 auto; padding: 32px 24px; background: var(--surface); }
.report h1 { font-size: 22px; }
.report section { margin-top: 24px; }
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .report { padding: 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .g-main, .g-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .sidebar .nav, .sidebar .sidebar-foot { display: none; }
  .sidebar.open .nav, .sidebar.open .sidebar-foot { display: grid; }
  .brand { padding: 0; justify-content: space-between; }
  .btn.menu-toggle { display: inline-flex; }
  .main { padding: 16px; }
  .g-2 { grid-template-columns: minmax(0, 1fr); }
  dl.facts { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  dl.facts dd { margin-bottom: 8px; }
  .kpi { border-bottom: 1px solid var(--border); }
  th, td { padding: 8px; }
  .timeline .ev { grid-template-columns: 44px 10px 1fr; padding: 6px 12px; }
}
