:root {
    --bg-main: #050914;
    --bg-glass: rgba(10, 15, 30, 0.6);
    --bg-glass-hover: rgba(15, 25, 45, 0.8);
    --border-glass: rgba(0, 240, 255, 0.15);
    --accent-primary: #00f0ff;
    --accent-primary-glow: rgba(0, 240, 255, 0.6);
    --accent-secondary: #8b5cf6;
    --accent-secondary-glow: rgba(139, 92, 246, 0.6);
    --status-ok: #4ade80;
    --status-error: #ff003c;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --panel-radius: 16px;
}

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

body,
html {
    height: 100%;
    width: 100%;
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    background-color: var(--bg-main);
    overflow: hidden;
    position: relative;
}

/* Scanline Overlay for Control Room Vibe */
body::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%);
    background-size: 100% 4px;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.3;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ===== SIDEBAR MENU ===== */
#sidebar-menu {
    width: 260px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    z-index: 2000;
    box-shadow: 4px 0 32px rgba(0, 240, 255, 0.05);
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-glass);
    position: relative;
    overflow: hidden;
}

.sidebar-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
}

.sidebar-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 10px var(--accent-primary-glow);
}

/* Status Indicator */
.status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.status::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #666;
    transition: background-color 0.3s ease;
}

.status.connected {
    color: #4ade80;
    background: rgba(74, 222, 128, 0.1);
}

.status.connected::before {
    background-color: #4ade80;
    box-shadow: 0 0 10px #4ade80;
    animation: pulse 2s infinite;
}

.status.error {
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
}

.status.error::before {
    background-color: #f87171;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    margin-bottom: 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: left;
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 240, 255, 0.1), transparent);
    transition: left 0.5s ease;
}

.nav-item:hover::before {
    left: 100%;
}

.nav-item .icon {
    font-size: 1.2rem;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.2));
}

.nav-item:hover {
    background: var(--bg-glass-hover);
    color: #fff;
    border-color: rgba(0, 240, 255, 0.2);
    transform: translateX(4px);
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(0, 240, 255, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
    color: #fff;
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px var(--accent-primary-glow), inset 0 0 10px rgba(0, 240, 255, 0.1);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.stats {
    display: flex;
    gap: 16px;
}

.stat-item {
    flex: 1;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: #666;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    display: block;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--accent-primary);
    text-shadow: 0 0 15px var(--accent-primary-glow);
    font-family: 'Inter', monospace;
}

/* ===== MAIN CONTENT ===== */
#main-content {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
}

#map {
    flex: 1;
    width: 100%;
    z-index: 1;
}

/* Map Controls Panel */
.control-panel {
    position: absolute;
    top: 24px;
    right: 24px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 24px;
    border-radius: var(--panel-radius);
    z-index: 1000;
    min-width: 300px;
    box-shadow: 0 8px 32px rgba(0, 240, 255, 0.1), inset 0 0 0 1px var(--border-glass);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    transition: all 0.3s ease;
}

.control-panel:hover {
    box-shadow: 0 12px 40px rgba(0, 240, 255, 0.15), inset 0 0 0 1px rgba(0, 240, 255, 0.3);
}

.control-section {
    margin-bottom: 20px;
}

.control-section:last-child {
    margin-bottom: 0;
}

.control-section label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-section select {
    width: 100%;
    padding: 12px 14px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2300f0ff'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

.control-section select:hover {
    background-color: rgba(0, 240, 255, 0.05);
    border-color: rgba(0, 240, 255, 0.4);
}

.control-section select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 10px 14px;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-size: 0.95rem;
    color: var(--text-main);
    border: 1px solid transparent;
}

.checkbox-group label:hover {
    background: rgba(0, 240, 255, 0.05);
    border-color: rgba(0, 240, 255, 0.2);
    transform: translateX(2px);
}

.checkbox-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--accent-primary);
    filter: drop-shadow(0 0 4px var(--accent-primary-glow));
}

/* Info Panel (Bus Details) */
#info-panel {
    position: absolute;
    bottom: 24px;
    left: 24px;
    width: 420px;
    max-height: 60vh;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--panel-radius);
    padding: 24px;
    z-index: 1500;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.8), inset 0 0 0 1px var(--border-glass);
    overflow-y: auto;
    transform: translateY(calc(100% + 48px));
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#info-panel:not(.hidden) {
    transform: translateY(0);
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 0, 60, 0.1);
    border: 1px solid rgba(255, 0, 60, 0.3);
    color: var(--status-error);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: var(--status-error);
    color: white;
    box-shadow: 0 0 15px rgba(255, 0, 60, 0.5);
    transform: rotate(90deg);
}

#panel-content h3 {
    font-size: 1.4rem;
    margin-bottom: 16px;
    color: #fff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 8px;
}

#panel-content p {
    font-size: 1rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 12px 0;
}

#panel-content strong {
    color: var(--accent-primary);
}

/* Map Customization */
.leaflet-container {
    background: #0a0a0a;
}

/* Custom Bus Marker */
.bus-marker {
    background: var(--accent-primary);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 15px var(--accent-primary-glow), inset 0 0 10px rgba(255, 255, 255, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    color: #050914;
    font-size: 13px;
    font-weight: 800;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.bus-marker:hover {
    transform: scale(1.4);
    box-shadow: 0 0 25px var(--accent-primary), 0 0 10px #fff;
    z-index: 1000 !important;
}

.bus-popup .leaflet-popup-content-wrapper {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--panel-radius);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
    padding: 18px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

.bus-popup .leaflet-popup-tip {
    background: var(--bg-glass);
}

.popup-content h3 {
    margin: 0 0 10px 0;
    font-size: 1.2rem;
    color: var(--accent-primary);
    text-shadow: 0 0 8px var(--accent-primary-glow);
    border-bottom: 1px solid rgba(0, 240, 255, 0.2);
    padding-bottom: 6px;
}

.popup-content p {
    margin: 8px 0;
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Route Polylines */
.route-polyline {
    stroke-width: 6;
    stroke-opacity: 0.85;
    fill: none;
    transition: all 0.3s ease;
    filter: drop-shadow(0 0 6px var(--accent-secondary-glow));
}

.route-polyline:hover {
    stroke-width: 9;
    stroke-opacity: 1;
    filter: drop-shadow(0 0 10px var(--accent-secondary));
}

/* Stop Markers */
.stop-marker {
    background: white;
    border: 3px solid var(--accent-secondary);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-secondary-glow);
    transition: all 0.3s ease;
}

.stop-marker:hover {
    transform: scale(1.5);
    box-shadow: 0 0 20px var(--accent-secondary);
    z-index: 1000 !important;
    background: var(--accent-secondary);
    border-color: white;
}

.stop-popup .leaflet-popup-content-wrapper {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border-radius: var(--panel-radius);
    color: white;
    border: 1px solid var(--accent-secondary-glow);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

.stop-popup .leaflet-popup-tip {
    background: var(--bg-glass);
}

/* Loading Spinner */
.loading {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 240, 255, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
    box-shadow: 0 0 10px var(--accent-primary-glow);
}

/* Leaflet Z-Index Fixes */
.leaflet-pane {
    z-index: 400 !important;
}

.leaflet-marker-pane {
    z-index: 600 !important;
}

.leaflet-popup-pane {
    z-index: 700 !important;
}

.custom-bus-icon-wrapper {
    background: transparent;
    border: none;
}

/* Responsive */
@media (max-width: 1024px) {
    #sidebar-menu {
        width: 200px;
    }

    .control-panel {
        right: 12px;
        top: 12px;
        min-width: 240px;
    }

    #info-panel {
        width: 340px;
        left: 12px;
        bottom: 12px;
    }
}

@media (max-width: 768px) {
    #sidebar-menu {
        width: 70px;
    }

    .sidebar-header h2,
    .nav-item .label,
    .sidebar-footer {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .control-panel {
        width: calc(100% - 94px);
        right: 12px;
    }

    #info-panel {
        width: calc(100% - 94px);
        max-height: 50vh;
    }
}