/* SesionaDesk dark mode is a chromatic layer only: no geometry or content changes. */
:root {
  --sd-dark-canvas: #071521;
  --sd-dark-surface: #0d2233;
  --sd-dark-surface-soft: #102a3d;
  --sd-dark-elevated: #14364c;
  --sd-dark-line: #29475b;
  --sd-dark-text: #f1f7fa;
  --sd-dark-muted: #a9bfcc;
  --sd-dark-blue: #0d5b8f;
  --sd-dark-teal: #26c6b8;
}

.theme-selector {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 42px;
  padding: 3px;
  border: 1px solid #cddce6;
  border-radius: 12px;
  background: #f4f8fa;
  white-space: nowrap;
}
.theme-selector button {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #60788a;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.theme-selector button.is-active,
.theme-selector button[aria-pressed="true"] {
  background: #073f78;
  color: #fff;
  box-shadow: 0 2px 7px rgba(7, 63, 120, .18);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --cream: var(--sd-dark-canvas);
  --header-cream: var(--sd-dark-surface);
  --paper: var(--sd-dark-surface);
  --ink: var(--sd-dark-text);
  --muted: var(--sd-dark-muted);
  --line: var(--sd-dark-line);
  --teal-700: #63ddd2;
  --teal-600: #35cdbf;
  --teal-500: #26c6b8;
  --teal-100: #164a4d;
  --teal-50: #102f38;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

html[data-theme="dark"] body,
html[data-theme="dark"] .page,
html[data-theme="dark"] .workspace,
html[data-theme="dark"] #main,
html[data-theme="dark"] .view,
html[data-theme="dark"] .patient-portal-main,
html[data-theme="dark"] .patient-page-shell {
  background-color: var(--sd-dark-canvas);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .topbar-enhanced,
html[data-theme="dark"] .patient-topbar,
html[data-theme="dark"] .calendar-toolbar,
html[data-theme="dark"] .tabs,
html[data-theme="dark"] .tab-list {
  background-color: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .sidebar-brand,
html[data-theme="dark"] .sidebar-profile-stack {
  background-color: #0b3f69;
  color: #eaf4f8;
}
html[data-theme="dark"] .sidebar-brand { border-color: var(--sd-dark-line); }
html[data-theme="dark"] .sidebar .nav-item { color: #c6dae4; }
html[data-theme="dark"] .sidebar .nav-item:hover,
html[data-theme="dark"] .sidebar .nav-item.active { color: #fff; background-color: rgba(255, 255, 255, .11); }
html[data-theme="dark"] :where(
  .card, .panel, .ui-panel, .content-card, .summary-card, .stat-card,
  .dashboard-card, .patient-card, .agenda-card, .calendar-shell,
  .calendar-grid, .calendar-legend, .review-card, .management-card,
  .settings-card, .profile-card, .metric-card, .resource-card, .task-card,
  .session-card, .session-editor-card, .clinical-card, .history-card,
  .portal-card, .patient-portal-card, .patient-home-card, .table-shell,
  .modal-card, .modal-body, .modal-footer, .popover, .topbar-popover,
  .patient-notifications-popover, .dropdown-menu, .profile-menu
) {
  background-color: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .2);
}
html[data-theme="dark"] :where(
  h1, h2, h3, h4, h5, h6, legend, label, strong,
  .title, .card-title, .section-title, .topbar-context h1,
  .patient-topbar-profile strong, .patient-notifications-popover h2
) { color: var(--sd-dark-text); }
html[data-theme="dark"] :where(
  p, small, .muted, .subtitle, .description, .helper, .hint,
  .meta, .eyebrow, .topbar-context-path, .patient-topbar-profile small
) { color: var(--sd-dark-muted); }
html[data-theme="dark"] :where(input, textarea, select, .input, .select, .search-input, .topbar-search-shell) {
  background-color: #0a1c2a;
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] :where(input, textarea)::placeholder { color: #7893a3; }
html[data-theme="dark"] :where(table, th, td, tr, .table-row, .list-row, .divider) { border-color: var(--sd-dark-line); }
html[data-theme="dark"] :where(th, .table-header) { background-color: var(--sd-dark-surface-soft); color: #d9e8ef; }
html[data-theme="dark"] :where(td, .table-row, .list-row) { background-color: var(--sd-dark-surface); color: var(--sd-dark-text); }
html[data-theme="dark"] :where(.secondary-button, .ghost-button, .button-secondary, .icon-button, .topbar-tool) {
  background-color: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] :where(.primary-button, .button-primary, button.primary, .cta-button) {
  background-color: var(--sd-dark-blue);
  color: #fff;
}

html[data-theme="dark"] .patient-briefing-button {
  border-color: #327f86;
  background: linear-gradient(135deg, #123d43, #15354d);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .patient-briefing-result { color: var(--sd-dark-text); }
html[data-theme="dark"] .patient-briefing-result section {
  border-color: var(--sd-dark-line);
  background: var(--sd-dark-surface);
}
html[data-theme="dark"] .patient-briefing-result .patient-briefing-focus {
  border-color: #327f86;
  background: #11363b;
}
html[data-theme="dark"] .patient-briefing-result aside { background: #493517; }
html[data-theme="dark"] a { color: #77c8f5; }
html[data-theme="dark"] .theme-selector { background: #091c2a; border-color: var(--sd-dark-line); }
html[data-theme="dark"] .theme-selector button { color: var(--sd-dark-muted); }
html[data-theme="dark"] .theme-selector button.is-active,
html[data-theme="dark"] .theme-selector button[aria-pressed="true"] { background: var(--sd-dark-blue); color: #fff; }

/* Keep existing semantic meaning while making status surfaces legible. */
html[data-theme="dark"] :where(.is-success, .status-success, .approved, .paid, .alert-success) { background-color: #103d38; border-color: #247c70; color: #a9eee5; }
html[data-theme="dark"] :where(.is-warning, .status-warning, .pending, .alert-warning) { background-color: #493517; border-color: #8b6729; color: #ffe0a1; }
html[data-theme="dark"] :where(.is-danger, .status-danger, .rejected, .alert-danger, .error) { background-color: #4a2428; border-color: #98434b; color: #ffc4c9; }
html[data-theme="dark"] :where(.is-info, .status-info, .alert-info) { background-color: #123b54; border-color: #2f7194; color: #b9e5fb; }

/* Calendar: retain structure, event colors and current-time semantics. */
html[data-theme="dark"] :where(.calendar-grid, .calendar-day, .calendar-time, .calendar-cell, .week-grid, .day-grid) {
  background-color: var(--sd-dark-surface);
  border-color: #355164;
  color: var(--sd-dark-text);
}
html[data-theme="dark"] :where(.calendar-day.is-today, .calendar-cell.is-today) { background-color: #102f38; }

html[data-theme="dark"] .invitation-email,
html[data-theme="dark"] .invitation-form-dashboard .invitation-email,
html[data-theme="dark"] .invitation-guidance article,
html[data-theme="dark"] .invitation-summary,
html[data-theme="dark"] .invitation-summary > div,
html[data-theme="dark"] .invitation-hint,
html[data-theme="dark"] .review-pagination,
html[data-theme="dark"] .professional-note-item {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .invitation-email input { background: transparent; color: var(--sd-dark-text); }
html[data-theme="dark"] .date-card,
html[data-theme="dark"] .privacy-note,
html[data-theme="dark"] .agenda-configuration-guidance {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .agenda-configuration-guidance-copy :where(strong, p),
html[data-theme="dark"] .date-card :where(strong, span, time),
html[data-theme="dark"] .privacy-note strong { color: inherit; }

html[data-theme="dark"] .timeline-axis {
  background: #0a1c2a;
  border-color: #355164;
}
html[data-theme="dark"] .timeline-axis-mark { color: var(--sd-dark-muted); }
html[data-theme="dark"] .timeline-axis-mark.half { border-color: #29475b; }
html[data-theme="dark"] .timeline-day-column,
html[data-theme="dark"] .timeline-day-column.today {
  border-color: #355164;
  background-color: var(--sd-dark-surface);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 35px, #29475b 35px, #29475b 36px, transparent 36px, transparent 71px, #355164 71px, #355164 72px);
}
html[data-theme="dark"] .timeline-day-column.today { background-color: #102f38; }

html[data-theme="dark"] .task-library-index a,
html[data-theme="dark"] .therapeutic-resource-index a,
html[data-theme="dark"] .builder-template-card {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .builder-template-card :where(h4, p),
html[data-theme="dark"] .task-library-index a strong,
html[data-theme="dark"] .therapeutic-resource-index a strong { color: inherit; }

html[data-theme="dark"] #view-clinical-tasks .task-library-index a > span,
html[data-theme="dark"] #view-clinical-tasks .builder-template-icon {
  background: #153b4d;
  border: 1px solid #2d6175;
  color: #54d4cc;
  box-shadow: inset 0 0 0 1px rgba(84, 212, 204, .05);
}
html[data-theme="dark"] #view-clinical-tasks .builder-field-chips span {
  background: #18384a;
  border: 1px solid #31566b;
  color: #b9d9e6;
}

/* Management uses dense nested surfaces, tables and semantic finance states. */
html[data-theme="dark"] #view-management .management-period,
html[data-theme="dark"] #view-management .management-period-navigation > .management-period-button,
html[data-theme="dark"] #view-management .management-tabs,
html[data-theme="dark"] #view-management .management-section {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-management .management-period-navigation > .management-period-button:hover:not(:disabled),
html[data-theme="dark"] #view-management .management-tabs button:hover {
  background: var(--sd-dark-surface-soft);
  border-color: #3a6077;
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-management .management-period-navigation > .management-period-button:disabled {
  background: #172b39;
  color: #7892a2;
}
html[data-theme="dark"] #view-management .management-tabs button {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-management .management-tabs button.active {
  background: var(--sd-dark-blue);
  color: #fff;
}
html[data-theme="dark"] #view-management .management-tabs .management-arca-link { color: #c8dce5; }
html[data-theme="dark"] #view-management .management-tabs .management-arca-link:hover { background: #164158; color: #54d7d1; }
html[data-theme="dark"] #view-management .management-tabs .management-arca-link.active { background: #126da3; color: #fff; }
html[data-theme="dark"] #view-management .management-section > header :where(h3, small),
html[data-theme="dark"] #view-management .finance-operation-heading :where(h4, p, span) {
  color: inherit;
}
html[data-theme="dark"] #view-management .management-kpi,
html[data-theme="dark"] #view-management .management-card,
html[data-theme="dark"] #view-management .management-mini-stat-list {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-management .management-kpi :where(small, strong, p),
html[data-theme="dark"] #view-management .management-card :where(h4, p, strong),
html[data-theme="dark"] #view-management .management-mini-stats > header :where(h4, p) {
  color: inherit;
}
html[data-theme="dark"] #view-management .management-kpi small,
html[data-theme="dark"] #view-management .management-kpi p,
html[data-theme="dark"] #view-management .management-card > header p,
html[data-theme="dark"] #view-management .management-mini-stats > header p {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-management .management-kpi > span {
  background: #173b50;
  color: #80c9ef;
}
html[data-theme="dark"] #view-management .management-kpi.blue > span {
  background: #123f40;
  color: #70e0d5;
}
html[data-theme="dark"] #view-management .management-kpi.alert > span {
  background: #4a282b;
  color: #ffaaa1;
}
html[data-theme="dark"] #view-management .management-bars i,
html[data-theme="dark"] #view-management .management-demand > div,
html[data-theme="dark"] #view-management .management-demand span {
  background: #173548;
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-management .management-bars > div > span,
html[data-theme="dark"] #view-management .management-demand :where(small, p),
html[data-theme="dark"] #view-management .management-month-bars :where(span, small) {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-management .management-attention-list > button,
html[data-theme="dark"] #view-management .management-invitation-row {
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-management .management-attention-list > button:hover {
  background: var(--sd-dark-elevated);
}
html[data-theme="dark"] #view-management :where(.finance-table-wrap, .management-adherence-table-wrap) {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-management :where(.finance-table, .management-adherence-table) th {
  background: #173548;
  color: #d8e8ef;
}
html[data-theme="dark"] #view-management :where(.finance-table, .management-adherence-table) td {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-management .finance-table tbody tr:hover td,
html[data-theme="dark"] #view-management .management-adherence-table tr:hover td {
  background: var(--sd-dark-elevated);
}
html[data-theme="dark"] #view-management .management-adherence-table tr.needs-attention td {
  background: #342b1d;
}
html[data-theme="dark"] #view-management .finance-toolbar :where(input, select) {
  background: #0a1c2a;
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-management .management-disclaimer {
  background: #173548;
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-management .finance-status,
html[data-theme="dark"] #view-management .management-trend {
  background: #294052;
  color: #d7e7ee;
}
html[data-theme="dark"] #view-management :where(.finance-status.paid, .management-trend.up) {
  background: #103d38;
  color: #a9eee5;
}
html[data-theme="dark"] #view-management :where(.finance-status.pending, .finance-status.overdue, .finance-status.rejected, .management-trend.down) {
  background: #4a2428;
  color: #ffc4c9;
}
html[data-theme="dark"] #view-management .finance-status.under_review {
  background: #123b54;
  color: #b9e5fb;
}
html[data-theme="dark"] #view-management :where(.finance-status.exempt, .finance-status.no_fee) {
  background: #342d49;
  color: #ddd0ff;
}

/* Shared section icon language: dark tiles, while preserving semantic tones. */
html[data-theme="dark"] :where(
  #view-dashboard .stat-icon,
  #view-dashboard .ui-empty-state__icon,
  #view-dashboard .invitation-guidance article > span,
  #view-questionnaires .builder-template-icon,
  #view-patient-detail .clinical-icon,
  #view-patient-detail .patient-adherence-clinical-note > span,
  #view-patient-detail .patient-tracking-tabs button > span,
  #view-patient-detail .patient-attachment-empty-icon
) {
  background: #153b4d;
  border: 1px solid #2d6175;
  color: #54d4cc;
  box-shadow: inset 0 0 0 1px rgba(84, 212, 204, .05);
}
html[data-theme="dark"] #view-dashboard .review-icon {
  background: #493717;
  border: 1px solid #806127;
  color: #ffd98c;
}
html[data-theme="dark"] #view-dashboard .review-icon.coral,
html[data-theme="dark"] #view-dashboard .stat-card.alert .stat-icon,
html[data-theme="dark"] #view-patient-detail .clinical-risk-overview .clinical-icon {
  background: #4a2428;
  border-color: #874048;
  color: #ffaaa1;
}
html[data-theme="dark"] #view-dashboard .stat-card.warm .stat-icon {
  background: #493717;
  border-color: #806127;
  color: #ffd98c;
}
html[data-theme="dark"] #view-dashboard .stat-card.blue .stat-icon {
  background: #153b4d;
  border-color: #2d6175;
  color: #80c9ef;
}
html[data-theme="dark"] #view-patient-detail .patient-detail-header .patient-avatar {
  background: #173b50;
  border-color: #315e75;
  color: #9bdcf4;
}
html[data-theme="dark"] #view-patient-detail .patient-header-actions > summary > span {
  background: #173548;
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-patient-detail .patient-attachment-empty-formats b {
  background: #173548;
  border-color: #31566b;
  color: #b9d9e6;
}
html[data-theme="dark"] #view-dashboard .stat-card .stat-icon,
html[data-theme="dark"] #view-dashboard [data-dashboard-agenda] .dashboard-agenda-empty .ui-empty-state__icon,
html[data-theme="dark"] #view-dashboard .invitation-guidance article > span,
html[data-theme="dark"] #view-questionnaires .metric-instrument-card .builder-template-icon,
html[data-theme="dark"] #view-questionnaires .builder-template-card .builder-template-icon {
  background: #153b4d;
  border: 1px solid #2d6175;
  color: #54d4cc;
}
html[data-theme="dark"] #view-dashboard .stat-card.warm .stat-icon {
  background: #493717;
  border-color: #806127;
  color: #ffd98c;
}
html[data-theme="dark"] #view-dashboard .stat-card.blue .stat-icon {
  background: #153b4d;
  border-color: #2d6175;
  color: #80c9ef;
}
html[data-theme="dark"] #view-patient-detail .patient-alt-attention-item > i {
  background: #493717;
  border: 1px solid #806127;
  color: #ffd98c;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-clinical-note > span,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-tracking-tabs button > span {
  background: #153b4d;
  border-color: #2d6175;
  color: #54d4cc;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-tracking-tabs button.is-active > span {
  background: #164d5c;
  border-color: #3b8a91;
  color: #8af0e7;
}
html[data-theme="dark"] #view-questionnaires .questionnaire-library-search label {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
  box-shadow: 0 7px 20px rgba(0, 0, 0, .18);
}
html[data-theme="dark"] #view-questionnaires .questionnaire-library-search label > span {
  color: #54d4cc;
}
html[data-theme="dark"] #view-questionnaires .questionnaire-library-search :where(input, small) {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-patient-detail .ui-action-menu > div,
html[data-theme="dark"] #view-patient-detail .clinical-record-actions-menu > div {
  background: var(--sd-dark-elevated);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail :where(.ui-action-menu, .clinical-record-actions-menu) > div button {
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail :where(.ui-action-menu, .clinical-record-actions-menu) > div button:hover {
  background: #1a455c;
  color: #8af0e7;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="clinical"] .clinical-info-header {
  background: linear-gradient(135deg, var(--sd-dark-surface-soft), var(--sd-dark-surface));
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="clinical"] .clinical-info-header > div:first-child :where(h3, p) {
  color: inherit;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="clinical"] .clinical-info-header > div:first-child p,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="clinical"] .clinical-header-meta small {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="clinical"] .clinical-header-meta {
  background: #173548;
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="clinical"] .clinical-header-meta strong {
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="clinical"] .clinical-history-button,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="clinical"] .clinical-record-actions-menu[open] > summary {
  background: #153b4d;
  border-color: #2d6175;
  color: #b9e5fb;
}
html[data-theme="dark"] #view-patient-detail .clinical-risk-overview {
  background: #321f25;
  border-color: #713a43;
  color: #ffd5d8;
}
html[data-theme="dark"] #view-patient-detail .clinical-risk-overview :where(small, strong) {
  color: inherit;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="sessions"] .patient-session-grid-placeholder {
  background: rgba(16, 42, 61, .72);
  border-color: #35566a;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="sessions"] :where(.session-placeholder-date, .patient-session-grid-placeholder small) {
  border-color: #35566a;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="sessions"] .session-placeholder-lines i {
  background: #29475b;
}
html[data-theme="dark"] #view-patient-detail .patient-notes-panel,
html[data-theme="dark"] #view-patient-detail .patient-note-history-item {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail .patient-note-history-item :where(h4, p, small, time) {
  color: inherit;
}
html[data-theme="dark"] #view-patient-detail .patient-attachments-footer {
  background: #173548;
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-patient-detail .patient-attachments-footer strong {
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail .patient-consent-card,
html[data-theme="dark"] #view-patient-detail .patient-data-use-card {
  background: linear-gradient(110deg, #152f40, var(--sd-dark-surface) 46%);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail .patient-consent-card.pending,
html[data-theme="dark"] #view-patient-detail .patient-data-use-card.pending {
  background: linear-gradient(110deg, #382d1d, var(--sd-dark-surface) 46%);
  border-color: #70552a;
}
html[data-theme="dark"] #view-patient-detail .patient-consent-card.signed,
html[data-theme="dark"] #view-patient-detail .patient-data-use-card.accepted {
  background: linear-gradient(110deg, #123b37, var(--sd-dark-surface) 46%);
  border-color: #287167;
}
html[data-theme="dark"] #view-patient-detail :where(.patient-consent-card, .patient-data-use-card) :where(strong, dd) {
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail :where(.patient-consent-card, .patient-data-use-card) :where(small, dt) {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-patient-detail .patient-incorporation-records {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-patient-detail .patient-incorporation-records-header {
  border-color: var(--sd-dark-line);
}

/* Patient directory: preserve hierarchy and patient color semantics without light tiles. */
html[data-theme="dark"] #view-patients .patient-directory-section > header {
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-patients .patient-directory-section > header h3 {
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patients .patient-directory-section > header > strong {
  background: #153b4d;
  border: 1px solid #2d6175;
  color: #54d4cc;
}
html[data-theme="dark"] #view-patients .patient-card {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patients .patient-card:hover {
  background: var(--sd-dark-surface-soft);
  border-color: #3b6a80;
  box-shadow: 0 13px 32px rgba(0, 0, 0, .24);
}
html[data-theme="dark"] #view-patients .patient-card .patient-avatar {
  background: #16453f;
  border: 1px solid #2b746b;
  color: #8af0e7;
}
html[data-theme="dark"] #view-patients .patient-card .patient-avatar.blue {
  background: #153b4d;
  border-color: #2d6175;
  color: #80c9ef;
}
html[data-theme="dark"] #view-patients .patient-card .patient-avatar.coral {
  background: #4a2428;
  border-color: #874048;
  color: #ffaaa1;
}
html[data-theme="dark"] #view-patients .patient-card .patient-avatar.gold {
  background: #493717;
  border-color: #806127;
  color: #ffd98c;
}
html[data-theme="dark"] #view-patients .patient-card .card-data {
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-patients .patient-card .card-footer .tag {
  background: #153b4d;
  border-color: #2d6175;
  color: #b9e5fb;
}
html[data-theme="dark"] #view-patients .patient-epicrisis-section {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-patients .patient-epicrisis-section > header > strong,
html[data-theme="dark"] #view-patients .patient-card.patient-card-epicrisis .card-footer .tag {
  background: #263d4c;
  border-color: #466273;
  color: #c5d4db;
}
html[data-theme="dark"] #view-patients .patient-card.patient-card-epicrisis {
  background: linear-gradient(145deg, #102637, #0d2233);
  border-color: #355164;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .18);
}
html[data-theme="dark"] #view-patients .patient-card .status-pin.closed {
  background: #829aa6;
  box-shadow: 0 0 0 3px #223b49;
}
html[data-theme="dark"] #view-patients .patient-directory-empty {
  background: rgba(16, 42, 61, .7);
  border-color: #3a5a6d;
  color: var(--sd-dark-muted);
}

/* Therapeutic resources keep their clinical category accents on dark surfaces. */
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-scope-notice {
  background: #2d2719;
  border-color: #6d592d;
  color: #f0dca9;
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-scope-notice :where(strong, p, li) {
  color: inherit;
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-section {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  border-top-color: var(--resource-section-accent);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-section-header {
  background: linear-gradient(110deg, var(--sd-dark-surface-soft), var(--sd-dark-surface));
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-section-header :where(h3, p),
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-section-number {
  color: inherit;
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-section-header p {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-section-icon {
  background: color-mix(in srgb, var(--resource-section-accent) 20%, var(--sd-dark-surface));
  border-color: color-mix(in srgb, var(--resource-section-accent) 55%, var(--sd-dark-line));
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-count {
  background: #29475b;
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-grid {
  background: var(--sd-dark-surface);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-card,
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-card.is-high-risk {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  border-top-color: var(--therapy-color);
  color: var(--sd-dark-text);
  box-shadow: 0 7px 20px rgba(0, 0, 0, .18);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-card-icon,
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-category {
  background: color-mix(in srgb, var(--therapy-color) 20%, var(--sd-dark-surface));
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-card.is-high-risk .therapeutic-resource-card-icon {
  background: #4a2725;
  color: #ffaaa1;
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-card :where(h4, p) {
  color: inherit;
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-card > p {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-details {
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-details > div {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-details :where(dt, dd) {
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-details dt {
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-card-meta {
  border-color: var(--sd-dark-line);
}
html[data-theme="dark"] #view-therapeutic-resources .therapeutic-resource-card-meta span {
  background: #29475b;
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-therapeutic-resources .empty-state {
  background: var(--sd-dark-surface-soft);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-therapeutic-resources .empty-state :where(h3, p) {
  color: inherit;
}

html[data-theme="dark"] .readonly-patient-field,
html[data-theme="dark"] .session-clinical-actions {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .readonly-patient-field :where(strong, small),
html[data-theme="dark"] .session-clinical-actions :where(h4, p, small) { color: inherit; }

html[data-theme="dark"] .patient-detail-layout-alt {
  --patient-alt-surface: var(--sd-dark-surface);
  --patient-alt-line: var(--sd-dark-line);
  --patient-alt-muted: var(--sd-dark-muted);
}
html[data-theme="dark"] .patient-detail-layout-alt .patient-detail-header,
html[data-theme="dark"] .patient-alt-tabs,
html[data-theme="dark"] .patient-alt-widget,
html[data-theme="dark"] .patient-alt-widget > header,
html[data-theme="dark"] .patient-portal-header-control,
html[data-theme="dark"] .patient-header-actions > summary,
html[data-theme="dark"] .next-session-embedded-note {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .patient-alt-tab { color: var(--sd-dark-muted); }
html[data-theme="dark"] .patient-alt-tab:hover { background: var(--sd-dark-surface-soft); color: var(--sd-dark-text); }
html[data-theme="dark"] .patient-alt-tab.is-active { background: var(--sd-dark-blue); color: #fff; }
html[data-theme="dark"] .patient-alt-widget > header :where(span, h3),
html[data-theme="dark"] .patient-detail-layout-alt .patient-detail-header :where(strong, small),
html[data-theme="dark"] .next-session-embedded-note :where(strong, small, p) { color: inherit; }
html[data-theme="dark"] .patient-alt-progress-list :where(strong, small, b),
html[data-theme="dark"] .patient-alt-attention-item :where(strong, small, b),
html[data-theme="dark"] .patient-alt-timeline :where(strong, small, time) { color: var(--sd-dark-text); }
html[data-theme="dark"] .patient-alt-progress-list > button > i { background: #29475b; }
html[data-theme="dark"] .patient-alt-attention-item,
html[data-theme="dark"] .patient-alt-timeline > button { border-color: var(--sd-dark-line); }
html[data-theme="dark"] .patient-alt-attention-item:hover,
html[data-theme="dark"] .patient-alt-timeline > button:hover,
html[data-theme="dark"] .patient-alt-progress-list > button:hover { background: var(--sd-dark-surface-soft); }

html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-collapsible-content.patient-quant-tracking-content,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-clinical-note,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-tracking-tabs,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-tracking-tab-panels,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-quant-subsection,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-quant-subsection > .patient-quant-subsection-header,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-quant-subsection[open] > .patient-quant-subsection-header,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-quant-subsection-content,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-quant-summary,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-quant-summary article {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-tracking-tabs button { color: var(--sd-dark-muted); }
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-tracking-tabs button:hover { background: var(--sd-dark-surface-soft); color: var(--sd-dark-text); }
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] :where(h2, h3, h4, strong, p, small) { color: inherit; }

/* Patient portal surfaces that use literal light colors in their original stylesheet. */
html[data-theme="dark"] :where(
  .patient-home-hero, .patient-agenda-shell, .patient-agenda-list,
  .patient-assignment-card, .patient-tool-card, .patient-document-card,
  .patient-payment-card, .patient-professional-card, .patient-note-card,
  .patient-history-card, .patient-tabs, .patient-modal
) { background-color: var(--sd-dark-surface); border-color: var(--sd-dark-line); color: var(--sd-dark-text); }
html[data-theme="dark"] .patient-portal-heading time,
html[data-theme="dark"] .patient-professional-preview,
html[data-theme="dark"] .patient-portal-card > header,
html[data-theme="dark"] .patient-onboarding-card,
html[data-theme="dark"] .patient-onboarding-card > header,
html[data-theme="dark"] .patient-onboarding-card article,
html[data-theme="dark"] .patient-private-banner,
html[data-theme="dark"] .patient-action-list a,
html[data-theme="dark"] .patient-session-list > div,
html[data-theme="dark"] .patient-notifications-popover > header {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .patient-onboarding-progress { background: #29475b; }
html[data-theme="dark"] .patient-onboarding-steps a {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .patient-onboarding-steps :where(strong, small) { color: inherit; }
html[data-theme="dark"] .patient-activation-alert,
html[data-theme="dark"] .patient-locked-note {
  background: #493517;
  border-color: #8b6729;
  color: #ffe0a1;
}
html[data-theme="dark"] .patient-activation-alert :where(strong, small),
html[data-theme="dark"] .patient-locked-note :where(strong, small) { color: inherit; }
html[data-theme="dark"] .patient-notifications > summary,
html[data-theme="dark"] .patient-private-banner .secondary-button,
html[data-theme="dark"] .patient-professional-preview .secondary-button {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}

/* Settings hub: keep the original information architecture with dark surfaces. */
html[data-theme="dark"] #view-settings .consulting-settings-card,
html[data-theme="dark"] #view-settings .consulting-settings-header,
html[data-theme="dark"] #view-settings .consulting-settings-list {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-settings .consulting-settings-header {
  background: linear-gradient(135deg, var(--sd-dark-surface-soft), var(--sd-dark-surface));
}
html[data-theme="dark"] #view-settings .consulting-settings-item {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-settings .consulting-settings-item:hover,
html[data-theme="dark"] #view-settings .consulting-settings-item.is-guidance-target {
  background: var(--sd-dark-elevated);
  border-color: #3d7187;
}
html[data-theme="dark"] #view-settings .consulting-settings-item-icon,
html[data-theme="dark"] #view-settings .settings-card-icon {
  background: #153e50;
  border-color: #2d6474;
  color: var(--sd-dark-teal);
}
html[data-theme="dark"] #view-settings .consulting-settings-item .consulting-settings-action {
  background: #153348;
  border-color: #3a6075;
  color: var(--sd-dark-text);
  box-shadow: none;
}
html[data-theme="dark"] #view-settings .consulting-settings-item .consulting-settings-action::after { color: var(--sd-dark-teal); }
html[data-theme="dark"] #view-settings .consulting-settings-item .consulting-settings-action:hover {
  background: var(--sd-dark-blue);
  border-color: #278bc2;
  color: #fff;
}
html[data-theme="dark"] #view-settings :where(
  .consulting-settings-header, .consulting-settings-item, .settings-card
) :where(h3, h4, p, strong, small) { color: inherit; }
html[data-theme="dark"] #view-settings :where(.consulting-settings-header, .consulting-settings-item, .settings-card) p { color: var(--sd-dark-muted); }
html[data-theme="dark"] #view-settings .settings-section-header { border-color: var(--sd-dark-line); }

/* Workflow-specific surfaces whose legacy rules still use literal light colors. */
html[data-theme="dark"] .receipt-review-summary {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .receipt-review-summary header :where(h3, p),
html[data-theme="dark"] .receipt-review-summary-stats span { color: inherit; }
html[data-theme="dark"] .receipt-review-summary-stats { border-color: var(--sd-dark-line); }
html[data-theme="dark"] .receipt-review-summary-stats span {
  background: #18384b;
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] .receipt-review-summary-stats span.is-high { background: #123f3c; color: #8ce7dc; }
html[data-theme="dark"] .receipt-review-summary-stats span.is-medium { background: #493817; color: #ffdda0; }
html[data-theme="dark"] .receipt-review-summary-stats span.is-low { background: #4b2928; color: #ffb0aa; }

html[data-theme="dark"] .modal-card .detail-stat,
html[data-theme="dark"] .session-agenda-summary > div,
html[data-theme="dark"] .session-agenda-clocks > div,
html[data-theme="dark"] .session-agenda-item {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .modal-card .detail-stat :where(small, strong),
html[data-theme="dark"] .session-agenda-summary :where(span, strong),
html[data-theme="dark"] .session-agenda-clocks :where(span, strong) { color: inherit; }
html[data-theme="dark"] .detail-section .meet-join-button {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .session-agenda-summary .is-under { background: #493817; color: #ffdda0; }
html[data-theme="dark"] .session-agenda-summary .is-over,
html[data-theme="dark"] .session-agenda-overrun { background: #4b2928; color: #ffb0aa; }
html[data-theme="dark"] .session-agenda-summary .is-complete { background: #123f3c; color: #8ce7dc; }

html[data-theme="dark"] .clinical-record-signature {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .clinical-record-signature :where(h4, p, small, label) { color: inherit; }
html[data-theme="dark"] .clinical-record-signature canvas {
  background: #eaf2f5;
  border-color: #7190a1;
}

html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="sessions"] .patient-session-grid-card {
  background: linear-gradient(155deg, var(--sd-dark-surface-soft), var(--sd-dark-surface));
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .18);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="sessions"] .patient-session-grid-card :where(strong, small, p, time),
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="sessions"] .patient-session-grid-card .session-row-main small { color: inherit; }
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="sessions"] .patient-session-grid-card .session-card-footer { border-color: var(--sd-dark-line); }
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt .clinical-task-list .task-response-row,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt .patient-task-row,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt .patient-questionnaire-assignment {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt :where(.patient-task-row, .patient-questionnaire-assignment) :where(strong, small, span) { color: inherit; }
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt :where(.patient-task-row, .patient-questionnaire-assignment):hover {
  background: var(--sd-dark-elevated);
  border-color: #3d657d;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="sessions"] .session-date-box {
  background: #18384b;
  color: #bfe1ef;
}

html[data-theme="dark"] #view-patient-clinical-tasks .patient-dbt-diary-assignment,
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-diary-usage article,
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-longitudinal-chart,
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-chart-canvas,
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-chart-empty {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-clinical-tasks .patient-dbt-diary-assignment {
  background: linear-gradient(135deg, var(--sd-dark-surface-soft), var(--sd-dark-surface));
}
html[data-theme="dark"] #view-patient-clinical-tasks :where(
  .patient-dbt-diary-assignment, .dbt-diary-usage article,
  .dbt-longitudinal-heading, .dbt-longitudinal-chart
) :where(h3, h4, strong, p, small, span) { color: inherit; }
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-longitudinal-heading { border-color: var(--sd-dark-line); }
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-longitudinal-heading > span,
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-longitudinal-chart > header > span {
  background: #18384b;
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-longitudinal-chart > header { border-color: var(--sd-dark-line); }
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-chart-grid { stroke: #29475b; }
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-chart-axis-line { stroke: #557286; }
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-chart-axis,
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-chart-date { fill: #a9bfcc; }
html[data-theme="dark"] #view-patient-clinical-tasks .dbt-chart-point { fill: var(--sd-dark-surface); }

html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-overview > section,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-general,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-dimension,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-metric-administration,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-longitudinal-section,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-longitudinal-item,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-longitudinal-detail,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .longitudinal-series-card,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-longitudinal-empty,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .dbt-longitudinal-chart,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .longitudinal-stat-grid article {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-overview,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-mood-monitoring-panel.patient-mood-monitoring-integrated {
  background: var(--sd-dark-surface) !important;
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-ring {
  background: conic-gradient(#0a9488 calc(var(--adherence) * 1%), #29475b 0) !important;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-ring::after {
  background: var(--sd-dark-surface-soft) !important;
  box-shadow: inset 0 0 0 1px var(--sd-dark-line);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-periods > div,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-comparison > header > span,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .dbt-longitudinal-chart > header > span {
  background: #18384b;
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-dimension > i {
  background: conic-gradient(#0a9488 calc(var(--dimension-rate) * 1%), #29475b 0) !important;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-dimension.is-empty > i { background: #29475b !important; }
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-dimension > i::after {
  background: var(--sd-dark-surface-soft) !important;
  box-shadow: inset 0 0 0 1px var(--sd-dark-line);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .patient-adherence-dimension-changes,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .dbt-longitudinal-chart > header,
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .longitudinal-response-table :where(th, td) { border-color: var(--sd-dark-line); }
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .longitudinal-response-table thead th {
  background: #18384b;
  color: var(--sd-dark-muted);
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] .sd-chart {
  --chart-ink: #d9e9ef;
  --chart-grid: #29475b;
}
html[data-theme="dark"] #view-patient-detail.patient-detail-layout-alt[data-alt-active-tab="tracking"] :where(
  .patient-adherence-overview, .patient-adherence-overview > section,
  .patient-metric-administration, .patient-longitudinal-section,
  .patient-longitudinal-item, .patient-longitudinal-detail,
  .longitudinal-series-card, .dbt-longitudinal-chart, .longitudinal-stat-grid article
) :where(h3, h4, h5, strong, p, small, span, b, td) { color: inherit; }

/* The standalone subscription route shares the account's visual preference. */
html[data-theme="dark"] body.billing-page { background: var(--sd-dark-canvas); color: var(--sd-dark-text); }
html[data-theme="dark"] .billing-top,
html[data-theme="dark"] .billing-card,
html[data-theme="dark"] .billing-plan-card,
html[data-theme="dark"] .billing-plan-management,
html[data-theme="dark"] .billing-method,
html[data-theme="dark"] .billing-payment-steps li,
html[data-theme="dark"] .billing-payment-empty,
html[data-theme="dark"] .referral-stats > div,
html[data-theme="dark"] .referral-history__list,
html[data-theme="dark"] .renewal-dialog,
html[data-theme="dark"] .renewal-dialog__summary {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .billing-plan-card--premium { border-color: #278bc2; }
html[data-theme="dark"] .billing-main :where(h1, h2, h3, strong, dd, td),
html[data-theme="dark"] .billing-top__in,
html[data-theme="dark"] .renewal-dialog :where(h2, strong) { color: var(--sd-dark-text); }
html[data-theme="dark"] .billing-main :where(p, dt, th, small, label),
html[data-theme="dark"] .renewal-dialog p { color: var(--sd-dark-muted); }
html[data-theme="dark"] .billing-summary div,
html[data-theme="dark"] .billing-table :where(th, td),
html[data-theme="dark"] .billing-progress span,
html[data-theme="dark"] .billing-plan-header,
html[data-theme="dark"] .billing-plan-features li,
html[data-theme="dark"] .billing-method-details div,
html[data-theme="dark"] .billing-payment-form,
html[data-theme="dark"] .referral-history__row { border-color: var(--sd-dark-line); }
html[data-theme="dark"] .billing-form :where(input, select, textarea) {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .billing-features span,
html[data-theme="dark"] .billing-plan-note,
html[data-theme="dark"] .billing-plan-action .billing-current-label,
html[data-theme="dark"] .billing-invoice-number,
html[data-theme="dark"] .billing-method-note,
html[data-theme="dark"] .referral-result {
  background: #18384b;
  border-color: var(--sd-dark-line);
  color: #bfe1ef;
}
html[data-theme="dark"] .billing-pill { background: #153e56; color: #a9dcf4; }
html[data-theme="dark"] .billing-pill--success,
html[data-theme="dark"] .billing-review-state,
html[data-theme="dark"] .referral-result--success { background: #123f3c; border-color: #286a64; color: #8ce7dc; }
html[data-theme="dark"] .billing-status,
html[data-theme="dark"] .billing-plan-action .billing-pending-label,
html[data-theme="dark"] .billing-payment-empty--warning { background: #493817; border-color: #725b2a; color: #ffdda0; }
html[data-theme="dark"] .renewal-dialog__notice { background: #123f3c; color: #8ce7dc; }
html[data-theme="dark"] .billing-top .secondary-button,
html[data-theme="dark"] .billing-logout { color: var(--sd-dark-text); }

/* Standalone professional settings pages share the account theme. */
html[data-theme="dark"] body.professional-settings-page {
  background: var(--sd-dark-canvas);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .settings-topbar {
  background: rgba(13, 34, 51, .97);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
  box-shadow: 0 3px 18px rgba(0, 0, 0, .22);
}
html[data-theme="dark"] .settings-topbar-context :where(span, strong) { color: inherit; }
html[data-theme="dark"] .settings-topbar-context span { color: var(--sd-dark-muted); }
html[data-theme="dark"] .settings-section-nav,
html[data-theme="dark"] .settings-editor,
html[data-theme="dark"] .settings-editor > form,
html[data-theme="dark"] .settings-editor > .settings-consent-list,
html[data-theme="dark"] .settings-editor > .settings-service-list,
html[data-theme="dark"] .settings-editor > .settings-service,
html[data-theme="dark"] .settings-editor > .settings-history-list {
  background: var(--sd-dark-surface);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .settings-section-nav a { color: var(--sd-dark-muted); }
html[data-theme="dark"] .settings-section-nav a:hover {
  background: var(--sd-dark-elevated);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .settings-section-nav span,
html[data-theme="dark"] .settings-section-icon {
  background: #153b4d;
  border: 1px solid #2d6175;
  color: #54d4cc;
}
html[data-theme="dark"] .settings-section-icon.gold {
  background: #493717;
  border-color: #806127;
  color: #ffd98c;
}
html[data-theme="dark"] .settings-section-icon:not(.turquoise):not(.blue):not(.gold) {
  background: #4a2428;
  border-color: #874048;
  color: #ffaaa1;
}
html[data-theme="dark"] .settings-section-header {
  background: linear-gradient(120deg, var(--sd-dark-surface-soft), var(--sd-dark-surface));
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .settings-section-header :where(h2, p, span) { color: inherit; }
html[data-theme="dark"] .settings-section-header p { color: var(--sd-dark-muted); }
html[data-theme="dark"] :where(.settings-consent-card, .settings-service-card, .settings-create-consent, .settings-create-service, .settings-history-list > .settings-service) {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] :where(.settings-consent-card, .settings-service-card, .settings-history-list > .settings-service) :where(h3, p, strong, summary, dd) { color: inherit; }
html[data-theme="dark"] :where(.settings-consent-card, .settings-service-card) :where(small, dt) { color: var(--sd-dark-muted); }
html[data-theme="dark"] .settings-service-card dl > div,
html[data-theme="dark"] .settings-document:not(.settings-consent-preview) {
  background: #18384b;
  border-color: var(--sd-dark-line);
  color: #c4d9e3;
}
html[data-theme="dark"] .settings-editor :where(input, select, textarea) {
  background: #0a1c2a;
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .settings-editor :where(label, legend) { color: var(--sd-dark-text); }
html[data-theme="dark"] .settings-form-footer,
html[data-theme="dark"] .settings-service-card form,
html[data-theme="dark"] .settings-inline-editor > form { border-color: var(--sd-dark-line); }

/* Fee update flow uses the same dark hierarchy as the settings editor. */
html[data-theme="dark"] :where(
  .fee-update-step, .fee-update-switch, .fee-update-choice,
  .fee-update-message-block, .fee-update-save-message,
  .fee-update-table, .fee-update-campaign, .fee-update-campaign-body,
  .fee-update-recipient-list article, .fee-update-empty
) {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line) !important;
  color: var(--sd-dark-text);
}
html[data-theme="dark"] :where(.fee-update-step, .fee-update-switch, .fee-update-choice, .fee-update-message-block, .fee-update-campaign, .fee-update-recipient-list article) :where(strong, b, h3, legend) { color: var(--sd-dark-text); }
html[data-theme="dark"] :where(.fee-update-step, .fee-update-switch, .fee-update-choice, .fee-update-message-block, .fee-update-campaign, .fee-update-recipient-list article) :where(p, small, span) { color: var(--sd-dark-muted); }
html[data-theme="dark"] .fee-update-step legend > span { background: #155b87; color: #fff; }
html[data-theme="dark"] :where(.fee-update-switch, .fee-update-choice, .fee-update-save-message):has(input:checked) {
  background: #123f3c;
  border-color: #34796f !important;
}
html[data-theme="dark"] :where(.fee-update-switch, .fee-update-choice, .fee-update-save-message):hover { background: var(--sd-dark-elevated); }
html[data-theme="dark"] .fee-update-choice:has(input:disabled) { background: #142633; }
html[data-theme="dark"] .fee-update-table > div,
html[data-theme="dark"] .fee-update-campaign-body,
html[data-theme="dark"] .fee-update-actions { border-color: var(--sd-dark-line); }
html[data-theme="dark"] .fee-update-effective-note {
  background: #18384b;
  border-color: #9c6c34;
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .fee-update-message-heading > span { background: #123f3c; color: #8ce7dc; }

/* Settings modals: replace literal light panels without changing their layout. */
html[data-theme="dark"] :where(
  .recurrence-toggle, .availability-week, .availability-range,
  .monthly-billing-settings, .monthly-patient-selector label,
  .reminder-options, .reminder-options label, .date-rule-editor,
  .date-rule-row, .notification-preference-row, .notification-push-device,
  .protected-export-sections, .protected-export-option
) {
  background: var(--sd-dark-surface-soft);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text) !important;
}
html[data-theme="dark"] :where(
  .recurrence-toggle, .availability-week, .availability-range,
  .monthly-billing-settings, .monthly-patient-selector label,
  .reminder-options label, .notification-preference-row,
  .notification-push-device, .protected-export-option
) :where(strong, span, label) { color: inherit; }
html[data-theme="dark"] :where(.recurrence-toggle, .monthly-billing-settings, .monthly-patient-selector label) small,
html[data-theme="dark"] :where(.availability-week, .notification-settings) p,
html[data-theme="dark"] .notification-preference-channel { color: var(--sd-dark-muted); }
html[data-theme="dark"] .availability-week > header,
html[data-theme="dark"] .availability-day-row { border-color: var(--sd-dark-line); }
html[data-theme="dark"] .availability-day-name strong,
html[data-theme="dark"] .availability-range label,
html[data-theme="dark"] .monthly-patient-selector legend,
html[data-theme="dark"] .reminder-options legend,
html[data-theme="dark"] .notification-settings h3,
html[data-theme="dark"] .notification-preference-label,
html[data-theme="dark"] .protected-export-sections legend { color: var(--sd-dark-text); }
html[data-theme="dark"] .day-enable span {
  background: #0a1c2a;
  border-color: #557286;
}
html[data-theme="dark"] .repeat-week-button,
html[data-theme="dark"] .add-day-range {
  background: #153b4d;
  border-color: #2d6175;
  color: #74ddd5;
}
html[data-theme="dark"] .range-remove { background: #4a2428; color: #ffaaa1; }
html[data-theme="dark"] .field-info {
  background: #153b4d;
  border-color: #4f788d;
  color: #9bdcf4;
}
html[data-theme="dark"] .field-info-popover {
  background: var(--sd-dark-elevated);
  border-color: var(--sd-dark-line);
  color: var(--sd-dark-text);
}
html[data-theme="dark"] .protected-export-notice {
  background: #493817;
  border: 1px solid #806127;
  color: #ffdda0;
}
html[data-theme="dark"] .protected-export-notice :where(strong, span) { color: inherit; }

/* Extractable and externally supplied material is intentionally always light. */
html[data-theme="dark"] :where(
  [data-theme-scope="document"], [data-theme-scope="attachment"],
  .pdf-preview, .document-preview, .print-preview, .email-preview,
  .receipt-preview, .attachment-preview, .annex-preview, .patient-attachment-empty, .consent-preview,
  object[type="application/pdf"], iframe[src$=".pdf"], iframe[src*=".pdf?"]
) {
  color-scheme: light;
  --cream: #f4f7f8;
  --header-cream: #fff;
  --paper: #fff;
  --ink: #14324a;
  --muted: #687e8d;
  --line: #d3e0e7;
  background-color: #fff !important;
  color: #14324a !important;
  filter: none !important;
}
html[data-theme="dark"] :where(
  [data-theme-scope="document"], [data-theme-scope="attachment"],
  .pdf-preview, .document-preview, .print-preview, .email-preview,
  .receipt-preview, .attachment-preview, .annex-preview, .patient-attachment-empty, .consent-preview
) * { filter: none !important; }
html[data-theme="dark"] .patient-attachment-empty :where(h3, p) { color: #14324a !important; }
html[data-theme="dark"] :where(img, video, canvas, svg.image-content) { filter: none; }
html[data-theme="dark"] .founding-welcome { background: linear-gradient(115deg,#0b3037,#102b43); border-color:#237e78; color:#e9ffff; }
html[data-theme="dark"] .founding-welcome p { color:#b7d2da; }
html[data-theme="dark"] :where(.founding-cycle-summary span,.founding-steps article,.founding-video) { background:#112f40; border-color:#315267; color:#e6f5fa; }
html[data-theme="dark"] .founding-steps .is-complete { background:#123a35; }
html[data-theme="dark"] .founding-action { border-color:#315267; }

@media (max-width: 760px) {
  .theme-selector button { padding-inline: 8px; font-size: 11px; }
}

@media print {
  html, html[data-theme="dark"], html[data-theme="dark"] body {
    color-scheme: light !important;
    --cream: #fff;
    --header-cream: #fff;
    --paper: #fff;
    --ink: #000;
    --muted: #444;
    --line: #bbb;
    background: #fff !important;
    color: #000 !important;
  }
  .theme-selector { display: none !important; }
}
