/* dblive · dark rail-style theme */
:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel-2: #1d232d;
  --border: #2a3340;
  --text: #e8ecf1;
  --muted: #8b98a9;
  --red: #ec0016;            /* DB red */
  --green: #2fbf71;
  --amber: #f5b942;
  --accent: #58a6ff;
  --radius: 12px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 2px solid var(--red);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 3px;
  background: var(--red);
  box-shadow: 0 0 12px rgba(236, 0, 22, 0.7);
}
.brand h1 { font-size: 1.1rem; margin: 0; letter-spacing: 0.5px; }

#search-form { display: flex; gap: 0.4rem; flex: 1; max-width: 340px; }
#train-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  outline: none;
}
#train-input:focus { border-color: var(--accent); }
#search-btn, #refresh-btn {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
}
#search-btn:hover { filter: brightness(1.15); }

.topbar-meta { display: flex; align-items: center; gap: 0.9rem; margin-left: auto; }
.auto-refresh { color: var(--muted); font-size: 0.85rem; display: flex; gap: 0.3rem; align-items: center; cursor: pointer; }
#refresh-btn { background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); font-weight: 400; font-size: 0.85rem; }
#refresh-btn:hover { color: var(--text); }

/* ---------------------------------------------------------------- layout */
main { flex: 1; width: min(920px, 100%); margin: 0 auto; padding: 1.25rem; }

.error {
  background: rgba(236, 0, 22, 0.12);
  border: 1px solid rgba(236, 0, 22, 0.5);
  color: #ff9aa4;
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
}
.loading { color: var(--muted); padding: 2rem; text-align: center; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- summary */
.summary {
  background: linear-gradient(135deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.train-title { display: flex; align-items: center; gap: 0.7rem; }
.train-name { font-size: 1.6rem; font-weight: 800; }
.route { margin-top: 0.35rem; font-size: 1.05rem; }
.route-arrow { color: var(--red); margin: 0 0.4rem; }
.operator { color: var(--muted); font-size: 0.82rem; margin-top: 0.35rem; }

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  border: 1px solid var(--border);
}
.badge-running { color: var(--green); border-color: var(--green); }
.badge-planned { color: var(--accent); border-color: var(--accent); }
.badge-completed { color: var(--muted); }
.badge-canceled { color: #ff6b78; border-color: #ff6b78; }

.summary-live { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.live-item { display: flex; flex-direction: column; gap: 0.2rem; min-width: 120px; }
.live-label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1px; }
.live-value { font-size: 1.05rem; font-weight: 600; }
.live-value a { color: var(--accent); text-decoration: none; }
.live-item.minor .live-value { color: var(--amber); }
.live-item.major .live-value { color: #ff6b78; }
.live-item.ontime .live-value { color: var(--green); }

/* ------------------------------------------------------ search suggestions */
.suggest-wrap { position: relative; flex: 1; display: flex; }

.suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 340px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  z-index: 100;
}
.sug-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  font-size: 0.83rem;
  border-bottom: 1px solid rgba(42, 51, 64, 0.4);
}
.sug-row:last-child { border-bottom: none; }
.sug-row:hover, .sug-row.active { background: rgba(88, 166, 255, 0.1); }
.sug-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.sug-dot.running { background: var(--green); box-shadow: 0 0 6px rgba(47,191,113,.8); }
.sug-dot.planned { background: var(--accent); }
.sug-dot.canceled { background: #ff6b78; }
.sug-name { font-weight: 700; white-space: nowrap; }
.sug-route {
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
.sug-meta { color: var(--amber); font-weight: 600; white-space: nowrap; }

/* ---------------------------------------------------------------- map */
.map-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.25rem;
}
#map {
  height: 360px;
  width: 100%;
  background: #1a2029;
}

/* live train marker */
.train-marker { background: none; border: none; }
.train-dot {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--red);
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  animation: train-pulse 2s infinite;
}
@keyframes train-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(236, 0, 22, 0.55), 0 2px 10px rgba(0,0,0,0.45); }
  70%  { box-shadow: 0 0 0 16px rgba(236, 0, 22, 0), 0 2px 10px rgba(0,0,0,0.45); }
  100% { box-shadow: 0 0 0 0 rgba(236, 0, 22, 0), 0 2px 10px rgba(0,0,0,0.45); }
}

/* popups in theme colors */
.leaflet-popup-content-wrapper {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.leaflet-popup-tip { background: var(--panel-2); }
.leaflet-popup-content { margin: 10px 14px; font-size: 0.85rem; }
.pp-title { font-weight: 700; margin-bottom: 0.4rem; }
.pp-row { display: flex; justify-content: space-between; gap: 1.2rem; color: var(--muted); }
.pp-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

/* ---------------------------------------------------------------- timeline */
.timeline-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.timeline-head, .stop {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 1fr 1fr;
  gap: 0.6rem;
  padding: 0.6rem 1.1rem;
  align-items: center;
}
.timeline-head {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.timeline { list-style: none; margin: 0; padding: 0; }
.stop { border-bottom: 1px solid rgba(42, 51, 64, 0.5); position: relative; }
.stop:last-child { border-bottom: none; }
.stop:hover { background: rgba(88, 166, 255, 0.05); }

.col-station { display: flex; align-items: center; gap: 0.7rem; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--muted);
  flex-shrink: 0;
  position: relative;
}
/* connecting rail line */
.stop::before {
  content: "";
  position: absolute;
  left: calc(1.1rem + 4px);
  top: -1px; bottom: -1px;
  width: 2px;
  background: var(--border);
}
.stop:first-child::before { top: 50%; }
.stop:last-child::before { bottom: 50%; }

.station-name { font-weight: 600; }
.stop.first .dot, .stop.last .dot { width: 13px; height: 13px; background: var(--red); border-color: var(--red); }

.stop.current { background: rgba(47, 191, 113, 0.08); }
.stop.current .dot { background: var(--green); border-color: var(--green); box-shadow: 0 0 10px rgba(47, 191, 113, 0.8); animation: pulse 1.6s infinite; }
.stop.current .station-name::after {
  content: " ●";
  color: var(--green);
  font-size: 0.7rem;
  vertical-align: middle;
}
@keyframes pulse { 50% { box-shadow: 0 0 2px rgba(47, 191, 113, 0.3); } }

.leg .times { display: flex; align-items: center; gap: 0.45rem; }
.leg .actual { font-weight: 700; font-size: 1.02rem; font-variant-numeric: tabular-nums; }
.leg .sub { color: var(--muted); font-size: 0.78rem; display: flex; gap: 0.6rem; margin-top: 0.1rem; }
.leg .planned { text-decoration: line-through; text-decoration-thickness: 1px; }
.leg.ontime .actual { color: var(--green); }
.leg.minor .actual { color: var(--amber); }
.leg.major .actual { color: #ff6b78; }
.leg.cancelled .actual { color: #ff6b78; font-size: 0.85rem; font-weight: 600; }
.leg.empty { color: var(--muted); }

.chip {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.08rem 0.45rem;
  border-radius: 99px;
}
.chip.minor { background: rgba(245, 185, 66, 0.15); color: var(--amber); }
.chip.major { background: rgba(255, 107, 120, 0.15); color: #ff6b78; }

.platform.changed { color: var(--amber); font-weight: 600; }

/* ---------------------------------------------------------------- footer */
footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 1.2rem;
}
footer a { color: var(--accent); }

@media (max-width: 640px) {
  .timeline-head { display: none; }
  .stop { grid-template-columns: 1fr 1fr; }
  .col-station { grid-column: 1 / -1; }
  .summary-live { width: 100%; }
}
