:root {
    --bg-app: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --brand: #1e293b;
    --accent: #ef4444;
    --ready: #10b981;
    --busy: #f59e0b;
    --break: #64748b;
    --w-left: 360px;
    --w-right: 380px;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background: var(--bg-app);
    color: var(--text-main);
    display: grid;
    grid-template-columns: minmax(200px, var(--w-left)) 4px 1fr 4px var(--w-right);
    grid-template-rows: 60px 1fr;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

header {
    grid-column: 1/-1;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 2000;
    box-shadow: var(--glass-shadow);
}

.brand {
    font-size: 1.4rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(to right, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand i {
    -webkit-text-fill-color: #38bdf8;
}

.version-tag {
    font-size: 0.7rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 500;
    margin-left: 10px;
    border: 1px solid var(--border);
    -webkit-text-fill-color: var(--text-muted);
}

.sync-status {
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 15px;
    border: 1px solid var(--border);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    transition: all 0.3s ease;
}

.dot.live {
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
}

.dot.error {
    background: #ef4444;
    box-shadow: 0 0 8px #ef4444;
}

.resizer {
    background: rgba(255, 255, 255, 0.05);
    cursor: col-resize;
    z-index: 1500;
    transition: all 0.2s ease;
}

.resizer:hover,
.resizer.dragging {
    background: rgba(56, 189, 248, 0.5);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.sidebar {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
    z-index: 1000;
    min-width: 200px;
}

#panel-left {
    grid-column: 1;
    border-right: 1px solid var(--border);
}

#panel-right {
    grid-column: 5;
    border-left: 1px solid var(--border);
}

#map-container {
    grid-column: 3;
    position: relative;
    height: 100%;
    width: 100%;
}

#map {
    background: #1e293b;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Dark mode map tiles via CSS filter */
.leaflet-layer,
.leaflet-control-zoom-in,
.leaflet-control-zoom-out,
.leaflet-control-attribution {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}
.leaflet-container {
    background: #0f172a !important;
}

.map-relocating {
    cursor: crosshair !important;
}

#relocate-banner {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    z-index: 2000;
    display: none;
    font-weight: 600;
    box-shadow: var(--glass-shadow);
    white-space: nowrap;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { transform: translate(-50%, -20px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

.section {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 15px;
}

.section::-webkit-scrollbar {
    width: 6px;
}
.section::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}
.section::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.card {
    padding: 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.card:hover {
    transform: translateX(4px);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.card.free { border-left-color: var(--ready); }
.card.busy { border-left-color: var(--busy); }
.card.break {
    border-left-color: var(--break);
    background: rgba(0, 0, 0, 0.2);
    opacity: 0.7;
}

.card.alert {
    border: 1px solid var(--accent);
    border-left: 4px solid var(--accent);
    animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

button {
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s ease;
}

.btn-main, .btn-sec, .btn-warn, .btn-danger {
    border: none;
    padding: 12px;
    width: 100%;
    border-radius: 8px;
    font-weight: 600;
    margin-bottom: 8px;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.btn-main { background: linear-gradient(135deg, #10b981, #059669); }
.btn-main:hover { background: linear-gradient(135deg, #34d399, #10b981); transform: translateY(-1px); box-shadow: 0 6px 12px rgba(16, 185, 129, 0.3); }

.btn-sec { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.btn-sec:hover { background: linear-gradient(135deg, #60a5fa, #3b82f6); transform: translateY(-1px); box-shadow: 0 6px 12px rgba(59, 130, 246, 0.3); }

.btn-warn { background: linear-gradient(135deg, #64748b, #475569); }
.btn-warn:hover { background: linear-gradient(135deg, #94a3b8, #64748b); transform: translateY(-1px); box-shadow: 0 6px 12px rgba(100, 116, 139, 0.3); }

.btn-danger { background: linear-gradient(135deg, #ef4444, #dc2626); }
.btn-danger:hover { background: linear-gradient(135deg, #f87171, #ef4444); transform: translateY(-1px); box-shadow: 0 6px 12px rgba(239, 68, 68, 0.3); }

.btn-cancel-job {
    float: right;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.7rem;
    margin-left: 5px;
    font-weight: 500;
}

.btn-cancel-job:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.5);
}

.btn-head {
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    backdrop-filter: blur(4px);
}

.btn-head:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-head.logout {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}
.btn-head.logout:hover {
    background: rgba(239, 68, 68, 0.4);
}

.input-std {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    color: white;
    border-radius: 6px;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s ease;
}

.input-std:focus {
    outline: none;
    border-color: #38bdf8;
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.input-std option {
    background: #1e293b;
    color: white;
}

.db-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 10px;
}

.db-table th {
    text-align: left;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
}

.db-table td {
    padding: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.tab-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    background: rgba(0,0,0,0.2);
    padding: 4px;
    border-radius: 8px;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-weight: 600;
    border-radius: 6px;
    color: var(--text-muted);
}

.tab-btn.active {
    background: rgba(255,255,255,0.1);
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-edit {
    color: #60a5fa;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(59, 130, 246, 0.1);
    transition: all 0.2s ease;
    margin-right: 5px;
    display: inline-block;
}
.btn-edit:hover {
    background: rgba(59, 130, 246, 0.2);
}

.btn-del {
    color: #f87171;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(239, 68, 68, 0.1);
    transition: all 0.2s ease;
}
.btn-del:hover {
    background: rgba(239, 68, 68, 0.2);
}

.modal-mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.modal {
    background: var(--bg-app);
    padding: 30px;
    border-radius: 16px;
    width: 550px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
    animation: modalPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal h2 {
    margin-top: 0;
    margin-bottom: 20px;
    font-weight: 600;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.lbl {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: block;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

#preview-box {
    display: none;
    background: rgba(56, 189, 248, 0.1);
    padding: 10px;
    margin-bottom: 12px;
    border-left: 4px solid #38bdf8;
    border-radius: 0 6px 6px 0;
    font-size: 0.8rem;
    color: #bae6fd;
}

.mileage-tag {
    float: right;
    background: rgba(255,255,255,0.1);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-main);
    font-weight: 600;
    margin-left: 5px;
    border: 1px solid var(--border);
}

.time-badge {
    font-size: 0.75rem;
    background: rgba(56, 189, 248, 0.2);
    color: #7dd3fc;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 5px;
    vertical-align: middle;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.flow-line {
    stroke-dasharray: 10, 10;
    animation: dash 1s linear infinite;
    opacity: 0.9;
}

.job-route-line {
    stroke-dasharray: 8, 8;
    animation: dash-reverse 1.5s linear infinite;
    opacity: 0.5;
}

@keyframes dash {
    to { stroke-dashoffset: -200; }
}

@keyframes dash-reverse {
    to { stroke-dashoffset: 200; }
}

.rider-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
}

.rider-wrapper:active { cursor: grabbing; }

.rider-dot {
    width: 16px;
    height: 16px;
    background: var(--brand);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

.rider-label {
    position: absolute;
    bottom: 24px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(4px);
    color: white;
    border: 2px solid var(--brand);
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 11px;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
}

.rider-wrapper.busy .rider-dot { background: var(--busy); }
.rider-wrapper.busy .rider-label { border-color: var(--busy); color: #fde68a; }

.rider-wrapper.free .rider-dot { background: var(--ready); }
.rider-wrapper.free .rider-label { border-color: var(--ready); color: #a7f3d0; }

.rider-wrapper.break .rider-dot { background: var(--break); border-color: #cbd5e1; }
.rider-wrapper.break .rider-label { border-color: var(--break); color: #cbd5e1; }

.veh-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.05);
    cursor: pointer;
    font-weight: 600;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-main);
}

.veh-btn.active {
    background: rgba(56, 189, 248, 0.2);
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.5);
}

h3 {
    margin: 0 0 15px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

#mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    z-index: 3000;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.nav-item {
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: all 0.2s ease;
}

.nav-item.active {
    color: #38bdf8;
    background: rgba(255, 255, 255, 0.05);
}

.nav-item i {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 6px;
}

@media (max-width: 800px) {
    body {
        grid-template-columns: 100%;
        grid-template-rows: 60px 1fr 70px;
    }

    .resizer { display: none !important; }

    .sidebar {
        display: none;
        grid-column: 1;
        grid-row: 2;
        width: 100%;
        height: 100%;
        border: none;
        z-index: 1500;
        box-sizing: border-box;
    }

    #map-container {
        display: block;
        grid-column: 1;
        grid-row: 2;
        width: 100%;
        height: 100%;
    }

    #mobile-nav { display: flex; grid-row: 3; }

    .modal {
        width: 90%;
        max-height: 80vh;
        padding: 20px;
    }

    header { padding: 0 15px; }
    .brand { font-size: 1.2rem; }
}

/* LOGIN SCREEN */
#login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-app);
    background-image: radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 1) 0%, rgba(15, 23, 42, 1) 100%);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: white;
}

#login-box {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    width: 320px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: modalPop 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

#login-box h1 {
    margin-top: 0;
    font-size: 2rem;
    margin-bottom: 5px;
    background: linear-gradient(to right, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#login-box h1 i {
    -webkit-text-fill-color: #38bdf8;
    margin-right: 8px;
}

/* CUSTOM TOAST NOTIFICATIONS */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    border-left: 4px solid #3b82f6;
    color: white;
    padding: 12px 20px;
    border-radius: 6px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    font-size: 0.9rem;
    font-weight: 500;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s;
    opacity: 0;
    max-width: 300px;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.success { border-left-color: #10b981; }
.toast.error { border-left-color: #ef4444; }
.toast.warning { border-left-color: #f59e0b; }

/* Light theme overrides */
.light-theme {
    --bg-app: #f1f5f9;
    --bg-panel: rgba(255, 255, 255, 0.8);
    --brand: #f8fafc;
    --text-main: #0f172a;
    --text-muted: #475569;
    --border: rgba(0, 0, 0, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}

.light-theme header {
    background: rgba(255, 255, 255, 0.85);
    color: #0f172a;
}

.light-theme #map {
    background: #e2e8f0;
}

.light-theme .leaflet-layer,
.light-theme .leaflet-control-zoom-in,
.light-theme .leaflet-control-zoom-out,
.light-theme .leaflet-control-attribution {
    filter: none !important;
}

.light-theme .leaflet-container {
    background: #e2e8f0 !important;
}

.light-theme .card {
    background: rgba(0, 0, 0, 0.02);
}

.light-theme .card:hover {
    background: rgba(0, 0, 0, 0.05);
}

.light-theme .card.break {
    background: rgba(0, 0, 0, 0.08);
}

.light-theme #relocate-banner {
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
}

.light-theme .input-std {
    background: rgba(255, 255, 255, 0.9);
    color: #0f172a;
}

.light-theme .input-std option {
    background: #ffffff;
    color: #0f172a;
}

.light-theme .tab-group {
    background: rgba(0, 0, 0, 0.05);
}

.light-theme .tab-btn.active {
    background: rgba(0, 0, 0, 0.1);
    color: #0f172a;
}

.light-theme .modal {
    background: #ffffff;
}

.light-theme #login-screen {
    background: #f1f5f9;
    background-image: radial-gradient(circle at 50% 50%, rgba(241, 245, 249, 1) 0%, rgba(226, 232, 240, 1) 100%);
    color: #0f172a;
}

.light-theme #login-box {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.light-theme #toast-container .toast {
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
}

/* --- Controller Quick Guide --- */
#controller-guide {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    flex: 1;
    overflow-y: auto;
}

#controller-guide h4 {
    margin: 0 0 14px 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#controller-guide h4 i {
    color: #818cf8;
}

.guide-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.guide-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.step-num {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #818cf8, #38bdf8);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}

.step-text {
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-muted);
}

.step-text strong {
    color: var(--text-main);
}

.step-text em {
    color: #38bdf8;
    font-style: normal;
    font-weight: 600;
}

.guide-reminder {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.25);
    margin-top: 8px;
}

.guide-reminder > i {
    color: #f59e0b;
    font-size: 1rem;
    margin-top: 2px;
    flex-shrink: 0;
}

.guide-reminder strong {
    display: block;
    font-size: 0.8rem;
    color: #fbbf24;
    margin-bottom: 4px;
}

.guide-reminder p {
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--text-muted);
}

/* Light theme overrides */
.light-theme .guide-reminder {
    background: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.3);
}

.light-theme .guide-reminder strong {
    color: #b45309;
}

.light-theme .step-text em {
    color: #2563eb;
}

/* Stack database form fields vertically on compact mobile screens */
@media (max-width: 500px) {
    .modal .row {
        grid-template-columns: 1fr; /* Drop to 1 single column */
        gap: 8px;
    }
    
    .modal-mask .modal {
        width: 95%;
        padding: 15px;
    }
    
    .db-table th, .db-table td {
        padding: 6px 8px; /* Slightly reduce cell padding for touch targets */
        font-size: 0.85rem;
    }
}

/* ==============================
   JOB HISTORY VIEWER
   ============================== */

.history-header {
    margin-bottom: 20px;
}

.history-header h2 {
    margin-bottom: 4px;
}

.history-header h2 i {
    color: #818cf8;
    margin-right: 8px;
}

.history-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Time Range Filter Buttons */
.history-time-filters {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px;
    border-radius: 10px;
}

.history-time-btn {
    flex: 1;
    padding: 8px 6px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.history-time-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.history-time-btn.active {
    background: linear-gradient(135deg, rgba(129, 140, 248, 0.3), rgba(56, 189, 248, 0.2));
    color: white;
    box-shadow: 0 2px 8px rgba(129, 140, 248, 0.2);
}

/* Search Row */
.history-search-row {
    margin-bottom: 16px;
}

.history-search-row .input-std {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.85rem;
    padding: 10px 14px;
}

/* Stats Bar */
.history-stats {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.stat-chip i {
    font-size: 0.7rem;
}

.stat-chip:nth-child(1) i { color: #10b981; }
.stat-chip:nth-child(2) i { color: #38bdf8; }
.stat-chip:nth-child(3) i { color: #818cf8; }

/* Results Container */
.history-results {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 4px;
}

.history-results::-webkit-scrollbar {
    width: 5px;
}
.history-results::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}
.history-results::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

/* Date Group Headers */
.history-date-group {
    margin-bottom: 16px;
}

.history-date-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.history-date-label {
    font-weight: 700;
    font-size: 0.82rem;
    color: #818cf8;
    white-space: nowrap;
}

.history-date-count {
    font-size: 0.72rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 10px;
}

.history-date-line {
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Individual Job Cards */
.history-job {
    display: grid;
    grid-template-columns: 100px 1fr auto;
    gap: 12px;
    align-items: start;
    padding: 12px 14px;
    margin-bottom: 6px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    transition: all 0.15s ease;
    animation: histFadeIn 0.3s ease-out;
}

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

.history-job:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(129, 140, 248, 0.2);
}

.history-job-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.history-job-ref {
    font-weight: 700;
    font-size: 0.82rem;
    color: #38bdf8;
}

.history-job-time {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.history-job-body {
    min-width: 0;
}

.history-job-route {
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 4px;
    word-break: break-word;
}

.history-job-route .arrow {
    color: var(--text-muted);
    margin: 0 4px;
}

.history-job-details {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.history-job-detail {
    display: flex;
    align-items: center;
    gap: 4px;
}

.history-job-detail i {
    font-size: 0.65rem;
}

.history-job-miles {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.2);
    color: #7dd3fc;
    white-space: nowrap;
    align-self: center;
}

/* Empty State */
.history-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.history-empty i {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 14px;
    opacity: 0.4;
}

.history-empty p {
    margin: 0;
    font-size: 0.9rem;
}

/* Light theme overrides for history */
.light-theme .history-time-btn.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(59, 130, 246, 0.1));
    color: #4f46e5;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.15);
}

.light-theme .history-date-label {
    color: #6366f1;
}

.light-theme .history-job-ref {
    color: #2563eb;
}

.light-theme .history-job-miles {
    background: rgba(37, 99, 235, 0.08);
    border-color: rgba(37, 99, 235, 0.15);
    color: #2563eb;
}

/* Responsive: compact job cards on mobile */
@media (max-width: 600px) {
    .history-job {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .history-job-meta {
        flex-direction: row;
        gap: 8px;
        align-items: center;
    }
    
    .history-job-miles {
        align-self: flex-start;
    }
    
    .history-time-filters {
        flex-wrap: wrap;
    }
    
    .history-time-btn {
        min-width: 0;
    }
}

/* --- 14-DAY CALENDAR ROTA --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 15px;
}
.calendar-day {
    background: var(--bg-panel, rgba(22, 27, 34, 0.8));
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 120px;
}
.calendar-day.today {
    border-color: #38bdf8;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}
.calendar-day.warning {
    border-color: #ef4444;
}
.calendar-day-header {
    background: rgba(0,0,0,0.3);
    padding: 8px 10px;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border, rgba(255,255,255,0.05));
    color: var(--text-main, #f8fafc);
}
.coverage-badge {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
}
.calendar-day-body {
    padding: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.no-shifts {
    color: var(--text-muted, #64748b);
    font-size: 0.8rem;
    text-align: center;
    margin-top: auto;
    margin-bottom: auto;
}
.shift-entry {
    background: rgba(0,0,0,0.2);
    border-radius: 6px;
    padding: 6px;
    font-size: 0.8rem;
    border-left: 3px solid #38bdf8;
}
.shift-time {
    color: var(--text-muted, #94a3b8);
    font-size: 0.75rem;
    margin-bottom: 3px;
}
.shift-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.shift-person {
    color: var(--text-main, #e2e8f0);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
}
.btn-del-shift {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    opacity: 0.7;
}
.btn-del-shift:hover {
    opacity: 1;
}

/* --- ITEM SELECTOR --- */
.item-selector-btn {
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: rgba(22, 27, 34, 0.8);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
    box-sizing: border-box;
}
.item-selector-btn:hover {
    border-color: #38bdf8;
    background: rgba(255,255,255,0.05);
}

.item-category {
    margin-bottom: 8px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    overflow: hidden;
}
.item-category-header {
    background: rgba(0,0,0,0.3);
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #e2e8f0;
}
.item-category-header:hover {
    background: rgba(0,0,0,0.5);
}
.item-category-body {
    background: transparent;
}
.item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    border-top: 1px solid rgba(255,255,255,0.05);
    font-size: 0.9rem;
    color: #cbd5e1;
}
.item-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}
.btn-qty {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    width: 28px;
    height: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-weight: bold;
    color: #e2e8f0;
}
.btn-qty:hover {
    background: #38bdf8;
    color: #1e293b;
    border-color: #38bdf8;
}
.item-qty {
    min-width: 20px;
    text-align: center;
    font-weight: 600;
}

