:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #0f1b2d;
  --muted: #5b6678;
  --line: #dde3ec;
  --accent: #ff6415;
  --accent-ink: #ffffff;
  --focus: #2f6fdb;
  --s-none: #8a94a6;
  --s-pass: #1f9d55;
  --s-warn: #c98a00;
  --s-fail: #d64545;
  --s-off: #7b5cd6;
  --h-bad: #d64545;
  --h-warn: #c98a00;
  --h-ok: #1f9d55;
  --h-idle: #a3adbd;
  --h-off: #7b5cd6;
  --h-none: transparent;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1424;
    --panel: #121e33;
    --ink: #e8eef8;
    --muted: #9aa8bd;
    --line: #23324d;
    --focus: #6ea0ff;
    --s-none: #7d889c;
    --s-pass: #38b673;
    --s-warn: #e0a92a;
    --s-fail: #ef6464;
    --s-off: #a08bf0;
    --h-bad: #ef6464;
    --h-warn: #e0a92a;
    --h-ok: #38b673;
    --h-idle: #56637a;
    --h-off: #a08bf0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--focus); }
h1 { font-size: 26px; margin: 8px 0 6px; line-height: 1.2; }
h2 { font-size: 19px; margin: 26px 0 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }
code, .mono { font: 0.88em ui-monospace, SFMono-Regular, Menlo, monospace; }
code { background: color-mix(in srgb, var(--line) 60%, transparent); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }
pre { white-space: pre-wrap; font: 12px ui-monospace, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--s-fail); min-height: 1.2em; margin: 4px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.spacer { flex: 1 1 auto; }
.lead { font-size: 16px; max-width: 900px; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  min-width: 0;
}
textarea { width: 100%; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  display: inline-flex; align-items: center; gap: 4px;
}
.btn:hover { border-color: var(--muted); }
.btn.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.link { background: none; border: 0; color: var(--focus); cursor: pointer; padding: 6px 0; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: #fff;
  display: inline-grid; place-items: center; font-weight: 800;
}

/* Sign in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card { width: 100%; max-width: 380px; padding: 24px; display: grid; gap: 12px; }
.signin-card label { display: grid; gap: 4px; font-size: 14px; }
.row-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* Shell */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 14px;
  padding: 8px 16px 0; background: var(--panel); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1 0 100%; scrollbar-width: none; margin: 0 -4px; padding-bottom: 6px; }
.tabs a { padding: 7px 11px; border-radius: 7px; color: var(--muted); text-decoration: none; white-space: nowrap; font-size: 14px; font-weight: 500; }
.tabs a:hover { color: var(--ink); background: var(--bg); }
.tabs a.active { color: var(--ink); background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 0 -2px 0 var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.me, .sync { font-size: 12px; }
.page { max-width: 1440px; margin: 0 auto; padding: 16px 16px 60px; min-width: 0; }

/* Summary */
.intro p { max-width: 900px; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 14px 0; }
.stat { padding: 14px; display: grid; gap: 2px; align-content: start; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; }
.stat .sub { font-size: 12px; color: var(--muted); }
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line); margin-top: 8px; }
.bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.s-none { background: var(--s-none); }
.s-pass { background: var(--s-pass); }
.s-warn { background: var(--s-warn); }
.s-fail { background: var(--s-fail); }
.s-off { background: var(--s-off); }
select.s-none, select.s-pass, select.s-warn, select.s-fail, select.s-off { color: #fff; border-color: transparent; font-weight: 600; }
select option { background: var(--panel); color: var(--ink); }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; vertical-align: 0; border: 1px solid transparent; }
.dot.h-bad { background: var(--h-bad); }
.dot.h-warn { background: var(--h-warn); }
.dot.h-ok { background: var(--h-ok); }
.dot.h-idle { background: var(--h-idle); }
.dot.h-off { background: var(--h-off); }
.dot.h-none { border-color: var(--line); }

.spark svg { display: block; }
.spark .sg { fill: color-mix(in srgb, var(--h-ok) 75%, transparent); }
.spark .sb { fill: var(--h-bad); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; margin: 10px 0 16px; align-items: center; position: sticky; top: 96px; z-index: 5; }
.filters input[type=search] { flex: 1 1 260px; }

/* Diagrams */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; color: var(--ink); text-decoration: none; background: var(--bg); }
.chip-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.diagram-wrap { padding: 10px; margin: 8px 0 16px; display: grid; gap: 8px; }
.diagram-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.seg { display: inline-flex; gap: 4px; }
.diagram { overflow: auto; max-height: 75vh; min-height: 120px; border-radius: 8px; background: var(--panel); }
.diagram-wrap.tall .diagram { max-height: 85vh; }
.diagram svg { display: block; margin: 0 auto; }
.diagram svg a { cursor: pointer; }
.kind-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.kind-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -2px; }
.kind-legend .k-actor { background: #ff6415; }
.kind-legend .k-device { background: #2f6fdb; }
.kind-legend .k-group { background: #1a2a45; border: 2px solid #ff6415; }
.kind-legend .k-external { background: #7b5cd6; }
.kind-legend .k-table { background: #0e8a6a; }
.kind-legend .k-service { background: var(--line); border: 1px solid var(--muted); }

/* Areas */
.domain-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.domain { padding: 14px; }
.domain h3 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.domain .count { font-weight: 400; font-size: 13px; }
.group-list { margin: 10px 0 0; padding-left: 18px; font-size: 14px; columns: 2; column-gap: 18px; }
.group-list li { break-inside: avoid; }

/* Flow list */
.group-h { margin: 16px 0 6px; color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .04em; }
.flow-row { display: grid; grid-template-columns: 70px minmax(0, 1fr) 110px 22px 100px; gap: 12px; align-items: center; padding: 10px 12px; margin-bottom: 6px; color: var(--ink); text-decoration: none; }
.flow-row:hover { border-color: var(--muted); }
.fid { font: 600 12.5px ui-monospace, Menlo, monospace; color: var(--muted); }
.fid.big { font-size: 18px; color: var(--accent); }
.ftitle { display: grid; min-width: 0; }
.fsum { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trig { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; justify-self: start; }
.flow-row .chip { justify-self: end; }

/* Flow detail */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.flow-head h1 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.flow-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; }
.verify { padding: 14px; display: grid; gap: 10px; border-left: 4px solid var(--accent); }
.verify-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.verify-head h2 { margin: 0; font-size: 17px; }
.how { font-size: 14.5px; }
.meta { font-size: 12px; }
.health-notes { margin: 0; padding-left: 18px; font-size: 13px; color: var(--s-fail); }
.steps { list-style: none; padding: 0; margin: 0; counter-reset: st; display: grid; gap: 8px; }
.steps li { counter-increment: st; padding: 10px 12px 10px 48px; position: relative; display: grid; gap: 4px; }
.steps li::before { content: counter(st); position: absolute; left: 12px; top: 10px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 700; display: grid; place-items: center; }
.step-route { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; font-weight: 600; }
.step-route .arrow { color: var(--muted); }
.step-kind { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; margin-left: 6px; }
.step-detail { font-size: 14px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; margin-top: 12px; }
.block { padding: 14px; margin-top: 12px; }
.two-col .block { margin-top: 0; }
.block ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 14.5px; }
.block.plain { list-style: none; padding-left: 14px; display: grid; gap: 6px; }
.warn-block { border-left: 4px solid var(--s-warn); }
.code-list { list-style: none; padding-left: 0 !important; }
.kv { display: grid; gap: 8px; font-size: 14px; }
.kv > div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.kv b { color: var(--muted); font-weight: 600; }
.block-code { display: inline-block; margin: 0 6px 4px 0; }
.ops { display: flex; flex-wrap: wrap; gap: 4px; }
code.op.missing { background: color-mix(in srgb, var(--s-fail) 25%, transparent); text-decoration: underline wavy var(--s-fail); }
.tag { display: inline-block; font: 600 12px ui-monospace, Menlo, monospace; padding: 1px 6px; margin: 0 4px 2px 0; border-radius: 5px; border: 1px solid var(--line); text-decoration: none; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
table.grid tr:last-child td { border-bottom: 0; }

/* Coverage / issues / screens */
.cov-list { columns: 2; column-gap: 24px; font-size: 13px; }
.cov-list li { break-inside: avoid; margin-bottom: 3px; }
.issue-list, .screen-list { display: grid; gap: 10px; }
.issue { padding: 12px 14px; display: grid; gap: 8px; }
.issue.focus { outline: 2px solid var(--accent); }
.issue-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.screen { padding: 14px; }
.screen .block { margin-top: 6px; padding: 0; border: 0; }
.screen h3 { margin-bottom: 2px; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); z-index: 21;
  background: var(--panel); border-left: 1px solid var(--line); display: grid; grid-template-rows: auto 1fr;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-body { overflow: auto; padding: 14px 16px; }
.hist { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; font-size: 14px; }
.hist li { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.hist .when { font-size: 12px; color: var(--muted); }
.drawer textarea { width: 100%; min-height: 220px; }

@media (max-width: 1100px) {
  .filters { top: 130px; }
}
@media (max-width: 720px) {
  .page { padding: 12px 16px 48px; }
  .topbar .me, .topbar .sync, #btn-export { display: none; }
  .filters { position: static; }
  .filters select { flex: 1 1 140px; }
  .flow-row { grid-template-columns: 60px minmax(0, 1fr) 16px; }
  .flow-row .trig, .flow-row .chip { grid-column: 2; justify-self: start; }
  .flow-row .fh { grid-row: 1; grid-column: 3; }
  .fsum { white-space: normal; }
  .kv > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .cov-list, .group-list { columns: 1; }
  .two-col { grid-template-columns: minmax(0, 1fr); }
  table.grid td:nth-child(3), table.grid th:nth-child(3), table.grid td:nth-child(6), table.grid th:nth-child(6) { display: none; }
}

/* Overview chart (hand-laid SVG) */
svg.ov { display: block; font: 12.5px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.ov-col { fill: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
.ov-edge { fill: none; stroke: var(--muted); stroke-opacity: .38; transition: stroke-opacity .12s; }
.ov-arrow { fill: var(--muted); }
.ov-node rect { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; }
.ov-node text { fill: var(--ink); pointer-events: none; }
.ov-node:hover rect { stroke: var(--accent); stroke-width: 2.5; }
.ov-actor rect { fill: #ff6415; stroke: #c84a08; }
.ov-actor text, .ov-device text, .ov-screen text, .ov-external text { fill: #fff; }
.ov-device rect, .ov-screen rect { fill: #2f6fdb; stroke: #1d4fa8; }
.ov-external rect { fill: #7b5cd6; stroke: #5a3fb0; }
.ov-store rect { fill: #0e8a6a; stroke: #0a6a51; }
.ov-store text { fill: #fff; }
.ov-group rect { fill: #1a2a45; stroke: #ff6415; stroke-width: 2; }
.ov-group text { fill: #fff; font-weight: 600; }
.ov-bad rect { stroke: var(--h-bad); stroke-width: 3; }
.ov-warn rect { stroke: var(--h-warn); stroke-width: 3; }
svg.ov.focus .ov-edge { stroke-opacity: .07; }
svg.ov.focus .ov-edge.on { stroke-opacity: .95; stroke: var(--accent); }
svg.ov.focus .ov-node { opacity: .35; }
svg.ov.focus .ov-node.on { opacity: 1; }
.cov-list .why { font-size: 12px; color: var(--muted); margin: 2px 0 6px 12px; }
