:root {
  color-scheme: light;
  --bg: #f4efe6;
  --panel: rgba(255, 251, 245, 0.92);
  --panel-border: #d6c7ae;
  --text: #1e1a16;
  --muted: #675d51;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --shadow: 0 -8px 40px rgba(68, 54, 34, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
}

/* ── Full-viewport map ───────────────────────────────────────────────────── */

#map {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
}

/* ── Map status badge (top-left) ─────────────────────────────────────────── */

.map-status-badge {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.78rem;
  color: var(--muted);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 12px rgba(68, 54, 34, 0.14);
  pointer-events: none;
  white-space: nowrap;
}

/* ── Shared elements ─────────────────────────────────────────────────────── */

button {
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  cursor: pointer;
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* ── Station count badge (busy stations) ─────────────────────────────────── */

.station-count {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1e3a5f;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  font-family: system-ui, sans-serif;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

code {
  font-family: Consolas, "Courier New", monospace;
}

/* ── Layer control panel (top-right) ─────────────────────────────────────── */

.layer-control {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 2px 16px rgba(68, 54, 34, 0.16);
  backdrop-filter: blur(10px);
  overflow: hidden;
  min-width: 158px;
}

.layer-control-title {
  padding: 8px 12px 7px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--panel-border);
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid rgba(214, 199, 174, 0.4);
}

.layer-row:last-child {
  border-bottom: none;
}

.layer-row:hover {
  background: rgba(15, 118, 110, 0.06);
}

/* Hide the native checkbox; drive visual state via CSS sibling selector */
.layer-row input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* Toggle track */
.layer-toggle {
  width: 28px;
  height: 16px;
  border-radius: 8px;
  background: #cbd5e1;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}

/* Toggle thumb */
.layer-toggle::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.layer-row input:checked + .layer-toggle {
  background: var(--accent);
}

.layer-row input:checked + .layer-toggle::after {
  transform: translateX(12px);
}

.layer-label {
  font-size: 0.8rem;
  font-family: system-ui, sans-serif;
  color: var(--text);
  user-select: none;
}

/* ── Activity feed panel (right side) ────────────────────────────────────── */

.activity-feed {
  position: fixed;
  top: 172px;
  right: 16px;
  width: 300px;
  max-height: calc(100vh - 80px);
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(68, 54, 34, 0.18);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.activity-feed.hidden {
  display: none;
}

.activity-feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}

.feed-filter-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  margin-left: auto;
  margin-right: 8px;
  text-transform: none;
  letter-spacing: 0;
}

.feed-filter-label input {
  accent-color: var(--accent);
  cursor: pointer;
}

.feed-clear-btn {
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 0 4px;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  box-shadow: none;
}

.feed-clear-btn:hover {
  color: var(--accent);
  background: transparent;
}

.activity-list {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
  scroll-behavior: smooth;
}

.feed-event {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 6px;
  row-gap: 0;
  padding: 5px 12px;
  font-family: system-ui, sans-serif;
  border-bottom: 1px solid rgba(214, 199, 174, 0.3);
}

.feed-event:last-child {
  border-bottom: none;
}

.feed-sign {
  grid-row: 1 / 3;
  font-size: 0.95rem;
  line-height: 1;
  padding-top: 2px;
  align-self: center;
}

.feed-event.appeared .feed-sign { color: #4ade80; }
.feed-event.disappeared .feed-sign { color: #f87171; }

.feed-id {
  font-size: 0.78rem;
  font-weight: 700;
  font-family: Consolas, monospace;
  line-height: 1.3;
}

.feed-event.appeared .feed-id { color: #4ade80; }
.feed-event.disappeared .feed-id { color: #f87171; }

.feed-meta {
  font-size: 0.72rem;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.feed-schedule-link {
  color: inherit;
  text-decoration: underline dotted;
}

.feed-schedule-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 600;
  background: rgba(74, 222, 128, 0.12);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.3);
  border-radius: 3px;
  padding: 0 3px;
  vertical-align: middle;
  margin-left: 3px;
  line-height: 1.5;
}

.feed-schedule-badge.no-sched {
  background: rgba(100, 116, 139, 0.12);
  color: #64748b;
  border-color: rgba(100, 116, 139, 0.3);
}

/* ── Schedule modal ──────────────────────────────────────────────────────── */

.schedule-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.schedule-modal[hidden] {
  display: none;
}

.schedule-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 26, 22, 0.55);
  backdrop-filter: blur(3px);
}

.schedule-modal-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 8px 48px rgba(68, 54, 34, 0.28);
  width: min(520px, 100%);
  max-height: min(82vh, 700px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.schedule-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.schedule-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.schedule-modal-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 3px;
  font-family: system-ui, sans-serif;
}

.schedule-modal-close {
  background: transparent;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.schedule-modal-close:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
}

/* ── Calling points list ─────────────────────────────────────────────────── */

.schedule-calling-points {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
}

.calling-point {
  display: grid;
  grid-template-columns: 16px auto 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  border-bottom: 1px solid rgba(214, 199, 174, 0.4);
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  transition: background 0.1s;
}

.segment-info {
  padding: 2px 20px 2px 52px;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  border-bottom: 1px solid rgba(214, 199, 174, 0.4);
  line-height: 1.4;
}

.calling-point:last-child {
  border-bottom: none;
}

.calling-point.pass {
  opacity: 0.55;
}

.calling-point.origin,
.calling-point.terminus {
  font-weight: 600;
}

.calling-point.current-location {
  background: rgba(15, 118, 110, 0.10);
  border-left: 3px solid var(--accent);
  padding-left: 17px;
}

.calling-point-indicator {
  font-size: 0.65rem;
  color: var(--accent);
  text-align: center;
  line-height: 1;
}

.calling-point-time {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
}

.calling-point.pass .calling-point-time {
  font-style: italic;
  color: var(--muted);
}

.calling-point-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calling-point-crs {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: Consolas, monospace;
  margin-left: 4px;
}

.calling-point-platform {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  text-align: right;
}

.calling-point-realtime {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.78rem;
  white-space: nowrap;
  text-align: right;
  min-width: 54px;
}

.schedule-no-data {
  text-align: center;
  color: var(--muted);
  padding: 40px 24px;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
}

