/* ShakeAzul dashboard on the Azul design system (vendor/azul). App layout only:
   colours come from Azul tokens; status colour uses --destructive and --chart-* only. */

:root {
  --ok: var(--chart-2);          /* listening / warning time left */
  --soon: var(--chart-3);        /* last seconds before shaking */
  --trace-x: var(--chart-1);
  --trace-y: var(--chart-2);
  --trace-z: var(--chart-4);
  --trace-r: var(--muted-foreground);
}
html, body { margin: 0; min-height: 100%; }
body { font-size: var(--text-sm); line-height: var(--text-sm--line-height); }
* { box-sizing: border-box; }
h1, h2, h3 { letter-spacing: var(--tracking-tight); }
[hidden] { display: none !important; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted-foreground); }
.small { font-size: var(--text-xs); line-height: var(--text-xs--line-height); }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.app-header { position: sticky; top: 0; z-index: 40; height: 3.5rem; display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem; border-bottom: 1px solid var(--border); background: var(--background); }
.brand { display: flex; align-items: baseline; gap: .75rem; min-width: 0; }
.wordmark { font-family: var(--font-brand); font-size: var(--text-xl); line-height: 1; }
.brand-sub { color: var(--muted-foreground); font-size: var(--text-xs); white-space: nowrap; }
.app-tabs { margin: 0 auto; }
.header-actions { display: flex; align-items: center; gap: .5rem; }
.conn .dot { width: .5rem; height: .5rem; border-radius: var(--radius-full); background: var(--muted-foreground); }
.conn[data-state="live"] .dot { background: var(--ok); }
.conn[data-state="down"] { color: var(--destructive); border-color: color-mix(in oklab, var(--destructive) 30%, transparent); }
.conn[data-state="down"] .dot { background: var(--destructive); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 26rem; gap: 1.5rem; padding: 1.5rem;
  max-width: 100rem; margin: 0 auto; }
body[data-tab="arch"] .layout { grid-template-columns: minmax(0, 1fr); max-width: 80rem; }
body[data-tab="arch"] .col-side { display: none; }
.col-main { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.tab-panel { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.col-side { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; position: sticky; top: 5rem;
  align-self: start; max-height: calc(100vh - 6.5rem); }
.side-card { padding: 1.25rem 0; gap: 1rem; }
.log-card { min-height: 0; flex: 1; }
.log-card .ui-card-content { overflow-y: auto; min-height: 8rem; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 .375rem; font-size: var(--text-2xl); line-height: var(--text-2xl--line-height); font-weight: var(--font-weight-semibold); }
.page-head p { margin: 0; max-width: 46rem; color: var(--muted-foreground); }
.page-actions { display: flex; gap: .5rem; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1rem; }
.stat { border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm); }
.stat-label { color: var(--muted-foreground); font-size: var(--text-xs); font-weight: var(--font-weight-medium); }
.stat-value { margin-top: .25rem; font-size: var(--text-2xl); line-height: var(--text-2xl--line-height);
  font-weight: var(--font-weight-semibold); font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-tight); }

/* ---------- sensors ---------- */
.traces { display: flex; flex-direction: column; gap: .75rem; }
.node { border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); box-shadow: var(--shadow-sm);
  padding: .75rem 1rem .25rem; transition: border-color var(--duration-fast) var(--ease-in-out); }
.node[data-status="triggered"] { border-color: var(--destructive); box-shadow: 0 0 0 3px color-mix(in oklab, var(--destructive) 20%, transparent); }
.node[data-status="offline"] { opacity: .5; }
.node-hdr { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.node-name { font-weight: var(--font-weight-semibold); font-size: var(--text-sm); }
.node-meta { margin-left: auto; color: var(--muted-foreground); font-family: var(--font-mono); font-size: var(--text-xs); }
.ui-badge[data-status="triggered"] { background: var(--destructive); color: #fff; border-color: transparent; }
.ui-badge[data-status="listening"] { color: var(--ok); border-color: color-mix(in oklab, var(--ok) 35%, transparent); }
.node .plot { margin-top: .25rem; }
.traces.compact .node { padding: .5rem .75rem 0; border-radius: var(--radius-lg); box-shadow: none; }
.u-legend { font-size: var(--text-xs); color: var(--muted-foreground); }
.u-legend .u-marker { border-radius: 2px; }
.uplot, .uplot * { font-family: var(--font-sans); }
.stations-card { padding: 1.25rem 0; gap: 1rem; }
#stationTraces:empty { display: none; }
.empty-qr { width: 11rem; height: 11rem; margin-top: 1rem; border-radius: var(--radius-lg); background: #fff; padding: .5rem; }

/* ---------- event / countdown card ---------- */
.event-slot:empty { display: none; }
.event-card { border: 1px solid var(--destructive); border-radius: var(--radius-xl); background: var(--card);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--destructive) 20%, transparent); padding: 1.25rem 1.5rem;
  display: flex; flex-direction: column; gap: 1rem; animation: ui-fade 150ms var(--ease-out); }
.event-top { display: flex; align-items: center; gap: .75rem; color: var(--destructive); }
.event-top svg { width: 1.25rem; height: 1.25rem; }
.event-title { font-size: var(--text-lg); font-weight: var(--font-weight-semibold); letter-spacing: var(--tracking-tight); }
.event-id { margin-left: auto; color: var(--muted-foreground); font-family: var(--font-mono); font-size: var(--text-xs); }
.event-body { color: var(--muted-foreground); }
.headline { font-size: var(--text-xl); font-weight: var(--font-weight-semibold); letter-spacing: var(--tracking-tight); }
.headline .big { font-size: var(--text-4xl); line-height: var(--text-4xl--line-height); color: var(--ok); font-variant-numeric: tabular-nums; }
.headline .big.blind { color: var(--destructive); }
.cities td.cd { text-align: right; font-family: var(--font-mono); font-size: var(--text-lg); font-weight: var(--font-weight-semibold); }
.cities tr[data-phase="ok"] td.cd { color: var(--ok); }
.cities tr[data-phase="soon"] td.cd { color: var(--soon); }
.cities tr[data-phase="now"] td.cd, .cities tr[data-phase="blind"] td.cd, .cities tr[data-phase="blind"] td.lead { color: var(--destructive); }
.latency { display: flex; flex-wrap: wrap; gap: .5rem; }
.latency .ui-badge { font-family: var(--font-mono); font-weight: var(--font-weight-normal); }
.latency .ui-badge b { font-weight: var(--font-weight-semibold); }
.fineprint { color: var(--muted-foreground); font-size: var(--text-xs); line-height: 1.5; }

/* ---------- replay ---------- */
.speed { display: flex; align-items: center; gap: .5rem; }
.speed .ui-native-select { width: 9rem; }
/* replay picker: one row of controls + a summary line */
.picker-card { padding: 1rem 0; }
.picker { display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; }
.picker-field { display: flex; flex-direction: column; align-items: stretch; gap: .375rem; }
.picker-field:first-child { flex: 1; min-width: 18rem; }
.picker-field.speed .ui-native-select { width: 9rem; }
.picker-info { display: flex; flex-wrap: wrap; align-items: center; gap: .375rem; margin-top: .75rem; }
.picker-note { color: var(--muted-foreground); font-size: var(--text-xs); margin-left: .25rem; }
.np-clock { display: flex; align-items: baseline; gap: 1rem; margin-bottom: .75rem; }
.np-clock .mono { font-size: var(--text-3xl); line-height: var(--text-3xl--line-height); font-weight: var(--font-weight-semibold); }
.timeline { position: relative; height: .5rem; border-radius: var(--radius-full); background: var(--muted); margin: 1.75rem 0 2.25rem; }
.timeline-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: var(--radius-full); background: var(--primary);
  transition: width var(--duration-normal) linear; }
.tick { position: absolute; top: -.375rem; width: 2px; height: 1.25rem; background: var(--muted-foreground); transform: translateX(-1px); }
.tick span { position: absolute; top: 1.5rem; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: var(--text-xs); color: var(--muted-foreground); }
.tick.above span { top: -1.375rem; }
.tick.start span { left: 0; transform: none; }
.tick.end span { left: auto; right: 0; transform: none; }
.tick[data-kind="detect"] { background: var(--destructive); }
.tick[data-kind="detect"] span { color: var(--destructive); }
.tick[data-kind="s"] { background: var(--soon); }

/* ---------- map ---------- */
#map { height: 20rem; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--muted); }
.leaflet-container { font-family: var(--font-sans); background: var(--muted); }
.leaflet-control-attribution { font-size: 10px; }
.city-label { background: var(--popover); color: var(--popover-foreground); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs); font-size: var(--text-xs); padding: 0 .375rem; }
.city-label::before { display: none; }
.city-label.shaking { background: var(--destructive); color: #fff; border-color: transparent; }
path.node-marker.triggered { animation: ui-pulse 1s ease-in-out infinite; }
.legend { display: flex; flex-wrap: wrap; gap: .375rem 1rem; margin-top: .75rem; color: var(--muted-foreground); font-size: var(--text-xs); }
.legend span { display: inline-flex; align-items: center; gap: .375rem; }
.lg-dot { width: .625rem; height: .625rem; border-radius: var(--radius-full); display: inline-block; }
.lg-dot.ok { background: var(--ok); } .lg-dot.trig { background: var(--destructive); }
.lg-dot.off { background: var(--muted-foreground); } .lg-dot.city { background: var(--foreground); }
.lg-ring { width: .75rem; height: .75rem; border-radius: var(--radius-full); border: 2px solid; display: inline-block; }
.lg-ring.p { border-color: var(--chart-1); border-style: dashed; } .lg-ring.s { border-color: var(--destructive); }
.lg-ring.blind { border-color: transparent; background: color-mix(in oklab, var(--destructive) 25%, transparent); }
body:not([data-replay="on"]) .replay-legend { display: none; }

/* ---------- log ---------- */
#log { list-style: none; margin: 0; padding: 0; }
#log li { display: grid; grid-template-columns: 1rem 1fr auto; gap: .5rem; align-items: start; padding: .5rem 0; border-bottom: 1px solid var(--border); }
#log li:last-child { border-bottom: 0; }
#log li svg { width: 1rem; height: 1rem; margin-top: 2px; }
#log .t { color: var(--muted-foreground); font-family: var(--font-mono); font-size: var(--text-xs); }
#log [data-kind="trigger"] { color: var(--destructive); }
#log [data-kind="event"] .msg { font-weight: var(--font-weight-medium); }
#log [data-kind="event"] svg { color: var(--destructive); }
#log [data-kind="end"], #log [data-kind="info"], #log [data-kind="noise"] { color: var(--muted-foreground); }
#log [data-kind="warning"] svg { color: var(--ok); }

/* ---------- join dialog ---------- */
.join-qr { width: 15rem; height: 15rem; align-self: center; border-radius: var(--radius-lg); background: #fff; padding: .5rem; }
.steps { margin: 0; padding-left: 1.25rem; line-height: 1.75; }

/* ---------- how it works ---------- */
.arch-flow { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .75rem; }
.stage { position: relative; display: flex; flex-direction: column; gap: .625rem; border: 1px solid var(--border);
  border-radius: var(--radius-xl); background: var(--card); box-shadow: var(--shadow-sm); padding: 1rem; }
.stage[data-built="planned"] { border-style: dashed; box-shadow: none; background: transparent; }
.stage:not(:last-child)::after { content: ""; position: absolute; right: -.6rem; top: 1.6rem; width: .45rem; height: .45rem;
  border-top: 2px solid var(--muted-foreground); border-right: 2px solid var(--muted-foreground); transform: rotate(45deg); }
.stage-hdr { display: flex; align-items: center; gap: .5rem; }
.stage-hdr .n { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--muted-foreground); }
.stage-icon { display: flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; border-radius: var(--radius-md); background: var(--muted); }
.stage-title { font-weight: var(--font-weight-semibold); letter-spacing: var(--tracking-tight); }
.stage ul { margin: 0; padding-left: 1rem; color: var(--muted-foreground); font-size: var(--text-xs); line-height: 1.5; }
.stage .gaps-list { list-style: none; padding: 0; color: var(--destructive); }
.stage .gaps-list li { display: grid; grid-template-columns: .875rem 1fr; gap: .375rem; }
.stage .gaps-list svg { width: .875rem; height: .875rem; margin-top: 2px; }
.stage-sub { font-size: var(--text-xs); font-weight: var(--font-weight-medium); color: var(--foreground); }
.arch-bus { display: flex; gap: .75rem; align-items: flex-start; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--muted); padding: .75rem 1rem; color: var(--muted-foreground); }
.arch-bus b { color: var(--foreground); font-weight: var(--font-weight-medium); }
.arch-bus svg { margin-top: 2px; flex-shrink: 0; }
.budget { display: flex; flex-direction: column; gap: .75rem; }
.budget-bar { display: flex; height: 2.25rem; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); }
.seg { display: flex; align-items: center; justify-content: center; font-size: var(--text-xs); font-weight: var(--font-weight-medium);
  white-space: nowrap; overflow: hidden; padding: 0 .25rem; }
.seg[data-k="travel"] { background: var(--muted); color: var(--muted-foreground); }
.seg[data-k="assoc"] { background: color-mix(in oklab, var(--chart-1) 35%, transparent); }
.seg[data-k="pipe"] { background: var(--chart-1); color: #fff; }
.seg[data-k="deliver"] { background: color-mix(in oklab, var(--soon) 70%, transparent); color: #000; }
.seg[data-k="warn"] { background: var(--ok); color: #000; }
.budget-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .5rem 1.5rem; }
.budget-legend div { display: grid; grid-template-columns: .75rem 1fr auto; gap: .5rem; align-items: center; }
.budget-legend i { width: .75rem; height: .75rem; border-radius: 3px; display: inline-block; }
.gaps td { white-space: normal; vertical-align: top; }
.gaps td:first-child { font-weight: var(--font-weight-medium); }
.gaps tr.gap-layer td { padding-top: 1.25rem; font-weight: var(--font-weight-semibold); color: var(--foreground); border-bottom: 1px solid var(--border); }
.gaps tr.gap-layer .n { display: inline-block; min-width: 1.25rem; font-family: var(--font-mono); color: var(--muted-foreground); }
.gaps tr.gap-layer:first-child td { padding-top: .5rem; }

@media (max-width: 1200px) { .arch-flow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage:nth-child(3)::after { display: none; } }
@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 1rem; }
  .col-side { position: static; max-height: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand-sub { display: none; }
}
@media (max-width: 640px) {
  .app-header { padding: 0 1rem; gap: .5rem; overflow-x: auto; }
  .app-tabs .ui-tabs-trigger { padding: 0 .5rem; }
  .arch-flow { grid-template-columns: minmax(0, 1fr); }
  .stage::after { display: none; }
}

/* Card headers with an action: keep title and description in the first column even while
   the (presenter-only) action is hidden, so the grid never re-flows them side by side. */
.ui-card-header[data-action="true"] > .ui-card-title,
.ui-card-header[data-action="true"] > .ui-card-description { grid-column: 1; }
.ui-card-header[data-action="true"] > .ui-card-action { grid-row: 1 / span 2; }

/* sensor tier badge: tier 1 strongest contrast, lower tiers progressively quieter */
.ui-badge.tier { font-weight: var(--font-weight-medium); }
.ui-badge.tier[data-tier="1"] { background: var(--secondary); color: var(--foreground); }
.ui-badge.tier[data-tier="2"] { background: transparent; border-color: var(--border); color: var(--foreground); }
.ui-badge.tier[data-tier="3"], .ui-badge.tier[data-tier="4"], .ui-badge.tier[data-tier="0"] {
  background: transparent; border-color: var(--border); color: var(--muted-foreground); }
.tiers td { white-space: normal; vertical-align: top; }
.tiers td:first-child { white-space: nowrap; }

/* ================= v3: unified tabs, sensor lists, map hierarchy, explainer ================= */
.layout { grid-template-columns: minmax(0, 1fr) 33rem; }
.stat-sub { margin-top: .125rem; color: var(--muted-foreground); font-size: var(--text-xs); }
.stat-value[data-tone="good"] { color: var(--ok); }
.stat-value[data-tone="bad"] { color: var(--destructive); }

/* sources (Live) */
.sources { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.source { display: flex; flex-direction: column; justify-content: space-between; gap: .75rem; border: 1px solid var(--border);
  border-radius: var(--radius-xl); background: var(--card); box-shadow: var(--shadow-sm); padding: 1rem 1.25rem; }
.source-hdr { display: flex; gap: .75rem; align-items: flex-start; }
.source-icon { display: flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; flex-shrink: 0;
  border-radius: var(--radius-md); background: var(--muted); }
.source-title { font-weight: var(--font-weight-semibold); }
.source-desc { color: var(--muted-foreground); font-size: var(--text-xs); line-height: 1.5; margin-top: .125rem; }
.source-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* sensor list */
.list-card { padding: 1.25rem 0; gap: 1rem; }
.list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.toolbar-right { display: flex; align-items: center; gap: .5rem; }
.sort { display: flex; align-items: center; gap: .5rem; }
.sort .ui-native-select { height: 2rem; width: auto; min-width: 11rem; }
.ui-toggle[data-state="on"] { background: var(--accent); color: var(--accent-foreground); }
.node .hide-btn { margin-left: .25rem; opacity: .6; }
.node .hide-btn:hover { opacity: 1; }
.node.is-hidden { opacity: .45; border-style: dashed; }
.node-meta { margin-left: auto; }
#liveEmpty, #replayEmpty { padding: 2rem 1rem; }

/* map hierarchy */
.map-card #map { height: 32rem; }
.sym { background: none; border: 0; }
.sym svg { display: block; filter: drop-shadow(0 1px 1px rgb(0 0 0 / .35)); }
.sym.pulse svg { animation: sym-pulse 1s ease-in-out infinite; }
@keyframes sym-pulse { 50% { transform: scale(1.35); } }
.city-label.capital { font-weight: var(--font-weight-semibold); font-size: var(--text-sm); }
.legend { flex-direction: column; gap: .5rem; }
.legend-group { display: flex; flex-wrap: wrap; align-items: center; gap: .375rem .875rem; }
.legend-title { width: 4.5rem; color: var(--foreground); font-weight: var(--font-weight-medium); }
.legend svg { width: 12px; height: 12px; }
.lg-epi { width: .875rem; height: .875rem; border-radius: 50%; border: 2.5px solid var(--destructive); display: inline-block; }
.leaflet-control-layers { background: var(--popover) !important; color: var(--popover-foreground); border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important; box-shadow: var(--shadow-md) !important; font-family: var(--font-sans); font-size: var(--text-xs); }
.leaflet-control-layers-expanded { padding: .5rem .75rem; }
.leaflet-bar a { background: var(--popover); color: var(--popover-foreground); border-color: var(--border); }
.leaflet-tooltip .muted { color: #666; }

/* dialogs */
.ui-dialog.wide { max-width: 52rem; max-height: 85vh; }
.station-table-wrap { max-height: 60vh; overflow: auto; }
#stationTable td { white-space: normal; }
#stationTable .note { color: var(--muted-foreground); font-size: var(--text-xs); }

/* how it works */
.toc { display: flex; flex-wrap: wrap; gap: .25rem; }
#tab-arch .ui-card { scroll-margin-top: 4.5rem; }
.solution svg { width: 100%; height: auto; display: block; font-family: var(--font-sans); }
.solution .sd-box { fill: var(--card); stroke: var(--border); stroke-width: 1.5; }
.solution .sd-core { fill: color-mix(in oklab, var(--muted) 60%, transparent); stroke: var(--border); }
.solution .sd-step { fill: var(--background); }
.solution .sd-planned .sd-box { stroke-dasharray: 6 5; fill: transparent; }
.solution .sd-people .sd-box { stroke: var(--chart-2); stroke-width: 2; }
.solution .sd-chan .sd-box { fill: var(--background); }
.solution .sd-node, .solution .sd-hit { cursor: pointer; outline: none; }
.solution .sd-node .sd-box, .solution .sd-hit { transition: stroke var(--duration-fast) var(--ease-in-out); }
.solution .sd-node:hover .sd-box, .solution .sd-node:focus-visible .sd-box, .solution .sd-hit:hover, .solution .sd-hit:focus-visible { stroke: var(--muted-foreground); }
.solution .sd-node.sd-sel .sd-box, .solution .sd-hit.sd-sel { stroke: var(--primary); stroke-width: 2.5; }
.solution .sd-strong { fill: var(--foreground); font-weight: 500; }
.sd-detail { margin-top: 1rem; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem 1.25rem; }
.sd-detail-hdr { display: flex; align-items: center; gap: .625rem; flex-wrap: wrap; }
.sd-what { margin: .75rem 0 0; color: var(--muted-foreground); max-width: 60rem; line-height: 1.5; }
.sd-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem 1.5rem; margin-top: 1rem; }
.sd-block-t { font-size: var(--text-xs); font-weight: var(--font-weight-medium); color: var(--muted-foreground); margin-bottom: .375rem; }
.sd-block p, .sd-block ul { margin: 0; font-size: var(--text-xs); line-height: 1.5; }
.sd-block ul { padding-left: 1rem; }
.sd-chips { display: flex; flex-wrap: wrap; gap: .375rem; }
.sd-gaps { color: var(--destructive); }
.sd-hint { display: none; margin: .5rem 0 0; }
.solution .sd-h { fill: var(--foreground); font-size: 15px; font-weight: 600; }
.solution .sd-t { fill: var(--foreground); font-size: 13px; font-weight: 500; }
.solution .sd-s { fill: var(--muted-foreground); font-size: 11.5px; }
.solution .mid { text-anchor: middle; }
.solution .sd-icon { color: var(--foreground); stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.solution .sd-num { fill: var(--primary); } .solution .sd-numtxt { fill: var(--primary-foreground); font-size: 12px; font-weight: 600; text-anchor: middle; }
.solution .sd-arrow { stroke: var(--muted-foreground); stroke-width: 1.5; fill: none; }
.solution .sd-headfill { fill: var(--muted-foreground); }
.solution .sd-ground { stroke: var(--muted-foreground); stroke-width: 2; }
.solution .sd-p { fill: none; stroke: var(--chart-1); stroke-width: 2; stroke-dasharray: 6 5; }
.solution .sd-s { }
.solution circle.sd-s { fill: none; stroke: var(--destructive); stroke-width: 2.5; }
.solution .sd-hypo { fill: var(--destructive); }
.solution .sd-tri { fill: var(--foreground); }
.solution .sd-parrow { stroke: var(--chart-1); stroke-dasharray: 5 4; }
.solution .sd-plabel { fill: var(--chart-1); font-size: 12px; font-weight: 500; }
.solution .sd-swave { stroke: var(--destructive); stroke-width: 2.5; fill: none; }
.solution .sd-slabel { fill: var(--destructive); font-size: 12px; font-weight: 500; }

.race { display: flex; flex-direction: column; gap: 1.25rem; }
.race-explain { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; color: var(--muted-foreground); line-height: 1.5; }
.race-explain b { color: var(--foreground); font-weight: var(--font-weight-medium); }
.wave-chip { display: inline-block; width: 1.5rem; height: 0; vertical-align: middle; margin-right: .375rem; border-top: 3px solid; }
.wave-chip.p { border-color: var(--chart-1); border-top-style: dashed; } .wave-chip.s { border-color: var(--destructive); } .wave-chip.w { border-color: var(--ok); border-top-width: 6px; }
.race-presets { display: flex; flex-wrap: wrap; gap: .5rem; }
.race-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem 2rem; }
.race-controls label { display: grid; grid-template-columns: 1fr 4rem; gap: .25rem 1rem; align-items: center; }
.race-controls label span { grid-column: 1 / -1; color: var(--muted-foreground); font-size: var(--text-xs); font-weight: var(--font-weight-medium); }
.race-controls b { font-family: var(--font-mono); font-weight: var(--font-weight-medium); text-align: right; }
.ui-slider-native { width: 100%; accent-color: var(--primary); }
.race-result { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.race-big { font-size: var(--text-2xl); font-weight: var(--font-weight-semibold); letter-spacing: var(--tracking-tight); }
.race-big .good { color: var(--ok); font-size: var(--text-4xl); } .race-big .bad { color: var(--destructive); font-size: var(--text-4xl); }
.race-sub { color: var(--muted-foreground); }
.race-chart { display: flex; flex-direction: column; gap: .5rem; }
.race-presets.ui-toggle-group { display: flex; flex-wrap: wrap; width: fit-content; max-width: 100%; }
.race-presets .ui-toggle { padding: 0 .75rem; }
.race-scene { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--card); }
.race-scene svg { display: block; width: 100%; height: auto; font-family: var(--font-sans); }
.rs-earth { fill: color-mix(in oklab, var(--muted) 70%, transparent); }
.rs-ground { stroke: var(--muted-foreground); stroke-width: 2; fill: none; }
.rs-p { fill: color-mix(in oklab, var(--chart-1) 12%, transparent); stroke: var(--chart-1); stroke-width: 2; stroke-dasharray: 6 5; }
.rs-s { fill: color-mix(in oklab, var(--destructive) 14%, transparent); stroke: var(--destructive); stroke-width: 2.5; }
.rs-hypo { fill: var(--destructive); }
.rs-lbl { fill: var(--muted-foreground); font-size: 13px; } .rs-lbl.mid { text-anchor: middle; } .rs-lbl.end { text-anchor: end; font-size: 11px; }
.rs-sensor path { fill: var(--muted-foreground); } .rs-sensor.on path { fill: var(--chart-1); }
.rs-city rect { fill: var(--foreground); } .rs-city.alerted rect { fill: var(--ok); } .rs-city.shaking rect { fill: var(--destructive); }
.rs-alertdot { fill: var(--ok); }
.race-play { display: flex; align-items: center; gap: .75rem; }
.race-play input { flex: 1; }
.race-play .mono { min-width: 5.5rem; text-align: right; }
.race-play .ui-btn svg { width: 1rem; height: 1rem; }
.race-phase { min-height: 1.25rem; }
.rc-now { position: absolute; top: -.25rem; bottom: -.25rem; width: 2px; left: 0; background: var(--foreground); opacity: .7; pointer-events: none; }
.rc-row { display: grid; grid-template-columns: 4.5rem 1fr; align-items: center; gap: .75rem; }
.rc-label { color: var(--muted-foreground); font-size: var(--text-xs); font-weight: var(--font-weight-medium); }
.rc-track { position: relative; height: 2.5rem; border-radius: var(--radius-md); background: var(--muted); }
.rc-seg { position: absolute; top: .5rem; bottom: .5rem; border-radius: var(--radius-sm); }
.rc-seg.travel { background: color-mix(in oklab, var(--chart-1) 30%, transparent); }
.rc-seg.proc { background: var(--chart-1); } .rc-seg.deliver { background: color-mix(in oklab, var(--chart-3) 75%, transparent); }
.rc-seg.warn { background: color-mix(in oklab, var(--chart-2) 55%, transparent); }
.rc-mark { position: absolute; top: 0; bottom: 0; width: 2px; transform: translateX(-1px); }
.rc-mark.p { background: var(--chart-1); } .rc-mark.s { background: var(--destructive); width: 3px; } .rc-mark.a { background: var(--chart-3); }
.rc-mark > span { position: absolute; bottom: calc(100% + 2px); left: 4px; white-space: nowrap; font-size: var(--text-xs); color: var(--muted-foreground); }
.rc-mark.s > span { color: var(--destructive); font-weight: var(--font-weight-medium); }
.rc-row { margin-top: 1rem; }
.rc-axis { display: flex; justify-content: space-between; margin-left: 5.25rem; color: var(--muted-foreground); font-size: var(--text-xs); }
.glossary { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: .75rem; }
.term { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: .75rem 1rem; }
.term-t { font-weight: var(--font-weight-semibold); margin-bottom: .25rem; }
.term-d { color: var(--muted-foreground); font-size: var(--text-xs); line-height: 1.5; }
#tab-arch .arch-flow { margin-bottom: 1rem; }

@media (max-width: 1280px) { .layout { grid-template-columns: minmax(0, 1fr) 28rem; } .sources { grid-template-columns: 1fr; } }
@media (max-width: 1000px) { .race-explain, .race-controls { grid-template-columns: 1fr; } }
.stage-gaps { margin-top: auto; align-self: flex-start; display: inline-flex; align-items: center; gap: .375rem; border: 0; background: none;
  padding: 0; color: var(--destructive); font: inherit; font-size: var(--text-xs); font-weight: var(--font-weight-medium); cursor: pointer; }
.stage-gaps:hover { text-decoration: underline; }
.clock { gap: .375rem; font-weight: var(--font-weight-normal); }
.clock .mono { font-weight: var(--font-weight-medium); color: var(--foreground); }
.clock .tz { color: var(--muted-foreground); }
.event-time { color: var(--muted-foreground); font-size: var(--text-xs); }
.event-time b { color: var(--foreground); font-weight: var(--font-weight-medium); }
.event-card[data-test="true"] { border-color: var(--border); box-shadow: var(--shadow-sm); }
.event-card[data-test="true"] .event-top { color: var(--foreground); }
.ui-badge[data-status="idle"] { color: var(--muted-foreground); }

.list-toolbar .ui-toggle { padding: 0 .625rem; }

/* ================= responsive (last, so it wins over the desktop rules above) ================= */
@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 1rem; gap: 1rem; }
  .col-side { position: static; max-height: none; }
  .map-card #map { height: 24rem; }
  .log-card .ui-card-content { max-height: 18rem; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sources { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .app-header { height: auto; flex-wrap: wrap; padding: .5rem 1rem; gap: .5rem; overflow: visible; }
  .brand { flex: 1; }
  .header-actions { gap: .375rem; }
  .clock .tz { display: none; }                 /* the full zone is in the log header and event cards */
  .app-tabs { order: 3; width: 100%; margin: 0; }
  .app-tabs .ui-tabs-trigger { flex: 1; padding: 0 .375rem; font-size: var(--text-xs); }
  .app-tabs .ui-tabs-trigger svg { display: none; }
  .page-head h1 { font-size: var(--text-xl); }
  .stats { gap: .5rem; }
  .stat { padding: .75rem 1rem; }
  .stat-value { font-size: var(--text-xl); }
  .list-toolbar { flex-direction: column; align-items: stretch; }
  .list-toolbar .ui-toggle-group { display: flex; }
  .list-toolbar .ui-toggle { flex: 1; min-width: 0; padding: 0 .25rem; font-size: var(--text-xs); }
  .toolbar-right { justify-content: space-between; }
  .sort .ui-native-select { min-width: 0; flex: 1; }
  .node-hdr { row-gap: .25rem; }
  .node-meta { margin-left: 0; width: 100%; order: 5; }
  .picker-field:first-child { min-width: 100%; }
  .np-clock { gap: .75rem; }
  .rc-long { display: none; }
  .ui-table.stack thead { display: none; }
  .ui-table.stack, .ui-table.stack tbody, .ui-table.stack tr, .ui-table.stack td { display: block; width: 100%; }
  .ui-table.stack tr { padding: .75rem 0; border-bottom: 1px solid var(--border); }
  .ui-table.stack tr:last-child { border-bottom: 0; }
  .ui-table.stack td { padding: 0; border: 0; white-space: normal; height: auto; }
  .ui-table.stack td:first-child { font-weight: var(--font-weight-medium); }
  .ui-table.stack td:not(:first-child)::before { content: attr(data-label); display: block; margin-top: .5rem;
    color: var(--muted-foreground); font-size: var(--text-xs); font-weight: var(--font-weight-medium); }
  .solution { overflow-x: auto; }
  .solution svg { min-width: 920px; }
  .sd-hint { display: block; }
  .np-clock .mono { font-size: var(--text-2xl); line-height: var(--text-2xl--line-height); white-space: nowrap; }
  .event-card { padding: 1rem; }
  .headline .big { font-size: var(--text-3xl); }
  .cities th, .cities td { padding: .375rem .25rem; font-size: var(--text-xs); }
  .cities th { white-space: normal; vertical-align: bottom; line-height: 1.2; }
  .latency .ui-badge { white-space: normal; height: auto; min-height: 1.25rem; max-width: 100%; }
  .cities td.cd { font-size: var(--text-sm); }
  .ui-dialog, .ui-dialog.wide { width: calc(100% - 2rem); max-width: none; padding: 1.25rem; }
  .legend-title { width: 100%; }
}
