.theme-toggle,
.dashboard-theme-toggle {
    display: inline-grid;
    place-items: center;
    flex: 0 0 40px;
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.theme-toggle:hover,
.dashboard-theme-toggle:hover {
    background: var(--panel-soft);
}

.theme-toggle:focus-visible,
.dashboard-theme-toggle:focus-visible {
    outline: 3px solid rgba(31, 111, 235, 0.3);
    outline-offset: 2px;
}

.theme-icon {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.theme-icon-sun { display: none; }
html[data-theme="dark"] .theme-icon-moon { display: none; }
html[data-theme="dark"] .theme-icon-sun { display: block; }

.login-theme-toggle {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 20;
}

.fleet-loader-host {
    position: relative;
}

.fleet-loader-overlay {
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 12px;
    visibility: hidden;
    opacity: 0;
    background: rgba(243, 246, 251, 0.88);
    backdrop-filter: blur(3px);
    transition: opacity 160ms ease, visibility 160ms ease;
    pointer-events: none;
}

.fleet-loader-overlay.is-page {
    position: fixed;
    inset: 0;
    z-index: 10000;
}

.fleet-loader-overlay.is-contained {
    position: absolute;
    inset: 0;
    z-index: 80;
    min-height: 120px;
    border-radius: inherit;
}

.fleet-loader-overlay.is-visible {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.fleet-radial-loader {
    position: relative;
    width: 58px;
    height: 58px;
}

.fleet-radial-loader i {
    --loader-colour: var(--blue);
    position: absolute;
    top: 3px;
    left: 50%;
    width: 6px;
    height: 17px;
    margin-left: -3px;
    border-radius: 4px;
    background: var(--loader-colour);
    box-shadow: 0 0 8px color-mix(in srgb, var(--loader-colour) 30%, transparent);
    opacity: 0.14;
    transform: rotate(calc(var(--loader-step) * 30deg));
    transform-origin: 3px 26px;
    animation: fleet-radial-fade 960ms linear infinite;
    animation-delay: calc(var(--loader-step) * -80ms);
}

.fleet-radial-loader i:nth-child(4n + 2) { --loader-colour: var(--cyan); }
.fleet-radial-loader i:nth-child(4n + 3) { --loader-colour: var(--green); }
.fleet-radial-loader i:nth-child(4n + 4) { --loader-colour: #2563eb; }

.fleet-loader-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
}

html[data-theme="dark"] .fleet-loader-overlay {
    background: rgba(8, 15, 29, 0.88);
}

@keyframes fleet-radial-fade {
    0%, 100% { opacity: 0.14; }
    18% { opacity: 1; }
    42% { opacity: 0.38; }
}

@media (prefers-reduced-motion: reduce) {
    .fleet-radial-loader i {
        animation-duration: 1800ms;
    }
}

.modal-card > .modal-heading,
.modal-card > .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}

.modal-card > .modal-heading > h2,
.modal-card > .modal-header h2 {
    min-width: 0;
    margin: 0;
}

.modal-card > .modal-heading > .icon-button,
.modal-card > .modal-header > .icon-button {
    flex: 0 0 36px;
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    border: 1px solid #b91c1c;
    border-radius: 6px;
    background: #dc2626;
    color: #ffffff;
    font-size: 0;
    line-height: 1;
}

.modal-card > .modal-heading > .icon-button::before,
.modal-card > .modal-header > .icon-button::before {
    content: "\00d7";
    font-size: 24px;
    font-weight: 800;
    line-height: 1;
}

.modal-card > .modal-heading > .icon-button:hover,
.modal-card > .modal-header > .icon-button:hover {
    border-color: #991b1b;
    background: #b91c1c;
}

.modal-card > .modal-heading > .icon-button:focus-visible,
.modal-card > .modal-header > .icon-button:focus-visible {
    outline: 3px solid rgba(248, 113, 113, 0.4);
    outline-offset: 2px;
}

.modal-card > .modal-actions,
.modal-card > .form-actions,
.modal-card .form-grid > .form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    column-gap: 12px;
    row-gap: 10px;
    margin-top: 18px;
}

.modal-card .form-grid > .form-actions {
    margin-top: 4px;
}

.modal-card > .modal-actions > button,
.modal-card > .form-actions > button,
.modal-card .form-grid > .form-actions > button {
    flex: 0 0 auto;
    margin: 0;
}

.modal-card .form-actions > .settings-form-status {
    flex: 1 1 180px;
    margin-right: auto;
}

html[data-theme="light"] .sidebar {
    border-color: #d4e0ee;
    background: #ffffff;
    color: #142033;
    box-shadow: 10px 0 30px rgba(37, 60, 89, 0.1);
}

html[data-theme="light"] .sidebar .brand-logo:not(.is-fallback) {
    border-color: #d4e0ee;
    background: #ffffff !important;
    box-shadow: none;
}

html[data-theme="light"] .sidebar .brand.platform-brand .brand-logo:not(.is-fallback) {
    border-color: #b8cce0;
    background: #18324a !important;
    box-shadow: 0 6px 18px rgba(24, 50, 74, 0.14);
}

.sidebar .brand.platform-brand {
    display: block;
    min-height: 0;
}

.sidebar .brand.platform-brand .brand-logo {
    width: 100%;
    height: 72px;
    padding: 10px 14px;
    box-sizing: border-box;
}

html[data-theme="light"] .sidebar .brand strong {
    color: #142033;
}

html[data-theme="light"] .sidebar .brand small,
html[data-theme="light"] .sidebar-fleet-toggle small,
html[data-theme="light"] .sidebar-vehicle-item small {
    color: #64748b;
}

html[data-theme="light"] .sidebar nav a {
    color: #42526b;
}

html[data-theme="light"] .sidebar nav a:hover,
html[data-theme="light"] .sidebar nav a.active {
    background: #eaf2fb;
    color: #142033;
}

html[data-theme="light"] .sidebar-fleet-toggle {
    border-color: #c7d8ea;
    background: #f8fbff;
    color: #142033;
}

html[data-theme="light"] .sidebar-fleet-toggle:hover,
html[data-theme="light"] .sidebar-fleet-toggle[aria-expanded="true"] {
    background: #eaf2fb;
}

html[data-theme="light"] .sidebar-fleet-toggle strong {
    color: #142033;
}

html[data-theme="light"] .sidebar-fleet-toggle i {
    border-color: #64748b;
}

html[data-theme="light"] .sidebar-fleet-toggle[aria-expanded="true"] i {
    border-color: #142033;
}

html[data-theme="light"] .sidebar-vehicle-item {
    border-color: #d4e0ee;
    background: #f8fbff;
    color: #334155;
}

html[data-theme="light"] .sidebar-vehicle-item:hover {
    background: #eaf2fb;
}

html[data-theme="light"] .sidebar-vehicle-item strong {
    color: #142033;
}

html[data-theme="light"] body[data-page="dashboard"] .map-filter-tabs {
    border: 1px solid #d4e0ee;
    background: rgba(238, 244, 250, 0.96);
    box-shadow: 0 12px 28px rgba(37, 60, 89, 0.14);
}

html[data-theme="light"] body[data-page="dashboard"] .map-filter-tab {
    border: 1px solid #d4e0ee;
    background: #ffffff;
    color: #334155;
}

html[data-theme="light"] body[data-page="dashboard"] .map-filter-tab select {
    background-color: #f5f8fc;
    color: #142033;
}

html[data-theme="light"] body[data-page="dashboard"] .map-filter-reset {
    border-color: transparent;
    background: #e2e8f0;
    color: #42526b;
}

html[data-theme="light"] body[data-page="dashboard"] .map-filter-reset:hover,
html[data-theme="light"] body[data-page="dashboard"] .map-filter-reset.is-active {
    border-color: #86efac;
    background: #13a56b;
    color: #ffffff;
}

html[data-theme="dark"] body {
    --bg: #0b1220;
    --panel: #111827;
    --panel-soft: #172033;
    --text: #e5edf7;
    --muted: #9fb0c6;
    --line: #2b3a51;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
    --shadow-hover: 0 18px 46px rgba(0, 0, 0, 0.36);
    background: var(--bg);
    color: var(--text);
    color-scheme: dark;
}

html[data-theme="dark"] body,
html[data-theme="dark"] .app-shell,
html[data-theme="dark"] .login-shell {
    background-color: var(--bg);
}

html[data-theme="dark"] .sidebar .brand-logo:not(.is-fallback) {
    border-color: #3a4a63;
    background: #0f172a !important;
}

html[data-theme="dark"] .topbar,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .feature-card,
html[data-theme="dark"] .status-panel,
html[data-theme="dark"] .map-panel,
html[data-theme="dark"] .modal-card,
html[data-theme="dark"] .login-panel,
html[data-theme="dark"] .settings-section,
html[data-theme="dark"] .settings-profile-layout,
html[data-theme="dark"] .trip-playback-panel,
html[data-theme="dark"] .table-pagination-actions {
    border-color: var(--line);
    background-color: var(--panel);
    color: var(--text);
}

html[data-theme="dark"] .topbar {
    background: rgba(17, 24, 39, 0.96);
}

html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] strong,
html[data-theme="dark"] label,
html[data-theme="dark"] legend,
html[data-theme="dark"] dt,
html[data-theme="dark"] td,
html[data-theme="dark"] summary {
    color: var(--text);
}

html[data-theme="dark"] p,
html[data-theme="dark"] small,
html[data-theme="dark"] dd,
html[data-theme="dark"] .form-note,
html[data-theme="dark"] .panel-heading p,
html[data-theme="dark"] .table-pagination span {
    color: var(--muted);
}

html[data-theme="dark"] th,
html[data-theme="dark"] td,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .definition-grid,
html[data-theme="dark"] .panel-heading,
html[data-theme="dark"] .modal-heading,
html[data-theme="dark"] .modal-actions,
html[data-theme="dark"] .form-actions {
    border-color: var(--line);
}

html[data-theme="dark"] tbody tr:hover {
    background: #172033;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .search-input,
html[data-theme="dark"] .select-input,
html[data-theme="dark"] .date-filter-shell,
html[data-theme="dark"] .date-filter-shell .search-input {
    border-color: #3a4a63;
    background-color: #0f172a;
    color: var(--text);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
    color: #7f91aa;
}

html[data-theme="dark"] select option {
    background: #111827;
    color: var(--text);
}

html[data-theme="dark"] .secondary-button,
html[data-theme="dark"] .icon-text-button,
html[data-theme="dark"] .user-chip,
html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .dashboard-theme-toggle,
html[data-theme="dark"] .table-pagination-button:not(.is-current) {
    border-color: var(--line);
    background-color: #172033;
    color: var(--text);
}

html[data-theme="dark"] .secondary-button:hover,
html[data-theme="dark"] .icon-text-button:hover,
html[data-theme="dark"] .theme-toggle:hover,
html[data-theme="dark"] .dashboard-theme-toggle:hover,
html[data-theme="dark"] .table-pagination-button:hover:not(:disabled):not(.is-current) {
    background-color: #223049;
}

html[data-theme="dark"] .user-avatar {
    background: #123d34;
    color: #7ce2bd;
}

html[data-theme="dark"] .stack-item,
html[data-theme="dark"] .alert-item,
html[data-theme="dark"] .vehicle-card,
html[data-theme="dark"] .can-parameter,
html[data-theme="dark"] .can-summary div,
html[data-theme="dark"] .settings-user-row,
html[data-theme="dark"] .settings-list-row,
html[data-theme="dark"] .history-filter-panel,
html[data-theme="dark"] .empty-state {
    border-color: var(--line);
    background-color: var(--panel-soft);
    color: var(--text);
}

html[data-theme="dark"] .report-total-row td {
    background: #172033;
    color: var(--text);
}

html[data-theme="dark"] .modal-backdrop {
    background: rgba(2, 6, 23, 0.76);
}

html[data-theme="dark"] #trip-detail-modal .trip-telemetry-grid div {
    border-color: #3a4a63;
    background: #0f172a;
    color: var(--text);
}

html[data-theme="dark"] #trip-detail-modal .trip-telemetry-grid dt {
    color: #9fb0c6;
}

html[data-theme="dark"] #trip-detail-modal .trip-telemetry-grid dd {
    color: #f8fafc;
}

html[data-theme="dark"] #trip-detail-modal .map-unavailable {
    background: #0f172a;
    color: var(--text);
}

html[data-theme="dark"] .file-button,
html[data-theme="dark"] code {
    border-color: var(--line);
    background-color: #172033;
    color: var(--text);
}

html[data-theme="dark"] .settings-logo-preview {
    border-color: #50627a;
    background: #0f172a;
    color: #b8c7da;
}

html[data-theme="dark"] .settings-plan-details div {
    border-color: #3a4a63;
    background: #172033;
}

html[data-theme="dark"] .settings-plan-details dt {
    color: #aebdd0;
}

html[data-theme="dark"] .settings-plan-details dd {
    color: #f8fafc;
}

html[data-theme="dark"] .settings-feature-list span {
    border-color: #2f806a;
    background: #103b32;
    color: #a7f3d0;
}

html[data-theme="dark"] .settings-request-item {
    border-color: #3a4a63;
}

html[data-theme="dark"] .settings-request-item strong {
    color: #f8fafc;
}

html[data-theme="dark"] .settings-request-item small,
html[data-theme="dark"] .settings-brand-panel > small,
html[data-theme="dark"] .settings-form-status {
    color: #aebdd0;
}

html[data-theme="dark"] .danger-button {
    color: #fca5a5;
}

@media (max-width: 560px) {
    .modal-card .form-actions > .settings-form-status {
        flex-basis: 100%;
        margin-right: 0;
    }
}

@media (max-width: 720px) {
    .theme-toggle,
    .dashboard-theme-toggle {
        flex-basis: 38px;
        width: 38px;
        min-width: 38px;
        height: 38px;
        min-height: 38px;
    }

    .login-theme-toggle {
        top: 12px;
        right: 12px;
    }
}

@media print {
    .theme-toggle,
    .dashboard-theme-toggle {
        display: none !important;
    }
}
