* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #10151c;
  --panel: #1a212b;
  --panel-2: #222b37;
  --text: #e8edf3;
  --muted: #93a1b1;
  --accent: #3fa9f5;
  --ok: #37c871;
  --warn: #f5a83f;
}

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid #2c3644;
  z-index: 1000;
}

#brand { display: flex; align-items: center; gap: 10px; }

#brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  50% { opacity: 0.4; }
}

#brand h1 { font-size: 17px; font-weight: 600; letter-spacing: 0.2px; }

#stats { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }

#train-count { font-weight: 700; color: var(--text); font-size: 15px; }

.badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  background: var(--panel-2);
  color: var(--muted);
}

.badge.live { background: #123b24; color: var(--ok); }
.badge.simulated { background: #3b2e12; color: var(--warn); }

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

#sidebar {
  width: 300px;
  background: var(--panel);
  border-right: 1px solid #2c3644;
  display: flex;
  flex-direction: column;
  z-index: 900;
}

#search {
  margin: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid #2c3644;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

#search:focus { border-color: var(--accent); }

#train-list { flex: 1; overflow-y: auto; padding: 0 10px 10px; }

.train-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 6px;
  background: var(--panel-2);
  border-left: 4px solid transparent;
  transition: background 0.15s;
}

.train-item:hover { background: #2b3543; }
.train-item.selected { background: #2b3543; outline: 1px solid var(--accent); }

.train-item .hc { font-weight: 700; font-size: 13px; }
.train-item .toc { font-size: 11px; color: var(--muted); float: right; }
.train-item .dest { font-size: 12px; color: var(--muted); margin-top: 2px; }
.train-item .late { color: var(--warn); font-size: 11px; font-weight: 600; }
.train-item .ontime { color: var(--ok); font-size: 11px; font-weight: 600; }

#map { flex: 1; background: #0b0f14; }

/* Departure board panel */
#layout { position: relative; }

#board {
  position: absolute;
  top: 12px; right: 12px;
  width: 420px;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid #2c3644;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.55);
  z-index: 950;
}

#board-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 14px 8px;
  position: sticky;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid #2c3644;
}

#board-station { font-size: 16px; font-weight: 700; }
#board-sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; margin-top: 2px; }

#board-close {
  background: none; border: none; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1; padding: 0 2px;
}
#board-close:hover { color: var(--text); }

#board-messages { padding: 0 14px; }
#board-messages .msg {
  font-size: 11px; color: var(--warn);
  background: #3b2e12; border-radius: 6px;
  padding: 6px 8px; margin: 8px 0;
}

#board-table { width: 100%; border-collapse: collapse; font-size: 12px; }
#board-table th {
  text-align: left; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted);
  padding: 8px 8px 4px; border-bottom: 1px solid #2c3644;
}
#board-table th:first-child, #board-table td:first-child { padding-left: 14px; }
#board-table td { padding: 7px 8px; border-bottom: 1px solid #232c38; vertical-align: top; }
#board-table tr.linkable { cursor: pointer; }
#board-table tr.linkable:hover { background: var(--panel-2); }
#board-table .dest { font-weight: 600; }
#board-table .via { font-size: 10px; color: var(--muted); }
#board-table .ok { color: var(--ok); font-weight: 600; }
#board-table .late { color: var(--warn); font-weight: 600; }
#board-table .cancelled { color: #f55; font-weight: 700; }

.check { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.check.match { background: #123b24; color: var(--ok); }
.check.differs { background: #3b2e12; color: var(--warn); }
.check.nomatch { background: var(--panel-2); color: var(--muted); }

#board-foot { padding: 8px 14px 12px; font-size: 10px; color: var(--muted); }

.station-tip {
  background: var(--panel); color: var(--text);
  border: 1px solid #2c3644; font-size: 11px;
}

#attribution-note {
  position: fixed;
  bottom: 0; right: 0;
  font-size: 10px;
  color: var(--muted);
  background: rgba(16, 21, 28, 0.85);
  padding: 3px 8px;
  border-top-left-radius: 6px;
  z-index: 1000;
}

#attribution-note a { color: var(--accent); text-decoration: none; }

/* Train markers */
.train-marker { transition: transform 0.2s; }

.train-marker svg { display: block; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.6)); }

.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
}

.leaflet-popup-tip { background: var(--panel); }

.popup-hc { font-size: 15px; font-weight: 700; }
.popup-toc { font-size: 11px; padding: 1px 8px; border-radius: 999px; color: #fff; margin-left: 6px; }
.popup-row { font-size: 12px; margin-top: 5px; color: var(--muted); }
.popup-row b { color: var(--text); font-weight: 600; }

@media (max-width: 720px) {
  #sidebar { display: none; }
}
