:root {
    --bg: #0b1220;
    --bg-soft: #111a2b;
    --surface: #ffffff;
    --surface-soft: #f5f8ff;
    --text: #0f172a;
    --text-soft: #4b5563;
    --primary: #2563eb;
    --primary-strong: #1d4ed8;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --success: #047857;
    --success-soft: #d1fae5;
    --warning-soft: #fef3c7;
    --border: #dbe3f0;
    --shadow: 0 14px 40px rgba(11, 18, 32, 0.12);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text);
    background: radial-gradient(circle at top left, #1f3564 0%, #0b1220 55%);
    min-height: 100vh;
    min-height: 100dvh;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

a {
    color: var(--primary);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

.app-shell {
    min-height: 100vh;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 8px;
    background: #fff;
    color: #0f172a;
    border-radius: 8px;
    padding: 8px 12px;
    font-weight: 700;
    z-index: 1000;
}

.skip-link:focus {
    left: 12px;
}

.topbar {
    background: linear-gradient(120deg, rgba(8, 13, 27, 0.96), rgba(15, 23, 42, 0.9));
    color: #f8fafc;
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.35);
    position: relative;
    z-index: 500;
    overflow: visible;
}

.topbar-inner {
    max-width: 1320px;
    margin: 0 auto;
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.topbar-nav {
    --bs-navbar-padding-y: 0;
    width: 100%;
}

.topbar-nav > .topbar-inner {
    width: 100%;
}

.topbar-nav .navbar-collapse {
    flex: 1 1 auto;
    min-width: 0;
}

.topbar-nav .navbar-nav .dropdown-menu {
    z-index: 1060;
}

.brand {
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    color: #f8fafc !important;
    white-space: nowrap;
    line-height: 1.25;
    flex-shrink: 0;
}

.app-navbar-toggler {
    border-color: rgba(148, 163, 184, 0.45);
    padding: 0.4rem 0.55rem;
}

.app-navbar-toggler:focus {
    box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.45);
}

.app-nav-link {
    color: #dbeafe !important;
    font-size: 0.92rem;
    font-weight: 600;
    border-radius: 999px;
    padding: 0.55rem 0.85rem !important;
    border: 1px solid rgba(147, 197, 253, 0.22);
    background: rgba(30, 41, 59, 0.45);
    margin-bottom: 0.35rem;
}

.app-nav-link:hover,
.app-nav-link:focus-visible {
    background: rgba(59, 130, 246, 0.3) !important;
    border-color: rgba(147, 197, 253, 0.55);
    color: #fff !important;
}

.app-nav-link.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.92), rgba(14, 116, 236, 0.86)) !important;
    border-color: rgba(147, 197, 253, 0.75);
    color: #fff !important;
}

.app-nav-dropdown .dropdown-item.active {
    background: rgba(59, 130, 246, 0.35) !important;
    border: none;
    color: #fff !important;
}

.app-nav-dropdown {
    background: #0f172a;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 12px;
    box-shadow: 0 14px 30px rgba(2, 6, 23, 0.45);
    padding: 0.35rem;
}

.app-nav-dropdown .dropdown-item {
    border-radius: 8px;
    font-weight: 600;
    padding: 0.55rem 0.75rem;
}

.app-nav-dropdown .dropdown-item:hover,
.app-nav-dropdown .dropdown-item:focus-visible {
    background: rgba(59, 130, 246, 0.25);
}

.user-menu-trigger {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 768px) {
    .topbar-inner {
        flex-wrap: nowrap;
        justify-content: space-between;
        padding: 10px 16px;
    }

    .topbar-nav .navbar-collapse {
        display: flex !important;
        flex: 1 1 auto;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-end;
        min-width: 0;
    }

    .topbar-nav .navbar-nav {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-end;
        width: auto;
        margin-left: auto !important;
    }

    .topbar-nav .navbar-nav .nav-item {
        flex-shrink: 0;
    }

    .topbar-nav .navbar-nav .dropdown-menu {
        position: absolute;
    }

    .app-nav-link {
        margin-bottom: 0;
        padding: 0.45rem 0.7rem !important;
        font-size: 0.86rem;
        white-space: nowrap;
    }

    .user-menu-trigger {
        max-width: 220px;
    }
}

@media (max-width: 767.98px) {
    .topbar-inner .navbar-collapse {
        flex-basis: 100%;
        width: 100%;
    }

    .topbar-nav .navbar-nav .dropdown-menu {
        border: none;
        box-shadow: none;
        background: transparent;
        padding: 0 0 0 0.75rem;
        margin: 0 0 0.35rem;
    }

    .topbar-nav .navbar-nav .dropdown-menu .dropdown-item {
        border-radius: 999px;
        border: 1px solid rgba(147, 197, 253, 0.15);
        background: rgba(15, 23, 42, 0.55);
        margin-bottom: 0.35rem;
        padding: 0.5rem 0.85rem;
    }
}

main.main-wrap {
    max-width: 1320px;
    margin: 16px auto 32px;
    padding-top: 8px;
}

.flash {
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid transparent;
    font-weight: 600;
}

.flash-success {
    background: var(--success-soft);
    border-color: #6ee7b7;
    color: #065f46;
}

.flash-error {
    background: var(--danger-soft);
    border-color: #fca5a5;
    color: #7f1d1d;
}

.flash-warning {
    background: var(--warning-soft);
    border-color: #fcd34d;
    color: #92400e;
}

.trip-imputed-notice {
    border-color: #fcd34d;
    background: var(--warning-soft);
}

.history-imputed-pill {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--warning-soft);
    border: 1px solid #fcd34d;
    color: #92400e;
    max-width: 100%;
    cursor: help;
}

.history-spare-pill {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e0e7ff;
    border: 1px solid #a5b4fc;
    color: #312e81;
    cursor: help;
}

.page-grid {
    display: grid;
    gap: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.card h2,
.card h3 {
    margin: 0 0 12px;
}

.muted {
    color: var(--text-soft);
    font-size: 0.92rem;
}

.stack-sm {
    display: grid;
    gap: 10px;
}

.stack-md {
    display: grid;
    gap: 16px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
}

input,
select,
textarea,
button {
    font: inherit;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select,
textarea {
    width: 100%;
    background: var(--surface-soft);
    border: 1px solid #cfdaec;
    border-radius: 10px;
    padding: 10px 12px;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
    background: #fff;
}

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    padding: 10px 14px;
}

button:hover,
.btn:hover {
    background: var(--primary-strong);
}

.btn-muted {
    background: #334155;
}

.btn-muted:hover {
    background: #1f2937;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #991b1b;
}

.btn-add-service::before {
    content: "+";
    font-weight: 800;
    line-height: 1;
}

.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.inline-checks {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.inline-checks label {
    margin: 0;
    font-weight: 500;
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
    background: #fff;
}

.fleet-site-table {
    table-layout: auto;
    min-width: 980px;
}

.fleet-site-table .col-name { width: 12%; }
.fleet-site-table .col-plate { width: 12%; }
.fleet-site-table .col-model { width: 12%; }
.fleet-site-table .col-energy { width: 15%; }
.fleet-site-table .col-transmission { width: 12%; }
.fleet-site-table .col-services { width: 30%; }
.fleet-site-table .col-actions { width: 130px; }

.fleet-site-table th,
.fleet-site-table td {
    text-align: center;
    vertical-align: middle;
}

.fleet-site-table td button,
.fleet-site-table td .btn {
    white-space: nowrap;
    min-width: 104px;
}

.fleet-site-table td .muted {
    text-align: center;
}

.fleet-mobile-list,
.mobile-card-list {
    display: none;
    gap: 12px;
}

.fleet-mobile-card,
.mobile-card {
    border: 1px solid #dbe3f0;
    border-radius: 12px;
    background: #f8fbff;
    padding: 12px;
    display: grid;
    gap: 8px;
}

.fleet-mobile-row,
.mobile-card-row {
    display: grid;
    gap: 2px;
}

.fleet-mobile-label,
.mobile-card-label {
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #64748b;
    font-weight: 700;
}

.fleet-mobile-actions .btn,
.fleet-mobile-actions button,
.mobile-card-actions .btn,
.mobile-card-actions button {
    width: 100%;
    min-height: 44px;
}

.table-desktop {
    display: block;
}

th,
td {
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
}

th {
    background: #eef4ff;
    color: #1e293b;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.services-list {
    margin-top: 10px;
    border-top: 1px solid #e2e8f0;
}

.service-item {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.service-item:last-child {
    border-bottom: none;
}

.service-item-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    flex-wrap: wrap;
    width: 100%;
}

.service-create-form {
    margin-bottom: 2px;
    align-items: end;
}

.service-create-form #create-service-button {
    min-width: 170px;
    height: 42px;
}

.services-rename-form {
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0;
}

.services-rename-form input[type="text"] {
    width: 240px;
    height: 40px;
    background: #f8fafc;
}

.service-delete-form {
    margin: 0;
}

.service-item-actions .btn-muted,
.service-item-actions .btn-danger {
    height: 40px;
    padding: 0 12px;
}

.users-admin-table .user-actions-cell {
    width: 420px;
    min-width: 420px;
}

.user-edit-form,
.user-password-form {
    gap: 8px;
}

.user-edit-grid {
    gap: 8px;
}

.user-edit-form input[type="text"],
.user-edit-form input[type="email"],
.user-edit-form select,
.user-password-form input[type="password"] {
    padding: 7px 10px;
    min-height: 34px;
}

.user-inline-checks {
    gap: 8px;
}

.user-inline-checks label {
    font-size: 0.8rem;
}

.user-inline-actions button,
.user-password-form button {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.86rem;
}

.user-password-form {
    margin-top: 6px;
}

.user-actions-drop {
    border: 1px solid #dbe3f0;
    border-radius: 10px;
    background: #f8fbff;
    padding: 6px 8px;
}

.user-actions-drop summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    list-style: none;
}

.user-actions-drop summary::-webkit-details-marker {
    display: none;
}

.user-actions-drop summary::after {
    content: "▾";
    float: right;
    color: #334155;
}

.user-actions-drop[open] summary::after {
    content: "▴";
}

.user-actions-drop-body {
    margin-top: 8px;
}

.status-pill {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.status-ok {
    color: #166534;
    background: #dcfce7;
}

.status-warn {
    color: #92400e;
    background: #fef3c7;
}

.status-danger {
    color: #991b1b;
    background: #fee2e2;
}

.hero {
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: #fff;
}

.hero .muted {
    color: #e2e8f0;
}

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
}

.kpi {
    border: 1px solid #dbeafe;
    background: #eff6ff;
    border-radius: 12px;
    padding: 12px;
}

.kpi .value {
    font-size: 1.25rem;
    font-weight: 800;
    color: #1d4ed8;
}

.login-card {
    max-width: 440px;
    margin: 72px auto 0;
}

.accordion {
    border: 1px solid #d9e3f4;
    border-radius: 12px;
    background: #f8fbff;
    padding: 10px 12px;
}

.accordion + .accordion {
    margin-top: 10px;
}

.accordion summary {
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

.accordion summary::-webkit-details-marker {
    display: none;
}

.accordion summary::after {
    content: "▾";
    float: right;
    color: #334155;
}

.accordion[open] summary::after {
    content: "▴";
}

.accordion-body {
    margin-top: 10px;
}

.vehicle-edit-modal {
    width: min(760px, calc(100% - 32px));
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 12px;
}

.vehicle-edit-modal::backdrop {
    background: rgba(15, 23, 42, 0.45);
}

.vehicle-edit-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.vehicle-edit-modal-head h3 {
    margin: 0;
}

.vehicle-delete-zone {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e2e8f0;
}

.trip-page .hero h2 {
    font-size: clamp(1.25rem, 5vw, 1.6rem);
}

.trip-page .card form label {
    margin-top: 4px;
}

.trip-page #issue-reason-wrap label {
    min-height: 44px;
    display: flex !important;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 6px 0;
}

.trip-page #issue-reason-wrap input[type="checkbox"] {
    width: 1.15rem;
    height: 1.15rem;
    flex-shrink: 0;
}

.mobile-card-select {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.mobile-card-select > input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 4px;
    flex-shrink: 0;
}

.mobile-card-select-body {
    flex: 1;
    min-width: 0;
    display: grid;
    gap: 8px;
}

.mobile-site-heading {
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
    margin: 4px 0 0;
    padding-top: 4px;
}

.admin-mobile-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: stretch;
}

.admin-mobile-actions .btn,
.admin-mobile-actions button {
    flex: 1 1 auto;
    min-width: 0;
}

.users-mobile-list {
    display: none;
    gap: 12px;
}

@media (max-width: 991.98px) {
    .card {
        padding: 16px;
        border-radius: 14px;
    }

    .table-desktop,
    .fleet-table-wrap,
    .users-table-wrap {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        padding: 0 !important;
        margin: -1px !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
        white-space: nowrap !important;
        border: 0 !important;
    }

    .fleet-mobile-list,
    .mobile-card-list,
    .users-mobile-list {
        display: grid;
    }

    .users-admin-table .user-actions-cell {
        width: auto;
        min-width: 0;
    }

    .vehicle-edit-modal {
        width: calc(100vw - 24px);
        max-width: none;
        margin: auto;
    }

    .services-rename-form input[type="text"] {
        width: 100%;
    }

    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px;
        min-height: 44px;
    }

    button,
    .btn {
        min-height: 44px;
    }

    .inline-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-actions .btn,
    .inline-actions button {
        width: 100%;
    }
}

@media (max-width: 575.98px) {
    body {
        font-size: 15px;
    }

    main.main-wrap {
        margin-top: 12px;
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .inline-checks {
        flex-direction: column;
        align-items: stretch;
    }

    .service-item-actions,
    .services-rename-form {
        flex-direction: column;
        align-items: stretch;
    }

    .services-rename-form input[type="text"] {
        width: 100%;
    }

    .login-card {
        margin-top: 24px;
    }
}

@media (min-width: 992px) {
    .table-wrap.table-responsive-mobile {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
