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

:root {
  --bg: #f8f9fa;
  --surface: #fff;
  --surface2: #f1f3f5;
  --border: #e9ecef;
  --border-light: #f1f3f5;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --text-dim: #adb5bd;
  --accent: #228be6;
  --bus: #12b886;
  --trolley: #f59f00;
  --minibus: #7950f2;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.10);
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1c2128;
  --border: #21262d;
  --border-light: #1c2128;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #484f58;
  --accent: #58a6ff;
  --bus: #10b981;
  --trolley: #f59e0b;
  --minibus: #8b5cf6;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#map { position: absolute; inset: 0; z-index: 0; }

/* ─── Top bar ─────────────────────────────────────────── */

.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  padding: 12px 16px; display: flex; gap: 8px; align-items: center;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.topbar .logo {
  font-size: 13px; font-weight: 600; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: var(--radius); text-decoration: none;
  white-space: nowrap; box-shadow: var(--shadow);
}

.search-box {
  flex: 1; max-width: 320px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; color: var(--text); font-size: 14px;
  outline: none; font-family: var(--font); box-shadow: var(--shadow);
}
.search-box::placeholder { color: var(--text-dim); }
.search-box:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,139,230,0.15); }

.filters { display: flex; gap: 6px; }

.filter-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 14px; color: var(--text-muted);
  font-size: 12px; cursor: pointer; font-family: var(--font);
  display: flex; align-items: center; gap: 5px;
  transition: all 0.15s; white-space: nowrap; box-shadow: var(--shadow);
  font-weight: 500;
}
.filter-btn.active { color: var(--text); border-color: var(--text-muted); }
.filter-btn .dot { width: 8px; height: 8px; border-radius: 50%; }
.filter-btn[data-type="bus"] .dot { background: var(--bus); }
.filter-btn[data-type="trolley"] .dot { background: var(--trolley); }
.filter-btn[data-type="minibus"] .dot { background: var(--minibus); }

.theme-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px; cursor: pointer;
  font-size: 14px; box-shadow: var(--shadow); line-height: 1;
}

/* ─── Sheet ───────────────────────────────────────────── */

.sheet {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 55dvh; transition: transform 0.3s ease;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.sheet.collapsed { transform: translateY(calc(100% - 48px)); }

.sheet-handle {
  width: 36px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 8px auto; cursor: grab;
}

.sheet-header {
  padding: 0 16px 10px; font-size: 12px; color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
}
.stat { font-variant-numeric: tabular-nums; }

/* ─── Favorites section ───────────────────────────────── */

.fav-section {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.fav-section::-webkit-scrollbar { display: none; }
.fav-section:empty { display: none; }

.fav-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 5px 10px 5px 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: all 0.15s;
}
.fav-chip:hover { border-color: var(--accent); }
.fav-chip .fav-badge {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff;
}
.fav-chip .fav-badge.bus { background: var(--bus); }
.fav-chip .fav-badge.trolley { background: var(--trolley); }
.fav-chip .fav-badge.minibus { background: var(--minibus); }
.fav-chip .fav-online {
  font-size: 10px; color: var(--bus); font-weight: 500;
}

/* ─── Route list ──────────────────────────────────────── */

.route-list { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }

.route-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border-light);
  cursor: pointer; transition: background 0.1s;
}
.route-item:hover { background: var(--surface2); }
.route-item:active { background: var(--border); }

.route-item .badge {
  min-width: 40px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
}
.route-item .badge.bus { background: var(--bus); }
.route-item .badge.trolley { background: var(--trolley); }
.route-item .badge.minibus { background: var(--minibus); }

.route-item .info { flex: 1; min-width: 0; }
.route-item .info .name {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.route-item .info .meta {
  font-size: 11px; color: var(--text-muted); display: flex; gap: 8px; align-items: center;
}
.route-item .online-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--bus);
  display: inline-block; animation: pulse 2s infinite;
}
.route-item .online-count { color: var(--bus); font-weight: 600; font-size: 11px; }

.route-item .fav {
  font-size: 16px; opacity: 0.25; cursor: pointer; padding: 4px;
  transition: opacity 0.15s;
}
.route-item .fav:hover { opacity: 0.6; }
.route-item .fav.active { opacity: 1; color: var(--trolley); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ─── Route detail panel ──────────────────────────────── */

.route-detail {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.route-detail-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
}
.route-detail-badge {
  min-width: 44px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
}
.route-detail-title { font-size: 14px; font-weight: 600; flex: 1; }
.route-detail-close {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--text-muted); padding: 4px 8px;
}
.route-detail-stats {
  display: flex; gap: 16px; font-size: 12px; color: var(--text-muted);
}
.route-detail-stats .live { color: var(--bus); font-weight: 600; }
.route-detail-stats .eta {
  color: var(--accent); font-weight: 700; font-size: 14px;
  background: rgba(34,139,230,0.1); padding: 2px 10px; border-radius: 12px;
}
.route-detail-stats .eta.passed { color: var(--text-muted); font-weight: 500; font-size: 11px; background: none; }

/* ─── Loading ─────────────────────────────────────────── */

.loading {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); z-index: 5;
  background: var(--surface); padding: 12px 20px;
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  font-size: 13px; color: var(--text-muted);
}

/* ─── User location dot ───────────────────────────────── */

.maplibregl-user-location-dot {
  width: 16px !important; height: 16px !important;
  background: #4285f4 !important;
  border: 3px solid #fff !important;
  border-radius: 50% !important;
  box-shadow: 0 0 8px rgba(66,133,244,0.6), 0 0 20px rgba(66,133,244,0.25) !important;
}
.maplibregl-user-location-dot::before { display: none !important; }
.maplibregl-user-location-dot::after {
  content: "" !important; position: absolute !important;
  inset: -4px !important; border-radius: 50% !important;
  background: rgba(66,133,244,0.15) !important;
  animation: loc-pulse 2s ease-out infinite !important;
}
@keyframes loc-pulse {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(2.5); opacity: 0; }
}

/* ─── Bus markers ─────────────────────────────────────── */

.bus-marker-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.bus-dot {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2.5px solid #fff; display: flex; align-items: center;
  justify-content: center; font-size: 11px; font-weight: 700;
  color: #fff; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  font-family: var(--font);
}
.bus-eta {
  font-size: 9px; font-weight: 700; color: var(--accent);
  background: var(--surface); border-radius: 4px; padding: 0 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  min-height: 14px; line-height: 14px; text-align: center;
}
.bus-eta:empty { display: none; }

/* ─── Maplibre popup override ─────────────────────────── */

.maplibregl-popup-content {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-radius: 8px !important;
  padding: 8px 12px !important;
  box-shadow: var(--shadow-lg) !important;
  border: 1px solid var(--border) !important;
}
.maplibregl-popup-tip {
  border-top-color: var(--surface) !important;
}

/* ─── Desktop ─────────────────────────────────────────── */

@media (min-width: 768px) {
  .sheet {
    left: 16px; right: auto; bottom: 16px; top: 72px;
    width: 360px; max-height: none; border-radius: var(--radius);
    border: 1px solid var(--border);
  }
  .sheet.collapsed { transform: none; }
  .sheet-handle { display: none; }
}

/* ─── Mobile ──────────────────────────────────────────── */

@media (max-width: 767px) {
  .topbar { padding: 8px 10px; gap: 6px; flex-wrap: wrap; }
  .filters { overflow-x: auto; scrollbar-width: none; }
  .filter-btn .filter-icon { display: none; }
  .search-box { max-width: none; order: 10; flex-basis: 100%; }
}
