/* Zugtracker – dunkles, großflächiges Layout für den Einsatz unterwegs */
:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1f2630; --line: #2d3540;
  --text: #e6edf3; --muted: #9aa7b4; --accent: #3ea6ff; --accent2: #ffb23e;
  --ok: #3fb950; --warn: #f0a020; --bad: #f85149;
  --area: #3ea6ff; --train: #ffb23e; --sel: #ff5fa2;
  --r: 14px; --tap: 52px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --sheet-h: 46vh;
  font-size: 17px;
}
body.theme-light { --bg:#f4f6f8; --panel:#ffffff; --panel2:#eef1f4; --line:#d6dce2; --text:#111; --muted:#5b6670; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; overscroll-behavior: none; }
a { color: var(--accent); }
h3 { margin: 18px 0 8px; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

#map { position: fixed; inset: 0; z-index: 1; background: #0b0f14; }
body.theme-light #map { background: #dde3e8; }
.dark-tiles { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.6); }

/* Kopfleiste */
#topbar { position: fixed; z-index: 1000; top: calc(8px + var(--safe-t)); left: 8px; right: 8px;
  display: flex; gap: 8px; align-items: center; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.chip { height: var(--tap); padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chip-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--area); }
.status { flex: 1; min-width: 0; height: var(--tap); padding: 0 14px; border-radius: 999px; background: var(--panel);
  border: 1px solid var(--line); display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.icon-btn { width: var(--tap); height: var(--tap); border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 1.4rem; }

/* Unteres Panel */
.sheet { position: fixed; z-index: 1000; left: 0; right: 0; bottom: 0; height: calc(var(--sheet-h) + var(--safe-b));
  background: var(--panel); border-top-left-radius: 20px; border-top-right-radius: 20px;
  box-shadow: 0 -6px 24px rgba(0,0,0,.45); display: flex; flex-direction: column; transition: height .25s ease; }
.sheet.collapsed { height: calc(118px + var(--safe-b)); }
.sheet.expanded { height: calc(88vh - var(--safe-t)); }
.grip { height: 22px; flex: none; display: flex; justify-content: center; align-items: center; cursor: grab; }
.grip::after { content: ""; width: 48px; height: 6px; border-radius: 3px; background: var(--line); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 0 8px 6px; flex: none; }
.tabs button { min-height: var(--tap); border: 0; border-radius: 12px; background: transparent; color: var(--muted);
  font-size: 1.15rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button span { font-size: .72rem; }
.tabs button.active { background: var(--panel2); color: var(--text); }
.pane { display: none; overflow-y: auto; padding: 4px 14px calc(18px + var(--safe-b)); -webkit-overflow-scrolling: touch; flex: 1; }
.pane.active { display: block; }

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
input, select { width: 100%; min-height: var(--tap); padding: 0 14px; font-size: 1.05rem; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.btn { min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-size: 1rem; font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #001428; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: .9rem; }
.btn:active, .item:active { transform: scale(.98); }
.field { display: block; margin: 10px 0; font-size: .85rem; color: var(--muted); }
.field input, .field select { margin-top: 6px; }
.toggle { display: flex; align-items: center; gap: 12px; min-height: var(--tap); font-size: 1rem; }
.toggle input { width: 28px; height: 28px; min-height: 0; accent-color: var(--accent); }
.hint { color: var(--muted); font-size: .85rem; margin: 8px 2px; }
.small { font-size: .85rem; color: var(--muted); padding-left: 18px; }
.small li { margin: 6px 0; }
.note { padding: 10px 12px; border-radius: 12px; font-size: .9rem; margin: 10px 0; }
.note.warn { background: rgba(240,160,32,.12); border: 1px solid rgba(240,160,32,.35); }
.badge { display: inline-block; min-width: 26px; padding: 2px 8px; border-radius: 999px; background: var(--panel2);
  color: var(--text); font-size: .8rem; text-align: center; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; }

.list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.item { min-height: var(--tap); padding: 10px 12px; border-radius: 12px; background: var(--panel2);
  border: 1px solid var(--line); display: flex; align-items: center; gap: 10px; cursor: pointer; }
.item .main { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t2 { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .time { text-align: right; font-variant-numeric: tabular-nums; min-width: 64px; }
.item.cancel .t1 { text-decoration: line-through; color: var(--bad); }
.linebadge { flex: none; min-width: 52px; padding: 4px 8px; border-radius: 8px; background: #263241; color: #cfe6ff;
  font-weight: 700; font-size: .85rem; text-align: center; }
.delay { font-size: .8rem; font-weight: 700; }
.delay.ok { color: var(--ok); } .delay.warn { color: var(--warn); } .delay.bad { color: var(--bad); }
.chg { color: var(--warn); font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.grid .btn.active { background: var(--accent); color: #001428; border-color: var(--accent); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 10px 0; background: var(--panel2); padding: 4px; border-radius: 12px; }
.seg button { min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; font-size: .95rem; }
.seg button.active { background: var(--panel); color: var(--text); }

/* Zugdetail / Haltliste */
.trainhead { display: flex; gap: 10px; align-items: center; margin: 12px 0 6px; }
.trainhead .big { font-size: 1.3rem; font-weight: 800; }
.est { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: rgba(255,178,62,.15);
  color: var(--accent2); border: 1px solid rgba(255,178,62,.4); }
.stops { list-style: none; margin: 8px 0; padding: 0; }
.stops li { display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; align-items: center; min-height: 48px; padding: 4px 0; cursor: pointer; }
.stops .pin { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--accent); background: var(--panel); justify-self: center; }
.stops li.past .pin { background: var(--accent); }
.stops li.past .nm { color: var(--muted); }
.stops li.now .pin { border-color: var(--sel); background: var(--sel); }
.stops .tm { text-align: right; font-size: .85rem; font-variant-numeric: tabular-nums; }
.stops .tm small { display: block; color: var(--muted); }

/* Infofenster */
.card { position: fixed; z-index: 1100; left: 8px; right: 8px; top: calc(70px + var(--safe-t)); max-height: 46vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.card .close { position: absolute; right: 8px; top: 8px; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--panel2); color: var(--text); font-size: 1.1rem; }
.card h2 { margin: 0 52px 6px 0; font-size: 1.25rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: .95rem; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.contact { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.contact a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px; border-radius: 10px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: .9rem; }
.hidden { display: none !important; }

.toast { position: fixed; z-index: 1200; left: 12px; right: 12px; bottom: calc(var(--sheet-h) + 16px + var(--safe-b));
  padding: 12px 16px; border-radius: 12px; background: #2a1f12; border: 1px solid var(--warn); color: var(--text); font-size: .95rem; }

/* Kartenmarker */
.tr-mk { display: flex; align-items: center; justify-content: center; }
.tr-mk .b { padding: 2px 6px; border-radius: 8px; background: var(--train); color: #1a1000; font-weight: 800; font-size: 12px;
  border: 2px solid #1a1000; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.tr-mk.rt0 .b { background: #9aa7b4; }
.tr-mk.sel .b { background: var(--sel); color: #fff; border-color: #fff; font-size: 14px; padding: 4px 9px; }
.tr-mk.late .b { box-shadow: 0 0 0 3px var(--bad); }
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { margin: 12px 14px; font-size: .95rem; }
.leaflet-control-attribution { font-size: 10px; background: rgba(13,17,23,.7) !important; color: #9aa7b4; }
.leaflet-control-attribution a { color: #9cc9ff; }
.leaflet-control-zoom { display: none; }
.leaflet-tooltip.kreis { background: var(--panel); color: var(--text); border-color: var(--line); }
