/* CSS Design System for Fleet Analytics Dashboard */
/* Google Fonts loaded via <link> in index.html for parallel loading */

:root {
    --bg-main: #0b0f19;
    --bg-card: #151b2c;
    --bg-sidebar: #0e1320;
    --border-color: #222c44;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --color-primary: #38bdf8;
    --color-primary-glow: rgba(56, 189, 248, 0.15);
    --color-success: #10b981;
    --color-success-glow: rgba(16, 185, 129, 0.15);
    --color-warning: #fbbf24;
    --color-warning-glow: rgba(251, 191, 36, 0.15);
    --color-danger: #f87171;
    --color-danger-glow: rgba(248, 113, 113, 0.15);
    
    --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --card-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.3);
    --glow-shadow: 0 0 20px rgba(56, 189, 248, 0.25);
}

html {
    font-size: 14px;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow-x: hidden;
    height: 100vh;
    display: flex;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.3);
    border-radius: 4px;
    border: 1px solid var(--border-color);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

/* Layout */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    height: 100%;
    flex-shrink: 0;
}

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

.logo-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--color-primary), #0284c7);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
}

.logo-text {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.nav-item:hover, .nav-item.active {
    color: var(--text-primary);
    background-color: var(--border-color);
}

.nav-item.active {
    background: linear-gradient(90deg, var(--border-color), rgba(56, 189, 248, 0.05));
    border-left: 3px solid var(--color-primary);
}

/* Live open-issues count on the "Vehicle Issues" nav item */
.nav-badge {
    margin-left: auto;
    background-color: var(--color-danger);
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 800;
    border-radius: 100px;
    padding: 2px 8px;
    min-width: 22px;
    text-align: center;
    line-height: 1.4;
}

/* Vehicle Issues table: severity accent + inline status control */
.issue-row-high td:first-child { border-left: 3px solid var(--color-danger); }
.issue-row-medium td:first-child { border-left: 3px solid var(--color-warning); }
.issue-row-low td:first-child { border-left: 3px solid var(--color-primary); }
tr.issue-resolved td { opacity: 0.55; }

.issue-status-select {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 100px;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}
.issue-status-select.status-open { color: var(--color-danger); border-color: rgba(248, 113, 113, 0.5); }
.issue-status-select.status-in-progress { color: var(--color-warning); border-color: rgba(251, 191, 36, 0.5); }
.issue-status-select.status-resolved { color: var(--color-success); border-color: rgba(16, 185, 129, 0.5); }

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
    margin-top: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 40px;
    border-bottom: 1px solid var(--border-color);
    background-color: rgba(11, 15, 25, 0.8);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.page-title h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.page-title p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.time-badge {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--color-primary);
    font-weight: 600;
}

/* Page Containers */
.page-container {
    padding: 30px 40px;
    display: none;
}

.page-container.active {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 76px); /* fill the area below the sticky top-bar */
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* KPI Banner */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.kpi-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    transition: transform var(--transition-fast);
}

.kpi-card:hover {
    transform: translateY(-2px);
    border-color: rgba(56, 189, 248, 0.4);
}

.kpi-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.kpi-value {
    font-size: 2rem;
    font-weight: 800;
    margin: 10px 0 5px 0;
    color: var(--text-primary);
}

.kpi-trend {
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.trend-up { color: var(--color-success); }
.trend-down { color: var(--color-danger); }
.trend-warning { color: var(--color-warning); }

.kpi-icon {
    position: absolute;
    right: 20px;
    top: 20px;
    color: var(--text-muted);
    opacity: 0.25;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 25px;
    margin-bottom: 30px;
}

@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

.chart-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--card-shadow);
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

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

/* Tables and Filters */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 20px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px;
}

.search-input-wrapper {
    position: relative;
    flex-grow: 1;
    max-width: 400px;
}

.search-input-wrapper svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input {
    width: 100%;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px 10px 40px;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition-fast);
}

.search-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.1);
}

.filter-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.filter-select {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

.filter-select:focus {
    border-color: var(--color-primary);
}

.filter-reset-btn {
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.2s;
}
.filter-reset-btn:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.table-wrapper {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    flex: 1 1 auto;        /* grow to fill remaining page height */
    min-height: 0;         /* allow the inner scroll area to size correctly */
    display: flex;
    flex-direction: column;
}

.table-scroll {
    overflow-x: auto;
    overflow-y: auto;
    flex: 1 1 auto;        /* fill the table card so the grid uses the full page height */
    min-height: 240px;     /* never collapse on short content/viewports */
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* Long free-text columns may wrap so the table fits the viewport instead of
   overflowing horizontally. Numeric/short columns stay on one line. */
.custom-table td.wrap,
.custom-table th.wrap {
    white-space: normal;
    min-width: 130px;
}

.custom-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #151b2c; /* Solid match for var(--bg-card) */
    color: var(--text-secondary);
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
}

.custom-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.custom-table td.action-cell,
.custom-table th.action-cell {
    text-align: center !important;
    white-space: nowrap;
}

.custom-table tr:last-child td {
    border-bottom: none;
}

.custom-table tr:hover td {
    background-color: rgba(255, 255, 255, 0.015);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background-color: var(--color-success-glow);
    color: var(--color-success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
    background-color: var(--color-warning-glow);
    color: var(--color-warning);
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.badge-danger {
    background-color: var(--color-danger-glow);
    color: var(--color-danger);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.badge-info {
    background-color: var(--color-primary-glow);
    color: var(--color-primary);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-card);
}

.pagination-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.pagination-btn-group {
    display: flex;
    gap: 8px;
}

.btn {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition-fast);
}

.btn:hover:not(:disabled) {
    background-color: var(--border-color);
    border-color: var(--text-muted);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Card view for vehicles list */
.vehicles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.vehicle-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--card-shadow);
    transition: transform var(--transition-fast), border-color var(--transition-fast);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.vehicle-card:hover {
    transform: translateY(-3px);
    border-color: var(--color-primary);
    box-shadow: var(--glow-shadow);
}

.card-header-v {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 15px;
}

.reg-no {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}

.site-lbl {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background-color: var(--bg-main);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.v-model {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    line-height: 1.4;
    min-height: 40px;
}

.card-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
    font-size: 0.85rem;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.meta-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.meta-val {
    font-weight: 600;
    color: var(--text-primary);
}

/* Modal detail view */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

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

.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 650px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    overflow: hidden;
    transform: scale(0.9);
    transition: transform var(--transition-normal);
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    transition: var(--transition-fast);
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 15px;
    color: var(--color-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.alert-item-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: var(--transition-fast);
}

.alert-item-container:hover {
    border-color: rgba(255,255,255,0.1);
}

.alert-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.alert-title-text {
    font-weight: 700;
    font-size: 0.95rem;
}

.alert-subtitle-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Reports & PDF Print Override Classes */
.pdf-print-mode {
    background-color: #ffffff !important;
    color: #000000 !important;
    padding: 20px !important;
    font-size: 9px !important;
}

.pdf-print-mode h2,
.pdf-print-mode h3,
.pdf-print-mode span,
.pdf-print-mode strong,
.pdf-print-mode div,
.pdf-print-mode p {
    color: #0d1527 !important;
}

.pdf-print-mode .custom-table {
    font-size: 8.5px !important;
    width: 100% !important;
}

.pdf-print-mode .custom-table th {
    background-color: #f1f5f9 !important;
    color: #334155 !important;
    border-bottom: 2px solid #cbd5e1 !important;
    padding: 5px 6px !important;
    font-size: 8.5px !important;
}

.pdf-print-mode .custom-table td {
    color: #334155 !important;
    border-bottom: 1px solid #e2e8f0 !important;
    padding: 5px 6px !important;
    font-size: 8.5px !important;
}

.pdf-print-mode .custom-table tr:hover td {
    background-color: transparent !important;
}

.pdf-print-mode div[style*="background-color"] {
    background-color: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
}

/* Page break protection for table rows in PDF */
#report-print-area tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
}

/* ========================================= */
/* MOBILE RESPONSIVENESS                     */
/* ========================================= */

.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background-color: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-only {
    display: none;
}

.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 1400;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 1024px) {
    body {
        flex-direction: column;
    }

    .mobile-header {
        display: flex;
    }

    .mobile-only {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 280px;
        height: 100vh;
        z-index: 1500;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }

    .sidebar.active {
        transform: translateX(300px);
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    @media (max-width: 480px) {
        .kpi-grid {
            grid-template-columns: 1fr;
        }
    }

    .charts-grid,
    .modal-info-grid,
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns: repeat(3, 1fr)"] {
        grid-template-columns: 1fr !important;
    }

    .main-content {
        padding: 15px;
    }

    .top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        margin-bottom: 20px;
    }

    .action-buttons {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 5px;
    }
    
    .action-buttons .btn {
        flex-shrink: 0;
    }

    .table-wrapper {
        margin: 0 -15px;
        padding: 0;
        width: calc(100% + 30px);
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-scroll .custom-table {
        min-width: 800px;
        font-size: 0.78rem;
    }
    
    .table-scroll .custom-table th,
    .table-scroll .custom-table td {
        padding: 8px 10px;
    }

    .modal-content {
        width: 95% !important;
        margin: 20px auto;
        padding: 20px;
    }
    
    /* Make inline display: flex inputs wrap */
    .filter-bar, div[style*="display: flex; gap: 15px; margin-bottom: 25px;"] {
        flex-direction: column;
        align-items: stretch !important;
    }
    
    .search-container {
        max-width: 100%;
    }
    
    .time-badge {
        display: none !important;
    }
}
