/* Tokens. Surfaces and the four status colours come from the validated data-viz palette. The status colours are
   fixed in both themes and are always shown with an icon and a label, never as colour alone. */
:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #f0efec; --line: #dcdbd6;
  --text: #0b0b0b; --text-2: #52514e; --text-3: #75746f;
  --accent: #2a78d6; --accent-soft: #e3eefb;
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b; --neutral: #75746f;
  --good-ink: #0a6b0a; --warning-ink: #6b4a00; --critical-ink: #a72828; --neutral-ink: #52514e;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242423; --line: #383835;
    --text: #f4f4f2; --text-2: #b9b8b3; --text-3: #8e8d88;
    --accent: #6aa8f0; --accent-soft: #1c2c40;
    --good-ink: #5fd35f; --warning-ink: #fab219; --critical-ink: #ff8a8a; --neutral-ink: #b9b8b3;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242423; --line: #383835;
  --text: #f4f4f2; --text-2: #b9b8b3; --text-3: #8e8d88;
  --accent: #6aa8f0; --accent-soft: #1c2c40;
  --good-ink: #5fd35f; --warning-ink: #fab219; --critical-ink: #ff8a8a; --neutral-ink: #b9b8b3;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--text-2); margin-bottom: 10px; }
h3 { font-size: 13px; color: var(--text-2); margin: 18px 0 6px; }
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { left: 8px; }
.muted { color: var(--text-3); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- top bar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { display: grid; place-items: center; min-width: 34px; height: 30px; padding: 0 6px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; }
.brand-name { font-weight: 600; font-size: 16px; white-space: nowrap; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
.chip.warn { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--warning-ink); border-color: transparent; }
.search { flex: 1; max-width: 420px; margin-left: 16px; }
.search input { width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.live { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 50%, transparent); animation: pulse 2s infinite; }
.live.warn .pulse { background: var(--warning); animation: none; }
.live.off .pulse { background: var(--critical); animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

/* ---- layout */
main { padding: 20px 24px 40px; max-width: 1500px; margin: 0 auto; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; margin-top: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.side { display: grid; gap: 16px; position: sticky; top: 68px; }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } .side { position: static; } }
@media (max-width: 720px) { .topbar { flex-wrap: wrap; padding: 10px 16px; } .search { order: 5; flex-basis: 100%; max-width: none; margin: 0; } main { padding: 16px; } }

/* ---- KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); min-height: 112px; display: flex; flex-direction: column; }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 30px; font-weight: 600; line-height: 1.15; margin-top: 4px; }
.tile .sub { margin-top: auto; padding-top: 6px; color: var(--text-2); font-size: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.spark { display: block; width: 100%; height: 26px; margin-top: 4px; }
.spark path { fill: none; stroke: var(--text-3); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark path.now { stroke: var(--accent); stroke-width: 7; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--bg), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; color: transparent; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- status pills: icon + label, never colour alone */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 6px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill svg { width: 13px; height: 13px; flex: none; }
.pill.s-ok { color: var(--good-ink); background: color-mix(in srgb, var(--good) 14%, transparent); }
.pill.s-warn { color: var(--warning-ink); background: color-mix(in srgb, var(--warning) 22%, transparent); }
.pill.s-down { color: var(--critical-ink); background: color-mix(in srgb, var(--critical) 14%, transparent); }
.pill.s-unknown, .pill.s-none { color: var(--neutral-ink); background: var(--surface-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.swatch.s-ok { background: var(--good); } .swatch.s-warn { background: var(--warning); } .swatch.s-down { background: var(--critical); } .swatch.s-unknown { background: var(--neutral); }

/* ---- tabs and tables */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 14px; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; cursor: pointer; color: var(--text-2); font-weight: 500; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--text); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--text-2); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th button { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: inherit; display: inline-flex; gap: 4px; align-items: center; }
th button:hover { color: var(--text); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr:focus-visible { background: var(--surface-2); }
tbody tr.dim { opacity: .35; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.cell-title { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--text-3); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
.tag.warn { color: var(--warning-ink); background: color-mix(in srgb, var(--warning) 18%, transparent); border-color: transparent; }
.empty { padding: 28px 12px; text-align: center; color: var(--text-3); }

/* ---- avatars: initials on neutral discs, so a person's colour never carries meaning */
.avatar { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); border: 2px solid var(--surface); font-size: 10px; font-weight: 600; flex: none; }
.avatar.lg { width: 34px; height: 34px; font-size: 12px; border-color: transparent; }
.stack { display: inline-flex; align-items: center; }
.stack .avatar + .avatar { margin-left: -8px; }
.stack .more { font-size: 11px; color: var(--text-3); margin-left: 6px; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* ---- map */
.stage { position: relative; }
#graph, #fx { width: 100%; height: auto; display: block; }
#fx { position: absolute; inset: 0; pointer-events: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; list-style: none; padding: 10px 0 0; margin: 0; color: var(--text-2); font-size: 12px; }
.legend-note { flex-basis: 100%; color: var(--text-3); }
.edge { fill: none; stroke-linecap: round; opacity: .9; }
.edge.s-ok { stroke: var(--good); } .edge.s-warn { stroke: var(--warning); } .edge.s-down { stroke: var(--critical); } .edge.s-unknown { stroke: var(--neutral); stroke-dasharray: 5 4; }
.edge.dim { opacity: .15; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 16; cursor: pointer; }
.node { cursor: pointer; }
.node circle.body { fill: var(--surface); stroke-width: 3; }
.node.s-ok circle.body { stroke: var(--good); } .node.s-warn circle.body { stroke: var(--warning); } .node.s-down circle.body { stroke: var(--critical); }
.node.s-unknown circle.body { stroke: var(--neutral); stroke-dasharray: 4 3; } .node.s-none circle.body { stroke: var(--line); stroke-dasharray: 2 4; }
.node.selected circle.body { fill: var(--accent-soft); }
.node text { fill: var(--text); text-anchor: middle; pointer-events: none; }
.node .ini { font-size: 13px; font-weight: 700; fill: var(--text-2); }
.node .name { font-size: 12px; font-weight: 600; }
.node .meta { font-size: 11px; fill: var(--text-3); }
.node.dim { opacity: .25; }
.node:focus-visible circle.body { outline: 2px solid var(--accent); outline-offset: 3px; }
.group-label { fill: var(--text-3); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.dot-fly { fill: var(--accent); }
.ripple { fill: none; stroke: var(--good); stroke-width: 3; transform-box: fill-box; transform-origin: center; animation: ripple 1s ease-out forwards; }
@keyframes ripple { from { transform: scale(1); opacity: .9; } to { transform: scale(1.7); opacity: 0; } }

/* ---- side lists and feed */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:last-child, .feed li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; font-size: 13px; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.feed li { display: grid; grid-template-columns: 58px 1fr; gap: 2px 8px; padding: 7px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.feed time { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.feed .type { overflow-wrap: anywhere; font-size: 13px; }
.feed .to { grid-column: 2; color: var(--text-3); font-size: 12px; }
.feed li.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } to { background: transparent; } }

/* ---- drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 40; overflow-y: auto; padding: 20px; animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer[hidden], .scrim[hidden] { display: none; }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; justify-content: space-between; }
.drawer-head h2 { font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 2px; }
.drawer a { color: var(--accent); }
.mini-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 4px; }
.mini { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.mini .v { font-size: 18px; font-weight: 600; }
.mini .l { font-size: 12px; color: var(--text-2); }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.notice { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning-ink); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 10px 0; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } }

.edge-tag { font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; fill: var(--text-2); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.edge-tag.dim { opacity: .2; }
.edge.api { stroke-dasharray: 2 5; }
.edge.api.s-ok, .edge.api.s-down { stroke-dasharray: 8 4; }
/* Sign in */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 20px; margin: 18px 0 4px; }
.login-card form { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.login-card label { font-size: 13px; color: var(--text-2); margin-top: 6px; }
.login-card input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
.login-card input:focus-visible, .primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.login-error { color: var(--critical-ink); font-size: 13px; margin: 6px 0 0; }
.primary { margin-top: 12px; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 12px; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: .7; cursor: default; }
.signout { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.signout button { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; color: var(--text-2); }
.signout button:hover { color: var(--text); }
