/* Layout: a transit control room. The 3D map is the stage; parishes beside it; scenario lab and evidence charts below.
   Two themes: light (default) and dark ("night shift"). The page follows the system setting until the
   Light / Dark switch is used; data-theme on <html> wins in both directions. */
:root {
  color-scheme: light;
  --bg: #EEF3F1;
  --panel: #FFFFFF;
  --panel-2: #F5F8F7;
  --stage: #E4ECEA;
  --line: #D5DFDC;
  --ink: #15201E;
  --muted: #586764;
  --teal: #1F6E74;
  --teal-deep: #2B7A80;
  --orange: #D24E12;
  --amber: #C97F22;
  --on-accent: #FFFFFF;
  --shadow: rgba(21, 32, 30, 0.18);
  --f-display: "Overpass", "Segoe UI", system-ui, sans-serif;
  --f-body: "Inter", "Segoe UI", system-ui, sans-serif;
  --f-mono: "Overpass Mono", ui-monospace, Consolas, monospace;
  --r: 12px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  color-scheme: dark;
  --bg: #0B1110; --panel: #121B1A; --panel-2: #172322; --stage: #0B1110; --line: #24332F; --ink: #E4ECEA; --muted: #8FA29E;
  --teal: #5BB3B8; --teal-deep: #2B7A80; --orange: #FF7033; --amber: #E8AA5A; --on-accent: #0B1110; --shadow: rgba(0, 0, 0, 0.45);
} }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B1110; --panel: #121B1A; --panel-2: #172322; --stage: #0B1110; --line: #24332F; --ink: #E4ECEA; --muted: #8FA29E;
  --teal: #5BB3B8; --teal-deep: #2B7A80; --orange: #FF7033; --amber: #E8AA5A; --on-accent: #0B1110; --shadow: rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; }
.theme { display: inline-flex; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; align-self: center; }
.theme button { border: 0; background: transparent; border-radius: 999px; padding: 4px 11px; cursor: pointer; font-size: 0.8rem; font-weight: 600; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.theme button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.theme svg { width: 14px; height: 14px; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { font-family: var(--f-body); font-size: 14px; line-height: 1.5; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: clamp(1.35rem, 1rem + 1.4vw, 1.9rem); font-weight: 800; line-height: 1.05; }
h2 { font-size: 1.25rem; font-weight: 800; }
h3 { font-size: 0.95rem; font-weight: 700; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.eyebrow { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app { max-width: 1600px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 16px 28px; display: grid; gap: 14px; }

/* Header */
.bar { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: end; justify-content: space-between; }
.brand { display: grid; gap: 4px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, auto)); gap: 8px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: grid; min-width: 0; }
.kpi .v { font-family: var(--f-display); font-weight: 800; font-size: 1.35rem; line-height: 1.1; }
.kpi:nth-child(1) .v, .kpi:nth-child(2) .v { color: var(--orange); }
.kpi:nth-child(4) .v { color: var(--teal); }
.kpi .l { font-size: 0.76rem; color: var(--muted); }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; } }

/* View tabs */
.views { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.views button { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 14px 5px; cursor: pointer; font-family: var(--f-display); font-weight: 700; font-size: 0.86rem; }
.views button[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Grid */
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "stage side" "lab lab" "surface surface" "day model"; gap: 14px; }
.lab { grid-area: lab; padding: 14px; display: grid; gap: 12px; }
.lab-head { display: flex; justify-content: space-between; align-items: end; gap: 10px; flex-wrap: wrap; }
.tests { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1000px) { .tests { grid-template-columns: minmax(0, 1fr); } }
.test { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 10px; align-content: start; min-width: 0; }
.test.active { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.test h3 { font-size: 1rem; }
.field { display: flex; align-items: center; gap: 10px; font-size: 0.84rem; }
.field label { color: var(--muted); white-space: nowrap; }
.field input[type=range] { flex: 1; min-width: 60px; accent-color: var(--teal); }
.field output { font-family: var(--f-mono); font-weight: 600; min-width: 5ch; text-align: right; }
.field select { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; }
.note { margin: 0; font-size: 0.78rem; color: var(--muted); }
.run { justify-self: start; border: 0; border-radius: 8px; padding: 7px 16px 6px; background: var(--teal); color: var(--on-accent); font-family: var(--f-display); font-weight: 800; cursor: pointer; }
.run:hover { filter: brightness(1.1); }
.result { border-top: 1px dashed var(--line); padding-top: 10px; display: grid; gap: 7px; font-size: 0.84rem; }
.result p { margin: 0; }
.result .hint { color: var(--muted); }
.result .big { font-family: var(--f-display); font-weight: 800; font-size: 1.7rem; line-height: 1.1; color: var(--orange); }
.result .big .ok { color: var(--teal); }
.result .unit { font-family: var(--f-body); font-weight: 500; font-size: 0.85rem; color: var(--muted); }
.rbar { display: grid; grid-template-columns: 6.8rem minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 0.78rem; }
.rbar .rl { color: var(--muted); }
.rbar .rt { height: 9px; background: var(--panel); border-radius: 5px; overflow: hidden; }
.rbar .rt span { display: block; height: 100%; border-radius: 5px; transition: width .5s ease; }
.rbar .rv { font-family: var(--f-mono); font-size: 0.76rem; }
.scn { display: block; font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--teal); margin-bottom: 3px; }
.stage { grid-area: stage; }
.side { grid-area: side; }
.surface-card { grid-area: surface; }
.day-card { grid-area: day; }
.model-card { grid-area: model; }
@media (max-width: 1100px) {
  .grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "lab" "side" "surface" "day" "model"; }
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.card { padding: 14px; display: grid; gap: 8px; align-content: start; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.chart { width: 100%; min-width: 0; }
.chart.small { height: 260px; }
.chart.surface { height: 460px; }
.chart.rank { height: 640px; }
@media (max-width: 700px) { .chart.surface { height: 380px; } .chart.rank { height: 560px; } }

/* Stage */
.stage { position: relative; height: min(76vh, 780px); min-height: 460px; overflow: hidden; background: var(--stage); }
.deck { position: absolute; inset: 0; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.hud { position: absolute; z-index: 2; }
.top-left { left: 14px; top: 14px; max-width: min(460px, calc(100% - 200px)); }
.top-right { right: 14px; top: 14px; }
.bottom-left { left: 14px; bottom: 92px; }
.bottom { left: 14px; right: 14px; bottom: 14px; }
.caption { margin: 0; background: color-mix(in srgb, var(--bg) 78%, transparent); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 0.86rem; backdrop-filter: blur(6px); }
.caption b { color: var(--orange); font-weight: 600; }
.cam { display: flex; gap: 4px; background: color-mix(in srgb, var(--bg) 78%, transparent); border: 1px solid var(--line); border-radius: 10px; padding: 4px; backdrop-filter: blur(6px); }
.cam button { border: 0; background: transparent; border-radius: 7px; padding: 5px 9px; cursor: pointer; font-family: var(--f-mono); font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.cam button[aria-pressed="true"] { background: var(--panel-2); color: var(--ink); }
.legend { background: color-mix(in srgb, var(--bg) 82%, transparent); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 0.76rem; display: grid; gap: 4px; backdrop-filter: blur(6px); max-width: calc(100% - 28px); }
.legend b { font-weight: 600; font-size: 0.78rem; }
.legend .row { display: flex; gap: 7px; align-items: center; }
.sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.ramp { width: 140px; height: 10px; border-radius: 3px; }
.panel-soft { background: color-mix(in srgb, var(--bg) 82%, transparent); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; backdrop-filter: blur(6px); }
.ctl { display: flex; align-items: center; gap: 9px; font-size: 0.84rem; flex: 1 1 320px; min-width: 0; }
.ctl label { color: var(--muted); white-space: nowrap; }
.ctl input[type=range] { flex: 1; min-width: 80px; accent-color: var(--orange); }
.ctl output { font-family: var(--f-mono); font-weight: 600; min-width: 5.5ch; }
.play { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--orange); color: var(--on-accent); cursor: pointer; font-size: 0.85rem; flex: none; }
.play[aria-pressed="true"] { background: var(--ink); }
.pill { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 0.78rem; flex: none; }
.pill[aria-pressed="true"] { border-color: var(--orange); color: var(--orange); font-weight: 600; }
.toggles { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.84rem; }
.toggles label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.toggles input { accent-color: var(--teal); }
@media (max-width: 700px) {
  .stage { height: 72vh; min-height: 520px; }
  .top-left { left: 10px; top: 54px; max-width: calc(100% - 20px); }
  .caption { font-size: 0.76rem; padding: 6px 9px; }
  .top-right { right: 10px; top: 10px; }
  .bottom-left { left: 10px; bottom: 150px; max-width: 70%; font-size: 0.68rem; padding: 6px 8px; gap: 2px; }
  .legend .routes-row { display: none; }
  .bottom { left: 10px; right: 10px; bottom: 10px; }
}

/* Side panel */
.sel { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.stats div { display: grid; }
.stats .v { font-family: var(--f-display); font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stats .l { color: var(--muted); font-size: 0.75rem; }
.link { justify-self: start; background: none; border: 0; padding: 0; color: var(--teal); cursor: pointer; text-decoration: underline; font-size: 0.82rem; }
.side .chart-head { padding: 12px 16px 0; }
.side .chart { padding: 0 6px 8px; }

/* Tooltip */
.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--ink); color: var(--bg); border-radius: 9px; padding: 8px 10px; font-size: 0.8rem; line-height: 1.4; max-width: 260px; box-shadow: 0 8px 24px var(--shadow); }
.tip b { font-weight: 700; }
.tip .k { opacity: .7; }

.foot { display: grid; gap: 4px; font-size: 0.76rem; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
