/*
 * Application light-theme contract.
 * Loaded after module-local styles so legacy dark-only pages cannot leak their
 * palette into the current light application shell.
 */

body.app-shell:not(.dark-mode) .page-content {
    --bg-dark-900: #f8fafc;
    --bg-dark-800: #ffffff;
    --bg-dark-700: #e2e8f0;
    --bg-dark: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #dbeafe;
    --bg-input: #ffffff;
    color: #0f172a;
}

/* Management pages that previously declared dark variables at :root. */
body.app-shell:not(.dark-mode):is(
    .page-users,
    .page-device,
    .page-driver,
    .page-device_model,
    .page-users_edit,
    .page-device_edit
) .main-page,
body.app-shell:not(.dark-mode) .user-edit-page,
body.app-shell:not(.dark-mode) .device-edit-page {
    background: #f8fafc !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .stat-card,
    .table-section,
    .main-content-container
) {
    background: #ffffff !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.07) !important;
}

body.app-shell:not(.dark-mode).page-device .page-content > div[style*="background-color: #0f172a"] {
    background: #f8fafc !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-device .page-content > div > div:first-child h2 {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .table-header,
    .controls-header,
    .pagination-wrapper,
    .pagination-footer
) {
    background: #f8fafc !important;
    border-color: #dbeafe !important;
    color: #475569 !important;
}

body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .search-input,
    .dark-search-input,
    .dark-select,
    .btn-pg,
    .page-btn
) {
    background: #ffffff !important;
    border-color: #bfdbfe !important;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
}

body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .dashboard-title h1,
    .stat-value,
    .custom-table td,
    .dark-tbody td
) {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .custom-table th,
    .dark-th
) {
    background: #e0f2fe !important;
    border-color: #bae6fd !important;
    color: #075985 !important;
}

body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .custom-table td,
    .dark-tbody td
) [style*="color:#fff"],
body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .custom-table td,
    .dark-tbody td
) [style*="color:#f8fafc"],
body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .custom-table td,
    .dark-tbody td
) [style*="color:#e2e8f0"],
body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    .custom-table td,
    .dark-tbody td
) [style*="color:#cbd5e1"] {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) :is(
    #userCount,
    #vehicleCount
) {
    color: #0f172a !important;
}

/* Edit forms and their Select2 surfaces. */
body.app-shell:not(.dark-mode):is(.page-users_edit, .page-device_edit) :is(
    .user-edit-card,
    .edit-form,
    .sensor-panel,
    .flags label,
    .saved-password-panel
) {
    background: #ffffff !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06) !important;
}

body.app-shell:not(.dark-mode):is(.page-users_edit, .page-device_edit) :is(
    input,
    select,
    textarea,
    .user-edit-input,
    .custom-select,
    .select2-selection
) {
    background: #ffffff !important;
    border-color: #bfdbfe !important;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-device_edit section h3,
body.app-shell:not(.dark-mode).page-users_edit :is(h1, h2, h3, label) {
    color: #0f172a !important;
}

/* System settings workbench. */
body.app-shell:not(.dark-mode).page-system :is(
    .system-page,
    .settings-workbench,
    .settings-sidebar,
    .settings-jump,
    .dash-card,
    .card-header,
    .card-body,
    .preview-box,
    .vehicle-type-row,
    .icon-slot
) {
    background: #ffffff !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-system .system-page {
    background: #f8fafc !important;
}

body.app-shell:not(.dark-mode).page-system .system-page .dashboard-header {
    background: #ffffff !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06) !important;
}

body.app-shell:not(.dark-mode).page-system :is(h1, h2, h3, h4, label, .card-header, .longdo-usage-head h4) {
    color: #0f172a !important;
}

/* Restore readable contrast for controls that still inherit the legacy dark-theme palette. */
body.app-shell:not(.dark-mode).page-system .settings-jump a {
    color: #334155 !important;
}

body.app-shell:not(.dark-mode).page-system .settings-jump a i {
    color: #0369a1 !important;
}

body.app-shell:not(.dark-mode).page-system .settings-jump a:hover {
    color: #0f172a !important;
    background: #f0f9ff !important;
    border-color: #bae6fd !important;
}

body.app-shell:not(.dark-mode).page-system .settings-jump a.active {
    color: #075985 !important;
    background: #e0f2fe !important;
    border-color: #7dd3fc !important;
    box-shadow: inset 3px 0 0 #0284c7 !important;
}

body.app-shell:not(.dark-mode).page-system :is(
    .header-title p,
    .system-icon-preview,
    .vehicle-icon-preview,
    .color-input-row span,
    .status-image-meta span,
    .slot-label,
    .totp-card-head p,
    .longdo-usage-head p,
    .longdo-usage-foot
) {
    color: #475569 !important;
}

body.app-shell:not(.dark-mode).page-system :is(.icon-tool-btn, .slot-btn, .totp-action-btn) {
    background: #0369a1 !important;
    border-color: #0369a1 !important;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
}

body.app-shell:not(.dark-mode).page-system :is(.icon-tool-btn, .slot-btn, .totp-action-btn):hover {
    background: #075985 !important;
    border-color: #075985 !important;
    color: #ffffff !important;
}

body.app-shell:not(.dark-mode).page-system .settings-note {
    background: #ecfdf5 !important;
    border-color: #a7f3d0 !important;
    color: #065f46 !important;
}

body.app-shell:not(.dark-mode).page-system :is(
    .totp-card,
    .longdo-usage-panel,
    .longdo-usage-card,
    .color-input-row,
    .status-image-item
) {
    background: #f8fafc !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-system .totp-status-pill {
    background: #fef2f2 !important;
    border-color: #fecaca !important;
    color: #991b1b !important;
}

body.app-shell:not(.dark-mode).page-system .totp-status-pill.enabled {
    background: #ecfdf5 !important;
    border-color: #a7f3d0 !important;
    color: #065f46 !important;
}

body.app-shell:not(.dark-mode).page-system .longdo-usage-title {
    color: #075985 !important;
}

body.app-shell:not(.dark-mode).page-system .longdo-usage-number {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-system :is(input, select, textarea, .custom-input) {
    background: #ffffff !important;
    border-color: #bfdbfe !important;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-system .system-page [style*="background: #111c31"],
body.app-shell:not(.dark-mode).page-system .system-page [style*="background:#111c31"],
body.app-shell:not(.dark-mode).page-system .system-page [style*="background: #0b1220"],
body.app-shell:not(.dark-mode).page-system .system-page [style*="background:#0b1220"] {
    background: #ffffff !important;
    border-color: #dbeafe !important;
}

/* System monitor. Semantic health badges remain colored. */
body.app-shell:not(.dark-mode).page-system_monitor .sysmon-page {
    background: #f8fafc !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-system_monitor :is(
    .sysmon-live-card,
    .sysmon-card,
    .sysmon-core-item,
    .sysmon-ram-row,
    .sysmon-list > *,
    .sysmon-log-list > *
) {
    background: #ffffff !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.06) !important;
}

body.app-shell:not(.dark-mode).page-system_monitor :is(
    .sysmon-header h1,
    .sysmon-live-head,
    .sysmon-live-head strong,
    .sysmon-card-title,
    .sysmon-table,
    .sysmon-core-label
) {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-system_monitor :is(.sysmon-header p, .sysmon-table td, .sysmon-list) {
    color: #64748b !important;
}

body.app-shell:not(.dark-mode).page-system_monitor .sysmon-table th {
    background: #e0f2fe !important;
    color: #075985 !important;
}

/* System monitor: inline dark-theme colors need explicit light-theme contrast. */
body.app-shell:not(.dark-mode).page-system_monitor :is(
    .sysmon-kicker,
    .sysmon-metric-label,
    .sysmon-metric-sub,
    .sysmon-header p,
    .sysmon-ram-row,
    .sysmon-table td,
    .sysmon-list-item
) {
    color: #334155 !important;
}

body.app-shell:not(.dark-mode).page-system_monitor :is(
    .sysmon-metric-value,
    .sysmon-core-label,
    .sysmon-list-item strong
) {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-system_monitor .sysmon-log-line {
    color: #991b1b !important;
}

/* Realtime history import queue. */
body.app-shell:not(.dark-mode).page-realtime_history_import .history-import-page {
    background: #f8fafc !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-realtime_history_import :is(
    .history-import-window,
    .history-import-card,
    .history-import-drop,
    .history-import-job,
    .history-import-stat
) {
    background: #ffffff !important;
    border-color: #bfdbfe !important;
    color: #0f172a !important;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.06) !important;
}

body.app-shell:not(.dark-mode).page-realtime_history_import :is(
    .history-import-header h1,
    .history-import-window strong,
    .history-import-card-title h2,
    .history-import-drop strong,
    .history-import-job-name
) {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-realtime_history_import :is(
    .history-import-header p,
    .history-import-window span,
    .history-import-card-title span,
    .history-import-drop small
) {
    color: #64748b !important;
}

body.app-shell:not(.dark-mode).page-realtime_history_import :is(
    .history-import-note li,
    .history-import-jobs,
    .history-import-empty,
    .history-import-stat
) {
    color: #334155 !important;
}

/* POI map guidance and type labels must follow the light content surface. */
body.app-shell:not(.dark-mode).page-poi .poi-map-help {
    background: rgba(255, 255, 255, 0.96) !important;
    border-color: #bfdbfe !important;
    color: #0f172a !important;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14) !important;
}

body.app-shell:not(.dark-mode).page-poi #poiTable .badge-info {
    background: #eff6ff !important;
    border-color: #bfdbfe !important;
    color: #075985 !important;
    box-shadow: none !important;
}

/* Unified Admin report shell and every report type included inside it. */
body.app-shell:not(.dark-mode).report-surface .report-shell {
    background: #f8fafc !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).report-surface .report-sidebar {
    background: #eff6ff !important;
    border-color: #bfdbfe !important;
}

body.app-shell:not(.dark-mode).report-surface .report-sidebar-header {
    background: #ffffff !important;
    border-color: #bfdbfe !important;
}

body.app-shell:not(.dark-mode).report-surface .report-sidebar-header h3 {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).report-surface .report-menu-item {
    color: #475569 !important;
}

body.app-shell:not(.dark-mode).report-surface .report-menu-item:hover {
    background: #dbeafe !important;
    color: #075985 !important;
}

body.app-shell:not(.dark-mode).report-surface .report-menu-item.active {
    background: #bfdbfe !important;
    color: #075985 !important;
    border-color: #0284c7 !important;
}

body.app-shell:not(.dark-mode).report-surface :is(.report-content, .report-page) {
    background: #f8fafc !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).report-surface :is(
    .report-card,
    .report-card.light,
    .report-table-wrapper,
    .dataTables_wrapper
) {
    background: #ffffff !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06) !important;
}

body.app-shell:not(.dark-mode).report-surface :is(.report-page h2, .report-page h3, .report-card h2, .report-card h3) {
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).report-surface .report-card label {
    color: #475569 !important;
}

body.app-shell:not(.dark-mode).report-surface :is(
    .report-card input,
    .report-card select,
    .report-card textarea,
    .form-control,
    .form-select,
    .select2-selection
) {
    background-color: #ffffff !important;
    border-color: #bfdbfe !important;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
    color-scheme: light !important;
}

body.app-shell:not(.dark-mode).report-surface .report-card :is(
    input[type="date"],
    input[type="datetime-local"],
    input[type="time"]
) {
    background-image: none !important;
}

body.app-shell:not(.dark-mode).report-surface :is(.report-table, .report-table td, table td) {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #dbeafe !important;
}

body.app-shell:not(.dark-mode).report-surface :is(.report-table thead, .report-table th, table thead th) {
    background: #e0f2fe !important;
    color: #075985 !important;
    border-color: #bae6fd !important;
}

body.app-shell:not(.dark-mode).report-surface :is(.report-btn.secondary, .btn-secondary, .btn-outline-secondary) {
    background: #ffffff !important;
    color: #075985 !important;
    border-color: #bfdbfe !important;
}

body.app-shell:not(.dark-mode).report-surface [style*="background: #1e293b"],
body.app-shell:not(.dark-mode).report-surface [style*="background:#1e293b"],
body.app-shell:not(.dark-mode).report-surface [style*="background: #111c31"],
body.app-shell:not(.dark-mode).report-surface [style*="background:#111c31"],
body.app-shell:not(.dark-mode).report-surface [style*="background: #0f172a"],
body.app-shell:not(.dark-mode).report-surface [style*="background:#0f172a"],
body.app-shell:not(.dark-mode).report-surface [style*="background: #0b1220"],
body.app-shell:not(.dark-mode).report-surface [style*="background:#0b1220"] {
    background: #ffffff !important;
    border-color: #dbeafe !important;
}

body.app-shell:not(.dark-mode).report-surface [style*="color: #f8fafc"],
body.app-shell:not(.dark-mode).report-surface [style*="color:#f8fafc"],
body.app-shell:not(.dark-mode).report-surface [style*="color: #e2e8f0"],
body.app-shell:not(.dark-mode).report-surface [style*="color:#e2e8f0"],
body.app-shell:not(.dark-mode).report-surface [style*="color: #cbd5e1"],
body.app-shell:not(.dark-mode).report-surface [style*="color:#cbd5e1"] {
    color: #0f172a !important;
}

/* Direct legacy report routes outside report_main.php. */
body.app-shell:not(.dark-mode):is(.page-report_expire, .page-report_suspended) :is(
    .report-page,
    .report-card,
    .report-table-wrapper
) {
    background: #ffffff !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode):is(.page-report_expire, .page-report_suspended) [style*="color:#f8fafc"],
body.app-shell:not(.dark-mode):is(.page-report_expire, .page-report_suspended) [style*="color:#e2e8f0"] {
    color: #0f172a !important;
}

/* Long Stop Report must stay legible when its empty-state table is rendered. */
body.app-shell:not(.dark-mode).page-report_longstop :is(
    .report-page,
    .report-card,
    .report-table-wrapper,
    .report-table,
    .report-table tbody,
    .report-table td
) {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #dbeafe !important;
}

body.app-shell:not(.dark-mode).page-report_longstop :is(
    .report-table tbody tr:only-child td,
    .dataTables_empty
) {
    background: #f8fafc !important;
    color: #475569 !important;
}

body.app-shell:not(.dark-mode).page-report_longstop :is(
    .select2-selection,
    .select2-selection__rendered,
    .select2-selection__placeholder
) {
    background: #ffffff !important;
    color: #475569 !important;
    border-color: #bfdbfe !important;
}

/* Hidden maintenance utility retained in the same light application shell. */
body.app-shell:not(.dark-mode).page-vt200_pulse_test :is(.vt200-test-page, .vt200-panel, .vt200-mode-fixed, .vt200-preview) {
    background: #ffffff !important;
    border-color: #dbeafe !important;
    color: #0f172a !important;
}

body.app-shell:not(.dark-mode).page-vt200_pulse_test :is(.vt200-test-header h2, .vt200-panel-title, .vt200-table td) {
    color: #0f172a !important;
}

@media (max-width: 640px) {
    body.app-shell:not(.dark-mode):is(.page-users, .page-device, .page-driver, .page-device_model) .main-page,
    body.app-shell:not(.dark-mode):is(.page-system, .page-system_monitor, .page-realtime_history_import) :is(
        .system-page,
        .sysmon-page,
        .history-import-page
    ) {
        padding: 16px !important;
    }
}
