/* ══════════════════════════════════════════
   DriverBook Dashboard — Design System
   ══════════════════════════════════════════ */

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.25);
    --bg: #0a0f1e;
    --bg-surface: #111827;
    --bg-card: #1a2236;
    --bg-card-hover: #1f2a42;
    --text: #f1f5f9;
    --text-dim: #8896b0;
    --text-muted: #4b5c78;
    --accent: #06b6d4;
    --green: #10b981;
    --green-bg: rgba(16, 185, 129, 0.12);
    --amber: #f59e0b;
    --amber-bg: rgba(245, 158, 11, 0.12);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.10);
    --border: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(255, 255, 255, 0.14);
    --glass: rgba(255, 255, 255, 0.03);
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 4px 24px rgba(0,0,0,0.25);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* ── Auth Gate ── */
#authGate {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    z-index: 9000; padding: 20px;
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 36px 40px;
    width: 100%; max-width: 400px;
    text-align: center;
}
.auth-icon { font-size: 3rem; margin-bottom: 16px; }
.auth-title {
    font-size: 1.8rem; font-weight: 700;
    color: var(--primary); margin-bottom: 4px;
}
.auth-subtitle { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 32px; }
.auth-input-group {
    display: flex; gap: 8px;
}
.auth-input-group input {
    flex: 1; padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--glass);
    color: var(--text); font-size: 1rem;
    font-family: inherit; outline: none;
    transition: border-color 0.2s;
}
.auth-input-group input:focus { border-color: var(--primary); }
.auth-input-group button {
    padding: 14px 24px; border-radius: var(--radius-sm);
    border: none; background: var(--primary);
    color: white; font-weight: 600; font-size: 0.95rem;
    cursor: pointer; font-family: inherit;
    transition: background 0.2s;
}
.auth-input-group button:hover { background: var(--primary-dark); }
.auth-error {
    color: var(--red); font-size: 0.85rem;
    margin-top: 12px; min-height: 20px;
}

/* ── Top Bar ── */
.top-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 28px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
}
.top-bar-left { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.logo-sub { font-size: 0.8rem; color: var(--text-dim); }
.top-bar-right { display: flex; align-items: center; gap: 10px; }
.date-picker-wrap { display: flex; align-items: center; gap: 6px; }
.date-picker-wrap input[type=date] {
    padding: 8px 12px; border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--glass); color: var(--text);
    font-family: inherit; font-size: 0.85rem;
    color-scheme: dark; outline: none;
    transition: border-color 0.2s;
}
.date-picker-wrap input[type=date]:focus { border-color: var(--primary); }
.btn-today {
    padding: 8px 14px; border-radius: 8px;
    border: 1px solid var(--primary);
    background: transparent; color: var(--primary);
    font-weight: 600; font-size: 0.8rem;
    cursor: pointer; font-family: inherit;
    transition: all 0.2s;
}
.btn-today:hover { background: var(--primary); color: white; }
.btn-today.active-today { background: var(--primary); color: white; }
.btn-refresh {
    width: 40px; height: 40px;
    border-radius: 10px; border: 1px solid var(--border);
    background: var(--glass); color: var(--text);
    font-size: 1.3rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.btn-refresh:hover { border-color: var(--primary); color: var(--primary); }
.btn-refresh.spinning .refresh-icon {
    animation: spin 0.6s linear infinite;
}
.btn-logout {
    width: 40px; height: 40px;
    border-radius: 10px; border: 1px solid var(--border);
    background: var(--glass); color: var(--text-dim);
    font-size: 1.1rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Date Display ── */
.date-display {
    padding: 12px 28px;
    display: flex; align-items: center; justify-content: space-between;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}
#dateLabel { font-size: 0.9rem; font-weight: 500; color: var(--text-dim); }
.last-refreshed { font-size: 0.78rem; color: var(--text-muted); }

/* ── Navigation Tabs ── */
.nav-tabs {
    display: flex; gap: 4px;
    padding: 12px 28px 0;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}
.nav-tab {
    padding: 10px 20px;
    border: none; background: transparent;
    color: var(--text-dim); font-family: inherit;
    font-size: 0.88rem; font-weight: 500;
    cursor: pointer; border-bottom: 2px solid transparent;
    transition: all 0.2s; display: flex; align-items: center; gap: 6px;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-icon { font-size: 1rem; }

/* ── Tab Content ── */
.tab-content { display: none; padding: 24px 28px 40px; animation: fadeIn 0.2s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ── Loading ── */
.loading-overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(10, 15, 30, 0.5);
    display: flex; align-items: center; justify-content: center;
}
.loader-spinner {
    width: 44px; height: 44px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ══════════════════════ SCORECARDS ══════════════════════ */
.stats-overview {
    display: flex;
    flex-direction: column;
    gap: 28px;
    margin-bottom: 32px;
}
.stats-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.stats-group-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding-left: 4px;
}
.stats-grid {
    display: grid;
    gap: 16px;
}
.stats-grid.grid-3 { grid-template-columns: repeat(3, 1fr); }
.stats-grid.grid-4 { grid-template-columns: repeat(4, 1fr); }
.stats-group-last .stats-grid { grid-template-columns: 1fr; }
.stats-group-last .scorecard { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 24px;
    padding: 16px;
}
.stats-group-last .sc-icon { margin-bottom: 0; font-size: 1.8rem; }
.stats-group-last .sc-label { margin-top: 0; }
.scorecard {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: border-color 0.2s, transform 0.2s;
    cursor: pointer;
}
.scorecard:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.sc-icon { font-size: 1.5rem; margin-bottom: 8px; }
.sc-value {
    font-size: 2rem; font-weight: 700;
    color: var(--primary); line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.sc-label {
    font-size: 0.72rem; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 1px; margin-top: 6px;
}
.sc-green { color: var(--green); }
.sc-amber { color: var(--amber); }
.sc-red { color: var(--red); }

/* ══════════════════════ PANELS ══════════════════════ */
.overview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.panel-title { font-size: 0.95rem; font-weight: 600; }
.panel-badge {
    background: var(--primary);
    color: white; font-size: 0.75rem; font-weight: 700;
    padding: 3px 10px; border-radius: 20px;
}
.panel-body { padding: 12px 20px; max-height: 380px; overflow-y: auto; }

/* Active Driver Item */
.active-driver-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.active-driver-item:last-child { border-bottom: none; }
.ad-pulse {
    width: 10px; height: 10px;
    background: var(--green); border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16,185,129,0.5);
    animation: pulse-ring 1.6s ease infinite;
    flex-shrink: 0;
}
@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
    70% { box-shadow: 0 0 0 7px rgba(16,185,129,0); }
    100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
.ad-info { flex: 1; }
.ad-name { font-weight: 600; font-size: 0.9rem; }
.ad-vehicle { font-size: 0.78rem; color: var(--text-dim); }

/* Top Driver Item */
.top-driver-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.top-driver-item:last-child { border-bottom: none; }
.td-rank {
    width: 32px; height: 32px;
    border-radius: 8px; display: flex;
    align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem;
    background: var(--glass); color: var(--text-dim);
    flex-shrink: 0;
}
.td-rank.rank-1 { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #0f172a; }
.td-rank.rank-2 { background: linear-gradient(135deg, #94a3b8, #64748b); color: #0f172a; }
.td-rank.rank-3 { background: linear-gradient(135deg, #d97706, #b45309); color: white; }
.td-info { flex: 1; }
.td-name { font-weight: 600; font-size: 0.9rem; }
.td-stats { font-size: 0.78rem; color: var(--text-dim); }
.td-badge {
    font-size: 0.82rem; font-weight: 700;
    color: var(--primary); white-space: nowrap;
}

/* ══════════════════════ PROGRESS BAR ══════════════════════ */
.progress-bar-container { padding: 8px 0; }
.progress-bar {
    height: 14px; border-radius: 7px;
    background: var(--glass);
    display: flex; overflow: hidden;
    margin-bottom: 12px;
}
.progress-fill {
    height: 100%;
    transition: width 0.6s ease;
}
.progress-delivered { background: var(--green); }
.progress-returned { background: var(--red); }
.progress-legend { display: flex; gap: 20px; justify-content: center; }
.legend-item {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.78rem; color: var(--text-dim);
}
.legend-dot {
    width: 10px; height: 10px; border-radius: 50%;
}
.dot-delivered { background: var(--green); }
.dot-returned { background: var(--red); }
.dot-dispatched { background: var(--text-muted); }

/* ══════════════════════ TRIPS LIST ══════════════════════ */
.trips-filter-bar {
    display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap;
}
.filter-chip {
    padding: 8px 16px; border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--glass); color: var(--text-dim);
    font-size: 0.82rem; font-weight: 600;
    cursor: pointer; font-family: inherit;
    transition: all 0.2s;
}
.filter-chip:hover { border-color: var(--primary); color: var(--text); }
.filter-chip.active {
    background: var(--primary); border-color: var(--primary); color: white;
}

.trips-list { display: flex; flex-direction: column; gap: 12px; }

.trip-card-full {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.2s;
}
.trip-card-full:hover { border-color: var(--border-hover); }
.trip-card-full.status-active { border-left: 3px solid var(--amber); }
.trip-card-full.status-completed { border-left: 3px solid var(--green); }

.tc-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    cursor: pointer;
}
.tc-header:hover { background: var(--bg-card-hover); }
.tc-left { display: flex; align-items: center; gap: 14px; }
.tc-id { font-weight: 700; font-size: 0.95rem; color: var(--accent); }
.tc-driver { font-size: 0.88rem; color: var(--text); }
.tc-vehicle { font-size: 0.78rem; color: var(--text-dim); }
.tc-right { display: flex; align-items: center; gap: 16px; text-align: right; }
.tc-stats { font-size: 0.82rem; color: var(--text-dim); }
.tc-stats strong { color: var(--text); }
.tc-time { font-size: 0.75rem; color: var(--text-muted); }
.tc-status-badge {
    font-size: 0.7rem; font-weight: 700;
    padding: 4px 10px; border-radius: 20px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.tc-status-badge.badge-active {
    background: var(--amber-bg); color: var(--amber);
    border: 1px solid rgba(245,158,11,0.3);
}
.tc-status-badge.badge-completed {
    background: var(--green-bg); color: var(--green);
    border: 1px solid rgba(16,185,129,0.3);
}
.tc-chevron {
    font-size: 0.8rem; color: var(--text-muted);
    transition: transform 0.2s;
}
.trip-card-full.expanded .tc-chevron { transform: rotate(180deg); }

/* Invoice detail rows inside trip card */
.tc-invoices {
    display: none;
    border-top: 1px solid var(--border);
    padding: 0 20px 16px;
}
.trip-card-full.expanded .tc-invoices { display: block; }

.inv-row {
    display: grid;
    grid-template-columns: 2fr 2fr 0.8fr 1fr;
    gap: 8px; padding: 10px 0;
    align-items: center;
    border-bottom: 1px solid var(--border);
    font-size: 0.84rem;
}
.inv-row:last-child { border-bottom: none; }
.inv-row-header {
    font-size: 0.72rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
    font-weight: 600; padding-top: 14px;
}
.inv-num { font-weight: 600; color: var(--text); }
.inv-party { color: var(--text-dim); }
.inv-qty { color: var(--text-dim); text-align: center; }
.inv-status { text-align: right; }
.inv-badge {
    font-size: 0.68rem; font-weight: 700;
    padding: 3px 8px; border-radius: 12px;
    display: inline-block;
}
.inv-badge.b-dispatched { background: var(--amber-bg); color: var(--amber); }
.inv-badge.b-delivered { background: var(--green-bg); color: var(--green); }
.inv-badge.b-returned { background: var(--red-bg); color: var(--red); }

/* ══════════════════════ DRIVERS TABLE ══════════════════════ */
.search-input {
    width: 100%; padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card); color: var(--text);
    font-family: inherit; font-size: 0.9rem;
    outline: none; margin-bottom: 16px;
    transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--primary); }
.search-input::placeholder { color: var(--text-muted); }

.drivers-table-wrap { overflow-x: auto; }
.drivers-table {
    width: 100%; border-collapse: collapse;
}
.drivers-table th {
    text-align: left; padding: 12px 16px;
    font-size: 0.72rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1px;
    font-weight: 600; border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}
.drivers-table td {
    padding: 14px 16px; font-size: 0.88rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.drivers-table tr:hover td { background: var(--bg-card); }
.dt-mobile { color: var(--text-dim); font-size: 0.82rem; }
.dt-vehicles { display: flex; flex-wrap: wrap; gap: 4px; }
.dt-vehicle-tag {
    background: rgba(59,130,246,0.12);
    color: var(--primary); font-size: 0.75rem;
    font-weight: 600; padding: 3px 8px;
    border-radius: 6px;
}

/* ══════════════════════ HISTORY ══════════════════════ */
.history-filters { margin-bottom: 20px; }
.history-filter-row {
    display: flex; gap: 10px; margin-bottom: 10px;
}
.filter-select {
    padding: 10px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card); color: var(--text);
    font-family: inherit; font-size: 0.85rem;
    outline: none; min-width: 140px;
}
.filter-select option { background: var(--bg-card); }
.date-input {
    flex: 1; padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card); color: var(--text);
    font-family: inherit; font-size: 0.85rem;
    color-scheme: dark; outline: none;
}
.btn-search {
    padding: 10px 22px; border-radius: var(--radius-sm);
    border: none; background: var(--primary); color: white;
    font-weight: 600; font-size: 0.85rem;
    cursor: pointer; font-family: inherit;
    transition: background 0.2s; white-space: nowrap;
}
.btn-search:hover { background: var(--primary-dark); }

/* Pagination */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; padding: 20px 0;
}
.page-btn {
    padding: 8px 14px; border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--glass); color: var(--text-dim);
    font-family: inherit; font-size: 0.82rem;
    cursor: pointer; transition: all 0.2s;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.page-info { font-size: 0.82rem; color: var(--text-dim); }

/* View Toggle Button */
.view-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--primary);
    background: var(--primary-glow);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s;
}
.view-toggle-btn:hover {
    background: var(--primary);
    color: white;
}
.view-toggle-btn .toggle-icon {
    font-size: 0.9rem;
}

/* ══════════════════════ EMPTY STATE ══════════════════════ */
.empty-state {
    text-align: center; padding: 40px 20px;
    color: var(--text-muted); font-size: 0.9rem;
}

/* ══════════════════════ RESPONSIVE ══════════════════════ */
@media (max-width: 1024px) {
    .stats-grid.grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .top-bar { flex-direction: column; gap: 12px; padding: 12px 16px; }
    .top-bar-right { width: 100%; justify-content: space-between; }
    .date-display { padding: 10px 16px; flex-direction: column; gap: 4px; }
    .nav-tabs { padding: 10px 16px 0; overflow-x: auto; }
    .nav-tab { padding: 8px 14px; font-size: 0.82rem; white-space: nowrap; }
    .tab-content { padding: 16px; }
    .stats-grid.grid-3, .stats-grid.grid-4 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .scorecard { padding: 14px; }
    .sc-value { font-size: 1.5rem; }
    .overview-grid { grid-template-columns: 1fr; }
    .inv-row { grid-template-columns: 1fr 1fr; gap: 4px; }
    .inv-row-header { display: none; }
    .tc-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .tc-right { width: 100%; justify-content: space-between; }
    .history-filter-row { flex-direction: column; }
    .stats-group-last .scorecard { flex-direction: column; gap: 8px; }
}
@media (max-width: 480px) {
    .stats-grid.grid-3, .stats-grid.grid-4 { grid-template-columns: 1fr; }
    .logo { font-size: 1.1rem; }
    .logo-sub { display: none; }
    .auth-card { padding: 32px 20px; }
}

/* ══════════════════════ SCROLLBAR ══════════════════════ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
