:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  color: #e9f6f7;
  background: #091522;
  --panel: #0f2030;
  --panel-raised: #142738;
  --line: #254050;
  --muted: #a0b6c4;
  --accent: #67e5ce;
  --alert: #f56e78;
  --depot: #b395ff;
  --current: #f9b85e;
  --deviation: #f0d47d;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
a { color: var(--accent); text-decoration: none; }
button:disabled { opacity: .5; cursor: wait; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(16px, 3.4vw, 54px);
  border-bottom: 1px solid #203445;
  background: #0b1928;
}
.brand { display: flex; align-items: center; gap: 13px; color: #dbe9ed; font-weight: 600; }
.brand span:first-child {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: .08em;
  border-right: 1px solid var(--line);
  padding-right: 13px;
}
.top-actions, .dialog-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.button, .square, .filters button {
  border: 1px solid var(--line);
  color: #e8f4f5;
  background: #152c3b;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: .85rem;
  font-weight: 650;
}
.button:hover, .square:hover, .filters button:hover { background: #1e3c49; }
.button.quiet { color: var(--muted); background: transparent; }
.button.accent { color: #0b2928; background: var(--accent); border-color: var(--accent); }
.square { display: grid; place-items: center; width: 41px; height: 41px; padding: 0; font-size: 1.25rem; }
.workspace { padding: clamp(15px, 2.6vw, 38px) clamp(16px, 3.4vw, 54px); max-width: 1840px; margin: 0 auto; }
.overview { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 19px; }
h1 { margin: 0 0 6px; font-size: clamp(1.72rem, 3.2vw, 2.6rem); letter-spacing: -.035em; }
h2, h3, p { margin: 0; }
.source-time { color: var(--muted); font-size: .82rem; }
.metrics { display: flex; gap: clamp(11px, 2vw, 31px); font-variant-numeric: tabular-nums; }
.metrics > div { display: grid; gap: 3px; min-width: 65px; border-left: 1px solid var(--line); padding-left: 12px; }
.metrics span { font-size: 1.6rem; font-weight: 700; color: var(--accent); line-height: 1; }
.metrics .urgent span { color: var(--alert); }
.metrics small { color: var(--muted); white-space: nowrap; font-size: .72rem; }
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(330px, 385px); gap: 15px; }
.map-stage, .rail { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.map-stage { position: relative; isolation: isolate; height: max(540px, calc(100vh - 291px)); background: #071422; }
#map { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#smoke { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.puff { position: absolute; border-radius: 50%; width: 6px; height: 6px; background: #ffb2ba; animation: smoke 2.1s ease-out infinite; opacity: 0; }
.puff:nth-child(2n) { animation-delay: .8s; }
@keyframes smoke { 0% { opacity: .68; transform: translate(0, 0); } 100% { opacity: 0; transform: translate(9px, -18px) scale(2.2); } }
@media (prefers-reduced-motion: reduce) { .puff { animation: none; } }
.map-tools { display: grid; gap: 6px; position: absolute; right: 13px; top: 13px; }
.map-legend {
  display: flex; flex-wrap: wrap; gap: 6px 13px; position: absolute; left: 12px; bottom: 31px;
  right: auto; max-width: calc(100% - 24px); padding: 10px 11px; border: 1px solid #294253;
  border-radius: 10px; background: #0a1b28ed; font-size: .73rem; color: #d9e9ed;
}
.map-legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-key, .count { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.legend-key.vu23, .count.vu23 { background: var(--alert); }
.legend-key.depot, .count.depot { background: var(--depot); }
.legend-key.current, .count.current { background: var(--current); }
.legend-key.deviation, .count.deviation { background: var(--deviation); }
.geometry-source { position: absolute; left: 15px; bottom: 9px; color: #a1b7c2; font-size: .65rem; pointer-events: none; }
.rail { background: var(--panel); display: flex; flex-direction: column; height: max(540px, calc(100vh - 291px)); }
.rail-controls { padding: 13px; border-bottom: 1px solid var(--line); }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 9px; padding: 0 0 0 10px; background: #0b1a28; }
.search > span { color: var(--accent); font-size: 1.17rem; }
.search input { width: 100%; min-width: 0; border: 0; color: #e7f1f5; background: transparent; padding: 10px 0; font-size: .86rem; }
.search input::placeholder { color: #98acba; }
.search input:focus-visible { outline-offset: 0; }
.search .refresh { height: 38px; flex: 0 0 38px; border: 0; border-left: 1px solid var(--line); border-radius: 0 8px 8px 0; }
.filters { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.filters button { font-size: .74rem; padding: 6px 9px; background: transparent; color: var(--muted); }
.filters button[aria-pressed=true] { color: #b1f8eb; background: #173e45; border-color: #34716e; }
.rail-body { padding: 12px 13px; overflow: auto; min-height: 0; }
.rail-body:empty { display: none; }
#groups { flex: 1; }
#detail:not(:empty) { flex: 1; }
#detail:not(:empty) + #groups { display: none; }
.list-intro { margin-bottom: 9px; color: var(--muted); font-size: .78rem; }
.group-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr); width: 100%; gap: 10px; text-align: left;
  border: 1px solid #223a4b; margin-bottom: 6px; padding: 10px; border-radius: 10px; background: #122535; color: #edf8f9;
}
.group-row:hover { border-color: #4d797b; background: #163341; }
.group-row strong, .group-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-row strong { font-size: .91rem; }
.group-row small { font-size: .75rem; margin-top: 3px; color: #aec4d0; }
.count { width: auto; height: auto; min-width: 30px; align-self: center; padding: 6px; text-align: center; color: #091522; border-radius: 8px; font-weight: 800; font-size: .89rem; }
.group-row .exception { color: var(--deviation); }
.detail-heading { margin: 11px 0 13px; }
.detail-heading h2 { font-size: 1.3rem; margin-bottom: 4px; line-height: 1.2; overflow-wrap: anywhere; }
.detail-heading p { color: var(--muted); font-size: .86rem; margin-top: 5px; }
.detail-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.wagon { border: 1px solid #294252; border-radius: 9px; background: #112432; padding: 10px; margin-bottom: 7px; overflow-wrap: anywhere; }
.wagon-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 5px; }
.wagon-head strong { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.distance { font-weight: 750; color: var(--accent); font-size: .82rem; }
.wagon p { font-size: .78rem; color: #b8cbd5; margin: 4px 0; }
.text-button { font-size: .8rem; border: 0; background: transparent; color: var(--accent); padding: 3px 0; text-align: left; }
.text-button:hover { text-decoration: underline; }
.empty-state { padding: 12px; border: 1px dashed #355669; border-radius: 10px; font-size: .88rem; color: var(--muted); }
dialog { max-width: min(460px, calc(100% - 30px)); color: #eaf8fa; border: 1px solid var(--line); border-radius: 14px; background: #102333; padding: 20px; }
dialog::backdrop { background: #030a14bd; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
dialog p { margin: 13px 0; font-size: .89rem; color: #b8ced8; }
.pair-code { user-select: all; overflow-wrap: anywhere; padding: 11px; margin: 7px 0; border: 1px solid #3e696c; border-radius: 8px; background: #071823; font-family: Consolas, monospace; color: var(--accent); }
.revoke { margin-top: 14px; }
#toast:empty { display: none; }
#toast { position: fixed; z-index: 10; right: 15px; bottom: 15px; max-width: min(420px, calc(100vw - 30px)); padding: 11px 15px; color: #e9fcf7; background: #173e43; border: 1px solid #4e8f90; border-radius: 9px; }
@media (max-width: 920px) {
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .map-stage { height: max(360px, 54vh); }
  .rail { min-height: 300px; height: min(540px, 62vh); }
}
@media (max-width: 600px) {
  .top { padding: 10px 12px; }
  .brand span:last-child { display: none; }
  .brand span:first-child { border-right: 0; padding-right: 0; }
  .button { font-size: .77rem; }
  .workspace { padding: 14px 12px 18px; }
  .overview { display: grid; gap: 13px; margin-bottom: 13px; }
  .metrics { width: 100%; justify-content: space-between; gap: 5px; }
  .metrics > div { min-width: 0; padding-left: 7px; }
  .metrics span { font-size: 1.3rem; }
  .map-tools { top: 9px; right: 9px; }
  .map-tools .square { width: 39px; height: 39px; }
  .map-legend { gap: 7px 9px; padding: 7px 9px; font-size: .67rem; }
}

.timeline {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 13px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #0c2030;
}
.timeline-heading { display: grid; flex: 1 0 200px; gap: 3px; }
.timeline-heading strong { font-size: .8rem; }
#history-status { color: var(--muted); font-size: .74rem; }
.timeline-controls, .timeline-changes { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.timeline-controls .square { width: 32px; height: 34px; }
.timeline-controls .button { padding: 7px 8px; }
.timeline-controls input, .route-card select {
  border: 1px solid #355365; border-radius: 8px; min-height: 34px; background: #112638;
  color: #e5f5fa; font: inherit; font-size: .8rem; padding: 5px 7px; max-width: 100%;
}
.timeline button:disabled, .timeline input:disabled { opacity: .46; cursor: default; }
.timeline button[aria-pressed=true] { color: #b1f8eb; background: #173e45; border-color: #34716e; }
.timeline-changes:empty { display: none; }
.change { font-size: .7rem; border: 1px solid #324b5e; background: #142c3c; padding: 5px 7px; border-radius: 7px; white-space: nowrap; }
.change.in { color: #8ff0c1; }
.change.out { color: #ffacb5; }
.legend-icon { width: 17px; height: 17px; }
.route-banner {
  position: absolute; top: 13px; left: 13px; max-width: calc(100% - 84px); padding: 10px 13px;
  background: #0a202cf5; border: 1px solid #448682; border-radius: 10px; pointer-events: none; box-shadow: 0 2px 12px #04122080;
}
.route-banner[hidden] { display: none; }
.route-banner span { display: block; color: #cee3e6; font-size: .75rem; overflow-wrap: anywhere; }
.route-banner strong { display: block; color: #8ff8dd; font-size: .97rem; margin-top: 3px; }
.route-card {
  display: grid; gap: 7px; background: #102d38; border: 1px solid #356568;
  border-radius: 11px; padding: 10px; margin-bottom: 10px;
}
.route-card .route-heading { color: #f0fffc; font-size: .86rem; }
.route-card .route-km { font-weight: 750; color: #91f8dd; font-variant-numeric: tabular-nums; }
.route-card p, .route-card .route-label { font-size: .75rem; line-height: 1.35; color: #b3ced7; }
.route-card .index-line { color: #ffda92; }
.route-card .route-label { display: grid; gap: 4px; }
.route-junctions { display: flex; gap: 4px 7px; flex-wrap: wrap; align-items: baseline; }
.route-junctions .text-button { font-size: .73rem; }
#change-pulses { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.change-pulse { position: absolute; width: 26px; height: 26px; border: 2px solid #a8fce1; border-radius: 50%; animation: rise .85s ease-out both; }
@keyframes rise { from { transform: translate(-50%, -50%) scale(.8); opacity: 1; } to { transform: translate(-50%, -50%) scale(2.1); opacity: 0; } }
.canvas-swap { animation: appear .3s ease-out both; }
@keyframes appear { from { opacity: .68; } to { opacity: 1; } }
@media (max-width: 600px) {
  .timeline { gap: 7px; padding: 8px; }
  .timeline-heading { flex-basis: 100%; }
  .timeline-controls { gap: 4px; }
  .route-banner { top: 9px; left: 9px; padding: 7px 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .canvas-swap { animation: none; }
  .change-pulse { display: none; }
}

.wagon-links { display: flex; flex-wrap: wrap; gap: 2px 12px; }

.watch-panel { min-height: 0; border-bottom: 1px solid var(--line); background: #102738; }
.watch-panel summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; gap: 6px; padding: 8px 12px; font-size: .78rem; font-weight: 700; }
.watch-panel summary::after { content: "▸"; color: var(--muted); }
.watch-panel[open] summary::after { content: "▾"; }
.watch-panel summary small { margin-left: auto; font-weight: 500; color: var(--muted); }
.watch-list { max-height: 106px; overflow: auto; padding: 0 9px 6px; }
.watch-list:empty { display: none; }
.watch-row { display: grid; gap: 5px; grid-template-columns: minmax(0, 1fr) 29px; margin: 0 0 4px; }
.watch-row:last-child { margin-bottom: 0; }
.watch-row .watch-location { min-width: 0; text-align: left; padding: 4px 7px; }
.watch-row strong, .watch-row small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.watch-row strong { font: 700 .73rem 'Segoe UI', sans-serif; }
.watch-row small { margin-top: 2px; font: .68rem 'Segoe UI', sans-serif; color: #b6ced9; }
.watch-row .watch-toggle { padding: 0; color: #ffda7e; font-size: 1rem; }
.watch-row .watch-toggle[aria-pressed=true] { background: #503d23; border-color: #795f32; }
.wagon .due-message, .due-message { color: #ffdc85; }
.wagon .vu23-message, .vu23-message { color: #ff9bac; }
.alert-chip { font-size: .72rem; display: inline-block; border: 1px solid #805f30; color: #ffda7d;
  border-radius: 7px; padding: 4px 6px; background: #352c26; }
#map-alerts { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pin-alert { position: absolute; transform: translate(-50%, -50%); animation: pin-alert 1.65s ease-in-out infinite; }
.pin-alert.vu23 { width: 37px; height: 37px; border: 2px solid #ff5a72; border-radius: 50%; filter: drop-shadow(0 0 3px #ff526f); }
.pin-alert.due, .legend-deadline { display: inline-grid; place-items: center; width: 22px; height: 20px;
  clip-path: polygon(50% 0, 100% 98%, 0 98%); background: #ffce62; color: #2b200d;
  font: 900 13px 'Segoe UI', sans-serif; padding-top: 4px; }
.legend-deadline { width: 13px; height: 11px; }
.legend-trail { width: 13px; height: 3px; background: #a9aaff; border-radius: 3px; }
.map-legend [hidden] { display: none; }
@keyframes pin-alert { 0%, 100% { opacity: 1; } 50% { opacity: .32; } }
@media (prefers-reduced-motion: reduce) { .pin-alert { animation: none; } }
.track-heading { display: grid; gap: 6px; padding: 10px; margin-bottom: 8px; border: 1px solid #4c577d; border-radius: 10px; background: #1a2b45; }
.track-heading h2 { font-size: 1.1rem; overflow-wrap: anywhere; }
.track-heading p { color: #c0cfeb; font-size: .77rem; }
.track-list { display: grid; gap: 5px; margin-top: 10px; }
.track-entry { width: 100%; min-width: 0; text-align: left; padding: 7px 9px; border-left: 3px solid #8395e8; }
.track-entry strong { display: block; }
.track-entry small { display: block; margin-top: 4px; white-space: normal; font-weight: 450; color: #b9cfdf; }
.track-entry.rejected { border-left-color: #ff6686; }
.track-entry[aria-current=true] { background: #273d5c; border-color: #9d9cff; }
.track-entry.rejected[aria-current=true] { border-color: #ff6686; }
.track-banner { border-color: #706db2; }
.track-banner strong { color: #cbc5ff; }
@media (max-width: 920px) {
  .watch-list { max-height: 86px; }
  .rail { height: min(650px, 75vh); }
}

#station-dialog { width: min(560px, calc(100% - 30px)); max-width: none; max-height: min(680px, calc(100% - 38px)); }
#station-title { font-size: 1.15rem; }
#station-actions { margin: 11px 0; }
.station-section { padding: 9px 10px; border: 1px solid #294553; border-radius: 9px; margin-top: 7px; background: #10293a; }
.station-section h3 { font-size: .83rem; margin-bottom: 6px; color: #d8faf4; }
.station-section dl { margin: 0; display: grid; grid-template-columns: minmax(80px, .75fr) minmax(0, 1fr); gap: 4px 10px; font-size: .78rem; }
.station-section dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.station-section dt { color: #a3becb; overflow-wrap: anywhere; }
.wagon .due-message::before, .track-list .due-message::before { content: ""; display: inline-block; width: 7px; height: 7px;
  margin-right: 5px; border-radius: 50%; background: #ffd46d; animation: pin-alert 1.65s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  .wagon .due-message::before, .track-list .due-message::before { animation: none; }
}

.empty-hover { position: absolute; bottom: 90px; left: 13px; max-width: calc(100% - 65px); text-align: left;
  padding: 8px 12px; border: 1px solid #a1b0ff; border-radius: 9px; background: #172242f5; color: #edf2ff;
  font: 650 .77rem 'Segoe UI', sans-serif; }
.empty-hover[hidden] { display: none; }
.empty-card { background: #192843; border-color: #4b5d87; }
.empty-card .route-heading { color: #d7dfff; }
.empty-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.empty-target { display: flex; gap: 5px; align-items: stretch; }
.empty-target input { flex: 1; min-width: 0; padding: 7px; border: 1px solid #4b5d87;
  border-radius: 7px; background: #112638; color: #edf1ff; font-size: .78rem; }
.empty-card .detail-tools { margin: 0; }
.empty-quote { width: 100%; text-align: left; display: grid; gap: 4px; }
.empty-quote small { color: #b6c6df; font-weight: 450; }
.empty-quote[aria-pressed=true] { border-color: #acb8ff; background: #2c4064; }
.empty-quote strong { color: #d5e0ff; }
.empty-error { margin: 0; padding: 7px; border-left: 2px solid #f0a289; }
.legend-empty { width: 14px; height: 3px; background: #a9b8ff; border-radius: 3px; }
#map.pick-empty { cursor: crosshair; }

.empty-fields .route-label, .empty-fields select { min-width: 0; }
.empty-fields select { width: 100%; }
.empty-settings { border-top: 1px solid #425579; padding-top: 6px; }
.empty-settings summary { cursor: pointer; color: #c4d6f1; font-size: .74rem; }
.empty-settings .empty-fields { margin-top: 6px; }
.empty-card .detail-tools { align-items: center; gap: 6px 10px; }

.detail-tabs { display: flex; gap: 5px; flex-wrap: wrap; padding-bottom: 10px; }
.detail-tabs .button { padding: 6px 9px; }
.detail-tabs .button[aria-pressed=true] { border-color: #688da6; background: #274967; color: #eef8ff; }
.empty-scope { margin-bottom: 2px; }
.empty-scope:has(> :only-child) { grid-template-columns: minmax(0, 1fr); }

.rail:has(.empty-card) .watch-list { max-height: 70px; }
