/* Gestaltung: klar, sachlich, angelehnt an Verkehrs-Leitsysteme.
   Rot als Signalfarbe, kühle Grautöne, kräftige Überschriften. */
:root {
  --red: #ec0016;
  --red-dark: #c50014;
  --red-soft: #fee6e6;
  --ink: #131821;
  --ink-2: #282d37;
  --muted: #646973;
  --line: #d7dce1;
  --line-soft: #e9edf0;
  --bg: #f0f3f5;
  --card: #ffffff;
  --field: #ffffff;
  --green: #408335;
  --green-soft: #e2f3e5;
  --yellow: #f39200;
  --blue: #0087b9;
  --blue-soft: #e0eff6;
  --track: #3c414b;
  --track-off: #c8cdd2;
  --route: #408335;
  --occupied: #ec0016;
  --grid: #eef1f3;
  --shadow: 0 1px 2px rgba(19, 24, 33, .06), 0 4px 12px rgba(19, 24, 33, .06);
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --red: #ff2a3c;
    --red-dark: #ec0016;
    --red-soft: #3b1418;
    --ink: #f0f3f5;
    --ink-2: #d7dce1;
    --muted: #a0a5ad;
    --line: #3c414b;
    --line-soft: #2a2f39;
    --bg: #0f131a;
    --card: #1b2029;
    --field: #141921;
    --green: #66a558;
    --green-soft: #1d3020;
    --yellow: #ffad33;
    --blue: #4bb2d9;
    --blue-soft: #10303d;
    --track: #d7dce1;
    --track-off: #4b515c;
    --route: #66a558;
    --occupied: #ff4d5c;
    --grid: #20252e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 15px/1.45 "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 20px; font-weight: 800; }
h3 { font-size: 15px; font-weight: 700; }
a { color: var(--red); }
small, .muted { color: var(--muted); }
.label {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}

/* ---------- Bedienelemente ---------- */
button, input, select {
  font: inherit; color: var(--ink);
}
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover { border-color: var(--ink); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--red); border-color: var(--red); color: #fff; }
button.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
button.dark { background: var(--ink); border-color: var(--ink); color: var(--bg); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--line-soft); }
button.danger { color: var(--red); }
button.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
button.icon { width: 40px; padding: 0; }
input, select {
  min-height: 40px; padding: 8px 10px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--field); width: 100%;
}
input[type=checkbox] { width: auto; min-height: 0; }
input[type=range] { padding: 0; border: 0; background: transparent; accent-color: var(--red); min-height: 24px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.seg button { border: 0; border-radius: 0; min-height: 36px; padding: 6px 12px; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--ink); color: var(--bg); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; user-select: none; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--track-off); position: relative; cursor: pointer; transition: background .15s; border: 0; padding: 0; min-height: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(18px); }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--line-soft); color: var(--muted); white-space: nowrap; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip.ok { background: var(--green-soft); color: var(--green); }
.chip.bad { background: var(--red-soft); color: var(--red); }
.chip.info { background: var(--blue-soft); color: var(--blue); }
.chip.plain::before { display: none; }

/* ---------- Anmeldung ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(400px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.login .brand { margin-bottom: 8px; }
.msg { min-height: 1.4em; color: var(--muted); font-size: 14px; margin: 0; }

/* ---------- Kopf ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.top-inner { max-width: 1440px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 20px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; white-space: nowrap; }
.brand .mark { width: 32px; height: 32px; border-radius: 6px; background: var(--red); display: grid; place-items: center; }
.brand .mark svg { width: 20px; height: 20px; }
nav.tabs { display: flex; gap: 2px; align-self: stretch; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.tabs button {
  border: 0; border-radius: 0; background: transparent; min-height: 64px; padding: 0 14px;
  color: var(--muted); font-weight: 700; box-shadow: inset 0 -3px 0 transparent; white-space: nowrap;
}
nav.tabs button:hover { color: var(--ink); }
nav.tabs button.active { color: var(--ink); box-shadow: inset 0 -3px 0 var(--red); }
.top-right { display: flex; align-items: center; gap: 10px; }
.estop {
  background: var(--red); color: #fff; border: 0; font-weight: 800; letter-spacing: .04em;
  min-height: 44px; padding: 0 20px; text-transform: uppercase;
}
.estop:hover { background: var(--red-dark); }

main { max-width: 1440px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line-soft); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 0; }
.card-body { padding: 14px 16px 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* ---------- Fahrpult ---------- */
.desk { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.desk-side { display: flex; flex-direction: column; gap: 16px; }
.statusbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px; margin-bottom: 16px; }
.statusbar .sep { width: 1px; height: 24px; background: var(--line); }

.plan-card { overflow: hidden; }
.plan-scroll { overflow: auto; max-height: 62vh; background: var(--card); }
.plan-scroll svg { display: block; touch-action: manipulation; }

.acc-list { display: flex; flex-direction: column; }
.acc-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.acc-item:first-child { border-top: 0; }
.acc-item .name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-item .seg button { min-height: 32px; padding: 4px 10px; font-size: 13px; }

.lamps { display: inline-flex; gap: 6px; }
.lamp-btn { width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 50%; font-size: 10px; font-weight: 800; }
.lamp-btn .dot { width: 14px; height: 14px; border-radius: 50%; display: block; }
.lamp-btn.active { border-width: 2px; border-color: var(--ink); }

/* Fahrregler */
.throttles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.throttle { padding: 16px; display: flex; flex-direction: column; gap: 10px; position: relative; }
.throttle .t-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.throttle .t-head h3 { font-size: 16px; }
.throttle .t-head small { display: block; font-weight: 400; }
.gauge { width: 100%; max-width: 240px; margin: 0 auto; display: block; touch-action: none; cursor: pointer; user-select: none; }
.gauge .g-track { fill: none; stroke: var(--line-soft); stroke-width: 14; stroke-linecap: round; }
.gauge .g-value { fill: none; stroke: var(--red); stroke-width: 14; stroke-linecap: round; transition: stroke-dashoffset .15s; }
.gauge .g-tick { stroke: var(--muted); stroke-width: 1.5; }
.gauge .g-tick.major { stroke: var(--ink); stroke-width: 2; }
.gauge .g-num { font-size: 10px; fill: var(--muted); text-anchor: middle; dominant-baseline: middle; font-weight: 600; }
.gauge .g-needle { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; transition: transform .15s; }
.gauge .g-hub { fill: var(--ink); }
.gauge .g-big { font-size: 30px; font-weight: 800; fill: var(--ink); text-anchor: middle; font-variant-numeric: tabular-nums; }
.gauge .g-unit { font-size: 10px; fill: var(--muted); text-anchor: middle; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.gauge .g-step { font-size: 13px; fill: var(--ink-2); text-anchor: middle; font-weight: 700; font-variant-numeric: tabular-nums; }
.throttle.auto .g-value { stroke: var(--blue); }
.throttle .controls { display: grid; grid-template-columns: 40px 1fr 40px; gap: 8px; align-items: center; }
.throttle .dirrow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.throttle .dirrow button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.throttle .fns { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.throttle .fns button { min-height: 32px; padding: 0; font-size: 12px; }
.throttle .fns button.on { background: var(--yellow); border-color: var(--yellow); color: #131821; }
.throttle .where { font-size: 13px; color: var(--muted); }
.add-throttle { min-height: 200px; border: 2px dashed var(--line); background: transparent; box-shadow: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; }

/* Fahraufträge */
.trip { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line-soft); font-size: 14px; }
.trip:first-child { border-top: 0; }
.trip .grow b { display: block; }

/* ---------- Gleisplan (SVG) ---------- */
.cell { fill: transparent; stroke: var(--grid); stroke-width: 1; }

.tile path, .tile line { stroke: var(--track); stroke-width: 6; fill: none; stroke-linecap: butt; }
.tile .off { stroke: var(--track-off); }
.tile.route path:not(.off), .tile.route line:not(.off) { stroke: var(--route); }
.tile.occupied path:not(.off), .tile.occupied line:not(.off) { stroke: var(--occupied); }
.tile .blockbox { fill: var(--card); stroke: var(--track); stroke-width: 2; }
.tile.route .blockbox { stroke: var(--route); }
.tile.occupied .blockbox { stroke: var(--occupied); fill: var(--red-soft); }
.tile text { font-size: 9px; font-weight: 700; fill: var(--ink); text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.tile .mast { stroke: var(--muted); stroke-width: 2; }
.tile .sensor { fill: var(--card); stroke: var(--blue); stroke-width: 2; }
.tile .sensor.on { fill: var(--blue); }
.tile.selected .sel { fill: none; stroke: var(--blue); stroke-width: 2; stroke-dasharray: 4 3; }
svg.run .tile.clickable { cursor: pointer; }
svg.run .tile.clickable:hover > rect:first-child { fill: var(--line-soft); }
.loco-tag rect { fill: var(--ink); }
.loco-tag text { fill: var(--bg); font-size: 10px; font-weight: 800; }
.lamp-Hp0 { fill: var(--red); }
.lamp-Hp1 { fill: var(--green); }
.lamp-Hp2 { fill: var(--yellow); }
.lamp-aus { fill: var(--track-off); }
.dot.Hp0 { background: var(--red); }
.dot.Hp1 { background: var(--green); }
.dot.Hp2 { background: linear-gradient(90deg, var(--green) 50%, var(--yellow) 50%); }
.dot.aus { background: var(--track-off); }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.palette { display: flex; gap: 6px; flex-wrap: wrap; }
.palette button { width: 48px; height: 48px; padding: 4px; min-height: 0; }
.palette button.active { border: 2px solid var(--red); }
.palette svg { width: 34px; height: 34px; }
.palette path, .palette line { stroke: var(--ink); stroke-width: 6; fill: none; }
.palette .blockbox { fill: none; stroke: var(--ink); stroke-width: 2; }
.palette .mast { stroke: var(--ink); stroke-width: 2; }
.palette circle { fill: var(--red); }
.props { display: flex; flex-direction: column; gap: 12px; }
.palette-groups { display: flex; flex-wrap: wrap; gap: 12px 20px; }
.pgroup { display: flex; flex-direction: column; gap: 6px; }
.save-state { margin-left: auto; }
.palette .cursor-icon { fill: var(--ink); stroke: none; }
.editor-scroll svg { cursor: crosshair; user-select: none; -webkit-user-select: none; }
.ghost { opacity: .45; }
.ghost .ghost-bg { fill: var(--blue-soft); }
.ghost path, .ghost line { stroke: var(--blue); stroke-width: 6; fill: none; }
.ghost .blockbox { fill: none; stroke: var(--blue); stroke-width: 2; }
.ghost circle { fill: var(--blue); }
.howto { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.props .palette button { width: 44px; height: 44px; }

/* ---------- Einrichtungslisten ---------- */
.section { margin-bottom: 28px; }
.section > .row:first-child { margin-bottom: 12px; }
.items { display: flex; flex-direction: column; gap: 10px; }
.item { padding: 14px 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px 12px; align-items: end; }
.item .wide { grid-column: span 2; }
.item .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.item .full { grid-column: 1 / -1; }
.found { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); background: var(--blue-soft); margin-bottom: 8px; }
.found b { color: var(--blue); }
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius); background: var(--blue-soft); color: var(--ink); margin-bottom: 16px; flex-wrap: wrap; }

/* ---------- Dialog / Toast ---------- */
.popover { position: fixed; z-index: 40; width: min(320px, calc(100vw - 32px)); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; max-width: min(560px, 90vw);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: var(--radius); font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

@media (max-width: 1100px) {
  .desk, .editor { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  main { padding: 12px 16px; }
  .top-inner { padding: 0 12px; gap: 10px; flex-wrap: wrap; }
  nav.tabs { order: 3; flex-basis: 100%; }
  nav.tabs button { min-height: 44px; }
  .brand span { display: none; }
  .estop { padding: 0 14px; }
  .item .wide { grid-column: 1 / -1; }
  .plan-card .card-head .muted { display: none; }
}
