:root {
  --bg: #0a0e13;
  --panel: #10161e;
  --panel-2: #141b25;
  --inset: #0b1017;
  --line: #1e2834;
  --line-2: #2a3644;
  --text: #e6edf3;
  --text-2: #a3b0bf;
  --text-3: #6b7888;
  --mint: #34d399;
  --mint-bg: #0b2b22;
  --mint-line: #145c45;
  --cyan: #38bdf8;
  --cyan-bg: #0b2536;
  --amber: #fbbf24;
  --amber-bg: #2b1f07;
  --amber-line: #6b4a0c;
  --red: #f87171;
  --red-bg: #2e1111;
  --indigo: #818cf8;
  --indigo-bg: #1a1c3d;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --r: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 72px;
}
a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: rgba(10, 14, 19, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 9px; background: var(--mint-bg); color: var(--mint);
  border: 1px solid var(--mint-line);
}
.brand-name { display: block; font-weight: 600; font-size: 15px; line-height: 1.1; }
.brand-sub { display: block; font: 11px var(--mono); color: var(--text-3); white-space: nowrap; }
@media (max-width: 560px) { #budget-pill { display: none; } }
.nav { display: none; gap: 4px; margin-left: 12px; }
.nav a { color: var(--text-2); padding: 6px 12px; border-radius: 8px; }
.nav a:hover { text-decoration: none; background: var(--panel-2); color: var(--text); }
.nav a.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--mint); }
.status { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font: 11px/1 var(--mono); padding: 6px 9px; border-radius: 999px;
  border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-ok { color: var(--mint); border-color: var(--mint-line); background: var(--mint-bg); }
.pill-warn { color: var(--amber); border-color: var(--amber-line); background: var(--amber-bg); }
.pill-bad { color: var(--red); border-color: #6b2222; background: var(--red-bg); }

/* ---- bottom tab bar (mobile) ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: rgba(10, 14, 19, 0.96); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 10px; color: var(--text-3); font: 11px var(--mono);
}
.tabbar a:hover { text-decoration: none; }
.tabbar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--mint); box-shadow: inset 0 2px 0 var(--mint); }

@media (min-width: 860px) {
  body { padding-bottom: 0; }
  .nav { display: flex; }
  .tabbar { display: none; }
}

/* ---- layout ---- */
.view { max-width: 1180px; margin: 0 auto; padding: 16px; outline: none; }
.banner {
  max-width: 1180px; margin: 12px auto 0; padding: 10px 14px;
  border: 1px solid #6b2222; background: var(--red-bg); color: #fecaca;
  border-radius: var(--r); font-size: 13px;
}
@media (min-width: 1212px) { .banner { margin: 12px auto 0; } }
@media (max-width: 1211px) { .banner { margin: 12px 16px 0; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
.page-head h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.page-head p { margin: 4px 0 0; color: var(--text-2); max-width: 640px; }

.grid-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .grid-2 { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; } }
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.sticky-col { position: sticky; top: 76px; }
@media (max-width: 959px) { .sticky-col { position: static; } }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px 16px; min-width: 0;
}
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 10px; }
.card-h h2, .card-h h3 { margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.eyebrow { font: 500 11px var(--mono); color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; margin: 0 0 6px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 8px 2px 0; }
.section-title h2 { font-size: 16px; font-weight: 600; margin: 0; }

.ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- form ---- */
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2);
  border-radius: 999px; padding: 6px 12px; font: 12px var(--mono); cursor: pointer;
}
.preset:hover { color: var(--text); border-color: var(--text-3); }
.preset.active { color: var(--mint); border-color: var(--mint-line); background: var(--mint-bg); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font: 500 11px var(--mono); color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.input, select.input, textarea.input {
  width: 100%; background: var(--inset); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 9px 11px; font-family: var(--mono); font-size: 13px;
}
textarea.input { resize: vertical; min-height: 72px; line-height: 1.5; }
.input:focus { outline: none; border-color: var(--mint); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15); }
.form-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); margin-top: 14px; }
@media (min-width: 640px) { .form-grid .two { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; } }
.form-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 9px; overflow: hidden; }
.seg button {
  background: transparent; border: 0; padding: 7px 12px; cursor: pointer;
  color: var(--text-2); font-size: 12.5px; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2;
}
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button small { font: 10.5px var(--mono); color: var(--text-3); }
.seg button.on { background: var(--mint-bg); color: var(--mint); }
.seg button.on small { color: #6ee7b7; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 9px; padding: 10px 18px; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text); cursor: pointer; font-weight: 500;
}
.btn:hover { border-color: var(--text-3); text-decoration: none; }
.btn-primary { background: var(--mint); border-color: var(--mint); color: #04261b; }
.btn-primary:hover { background: #4ade9f; border-color: #4ade9f; }
.btn[aria-busy="true"] { opacity: 0.7; cursor: progress; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.err { color: var(--red); font-size: 13px; margin: 0; }

/* ---- chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font: 11.5px/1 var(--mono); padding: 5px 8px; border-radius: 6px;
  border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap;
}
.chip-ev { background: var(--mint-bg); border-color: var(--mint-line); color: #a7f3d0; }
.chip-cx { border-style: dashed; color: var(--text-2); }
.chip-tag { color: var(--cyan); border-color: #164e63; background: var(--cyan-bg); }
.chip-dep { color: #c7d2fe; border-color: #3730a3; background: var(--indigo-bg); }
.chip-btn { cursor: pointer; background: transparent; }
.chip-btn.on { color: var(--mint); border-color: var(--mint-line); background: var(--mint-bg); }

.sev { font: 600 11px/1 var(--mono); padding: 4px 7px; border-radius: 5px; letter-spacing: 0.02em; }
.sev-SEV1 { background: var(--red-bg); color: var(--red); border: 1px solid #7f1d1d; }
.sev-SEV2 { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-line); }
.sev-SEV3 { background: #16202c; color: #a5b4c8; border: 1px solid var(--line-2); }

/* ---- normalisation ---- */
.norm { display: grid; gap: 8px; }
.norm-row { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 10px; align-items: start; }
.norm-row .eyebrow { margin: 3px 0 0; }
.norm-text { font: 12.5px/1.6 var(--mono); background: var(--inset); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; }
.norm-text del { color: var(--red); text-decoration-color: rgba(248, 113, 113, 0.7); background: rgba(248, 113, 113, 0.08); }
.norm-text mark, .code mark { color: #bae6fd; background: var(--cyan-bg); border: 1px solid #155e75; border-radius: 4px; padding: 0 3px; }
@media (max-width: 520px) { .norm-row { grid-template-columns: minmax(0, 1fr); gap: 4px; } }

/* ---- briefing ---- */
.briefing { border-color: #1d4b63; background: linear-gradient(180deg, #0f1b25, var(--panel)); }
.briefing p { margin: 0 0 8px; color: #d4dde6; }
.briefing p:last-child { margin: 0; }

/* ---- match card ---- */
.match { padding: 0; overflow: hidden; }
.match-top { display: flex; gap: 12px; padding: 14px 16px 10px; cursor: pointer; }
.match-main { flex: 1; min-width: 0; }
.match-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-3); }
.match-title { font-size: 16px; font-weight: 600; margin: 6px 0 4px; line-height: 1.35; }
.score { text-align: right; flex: none; }
.score b { display: block; font: 600 26px/1 var(--mono); color: var(--mint); }
.score span { font: 11px var(--mono); color: var(--text-3); }
.match-body { padding: 0 16px 14px; display: grid; gap: 12px; }
.match.collapsed .match-body { display: none; }
.match.collapsed .match-top { padding-bottom: 14px; }

.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--inset); border: 1px solid var(--line); }
.bar span { display: block; height: 100%; }
.b-signature { background: var(--mint); }
.b-tags { background: #22a37a; }
.b-same_service { background: var(--cyan); }
.b-dependency { background: #475569; }
.math { display: flex; flex-wrap: wrap; gap: 4px 14px; font: 12px var(--mono); color: var(--text-2); margin-top: 6px; }
.math i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; font-style: normal; }
.math em { font-style: normal; color: var(--text); }

.fix { background: var(--inset); border: 1px solid var(--line); border-left: 3px solid var(--mint); border-radius: 0 8px 8px 0; padding: 10px 12px; }
.fix .eyebrow { color: var(--mint); }
.fix p { margin: 0; }
.fix .by { margin-top: 6px; font: 11.5px var(--mono); color: var(--text-3); }
.kv-label { font: 11px var(--mono); color: var(--text-3); margin-right: 6px; }

/* ---- risk ---- */
.risk { border-color: var(--amber-line); background: linear-gradient(180deg, #1a1408, var(--panel) 60%); }
.risk h2 { color: var(--amber); }
.peer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.peer:first-of-type { border-top: 0; }
.peer-name { font: 500 13px var(--mono); }
.peer-sub { font-size: 12px; color: var(--text-3); }
.peer-count { font: 11.5px var(--mono); text-align: right; white-space: nowrap; }
.peer-count.zero { color: var(--amber); }
.risk-graph { width: 100%; height: auto; display: block; margin: 4px 0 8px; }

.weights { display: grid; gap: 6px; font: 12.5px var(--mono); }
.weights div { display: flex; justify-content: space-between; }
.weights b { color: var(--mint); font-weight: 500; }
.weights .dim, .weights .dim b { color: var(--text-3); }

/* ---- empty / loading ---- */
.empty { text-align: center; padding: 40px 16px; color: var(--text-2); }
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 16px; }
.skeleton { height: 120px; border-radius: var(--r); background: linear-gradient(90deg, var(--panel) 0%, var(--panel-2) 50%, var(--panel) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border: 1px solid var(--line); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- incidents ---- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .input { flex: 1 1 260px; }
.toolbar select.input { flex: 0 0 auto; width: auto; }
.families { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); margin-bottom: 16px; }
.family { cursor: pointer; text-align: left; transition: border-color 0.15s; }
.family:hover { border-color: var(--line-2); }
.family.on { border-color: var(--mint-line); background: linear-gradient(180deg, #0c2019, var(--panel)); }
.family h3 { margin: 0; font-size: 14px; font-weight: 600; }
.family .n { font: 600 20px var(--mono); color: var(--text); }
.family .stats { font-size: 12px; color: var(--text-3); margin-top: 6px; line-height: 1.6; }

.rows { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--panel); }
.rows-h { display: flex; justify-content: space-between; padding: 9px 14px; font: 11.5px var(--mono); color: var(--text-3); background: var(--panel-2); border-bottom: 1px solid var(--line); }
.row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 14px; border-top: 1px solid var(--line); color: var(--text); }
.row:first-of-type { border-top: 0; }
.row:hover { background: var(--panel-2); text-decoration: none; }
.row-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-right { text-align: right; font: 11.5px var(--mono); color: var(--text-3); white-space: nowrap; }

/* ---- detail ---- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; margin-bottom: 12px; }
.detail-title { font-size: 22px; font-weight: 600; margin: 8px 0 6px; letter-spacing: -0.01em; line-height: 1.3; }
.stats-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 16px 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; min-width: 0; }
.stat .v { font: 600 17px var(--mono); margin-top: 2px; overflow-wrap: anywhere; }
@media (max-width: 520px) { .stat .v { font-size: 14px; } }
.code { font: 12.5px/1.6 var(--mono); background: var(--inset); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: #bae6fd; overflow-wrap: anywhere; }
.resolution { border-color: var(--mint-line); }
.resolution .card-h h2 { color: var(--mint); }
.mini-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 13px; }
.mini-row:first-child { border-top: 0; }

/* ---- services ---- */
.graph-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.graph-wrap svg { display: block; min-width: 300px; max-width: 760px; width: 100%; height: auto; margin: 0 auto; }
.svc-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.svc-card { color: var(--text); }
.svc-card:hover { text-decoration: none; border-color: var(--line-2); }
.svc-card .name { font: 500 14px var(--mono); }
.svc-card .meta { font-size: 12px; color: var(--text-3); margin: 2px 0 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-3); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.foot-note { font-size: 12px; color: var(--text-3); margin: 6px 0 0; }
