/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --bg:            #0d1219;
  --panel:         #141b24;
  --panel-alt:     #1a232f;
  --border:        #263241;
  --border-soft:   #1e2733;

  --text:          #e7ecf1;
  --text-dim:      #8b96a3;
  --text-faint:    #5c6878;

  --accent-route:  #18c2ae;   /* gefahrene Strecke / Auswahl */
  --accent-route-dim: #0f5f57;
  --accent-live:   #ffb020;   /* aktuellste Position / Vorhersage */
  --accent-live-dim: #4a3414;
  --accent-danger: #ef5a5a;
  --accent-ok:     #2bd576;

  --radius: 3px;
  --font-ui:   'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
}
.mono { font-family: var(--font-mono); letter-spacing: 0.01em; }
.hidden { display: none !important; }

/* ==========================================================================
   Layout
   ========================================================================== */
.app { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 52px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { display: flex; align-items: baseline; gap: 8px; }
.topbar__mark {
  width: 10px; height: 10px;
  background: var(--accent-route);
  display: inline-block;
  border-radius: 1px;
  transform: rotate(45deg);
}
.topbar__title { font-weight: 600; font-size: 14px; letter-spacing: 0.02em; }
.topbar__subtitle { color: var(--text-dim); font-size: 12px; }

.topbar__status {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}
.topbar__clock { color: var(--text-faint); padding-left: 10px; border-left: 1px solid var(--border); }

.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  display: inline-block;
  background: var(--text-faint);
}
.status-dot--off { background: var(--accent-danger); box-shadow: 0 0 0 0 rgba(239,90,90,.5); }
.status-dot--on  { background: var(--accent-ok); box-shadow: 0 0 6px 0 rgba(43,213,118,.6); }

.layout { flex: 1 1 auto; display: flex; min-height: 0; }

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
  width: 320px;
  flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.panel { border-bottom: 1px solid var(--border-soft); }
.panel__head {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  background: none; border: none; cursor: pointer;
  padding: 12px 16px;
  color: var(--text);
  font-family: var(--font-ui);
}
.panel__head-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-dim);
}
.panel__head-chevron { color: var(--text-faint); transition: transform .15s ease; }
.panel.collapsed .panel__head-chevron { transform: rotate(-90deg); }
.panel.collapsed .panel__body { display: none; }
.panel__body { padding: 0 16px 16px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.field span { font-size: 11px; color: var(--text-dim); }
.field-row { display: flex; gap: 10px; }
input, select {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 9px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  width: 100%;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent-route);
  outline-offset: 1px;
}
.hint { font-size: 11px; color: var(--text-faint); margin: 2px 0 0; line-height: 1.5; }

.btn {
  font-family: var(--font-ui);
  font-size: 12px; font-weight: 600;
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn--primary { background: var(--accent-route); color: #06231f; border-color: var(--accent-route); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--secondary { background: var(--panel-alt); color: var(--text); border-color: var(--border); }
.btn--secondary:hover { border-color: var(--accent-route); }
.btn--ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn--ghost:hover { color: var(--text); border-color: var(--text-dim); }
.btn--sm { padding: 5px 9px; font-size: 11px; }

.form__actions { margin-top: 2px; }
.form__feedback { font-size: 11.5px; margin: 4px 0 0; min-height: 14px; }
.form__feedback.is-error { color: var(--accent-danger); }
.form__feedback.is-ok { color: var(--accent-ok); }

.conn-summary { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.conn-summary__row { display: flex; justify-content: space-between; font-size: 12px; }
.conn-summary__row span:first-child { color: var(--text-dim); }

/* Routes */
.route-toolbar { display: flex; gap: 6px; margin-bottom: 10px; }
.search-input { flex: 1; }
.route-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.route-list__empty { color: var(--text-faint); font-size: 12px; padding: 10px 0; }
.route-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 9px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  background: var(--panel-alt);
}
.route-item:hover { border-color: var(--text-faint); }
.route-item.is-active { border-color: var(--accent-route); background: rgba(24,194,174,0.08); }
.route-item__key { font-family: var(--font-mono); font-size: 11.5px; color: var(--text); }
.route-item__meta { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); }

/* Attributes */
.attr-grid { display: flex; flex-direction: column; gap: 7px; margin-top: 8px; }
.attr-grid label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
  cursor: pointer;
}
.attr-grid input[type="checkbox"] { width: auto; accent-color: var(--accent-route); }

/* ==========================================================================
   Map
   ========================================================================== */
.mapwrap { flex: 1 1 auto; position: relative; }
#map { width: 100%; height: 100%; background: #0d1219; }

.map-overlay {
  position: absolute;
  background: rgba(20,27,36,0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  z-index: 500;
  font-size: 11.5px;
  color: var(--text-dim);
  backdrop-filter: blur(2px);
}
.map-overlay--top-left { top: 12px; left: 12px; display: flex; flex-direction: column; gap: 2px; }
.map-overlay--bottom-left { bottom: 12px; left: 12px; display: flex; gap: 8px; align-items: center; }
.map-overlay__label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.map-overlay__value { color: var(--text); font-size: 12.5px; }
.dot-sep { color: var(--text-faint); }

.map-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.map-empty__inner {
  background: rgba(20,27,36,0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  max-width: 320px;
  text-align: center;
}
.map-empty__title { margin: 0 0 6px; font-weight: 600; }
.map-empty__text { margin: 0; color: var(--text-dim); font-size: 12px; }

/* Leaflet overrides */
.leaflet-container { background: #0d1219; font-family: var(--font-ui); }
.leaflet-popup-content-wrapper, .leaflet-tooltip {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.leaflet-popup-tip { background: var(--panel); border: 1px solid var(--border); }
.leaflet-tooltip { font-size: 11.5px; padding: 6px 8px; }
.leaflet-tooltip::before { display: none; }

.attr-table { border-collapse: collapse; }
.attr-table td { padding: 1px 6px 1px 0; font-size: 11.5px; }
.attr-table td.k { color: var(--text-dim); }
.attr-table td.v { font-family: var(--font-mono); color: var(--text); text-align: right; }

/* Live-Pulse-Marker (Signature-Element: aktuellste Position der Route) */
.live-pulse {
  width: 16px; height: 16px;
  position: relative;
}
.live-pulse::before, .live-pulse::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  background: var(--accent-live);
}
.live-pulse::after {
  animation: pulse-ring 1.8s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
}
.live-pulse::before {
  inset: 5px;
  box-shadow: 0 0 6px 1px rgba(255,176,32,0.7);
}
@keyframes pulse-ring {
  0%   { transform: scale(0.5); opacity: 0.7; }
  100% { transform: scale(2.4); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .live-pulse::after { animation: none; opacity: 0.25; }
}

@media (max-width: 860px) {
  .sidebar { position: absolute; z-index: 600; height: calc(100% - 52px); }
}
