/* PREMIUM DESIGN SYSTEM - FLEET PORTAL */
:root {
    /* Modern Slate Palette */
    --primary: #3b82f6;
    /* Blue 500 */
    --primary-glow: rgba(59, 130, 246, 0.4);
    --primary-dark: #2563eb;
    /* Blue 600 */

    --bg-dark: #0f172a;
    /* Slate 900 */
    --bg-darker: #020617;
    /* Slate 950 */
    --surface-dark: #1e293b;
    /* Slate 800 */
    --surface-hover: #334155;
    /* Slate 700 */

    --border-dark: #334155;
    /* Slate 700 */
    --text-main: #f8fafc;
    /* Slate 50 */
    --text-muted: #94a3b8;
    /* Slate 400 */

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --sidebar-width: 280px;
    /* Slightly wider for better spacing */
    --header-height: 70px;
    /* Taller header */

    /* Shadows */
    --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);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 10px 10px -5px rgb(0 0 0 / 0.04);
}

html[data-theme="light"] {
    --bg-dark: #f8fafc;
    /* Slate 50 */
    --bg-darker: #ffffff;
    --surface-dark: #ffffff;
    --surface-hover: #f1f5f9;
    /* Slate 100 */
    --border-dark: #e2e8f0;
    /* Slate 200 */
    --text-main: #0f172a;
    /* Slate 900 */
    --text-muted: #64748b;
    /* Slate 500 */
}

body {
    background: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin: 0;
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* --- UTILITIES --- */
.glass {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

html[data-theme="light"] .glass {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.fade-in {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes float {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-4px);
    }

    100% {
        transform: translateY(0px);
    }
}

/* --- LAYOUT --- */
.app-layout {
    display: flex;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-darker);
    border-right: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    font-weight: 800;
    font-size: 1.2rem;
    letter-spacing: -0.025em;
    background: linear-gradient(to right, var(--bg-darker), var(--surface-dark));
}

/* --- NAVIGATION --- */
.nav-links {
    flex: 1;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.85rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 12px;
    font-weight: 500;
    font-size: 0.95rem;
    letter-spacing: 0.01em;
    position: relative;
    overflow: hidden;
}

.nav-item i {
    width: 24px;
    margin-right: 12px;
    text-align: center;
    font-size: 1.1rem;
    transition: transform 0.3s ease;
}

.nav-item:hover {
    background: var(--surface-hover);
    color: var(--text-main);
    transform: translateX(4px);
}

.nav-item:hover i {
    transform: scale(1.1);
    color: var(--primary);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.1), transparent);
    color: var(--primary);
    font-weight: 600;
    border-left: 3px solid var(--primary);
    border-radius: 0 12px 12px 0;
    /* Only round right side */
    box-shadow: none;
    /* Cleaner look */
}

.nav-item.active i {
    color: var(--primary);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    position: relative;
}

.top-bar {
    height: var(--header-height);
    background: var(--surface-dark);
    border-bottom: 1px solid var(--border-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    z-index: 30;
}

/* --- DASHBOARD COMPONENTS --- */
.dashboard-grid {
    padding: 1.5rem;
    flex: 1;
    display: grid;
    grid-template-columns: 380px 1fr;
    /* Wider list */
    gap: 1.5rem;
    overflow: hidden;
}

.panel {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.panel-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-dark);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-dark);
    /* Slightly darker header */
}

/* --- DEVICE LIST (The Floating Cards) --- */
.device-list {
    overflow-y: auto;
    flex: 1;
    padding: 10px;
    background: var(--bg-dark);
    /* Subtle contrast */
}

.device-item {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
    border-radius: 16px;
    padding: 1.2rem;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.device-item:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.device-item.active {
    border: 2px solid var(--primary);
    background: linear-gradient(to right, rgba(59, 130, 246, 0.05), transparent);
}

/* --- MAP --- */
#fleetMap {
    width: 100%;
    height: 100%;
    z-index: 1;
}

.map-controls {
    position: absolute;
    bottom: 30px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.map-btn {
    width: 50px;
    height: 50px;
    border-radius: 16px;
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    font-size: 1.25rem;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Bouncy */
}

.map-btn:hover {
    transform: scale(1.1);
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* --- UI ELEMENTS --- */
.badge {
    padding: 6px 12px;
    border-radius: 30px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 6px var(--primary-glow);
}

.btn-primary:hover {
    box-shadow: 0 8px 15px var(--primary-glow);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-dark);
    color: var(--text-muted);
}

.btn-outline:hover {
    border-color: var(--text-main);
    color: var(--text-main);
    background: var(--surface-hover);
}

.form-control {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    color: var(--text-main);
    padding: 0.85rem 1rem;
    border-radius: 12px;
    font-family: inherit;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* --- MOBILE RESPONSIVE --- */
.mobile-menu-btn {
    display: none;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(4px);
}

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

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        box-shadow: var(--shadow-xl);
    }

    .sidebar.open {
        transform: translateX(100%);
    }

    .mobile-menu-btn {
        display: block;
        background: transparent;
        border: none;
        font-size: 1.5rem;
        color: var(--text-main);
        padding: 5px;
        margin-right: 15px;
        cursor: pointer;
    }

    .top-bar {
        padding: 0 1rem;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        padding: 0;
        gap: 0;
        grid-template-rows: 1fr auto;
        /* Map then Bottom Sheet */
    }

    .dashboard-grid .panel:last-child {
        /* Map Panel (now usually on top visually or flex order) */
        border-radius: 0;
        border: none;
        order: 1;
        /* Map first */
    }

    .dashboard-grid .panel:first-child {
        /* List Panel (Bottom Sheet) */
        order: 2;
        border-radius: 24px 24px 0 0;
        height: 45vh;
        z-index: 20;
        border: none;
        border-top: 1px solid var(--border-dark);
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
    }
}


html[data-theme="light"] {
    --bg-dark: #f8fafc;
    --bg-darker: #ffffff;
    --surface-dark: #ffffff;
    --border-dark: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(15 23 42 / 0.08), 0 2px 4px -2px rgb(15 23 42 / 0.08);
}

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

/* Authentication Page */
.auth-wrapper {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, var(--surface-dark) 0%, var(--bg-darker) 100%);
}

.auth-card {
    background: var(--surface-dark);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-dark);
    padding: 2rem;
    border-radius: 24px;
    width: 100%;
    max-width: 550px;
    box-shadow: var(--shadow-xl);
    color: var(--text-main);
}

.input-group {
    margin-bottom: 20px;
    /* More breathing room */
}

.brand-section {
    text-align: center;
    margin-bottom: 2rem;
}

.brand-section i {
    font-size: 2.5rem;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Dashboard Layout */
.app-layout {
    display: flex;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Sidebar Overlay (Mobile) */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-darker);
    border-right: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.3s ease;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-dark);
    font-weight: 700;
    letter-spacing: 0.5px;
    font-size: 1.1rem;
}

.nav-links {
    flex: 1;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.8rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    border-radius: 8px;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--bg-dark);
    color: var(--text-main);
}

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

.nav-item i {
    width: 24px;
    margin-right: 12px;
    text-align: center;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-dark);
}

.top-bar {
    height: var(--header-height);
    background: var(--surface-dark);
    border-bottom: 1px solid var(--border-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    z-index: 30;
    box-shadow: var(--shadow-sm);
}

.mobile-menu-btn {
    display: none;
    /* Desktop default */
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.25rem;
    margin-right: 15px;
    cursor: pointer;
    padding: 5px;
}

/* Dashboard Widgets */
.dashboard-grid {
    padding: 3rem;
    /* Increased padding */
    overflow-y: auto;
    display: grid;
    grid-template-columns: 400px 1fr;
    /* Wider sidebar list */
    gap: 2.5rem;
    /* Increased gap */
    height: calc(100vh - var(--header-height));
}

.panel {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
    border-radius: 20px;
    /* Smoother */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    /* Deeper shadow */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.panel:hover {
    box-shadow: var(--shadow-lg);
}

.panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-dark);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-dark);
    /* Contrast header */
}

/* Device List */
.device-list {
    overflow-y: auto;
    flex: 1;
}

.device-item {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-dark);
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.device-item:hover {
    background: var(--bg-dark);
}

.device-item.active {
    background: rgba(59, 130, 246, 0.05);
}

.device-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary);
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.05);
}

.status-dot.online {
    background: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.status-dot.offline {
    background: #64748b;
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    /* Pill shape */
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-gps {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.badge-bus {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

/* Forms & Buttons */
.form-control {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    color: var(--text-main);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-family: inherit;
    transition: border 0.2s, box-shadow 0.2s;
    height: 50px;
    /* Taller inputs */
    font-size: 1rem;
}

.form-control:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 6px 10px rgba(59, 130, 246, 0.4);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-dark);
    color: var(--text-muted);
}

.btn-outline:hover {
    border-color: var(--text-main);
    color: var(--text-main);
    background: var(--bg-dark);
}

.btn-mini {
    padding: 4px 10px;
    font-size: 0.75rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    color: var(--text-main);
    border-radius: 6px;
    cursor: pointer;
}

.btn-mini:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

/* ---------------- OTHERS ---------------- */
.blurred {
    filter: blur(8px);
    pointer-events: none;
    user-select: none;
}

.locked-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    background: rgba(15, 23, 42, 0.9);
    padding: 40px;
    border-radius: 24px;
    border: 1px solid var(--border-dark);
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    min-width: 320px;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: translate(-50%, -40%) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.lock-icon {
    font-size: 3rem;
    color: var(--warning);
    margin-bottom: 5px;
    filter: drop-shadow(0 0 10px rgba(245, 158, 11, 0.3));
}

.lock-icon.maintenance {
    color: #3b82f6;
    /* Blue for maintenance */
    filter: drop-shadow(0 0 10px rgba(59, 130, 246, 0.3));
}

.lock-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.lock-desc {
    color: var(--text-muted);
    font-size: 0.95rem;
    max-width: 300px;
    margin: 0 auto;
    line-height: 1.5;
}

/* ---------------- MOBILE RESPONSIVE ---------------- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        /* Hidden off-screen */
        top: 0;
        bottom: 0;
        box-shadow: var(--shadow-lg);
        background: var(--surface-dark);
    }

    .sidebar.open {
        transform: translateX(100%);
        /* Slide in */
        left: -260px;
        /* Offset because transform is relative */
        /* Correct: */
        transform: none;
        left: 0;
    }

    .mobile-menu-btn {
        display: block;
    }

    .top-bar {
        padding: 0 1rem;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        /* Stack */
        grid-template-rows: 1fr 400px;
        /* Map flex, List fixed height */
        padding: 0;
        /* Remove padding for edge-to-edge map */
        gap: 0;
    }

    /* List Panel becomes a bottom sheet/section */
    .dashboard-grid .panel:first-child {
        order: 2;
        /* Move list below map */
        border-radius: 20px 20px 0 0;
        border: none;
        border-top: 1px solid var(--border-dark);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
        z-index: 10;
        height: 400px;
        /* Fixed height for list area */
    }

    /* Map Controls Position Fix */
    .map-controls {
        position: absolute;
        bottom: 30px;
        right: 20px;
        display: flex;
        flex-direction: column;
        gap: 12px;
        z-index: 5000;
        /* Force above everything */
    }

    .map-btn {
        width: 48px;
        height: 48px;
        border-radius: 14px;
        background: var(--surface-dark);
        border: 1px solid var(--border-dark);
        color: var(--text-main);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        /* Deep shadow */
        transition: all 0.2s ease;
        font-size: 1.2rem;
    }

    .map-btn:hover {
        transform: translateY(-3px) scale(1.05);
        background: var(--bg-dark);
        color: var(--primary);
        border-color: var(--primary);
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    }

    /* Adjust view sections padding */
    .view-section {
        height: 100%;
    }

    /* Hide some details on mobile list to save space */
    .device-item {
        padding: 0.8rem 1rem;
    }

    .device-item i.fa-external-link-alt {
        display: none;
    }
}

/* --- MODALS --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
}

.modal-content {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: var(--shadow-xl);
    width: 100%;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}