/* SignalMesh dashboard. Colours are tokens on :root; dark values are declared under both the OS setting and
   the manual toggle. Tiers use the fixed status palette (always with an icon and a label); the timeline
   uses categorical slots plus a distinct shape per kind, so colour is never the only channel. */
:root {
  color-scheme: light;
  --page: #f4f3f0; --surface: #fcfcfb; --surface-2: #f0efec; --line: #e2e0db; --grid: #e8e6e1;
  --text: #0b0b0b; --text-2: #52514e; --text-3: #7a7873;
  --accent: #184f95; --accent-ink: #ffffff; --accent-wash: #e3eefb;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-ink: #0a6e0a; --warning-ink: #7a5200; --serious-ink: #9a3f14; --critical-ink: #a32323;
  --c-employee: #2a78d6; --c-customer: #1baf7a; --c-system: #8b8a85; --c-human: #eda100;
  --seq-1: #cde2fb; --seq-2: #86b6ef; --seq-3: #3987e5; --seq-4: #1c5cab;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 4px 16px rgba(11, 11, 11, .04);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #34332f; --grid: #2c2b28;
    --text: #ffffff; --text-2: #c3c2b7; --text-3: #8d8c84;
    --accent: #6da7ec; --accent-ink: #0b0b0b; --accent-wash: #1d2a3b;
    --good-ink: #5fd35f; --warning-ink: #f0c25a; --serious-ink: #f0a07f; --critical-ink: #f08585;
    --c-employee: #3987e5; --c-customer: #199e70; --c-system: #9a9993; --c-human: #c98500;
    --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #3987e5; --seq-4: #86b6ef;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #34332f; --grid: #2c2b28;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #8d8c84;
  --accent: #6da7ec; --accent-ink: #0b0b0b; --accent-wash: #1d2a3b;
  --good-ink: #5fd35f; --warning-ink: #f0c25a; --serious-ink: #f0a07f; --critical-ink: #f08585;
  --c-employee: #3987e5; --c-customer: #199e70; --c-system: #9a9993; --c-human: #c98500;
  --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #3987e5; --seq-4: #86b6ef;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body { margin: 0; background: var(--page); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 13px; font-weight: 650; margin: 18px 0 8px; color: var(--text-2); }
button, select, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 10px 24px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand strong { font-size: 16px; letter-spacing: -.02em; }
.brand .sub { margin-left: 6px; color: var(--text-3); font-weight: 500; }
.logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M6 20l5-8 5 6 4-9 6 11' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/80% no-repeat; }
.sections { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.sections a { padding: 6px 10px; border-radius: 6px; color: var(--text-2); text-decoration: none; font-weight: 500; white-space: nowrap; }
.sections a:hover { background: var(--surface-2); color: var(--text); }
.controls { display: flex; align-items: center; gap: 10px; }
.select select { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.live { display: inline-flex; align-items: center; gap: 7px; color: var(--text-2); font-size: 12.5px; white-space: nowrap; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.live.ok i { background: var(--good); box-shadow: 0 0 0 0 rgba(12, 163, 12, .5); animation: pulse 2s infinite; }
.live.bad i { background: var(--critical); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(12, 163, 12, 0); } 100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); } }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn svg { width: 17px; height: 17px; stroke: var(--text-2); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.banner { margin: 12px 24px 0; padding: 10px 14px; border-radius: 8px; background: var(--accent-wash); border: 1px solid var(--line); color: var(--text); }
.banner.bad { border-color: var(--critical); }

/* layout */
main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 8px; display: grid; gap: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px 20px; box-shadow: var(--shadow); min-width: 0; }
.card > header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.card > header p { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.foot { text-align: center; color: var(--text-3); font-size: 12px; padding: 18px; }

/* overview */
.overview { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 16px; }
.hero { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #000)); color: #fff; border-radius: 12px; padding: 20px 22px; display: flex; flex-direction: column; justify-content: center; box-shadow: var(--shadow); }
:root[data-theme="dark"] .hero { color: #0b0b0b; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .hero { color: #0b0b0b; } }
.hero-label { font-size: 12.5px; opacity: .85; font-weight: 500; }
.hero-value { font-size: 64px; line-height: 1; font-weight: 700; letter-spacing: -.03em; margin: 6px 0 8px; }
.hero-sub { font-size: 13px; opacity: .9; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { color: var(--text-3); font-size: 12px; }
.tile .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .d { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.tile.flag .v { color: var(--critical-ink); }

/* tier badges: shape + label + colour */
.tier { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; font-size: 12px; padding: 3px 9px 3px 7px; border-radius: 999px; border: 1px solid currentColor; background: color-mix(in srgb, currentColor 9%, transparent); letter-spacing: .02em; }
.tier svg { width: 13px; height: 13px; fill: currentColor; }
.tier.MONITORING { color: var(--good-ink); } .tier.WATCH { color: var(--warning-ink); }
.tier.ELEVATED { color: var(--serious-ink); } .tier.CRITICAL { color: var(--critical-ink); }
.tier.RESOLVED { color: var(--text-3); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
.chip.warn { color: var(--critical-ink); border-color: var(--critical); background: color-mix(in srgb, var(--critical) 10%, transparent); }
.chip.ok { color: var(--good-ink); border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, transparent); }
.chip.pending { color: var(--warning-ink); border-color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, transparent); }
.chip.info { color: var(--accent); border-color: var(--accent); background: var(--accent-wash); }

/* topology */
.topology { overflow-x: auto; }
.topology svg { display: block; min-width: 520px; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; color: var(--text-2); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { width: 12px; height: 12px; }
.node text { fill: var(--text); } .node .small { fill: var(--text-3); font-size: 11px; }
.node rect { fill: var(--surface-2); stroke: var(--line); } .edge { stroke: var(--line); stroke-width: 1.5; fill: none; }
.node:hover rect { stroke: var(--accent); }

/* incidents */
.incidents { display: grid; gap: 12px; }
.incident { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: var(--surface); cursor: pointer; border-left: 4px solid var(--line); }
.incident.CRITICAL { border-left-color: var(--critical); } .incident.ELEVATED { border-left-color: var(--serious); }
.incident.WATCH { border-left-color: var(--warning); } .incident.MONITORING { border-left-color: var(--good); }
.incident.selected { outline: 2px solid var(--accent); outline-offset: -1px; }
.incident .top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.incident .asset { font-weight: 650; font-size: 15px; }
.incident .code { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.incident .cause { margin: 8px 0 10px; color: var(--text-2); }
.facts { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--text-2); }
.facts b { color: var(--text); font-variant-numeric: tabular-nums; }
.meter { display: inline-flex; align-items: center; gap: 8px; }
.meter .track { width: 96px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.meter .fill { display: block; height: 100%; border-radius: 4px 0 0 4px; }
.incident details { margin-top: 10px; }
.incident summary { cursor: pointer; color: var(--accent); font-weight: 550; list-style: none; }
.incident summary::-webkit-details-marker { display: none; }
.incident summary::before { content: "▸ "; } .incident details[open] summary::before { content: "▾ "; }
.detail { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; margin-top: 10px; }
.detail h4 { margin: 0 0 4px; font-size: 12px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.detail p, .detail li { color: var(--text-2); font-size: 13px; } .detail ol, .detail ul { margin: 0; padding-left: 18px; }
.spark { width: 100%; height: 56px; }
.spark .line { stroke: var(--accent); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.empty { color: var(--text-3); padding: 18px 4px; text-align: center; }

/* timeline */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); padding: 5px 12px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
#timeline-body svg { width: 100%; height: auto; display: block; }
.lane-label { fill: var(--text-2); font-size: 12px; } .tick { stroke: var(--grid); } .tick-label { fill: var(--text-3); font-size: 11px; }
.ev { cursor: pointer; } .ev:hover { stroke-width: 3; }
.ev.employee { fill: var(--c-employee); } .ev.customer { fill: var(--c-customer); } .ev.system { fill: var(--c-system); }
.ev.human { fill: var(--surface); stroke: var(--c-human); stroke-width: 3; }
.ev.hazardring { stroke: var(--critical); stroke-width: 2.5; }
.surface-ring { stroke: var(--surface); stroke-width: 2; }
.now-line { stroke: var(--accent); stroke-dasharray: 4 4; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-3); font-weight: 600; font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; }
.dot.employee { background: var(--c-employee); border-radius: 50%; } .dot.customer { background: var(--c-customer); border-radius: 2px; }
.dot.system { background: var(--c-system); transform: rotate(45deg) scale(.8); } .dot.human { border: 3px solid var(--c-human); border-radius: 50%; }

/* lists */
.approvals, .resolution, .feed, .comms, .history { display: grid; gap: 10px; }
.approval, .res, .history .row { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.approval .row1, .res .row1 { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.approval .sum { margin: 6px 0; color: var(--text-2); } .small-note { color: var(--text-3); font-size: 12px; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 650; }
.steps { display: flex; gap: 0; margin: 10px 0 4px; }
.step { flex: 1; font-size: 11.5px; color: var(--text-3); text-align: center; position: relative; padding-top: 18px; }
.step::before { content: ""; position: absolute; top: 4px; left: 50%; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line); transform: translateX(-50%); z-index: 1; }
.step::after { content: ""; position: absolute; top: 8px; left: -50%; width: 100%; height: 2px; background: var(--line); }
.step:first-child::after { display: none; }
.step.done { color: var(--text-2); } .step.done::before { background: var(--accent); border-color: var(--accent); } .step.done::after { background: var(--accent); }
.step.now { color: var(--text); font-weight: 650; } .step.now::before { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.step.bad::before { border-color: var(--critical); background: var(--critical); }
.cluster-row { display: grid; grid-template-columns: minmax(0, 1.3fr) auto 110px 56px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.cluster-row:last-child { border: 0; } .cluster-row .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mix { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 32px; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-2); }
.bar-row .b { height: 14px; background: transparent; } .bar-row .b span { display: block; height: 100%; background: var(--seq-3); border-radius: 0 4px 4px 0; }
.sig { display: grid; grid-template-columns: 62px 18px minmax(0, 1fr); gap: 8px; align-items: start; padding: 7px 0; border-bottom: 1px solid var(--grid); }
.sig .t { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.sig .who { font-weight: 550; } .sig .txt { color: var(--text-2); }
.sig.new { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: var(--accent-wash); } to { background: transparent; } }
.feed { max-height: 460px; overflow: auto; gap: 0; }
.comms { max-height: 520px; overflow: auto; gap: 0; }
.comm { display: grid; grid-template-columns: 66px 120px 90px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); align-items: start; }
.comm .t { color: var(--text-3); font-size: 12px; } .comm .who { font-size: 12.5px; color: var(--text-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; } .chips button { cursor: pointer; }
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.report { margin: 0; white-space: pre-wrap; font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 14px; max-height: 520px; overflow: auto; }
.history .row { display: grid; gap: 4px; } .history .row .head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-weight: 600; }

/* tooltip */
.tip { position: fixed; z-index: 40; max-width: 340px; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); font-size: 12.5px; }
.tip b { display: block; margin-bottom: 2px; } .tip span { color: var(--text-2); display: block; }

/* gate */
.gate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(6px); }
.gate-card { width: min(380px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.gate-card input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); }
.gate-card p { color: var(--text-2); } .gate-error { color: var(--critical-ink) !important; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 10px 14px; font-weight: 600; cursor: pointer; }

@media (max-width: 980px) {
  .overview, .grid2 { grid-template-columns: 1fr; } .detail { grid-template-columns: 1fr; }
  .sections { display: none; } .hero-value { font-size: 52px; }
  .comm { grid-template-columns: 56px 1fr; } .comm .who:nth-child(3) { display: none; }
}
@media (max-width: 560px) { main { padding: 14px 12px; } .topbar { padding: 8px 12px; gap: 10px; } .brand .sub { display: none; } .cluster-row { grid-template-columns: 1fr auto; } .cluster-row .meter, .cluster-row .n { display: none; } }
@media (prefers-reduced-motion: reduce) { .live.ok i, .sig.new { animation: none; } html { scroll-behavior: auto; } }
@media (forced-colors: active) { .tier, .chip { border: 1px solid CanvasText; } .ev.human { stroke: Highlight; } }

[hidden]{display:none !important}

/* approve / reject (only drawn when the server enables it) */
.decide { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.decide .btn { border: 1px solid var(--line); border-radius: 8px; padding: 6px 14px; cursor: pointer; background: var(--surface-2); font-weight: 600; }
.decide .btn.approve { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.decide .btn.reject { color: var(--critical-ink); }
.decide .btn:focus-visible, .decide .reason:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.decide .reason { flex: 1 1 180px; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--surface); }
.small-note.bad { color: var(--critical-ink); }
