:root {
  --bg: #eef1f6;
  --ink: #1f2937;
  --muted: #6b7280;
  --card: #ffffffee;
  --line: #d7dce5;
  --available: #22c55e;
  --preparing: #f59e0b;
  --charging: #3b82f6;
  --faulted: #ef4444;
  --offline: #94a3b8;
  --unavailable: #a1a1aa;
  --accent: #f5b301;
  --radius: 14px;
  --shadow: 0 8px 30px #1f29371a;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  --sky: radial-gradient(1200px 800px at 40% 40%, #ffffff 0%, var(--bg) 60%, #dfe5ee 100%);
  --ground: #f7f9fc;
  --ground-line: #e2e7ef;
  --scene-ink: #6b7280;
  display: grid;
  grid-template-columns: 1fr 380px;
  grid-template-rows: auto 1fr;
  background: var(--sky);
  transition: background 1.5s;
  overflow: hidden;
}

h1, h2, h3, h4 { text-wrap: balance; margin: 0; }
p, li { text-wrap: pretty; }

.top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 24px;
}
.brand h1 { font-size: 22px; letter-spacing: -0.02em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.live { margin-left: 8px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #e5e7eb; }
.live.ok { background: #dcfce7; color: #166534; }
.live.ok::before { content: "● "; animation: pulse 1.6s infinite; }
.live.err { background: #fee2e2; color: #991b1b; }

.banner { margin-left: 6px; font-size: 12px; padding: 2px 10px; border-radius: 99px; background: #fef3c7; color: #92400e; }
.rules { list-style: none; padding: 0; margin: 6px 0; }
.rules li { padding: 3px 0; font-size: 12px; }
.running { background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.kpis { display: flex; gap: 18px; }
.kpi { display: flex; align-items: center; gap: 10px; background: var(--card); padding: 8px 14px 8px 8px; border-radius: 99px; box-shadow: var(--shadow); }
.kpi svg { width: 40px; height: 40px; transform: rotate(-90deg); }
.kpi circle { fill: none; stroke-width: 5; }
.kpi .track { stroke: #e5e7eb; }
.kpi .value { stroke: var(--available); stroke-linecap: round; stroke-dasharray: 0 200; transition: stroke-dasharray .6s, stroke .3s; }
.kpi b { display: block; font-size: 17px; }
.kpi span { font-size: 11px; color: var(--muted); }
.kpi[data-kpi="charging"] .value { stroke: var(--charging); }
.kpi[data-kpi="power"] .value { stroke: var(--accent); }
.kpi[data-kpi="faulted"] .value { stroke: var(--faulted); }

.stage { position: relative; min-height: 0; }
#scene { width: 100%; height: 100%; display: block; }

.panel {
  grid-row: 2;
  grid-column: 2;
  margin: 0 16px 16px 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; }
.tabs button.active { background: #f3f4f6; color: var(--ink); font-weight: 600; }
.tab-body { padding: 16px; overflow: auto; flex: 1; font-size: 13px; }
.hint { color: var(--muted); }

.panel h3 { font-size: 18px; margin-bottom: 4px; }
.panel h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.meta { color: var(--muted); margin: 0 0 8px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; color: #fff; font-size: 12px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: #f8fafc; border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 16px; }
.stat span { color: var(--muted); font-size: 11px; }
.bar { height: 8px; background: #e5e7eb; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s; }
.bar i.over { background: var(--faulted); }
table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 12px; }
th { color: var(--muted); font-weight: 500; }

.control { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.control label { width: 100%; color: var(--muted); font-size: 12px; }
.control input[type=range] { flex: 1; }
.control output { min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
button.act, select {
  font: inherit; font-size: 12px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer;
}
button.act:hover { border-color: #9ca3af; }
button.act.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
button.act.danger { color: #b91c1c; border-color: #fecaca; background: #fff5f5; }
button.act:disabled { opacity: .5; cursor: progress; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 11px; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); background: #fff; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.site-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.site-row h5 { margin: 0 0 6px; font-size: 13px; }

.feed, .legend { position: absolute; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); font-size: 12px; }
.feed { left: 16px; top: 8px; width: 380px; max-height: 58%; display: flex; flex-direction: column; }
.feed h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.feed ol { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 4px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; }
.feed li time { color: var(--muted); font-variant-numeric: tabular-nums; }
.feed li.error b { color: #b91c1c; }
.feed li.ok b { color: #15803d; }
.muted { color: var(--muted); }
.legend { right: 16px; bottom: 16px; display: flex; gap: 12px; padding: 8px 12px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot.available { background: var(--available); } .dot.preparing { background: var(--preparing); }
.dot.charging { background: var(--charging); } .dot.faulted { background: var(--faulted); }
.dot.offline { background: var(--offline); } .dot.unavailable { background: var(--unavailable); }

.toast { position: fixed; left: 50%; top: 80px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); z-index: 10; }
.toast.err { background: #b91c1c; }

/* Scene */
.ground { fill: var(--ground); stroke: var(--ground-line); transition: fill 1.5s; }
.platform { stroke: #d5dbe5; stroke-width: 1; }
.clickable { cursor: pointer; }
.selected .platform, .station.selected .ped-top { stroke: var(--ink); stroke-width: 2; }
.label-card rect { fill: #ffffff; filter: drop-shadow(0 4px 10px #1f293722); }
.label-card text { font-size: 13px; fill: var(--ink); }
.label-card .small { font-size: 11px; fill: var(--muted); }
.label-card .barbg { fill: #e5e7eb; }
.label-card .barfg { fill: var(--accent); transition: width .6s; }
.label-card .barfg.over { fill: var(--faulted); }
.badge-down { fill: var(--faulted); }
.weather text { font-size: 12px; fill: var(--ink); }
.weather .w-sub { fill: var(--muted); font-size: 11px; }

.wire { fill: none; stroke: #c9d1dc; stroke-width: 2; stroke-linecap: round; }
.flow { fill: none; stroke: transparent; stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 3 9; }
.flow.on { stroke: var(--accent); animation: flow var(--speed, 1.5s) linear infinite; }
.flow.grid.on { stroke-width: 3.5; }
.flow.down { stroke: var(--faulted); stroke-dasharray: 6 6; animation: none; opacity: .8; }
.car { transition: opacity .4s; }
.car.hidden { opacity: 0; }
.glow { animation: pulse 1.6s infinite; }

@keyframes flow { to { stroke-dashoffset: -24; } }
@keyframes pulse { 50% { opacity: .45; } }

@media (max-width: 1100px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto 60vh auto; overflow: auto; }
  .panel { grid-column: 1; grid-row: 3; margin: 0 16px 16px; }
  .kpis { flex-wrap: wrap; gap: 8px; }
  .feed { display: none; }
}

/* Time of day: the whole map shifts, so it is obvious at a glance. */
body.phase-morning { --sky: linear-gradient(180deg, #fde2c4 0%, #f9d5e5 45%, #e8eef7 100%); --ground: #fbf3ea; --ground-line: #f0dfcc; }
body.phase-evening { --sky: linear-gradient(180deg, #fb923c 0%, #c084fc 55%, #6d6a9c 100%); --ground: #efe3dc; --ground-line: #d9c4b8; }
body.phase-night { --sky: radial-gradient(1200px 800px at 40% 30%, #1e3a5f 0%, #0f1b30 60%, #0a1222 100%); --ground: #1c2a40; --ground-line: #2b3d58; --scene-ink: #cbd5e1; }
.phase-evening .building, .phase-evening .platform { filter: brightness(.88) saturate(.9) sepia(.15); }
.phase-night .building { filter: brightness(.5) saturate(.7); }
.phase-night .platform { filter: brightness(.45) saturate(.6); }
.phase-night .canopy, .phase-night .pylon, .phase-night .tf-top { filter: brightness(.6); }
.phase-night .wire { stroke: #3b4c66; }
.phase-night .top h1, .phase-night .top .sub { color: #e5e7eb; }
.window { fill: #cbd5e1; opacity: .55; transition: fill 1.5s, opacity 1.5s; }
.phase-evening .window { fill: #fde68a; opacity: .8; }
.phase-night .window { fill: #fde047; opacity: 1; filter: drop-shadow(0 0 3px #fde047); }
.solar-panel { fill: #334155; opacity: .85; }
.phase-night .solar-panel { opacity: .5; }
.scene-text { font-size: 12px; fill: var(--scene-ink); text-anchor: middle; }
.moon-cut { fill: #ffffff; }
.pylon polyline { fill: none; stroke: #9ca3af; stroke-width: 1.4; }
.pylon .pylon-arm { stroke: #9ca3af; stroke-width: 1.6; }
.wire.overhead { stroke-width: 1.6; }
.clock { font-weight: 600; color: var(--ink); margin-right: 6px; }
.phase-pill { padding: 2px 8px; border-radius: 99px; font-size: 12px; margin-left: 4px; background: #e0f2fe; color: #075985; }
.phase-night .phase-pill { background: #1e293b; color: #fde68a; }
.phase-evening .phase-pill { background: #ffedd5; color: #9a3412; }
.phase-morning .phase-pill { background: #fce7f3; color: #9d174d; }
.metrics { align-self: center; font-size: 12px; text-decoration: none; color: var(--ink); background: var(--card); padding: 9px 14px; border-radius: 99px; box-shadow: var(--shadow); white-space: nowrap; }
.metrics:hover { background: #fff; }
.kpis { gap: 10px; }
.kpi { padding: 6px 12px 6px 6px; }
.kpi svg { width: 34px; height: 34px; }
.kpi b { font-size: 15px; }
.kpi[data-kpi="price"] .value { stroke: #a855f7; }
.kpi[data-kpi="incidents"] .value { stroke: var(--faulted); }
.kpi.alarm { box-shadow: 0 0 0 2px #fecaca, var(--shadow); }

/* Station markers */
.alert-ring { fill: none; stroke: var(--faulted); stroke-width: 2.5; animation: ping 1.4s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes ping { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(1.8); opacity: 0; } }
.plug-light { stroke: #ffffffaa; stroke-width: 1; }
.legend .sep { border-left: 1px solid var(--line); padding-left: 12px; }
.car-icon { display: inline-block; width: 14px; height: 8px; border-radius: 3px; background: #e5e7eb; border: 1px solid #9ca3af; margin-right: 6px; vertical-align: 0; position: relative; }
.car-icon::after { content: ""; position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--charging); right: -2px; top: -3px; }

/* Incidents feed */
.feed-head { all: unset; cursor: pointer; display: flex; gap: 8px; align-items: center; padding: 10px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.feed-head span:first-child { font-weight: 700; color: var(--ink); }
.feed-head .chev { margin-left: auto; font-style: normal; transition: transform .2s; }
.feed.collapsed .chev { transform: rotate(-90deg); }
.feed.collapsed .feed-body { display: none; }
.feed-body { overflow: auto; padding: 0 14px 10px; }
.feed ol { list-style: none; margin: 0; padding: 0; }
.inc { border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; padding: 8px 10px; margin: 6px 0; background: #fff; cursor: pointer; }
.inc.critical { border-left-color: var(--faulted); }
.inc.warning { border-left-color: var(--preparing); }
.inc.info { border-left-color: var(--charging); }
.inc.recovered { opacity: .75; border-left-color: var(--available); }
.inc-title { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.inc-title small { color: var(--muted); font-weight: 400; white-space: nowrap; }
.inc ul { list-style: none; margin: 6px 0 0; padding: 0; }
.inc li { display: grid; grid-template-columns: 74px 1fr; gap: 6px; padding: 3px 0; font-size: 12px; border: 0; }
.inc li b { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding-top: 1px; }
.inc li.detected b { color: #b91c1c; } .inc li.response b { color: #1d4ed8; } .inc li.update b { color: #a16207; } .inc li.recovered b { color: #15803d; }
.inc li em { color: var(--muted); font-style: normal; font-size: 11px; }
.linkish { all: unset; cursor: pointer; color: var(--muted); font-size: 11px; text-decoration: underline; margin-top: 6px; display: inline-block; }
.log li { padding: 3px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; font-size: 11px; }
.log li time { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Compact control panel */
.compact { padding: 12px 14px; }
.compact h4 { margin: 12px 0 6px; }
.row { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .what { min-width: 0; }
.row .what b { display: block; font-size: 13px; }
.row .what span { color: var(--muted); font-size: 11px; }
.switch { position: relative; width: 38px; height: 22px; border-radius: 99px; background: #d1d5db; border: 0; cursor: pointer; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch.on { background: var(--available); }
.switch.on::after { left: 19px; }
.mini { font: inherit; font-size: 11px; padding: 4px 9px; border-radius: 7px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.mini.danger { color: #b91c1c; border-color: #fecaca; background: #fff5f5; }
.mini.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.mini:disabled { opacity: .45; cursor: not-allowed; }
table.chaos td { padding: 4px 2px; }
table.chaos select { padding: 3px 6px; font-size: 11px; }
.spark { width: 100%; height: 46px; display: block; margin-top: 4px; }
.spark path { fill: none; stroke: #a855f7; stroke-width: 1.5; }
.spark .area { fill: #a855f71a; stroke: none; }
.spark .now { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 2 2; }
.spark .hot { fill: #ef44441a; }
.active-rules { margin: 4px 0 0; padding: 0; list-style: none; }
.active-rules li { font-size: 11px; color: #92400e; padding: 2px 0; }
.canopy { opacity: .3; }
.phase-night .clock, .phase-night .weather text { fill: #e5e7eb; color: #e5e7eb; }
.phase-night .weather .w-sub { fill: #94a3b8; }
.weather text { fill: var(--ink); }
.phase-evening .clock { color: #1f1235; }
.inc.monitoring { border-left-color: var(--preparing); background: #fffbeb; }
.feed li.inc { display: block; }
.brand { min-width: 0; flex: 1; }
.sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.kpi span, .kpi b { white-space: nowrap; }
.top { gap: 14px; }

/* Load: below 30 % green, 30-70 % yellow, 70 % and up red */
.label-card .barfg.load-low, .bar i.load-low { fill: var(--available); background: var(--available); }
.label-card .barfg.load-mid, .bar i.load-mid { fill: #eab308; background: #eab308; }
.label-card .barfg.load-high, .bar i.load-high { fill: var(--faulted); background: var(--faulted); }
.kpi[data-kpi="power"][data-load="low"] .value { stroke: var(--available); }
.kpi[data-kpi="power"][data-load="mid"] .value { stroke: #eab308; }
.kpi[data-kpi="power"][data-load="high"] .value { stroke: var(--faulted); }
.kpi[data-kpi="queue"] .value { stroke: var(--preparing); }
.kpi[data-kpi="margin"] .value { stroke: var(--available); }

/* Selection: impossible to miss */
.site.selected .platform { stroke: #2563eb; stroke-width: 4; filter: drop-shadow(0 0 10px #2563ebaa); }
.station.selected .ped-top { stroke: #2563eb; stroke-width: 2.5; }

/* Active things are green */
.rules li.active, .active-rules li { color: #15803d; font-weight: 500; }

.queue-text { font-size: 11px; font-weight: 700; fill: #b45309; }
.phase-night .queue-text { fill: #fbbf24; }
#scene { cursor: grab; touch-action: none; }
#scene.dragging { cursor: grabbing; }
.zoom { position: absolute; right: 16px; bottom: 64px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--card); box-shadow: var(--shadow); font-size: 18px; cursor: pointer; color: var(--ink); }
.zoom button:hover { background: #fff; }
.money { width: 100%; }
.money td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.money tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.neg { color: #b91c1c; } .pos { color: #15803d; }
.select-ring.top { fill: #3b82f633; stroke: #3b82f6; stroke-width: 4; pointer-events: none; animation: pulse 1.4s infinite; filter: drop-shadow(0 0 6px #3b82f6); }
.phase-night .select-ring.top { stroke: #93c5fd; fill: #93c5fd33; }

/* Canopies are scenery: clicks go through to the chargers underneath. */
.canopy { pointer-events: none; }

/* Incidents strip: full width of the map, cards side by side */
.feed { left: 16px; right: 16px; width: auto; max-height: 32%; }
#incidents { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 8px; }
#incidents > li.muted { grid-column: 1 / -1; }
.feed li.inc { margin: 0; }

/* Tabs with colour */
.tabs button { background: #f8fafc; }
.tabs button[data-tab="details"].active { background: #dbeafe; color: #1e40af; }
.tabs button[data-tab="controls"].active { background: #fef3c7; color: #92400e; }
.tabs button[data-tab="details"]:not(.active):hover { background: #eff6ff; }
.tabs button[data-tab="controls"]:not(.active):hover { background: #fffbeb; }

/* Scenario list */
.row.scen { justify-content: flex-start; }
.row.scen .what { flex: 1; }
.scen-icon { font-size: 20px; width: 30px; text-align: center; flex: none; }
.row.scen.is-running { background: #fff7ed; border-radius: 8px; }

/* Waiting lane and demand line */
.lane { fill: #cbd5e1; opacity: .45; }
.phase-night .lane { fill: #334155; opacity: .8; }
.label-card .demand-line { fill: #475569; }
.queue-text { font-size: 12px; }

/* Running scenario: affected sites and chargers in orange */
.site.in-scenario .platform { stroke: #f97316; stroke-width: 4; stroke-dasharray: 10 6; animation: march 1.2s linear infinite; }
.site.selected.in-scenario .platform { stroke: #2563eb; }
.scenario-ring { fill: #f9731622; stroke: #f97316; stroke-width: 3; pointer-events: none; animation: pulse 1.2s infinite; }
@keyframes march { to { stroke-dashoffset: -32; } }
.queue-text { paint-order: stroke; stroke: #ffffffcc; stroke-width: 3px; }
.phase-night .queue-text { stroke: #0f1b30cc; }

/* Incidents: one line each */
#incidents { display: block; }
.inc-row { list-style: none; border-radius: 8px; padding: 0; margin: 2px 0; background: #fff; border: 1px solid var(--line); }
.inc-row .line { display: flex; align-items: center; gap: 10px; padding: 6px 10px; cursor: pointer; white-space: nowrap; min-width: 0; font-size: 12px; }
.inc-row .line:hover { background: #f8fafc; }
.inc-row .sev { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.inc-row.critical .sev { background: var(--faulted); } .inc-row.warning .sev { background: var(--preparing); }
.inc-row.info .sev { background: var(--charging); }
.inc-row.monitoring .sev { background: var(--preparing); animation: pulse 1.4s infinite; }
.inc-row.recovered .sev { background: var(--available); }
.inc-row.open.critical .sev, .inc-row:not(.recovered):not(.monitoring).critical .sev { animation: pulse 1s infinite; }
.inc-row.recovered { opacity: .8; }
.inc-row .title { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; max-width: 34%; color: var(--ink); text-transform: none; letter-spacing: 0; }
.inc-row .chain { flex: 1; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.inc-row .chain .arrow { margin: 0 5px; color: #cbd5e1; }
.step.detected { color: #b91c1c; } .step.response { color: #1d4ed8; } .step.update { color: #a16207; } .step.recovered { color: #15803d; font-weight: 600; }
.inc-row small { flex: none; color: var(--muted); }
.inc-row .steps { list-style: none; margin: 0; padding: 4px 10px 8px 29px; border-top: 1px dashed var(--line); }
.inc-row .steps li { display: flex; gap: 10px; align-items: baseline; padding: 2px 0; font-size: 12px; white-space: nowrap; min-width: 0; }
.inc-row .steps time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.inc-row .steps b { flex: none; width: 72px; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.inc-row .steps span { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.inc-row .steps em { color: var(--muted); font-style: normal; flex: none; font-size: 11px; }
.inc-row .steps li.detected b { color: #b91c1c; } .inc-row .steps li.response b { color: #1d4ed8; }
.inc-row .steps li.update b { color: #a16207; } .inc-row .steps li.recovered b { color: #15803d; }
.feed { max-height: 26%; }
.feed li.inc-row { display: block; }
.inc-row .title { max-width: 45%; }
.inc-row small { margin-left: auto; }

.car.stale { filter: grayscale(1) brightness(.85); opacity: .5; }
.ok { color: #15803d; } .bad { color: #b91c1c; } .warn { color: #b45309; } .info { color: #1d4ed8; }
.st { font-weight: 600; }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { box-shadow: 0 0 0 2px #bfdbfe, var(--shadow); }
.kpi-value { font-size: 20px; font-weight: 700; margin: 4px 0 10px; }
.legend span[title] { cursor: help; }
.stat b i.val { font-style: normal; }
.age { font-size: 11px; color: var(--muted); }
.age.warn { color: #b45309; font-weight: 600; } .age.bad { color: #b91c1c; font-weight: 700; }

.inc-row .opened { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.batt-fill { fill: var(--available); opacity: .85; } .batt-fill.low { fill: var(--faulted); }
.batt-light { fill: #94a3b8; stroke: #fff; stroke-width: 1; }
.batt-light.charging { fill: var(--charging); animation: pulse 1.2s infinite; }
.batt-light.discharging { fill: var(--preparing); animation: pulse 1.2s infinite; }
.batt-text { font-size: 11px; font-weight: 700; }
.label-card .battery-line { fill: #475569; }

/* Human in the loop */
.questions { margin: 0 0 6px; }
.q-head { list-style: none; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #92400e; font-weight: 700; margin: 2px 0 4px; }
.question { list-style: none; display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 8px 10px; border-radius: 8px; background: #fffbeb; border: 1px solid #fcd34d; margin-bottom: 4px; font-size: 12px; }
.feed li.question { display: flex; }
.q-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.q-clock { font-variant-numeric: tabular-nums; color: #92400e; font-size: 11px; min-width: 62px; text-align: right; }
.callouts { position: absolute; inset: 0; pointer-events: none; }
.callout { position: absolute; transform: translate(-50%, calc(-100% - 18px)); pointer-events: auto; background: #fffbeb; border: 2px solid #f59e0b; border-radius: 10px; padding: 8px 10px; box-shadow: var(--shadow); font-size: 12px; width: 280px; z-index: 5; }
.callout::after { content: ""; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%) rotate(45deg); width: 14px; height: 14px; background: #fffbeb; border-right: 2px solid #f59e0b; border-bottom: 2px solid #f59e0b; }
.callout .q-text { white-space: normal; margin-bottom: 6px; }
.kpi[data-kpi="incidents"] b { font-size: 13px; }

/* Service levels */
table.slo td { vertical-align: top; padding: 8px 4px; }
table.slo td.v { font-size: 15px; font-weight: 700; white-space: nowrap; }
table.slo td.t { color: var(--muted); white-space: nowrap; font-size: 11px; }
.slo-pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #e5e7eb; color: #374151; white-space: nowrap; }
tr.met .slo-pill { background: #dcfce7; color: #166534; } tr.met td.v { color: #15803d; }
tr.close .slo-pill { background: #fef3c7; color: #92400e; } tr.close td.v { color: #b45309; }
tr.missed .slo-pill { background: #fee2e2; color: #991b1b; } tr.missed td.v { color: #b91c1c; }
.step.triage { color: #7c3aed; font-weight: 600; } .step.decision { color: #b45309; }
.inc-row .steps li.triage b { color: #7c3aed; } .inc-row .steps li.decision b { color: #b45309; }
/* Header: the brand block keeps its width; KPI chips wrap onto a second row instead of squeezing it */
.top { align-items: flex-start; flex-wrap: nowrap; }
.brand { flex: 0 0 auto; min-width: 300px; max-width: 420px; }
.sub { flex-wrap: wrap; }
.clock { white-space: nowrap; }
.phase-pill { white-space: nowrap; }
.kpis { flex: 1 1 auto; flex-wrap: wrap; justify-content: flex-end; row-gap: 8px; }
/* Incident rows: one line when it fits, wrap to a second or third when it doesn't (never cut the title) */
.inc-row .line { white-space: normal; flex-wrap: wrap; row-gap: 2px; align-items: baseline; }
.inc-row .title { max-width: none; overflow: visible; text-overflow: clip; flex: 0 1 auto; }
.inc-row .chain { flex: 1 1 240px; overflow: visible; text-overflow: clip; white-space: normal; }
.inc-row .chain .step { white-space: nowrap; }
.inc-row .sev { align-self: center; }
.inc-row .steps li.metrics-line b { color: #0f766e; }
.inc-row .steps li.metrics-line span { color: #0f766e; white-space: normal; }
.inc-row .steps li { white-space: normal; }

.handover { position: fixed; inset: 0; background: #0f172a55; display: flex; align-items: flex-start; justify-content: center; padding-top: 90px; z-index: 20; }
.handover[hidden] { display: none; }
.handover-card { background: #fff; border-radius: 16px; box-shadow: 0 24px 60px #0f172a40; width: min(640px, 92vw);
                 padding: 22px 24px 20px; max-height: 80vh; overflow: auto; font-size: 13px; color: var(--ink);
                 display: flex; flex-direction: column; gap: 16px; }
.ho-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.ho-head h3 { font-size: 19px; letter-spacing: -0.01em; }
.ho-head p { margin: 2px 0 0; font-size: 12.5px; }
.ho-head .act { flex: none; padding: 8px 16px; border-radius: 10px; }
.ho-ai { background: #f5f3ff; border: 1px solid #e9e5ff; border-radius: 12px; padding: 12px 14px 10px; }
.ho-badge { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
            color: #6d28d9; background: #ede9fe; padding: 2px 8px; border-radius: 99px; }
.ho-ai ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.5; }
.ho-ai li { margin: 3px 0; text-wrap: pretty; }
.ho-ai li::marker { color: #a78bfa; }
.ho-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ho-tile { background: #f8fafc; border: 1px solid #eef2f7; border-radius: 12px; padding: 12px 14px; display: flex;
           flex-direction: column; gap: 2px; min-width: 0; }
.ho-tile > b { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.ho-tile > span { color: var(--muted); font-size: 12px; text-wrap: pretty; }
.ho-tile.ok > b { color: #15803d; }
.ho-tile.bad > b { color: #b91c1c; }
.ho-tile.warn { background: #fffbeb; border-color: #fde68a; }
.ho-tile.warn > b { color: #b45309; }
.ho-kinds { grid-column: 1 / -1; }
.ho-sec h4 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 8px; }
.ho-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ho-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 12px;
              background: #f8fafc; border-radius: 10px; }
.ho-eta { flex: none; font-size: 11.5px; color: var(--muted); }
.ho-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ho-chip { font-size: 11.5px; padding: 3px 9px; border-radius: 99px; background: #f1f5f9; color: #334155; white-space: nowrap; }
.ho-chip b { font-weight: 700; margin-left: 2px; }
.ho-chip.bad { background: #fee2e2; color: #991b1b; font-weight: 600; }
.ho-foot { margin: 10px 0 0; font-size: 11.5px; color: var(--muted); }
@media (max-width: 700px) {
  .handover { padding: 12px; align-items: flex-end; }
  .handover-card { width: 100%; max-height: 85svh; padding: 18px 16px 16px; gap: 14px; }
  .ho-list li { flex-direction: column; gap: 2px; }
}
/* KPI chips: shrink with the window down to a minimum, then wrap to a second row */
.kpis { flex: 1 1 auto; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: clamp(4px, 0.6vw, 10px); min-width: 0; }
.kpi { flex: 1 1 0; min-width: 112px; max-width: 190px; padding: clamp(3px, 0.35vw, 6px) clamp(6px, 0.8vw, 12px) clamp(3px, 0.35vw, 6px) clamp(3px, 0.35vw, 6px); gap: clamp(5px, 0.6vw, 10px); }
.kpi svg { width: clamp(24px, 2.2vw, 34px); height: clamp(24px, 2.2vw, 34px); flex: none; }
.kpi > div { min-width: 0; }
.kpi b { font-size: clamp(12px, 1.05vw, 15px); overflow: hidden; text-overflow: ellipsis; }
.kpi span { font-size: clamp(9.5px, 0.75vw, 11px); overflow: hidden; text-overflow: ellipsis; display: block; }
.metrics { flex: 0 0 auto; padding: clamp(6px, 0.6vw, 9px) clamp(8px, 0.9vw, 14px); font-size: clamp(11px, 0.8vw, 12px); }
.brand { min-width: clamp(240px, 22vw, 300px); }
.brand h1 { font-size: clamp(18px, 1.5vw, 22px); }
/* Chips size to their content (never cut text); the row wraps before anything gets truncated */
.kpi { flex: 0 1 auto; min-width: 0; max-width: none; }
.kpi b, .kpi span { overflow: visible; text-overflow: clip; white-space: nowrap; }
/* Size chips from the space the header actually has: shrink first, wrap only at the minimum sizes */
.kpis { container-type: inline-size; flex: 1 1 0; }
.kpi { gap: clamp(4px, 0.7cqi, 10px); padding: clamp(3px, 0.45cqi, 6px) clamp(6px, 0.9cqi, 12px) clamp(3px, 0.45cqi, 6px) clamp(3px, 0.45cqi, 6px); }
.kpi svg { width: clamp(24px, 2.6cqi, 34px); height: clamp(24px, 2.6cqi, 34px); }
.kpi b { font-size: clamp(12px, 1.12cqi, 15px); }
.kpi span { font-size: clamp(9.5px, 0.84cqi, 11px); }
.metrics { padding: clamp(5px, 0.6cqi, 9px) clamp(8px, 1cqi, 14px); font-size: clamp(10.5px, 0.9cqi, 12px); }
.kpis { gap: clamp(4px, 0.6cqi, 10px); }

.title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.title .live { margin-left: 0; white-space: nowrap; }

.scenario { border-top: 1px solid var(--line); padding: 8px 14px 10px; font-size: 12px; }
.scenario .label { text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-size: 11px; margin-right: 6px; }
.scenario .row { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.scenario .row small { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.scenario.on { background: #fffbeb; border-radius: 0 0 var(--radius) var(--radius); }
.scenario .bar { height: 4px; background: #fde68a; border-radius: 99px; margin: 6px 0 4px; overflow: hidden; }
.scenario .bar i { display: block; height: 100%; background: #d97706; transition: width 1s linear; }
.scenario p { margin: 0; text-wrap: pretty; }

/* Tablet and phone: one scrolling column; incidents and legend move below the map. */
@media (max-width: 1100px) {
  html, body { height: auto; }
  body { display: block; overflow-x: hidden; overflow-y: auto; }
  .top { flex-wrap: wrap; }
  .brand { flex: 1 1 100%; min-width: 0; max-width: none; }
  .kpis { flex: 1 1 100%; justify-content: flex-start; }
  .stage { display: flex; flex-direction: column; }
  #scene { height: auto; aspect-ratio: 1600 / 1000; touch-action: pan-y; }
  .feed { display: flex; position: static; order: 2; width: auto; max-height: none; margin: 8px 16px 0; }
  .feed-body { max-height: 45vh; }
  .legend { position: static; order: 3; flex-wrap: wrap; margin: 8px 16px; }
  .zoom { top: 8px; right: 8px; bottom: auto; }
  .panel { margin: 0 16px 16px; }
}

@media (max-width: 700px) {
  .top { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px; }
  .top > .brand, .top > .kpis { flex: none; width: 100%; min-width: 0; max-width: 100%; }
  .kpis { container-type: normal; flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding: 2px 2px 6px;
          scroll-snap-type: x proximity; scrollbar-width: none; }
  .kpis::-webkit-scrollbar { display: none; }
  .kpi, .metrics { flex: 0 0 auto; scroll-snap-align: start; }
  .kpi { padding: 4px 10px 4px 4px; gap: 6px; }
  .kpi svg { width: 28px; height: 28px; }
  .kpi b { font-size: 14px; }
  .kpi span { font-size: 10px; }
  .metrics { padding: 8px 12px; font-size: 12px; }
  .feed, .legend { margin-left: 8px; margin-right: 8px; }
  .panel { margin: 0 8px 12px; }
  .legend { gap: 8px 12px; font-size: 11px; }
  .legend .sep { flex-basis: 100%; border-left: 0; padding-left: 0; }
  .callouts { display: none; }  /* questions are in the incidents list right below */
  .stage, .feed, .feed-body, .legend, .panel { min-width: 0; max-width: 100%; }
  #incidents { grid-template-columns: 1fr; }
  .inc-row .chain { flex-basis: 100%; }
  .inc-row .line small { margin-left: auto; }
  .question { flex-wrap: wrap; }
  table.slo td.t { white-space: normal; }
  table.slo td { padding: 6px 3px; }
  .zoom button { width: 38px; height: 38px; }
}

/* Chains have no spaces between steps, so wrap them as flex items. */
.inc-row .chain { display: flex; flex-wrap: wrap; align-items: baseline; row-gap: 2px; min-width: 0; }
.inc-row .line small { flex: 0 1 auto; white-space: normal; text-align: right; min-width: 0; }

/* Phones: the map fitted to the width, incidents as a bottom sheet with a one-line legend on top. */
@media (max-width: 700px) {
  #scene { height: auto; }
  /* Zoom buttons in a row in the map's empty bottom-right corner; pinch works too. */
  .zoom { flex-direction: row; top: auto; bottom: 6px; right: 6px; gap: 4px; }
  .zoom button { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; opacity: .9; }
  #scene { touch-action: pan-y; }
  /* Details and control panel: half a screen, scrolls inside, so a tap on the map shows its effect right away. */
  .panel { max-height: 50svh; }
  .panel .tab-body { overflow-y: auto; min-height: 0; flex: 1 1 auto; }
  .feed { position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto; z-index: 5; margin: 0; max-height: 72vh;
          border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px #0f172a33; background: #fff; padding-bottom: env(safe-area-inset-bottom); }
  .feed-body { max-height: none; flex: 1 1 auto; min-height: 0; }
  .feed-head { padding: 8px 14px; }
  /* Collapsed: the header, any question waiting for an answer and the scenario line stay visible. */
  .feed.collapsed .feed-body { display: block; padding-bottom: 0; }
  .feed.collapsed #incidents, .feed.collapsed #log-toggle, .feed.collapsed #log { display: none; }
  .feed.collapsed .questions:empty { display: none; }
  .legend { margin: 6px 8px; padding: 6px 10px; gap: 4px 10px; font-size: 10.5px; justify-content: center; }
  .legend .sep { display: none; }
  .scenario { padding: 6px 14px 8px; }
  .panel { margin: 0 8px 12px; }
}

/* The map and its overlays (zoom buttons, callouts) share one box, so they line up on every screen size. */
.map-wrap { position: relative; height: 100%; min-height: 0; }
@media (max-width: 1100px) { .map-wrap { height: auto; order: 1; } }

/* Dropdowns next to the small buttons: same height, text size and corners, with our own arrow. */
.control select, .tab-body select {
  appearance: none; -webkit-appearance: none; font: inherit; font-size: 11px; line-height: 1.3;
  padding: 4px 24px 4px 9px; border-radius: 7px; border: 1px solid var(--line); background-color: #fff; color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; max-width: 100%; cursor: pointer;
}
.control select:focus-visible, .tab-body select:focus-visible { outline: 2px solid #93c5fd; outline-offset: 1px; }

/* Incident row: dot | time | title + chain (wraps under the title) | status note (own column, wraps). */
.inc-row .line { display: grid; grid-template-columns: 9px auto minmax(0, 1fr) minmax(0, max-content); column-gap: 10px;
                 align-items: baseline; white-space: normal; }
.inc-row .line .sev { align-self: start; margin-top: 4px; }
.inc-row .what { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 10px; row-gap: 2px; min-width: 0; }
.inc-row .what .title { flex: 0 1 auto; min-width: 0; }
/* The chain sits beside the title only if all of it fits; otherwise the whole chain moves under the title. */
.inc-row .what .chain { flex: 0 1 max-content; max-width: 100%; display: flex; flex-wrap: wrap; align-items: baseline;
                        row-gap: 2px; min-width: 0; }
.inc-row .line small { max-width: 34ch; margin-left: 0; text-align: right; justify-self: end; white-space: normal; line-height: 1.35; }
@media (max-width: 700px) {
  .inc-row .line { grid-template-columns: 9px auto minmax(0, 1fr); }
  .inc-row .line small { grid-column: 3; justify-self: start; text-align: left; max-width: none; margin-top: 2px; }
}

/* KPI explanations split into labelled lines. */
.kpi-facts { margin: 8px 0 14px; font-size: 12.5px; }
.kpi-facts dt { font-weight: 600; color: var(--ink); }
.kpi-facts dd { margin: 1px 0 9px; color: #374151; line-height: 1.45; text-wrap: pretty; }
