/* =========================================================
   AmbTrack Unified Theme
   Canonical color tokens + dark-mode polish across web/PWA.
   Load this after page-local CSS.
   ========================================================= */

:root {
  color-scheme: light;

  --brand-ink: #071318;
  --brand-navy: #0b2d5c;
  --brand-cyan: #05b6c8;
  --brand-red: #dc2626;
  --brand-red-hover: #b91c1c;

  --red: #dc2626;
  --red-hover: #b91c1c;
  --red-bg: #fff1f2;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --green: #059669;
  --green-bg: #ecfdf5;
  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
  --teal: #0e9384;
  --teal-bg: #f0fdfa;

  --slate-950: #020617;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;

  --bg: #f5f8fb;
  --page-bg: #f5f8fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #edf3f8;
  --surface-raised: #ffffff;
  --surface-glass: rgba(255, 255, 255, 0.86);
  --white: #ffffff;
  --black: #071318;
  --text: #071318;
  --muted: #5e6b7c;
  --muted-soft: #8a98aa;
  --line: rgba(7, 19, 24, 0.09);
  --border: rgba(7, 19, 24, 0.1);
  --accent: var(--brand-red);
  --accent-deep: var(--brand-red-hover);

  --focus-ring: 0 0 0 3px rgba(5, 182, 200, 0.18);
  --shadow: 0 10px 34px rgba(7, 19, 24, 0.08), 0 1px 2px rgba(7, 19, 24, 0.05);
  --shadow-sm: 0 1px 3px rgba(7, 19, 24, 0.06), 0 1px 2px rgba(7, 19, 24, 0.04);
  --shadow-md: 0 10px 28px rgba(7, 19, 24, 0.09), 0 2px 8px rgba(7, 19, 24, 0.05);
  --shadow-lg: 0 22px 70px rgba(7, 19, 24, 0.16), 0 8px 24px rgba(7, 19, 24, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;

  --brand-ink: #06101d;
  --brand-navy: #8ab8ff;
  --brand-cyan: #22d3ee;
  --brand-red: #ff4d55;
  --brand-red-hover: #ff6b72;

  --red: #ff4d55;
  --red-hover: #ff6b72;
  --red-bg: rgba(255, 77, 85, 0.14);
  --amber: #fbbf24;
  --amber-bg: rgba(251, 191, 36, 0.14);
  --blue: #7db2ff;
  --blue-bg: rgba(59, 130, 246, 0.16);
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.13);
  --purple: #c4b5fd;
  --purple-bg: rgba(167, 139, 250, 0.14);
  --teal: #5eead4;
  --teal-bg: rgba(20, 184, 166, 0.14);

  --slate-950: #f8fbff;
  --slate-900: #eef6ff;
  --slate-800: #d9e6f5;
  --slate-700: #c2d2e4;
  --slate-600: #a8b9cc;
  --slate-500: #8ea2b8;
  --slate-400: #6e8298;
  --slate-300: #52677f;
  --slate-200: #34485f;
  --slate-100: #17263a;
  --slate-50: #101d2d;

  --bg: #06101d;
  --page-bg: #06101d;
  --surface: #0b1726;
  --surface-2: #101f31;
  --surface-3: #15283e;
  --surface-raised: #122236;
  --surface-glass: rgba(10, 22, 37, 0.86);
  --white: #ffffff;
  --black: #06101d;
  --text: #edf5ff;
  --muted: #9aacbf;
  --muted-soft: #70869d;
  --line: rgba(176, 207, 238, 0.1);
  --border: rgba(176, 207, 238, 0.13);
  --accent: var(--brand-red);
  --accent-deep: #ff8086;

  --focus-ring: 0 0 0 3px rgba(34, 211, 238, 0.2);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.035);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.025);
  --shadow-md: 0 16px 42px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.035);
  --shadow-lg: 0 30px 90px rgba(0, 0, 0, 0.56), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 8% -8%, rgba(255, 77, 85, 0.13), transparent 34%),
    radial-gradient(circle at 92% 4%, rgba(34, 211, 238, 0.12), transparent 32%),
    linear-gradient(180deg, #06101d 0%, #071424 48%, #050b14 100%) !important;
  color: var(--text) !important;
}

html[data-theme="dark"] ::selection {
  background: rgba(255, 77, 85, 0.88);
  color: #fff;
}

/* Shared typography and content color */
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] .page-title,
html[data-theme="dark"] .section-h2,
html[data-theme="dark"] .topbar-title,
html[data-theme="dark"] .user-name,
html[data-theme="dark"] .brand-name,
html[data-theme="dark"] .drawer-title,
html[data-theme="dark"] .modal-title,
html[data-theme="dark"] .card-title,
html[data-theme="dark"] .panel-title,
html[data-theme="dark"] .record-title,
html[data-theme="dark"] .caseTitle,
html[data-theme="dark"] .role-info h3,
html[data-theme="dark"] .cf-vehicle,
html[data-theme="dark"] .sb2-info-val,
html[data-theme="dark"] .sb2-metric-val,
html[data-theme="dark"] .inc-id,
html[data-theme="dark"] .inc-countdown,
html[data-theme="dark"] .cc-vehicle,
html[data-theme="dark"] .active-case-title,
html[data-theme="dark"] .history-title {
  color: var(--text) !important;
}

html[data-theme="dark"] p,
html[data-theme="dark"] .section-sub,
html[data-theme="dark"] .panel-sub,
html[data-theme="dark"] .card-desc,
html[data-theme="dark"] .record-sub,
html[data-theme="dark"] .drawer-copy,
html[data-theme="dark"] .field-hint,
html[data-theme="dark"] .pref-desc,
html[data-theme="dark"] .legal-body p,
html[data-theme="dark"] .legal-body li {
  color: var(--muted) !important;
}

/* Shells and navigation */
html[data-theme="dark"] .nav,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .rail,
html[data-theme="dark"] .site-header.scrolled,
html[data-theme="dark"] .sb-topbar,
html[data-theme="dark"] .ip-head,
html[data-theme="dark"] .ap-head,
html[data-theme="dark"] .fp-head {
  background: var(--surface-glass) !important;
  border-color: var(--border) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.035);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}

html[data-theme="dark"] .nav-logo,
html[data-theme="dark"] .nav-links a:hover,
html[data-theme="dark"] .nav-link-cta:hover,
html[data-theme="dark"] .nav-mobile a:hover {
  color: var(--text) !important;
}

html[data-theme="dark"] .nav-links a,
html[data-theme="dark"] .nav-link-cta,
html[data-theme="dark"] .nav-mobile a,
html[data-theme="dark"] .brand-sub,
html[data-theme="dark"] .rail-user span {
  color: var(--muted) !important;
}

/* Admin dashboard page headers should read as part of the workspace, not as a second app bar. */
html[data-theme="dark"] .main > .topbar {
  background: transparent !important;
  border-bottom-color: rgba(148, 163, 184, 0.16) !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

html[data-theme="dark"] .main > .topbar .sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px !important;
  background: rgba(18, 34, 54, 0.86) !important;
  border: 1px solid rgba(148, 163, 184, 0.18) !important;
  border-radius: 999px !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035), 0 10px 24px rgba(0, 0, 0, 0.1) !important;
  color: var(--muted) !important;
}

html[data-theme="dark"] .main > .topbar .sync-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.12);
}

/* Internal section headers/footers are dividers, not separate glass panels. */
html[data-theme="dark"] .panel-head,
html[data-theme="dark"] .card-foot,
html[data-theme="dark"] .drawer-head,
html[data-theme="dark"] .drawer-foot {
  background: transparent !important;
  border-color: rgba(148, 163, 184, 0.16) !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Cards, panels, drawers, forms */
html[data-theme="dark"] .section-alt,
html[data-theme="dark"] .hero-proof,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .card,
html[data-theme="dark"] .bento-card,
html[data-theme="dark"] .metric-card,
html[data-theme="dark"] .stat-tile,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .record,
html[data-theme="dark"] .mini,
html[data-theme="dark"] .list-item,
html[data-theme="dark"] .role-fields,
html[data-theme="dark"] .role-card,
html[data-theme="dark"] .signup-step,
html[data-theme="dark"] .otp-modal,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .drawer,
html[data-theme="dark"] .inc-card,
html[data-theme="dark"] .active-case-card,
html[data-theme="dark"] .history-item,
html[data-theme="dark"] .info-panel,
html[data-theme="dark"] .cases-panel,
html[data-theme="dark"] #ops-panel,
html[data-theme="dark"] #case-panel,
html[data-theme="dark"] .cancel-modal,
html[data-theme="dark"] .reassign-modal,
html[data-theme="dark"] .cp-stat-tile,
html[data-theme="dark"] .cp-case,
html[data-theme="dark"] .triage-opt,
html[data-theme="dark"] .hospital-opt,
html[data-theme="dark"] .amb-card,
html[data-theme="dark"] .reassign-opt,
html[data-theme="dark"] .cancel-reason-opt,
html[data-theme="dark"] .cp-placeholder,
html[data-theme="dark"] .cf-item,
html[data-theme="dark"] .cc-card,
html[data-theme="dark"] .modal-amb-item,
html[data-theme="dark"] .sb2-metric-card,
html[data-theme="dark"] .sb2-info-card,
html[data-theme="dark"] .sb2-route-card,
html[data-theme="dark"] .route-strip,
html[data-theme="dark"] .case-card,
html[data-theme="dark"] .alert-card,
html[data-theme="dark"] .history-card,
html[data-theme="dark"] .resource-card,
html[data-theme="dark"] .availability-card,
html[data-theme="dark"] .incoming-panel,
html[data-theme="dark"] .availability-panel,
html[data-theme="dark"] .fleet-panel,
html[data-theme="dark"] #incoming-panel,
html[data-theme="dark"] #availability-panel,
html[data-theme="dark"] #fleet-panel,
html[data-theme="dark"] .toast,
html[data-theme="dark"] .settings-panel,
html[data-theme="dark"] .settings-avatar-row,
html[data-theme="dark"] .session-item,
html[data-theme="dark"] .settings-export-row {
  background: linear-gradient(180deg, rgba(18, 34, 54, 0.96), rgba(11, 23, 38, 0.96)) !important;
  border-color: var(--border) !important;
  box-shadow: var(--shadow) !important;
}

html[data-theme="dark"] .drawer,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .settings-panel {
  box-shadow: var(--shadow-lg) !important;
}

html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .sb-no-case,
html[data-theme="dark"] .sessions-empty,
html[data-theme="dark"] .placeholder,
html[data-theme="dark"] .cp-empty {
  background: rgba(255, 255, 255, 0.035) !important;
  border-color: rgba(255, 255, 255, 0.09) !important;
  color: var(--muted) !important;
}

/* Inputs and low-emphasis controls */
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]),
html[data-theme="dark"] textarea,
html[data-theme="dark"] select,
html[data-theme="dark"] .search,
html[data-theme="dark"] .toolbar-select,
html[data-theme="dark"] .demo-input,
html[data-theme="dark"] .form-input,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .field-input,
html[data-theme="dark"] .pref-select,
html[data-theme="dark"] .cp-input,
html[data-theme="dark"] .cp-select,
html[data-theme="dark"] .cp-textarea,
html[data-theme="dark"] .cp-search,
html[data-theme="dark"] .ops-search,
html[data-theme="dark"] .ops-zone-select,
html[data-theme="dark"] .ap-number-input,
html[data-theme="dark"] .ap-select,
html[data-theme="dark"] .ap-textarea,
html[data-theme="dark"] .vital-input,
html[data-theme="dark"] .destination-input,
html[data-theme="dark"] .notes-area,
html[data-theme="dark"] .cc-chat-input,
html[data-theme="dark"] .chat-input {
  background: rgba(16, 31, 49, 0.9) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
  box-shadow: none !important;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: var(--muted-soft) !important;
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] .search:focus,
html[data-theme="dark"] .toolbar-select:focus,
html[data-theme="dark"] .cp-input:focus,
html[data-theme="dark"] .cp-select:focus,
html[data-theme="dark"] .cp-textarea:focus,
html[data-theme="dark"] .cp-search:focus,
html[data-theme="dark"] .ops-search:focus {
  border-color: rgba(34, 211, 238, 0.55) !important;
  box-shadow: var(--focus-ring) !important;
}

/* Buttons and segmented controls */
html[data-theme="dark"] .btn,
html[data-theme="dark"] .btn-primary,
html[data-theme="dark"] .btn-cp-submit,
html[data-theme="dark"] .btn-create-case,
html[data-theme="dark"] .btn-status,
html[data-theme="dark"] .btn-save-small,
html[data-theme="dark"] .btn-update-avail,
html[data-theme="dark"] .rail-logout,
html[data-theme="dark"] .edit-btn,
html[data-theme="dark"] .sb-center-btn {
  background: linear-gradient(180deg, #f4f8ff, #cddbed) !important;
  color: #06101d !important;
  border-color: transparent !important;
  box-shadow: 0 10px 28px rgba(148, 180, 214, 0.16) !important;
}

html[data-theme="dark"] .action-btn,
html[data-theme="dark"] .assign-btn,
html[data-theme="dark"] .drawer-save,
html[data-theme="dark"] .settings-btn-primary,
html[data-theme="dark"] .btn-red,
html[data-theme="dark"] .mockup-btn-sos,
html[data-theme="dark"] .btn-deliver,
html[data-theme="dark"] .btn-deliver-confirm,
html[data-theme="dark"] .cm-btn-nav,
html[data-theme="dark"] .cm-btn-ack,
html[data-theme="dark"] .btn-cancel-confirm,
html[data-theme="dark"] .modal-confirm-btn.danger,
html[data-theme="dark"] .sos-btn,
html[data-theme="dark"] .sos-confirm-btn {
  background: linear-gradient(180deg, var(--red), #d52f38) !important;
  color: #fff !important;
  box-shadow: 0 12px 32px rgba(255, 77, 85, 0.22) !important;
}

html[data-theme="dark"] .ghost-btn,
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .btn-logout,
html[data-theme="dark"] .toggle-btn,
html[data-theme="dark"] .btn-cases,
html[data-theme="dark"] .ops-refresh,
html[data-theme="dark"] .ops-toggle,
html[data-theme="dark"] .ops-action,
html[data-theme="dark"] .cp-close,
html[data-theme="dark"] .cases-panel-close,
html[data-theme="dark"] .settings-btn-secondary,
html[data-theme="dark"] .session-revoke-btn,
html[data-theme="dark"] .settings-export-btn {
  background: rgba(255, 255, 255, 0.055) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}

html[data-theme="dark"] .ghost-btn:hover,
html[data-theme="dark"] .btn-ghost:hover,
html[data-theme="dark"] .btn-logout:hover,
html[data-theme="dark"] .toggle-btn:hover,
html[data-theme="dark"] .btn-cases:hover,
html[data-theme="dark"] .ops-refresh:hover,
html[data-theme="dark"] .ops-toggle:hover,
html[data-theme="dark"] .ops-action:hover,
html[data-theme="dark"] .cp-close:hover,
html[data-theme="dark"] .cases-panel-close:hover,
html[data-theme="dark"] .settings-btn-secondary:hover,
html[data-theme="dark"] .session-revoke-btn:hover,
html[data-theme="dark"] .settings-export-btn:hover {
  background: rgba(34, 211, 238, 0.1) !important;
  border-color: rgba(34, 211, 238, 0.28) !important;
}

html[data-theme="dark"] .toggle-btn.active,
html[data-theme="dark"] .role-tab.active,
html[data-theme="dark"] .zone-chip.selected,
html[data-theme="dark"] .shift-option.selected,
html[data-theme="dark"] .theme-pill.active,
html[data-theme="dark"] .settings-theme-btn.active {
  background: linear-gradient(180deg, rgba(255, 77, 85, 0.22), rgba(255, 77, 85, 0.13)) !important;
  border-color: rgba(255, 77, 85, 0.42) !important;
  color: #ffd8db !important;
}

html[data-theme="dark"] .modal-amb-item.selected,
html[data-theme="dark"] .hospital-opt.selected,
html[data-theme="dark"] .amb-card.selected,
html[data-theme="dark"] .reassign-opt.selected,
html[data-theme="dark"] .cancel-reason-opt.selected,
html[data-theme="dark"] .sb2-action-btn.active {
  background: rgba(34, 211, 238, 0.11) !important;
  border-color: rgba(34, 211, 238, 0.34) !important;
  color: var(--text) !important;
}

/* Semantic chips */
html[data-theme="dark"] .badge.red,
html[data-theme="dark"] .triage-high,
html[data-theme="dark"] .active-case-badge.high,
html[data-theme="dark"] .history-badge.cancelled,
html[data-theme="dark"] .cp-badge.high,
html[data-theme="dark"] .cp-badge.cancelled,
html[data-theme="dark"] .ops-chip-high,
html[data-theme="dark"] .ops-triage.high,
html[data-theme="dark"] .status-badge.cancelled {
  background: rgba(255, 77, 85, 0.14) !important;
  color: #ffb4b8 !important;
  border-color: rgba(255, 77, 85, 0.25) !important;
}

html[data-theme="dark"] .badge.green,
html[data-theme="dark"] .triage-low,
html[data-theme="dark"] .cp-badge.low,
html[data-theme="dark"] .cp-badge.completed,
html[data-theme="dark"] .ops-chip-low,
html[data-theme="dark"] .ops-triage.low,
html[data-theme="dark"] .status-badge.available,
html[data-theme="dark"] .avail-pill.green {
  background: rgba(52, 211, 153, 0.14) !important;
  color: #8ff0c9 !important;
  border-color: rgba(52, 211, 153, 0.24) !important;
}

html[data-theme="dark"] .badge.gold,
html[data-theme="dark"] .triage-medium,
html[data-theme="dark"] .cp-badge.medium,
html[data-theme="dark"] .ops-chip-medium,
html[data-theme="dark"] .ops-triage.medium,
html[data-theme="dark"] .avail-pill.amber {
  background: rgba(251, 191, 36, 0.14) !important;
  color: #ffe08a !important;
  border-color: rgba(251, 191, 36, 0.24) !important;
}

html[data-theme="dark"] .badge.blue,
html[data-theme="dark"] .cp-badge.active,
html[data-theme="dark"] .status-badge.en_route,
html[data-theme="dark"] .status-strip.en_route,
html[data-theme="dark"] .status-strip.dispatched,
html[data-theme="dark"] .status-strip.transporting {
  background: rgba(125, 178, 255, 0.15) !important;
  color: #b8d5ff !important;
  border-color: rgba(125, 178, 255, 0.24) !important;
}

/* Map, Places, and floating overlays */
html[data-theme="dark"] #map-search-input,
html[data-theme="dark"] #map-stats-panel,
html[data-theme="dark"] #last-refresh-wrap,
html[data-theme="dark"] #amb-sidebar,
html[data-theme="dark"] .destination-options,
html[data-theme="dark"] .pac-container {
  background: rgba(10, 22, 37, 0.94) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
  box-shadow: var(--shadow-lg) !important;
  backdrop-filter: blur(18px) saturate(145%);
}

html[data-theme="dark"] .pac-item,
html[data-theme="dark"] .destination-option {
  color: var(--muted) !important;
}

html[data-theme="dark"] .pac-item:hover,
html[data-theme="dark"] .pac-item-selected,
html[data-theme="dark"] .destination-option:hover,
html[data-theme="dark"] .destination-option:focus {
  background: rgba(34, 211, 238, 0.08) !important;
}

html[data-theme="dark"] .pac-item-query,
html[data-theme="dark"] .pac-matched,
html[data-theme="dark"] .destination-option-body strong {
  color: var(--text) !important;
}

html[data-theme="dark"] #police-zone-label {
  background: rgba(34, 211, 238, 0.12) !important;
  border-color: rgba(34, 211, 238, 0.28) !important;
  color: #9cecff !important;
}

/* Global theme toggle */
.amb-theme-toggle {
  position: fixed;
  right: calc(18px + env(safe-area-inset-right, 0));
  bottom: calc(18px + env(safe-area-inset-bottom, 0));
  z-index: 12020;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border, rgba(7, 19, 24, 0.1));
  border-radius: 999px;
  background: var(--surface-glass, rgba(255, 255, 255, 0.86));
  color: var(--text, #071318);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md, 0 10px 28px rgba(7, 19, 24, 0.09));
  isolation: isolate;
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  transition: transform 0.2s cubic-bezier(0.2, 0.9, 0.2, 1.15), border-color 0.16s ease, background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.amb-theme-toggle::before {
  content: "";
  position: absolute;
  inset: -6px;
  z-index: -1;
  border-radius: inherit;
  background: conic-gradient(from 90deg, rgba(220, 38, 38, 0), rgba(220, 38, 38, 0.34), rgba(34, 211, 238, 0.3), rgba(220, 38, 38, 0));
  opacity: 0;
  transform: scale(0.82) rotate(0deg);
  filter: blur(2px);
  transition: opacity 0.22s ease, transform 0.32s ease;
}

.amb-theme-toggle svg {
  position: relative;
  z-index: 1;
  transform-origin: 50% 50%;
  transition: transform 0.24s cubic-bezier(0.2, 0.9, 0.2, 1.15);
}

.amb-theme-toggle:hover {
  transform: translateY(-3px) rotate(-4deg);
  border-color: rgba(220, 38, 38, 0.32);
  box-shadow: 0 16px 34px rgba(7, 19, 24, 0.15);
}

.amb-theme-toggle:hover::before {
  opacity: 1;
  transform: scale(1) rotate(18deg);
}

.amb-theme-toggle:hover svg {
  transform: rotate(12deg) scale(1.06);
}

.amb-theme-toggle:active {
  transform: translateY(0) scale(0.94) rotate(0deg);
}

.amb-theme-toggle.is-switching {
  animation: theme-toggle-pop 0.46s cubic-bezier(0.18, 0.9, 0.22, 1.18);
}

.amb-theme-toggle.is-switching::before {
  animation: theme-toggle-aura 0.62s ease-out;
}

.amb-theme-toggle.is-switching svg {
  animation: theme-toggle-orbit 0.46s cubic-bezier(0.18, 0.9, 0.22, 1.18);
}

.amb-theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--shadow-md), var(--focus-ring);
}

html[data-theme="dark"] .amb-theme-toggle {
  background: rgba(18, 34, 54, 0.9);
  color: #edf5ff;
  border-color: rgba(176, 207, 238, 0.14);
}

html[data-theme="dark"] .amb-theme-toggle:hover {
  border-color: rgba(34, 211, 238, 0.34);
  background: rgba(20, 42, 65, 0.94);
}

@keyframes theme-toggle-pop {
  0% { transform: scale(1) rotate(0deg); }
  40% { transform: scale(1.14) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes theme-toggle-orbit {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(150deg) scale(0.86); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes theme-toggle-aura {
  0% { opacity: 0.9; transform: scale(0.72) rotate(0deg); }
  100% { opacity: 0; transform: scale(1.45) rotate(120deg); }
}

/* Landing/public pages */
html[data-theme="dark"] .hero-eyebrow,
html[data-theme="dark"] .bento-tag,
html[data-theme="dark"] .stack-item,
html[data-theme="dark"] .sync-chip,
html[data-theme="dark"] .role-tab,
html[data-theme="dark"] .signup-step,
html[data-theme="dark"] .otp-step {
  background: rgba(255, 255, 255, 0.045) !important;
  border-color: var(--border) !important;
  color: var(--muted) !important;
}

html[data-theme="dark"] .cta-inner,
html[data-theme="dark"] .footer {
  background: linear-gradient(180deg, #07111f, #040914) !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
}

html[data-theme="dark"] .footer {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Public pages: one continuous immersive dark scene instead of stacked dual-tone bands. */
html.amb-public-page[data-theme="dark"] {
  background: #050b13;
}

html.amb-public-page[data-theme="dark"] body {
  position: relative;
  isolation: isolate;
  overflow-x: hidden;
  background: transparent !important;
  color: var(--muted) !important;
}

html.amb-public-page[data-theme="dark"] body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    linear-gradient(115deg, rgba(255, 77, 85, 0.085) 0%, rgba(255, 77, 85, 0) 32%),
    linear-gradient(245deg, rgba(34, 211, 238, 0.09) 0%, rgba(34, 211, 238, 0) 34%),
    linear-gradient(180deg, #06101d 0%, #071321 46%, #050b13 100%);
}

html.amb-public-page[data-theme="dark"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.42;
  background:
    linear-gradient(rgba(255, 255, 255, 0.024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 96px 96px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.8), transparent 78%);
}

html.amb-public-page[data-theme="dark"] .nav {
  background: rgba(5, 11, 19, 0.68) !important;
  border-color: rgba(148, 163, 184, 0.1) !important;
  box-shadow: none !important;
}

html.amb-public-page[data-theme="dark"] .nav.scrolled {
  background: rgba(5, 11, 19, 0.88) !important;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.18) !important;
}

html.amb-public-page[data-theme="dark"] .hero,
html.amb-public-page[data-theme="dark"] .section,
html.amb-public-page[data-theme="dark"] .section-alt,
html.amb-public-page[data-theme="dark"] .login-hero,
html.amb-public-page[data-theme="dark"] .register-hero,
html.amb-public-page[data-theme="dark"] .reset-hero,
html.amb-public-page[data-theme="dark"] .legal-hero,
html.amb-public-page[data-theme="dark"] .legal-body {
  background: transparent !important;
}

html.amb-public-page[data-theme="dark"] .hero-proof {
  background: rgba(255, 255, 255, 0.026) !important;
  border-top-color: rgba(148, 163, 184, 0.14) !important;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

html.amb-public-page[data-theme="dark"] .section-alt {
  box-shadow:
    inset 0 1px 0 rgba(148, 163, 184, 0.08),
    inset 0 -1px 0 rgba(148, 163, 184, 0.06);
}

html.amb-public-page[data-theme="dark"] .hero-h1,
html.amb-public-page[data-theme="dark"] .section-h2 {
  color: #eef6ff !important;
  text-shadow: 0 18px 70px rgba(0, 0, 0, 0.18);
}

html.amb-public-page[data-theme="dark"] .hero-muted {
  color: rgba(176, 194, 217, 0.62) !important;
}

html.amb-public-page[data-theme="dark"] .hero-p,
html.amb-public-page[data-theme="dark"] .section-sub,
html.amb-public-page[data-theme="dark"] .infra-p,
html.amb-public-page[data-theme="dark"] .form-footer,
html.amb-public-page[data-theme="dark"] .legal-updated {
  color: #9fb1c7 !important;
}

html.amb-public-page[data-theme="dark"] .section-label,
html.amb-public-page[data-theme="dark"] .hero-h1 em,
html.amb-public-page[data-theme="dark"] .section-h2 em {
  color: #ff6b72 !important;
}

html.amb-public-page[data-theme="dark"] .bento-card,
html.amb-public-page[data-theme="dark"] .metric-card,
html.amb-public-page[data-theme="dark"] .role-tabs,
html.amb-public-page[data-theme="dark"] .role-tab,
html.amb-public-page[data-theme="dark"] .stack-strip,
html.amb-public-page[data-theme="dark"] .stack-item,
html.amb-public-page[data-theme="dark"] .register-form,
html.amb-public-page[data-theme="dark"] .role-card,
html.amb-public-page[data-theme="dark"] .role-fields,
html.amb-public-page[data-theme="dark"] .otp-modal,
html.amb-public-page[data-theme="dark"] .legal-toc,
html.amb-public-page[data-theme="dark"] .rights-card,
html.amb-public-page[data-theme="dark"] .legal-highlight,
html.amb-public-page[data-theme="dark"] .countdown-badge {
  background: linear-gradient(180deg, rgba(18, 34, 54, 0.78), rgba(10, 22, 36, 0.72)) !important;
  border-color: rgba(148, 163, 184, 0.16) !important;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.04) !important;
  backdrop-filter: blur(18px) saturate(145%);
  -webkit-backdrop-filter: blur(18px) saturate(145%);
}

html.amb-public-page[data-theme="dark"] .register-form {
  padding: 24px !important;
  margin-bottom: 72px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 24px;
}

html.amb-public-page[data-theme="dark"] .bento-card:hover,
html.amb-public-page[data-theme="dark"] .metric-card:hover,
html.amb-public-page[data-theme="dark"] .role-card:hover,
html.amb-public-page[data-theme="dark"] .stack-item:hover {
  border-color: rgba(34, 211, 238, 0.28) !important;
  background: linear-gradient(180deg, rgba(22, 42, 66, 0.86), rgba(12, 25, 41, 0.78)) !important;
  transform: translateY(-4px);
}

html.amb-public-page[data-theme="dark"] .process-step,
html.amb-public-page[data-theme="dark"] .faq-item,
html.amb-public-page[data-theme="dark"] .role-tab,
html.amb-public-page[data-theme="dark"] .stack-item,
html.amb-public-page[data-theme="dark"] .mockup-stat-row,
html.amb-public-page[data-theme="dark"] .mockup-stat {
  border-color: rgba(148, 163, 184, 0.14) !important;
}

html.amb-public-page[data-theme="dark"] .process-num {
  color: rgba(148, 163, 184, 0.18) !important;
}

html.amb-public-page[data-theme="dark"] .process-step:hover .process-num {
  color: #ff6b72 !important;
}

html.amb-public-page[data-theme="dark"] .role-tab.active,
html.amb-public-page[data-theme="dark"] .signup-step.active,
html.amb-public-page[data-theme="dark"] .role-card.selected,
html.amb-public-page[data-theme="dark"] .zone-chip.selected,
html.amb-public-page[data-theme="dark"] .shift-option.selected,
html.amb-public-page[data-theme="dark"] .otp-step.active {
  background: linear-gradient(180deg, rgba(255, 77, 85, 0.2), rgba(255, 77, 85, 0.12)) !important;
  border-color: rgba(255, 77, 85, 0.42) !important;
  color: #ffe9eb !important;
  box-shadow: 0 14px 34px rgba(220, 38, 38, 0.12) !important;
}

html.amb-public-page[data-theme="dark"] .mockup-phone,
html.amb-public-page[data-theme="dark"] .mockup-tablet {
  background: rgba(2, 6, 23, 0.9) !important;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.34) !important;
}

html.amb-public-page[data-theme="dark"] .mockup-screen {
  background: #081422 !important;
}

html.amb-public-page[data-theme="dark"] .mockup-map {
  background: linear-gradient(135deg, rgba(255, 77, 85, 0.2), rgba(34, 211, 238, 0.18)) !important;
}

html.amb-public-page[data-theme="dark"] .mockup-btn-sec,
html.amb-public-page[data-theme="dark"] .otp-step span,
html.amb-public-page[data-theme="dark"] .password-strength {
  background: rgba(255, 255, 255, 0.06) !important;
  color: var(--muted) !important;
}

html.amb-public-page[data-theme="dark"] .form-group label,
html.amb-public-page[data-theme="dark"] .role-card strong,
html.amb-public-page[data-theme="dark"] .legal-body h3,
html.amb-public-page[data-theme="dark"] .legal-body h4,
html.amb-public-page[data-theme="dark"] .rights-card strong,
html.amb-public-page[data-theme="dark"] .success-check strong,
html.amb-public-page[data-theme="dark"] .expired-state strong {
  color: #eaf3ff !important;
}

html.amb-public-page[data-theme="dark"] .form-input,
html.amb-public-page[data-theme="dark"] .form-select,
html.amb-public-page[data-theme="dark"] .otp-inputs input,
html.amb-public-page[data-theme="dark"] .otp-digit {
  background: rgba(5, 15, 27, 0.72) !important;
  border-color: rgba(148, 163, 184, 0.18) !important;
  color: #eff6ff !important;
}

html.amb-public-page[data-theme="dark"] .form-input:focus,
html.amb-public-page[data-theme="dark"] .form-select:focus,
html.amb-public-page[data-theme="dark"] .otp-inputs input:focus,
html.amb-public-page[data-theme="dark"] .otp-digit:focus {
  border-color: rgba(34, 211, 238, 0.5) !important;
  box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.12) !important;
}

html.amb-public-page[data-theme="dark"] .legal-table th,
html.amb-public-page[data-theme="dark"] .legal-table td {
  background: rgba(18, 34, 54, 0.5) !important;
  border-color: rgba(148, 163, 184, 0.16) !important;
  color: var(--muted) !important;
}

html.amb-public-page[data-theme="dark"] .legal-table th {
  color: #eaf3ff !important;
}

html.amb-public-page[data-theme="dark"] .footer {
  background: transparent !important;
  border-top: 1px solid rgba(148, 163, 184, 0.12) !important;
  box-shadow: none !important;
}

html.amb-public-page .amb-reveal {
  opacity: 0;
  transform: translate3d(0, 18px, 0) scale(0.985);
  transition:
    opacity 0.72s cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 0.72s cubic-bezier(0.2, 0.8, 0.2, 1),
    border-color 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease;
  transition-delay: var(--amb-reveal-delay, 0ms);
}

html.amb-public-page .amb-reveal.amb-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
}

/* Late dashboard chat panels */
html[data-theme="dark"] .cc-chat-panel,
html[data-theme="dark"] .chat-panel {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  box-shadow: var(--shadow-lg) !important;
}

html[data-theme="dark"] .cc-chat-header,
html[data-theme="dark"] .cc-chat-input-row,
html[data-theme="dark"] .chat-input-row {
  background: var(--surface-2) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] .cc-chat-msg.mine,
html[data-theme="dark"] .chat-msg.mine {
  background: rgba(125, 178, 255, 0.16) !important;
  color: var(--text) !important;
}

html[data-theme="dark"] .cc-chat-msg.theirs,
html[data-theme="dark"] .chat-msg.theirs {
  background: rgba(255, 255, 255, 0.06) !important;
  color: var(--text) !important;
}

/* Motion/accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding-left: 12px !important;
    padding-right: 12px !important;
    gap: 8px !important;
  }

  .topbar-left {
    gap: 8px !important;
    min-width: 0;
  }

  .topbar-title {
    max-width: 116px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-badge,
  .user-name,
  .topbar-divider {
    display: none !important;
  }

  .topbar-right {
    margin-left: auto;
    gap: 6px !important;
    min-width: 0;
    flex-shrink: 1;
  }

  .user-chip {
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
  }

  .toggle-btn,
  .btn-cases,
  .btn-sound,
  .btn-incoming,
  .btn-update-avail,
  .btn-create-case {
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    padding: 0 !important;
    justify-content: center !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    font-size: 0 !important;
    gap: 0 !important;
  }

  .toggle-btn svg,
  .btn-cases svg,
  .btn-sound svg,
  .btn-incoming svg,
  .btn-update-avail svg,
  .btn-create-case svg {
    margin: 0 !important;
    width: 16px;
    height: 16px;
  }

  .btn-logout {
    display: none !important;
  }

  .amb-theme-toggle {
    right: calc(12px + env(safe-area-inset-right, 0));
    bottom: calc(12px + env(safe-area-inset-bottom, 0));
    width: 38px;
    height: 38px;
  }
}
