/* ============================================================
   Bus Watcher – Premium Dark Mode Design System
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;600&display=swap');

/* ─── CSS Custom Properties ─── */
:root {
    --bg-primary: #0a0a12;
    --bg-secondary: #12121e;
    --bg-glass: rgba(18, 18, 34, 0.75);
    --bg-glass-hover: rgba(28, 28, 50, 0.85);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-accent: rgba(255, 255, 255, 0.12);
    --text-primary: #f0f0f5;
    --text-secondary: #8888a8;
    --text-muted: #555570;
    --accent-green: #10b981;
    --accent-blue: #3b82f6;
    --accent-orange: #f59e0b;
    --accent-pink: #ec4899;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --shadow-glow: 0 0 40px rgba(59, 130, 246, 0.15);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ─── Map Container ─── */
#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Override Leaflet styles for dark mode */
.leaflet-container {
    background: var(--bg-primary) !important;
    font-family: var(--font-sans) !important;
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow-glow) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-glass) !important;
    backdrop-filter: blur(20px) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-glass) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
    transition: var(--transition) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-glass-hover) !important;
    border-color: var(--border-accent) !important;
}

.leaflet-control-attribution {
    background: rgba(10, 10, 18, 0.7) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
    backdrop-filter: blur(10px) !important;
    border: none !important;
}

.leaflet-control-attribution a {
    color: var(--text-secondary) !important;
}

/* ─── Sidebar Panel ─── */
.sidebar {
    position: fixed;
    top: 20px;
    left: 20px;
    bottom: 20px;
    width: 340px;
    z-index: 1000;
    background: var(--bg-glass);
    backdrop-filter: blur(30px) saturate(1.5);
    -webkit-backdrop-filter: blur(30px) saturate(1.5);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
        0 0 60px rgba(0, 0, 0, 0.5),
        0 0 30px rgba(59, 130, 246, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border-glass);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.sidebar-logo .logo-icon {
    font-size: 28px;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.5));
}

.sidebar-logo h1 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff 0%, #8888a8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-city {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    padding-left: 40px;
}

/* ─── Time Control Section ─── */
.time-section {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-glass);
}

.time-display {
    text-align: center;
    margin-bottom: 16px;
}

.time-display .time-value {
    font-family: var(--font-mono);
    font-size: 42px;
    font-weight: 700;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #fff 0%, var(--accent-blue) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
}

.time-display .time-seconds {
    font-family: var(--font-mono);
    font-size: 18px;
    color: var(--text-muted);
    font-weight: 400;
    vertical-align: super;
    margin-left: 2px;
}

.time-display .time-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 6px;
    font-weight: 600;
}

/* ─── Time Slider ─── */
.time-slider-wrap {
    position: relative;
    margin-bottom: 14px;
}

.time-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(90deg,
        rgba(59, 130, 246, 0.15) 0%,
        rgba(59, 130, 246, 0.3) 50%,
        rgba(59, 130, 246, 0.15) 100%);
    outline: none;
    cursor: pointer;
    transition: var(--transition);
}

.time-slider:hover {
    height: 8px;
}

.time-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: grab;
    box-shadow:
        0 0 12px rgba(59, 130, 246, 0.6),
        0 0 24px rgba(59, 130, 246, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: transform 0.15s ease;
}

.time-slider::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.2);
}

.time-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: grab;
    box-shadow:
        0 0 12px rgba(59, 130, 246, 0.6),
        0 0 24px rgba(59, 130, 246, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

/* ─── Time Controls ─── */
.time-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.time-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.time-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-color: var(--border-accent);
}

.time-btn.active {
    background: rgba(59, 130, 246, 0.2);
    color: var(--accent-blue);
    border-color: rgba(59, 130, 246, 0.4);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.15);
}

.time-btn.live-btn {
    margin-left: auto;
    font-family: var(--font-sans);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 10px;
}

.time-btn.live-btn.active {
    background: rgba(16, 185, 129, 0.2);
    color: var(--accent-green);
    border-color: rgba(16, 185, 129, 0.4);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.15);
}

.time-btn.play-btn {
    font-size: 16px;
    padding: 4px 10px;
    font-family: var(--font-sans);
}

/* ─── Lines Section ─── */
.lines-section {
    padding: 20px 24px;
    flex: 1;
    overflow-y: auto;
}

.lines-section::-webkit-scrollbar {
    width: 4px;
}

.lines-section::-webkit-scrollbar-track {
    background: transparent;
}

.lines-section::-webkit-scrollbar-thumb {
    background: var(--border-glass);
    border-radius: 2px;
}

.section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 14px;
}

.line-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.line-item:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border-glass);
}

.line-item.active {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--border-accent);
}

.line-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 8px currentColor;
}

.line-info {
    flex: 1;
    min-width: 0;
}

.line-id {
    font-size: 14px;
    font-weight: 700;
}

.line-route {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.line-toggle {
    position: relative;
    width: 40px;
    height: 22px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 11px;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.line-toggle.on {
    background: rgba(16, 185, 129, 0.3);
}

.line-toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: var(--transition);
}

.line-toggle.on::after {
    left: 21px;
    background: var(--accent-green);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

/* ─── Bus Count Badge ─── */
.bus-count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

/* ─── Info Panel ─── */
.info-section {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--border-glass);
}

.info-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 10px 0;
    font-style: italic;
}

.info-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 14px;
}

.info-card .info-line-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 10px;
}

.info-card .info-direction {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.info-card .info-detail {
    font-size: 12px;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}

.info-card .info-detail .label {
    color: var(--text-secondary);
}

/* ─── Bus Icon on Map ─── */
.bus-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.35);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.bus-marker:hover {
    transform: scale(1.25);
    z-index: 10000 !important;
}

.bus-marker.at-stop {
    animation: busPulse 1.5s ease-in-out infinite;
}

@keyframes busPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ─── Stop Marker on Map ─── */
.stop-marker-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 2px solid rgba(150, 150, 180, 0.6);
    transition: var(--transition);
}

.stop-marker-dot:hover {
    transform: scale(1.5);
    border-color: #fff;
    background: rgba(150, 150, 180, 0.4);
}

/* Leaflet popup dark theme */
.leaflet-popup-content-wrapper {
    background: var(--bg-glass) !important;
    backdrop-filter: blur(20px) !important;
    border: 1px solid var(--border-glass) !important;
    border-radius: var(--radius-md) !important;
    color: var(--text-primary) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4) !important;
    font-family: var(--font-sans) !important;
}

.leaflet-popup-tip {
    background: var(--bg-glass) !important;
    border: 1px solid var(--border-glass) !important;
}

.leaflet-popup-content {
    margin: 12px 16px !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
}

.leaflet-popup-close-button {
    color: var(--text-secondary) !important;
    font-size: 20px !important;
}

.popup-stop-name {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 4px;
}

.popup-stop-lines {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.popup-line-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    color: #fff;
}

/* ─── Sidebar Toggle (Mobile) ─── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background: var(--bg-glass-hover);
    transform: scale(1.05);
}

/* ─── Active Buses Counter (top right) ─── */
.active-counter {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.active-counter .counter-icon {
    font-size: 20px;
}

.active-counter .counter-value {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 800;
    color: var(--accent-blue);
}

.active-counter .counter-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ─── Speed indicator badge ─── */
.speed-badge {
    position: fixed;
    top: 85px;
    right: 20px;
    z-index: 1000;
    background: rgba(245, 158, 11, 0.15);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-md);
    padding: 8px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-orange);
    display: none;
    align-items: center;
    gap: 6px;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.1);
}

.speed-badge.visible {
    display: flex;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .sidebar {
        width: calc(100% - 40px);
        max-width: 360px;
        transform: translateX(-120%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .sidebar.open ~ .sidebar-toggle {
        left: calc(100% - 60px);
    }

    .active-counter {
        top: 20px;
        right: 70px;
    }
}
