:root {
  --bg: #0b0f14;
  --bg-elevated: #121821;
  --bg-elevated-2: #1a2230;
  --border: #263041;
  --text: #e8edf3;
  --text-dim: #8b98ab;
  --accent: #ffb703;
  --accent-dim: #7a5a00;
  --good: #35d07f;
  --bad: #ff5c5c;
  --grid: #1c2531;
  --station: #d7dee8;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Topbar ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  height: 56px;
  flex: 0 0 56px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.logo { font-size: 22px; }

#topbar h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated-2);
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--accent);
  color: #1a1200;
  font-weight: 600;
}

#searchInput {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  width: 200px;
  outline: none;
}
#searchInput:focus { border-color: var(--accent); }

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.status .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #666;
  box-shadow: 0 0 0 rgba(0,0,0,0);
  transition: background 0.2s;
}
.status.ok .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.status.bad .dot { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.status.connecting .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status.demo .dot { background: #7aa2ff; box-shadow: 0 0 8px #7aa2ff; }

.icon-btn {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex: 0 0 auto;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Main layout ---------- */

#main {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

#mapWrap {
  flex: 1;
  position: relative;
  min-width: 0;
  background: var(--bg);
}

#mapCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#mapCanvas.dragging { cursor: grabbing; }

#mapControls {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

#legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  background: rgba(18, 24, 33, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  max-width: 260px;
  max-height: 40vh;
  overflow-y: auto;
  backdrop-filter: blur(4px);
}
#legend .legend-title {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
#legend .legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}
#legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(18, 24, 33, 0.97);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  z-index: 30;
  box-shadow: var(--shadow);
  max-width: 260px;
  transform: translate(-50%, -120%);
}
.tooltip.hidden { display: none; }
.tooltip .t-title { font-weight: 600; margin-bottom: 3px; display: flex; align-items: center; gap: 6px; }
.tooltip .t-line { color: var(--text-dim); }

/* ---------- Sidebar ---------- */

#sidebar {
  width: 340px;
  flex: 0 0 340px;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-tabs {
  display: flex;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
}
.sidebar-tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 11px 8px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.sidebar-tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

#trainsView, #stationsView {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
#stationsView.hidden, #trainsView.hidden { display: none; }

.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-dim);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
}

#trainList, #stationList {
  overflow-y: auto;
  flex: 1;
}

.station-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.station-row:hover { background: var(--bg-elevated-2); }
.station-row .s-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
}
.station-row .s-dot.unknown { background: var(--text-dim); opacity: 0.5; }
.station-row .s-info { min-width: 0; flex: 1; }
.station-row .s-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.station-row .s-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticker-item {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.ticker-item .tk-icon { flex: 0 0 auto; }
.ticker-item .tk-time { color: var(--text-dim); font-size: 11px; }
.ticker-item .tk-empty { color: var(--text-dim); font-size: 13px; padding: 20px 0; text-align: center; }

.train-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.train-row:hover { background: var(--bg-elevated-2); }
.train-row.selected { background: var(--bg-elevated-2); box-shadow: inset 3px 0 0 var(--accent); }
.train-row.cancelled { opacity: 0.45; }

.train-badge {
  flex: 0 0 auto;
  min-width: 44px;
  text-align: center;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.train-info {
  min-width: 0;
  flex: 1;
}
.train-info .t-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.train-info .t-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delay-chip {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}
.delay-chip.ontime { color: var(--good); background: rgba(53, 208, 127, 0.12); }
.delay-chip.late { color: var(--bad); background: rgba(255, 92, 92, 0.14); }
.delay-chip.cancelled { color: var(--text-dim); background: rgba(139, 152, 171, 0.12); }

#sidebarToggle {
  display: none;
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 6;
}

/* ---------- Panels (detail / settings) ---------- */

.panel {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 92vw;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.18s ease;
}
.panel.hidden { transform: translateX(105%); pointer-events: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  gap: 10px;
}

.panel-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
}

.line-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  margin-right: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.field input {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.hint code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

.primary-btn {
  background: var(--accent);
  color: #1a1200;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
}

/* schedule table in detail panel */
.detail-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 14px 0 6px;
}
.detail-kv {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
}
.detail-kv .k { color: var(--text-dim); }

table.schedule {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.schedule th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
}
table.schedule td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  white-space: nowrap;
}
table.schedule tr.state-current td { background: rgba(255, 183, 3, 0.12); font-weight: 600; }
table.schedule tr.state-past td { color: var(--text-dim); }
table.schedule tr.state-next td { color: var(--good); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.toast.hidden { display: none; }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  #sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    right: 0;
    width: 86vw;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    z-index: 25;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebarToggle { display: flex; }
  #searchInput { width: 120px; }
  #topbar h1 { display: none; }
  .panel { top: 0; }
}

@media (max-width: 600px) {
  #topbar {
    height: auto;
    flex: 0 0 auto;
    flex-wrap: wrap;
    row-gap: 6px;
    padding: 8px 10px;
  }
  .topbar-left { order: 1; }
  .topbar-right { order: 2; margin-left: auto; }
  .topbar-center {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
  }
  .status .status-text { display: none; }
  #searchInput { width: 96px; }
}

/* ---------------------------------------------------------------------------
   Mandantenfähigkeit: Branding, Einbettung, Fußzeile
   ---------------------------------------------------------------------------
   --accent und --bg werden zur Laufzeit aus der Server-Konfiguration der
   jeweiligen Karte gesetzt (siehe applyTheme() in app.js). Alles andere leitet
   sich davon ab, damit eine einzige Farbe genügt, um eine Karte eigen aussehen
   zu lassen. */

/* Allgemeines Ausblenden — wird von applyTheme() für abgeschaltete
   Bedienelemente benutzt. */
.hidden { display: none !important; }

.logo-img {
  height: 26px;
  width: auto;
  max-width: 120px;
  display: block;
  object-fit: contain;
}

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}
.sidebar-footer a { color: var(--accent); text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }

.powered-by {
  position: absolute;
  right: 10px;
  bottom: 8px;
  z-index: 3;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--text-dim);
  font-size: 11px;
  text-decoration: none;
  backdrop-filter: blur(3px);
}
.powered-by:hover { color: var(--text); }

/* Einbettung per <iframe>: Kopfzeile und Seitenleiste weg, nur die Karte.
   Panels und Kartensteuerung bleiben — sonst wäre die Einbettung ein Bild. */
body.embed #topbar,
body.embed #sidebar,
body.embed #sidebarToggle {
  display: none;
}
body.embed #main { height: 100vh; }
