/* Track Layout: control-room schematic look. Light = drawing paper, dark = signalling VDU. */
:root {
  --bg: #eef1f3; --panel: #fff; --ink: #18232b; --muted: #5d6b75; --line: #cdd5db; --accent: #0b6e8a; --hl: rgba(11,110,138,.14);
  --track: #1f2a33; --rev: #0b6e8a; --red: #d0312d; --yellow: #e0a100; --green: #1f9d55; --off: #c3ccd2;
  --ac: #7b3fb3; --balise: #d48a00; --mb: #2f6fd6; --pf: #dfe5ea; --pf-edge: #7d8c97; --point: #0b6e8a;
  --sans: "Segoe UI", Barlow, system-ui, sans-serif; --cond: "Bahnschrift", "Barlow Condensed", "Arial Narrow", sans-serif; --mono: Consolas, "JetBrains Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) { :root {
  --bg: #0c1216; --panel: #131c22; --ink: #dbe5ea; --muted: #8b9ba5; --line: #26343d; --accent: #38b6d6; --hl: rgba(56,182,214,.18);
  --track: #e6eef2; --rev: #38b6d6; --red: #ff4d47; --yellow: #ffc21a; --green: #2fd27a; --off: #3a4952;
  --ac: #b685ff; --balise: #ffc21a; --mb: #6fa3ff; --pf: #1f2c34; --pf-edge: #5a6e7a; --point: #38b6d6; color-scheme: dark; } }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); display: flex; flex-direction: column; }
a { color: var(--accent); }
.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font: 700 18px var(--cond); letter-spacing: .03em; color: var(--ink); text-decoration: none; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; }
.top nav a.on, .top nav a:hover { background: var(--hl); color: var(--ink); }
.page { padding: 20px; display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 1400px; margin: 0 auto; }
.page.narrow { max-width: 820px; }
h1 { font: 700 22px var(--cond); letter-spacing: .02em; margin: 0; }
h2 { font: 600 13px var(--cond); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; min-width: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.ok { padding: 10px 14px; border-radius: 6px; background: color-mix(in srgb, var(--green) 14%, transparent); border: 1px solid var(--green); }
.err { padding: 10px 14px; border-radius: 6px; color: var(--red); border: 1px solid var(--red); }
button, .btn { font: 500 13px var(--sans); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: var(--accent); }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.danger { color: var(--red); }
input, select { font: 13px var(--sans); padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
pre { font: 12px var(--mono); background: var(--bg); padding: 10px; border-radius: 6px; overflow: auto; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; color: var(--ink); text-decoration: none; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; }
.tile b { font: 700 26px var(--cond); }
.tile span:last-child { grid-column: 2; color: var(--muted); font-size: 13px; }
.tile .sym { grid-row: span 2; width: 18px; height: 18px; }
.tile:hover { border-color: var(--accent); }
.search { display: flex; gap: 8px; }
.search input { flex: 1; padding: 9px 12px; font-size: 14px; }
.dhead { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; margin-bottom: 8px; }
.dhead h2 { font-size: 17px; color: var(--ink); text-transform: none; letter-spacing: .02em; }
.tablewrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th { text-align: left; font: 600 12px var(--cond); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); padding: 6px 8px; white-space: nowrap; }
.grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid .n { text-align: right; font-variant-numeric: tabular-nums; }
.rowlink { cursor: pointer; }
.rowlink:hover { background: var(--hl); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.filters .grow { flex: 1; min-width: 160px; }
/* legend chips */
.sym { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px; border-radius: 2px; flex: none; }
.sym-signal { background: var(--red); border-radius: 50%; }
.sym-point { background: var(--point); }
.sym-axle_counter { background: var(--ac); border-radius: 50%; }
.sym-balise { background: var(--balise); clip-path: polygon(50% 0, 100% 100%, 0 100%); border-radius: 0; }
.sym-marker_board { background: var(--mb); }
.sym-platform { background: var(--pf); border: 1px solid var(--pf-edge); }
.sym-track { background: var(--track); height: 3px; vertical-align: 3px; }
/* viewer */
.viewer { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px 16px; }
.vhead { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.vtitle { display: flex; flex-direction: column; min-width: 0; }
.vtools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.range { display: flex; gap: 6px; align-items: center; }
.range input { width: 110px; }
.vbody { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 12px; }
.stage { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-height: 420px; }
.stage svg { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; user-select: none; }
.stage svg.drag { cursor: grabbing; }
.hint { position: absolute; left: 10px; bottom: 6px; font-size: 12px; color: var(--muted); pointer-events: none; }
aside { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.layers { display: grid; grid-template-columns: 1fr; gap: 4px; }
.layers label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }
.layers .n { margin-left: auto; font: 12px var(--mono); color: var(--muted); }
#details dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 13px; }
#details dt { color: var(--muted); }
#details dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
#details p { margin: 8px 0 0; font-size: 13px; }
.listcard { flex: 1; min-height: 160px; display: flex; flex-direction: column; }
.listcard input { width: 100%; margin-bottom: 6px; }
#list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; font-size: 13px; }
#list li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
#list li:hover, #list li.on { background: var(--hl); }
#list b { font-family: var(--mono); font-weight: 600; }
#list .kp { margin-left: auto; font: 12px var(--mono); color: var(--muted); }
/* svg */
.trk { stroke: var(--track); stroke-width: 3; stroke-linecap: round; }
.trk.gap { stroke: var(--off); stroke-dasharray: 8 6; }
.gapl { font: 12px var(--sans); fill: var(--muted); }
.stband { fill: var(--hl); opacity: .5; }
.stline { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 4; }
.stl { font: 700 13px var(--cond); fill: var(--accent); letter-spacing: .05em; }
.stk { font: 10px var(--mono); fill: var(--muted); }
.okp { font: 9.5px var(--mono); fill: var(--muted); }
.trk.rev { stroke: var(--rev); stroke-width: 4; }
.tl { font: 600 12px var(--cond); fill: var(--muted); letter-spacing: .05em; }
.gl { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.rl { font: 10px var(--mono); fill: var(--muted); }
.pf { fill: var(--pf); stroke: var(--pf-edge); stroke-width: 1; }
.pfl { font: 600 11px var(--cond); fill: var(--muted); letter-spacing: .05em; }
.ink { stroke: var(--ink); stroke-width: 1.4; }
.head { stroke: var(--ink); stroke-width: 1; }
.pm { fill: var(--panel); stroke: var(--point); stroke-width: 1.5; }
.pt { fill: var(--point); }
.ac { stroke: var(--ac); stroke-width: 2; }
.acm { fill: var(--ac); }
.acd { fill: var(--panel); stroke: var(--ac); stroke-width: 1.4; }
.bg { fill: var(--panel); stroke: var(--balise); stroke-width: 1.8; stroke-linejoin: round; }
.mb { fill: var(--mb); }
.ol { font: 500 10px var(--mono); fill: var(--muted); }
.ol-signal { fill: var(--ink); font-weight: 600; font-size: 11px; }
.ol-point { fill: var(--point); font-weight: 600; font-size: 11px; }
.obj { cursor: pointer; }
.hit { fill: transparent; }
.obj:hover .hit { fill: var(--hl); }
.selbox { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; }
@media (max-width: 860px) {
  html, body { height: auto; }
  .vbody { grid-template-columns: minmax(0, 1fr); }
  .stage { height: 65vh; }
}
/* whole-line overview strip */
.mini { display: block; width: 100%; height: 60px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.mtrk { stroke: var(--track); stroke-width: 2; }
.mgap { stroke: var(--off); stroke-width: 2; stroke-dasharray: 4 4; }
.mst { stroke: var(--accent); stroke-width: 1.2; }
.mstl { font: 600 10px var(--cond); fill: var(--muted); letter-spacing: .04em; }
.mwin { fill: var(--hl); stroke: var(--accent); stroke-width: 1.5; }
.partsel { display: flex; align-items: center; gap: 6px; }
.partsel select { max-width: 420px; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.login { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
/* edit form in the side panel */
.edit { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; font-size: 13px; }
.edit label { color: var(--muted); }
.edit input, .edit select { width: 100%; min-width: 0; }
.edit .row { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.edit .msg { grid-column: 1 / -1; margin: 0; font-size: 13px; }
.edit .msg.bad { color: var(--red); }
.edit .note { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted); }
.edit .note:empty { display: none; }
.panelbtns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.speedband { stroke: var(--red); stroke-width: 1.4; }
.speedtick { stroke: var(--red); stroke-width: 1.2; }
.spl { font: 600 11px var(--mono); fill: var(--red); }
.spk { font: 9.5px var(--mono); fill: var(--muted); }
.leader { stroke: var(--muted); stroke-width: .8; opacity: .7; }
/* halo so labels stay readable where they cross a track or link */
#svg text.ol, #svg text.okp, #svg text.tl, #svg text.spl, #svg text.spk, #svg text.pfl, #svg text.gapl, #svg text.tunl, #svg text.portl { paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
.speedband.loop { stroke-dasharray: 8 4; }
.speedband.tsr { stroke: var(--balise); stroke-width: 3; stroke-dasharray: 10 4; }
.speedband.tsr.old { opacity: .4; }
.spl.tsrl { fill: var(--balise); }
.edit .ftitle { font-weight: 600; margin: 0 0 4px; }
.small { font-size: 12px; margin: 2px 0; }
/* OHE masts and viaduct piers */
.sym-mast { background: var(--ohe); border-radius: 1px; width: 4px; }
.sym-pier { background: var(--pf); border: 1px solid var(--pf-edge); border-radius: 2px; width: 7px; }
.mast { stroke: var(--ohe); stroke-width: 1.6; }
.mastb { fill: var(--ohe); }
.cant { stroke: var(--ohe); stroke-width: 1; }
.pier { fill: var(--pf); stroke: var(--pf-edge); stroke-width: 1; opacity: .85; }
.ol-mast { fill: var(--ohe); }
.ol-pier { fill: var(--muted); }
:root { --ohe: #8a5a2b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ohe: #d9a066; } }
:root[data-theme="dark"] { --ohe: #d9a066; }
/* neutral sections: magenta as on the drawings */
:root { --ns: #c0359a; }
.ns { fill: color-mix(in srgb, var(--ns) 18%, transparent); stroke: var(--ns); stroke-width: 1.4; }
.nsx { stroke: var(--ns); stroke-width: 1; fill: none; }
.sym-neutral_section { background: color-mix(in srgb, var(--ns) 25%, transparent); border: 1.5px solid var(--ns); border-radius: 1px; width: 10px; }
.ol-neutral_section { fill: var(--ns); font-weight: 600; }
/* tunnels and the hanger clamps that carry the rigid conductor inside them */
:root { --tun: #5b6670; --hang: #0f7f74; }
.tun { fill: color-mix(in srgb, var(--tun) 13%, transparent); stroke: none; }
.portal { stroke: var(--tun); stroke-width: 3; }
.tunl { fill: var(--tun); font-weight: 600; font-size: 11px; }
.portl { fill: var(--tun); font-size: 10px; }
.hroof { stroke: var(--hang); stroke-width: 2.4; }
.hang { stroke: var(--hang); stroke-width: 1.2; }
.hclamp { stroke: var(--hang); stroke-width: 1.4; fill: none; }
.ol-hanger { fill: var(--hang); }
.sym-hanger { width: 10px; background: linear-gradient(var(--hang), var(--hang)) top / 100% 3px no-repeat, linear-gradient(var(--hang), var(--hang)) center / 2px 100% no-repeat; border-radius: 0; }
.sym-tunnel { background: color-mix(in srgb, var(--tun) 22%, transparent); border-left: 3px solid var(--tun); border-right: 3px solid var(--tun); border-radius: 0; width: 14px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tun: #a3b0ba; --hang: #4fd1c0; } }
:root[data-theme="dark"] { --tun: #a3b0ba; --hang: #4fd1c0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ns: #e879c9; } }
:root[data-theme="dark"] { --ns: #e879c9; }
