[data-bs-theme="dark"] {
  --app-topbar-bg: #0d1420;
  --app-sidebar-bg: #111927;
  --app-sidebar-color: #d7e1ed;
  --app-sidebar-muted: #8ea0b6;
  --app-sidebar-active: #255db3;
  --app-page-bg: #151b24;
  --app-surface: #202833;
  --app-surface-secondary: #19212b;
  --app-border-color: #394657;
  --app-muted-color: #a9b7c8;
  --app-focus-ring: rgba(110, 168, 254, 0.42);
  --app-shadow-sm: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.2);
  --app-shadow-md: 0 0.75rem 2rem rgba(0, 0, 0, 0.24);

  /* Compatibility variables used by the older, still functional modules. */
  --bg: var(--app-page-bg);
  --panel: var(--app-surface);
  --panel-soft: var(--app-surface-secondary);
  --text: var(--bs-body-color);
  --muted: var(--bs-secondary-color);
  --line: var(--app-border-color);
  --line-strong: #526176;
  --border: var(--app-border-color);
  --shadow: var(--app-shadow-sm);
  --shadow-soft: var(--app-shadow-md);
  --shadow-card: var(--app-shadow-sm);
}

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

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

html[data-bs-theme="dark"] body.app-body :is(.dropdown-menu, .modal-content, .offcanvas) {
  color: var(--bs-body-color);
  background-color: var(--app-surface);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] body.app-body :is(.list-group-item, .accordion-item) {
  color: var(--bs-body-color);
  background-color: var(--app-surface);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] body.app-body :is(.list-group-item-action:hover, .list-group-item-action:focus) {
  background-color: var(--app-surface-secondary);
}

html[data-bs-theme="dark"] body.app-body .btn-close {
  filter: var(--bs-btn-close-white-filter);
}

html[data-bs-theme="dark"] body.app-body .app-content-inner :is(.card, .app-card) {
  color: var(--bs-body-color);
  background-color: var(--app-surface);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] body.app-body .app-content-inner :is(.bg-light, .text-bg-light) {
  color: var(--bs-body-color) !important;
  background-color: var(--app-surface-secondary) !important;
}

html[data-bs-theme="dark"] body.app-body .app-content-inner :is(.form-control, .form-select) {
  color: var(--bs-body-color);
  background-color: var(--app-surface-secondary);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] body.app-body .app-content-inner :is(.form-control, .form-select)::placeholder {
  color: var(--bs-tertiary-color);
}

html[data-bs-theme="dark"] body.app-body .search-form input {
  color: var(--bs-body-color);
  background: var(--app-surface-secondary);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] body.app-body .app-content-inner .table > :not(caption) > * > * {
  color: var(--bs-body-color);
  background-color: transparent;
  border-color: var(--app-border-color);
}

/* Dashboard */
html[data-bs-theme="dark"] .dashboard-page {
  --dashboard-border: var(--app-border-color);
  --dashboard-border-strong: #516076;
  --dashboard-muted: var(--bs-secondary-color);
  --dashboard-text: var(--bs-body-color);
  --dashboard-surface: var(--app-surface-secondary);
  --dashboard-surface-strong: #242e3b;
  --dashboard-shadow: var(--app-shadow-md);
  --dashboard-shadow-soft: var(--app-shadow-sm);
}

html[data-bs-theme="dark"] .dashboard-page::before {
  background:
    radial-gradient(circle at top left, rgba(49, 120, 235, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(14, 165, 233, 0.08), transparent 24%),
    linear-gradient(180deg, rgba(32, 40, 51, 0.8), rgba(21, 27, 36, 0.94));
}

html[data-bs-theme="dark"] :is(
  .dashboard-widget,
  .dashboard-widget-manager-card,
  .dashboard-widget-manager-item,
  .dashboard-inline-metric,
  .dashboard-list-item,
  .dashboard-stat-pill,
  .dashboard-empty-state,
  .dashboard-search-result,
  .dashboard-notification-item
) {
  color: var(--bs-body-color);
  background: var(--app-surface);
  border-color: var(--app-border-color);
}

/* UAS, SORA and emergency management */
html[data-bs-theme="dark"] .uas-page {
  --uas-border: var(--app-border-color);
  --uas-ink: var(--bs-body-color);
  --uas-muted: var(--bs-secondary-color);
  --uas-accent: #55b6bd;
}

html[data-bs-theme="dark"] .uas-emergency-page {
  color: var(--bs-body-color);
}

html[data-bs-theme="dark"] :is(.uas-panel, .uas-emergency-panel, .sora-panel, .uas-attachment-card, .uas-manual-panel) {
  color: var(--bs-body-color);
  background: var(--app-surface);
  border-color: var(--app-border-color);
  box-shadow: var(--app-shadow-sm);
}

html[data-bs-theme="dark"] :is(.uas-panel-head, .uas-emergency-panel > header, .sora-panel-head) {
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] .sora-page {
  --sora-border: var(--app-border-color);
  --sora-ink: var(--bs-body-color);
  --sora-muted: var(--bs-secondary-color);
  --sora-accent: #55b6bd;
}

html[data-bs-theme="dark"] :is(.uas-emergency-kicker, .uas-emergency-details dt, .sora-kicker) {
  color: var(--bs-secondary-color);
}

html[data-bs-theme="dark"] .uas-emergency-scenario {
  color: #ffb4ad;
  background: rgba(220, 53, 69, 0.14);
}

html[data-bs-theme="dark"] .sora-assessment-list .list-group-item.active {
  color: var(--bs-body-color);
  background: rgba(18, 108, 116, 0.22);
  border-color: var(--app-border-color);
}

/* Operational modules */
html[data-bs-theme="dark"] :is(
  .drone-summary-card .card-body,
  .drone-shell-card .card-body,
  .etb-kpi-card .card-body,
  .etb-form-card .card-body,
  .etb-table-card .card-body,
  .etb-guidance-card .card-body,
  .sections-metric-card .card-body,
  .sections-mode-card .card-body,
  .sections-form-card .card-body,
  .sections-grid-card .card-body,
  .sections-requirements-card .card-body,
  .sections-history-card .card-body
) {
  color: var(--bs-body-color);
  background: linear-gradient(180deg, var(--app-surface), var(--app-surface-secondary));
}

html[data-bs-theme="dark"] .drone-overview-app {
  --drone-ink: var(--bs-body-color);
}

html[data-bs-theme="dark"] :is(.drone-status-card, .drone-empty-state, .sections-card, .sections-empty-state, .etb-empty-state) {
  color: var(--bs-body-color);
  background: var(--app-surface-secondary);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] .drone-map-shell {
  background: #111827;
  border-color: var(--app-border-color);
}

/* Communication, reports and situation summaries */
html[data-bs-theme="dark"] .communication-app {
  --communication-border: var(--app-border-color);
  --communication-text-muted: var(--bs-secondary-color);
  --communication-surface: rgba(32, 40, 51, 0.9);
}

html[data-bs-theme="dark"] :is(
  .communication-area-card,
  .communication-shell,
  .communication-entry-card,
  .communication-sketch-panel,
  .communication-empty-state,
  .report-type-card,
  .report-mini,
  .situation-type-card,
  .situation-mini
) {
  color: var(--bs-body-color);
  background: var(--app-surface);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] .communication-live-pill {
  color: var(--bs-body-color);
  background: var(--app-surface-secondary);
}

html[data-bs-theme="dark"] .report-box {
  color: var(--bs-body-color);
  background: var(--app-surface-secondary);
  border-color: var(--app-border-color);
}

/* Patient transport and older shared styles */
html[data-bs-theme="dark"] :is(
  .pto-timer-panel,
  .pto-timer-meta-item,
  .pto-display-timer,
  .pto-live-pill,
  .pto-dispo-table-wrap,
  .pto-destination-form,
  .pto-destination-hint,
  .metric-card,
  .overview-panel,
  .flash,
  .hint-item,
  .secondary-action,
  .danger-action
) {
  color: var(--bs-body-color);
  background: var(--app-surface);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] .pto-dispo-table thead th {
  background: var(--app-surface-secondary);
}

html[data-bs-theme="dark"] :is(.pto-priority-badge, .pto-status-pill, .tag) {
  background: var(--app-surface-secondary);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] .mobile-sticky {
  background: rgba(21, 27, 36, 0.95);
}

/* Strategic transport */
html[data-bs-theme="dark"] .strategic-transport-app {
  --st-ink: var(--bs-body-color);
  --st-muted: var(--bs-secondary-color);
  --st-border: var(--app-border-color);
}

html[data-bs-theme="dark"] :is(
  .strategic-toolbar__main,
  .strategic-event-form,
  .strategic-module-nav .nav-link,
  .strategic-panel,
  .strategic-patient-card,
  .strategic-location-card
) {
  color: var(--bs-body-color);
  background: var(--app-surface);
  border-color: var(--app-border-color);
}

html[data-bs-theme="dark"] .st-intake {
  --st-ink: var(--bs-body-color);
  --st-muted: var(--bs-secondary-color);
  --st-line: var(--app-border-color);
  --st-surface: var(--app-surface);
  --st-soft: var(--app-surface-secondary);
  color: var(--bs-body-color);
}

html[data-bs-theme="dark"] .st-intake__topbar {
  background: rgba(21, 27, 36, 0.96);
}

/* Forest search: theme the chrome, never invert the map or its images. */
html[data-bs-theme="dark"] [data-forest-root] {
  --forest-ink: var(--bs-body-color);
  --forest-ink-soft: #c3d6ce;
  --forest-muted: var(--bs-secondary-color);
  --forest-line: var(--app-border-color);
  --forest-line-strong: #506457;
  --forest-surface: var(--app-surface);
  --forest-surface-soft: var(--app-surface-secondary);
  --forest-surface-tint: #24332e;
  --forest-shadow: var(--app-shadow-md);
  --forest-shadow-soft: var(--app-shadow-sm);
}

html[data-bs-theme="dark"] [data-forest-root] :is(
  .forest-map-shell,
  .forest-map-shell-header,
  .forest-map-toolbar,
  .forest-map-result-card,
  .forest-map-empty,
  .forest-map-detail
) {
  color: var(--bs-body-color);
  background: var(--app-surface);
  border-color: var(--app-border-color);
}

/* Admin stylesheet is loaded late and sets a light body background. */
html[data-bs-theme="dark"] body.app-body.app-layout-administration {
  background-color: var(--app-page-bg);
}

@media print {
  :root,
  [data-bs-theme="dark"] {
    color-scheme: light;
    --app-page-bg: #ffffff;
    --app-surface: #ffffff;
    --app-surface-secondary: #ffffff;
    --app-border-color: #cfd4da;
  }

  body.app-body {
    color: #000000 !important;
    background: #ffffff !important;
  }

  .app-shell {
    display: block;
  }

  .app-topbar,
  .app-sidebar,
  .app-sidebar-backdrop {
    display: none !important;
  }

  .app-main,
  .app-content,
  .app-content-inner {
    display: block;
    width: 100%;
    max-width: none;
    padding: 0;
  }

  .page-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  .app-content-inner :is(.card, .app-card, .form-section) {
    color: #000000 !important;
    background: #ffffff !important;
    box-shadow: none !important;
  }
}
