:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-inset: #121a24;
  --border: #2a3a4f;
  --text: #e8eef4;
  --muted: #8fa3b8;
  --accent: #3d9be9;
  --accent-dim: #2563a8;
  --green: #4ade80;
  --amber: #fbbf24;
  --radius: 10px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 1.5rem 1.5rem 0.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
}

.subtitle { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.95rem; }

.stats { color: var(--muted); font-size: 0.9rem; }

.panel {
  margin: 0 1.5rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filters label.grow { flex: 1; min-width: 180px; }

select, input[type="search"], input[type="date"] {
  font: inherit;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-inset);
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
}

.map-section {
  padding: 0;
  overflow: hidden;
}

.map-header {
  padding: 0.85rem 1.25rem 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
}

.map-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.map-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.map-container {
  height: min(52vh, 520px);
  min-height: 280px;
  width: 100%;
  background: var(--panel-inset);
}

.leaflet-container {
  font-family: var(--font);
  background: #1e2a38;
}

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

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

.map-popup h4 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.map-popup .region {
  font-size: 0.75rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.map-popup .months {
  font-size: 0.8rem;
  color: var(--amber);
  margin: 0.25rem 0 0.5rem;
}

.map-popup button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 0.35rem 0.65rem;
  border-radius: 5px;
  font-size: 0.85rem;
  font-weight: 600;
}

.map-popup button:hover {
  background: var(--accent-dim);
}

.pin-origin {
  background: transparent !important;
  border: none !important;
}

.pin-origin .origin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.5);
}

tbody tr.row-highlight {
  background: rgba(61, 155, 233, 0.14);
}

.table-wrap { overflow-x: auto; padding: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
}

tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}

tbody tr:hover { background: rgba(61, 155, 233, 0.08); }

td:nth-child(2) { font-weight: 600; color: #fff; white-space: nowrap; }
td:nth-child(3) { white-space: nowrap; color: var(--amber); font-size: 0.85rem; }
td:nth-child(4) { color: var(--muted); max-width: 420px; }

.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

.hidden { display: none !important; }

/* Dialog */
.detail-dialog {
  border: none;
  padding: 0;
  max-width: 720px;
  width: calc(100% - 2rem);
  background: transparent;
  color: var(--text);
}

.detail-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.dialog-inner {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}

.dialog-header h2 { margin: 0.25rem 0 0; font-size: 1.35rem; }

.region-tag {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.meta { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.9rem; }

.dialog-body {
  overflow-y: auto;
  padding: 1rem 1.25rem 1.25rem;
}

.dialog-body section { margin-bottom: 1.25rem; }

.dialog-body h3 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.transit-dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  font-size: 0.9rem;
}

.transit-dl dt { color: var(--muted); margin: 0; }
.transit-dl dd { margin: 0; }

.panel-inset {
  background: var(--panel-inset);
  border-radius: 8px;
  padding: 1rem;
  border: 1px solid var(--border);
}

.live-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.live-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.chk {
  flex-direction: row !important;
  align-items: center;
  gap: 0.4rem !important;
  color: var(--text) !important;
  text-transform: none !important;
}

.btn-primary, .btn-icon {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 1rem;
  font-weight: 600;
}

.btn-primary:hover { background: var(--accent-dim); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }

.btn-icon {
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  padding: 0.25rem 0.5rem;
}

.conn-block {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.conn-block:last-child { border-bottom: none; margin-bottom: 0; }

.conn-block h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--green);
}

.conn-query-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.conn-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.5rem;
  font-size: 0.88rem;
}

.conn-card .route { font-weight: 600; }
.conn-card .times { color: var(--accent); margin: 0.25rem 0; }
.conn-card .detail { color: var(--muted); font-size: 0.82rem; }

.error-msg { color: #f87171; font-size: 0.9rem; }

.loading { color: var(--muted); font-style: italic; }
