/* ARail app. Layout: one screen. Stage (camera image with AR) left, control panel right;
   on narrow screens the panel moves below the stage.
   Visual language: the corporate design of the Chair of Railway Operations, TU Dresden
   (source of truth: the chair's CD repository, screen version "tud-mobile"). 60/30/10:
   white surfaces (60 %), Türkis #0A777F (30 %: app bar, primary buttons, selected tabs,
   signs), Orange 1 #C85000 as the accent (10 %: pressed toggles, placing, attention).
   Rot 1 #D20F41 marks disruptions, Dunkelblau #001450 the departure boards and labels.
   Dark mode: a Dunkelblau field with lighter accents. Type: Noto Sans. The project website
   keeps its own (blue) design. */
:root {
  --bg: #f3f7f8;
  --surface: #ffffff;
  --surface-2: #f1f8f8;
  --text: #0c1f3a;
  --text-2: #566782;
  --line: #d6e6e7;
  --accent: #0A777F; /* Türkis 1: filled controls */
  --accent-text: #ffffff; /* text on --accent */
  --accent-ink: #0A777F; /* Türkis as text and lines on surfaces */
  --warn: #C85000; /* Orange 1: pressed toggles, placing, attention */
  --warn-text: #ffffff;
  --danger: #D20F41; /* Rot 1 */
  --ok: #0A777F;
  --bar: #0A777F;
  --bar-rule: #0A777F;
  --bar-text: #ffffff;
  --bar-muted: #e6f4f4;
  --bar-line: rgba(255, 255, 255, .6);
  --bar-hover: rgba(0, 20, 80, .2);
  --bar-primary: #ffffff;
  --bar-primary-text: #0A777F;
  --board: #001450; /* Dunkelblau */
  --board-2: #0c2766;
  --board-line: #2a4a92;
  --board-text: #eaf1ff;
  --board-muted: #a0b4d8;
  --board-warn: #f0922e;
  --sign: #0A777F; /* platform numbers, as the signs drawn on the layout */
  --sign-text: #ffffff;
  --stop-sign: #f7d417; /* the German bus stop sign "H" (Zeichen 224): traffic green RAL 6024 on yellow */
  --stop-sign-text: #008351;
  --overlay: rgba(0, 20, 80, .9); /* controls over the camera image (Dunkelblau) */
  --overlay-text: #eaf1ff;
  --overlay-ok: #36b8bf;
  --overlay-warn: #f0922e;
  --overlay-bad: #ff667e;
  --stage: #00061a;
  --focus: #0A777F;
  --font: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Noto Sans Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000c2e; --surface: #00103a; --surface-2: #0c2766; --text: #eaf1ff; --text-2: #a0b4d8; --line: #2a4a92;
    --accent: #36b8bf; --accent-text: #001450; --accent-ink: #36b8bf; --warn: #f0922e; --warn-text: #001450; --danger: #ff667e; --ok: #36b8bf;
    --bar: #001450; --bar-rule: #0A777F; --bar-text: #ffffff; --bar-muted: #a0b4d8; --bar-line: #2a4a92; --bar-hover: rgba(255, 255, 255, .08);
    --bar-primary: #36b8bf; --bar-primary-text: #001450;
    --board: #001450; --board-2: #0c2766; --board-line: #2a4a92; --board-text: #eaf1ff; --board-muted: #a0b4d8; --board-warn: #f0922e;
    --stage: #00030f; --focus: #36b8bf;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000c2e; --surface: #00103a; --surface-2: #0c2766; --text: #eaf1ff; --text-2: #a0b4d8; --line: #2a4a92;
  --accent: #36b8bf; --accent-text: #001450; --accent-ink: #36b8bf; --warn: #f0922e; --warn-text: #001450; --danger: #ff667e; --ok: #36b8bf;
  --bar: #001450; --bar-rule: #0A777F; --bar-text: #ffffff; --bar-muted: #a0b4d8; --bar-line: #2a4a92; --bar-hover: rgba(255, 255, 255, .08);
  --bar-primary: #36b8bf; --bar-primary-text: #001450;
  --board: #001450; --board-2: #0c2766; --board-line: #2a4a92; --board-text: #eaf1ff; --board-muted: #a0b4d8; --board-warn: #f0922e;
  --stage: #00030f; --focus: #36b8bf;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }

/* ------------------------------------------------------------------ frame */
.app { display: grid; grid-template-rows: auto 1fr; min-height: 100%; }
.bar {
  display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap;
  padding: 10px 16px 9px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--bar); color: var(--bar-text); border-bottom: 3px solid var(--bar-rule);
}
.bar :focus-visible { outline-color: var(--bar-text); }
.identity { display: flex; align-items: center; gap: 14px; min-width: 0; }
/* chair logo: the CD file's canvas (1014 × 321) has empty space right of the wordmark; show the
   left 800 units (room for wider fallback fonts than Arial) */
.cro-logo { --h: 40px; display: block; height: var(--h); width: calc(var(--h) * 800 / 321); object-fit: cover; object-position: left center; flex: none; }
.identity .divider { width: 1px; align-self: stretch; margin-block: 3px; background: var(--bar-line); }
.brand { display: flex; align-items: baseline; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.3rem; line-height: 1.2; }
.brand .sign { background: var(--bar-primary); color: var(--bar-primary-text); padding: 0 5px; border-radius: 3px; margin-right: 1px; }
.brand small { font-weight: 500; color: var(--bar-muted); letter-spacing: .1em; font-size: .72rem; margin-left: 7px; text-transform: uppercase; }
/* the layout name takes the free space of the first row and is shortened (…) down to 10ch rather than
   wrapping the bar onto a second row (that would cost the stage height on tablets) */
.layout-name { flex: 1000 1 0; color: var(--bar-muted); font-size: .9rem; min-width: 10ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30ch; }
.bar .spacer { flex: 1; }
.sources { display: flex; gap: 8px; flex-wrap: wrap; }
.bar .btn { background: transparent; border-color: var(--bar-line); color: var(--bar-text); }
.bar .btn:hover { background: var(--bar-hover); border-color: var(--bar-text); }
.bar .btn.primary { background: var(--bar-primary); border-color: var(--bar-primary); color: var(--bar-primary-text); }
.bar select { background: transparent; color: var(--bar-text); border: 1px solid var(--bar-line); border-radius: var(--radius); padding: 8px 10px; font-weight: 500; }
.bar select:hover { background: var(--bar-hover); border-color: var(--bar-text); }
.bar select option { background: var(--surface); color: var(--text); }

.bar .short { display: none; }
@media (max-width: 1099px) {
  /* the chair logo needs room: short labels keep the bar in one row on tablets (1024 px) */
  .bar .long { display: none; }
  .bar .short { display: inline; }
}
@media (max-width: 640px) {
  .bar { gap: 8px; padding-block: 8px 7px; }
  .bar .long { display: none; }
  .bar .short { display: inline; }
  .bar .btn, .bar select { padding: 6px 9px; font-size: .84rem; }
  .cro-logo { --h: 32px; }
  .identity { gap: 10px; }
  .layout-name { display: none; }
  .sources { width: 100%; }
  .sources select { flex: 1 1 120px; min-width: 0; }
}

.main { display: grid; gap: 0; min-height: 0; }
@media (min-width: 1000px) {
  .main { grid-template-columns: minmax(0, 1fr) 390px; height: calc(100dvh - var(--bar-h, 60px)); }
  .panel { overflow-y: auto; border-left: 1px solid var(--line); }
}

/* ------------------------------------------------------------------ stage */
.stage { position: relative; background: var(--stage); display: grid; place-items: center; min-height: 240px; overflow: hidden; }
.stage :focus-visible { outline-color: #ffffff; }
@media (max-width: 999px) { .stage { max-height: 72dvh; } }
.stage canvas { display: block; touch-action: manipulation; }
.stage canvas.editing { touch-action: none; cursor: crosshair; }
.stage canvas.dragging { cursor: grabbing; }
.hud { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 500; background: var(--overlay); color: var(--overlay-text); backdrop-filter: blur(4px); }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .9; }
.chip.ok { color: var(--overlay-ok); }
.chip.warn { color: var(--overlay-warn); }
.chip.bad { color: var(--overlay-bad); }
.chip.info::before { display: none; }
.stage-tools { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.stage-tools .btn { background: var(--overlay); color: var(--overlay-text); border-color: rgba(255, 255, 255, .22); padding: 6px 10px; font-size: .82rem; }
.stage-tools .btn:hover { border-color: var(--overlay-text); }
.stage-tools .btn[aria-pressed="true"] { background: var(--warn); border-color: var(--warn); color: var(--warn-text); }
.toast { position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%); max-width: min(560px, calc(100% - 32px)); background: var(--board); color: var(--board-text); border-left: 5px solid var(--warn); padding: 10px 14px; border-radius: var(--radius); font-weight: 500; box-shadow: 0 6px 24px rgba(0, 6, 26, .4); }
.placing { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--overlay); color: var(--overlay-text); border-left: 5px solid var(--warn); padding: 8px 10px; border-radius: var(--radius); font-size: .88rem; }
.placing strong { font-weight: 700; }
.placing .grow { flex: 1; min-width: 12ch; }
.empty-stage { color: var(--board-muted); padding: 24px; text-align: center; max-width: 42ch; }

/* ------------------------------------------------------------------ panel */
.panel { position: relative; background: var(--surface); min-width: 0; }
.tabs { display: flex; position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { flex: 1 0 auto; border: 0; background: none; padding: 12px 8px 10px; font-weight: 500; font-size: .92rem; color: var(--text-2); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); } /* same weight: the tabs must not shift */
.tabpanel { padding: 14px 16px 28px; display: grid; gap: 18px; }
.section { display: grid; gap: 8px; }
.section > h2 { margin: 0; font-size: .74rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-ink); display: flex; align-items: center; gap: 8px; }
.section > h2 .count { font-weight: 500; color: var(--text-2); letter-spacing: 0; text-transform: none; }
.hint { margin: 0; color: var(--text-2); font-size: .85rem; }
.hint.error { color: var(--danger); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: var(--radius); padding: 8px 12px; font-weight: 500; font-size: .9rem; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 9px; font-size: .82rem; }
.btn[aria-pressed="true"] { background: var(--warn); border-color: var(--warn); color: var(--warn-text); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:disabled:hover { border-color: var(--line); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 11px; font-weight: 500; cursor: pointer; border-right: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 700; }

.field { display: grid; gap: 3px; font-size: .8rem; color: var(--text-2); min-width: 0; }
.field > span small { color: var(--text-2); font-weight: 400; }
.field input[type="text"], .field input[type="number"], .field input[type="url"], .field select, .field textarea {
  width: 100%; min-width: 0; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; font-size: .92rem;
}
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--accent); }
.field textarea { font-family: var(--mono); font-size: .8rem; min-height: 8em; }
.field .help { font-size: .76rem; }
.field.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; }
.field input[type="color"] { width: 44px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.fields .wide { grid-column: 1 / -1; }
input[type="range"] { width: 100%; }

/* palette of object types */
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.palette button { display: grid; gap: 4px; justify-items: start; text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius); padding: 9px 10px; cursor: pointer; font-weight: 500; font-size: .86rem; }
.palette button small { font-weight: 400; color: var(--text-2); font-size: .72rem; }
.palette button:hover { border-color: var(--accent); }
.palette button[aria-pressed="true"] { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); }
.palette h3 { grid-column: 1 / -1; margin: 4px 0 0; font-size: .72rem; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); }

.list { display: grid; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; list-style: none; margin: 0; padding: 0; }
.list button, .list .item { display: flex; gap: 8px; align-items: center; justify-content: space-between; width: 100%; text-align: left; border: 0; background: var(--surface); padding: 8px 10px; cursor: pointer; font-size: .9rem; }
.list button:hover { background: var(--surface-2); }
.list > li + li { border-top: 1px solid var(--line); }
.list .meta { color: var(--text-2); font-size: .78rem; font-family: var(--mono); }
.list button[aria-current="true"] { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); box-shadow: inset 4px 0 0 var(--accent); font-weight: 500; }
.list .item { cursor: default; }

/* departure board */
.board { background: var(--board); color: var(--board-text); border: 1px solid var(--board-line); border-radius: var(--radius); padding: 12px; display: grid; gap: 14px; }
.board .stop { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; align-items: center; }
.board .num { grid-row: span 4; background: var(--sign); color: var(--sign-text); font-weight: 700; font-size: 1.3rem; min-width: 2.4rem; height: 2.7rem; padding: 0 6px; display: grid; place-items: center; border-radius: 4px; align-self: start; }
.board .num.bus { background: var(--stop-sign); color: var(--stop-sign-text); } /* the German bus stop sign: green H on yellow */
.board .title { font-weight: 500; font-size: 1rem; }
.board .figures { display: flex; gap: 12px; flex-wrap: wrap; font-variant-numeric: tabular-nums; font-size: .86rem; }
.board .status { font-size: .84rem; color: var(--board-muted); }
.board .status.warn { color: var(--board-warn); font-weight: 500; }
.board .meter { height: 6px; background: rgba(255, 255, 255, .14); border-radius: 3px; overflow: hidden; }
.board .meter > i { display: block; height: 100%; }
.board .calls { display: flex; gap: 6px; flex-wrap: wrap; grid-column: 2; }
.board .calls .btn { background: var(--board-2); border-color: var(--board-line); color: var(--board-text); padding: 4px 8px; font-size: .78rem; }
.board .calls .btn:hover:not(:disabled) { border-color: var(--board-text); }

.disruption { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; padding: 9px 10px; border-left: 4px solid var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-radius: 4px; }
.disruption strong { font-weight: 700; }
.disruption small { color: var(--text-2); grid-column: 1; }
.disruption .btn { grid-row: span 2; grid-column: 2; }
.scenario { display: grid; gap: 4px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); }
.scenario strong { font-weight: 500; }
.scenario p { margin: 0; color: var(--text-2); font-size: .84rem; }
.scenario .progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.scenario .progress > i { display: block; height: 100%; background: var(--warn); }

.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 0; font-size: .86rem; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--text-2); margin-right: 6px; vertical-align: middle; }
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.bad { background: var(--danger); }
code, .mono { font-family: var(--mono); font-size: .82em; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .82rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--text-2); font-weight: 500; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
details { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
details summary { cursor: pointer; font-weight: 500; }
details summary:hover { color: var(--accent-ink); }
details[open] summary { margin-bottom: 8px; }
/* time of day (Simulate panel) */
.clockface { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: var(--radius); background: var(--board); color: var(--board-text); border: 1px solid var(--board-line); }
.clockface .time { font-family: var(--mono); font-size: 2rem; font-weight: 500; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.clockface .daytime { color: var(--board-muted); font-size: .86rem; }
.clockface .daytime.night, .clockface .daytime.dusk { color: var(--board-warn); }
.legend-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 14px; font-size: .86rem; }
.legend-list li { display: flex; align-items: center; gap: 8px; }
.legend-list b { margin-left: auto; font-weight: 500; }
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 1px solid rgba(0, 0, 0, .35); }
.town-stats { display: grid; gap: 8px; }
.chip.clock { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* survey a video (Build panel, marker map) */
.survey { display: grid; gap: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.survey .subhead { margin: 0; font-size: .9rem; font-weight: 500; }
.survey progress { width: 100%; accent-color: var(--accent); }
.survey .plot { color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.survey .plot:empty { display: none; }
.marker-plot { display: block; width: 100%; max-height: 220px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
