/* Module adapters: keep original geometry and document colors, share the shell palette. */
html body.app-theme-dark :is(.fuel-page,.fuel-dialog) {
  --f-bg:var(--surface); --f-soft:var(--theme-raised); --f-text:var(--text);
  --f-muted:var(--muted); --f-line:var(--line); --f-accent:var(--theme-success);
}
html body.app-theme-dark :is(.approval-board,.approval-dialog,.approval-verification) {
  --a-bg:var(--surface); --a-soft:var(--theme-raised); --a-text:var(--text);
  --a-muted:var(--muted); --a-line:var(--line); --a-accent:var(--theme-success);
}
html body.app-theme-dark :is(.cat-page,.cat-dialog,.cat-work-dialog) {
  --cat-panel:var(--surface); --cat-soft:var(--theme-raised); --cat-ink:var(--text);
  --cat-muted:var(--muted); --cat-line:var(--line); --cat-green:var(--theme-success);
  --cat-blue:var(--theme-accent); --cat-gold:var(--theme-warning);
}
html body.app-theme-dark :is(.prom-risk-page,.prom-risk-dialog) {
  --pr-navy:var(--theme-accent); --pr-teal:var(--theme-success); --pr-amber:var(--theme-warning);
  --pr-green:var(--theme-success); --pr-red:var(--theme-danger);
  --pr-soft:var(--theme-inset); --pr-soft-strong:var(--theme-raised); --pr-shadow:var(--shadow);
}
html body.app-theme-dark .sf-page {
  --sf-teal:var(--theme-success); --sf-blue:var(--theme-accent);
  --sf-red:var(--theme-danger); --sf-amber:var(--theme-warning);
  --sf-soft:var(--theme-inset); --sf-soft-strong:var(--theme-raised); --sf-shadow:var(--shadow);
}
html body.app-theme-dark .statistics-page {
  --stats-ink:var(--text); --stats-muted:var(--muted); --stats-line:var(--line);
  --stats-surface:var(--surface); --stats-soft:var(--theme-inset);
  --stats-blue:var(--theme-accent); --stats-green:var(--theme-success);
  --stats-amber:var(--theme-warning); --stats-coral:var(--theme-danger);
}
html body.app-theme-dark .roles-workspace {
  --role-accent:var(--theme-accent); --role-soft:var(--theme-inset); --role-danger:var(--theme-danger);
}
html body.app-theme-dark :is(.document-marks,.document-marks-dialog) {
  --border:var(--line); --card-bg:var(--surface);
}

/* Shared folder, search and portalled previews. */
html body.app-theme-dark :is(.shared-folder-browser,.shared-file-list-panel,.shared-file-row) {
  background:var(--surface); color:var(--text); border-color:var(--line);
}
html body.app-theme-dark :is(.shared-browser-toolbar,.shared-list-head,.shared-preview-head,
  .shared-selection-bar,.shared-pagination) {
  background:var(--theme-raised); color:var(--muted); border-color:var(--line);
}
html body.app-theme-dark :is(.shared-preview,.shared-preview-content.is-structured) {
  background:var(--theme-inset); border-color:var(--line);
}
html body.app-theme-dark > .shared-preview.is-viewport-layer {
  background:var(--theme-inset) !important; border-color:var(--line) !important;
}
html body.app-theme-dark .shared-preview:is(.is-fullscreen,.is-mobile-window) .shared-preview-head {
  background:var(--theme-raised); color:var(--text); border-color:var(--line);
}
html body.app-theme-dark :is(.shared-icon-button,.shared-file-open,.shared-root-tab,
  .shared-preview-fullscreen-toggle,.shared-preview-fullscreen-close) {
  background:var(--theme-raised); border-color:var(--line); color:var(--text);
}
html body.app-theme-dark :is(.shared-file-row,.shared-icon-button,.shared-file-open,.shared-root-tab):hover {
  background:var(--theme-hover);
}
html body.app-theme-dark :is(.shared-file-row.is-selected,.shared-root-tab.is-active,
  .search-workspace-tabs .settings-tab.is-active) {
  background:var(--theme-selected); color:var(--text); border-color:var(--theme-accent);
}
html body.app-theme-dark :is(.shared-file-icon,.shared-browser-actions>span) {
  background:var(--theme-raised); color:var(--theme-accent);
}
html body.app-theme-dark .shared-file-row.is-folder .shared-file-icon {
  background:var(--theme-success-bg); color:var(--theme-success);
}
html body.app-theme-dark :is(.shared-file-cell,.shared-file-mobile-meta,.shared-breadcrumbs button,
  .shared-preview-title span,.shared-preview-message,.shared-preview-empty,.shared-list-empty,
  .shared-pagination span,.shared-folder-no-roots,.shared-selection-summary) { color:var(--muted); }
html body.app-theme-dark :is(.shared-preview-title strong,.shared-folder-no-roots strong,
  .shared-file-name,.shared-preview-content>pre) { color:var(--text); }
html body.app-theme-dark .shared-breadcrumbs button:hover { background:var(--theme-hover); color:var(--text); }
html body.app-theme-dark .shared-preview-loading i { border-color:var(--line); border-top-color:var(--theme-accent); }
html body.app-theme-dark :is(.shared-upload-state,.shared-drop-overlay) {
  background:var(--theme-selected); color:var(--text); border-color:var(--theme-accent);
}
html body.app-theme-dark .shared-drop-overlay span { color:var(--muted); }
html body.app-theme-dark .shared-preview-backdrop { background:#080a0eb3; }

/* Summaries below the fold use the same contrast as the main tables. */
html body.app-theme-dark :is(.paid-bonus-totals div,.paid-bonus-row,.system-health-grid div,
  .system-path-row,.system-job-row,.system-backup-row,.list-row,.workload-calendar-details section) {
  background:var(--theme-inset); border-color:var(--line); border-radius:6px;
}
html body.app-theme-dark :is(.paid-bonus-head>strong,.paid-bonus-row-main span,
  .paid-bonus-totals span,.paid-bonus-row-text,.system-health-grid strong,
  .system-path-row strong,.system-job-row strong,.system-backup-row strong,
  .workload-calendar-details strong) { color:var(--text); }
html body.app-theme-dark :is(.system-stat-card small,.system-health-grid span,.system-health-grid small,
  .system-path-row small,.system-job-row small,.system-backup-row small,.system-backup-row span,
  .system-action-state,.workload-calendar-details li,.workload-calendar-details p,
  .workload-calendar-legend) { color:var(--muted); }
html body.app-theme-dark .workload-calendar-card a { color:var(--theme-success); }
html body.app-theme-dark .workload-calendar-day-list { color:var(--text) !important; }
html body.app-theme-dark .workload-calendar-details { background:var(--line); border-color:var(--line); }
html body.app-theme-dark .schedule-day-code { background:var(--theme-inset); }
html body.app-theme-dark .workload-calendar-legend i { border-color:var(--line); }
html body.app-theme-dark .workload-calendar-legend i.holiday { background:var(--theme-danger-bg); }
html body.app-theme-dark .workload-calendar-legend i.weekend { background:var(--theme-raised) !important; }
html body.app-theme-dark .workload-calendar-legend i.shortened { background:var(--theme-warning-bg); }
html body.app-theme-dark .workload-calendar-legend i.working-weekend { background:var(--theme-selected); }
html body.app-theme-dark :is(.system-pill,.terminal-line,.terminal-output) {
  background:var(--theme-inset); color:var(--text); border-color:var(--line); border-radius:6px;
}
html body.app-theme-dark :is(.system-pill.ok,.workload-calendar-status) {
  background:var(--theme-success-bg); color:var(--theme-success);
}
html body.app-theme-dark :is(.system-alert,.system-alert span,.system-pill.danger) {
  background:var(--theme-danger-bg); color:var(--theme-danger); border-color:#805059;
}
html body.app-theme-dark .workload-calendar-status.is-preliminary {
  background:var(--theme-warning-bg); color:var(--theme-warning);
}
html body.app-theme-dark .data-table.bonus-table tbody tr:not(.bonus-month-row):hover>td { background:var(--theme-hover); }

/* Data tables retain semantic holiday, payment and selection states. */
html body.app-theme-dark :is(.workload-calendar-card strong,.workload-payroll-summary strong,
  .workload-payroll-total strong,.workload-payroll-table td:last-child strong) { color:var(--text); }
html body.app-theme-dark :is(.workload-calendar-card span,.workload-calendar-card small,
  .workload-payroll-summary span) { color:var(--muted); }
html body.app-theme-dark :is(.workload-payroll-total,.workload-payroll-summary>div) {
  background:var(--theme-inset); border-color:var(--line);
}
html body.app-theme-dark .schedule-table :is(.weekend,.schedule-day-off) {
  background:var(--theme-raised) !important; color:var(--muted);
}
html body.app-theme-dark .schedule-table :is(.total-col,.schedule-short-day) {
  background:var(--theme-warning-bg) !important; color:var(--theme-warning);
}
html body.app-theme-dark .schedule-table .schedule-holiday {
  background:var(--theme-danger-bg) !important; color:var(--theme-danger);
}
html body.app-theme-dark .schedule-table .schedule-working-weekend {
  background:var(--theme-selected) !important; color:var(--theme-accent);
}
html body.app-theme-dark .schedule-table .payroll-col {
  background:var(--theme-success-bg) !important; color:var(--theme-success);
}
html body.app-theme-dark :is(.workload-payroll-head span,.shared-upload-state.is-success,
  .fuel-status.paid,.statement-state.approved,.statement-state.paid) {
  background:var(--theme-success-bg); color:var(--theme-success); border-color:#446c58;
}
html body.app-theme-dark :is(.workload-salary-warning,.shared-upload-state.is-warning,
  .fuel-status.pending,.statement-state.pending,.cat-warning) {
  background:var(--theme-warning-bg); color:var(--theme-warning); border-color:#79613c;
}
html body.app-theme-dark :is(.shared-upload-state.is-error,.fuel-status.unpaid,.fuel-status.rejected,
  .statement-state.rejected,.statement-state.revoked,.approval-error,.approval-check-result.invalid,
  .document-viewer-state.is-error) {
  background:var(--theme-danger-bg); color:var(--theme-danger); border-color:#805059;
}
html body.app-theme-dark :is(#fuel-message,#fuel-dialog-error) {
  background:var(--theme-warning-bg); color:var(--theme-warning);
}
html body.app-theme-dark :is(.fuel-page,.fuel-dialog) .fuel-primary,
html body.app-theme-dark :is(.approval-board,.approval-dialog,.approval-verification) .approval-primary {
  background:var(--theme-action); border-color:var(--theme-action); color:var(--theme-action-text);
}
html body.app-theme-dark :is(.fuel-page,.fuel-dialog) .fuel-primary:hover,
html body.app-theme-dark :is(.approval-board,.approval-dialog,.approval-verification) .approval-primary:hover {
  background:#bfdbfa; color:var(--theme-action-text);
}

/* Engineering workspaces and material libraries. */
html body.app-theme-dark :is(.cat-menubar,.cat-pane-title,.cat-statusbar,.cat-report-table th,
  .cat-inline-action,.cat-check,.cat-report-hero,.cat-formula header>b) {
  background:var(--theme-raised); color:var(--text); border-color:var(--line);
}
html body.app-theme-dark :is(.cat-tree-pane,.cat-main-pane,.cat-report-content,.cat-text-menu,
  .cat-work-dialog,.cat-dialog,.cat-menu>div,[data-cat-import-projects] button) {
  background:var(--surface); color:var(--text); border-color:var(--line);
}
html body.app-theme-dark :is(.cat-tree-row,.cat-tool,.cat-field>span,.cat-statusbar b,
  .cat-empty strong,.cat-fields-heading strong,.cat-report-table td) { color:var(--text); }
html body.app-theme-dark :is(.cat-tree-row:hover,.cat-tool:hover,.cat-menu button:hover,
  .cat-menu>summary:hover,.cat-menu[open]>summary,[data-material-list] button:hover) {
  background:var(--theme-hover); color:var(--text);
}
html body.app-theme-dark :is(.cat-tree-row.is-selected,.cat-report-tabs button.is-active,
  [data-material-list] button[aria-pressed=true]) { background:var(--theme-selected); color:var(--text); }
html body.app-theme-dark .cat-resizer { background:var(--line); }
html body.app-theme-dark .cat-node-icon { background:var(--theme-raised); color:var(--muted); border-color:var(--line); }
html body.app-theme-dark :is(.cat-report-hero p,.cat-formula p) { color:var(--muted); }
html body.app-theme-dark :is(.cat-tree-row em,.cat-report-hero strong,.cat-selected-material>strong,
  .cat-selected-material svg,.cat-library-heat strong) { color:var(--theme-success); }
html body.app-theme-dark :is(.cat-formula code,.cat-library-source a) { color:var(--theme-accent); }
html body.app-theme-dark .cat-category-badge {
  background:var(--theme-success-bg); border-color:#446c58; color:var(--theme-success) !important;
}
html body.app-theme-dark .cat-category-badge.is-empty {
  background:var(--theme-raised); border-color:var(--line); color:var(--muted) !important;
}
html body.app-theme-dark :is(.statistics-view-tabs,.statistics-skeleton div) { background:var(--theme-inset); }
html body.app-theme-dark .statistics-view-tabs button.is-active { background:var(--theme-selected); color:var(--text); }
html body.app-theme-dark .statistics-status-list span { color:var(--muted); }
html body.app-theme-dark :is(.statistics-kpi>i,.statistics-employee>i,.statistics-service-main>i) { background:var(--theme-raised); }

/* System settings and assistant surfaces. */
html body.app-theme-dark .keendns-status-grid { background:var(--line); border-color:var(--line); }
html body.app-theme-dark .keendns-status-grid>div { background:var(--theme-inset); }
html body.app-theme-dark .keendns-status-grid strong { color:var(--text); }
html body.app-theme-dark .keendns-status-grid a { color:var(--theme-accent); }
html body.app-theme-dark .keendns-status-grid span { color:var(--muted); }
html body.app-theme-dark .inzhir-presence {
  --inzhir-text:var(--text); --inzhir-muted:var(--muted);
  --inzhir-panel:var(--surface); --inzhir-panel-muted:var(--theme-inset);
  --inzhir-line:var(--line); --inzhir-accent:var(--theme-success);
  --inzhir-accent-soft:var(--theme-success-bg);
}
html body.app-theme-dark :is(.inzhir-presence-card,.inzhir-presence-mini) {
  background:var(--surface); color:var(--text); border-color:var(--line);
}
html body.app-theme-dark .inzhir-presence-action:hover { background:var(--theme-hover); }
html body.app-theme-dark .inzhir-presence-progress-track { background:var(--theme-raised); }

/* Employee profiles and connection status must not fall back to light surfaces. */
html body.app-theme-dark :is(.employee-directory-row,.profile-theme-options,
  .profile-theme-option,.assignee-option,.bonus-editor-row,.check-row,
  .owner-access-note,.owner-access-empty,.object-add-dialog,.object-add-choice,
  .object-add-panel,.background-picker,.table-title-row) {
  background:var(--surface);color:var(--text);border-color:var(--line);box-shadow:none;
}
html body.app-theme-dark :is(.employee-directory-person strong,.employee-directory-person small,
  .profile-theme-copy strong,.profile-theme-copy small,.owner-access-head h2,
  .table-title-row h2,.detail-panel strong) {color:var(--text)}
html body.app-theme-dark :is(.employee-directory-person small,.employee-directory-state,
  .owner-access-note,.owner-access-empty,.owner-access-address small,
  .profile-theme-option small,.object-add-choice span) {color:var(--muted)}
html body.app-theme-dark :is(.employee-avatar,.profile-avatar,.employee-directory-state span,
  .profile-meta-row span,.owner-access-address>span,.assignee-option.is-primary) {
  background:var(--theme-raised);color:var(--muted);border-color:var(--line);
}
html body.app-theme-dark :is(.employee-avatar,.profile-avatar,.owner-role-badge) {color:var(--theme-accent)}
html body.app-theme-dark .owner-role-badge {background:var(--theme-success-bg);color:var(--theme-success);border-color:#446c58}
html body.app-theme-dark :is(.employee-directory-state .state-ok,.employee-directory-state .state-online,
  .profile-meta-row .state-online) {background:var(--theme-success-bg);color:var(--theme-success)}
html body.app-theme-dark :is(.employee-directory-state .state-muted,.profile-meta-row .state-muted) {
  background:var(--theme-inset);color:var(--muted);
}
html body.app-theme-dark :is(.profile-theme-option:has(input:checked),.object-add-choice.is-active) {
  background:var(--theme-selected);border-color:var(--theme-accent);color:var(--text);
}
html body.app-theme-dark .owner-access-address:hover {background:var(--theme-hover);border-color:var(--theme-accent)}
html body.app-theme-dark :is(.owner-access-address.is-offline,.owner-access-empty.is-error) {
  background:var(--theme-danger-bg);border-color:#805059;color:var(--theme-danger);
}
html body.app-theme-dark .owner-access-address.is-offline small {color:var(--theme-danger)}
html body.app-theme-dark :is(.owner-access-address.is-online,.owner-access-address.is-copied) {
  background:var(--theme-success-bg);border-color:#446c58;
}
html body.app-theme-dark :is(.owner-access-address.is-online,.owner-access-address.is-copied) small {color:var(--theme-success)}
html body.app-theme-dark .owner-access-address>span {background:var(--theme-raised);color:var(--theme-accent)}
html body.app-theme-dark .owner-access-skeleton {
  background:linear-gradient(90deg,var(--theme-inset),var(--theme-raised),var(--theme-inset));background-size:220% 100%;
}
html body.app-theme-dark .owner-access-note {background:var(--theme-inset)}
html body.app-theme-dark .password-reset-button {background:var(--theme-raised);color:var(--theme-accent);border-color:var(--line)}
html body.app-theme-dark .password-reset-button:hover {background:var(--theme-hover)}

/* Log counters and status controls must follow the same semantic palette. */
html body.app-theme-dark :is(.calendar-page,.calendar-modal) {
  --calendar-accent:var(--theme-success);
  --calendar-accent-soft:var(--theme-success-bg);
  --calendar-border:var(--line);
  --calendar-soft:var(--theme-inset);
  --calendar-danger:var(--theme-danger);
}
html body.app-theme-dark :is(.calendar-toolbar,.calendar-surface,.calendar-sidebar>section,
  .calendar-dialog,.calendar-dialog-head,.calendar-dialog-foot,.calendar-preferences,.calendar-day-cell) {
  background:var(--surface);color:var(--text);
}
html body.app-theme-dark :is(.calendar-icon-button,.calendar-dialog-close) {color:var(--text)}
html body.app-theme-dark :is(.calendar-icon-button,.calendar-dialog-close):hover {
  color:var(--theme-accent);background:var(--theme-raised);border-color:var(--theme-accent);
}
html body.app-theme-dark :is(.calendar-search,.calendar-view-switch button,.calendar-loading,
  .calendar-weekday,.calendar-day-cell.is-other-month,.calendar-day-add,.calendar-more-events,
  .calendar-list-time,.calendar-field>span,.calendar-color-field legend,.calendar-completed-field small) {color:var(--muted)}
html body.app-theme-dark .calendar-view-switch button.is-active {color:var(--calendar-accent);background:var(--theme-raised)}
html body.app-theme-dark .calendar-dialog :is(input:not([type=checkbox]):not([type=radio]):not([type=color]),select,textarea) {
  background:var(--theme-inset);color:var(--text);border-color:var(--line);
}
html body.app-theme-dark .calendar-loading {background:color-mix(in srgb,var(--surface) 92%,transparent)}
html body.app-theme-dark :is(.calendar-weekday,.calendar-day-cell.is-other-month,.calendar-agenda-date,
  .calendar-dialog-scroll,.calendar-check-field,.calendar-completed-field,.calendar-share-panel) {background:var(--theme-inset);border-color:var(--line)}
html body.app-theme-dark .calendar-day-cell:hover {background:var(--theme-raised)}
html body.app-theme-dark :is(.calendar-day-cell.is-selected,.calendar-day-cell.is-drop-target) {background:var(--theme-success-bg)}
html body.app-theme-dark .calendar-day-cell.is-today .calendar-day-number {color:var(--theme-inset)}
html body.app-theme-dark .calendar-completed-field strong {color:var(--theme-success)}
html body.app-theme-dark .calendar-toast {background:var(--theme-success-bg);color:var(--theme-success);border-color:var(--line)}
html body.app-theme-dark .calendar-toast.is-error {background:var(--theme-danger-bg);color:var(--theme-danger)}

html body.app-theme-dark .logs-summary-card {
  background:var(--surface);border-color:var(--line);border-radius:8px;box-shadow:var(--shadow);
}
html body.app-theme-dark .logs-summary-card.warning {background:var(--theme-warning-bg);border-color:#79613c}
html body.app-theme-dark .logs-summary-card.danger {background:var(--theme-danger-bg);border-color:#805059}
html body.app-theme-dark .logs-summary-card.system {background:var(--theme-selected);border-color:var(--line)}
html body.app-theme-dark :is(.registry-counter,.logs-summary-card span,.logs-filters label,.logs-live small,.logs-table td small,.logs-table details div) {color:var(--muted)}
html body.app-theme-dark :is(.registry-counter strong,.logs-summary-card strong,.logs-live label) {color:var(--text)}
html body.app-theme-dark .logs-summary-card.warning strong {color:var(--theme-warning)}
html body.app-theme-dark .logs-summary-card.danger strong {color:var(--theme-danger)}
html body.app-theme-dark .logs-summary-card.system strong {color:var(--theme-accent)}
html body.app-theme-dark :is(.logs-live,.logs-quick-tabs,.logs-table-wrap) {background:var(--theme-inset);border-color:var(--line);border-radius:8px}
html body.app-theme-dark .logs-quick-tabs button {color:var(--muted);border-radius:6px}
html body.app-theme-dark .logs-quick-tabs button:hover {background:var(--theme-hover);color:var(--text)}
html body.app-theme-dark .logs-quick-tabs button.is-active {background:var(--theme-selected);color:var(--theme-accent);border-color:var(--theme-accent);box-shadow:none}
html body.app-theme-dark :is(.log-source,.log-severity,.logs-history-end) {background:var(--theme-raised);color:var(--muted);border-color:var(--line)}
html body.app-theme-dark .log-severity-warning {background:var(--theme-warning-bg);color:var(--theme-warning);border-color:#79613c}
html body.app-theme-dark :is(.log-severity-error,.log-severity-critical) {background:var(--theme-danger-bg);color:var(--theme-danger);border-color:#805059}
html body.app-theme-dark .logs-table details summary {color:var(--theme-accent)}

/* Theme changes must never invert a document, drawing, signature or image. */
html body.app-theme-dark .messenger-root :is(h2,h3,h4) { color:var(--msg-text); }
html body.app-theme-dark .messenger-root :is(input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range]),select,textarea) {
  background:var(--msg-panel) !important; color:var(--msg-text) !important; border-color:var(--msg-line);
}
html body.app-theme-dark :is(.statement-paper,.shared-document) {
  color-scheme:light; background:#fff; color:#202020;
}
html body.app-theme-dark :is(.statement-paper,.shared-document) :is(h1,h2,h3,h4,p,th,td,strong,small,span) {
  color:inherit;
}
html body.app-theme-dark :is(.statement-paper,.shared-document) :is(h1,h2,h3,h4,p) { color:#202020; }
html body.app-theme-dark :is(.statement-paper,.shared-document) :is(table,td) { background:#fff; color:#202020; }
html body.app-theme-dark :is(.statement-paper,.shared-document) th { background:#f1f3f4; color:#202020; }
@media (max-width:980px) {
  html[data-ui-layout=mobile] body.app-theme-dark .topbar-workspace { background:var(--theme-inset); }
}
