/* ═══════════════════════════════════════════════════════
   MBCC Web – Vehicle Management System
   Complete Stylesheet
   ═══════════════════════════════════════════════════════ */

:root {
    --primary: #2563EB;
    --primary-dark: #1D4ED8;
    --primary-light: #DBEAFE;
    --secondary: #64748B;
    --accent: #10B981;
    --accent-light: #D1FAE5;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --bg: #F1F5F9;
    --card: #FFFFFF;
    --border: #E2E8F0;
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --transition: 0.2s ease;
}

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

html { font-size: 14px; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* ═══════════════ SCROLLBAR ═══════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* ═══════════════ LOGIN SCREEN ═══════════════ */
.login-screen {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1E3A5F 0%, #2563EB 50%, #3B82F6 100%);
    position: relative;
    overflow: hidden;
}
.login-screen::before {
    content: '';
    position: absolute;
    width: 600px; height: 600px;
    border-radius: 50%;
    background: rgba(255,255,255,0.03);
    top: -200px; right: -100px;
}
.login-screen::after {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
    bottom: -150px; left: -100px;
}
.login-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 400px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    z-index: 1;
    animation: slideUp 0.4s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.login-logo { text-align: center; margin-bottom: 32px; }
.logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px; height: 64px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 16px;
    margin-bottom: 12px;
}
.login-logo h1 { font-size: 28px; font-weight: 800; color: var(--primary); letter-spacing: -0.5px; }
.login-logo p { color: var(--text-secondary); font-size: 13px; }
.login-footer { text-align: center; margin-top: 20px; }
.secure-badge { font-size: 11px; color: var(--text-muted); }

/* ═══════════════ FORMS ═══════════════ */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; color: var(--text); font-size: 13px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: white;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.form-group input:focus, .form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; padding: 8px 12px; background: var(--danger-light); border-radius: 6px; }
.success-msg { color: var(--accent); font-size: 13px; margin-top: 8px; padding: 8px 12px; background: var(--accent-light); border-radius: 6px; }

/* ═══════════════ BUTTONS ═══════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-md); }
.btn-secondary { background: #F1F5F9; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #E2E8F0; }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: #059669; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-loader { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: white; border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ═══════════════ TOP BAR ═══════════════ */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-center { flex: 1; text-align: center; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.sidebar-toggle {
    background: none; border: none; cursor: pointer; color: var(--text);
    padding: 6px; border-radius: 6px; display: flex;
}
.sidebar-toggle:hover { background: #F1F5F9; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 20px; }
.brand-text { font-weight: 700; font-size: 16px; color: var(--primary); }
.page-title { font-weight: 600; font-size: 15px; color: var(--text); }

/* Connection Status */
.conn-status { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; }
.conn-status.connected .conn-dot { background: var(--accent); box-shadow: 0 0 6px rgba(16,185,129,0.5); }
.conn-status.connected .conn-text { color: var(--accent); }
.conn-status.disconnected .conn-dot { background: var(--danger); }
.conn-status.disconnected .conn-text { color: var(--danger); }

/* User Menu */
.user-btn { background: var(--primary); border: none; cursor: pointer; border-radius: 50%; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; }
.user-initials { color: white; font-size: 13px; font-weight: 600; }
.user-dropdown {
    position: absolute; top: calc(var(--topbar-height) - 4px); right: 16px;
    background: white; border-radius: var(--radius); box-shadow: var(--shadow-lg);
    border: 1px solid var(--border); min-width: 200px; z-index: 200; padding: 8px 0;
}
.user-dropdown .user-info { padding: 12px 16px; }
.user-dropdown .user-info strong { display: block; font-size: 14px; }
.user-dropdown .user-info small { color: var(--text-muted); }
.user-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.user-dropdown button {
    display: block; width: 100%; text-align: left; padding: 10px 16px;
    background: none; border: none; cursor: pointer; font-size: 13px; font-family: inherit; color: var(--text);
}
.user-dropdown button:hover { background: #F8FAFC; }

/* ═══════════════ SIDEBAR ═══════════════ */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 90;
    transition: transform 0.25s ease;
}
.sidebar.collapsed { transform: translateX(-100%); }
.sidebar-nav { padding: 12px 8px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px; font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}
.nav-item:hover { background: #F8FAFC; color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item svg { flex-shrink: 0; }
.nav-divider { padding: 16px 12px 8px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.admin-section { margin-top: 8px; }

/* ═══════════════ MAIN CONTENT ═══════════════ */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    height: calc(100vh - var(--topbar-height));
    overflow-y: auto;
    padding: 24px;
    transition: margin-left 0.25s ease;
}
.sidebar.collapsed ~ .main-content { margin-left: 0; }

/* ═══════════════ VIEW COMMON STYLES ═══════════════ */
.view-header { margin-bottom: 20px; }
.view-header h2 { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.view-header p { color: var(--text-secondary); font-size: 13px; }

/* Stats Cards Row */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
    background: white; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.3px; }
.stat-card .stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-card .stat-value.primary { color: var(--primary); }
.stat-card .stat-value.accent { color: var(--accent); }
.stat-card .stat-value.warning { color: var(--warning); }

/* Filter / Toolbar */
.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
    background: white; padding: 12px 16px; border-radius: var(--radius);
    border: 1px solid var(--border); box-shadow: var(--shadow);
}
.toolbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }

/* ═══════════════ DATA TABLE ═══════════════ */
.table-container {
    background: white; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead { background: #F8FAFC; position: sticky; top: 0; z-index: 2; }
.data-table th {
    padding: 12px 14px; text-align: left;
    font-weight: 600; color: var(--text-secondary); font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.3px;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #F1F5F9;
    vertical-align: middle;
}
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: #F8FAFC; }
.data-table .scroll-wrap { max-height: calc(100vh - 340px); overflow-y: auto; }

/* Row Colors */
.row-day { background: #E3F2FD !important; }
.row-night { background: #FFF8E1 !important; }
.row-alarm { background: #FFF3CD !important; }
.row-active-green { background: #E6FFE6 !important; }
.row-late { background: #FFF0E0 !important; border-left: 4px solid #F59E0B !important; }
.row-too-short { background: #FEF9C3 !important; border-left: 4px solid #EAB308 !important; }

/* Alert Bell & Badge */
.alert-bell {
    position: relative;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
}
.alert-bell:hover { background: var(--primary-light); color: var(--primary); }
.alert-badge {
    position: absolute;
    top: 0; right: 0;
    background: #EF4444;
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    animation: pulse 2s infinite;
}
.nav-badge {
    background: #EF4444;
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    margin-left: auto;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Status Badges */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
}
.badge-active { background: #D1FAE5; color: #065F46; }
.badge-completed { background: #DBEAFE; color: #1E40AF; }
.badge-normal { background: #D1FAE5; color: #065F46; }

/* ═══════════════ CARDS GRID ═══════════════ */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
    background: white; border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow); transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-body { padding: 16px; }
.card-footer { padding: 12px 16px; border-top: 1px solid var(--border); background: #FAFBFC; }

/* Photo Grid */
.photo-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.photo-grid img {
    width: 100%; height: 80px; object-fit: cover;
    border-radius: 4px; cursor: pointer;
    transition: opacity var(--transition);
}
.photo-grid img:hover { opacity: 0.85; }

/* Event Photos */
.event-photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.event-photos img {
    width: 80px; height: 60px; object-fit: cover;
    border-radius: 6px; cursor: pointer;
    border: 2px solid var(--border);
    transition: border-color var(--transition);
}
.event-photos img:hover { border-color: var(--primary); }

/* ═══════════════ MAP ═══════════════ */
.map-container { width: 100%; height: calc(100vh - 200px); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
#tracking-map { width: 100%; height: 100%; }

/* ═══════════════ MODALS ═══════════════ */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(2px); }
.modal-content {
    position: relative; background: white; border-radius: 12px;
    box-shadow: var(--shadow-lg); z-index: 1;
    max-height: 90vh; overflow: hidden; display: flex; flex-direction: column;
    animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-sm { width: 420px; max-width: 95vw; }
.modal-lg { width: 90vw; max-width: 1200px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); padding: 4px 8px; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Photo Viewer */
.photo-viewer { background: rgba(0,0,0,0.95); border-radius: 0; max-width: 100vw; width: 100vw; height: 100vh; max-height: 100vh; display: flex; align-items: center; justify-content: center; }
.photo-viewer img { max-width: 90vw; max-height: 85vh; object-fit: contain; }
.photo-close { position: absolute; top: 16px; right: 16px; color: white; font-size: 32px; z-index: 10; }
.photo-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: rgba(255,255,255,0.15); border: none; color: white;
    font-size: 48px; padding: 8px 16px; cursor: pointer; border-radius: 8px; z-index: 10;
}
.photo-nav:hover { background: rgba(255,255,255,0.25); }
.photo-prev-btn { left: 16px; }
.photo-next-btn { right: 16px; }
.photo-viewer-info { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,0.8); font-size: 13px; }

/* ═══════════════ LOADING ═══════════════ */
.loading-overlay {
    display: flex; align-items: center; justify-content: center;
    padding: 60px; color: var(--text-muted);
}
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 12px;
}
.load-more-trigger { height: 40px; display: flex; align-items: center; justify-content: center; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }

/* ═══════════════ CHECK ITEMS ═══════════════ */
.check-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.check-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; background: #F8FAFC; font-size: 12px; }
.check-ok { color: var(--accent); }
.check-fail { color: var(--danger); }

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; padding: 16px; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .photo-grid { grid-template-columns: repeat(3, 1fr); }
    .cards-grid { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .topbar-center { display: none; }
}

/* ═══════════════ PRINT ═══════════════ */
@media print {
    .topbar, .sidebar, .toolbar, .btn { display: none !important; }
    .main-content { margin: 0 !important; padding: 0 !important; }
    .data-table { font-size: 10px; }
}
