html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #071725;
  --surface: #0c2233;
  --surface-2: #102b3d;
  --surface-soft: #102b3d;
  --panel: #0c2233;
  --soft: #102b3d;
  --sidebar: #091d2d;
  --sidebar-ink: #edf7fa;
  --ink: #edf7fa;
  --muted: #a5bac7;
  --line: #29485b;
  --line-strong: #3d6075;
  --green: #48d5ae;
  --green-strong: #7be6d3;
  --green-soft: #123b35;
  --good: #48d5ae;
  --ok: #48d5ae;
  --teal: #37d4c0;
  --teal-soft: #103b3a;
  --blue: #76b7ff;
  --blue-soft: #122e4a;
  --accent: #76b7ff;
  --accent-strong: #9ccaff;
  --accent-2: #37d4c0;
  --red: #ff9797;
  --red-soft: #421f28;
  --danger: #ff9797;
  --yellow: #f1d06f;
  --yellow-soft: #3d341b;
  --warn: #f1c56c;
  --violet: #c3a9ff;
  --violet-soft: #30284a;
  --white: #0c2233;
  --gray-950: #edf7fa;
  --gray-800: #c6d5dd;
  --gray-600: #a5bac7;
  --gray-300: #35556a;
  --gray-200: #29485b;
  --gray-100: #0d2638;
  --blue-900: #9ccaff;
  --blue-800: #76b7ff;
  --blue-50: #102b3d;
  --blue-100: #153552;
  --green-700: #48d5ae;
  --green-100: #123b35;
  --teal-700: #37d4c0;
  --teal-100: #103b3a;
  --red-700: #ff9797;
  --red-100: #421f28;
  --orange-700: #ffb06e;
  --orange-100: #432b1d;
  --yellow-700: #f1d06f;
  --yellow-100: #3d341b;
  --focus: #66e6d3;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.32);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 8% 8%, rgba(55, 212, 192, 0.1), transparent 28rem),
    radial-gradient(circle at 92% 20%, rgba(118, 183, 255, 0.09), transparent 30rem),
    linear-gradient(180deg, #06131f 0%, #071725 55%, #091d2b 100%) !important;
  color: var(--ink) !important;
}

html[data-theme="dark"] :where(h1, h2, h3, h4, strong, legend, label, th, td) {
  color: var(--ink);
}

html[data-theme="dark"] :where(p, small, .hint, .help, .panel-copy, .section-note, .table-note) {
  color: var(--muted);
}

html[data-theme="dark"] a {
  color: #8ec7ff;
}

html[data-theme="dark"] :where(.topbar, .app-header) {
  border-color: #1ab9a7 !important;
  background: linear-gradient(125deg, #06131f 0%, #082a3c 58%, #075b5b 100%) !important;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.34) !important;
}

html[data-theme="dark"] :where(
  .topbar h1,
  .topbar h2,
  .topbar strong,
  .topbar p,
  .topbar small,
  .app-header h1,
  .app-header h2,
  .app-header strong,
  .app-header p,
  .app-header small
) {
  color: #f4fbfd;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid #b8d0dc;
  border-radius: 10px;
  background: #eff8fa;
  color: #0b4561;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 850;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 14px rgba(6, 47, 99, 0.12);
}

.topbar > .theme-toggle,
.app-header > .theme-toggle {
  margin-left: auto;
}

.sidebar > .theme-toggle {
  margin-top: auto;
}

.theme-toggle:hover {
  border-color: #4db7aa;
  background: #e1f5f2;
  color: #073b52;
}

.theme-toggle:focus-visible {
  outline: 3px solid #79ead7;
  outline-offset: 3px;
}

.theme-toggle [data-theme-icon] {
  font-size: 1.15rem;
}

.theme-toggle :where([data-theme-icon], [data-theme-label]) {
  color: inherit !important;
}

html[data-theme="dark"] .theme-toggle {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
}

html[data-theme="dark"] .theme-toggle:hover {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

html[data-theme="dark"] :where(input, select, textarea) {
  border-color: var(--line) !important;
  background: #081c2b !important;
  color: var(--ink) !important;
  caret-color: #79ead7;
}

html[data-theme="dark"] :where(input, textarea)::placeholder {
  color: #7892a3;
  opacity: 1;
}

html[data-theme="dark"] option {
  background: #0b2233;
  color: var(--ink);
}

html[data-theme="dark"] :where(input:disabled, select:disabled, textarea:disabled) {
  background: #102838 !important;
  color: #8299a8 !important;
}

html[data-theme="dark"] button:disabled {
  border-color: #35556a !important;
  background: #193447 !important;
  color: #91a7b5 !important;
}

html[data-theme="dark"] :where(.field > span, .field legend, .file-drop span) {
  color: #c6d5dd !important;
}

html[data-theme="dark"] :where(.profile-center-chip, .profile-center-empty, .profile-switch) {
  border-color: var(--line-strong) !important;
  background: #0c2435 !important;
  color: var(--ink) !important;
}

html[data-theme="dark"] .profile-center-chip strong {
  color: #e9f7fb !important;
}

html[data-theme="dark"] .profile-center-chip small {
  color: #a9c1cf !important;
}

html[data-theme="dark"] :where(
  .auth-user-panel,
  .hero-highlights span,
  .qf-dashboard-summary span,
  .mission-note,
  .readonly-grid p,
  .detail-grid p,
  .audit-list li
) {
  border-color: var(--line) !important;
  background: #0c2435 !important;
  color: var(--ink) !important;
}

html[data-theme="dark"] :where(.readonly-grid span, .detail-grid span, .audit-list li) {
  color: #a9c1cf !important;
}

html[data-theme="dark"] :where(.readonly-grid strong, .detail-grid strong) {
  color: #e9f7fb !important;
}

html[data-theme="dark"] :where(
  .app-boot-card,
  .beta-login-panel,
  .qf-dashboard,
  .qf-dashboard-item,
  .module-card,
  .management-header,
  .settings-panel,
  .dialog-body,
  .profile-center-item,
  .admin-secondary-section,
  .control-panel,
  .control-bar,
  .clinical-section,
  .form-section,
  .section-panel,
  .table-section,
  .summary-card,
  .status-panel,
  .panel,
  .work-area,
  .side-panel,
  .output-panel,
  .voice-panel,
  .interaction-module,
  .interaction-results-panel,
  .interaction-summary-panel,
  .interaction-card,
  .interaction-config-panel,
  .interaction-advanced-panel,
  .interaction-audit-panel,
  .interaction-recognition-panel,
  .interaction-source-detail,
  .interaction-list-preview,
  .deprescripcion-module,
  .deprescripcion-tool-panel,
  .deprescripcion-input-panel,
  .deprescripcion-card,
  .deprescripcion-details,
  .medication-input-panel,
  .medication-preview-panel,
  .table-field,
  .acb-panel,
  .ipa-panel,
  .bp-panel,
  .frail-panel,
  .chronic-condition-panel,
  .telepharmacy-module,
  .telepharmacy-row-card,
  .telepharmacy-suggestion-card,
  .telepharmacy-summary-dialog-shell
) {
  border-color: var(--line) !important;
  background: linear-gradient(145deg, #0d2536 0%, #0a1e2e 100%) !important;
  color: var(--ink) !important;
  box-shadow: var(--shadow);
}

html[data-theme="dark"] :where(.module-selection-heading, .welcome-hero) {
  border-color: #1b7d80 !important;
  background: linear-gradient(125deg, #08253a 0%, #075064 60%, #08756e 100%) !important;
}

html[data-theme="dark"] :where(.module-tabs, .sidebar, .toolbar, .panel-header, .section-heading) {
  border-color: var(--line) !important;
  background: #091d2d !important;
  color: var(--ink) !important;
}

html[data-theme="dark"] :where(
  button:not([class]):not(:disabled),
  button.secondary,
  button.secondary-action,
  button.link-action,
  .logout-button,
  .qf-dashboard-refresh,
  .main-menu-button,
  .secondary-action,
  .button-link,
  .table-action,
  .tab-button:not(.active)
) {
  border-color: var(--line-strong) !important;
  background: #102b3d !important;
  color: #cce5f3 !important;
}

html[data-theme="dark"] #validateBtn {
  border-color: #4baee8 !important;
  background: #0d5b91 !important;
  color: #ffffff !important;
}

html[data-theme="dark"] :where(button:hover, .main-menu-button:hover, .button-link:hover) {
  border-color: #4f91b5 !important;
}

html[data-theme="dark"] :where(.tab-button.active, button.active) {
  border-color: #4baee8 !important;
  background: #0d5b91 !important;
  color: #ffffff !important;
}

html[data-theme="dark"] :where(.check-grid, .radio-grid, .frequency-grid, fieldset) {
  border-color: var(--line) !important;
  background: rgba(8, 28, 43, 0.5) !important;
}

html[data-theme="dark"] :where(.check-grid label, .radio-grid label, .frequency-grid label, .settings-check) {
  border-color: var(--line) !important;
  background: #0c2435 !important;
  color: var(--ink) !important;
}

html[data-theme="dark"] :where(.check-grid label:has(input:checked), .radio-grid label:has(input:checked)) {
  border-color: #35bfa9 !important;
  background: #123b3a !important;
}

html[data-theme="dark"] :where(.table-wrap, .table-scroll, .deprescripcion-table-scroll) {
  border-color: var(--line) !important;
  background: #081c2b !important;
}

html[data-theme="dark"] table {
  color: var(--ink);
}

html[data-theme="dark"] :where(th, thead td) {
  border-color: var(--line) !important;
  background: #102d42 !important;
  color: #dff1f7 !important;
}

html[data-theme="dark"] td {
  border-color: var(--line) !important;
  background-color: #0b2132;
}

html[data-theme="dark"] tbody tr:nth-child(even) td {
  background-color: #0d2739;
}

html[data-theme="dark"] tbody tr:hover td {
  background-color: #12344a !important;
}

html[data-theme="dark"] :where(.clinical-spellcheck-backdrop, pre, code, .interaction-audit-pre, .medication-ai-panel pre) {
  border-color: var(--line) !important;
  background: #061725 !important;
  color: #dcecf2 !important;
}

html[data-theme="dark"] :where(.alerts-panel.warn, .interaction-alert, .status-yellow) {
  border-color: #8c7134 !important;
  background: #3a311d !important;
  color: #f4d98a !important;
}

html[data-theme="dark"] :where(.alerts-panel.error, .alert-notification, .status-red, [data-tone="error"]) {
  border-color: #874653 !important;
  background: #3b2028 !important;
  color: #ffb5bc !important;
}

html[data-theme="dark"] :where(.status-green, [data-tone="success"]) {
  border-color: #2b7663 !important;
  background: #15372f !important;
  color: #8ce6ca !important;
}

html[data-theme="dark"] :where(.status-blue, [data-tone="info"]) {
  border-color: #376b91 !important;
  background: #172f48 !important;
  color: #a9d1ff !important;
}

html[data-theme="dark"] :where(dialog, .modal-panel) {
  border-color: var(--line) !important;
  background: #0b2132 !important;
  color: var(--ink) !important;
}

html[data-theme="dark"] :where(dialog::backdrop, .modal-backdrop) {
  background: rgba(0, 7, 12, 0.78) !important;
}

html[data-theme="dark"] img.app-logo,
html[data-theme="dark"] img.brand-logo,
html[data-theme="dark"] img.health-logo {
  border-color: rgba(255, 255, 255, 0.22) !important;
  background: #071725 !important;
}

html[data-theme="dark"] ::selection {
  background: #176f75;
  color: #ffffff;
}

@media (max-width: 720px) {
  .theme-toggle {
    width: 100%;
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  body,
  input,
  select,
  textarea,
  .module-card,
  .settings-panel,
  .form-section {
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
  }
}
