:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.85);
  --border-color: rgba(255, 255, 255, 0.1);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-purple: #8b5cf6;
  --accent-red: #ef4444;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ==========================================================================
   Header Navbar
   ========================================================================== */
.app-header {
  height: 64px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent-cyan), #3b82f6);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.35);
}

.brand-text h1 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: #fff;
}

.brand-text h1 span {
  color: var(--accent-cyan);
}

.brand-text .subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Search Box */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 38px;
  width: 280px;
  transition: all 0.2s ease;
}

.search-box:focus-within {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.2);
}

.search-box i {
  color: var(--text-muted);
  font-size: 13px;
  margin-right: 8px;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13px;
  width: 100%;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.clear-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}

.clear-btn:hover {
  color: #fff;
}

/* Filters */
.filter-group {
  display: flex;
  gap: 8px;
}

.filter-group select {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  padding: 0 10px;
  height: 38px;
  font-size: 12px;
  font-family: var(--font-main);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
  max-width: 160px;
}

.filter-group select:focus {
  border-color: var(--accent-cyan);
}

/* Live Status Pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: #34d399;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Buttons */
.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0 14px;
  height: 38px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.action-btn:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.action-btn.secondary {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.action-btn.secondary:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   Main Map Area
   ========================================================================== */
.main-container {
  position: relative;
  flex: 1;
  width: 100%;
  height: calc(100vh - 64px);
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: #0f172a;
}

/* Floating Stats Overlay */
.floating-stats {
  position: absolute;
  top: 16px;
  left: 20px;
  z-index: 800;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  padding: 10px 18px;
  gap: 16px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

.stat-card {
  display: flex;
  flex-direction: column;
}

.stat-val {
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  font-family: var(--font-mono);
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.stat-divider {
  width: 1px;
  height: 28px;
  background: var(--border-color);
}

/* ==========================================================================
   Side Drawers (Left & Right)
   ========================================================================== */
.side-drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 380px;
  max-width: 90vw;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--border-color);
  z-index: 900;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
}

.side-drawer.left {
  left: 0;
  transform: translateX(-100%);
}

.side-drawer.left.open {
  transform: translateX(0);
}

.side-drawer.right {
  right: 0;
  border-right: none;
  border-left: 1px solid var(--border-color);
  transform: translateX(100%);
}

.side-drawer.right.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
}

.drawer-title i {
  color: var(--accent-cyan);
}

.drawer-title h2 {
  font-size: 15px;
  font-weight: 700;
}

.close-drawer-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.close-drawer-btn:hover {
  color: #fff;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* Bus List Cards in Left Drawer */
.bus-list-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.bus-list-item:hover {
  border-color: var(--accent-cyan);
  background: rgba(30, 41, 59, 0.9);
  transform: translateY(-2px);
}

.bus-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.bus-item-no {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  font-family: var(--font-mono);
}

.bus-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.bus-badge.city-ordinary, .bus-badge.ordinary {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.bus-badge.metro-express {
  background: rgba(37, 99, 235, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(37, 99, 235, 0.35);
}

.bus-badge.pallevelugu {
  background: rgba(22, 163, 74, 0.2);
  color: #4ade80;
  border: 1px solid rgba(22, 163, 74, 0.35);
}

.bus-badge.express {
  background: rgba(234, 88, 12, 0.2);
  color: #fb923c;
  border: 1px solid rgba(234, 88, 12, 0.35);
}

.bus-badge.super-luxury {
  background: rgba(124, 58, 237, 0.2);
  color: #c084fc;
  border: 1px solid rgba(124, 58, 237, 0.35);
}

.bus-badge.ultra-deluxe {
  background: rgba(8, 145, 178, 0.2);
  color: #22d3ee;
  border: 1px solid rgba(8, 145, 178, 0.35);
}

.bus-badge.saptagiri {
  background: rgba(202, 138, 4, 0.2);
  color: #facc15;
  border: 1px solid rgba(202, 138, 4, 0.35);
}

.bus-badge.indra-ac {
  background: rgba(2, 132, 199, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(2, 132, 199, 0.35);
}

.bus-badge.amaravathi-luxury {
  background: rgba(180, 83, 9, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(180, 83, 9, 0.35);
}

.bus-badge.green-ev {
  background: rgba(5, 150, 105, 0.2);
  color: #34d399;
  border: 1px solid rgba(5, 150, 105, 0.35);
}

.bus-badge.metro-luxury {
  background: rgba(79, 70, 229, 0.2);
  color: #818cf8;
  border: 1px solid rgba(79, 70, 229, 0.35);
}

.bus-badge.other {
  background: rgba(100, 116, 139, 0.2);
  color: #cbd5e1;
  border: 1px solid rgba(100, 116, 139, 0.35);
}

.bus-item-route {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.bus-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* Right Detail Card Styles */
.detail-hero {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.15), rgba(59, 130, 246, 0.15));
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
}

.detail-bus-no {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-route-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin: 10px 0 4px 0;
}

.detail-depot {
  font-size: 12px;
  color: var(--accent-cyan);
  font-weight: 600;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
}

.detail-card-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.detail-card-val {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.detail-card.highlight {
  grid-column: span 2;
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.05);
}

.detail-card.highlight .detail-card-val {
  color: #34d399;
  font-size: 14px;
}

.route-trace-btn {
  width: 100%;
  background: linear-gradient(135deg, #06b6d4, #2563eb);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
  transition: opacity 0.2s;
}

.route-trace-btn:hover {
  opacity: 0.9;
}

.route-trace-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Timeline of Waypoints */
.waypoints-timeline {
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

.timeline-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.timeline-list {
  position: relative;
  padding-left: 20px;
}

.timeline-list::before {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 6px;
  width: 2px;
  background: var(--border-color);
}

.timeline-item {
  position: relative;
  margin-bottom: 14px;
}

.timeline-dot {
  position: absolute;
  left: -20px;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 2px solid var(--text-muted);
}

.timeline-item.passed .timeline-dot {
  border-color: var(--accent-green);
  background: var(--accent-green);
}

.timeline-item.current .timeline-dot {
  border-color: var(--accent-amber);
  background: var(--accent-amber);
  box-shadow: 0 0 10px var(--accent-amber);
}

.timeline-stop-name {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.timeline-item.passed .timeline-stop-name {
  color: var(--text-secondary);
}

.timeline-item.current .timeline-stop-name {
  color: #fbbf24;
  font-weight: 700;
}

.timeline-stop-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* ==========================================================================
   Leaflet Custom Elements
   ========================================================================== */
.custom-bus-pin {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  border: 2px solid #fff;
  transition: transform 0.2s ease;
}

.custom-bus-pin:hover {
  transform: scale(1.15);
  z-index: 1000 !important;
}

.pin-city-ordinary, .pin-ordinary { background: #dc2626; } /* Red - City Ordinary */
.pin-metro-express { background: #2563eb; } /* Blue - Metro Express */
.pin-pallevelugu { background: #16a34a; } /* Green - Palle Velugu */
.pin-express { background: #ea580c; } /* Orange - Intercity Express */
.pin-super-luxury { background: #7c3aed; } /* Purple - Super Luxury */
.pin-ultra-deluxe { background: #0891b2; } /* Teal - Ultra Deluxe */
.pin-saptagiri { background: #ca8a04; } /* Yellow/Gold - Saptagiri Ghat */
.pin-indra-ac { background: #0284c7; } /* Sky Blue - Indra AC */
.pin-amaravathi-luxury { background: #b45309; } /* Amber Gold - Amaravathi / Garuda Multi-Axle */
.pin-green-ev { background: #059669; } /* Emerald - Electric Bus EV */
.pin-metro-luxury { background: #4f46e5; } /* Indigo - Metro Luxury / Aero Express */
.pin-other { background: #64748b; } /* Slate - Other / Depot */

/* Custom Popup Style */
.leaflet-popup-content-wrapper {
  background: rgba(15, 23, 42, 0.95) !important;
  backdrop-filter: blur(12px);
  color: #fff !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 4px !important;
}

.leaflet-popup-tip {
  background: rgba(15, 23, 42, 0.95) !important;
}

.popup-container {
  padding: 8px 10px;
}

.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 10px;
}

.popup-bus-no {
  font-size: 14px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #fff;
}

.popup-route {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 4px;
}

.popup-stop {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.popup-btn {
  width: 100%;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.popup-btn:hover {
  background: #1d4ed8;
}

/* Loading / Empty States */
.loading-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.loading-state i {
  font-size: 24px;
  margin-bottom: 10px;
  color: var(--accent-cyan);
}

/* Live GPS Enhancements */
.custom-bus-pin.live-gps {
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.4), 0 4px 14px rgba(0, 0, 0, 0.6);
}

.custom-bus-pin.is-moving {
  animation: live-bus-glow 2.5s infinite;
}

@keyframes live-bus-glow {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7), 0 4px 12px rgba(0,0,0,0.5); }
  70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0), 0 4px 12px rgba(0,0,0,0.5); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0), 0 4px 12px rgba(0,0,0,0.5); }
}

.pin-heading-arrow {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid #10b981;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
}

.speed-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.speed-tag.stopped {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.3);
}

.live-pulse-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-ring 1.8s infinite;
}

.detail-live-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 14px;
}

.detail-live-banner .live-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #34d399;
}

.detail-live-banner .live-speed-val {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 800;
  color: #fff;
}

.live-route-bus-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #06b6d4;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.4), 0 4px 16px rgba(0,0,0,0.7);
  border: 3px solid #fff;
  animation: live-bus-glow 2s infinite;
}

/* Floating Map Legend */
.map-legend {
  position: absolute;
  bottom: 24px;
  left: 20px;
  z-index: 800;
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 11px;
  overflow: hidden;
  transition: all 0.25s ease;
  user-select: none;
  max-width: 320px;
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  font-weight: 700;
  color: var(--text-primary);
  font-size: 11.5px;
  border-bottom: 1px solid transparent;
}

.legend-header:hover {
  background: rgba(255, 255, 255, 0.08);
}

.map-legend:not(.collapsed) .legend-header {
  border-bottom-color: var(--border-color);
}

.legend-toggle-icon {
  font-size: 10px;
  color: var(--text-secondary);
  transition: transform 0.25s ease;
}

.map-legend.collapsed .legend-toggle-icon {
  transform: rotate(180deg);
}

.map-legend.collapsed .legend-items {
  display: none;
}

.legend-items {
  padding: 8px 12px 10px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
  background: rgba(15, 23, 42, 0.4);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 11px;
  white-space: nowrap;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}

/* Responsive */
@media (max-width: 900px) {
  .app-header {
    height: auto;
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .search-box {
    width: 100%;
  }
  .filter-group {
    width: 100%;
  }
  .filter-group select {
    flex: 1;
    max-width: 100%;
  }
  .floating-stats {
    display: none;
  }
  .map-legend {
    bottom: 12px;
    left: 12px;
    max-width: 260px;
  }
  .main-container {
    height: calc(100vh - 120px);
  }
}

