:root {
    --primary: #4F46E5;
    --primary-dark: #3730A3;
    --primary-light: rgba(79, 70, 229, 0.1);
    --bg: #F8FAFC;
    --card-bg: #ffffff;
    --text-main: #0F172A;
    --text-light: #64748B;
    --border: #E2E8F0;
    --input-bg: #F1F5F9;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --sidebar-width: 280px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

[data-theme="dark"] {
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --bg: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f1f5f9;
    --text-light: #94a3b8;
    --border: #334155;
    --input-bg: #0f172a;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* --- Auth Screen (Fix for Map Overlay) --- */
#authScreen {
    position: relative;
    z-index: 3000;
    /* Must be higher than Map (0) and AppShell (10) */
    background: var(--bg);
}

/* --- App Shell --- */
.app-header {
    background: var(--card-bg);
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    /* High enough to stay above map (1) and content (0) */
    border-bottom: 1px solid var(--border);
    height: 64px;
}


.header-title {
    font-size: 1.15rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.menu-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 1rem;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.menu-btn:active {
    transform: scale(0.9);
    background: var(--border);
}


/* --- Sidebar (Off-canvas) --- */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--card-bg);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar.active {
    transform: translateX(0);
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    padding: 30px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary), #3B82F6);
    color: white;
}

.driver-avatar-wrapper {
    position: relative;
    width: 64px;
    height: 64px;
    margin-bottom: 15px;
}

.driver-avatar {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    overflow: hidden;
}

.driver-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.nav-links {
    list-style: none;
    padding: 20px 10px;
    margin: 0;
    flex: 1;
}

.nav-item {
    padding: 15px 20px;
    margin-bottom: 5px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 15px;
    transition: all 0.2s;
}

.nav-item:hover {
    background: var(--bg);
    color: var(--primary);
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.nav-item i {
    width: 20px;
    text-align: center;
}

/* --- App Shell --- */
.app-header {
    background: var(--card-bg);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid var(--border);
    height: 60px;
}

/* --- Views --- */
.view-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding-top: 0;
    min-height: 0;
    /* CRITICAL for flex scrolling */
}

.view-section {
    min-height: 100%;
    width: 100%;
    display: none;
    flex-direction: column;
}

.view-section.active-view {
    display: flex;
}

.view-container {
    max-width: 650px;
    margin: 0 auto;
    width: 100%;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

/* --- Helper Classes --- */
.h-100 {
    height: calc(100vh - 60px) !important;
    background: var(--bg);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* --- Components --- */
.container {
    max-width: 600px;
    margin: 0 auto;
}

.card {
    background: var(--card-bg);
    border-radius: 24px;
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:active {
    transform: scale(0.99);
}

/* Timeline Components */
.timeline-container {
    position: relative;
    padding-left: 20px;
    margin-left: 10px;
    border-left: 2px solid var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 25px;
    padding-left: 20px;
}

.timeline-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 15px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

.timeline-item.active .timeline-card {
    border-color: var(--primary);
    box-shadow: 0 4px 12px var(--primary-light);
    background: rgba(79, 70, 229, 0.02);
}

.timeline-item.passed .timeline-card {
    opacity: 0.8;
}

.timeline-item.cancelled .timeline-card {
    background: #fff5f5;
    border-color: #feb2b2;
}

.timeline-dot {
    position: absolute;
    left: -27px;
    top: 5px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--border);
}

.timeline-item.active .timeline-dot {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

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

.timeline-item.cancelled .timeline-dot {
    background: var(--danger);
    border-color: var(--danger);
}

/* Dashboard Action Center */
.action-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 15px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.trip-pill {
    background: var(--primary-light);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 700;
}

.btn {
    width: 100%;
    padding: 15px;
    border-radius: 14px;
    border: none;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-light);
}

.btn-xl {
    font-size: 1.2rem;
    padding: 20px;
    letter-spacing: 0.5px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 0.9rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text-light);
}

.status-badge.live {
    background: #dcfce7;
    color: #166534;
    border-color: #86efac;
}

/* Auth & Forms */
.form-input {
    width: 100%;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 1rem;
    margin-bottom: 15px;
}

.hidden {
    display: none !important;
}

/* Trip Items */
.trip-leg {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--input-bg);
    border-radius: 12px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
}

.trip-leg.active-leg {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.leg-type {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 8px;
}

.leg-type.fwd {
    background: #dbeafe;
    color: #1e40af;
}

.leg-type.ret {
    background: #fef3c7;
    color: #92400e;
}

/* --- Map Containers --- */
.map-box-wrap {
    height: 300px;
    /* Standard box height */
    width: 100%;
    position: relative;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#driverMap {
    height: 100%;
    width: 100%;
    z-index: 1;
    transition: all 0.3s ease;
}

/* Fullscreen State */
.fullscreen-active {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100vh !important;
    height: 100dvh !important;
    width: 100vw !important;
    z-index: 5000 !important;
    border-radius: 0;
    margin: 0;
    background: var(--bg);
    /* Prevent see-through */
}

.map-expand-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    color: var(--text-main);
    transition: all 0.2s;
}

.map-expand-btn:active {
    transform: scale(0.9);
}

.fullscreen-active .map-expand-btn {
    background: var(--danger);
    color: white;
}

/* Recenter Button Logic */
#recenterBtn {
    position: absolute;
    bottom: 25px;
    right: 25px;
    width: 46px;
    height: 46px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: none;
    /* Hidden in boxed mode */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-light);
    z-index: 1001;
    transition: all 0.2s;
}

.fullscreen-active #recenterBtn {
    display: flex;
    /* Visible ONLY in full screen */
}

#recenterBtn.active-center {
    color: var(--primary);
}


/* Map Overlay Info */
.map-overlay-info {
    position: absolute;
    bottom: 10px;
    /* Above controls? No, hide behind or move */
    left: 10px;
    /* Actually bottom sheet covers bottom area. Let's move this to top right or hide */
    display: none !important;
    /* Hide simplified overlay, use top card instead */
    flex-direction: column;
}

/* Leaflet Smoothness */


.custom-bus-icon div {
    transition: background 0.3s, border-color 0.3s, transform 0.3s ease-out;
    transform-origin: center;
}

.stop-icon-special div,
.stop-icon-dot div,
.stop-icon-passed div {
    transition: all 0.3s ease;
}

/* Fix overlay to viewport in fullscreen */
.fullscreen-active .map-overlay-info {
    position: fixed;
    bottom: 40px;
    left: 20px;
    z-index: 2001;
    display: flex;
}

.map-info-title {
    font-size: 0.75rem;
    color: var(--text-light);
    font-weight: 700;
    text-transform: uppercase;
}

.map-info-val {
    font-size: 1.1rem;
    color: var(--text-main);
    font-weight: 800;
}

[data-theme="dark"] .map-overlay-info {
    background: rgba(30, 41, 59, 0.9);
    color: var(--text-main);
}

[data-theme="dark"] .map-expand-btn {
    background: #334155;
    color: white;
}

[data-theme="dark"] .fullscreen-active .map-expand-btn {
    background: var(--danger);
}

/* Dark Mode Adjustments */
[data-theme="dark"] .dashboard-top-card,
[data-theme="dark"] .dashboard-bottom-sheet {
    background: rgba(30, 41, 59, 0.95);
    color: white;
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .app-header {
    background: rgba(30, 41, 59, 0.9);
}

/* --- User Panel Map Styles (Synced) --- */
.location-marker {
    width: 24px;
    height: 24px;
    background: var(--primary);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.3);
    animation: pulse-dot 1.5s infinite;
}

.stop-marker-dot {
    width: 14px;
    height: 14px;
    background: white;
    border: 3px solid var(--text-light);
    /* Grey border like timeline */
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@keyframes pulse-dot {
    0% {
        box-shadow: 0 0 0 0px rgba(59, 130, 246, 0.4);
    }

    100% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }
}