:root {
    --brand: #0f2744;
    --brand-2: #1c3d66;
    --gold: #e4b15a;
    --ink: #172033;
    --muted: #5c6b7a;
    --paper: #eef2f6;
    --line: #e3e8ef;
    --sidebar: 216px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--brand-2); }

.app-shell { min-height: 100vh; }

.app-sidebar {
    background: linear-gradient(180deg, #102846 0%, #0b1c33 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 1.1rem .9rem 1rem;
    width: var(--sidebar);
}

.side-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: #fff;
    text-decoration: none;
    padding: .2rem .45rem .9rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    margin-bottom: .85rem;
}

.side-brand:hover { color: #fff; }

.side-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--gold);
    color: #1b1406;
    font-weight: 800;
    letter-spacing: .02em;
    flex: 0 0 auto;
}

.brand-mark {
    display: block;
    font-weight: 700;
    letter-spacing: .06em;
    font-size: .92rem;
    line-height: 1.1;
}

.brand-sub {
    display: block;
    font-size: .75rem;
    opacity: .75;
    font-weight: 400;
}

.side-nav { display: flex; flex-direction: column; gap: .25rem; }

.side-label {
    margin: .85rem .75rem .1rem;
    font-size: .72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .5);
    font-weight: 700;
}

.datatable-card { overflow: hidden; }

.datatable-toolbar,
.datatable-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    padding: .9rem 1rem;
    background: #fff;
}

.datatable-toolbar { border-bottom: 1px solid #e8edf3; }
.datatable-footer { border-top: 1px solid #e8edf3; }

.datatable-filters {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}

.datatable-length,
.datatable-search {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin: 0;
    color: var(--muted);
    font-size: .9rem;
    font-weight: 600;
}

.datatable-length select { width: auto; min-width: 7.5rem; min-height: 40px; }

.datatable-search {
    margin-left: auto;
    flex: 1 1 260px;
    justify-content: flex-end;
    max-width: 460px;
}

.datatable-search input {
    flex: 1 1 160px;
    min-width: 0;
    width: auto;
    min-height: 40px;
}

.datatable-search .btn { min-height: 40px; white-space: nowrap; }

.datatable { border-collapse: separate; border-spacing: 0; }

.datatable thead th {
    background: #f4f7fb;
    border-bottom: 1px solid #e3e8ef;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.datatable td { padding-top: .7rem; padding-bottom: .7rem; vertical-align: middle; }

.datatable tbody tr:nth-child(even) { background: #f8fafc; }

.datatable tbody tr:hover { background: #eef4fb; }

.datatable .col-status,
.datatable .col-actions { white-space: nowrap; width: 1%; }

.datatable .table-actions { flex-wrap: nowrap; }

.datatable .table-actions .btn {
    min-height: 34px;
    padding: .25rem .7rem;
}

.sort-link {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    color: inherit;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-size: .72rem;
    font-weight: 700;
}

.sort-link.is-active { color: var(--brand); }

.sort-mark { font-size: .8rem; opacity: .7; }

.vehicle-picker { position: relative; }

.vehicle-picker-native {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.vehicle-picker-menu {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    max-height: 280px;
    overflow: auto;
    background: #fff;
    border: 1px solid #d5dde6;
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(15, 39, 68, .12);
}

.vehicle-picker-option,
.vehicle-picker-empty {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: #fff;
    padding: .7rem .9rem;
    min-height: 44px;
}

.vehicle-picker-option:hover,
.vehicle-picker-option.is-active {
    background: #e7eef7;
}

.vehicle-picker-empty { color: var(--muted); }

.vehicle-summary {
    background: #f8fafc;
    border: 1px solid #e3e8ef;
    border-radius: 12px;
    padding: .75rem .9rem;
}

.vehicle-summary div { margin-bottom: .15rem; }

.side-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    min-height: 44px;
    padding: .55rem .75rem;
    border-radius: 12px;
    color: rgba(255, 255, 255, .86);
    text-decoration: none;
    font-weight: 600;
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
}

.side-link svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.side-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.side-link.is-active {
    background: rgba(228, 177, 90, .16);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--gold);
}

.side-link-cta {
    margin-top: .35rem;
    background: var(--gold);
    color: #1b1406;
}

.side-link-cta:hover { background: #efc57a; color: #1b1406; }

.side-link-cta.is-active { box-shadow: none; background: #efc57a; color: #1b1406; }

.side-note {
    color: rgba(255, 255, 255, .8);
    font-size: .9rem;
    margin: .5rem .4rem 1rem;
}

.side-user {
    margin-top: auto;
    padding-top: .8rem;
    border-top: 1px solid rgba(255, 255, 255, .08);
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.side-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    display: grid;
    place-items: center;
    font-weight: 700;
    margin: .35rem .45rem .15rem;
}

.side-user-meta {
    padding: 0 .45rem .4rem;
    line-height: 1.2;
}

.side-user-meta strong { display: block; font-size: .92rem; }
.side-user-meta span { font-size: .75rem; opacity: .7; }

.side-logout { color: rgba(255, 255, 255, .78); cursor: pointer; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 18, 32, .45);
    z-index: 1030;
}

.app-topbar {
    display: none;
    align-items: center;
    gap: .75rem;
    height: 58px;
    padding: 0 .85rem;
    background: #0f2744;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.menu-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    min-height: 40px;
    padding: .3rem .7rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .2);
    background: transparent;
    color: #fff;
    font-weight: 600;
}

.menu-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.topbar-title {
    font-weight: 700;
    letter-spacing: .06em;
    font-size: .85rem;
}

.app-content { min-width: 0; }

.app-main {
    padding: 1.15rem 1rem 2rem;
}

.site-footer {
    color: var(--muted);
    font-size: .78rem;
    padding: 0 1rem 1.25rem;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.page-head h1,
.app-main > h1 {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -.02em;
    margin: 0;
}

.dash-block { margin-bottom: 1.15rem; }

.dash-block h2 {
    margin: 0 0 .6rem;
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: .85rem;
}

.stat-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-kicker {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    padding: .8rem 1rem;
    background: #f4f7fb;
    color: var(--ink);
    font-weight: 700;
    border-bottom: 1px solid #e8edf3;
}

.panel-head a {
    font-size: .85rem;
    font-weight: 600;
    text-decoration: none;
}

.entity-empty { color: #9aa6b2; }

.stat-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 108px;
    padding: 1rem 1rem .9rem;
    border-radius: 16px;
    background: #fff;
    text-decoration: none;
    color: inherit;
    border: 1px solid #fff;
    box-shadow: 0 8px 24px rgba(15, 39, 68, .05);
    border-top: 4px solid var(--brand);
}

.stat-card:hover {
    transform: translateY(-2px);
    color: inherit;
    box-shadow: 0 12px 28px rgba(15, 39, 68, .1);
}

.stat-fleet { border-top-color: #1d4ed8; }
.stat-issued { border-top-color: #d97706; }
.stat-available { border-top-color: #0f766e; }
.stat-returned { border-top-color: #15803d; }
.stat-damage { border-top-color: #b91c1c; }
.stat-fail { border-top-color: #c2410c; }

.stat-value {
    font-size: 1.85rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -.03em;
}

.stat-label {
    color: var(--muted);
    font-size: .9rem;
    margin-top: .55rem;
}

.section-card {
    border: 0;
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 39, 68, .05);
}

.section-head {
    background: #3f3f3f;
    color: #fff;
    font-weight: 700;
    padding: .7rem 1rem;
}

.card-body { padding: 1rem 1.05rem; }

.table { margin-bottom: 0; }

.table thead th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    background: #f8fafc;
    font-weight: 700;
    white-space: nowrap;
}

.table tbody tr:hover { background: #f5f8fc; }

.table td { vertical-align: middle; }

.btn {
    border-radius: 10px;
    font-weight: 600;
}

.btn-primary {
    --bs-btn-bg: #0f2744;
    --bs-btn-border-color: #0f2744;
    --bs-btn-hover-bg: #1a3d66;
    --bs-btn-hover-border-color: #1a3d66;
    --bs-btn-active-bg: #0a1b30;
    --bs-btn-active-border-color: #0a1b30;
    --bs-btn-disabled-bg: #0f2744;
    --bs-btn-disabled-border-color: #0f2744;
}

.btn-lg { min-height: 48px; }

.form-label { font-weight: 600; font-size: .9rem; }

.form-control,
.form-select {
    border-radius: 10px;
    min-height: 44px;
    border-color: #d5dde6;
}

.form-control:focus,
.form-select:focus {
    border-color: #8aa4c4;
    box-shadow: 0 0 0 .2rem rgba(15, 39, 68, .12);
}

.choice {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    min-height: 44px;
    padding: .35rem .75rem;
    border: 1px solid #cfd6df;
    border-radius: 999px;
    background: #fff;
    margin: 0 .35rem .35rem 0;
    cursor: pointer;
}

.choice:has(input:checked) {
    border-color: var(--brand);
    background: #e7eef7;
    font-weight: 700;
}

.choice-fail:has(input:checked) {
    border-color: #9b2c2c;
    background: #fde8e8;
}

.choice input { width: 1.05rem; height: 1.05rem; }

.dmg-key {
    min-width: 44px;
    min-height: 44px;
    font-weight: 700;
    color: #fff;
    border: 2px solid transparent;
    border-radius: 12px;
}

.dmg-key.active {
    outline: 3px solid var(--brand);
    outline-offset: 1px;
}

.car-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 320 / 150;
    background: #fff;
    border: 1px solid #cfd6df;
    border-radius: 12px;
    overflow: hidden;
    touch-action: manipulation;
}

.car-stage svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.marker-layer { position: absolute; inset: 0; cursor: crosshair; }

.dmg-marker {
    position: absolute;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #111;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    padding: 0;
}

.photo-thumb {
    width: 100%;
    max-height: 140px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid #d5dbe3;
    background: #fff;
}

.media-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.media-actions .btn { min-height: 44px; }

.media-file {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.video-preview {
    display: block;
    width: 100%;
    max-height: 280px;
    background: #0f172a;
    border-radius: 12px;
}

.camera-dialog {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, .55);
}

.camera-dialog[hidden] { display: none; }

.camera-panel {
    width: min(720px, 100%);
    background: #fff;
    border-radius: 16px;
    padding: 1rem;
}

#camera-preview {
    width: 100%;
    max-height: 55vh;
    background: #0f172a;
    border-radius: 12px;
    margin-bottom: .75rem;
}

.sig-canvas {
    width: 100%;
    height: 140px;
    border: 1px dashed #6b7280;
    border-radius: 12px;
    background: #fff;
    touch-action: none;
    display: block;
}

.sig-existing img {
    max-width: 100%;
    height: 80px;
    object-fit: contain;
    background: #fff;
    border: 1px solid #d5dbe3;
    border-radius: 10px;
}

.save-bar {
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: rgba(255, 255, 255, .96);
    border-top: 1px solid #d5dbe3;
    padding: .75rem 0;
    margin-top: 1rem;
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.table-actions { display: flex; flex-wrap: wrap; gap: .4rem; }

.table-actions .btn {
    min-height: 44px;
    padding: .4rem .85rem;
}

.handover-cards {
    display: grid;
    gap: .75rem;
}

.handover-card {
    background: #fff;
    border-radius: 16px;
    padding: 1rem;
    box-shadow: 0 8px 24px rgba(15, 39, 68, .05);
}

.handover-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    margin-bottom: .35rem;
}

.handover-card-top strong { font-size: 1.15rem; }

.handover-card p { margin: 0 0 .2rem; }

.page-link {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn,
.side-link,
.choice,
.stat-card,
.dmg-key {
    touch-action: manipulation;
}

.autosave-status {
    position: sticky;
    top: .5rem;
    z-index: 15;
    margin: 0 0 .8rem;
    padding: .55rem .8rem;
    border-radius: 12px;
    background: #e8f6ee;
    color: #14532d;
    font-weight: 600;
}

.autosave-status.is-saving { background: #e7eef7; color: #0f2744; }
.autosave-status.is-local { background: #fff7e6; color: #7c4a03; }
.autosave-status.is-saved { background: #e8f6ee; color: #14532d; }

.alert { border: 0; border-radius: 12px; }

.pagination { margin-bottom: 0; }

.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    background: #0f2744;
}

.login-panel {
    color: #fff;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background:
        radial-gradient(circle at 20% 20%, rgba(228, 177, 90, .25), transparent 40%),
        linear-gradient(160deg, #16375f, #0b1c33);
}

.login-panel h1 { font-weight: 700; letter-spacing: -.02em; }
.login-card { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; background: var(--paper); }
.login-card .card { width: min(440px, 100%); border: 0; border-radius: 18px; box-shadow: 0 16px 40px rgba(15, 39, 68, .08); }

@media (min-width: 768px) {
    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        height: 100vh;
        height: 100dvh;
        z-index: 100;
        overflow: auto;
    }

    .app-content { margin-left: var(--sidebar); }

    .app-main { padding: 1.15rem 1.15rem 5.5rem; }
    .site-footer { padding-left: 1.15rem; }
}

@media (min-width: 1200px) {
    :root { --sidebar: 248px; }
    .app-main { padding: 1.6rem 1.75rem 2.5rem; }
    .site-footer { padding-left: 1.75rem; }
}

@media (max-width: 767.98px) {
    .autosave-status { top: 64px; }
    .app-topbar { display: flex; }

    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        height: 100vh;
        height: 100dvh;
        z-index: 1040;
        transform: translateX(-105%);
        transition: transform .2s ease;
        overflow: auto;
    }

    .app-sidebar.is-open { transform: none; }
    .sidebar-backdrop.is-open { display: block; }
    body.sidebar-lock { overflow: hidden; }
}

@media (max-width: 1199.98px) {
    .save-bar .btn { flex: 1 1 180px; }
    .dmg-marker { width: 36px; height: 36px; font-size: 15px; }
    .sig-canvas { height: 160px; }
}

@media (max-width: 860px) {
    .login-shell { grid-template-columns: 1fr; }
    .login-panel { min-height: 180px; padding: 1.5rem; justify-content: center; }
}

@media (max-width: 1100px) {
    .stat-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .stat-grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 575.98px) {
    .stat-value { font-size: 1.5rem; }
    .page-head .btn { width: 100%; }
}

@media print {
    .no-print,
    .app-sidebar,
    .app-topbar,
    .sidebar-backdrop,
    .site-footer,
    .alert,
    .save-bar { display: none !important; }

    body { background: #fff !important; }
    .app-content { margin: 0 !important; }
    .app-main { padding: 0 !important; }
}
