:root {
    --bg-color: #0b0f19;
    --panel-bg: rgba(17, 24, 39, 0.75);
    --panel-border: rgba(255, 255, 255, 0.08);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.4);
    --accent: #10b981;
    --accent-glow: rgba(16, 185, 129, 0.3);
    --text-color: #f3f4f6;
    --text-muted: #9ca3af;
    --card-bg: rgba(31, 41, 55, 0.6);
    --glass-blur: 16px;
    --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Plus Jakarta Sans', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    height: -webkit-fill-available;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

html {
    height: 100vh;
    height: -webkit-fill-available;
    margin: 0;
    padding: 0;
}

#map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#map {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
}

/* Customize Leaflet Controls for Dark Theme compatibility */
.leaflet-bar {
    border: 1px solid var(--panel-border) !important;
    box-shadow: var(--shadow-lg) !important;
    border-radius: 12px !important;
    overflow: hidden;
}

.leaflet-bar a {
    background-color: var(--panel-bg) !important;
    color: var(--text-color) !important;
    border-bottom: 1px solid var(--panel-border) !important;
    backdrop-filter: blur(var(--glass-blur)) !important;
    transition: all 0.2s;
}

.leaflet-bar a:hover {
    background-color: rgba(99, 102, 241, 0.2) !important;
    color: #ffffff !important;
}

.leaflet-bar a:first-child {
    border-top-left-radius: 12px !important;
    border-top-right-radius: 12px !important;
}

.leaflet-bar a:last-child {
    border-bottom-left-radius: 12px !important;
    border-bottom-right-radius: 12px !important;
    border-bottom: none !important;
}

/* Glass Panels Overlay */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-lg);
    border-radius: 16px;
    z-index: 1010;
}

/* App Header */
.app-header {
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Action Button style */
.circle-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-lg);
    z-index: 1015;
}

.circle-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
    color: white;
    transform: scale(1.05);
}

.circle-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
    color: white;
}

/* Quick Map Action Controls (right side floating buttons) */
.map-actions {
    position: absolute;
    right: 1rem;
    top: 6rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 1015;
}

/* Route Drawer (Bottom sliding drawer on mobile, side panel on desktop) */
.drawer {
    position: absolute;
    z-index: 1025;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

/* Mobile: Bottom Drawer and Docked Header/Footer panels */
@media (max-width: 767px) {
    .drawer {
        bottom: 0;
        left: 0;
        right: 0;
        height: 80vh;
        max-height: 80vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        transform: translateY(100%);
    }

    .drawer.open {
        transform: translateY(0);
    }

    .drawer-handle {
        width: 40px;
        height: 5px;
        background-color: var(--text-muted);
        border-radius: 3px;
        margin: 0.75rem auto 0.25rem auto;
        opacity: 0.4;
    }

    /* Header docked to top */
    .app-header {
        top: 0;
        left: 0;
        right: 0;
        border-radius: 0;
        border-width: 0 0 1px 0;
        padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
        background-color: rgba(11, 15, 25, 0.95);
    }

    /* Adjust map actions down to avoid overlapping the top header */
    .map-actions {
        top: calc(5.5rem + env(safe-area-inset-top, 0px));
        right: 0.75rem;
    }

    /* Dashboard docked to bottom */
    .nav-dashboard {
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        border-width: 1px 0 0 0;
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
        transform: translateY(100%);
        background-color: rgba(11, 15, 25, 0.95);
    }

    .nav-dashboard.show {
        transform: translateY(0);
    }

    /* 2x2 grid on mobile for clean text wrapping and readability */
    .nav-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .nav-stat-box {
        padding: 0.6rem 0.5rem;
    }
}

/* Desktop: Side Panel */
@media (min-width: 768px) {
    .drawer {
        top: 1rem;
        left: 1rem;
        bottom: 1rem;
        width: 380px;
        height: calc(100% - 2rem);
        transform: translateX(-400px);
    }

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

    .drawer-handle {
        display: none;
    }
}

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

.drawer-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.search-box {
    padding: 0.75rem 1.5rem;
    position: relative;
    border-bottom: 1px solid var(--panel-border);
}

.search-input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.25rem;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 10px;
    color: white;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--primary);
}

.search-icon {
    position: absolute;
    left: 2.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.route-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Route Cards inside List */
.route-item {
    background: var(--card-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.route-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.route-item.selected {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.15);
}

.route-item h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: white;
}

.route-item p {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.route-item-meta {
    margin-top: 0.75rem;
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Bottom Navigation Dashboard Card */
.nav-dashboard {
    position: absolute;
    bottom: 1.5rem;
    left: 1.5rem;
    right: 1.5rem;
    padding: 1.25rem;
    z-index: 1020;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateY(150%);
    max-width: 600px;
}

@media (min-width: 768px) {
    .nav-dashboard {
        left: 50%;
        right: auto;
        transform: translate(-50%, 150%);
        width: 500px;
    }
}

.nav-dashboard.show {
    transform: translateY(0);
}

@media (min-width: 768px) {
    .nav-dashboard.show {
        transform: translate(-50%, 0);
    }
}

.nav-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.nav-title {
    font-weight: 700;
    font-size: 1.05rem;
}

.nav-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    max-height: 80px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.nav-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    text-align: center;
}

.nav-stat-box {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.5rem 0.25rem;
}

.nav-stat-val {
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
}

.nav-stat-lbl {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.2rem;
}

.nav-buttons {
    display: flex;
    gap: 0.75rem;
}

.nav-btn {
    flex: 1;
    padding: 0.75rem;
    border-radius: 10px;
    border: none;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.nav-btn-start {
    background: var(--primary);
    color: white;
}

.nav-btn-start:hover {
    background: var(--primary-hover);
}

.nav-btn-stop {
    background: var(--danger, #ef4444);
    color: white;
}

.nav-btn-stop:hover {
    background: #dc2626;
}

/* User GPS Marker Pulse */
.gps-pulse-marker {
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
    animation: pulse 1.6s infinite;
}

.gps-pulse-marker-inner {
    width: 12px;
    height: 12px;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

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

/* Compass arrow helper */
.gps-heading-arrow {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 12px solid var(--accent);
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* Toast Message standard style */
.toast-msg {
    position: fixed;
    top: 5.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(17, 24, 39, 0.9);
    border: 1px solid var(--panel-border);
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 2000;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast-msg.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Custom Scrollbar for Drawer List */
.route-list::-webkit-scrollbar {
    width: 6px;
}

.route-list::-webkit-scrollbar-track {
    background: transparent;
}

.route-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.route-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Custom Scrollbar for Nav Description */
.nav-desc::-webkit-scrollbar {
    width: 4px;
}

.nav-desc::-webkit-scrollbar-track {
    background: transparent;
}

.nav-desc::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.nav-desc::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

