/* A local theme preference, with the system appearance as the first-visit default. */
:root {
  color-scheme:light;
  --chat-user:#e6eaf1;
  --chat-answer:#f7f8f9;
}
html[data-theme=dark] {
  color-scheme:dark;
  --ink:#e4eaf4;
  --muted:#a2b0c5;
  --paper:#10151f;
  --surface:#191f2c;
  --line:#303b4d;
  --green:#9bbcff;
  --green-600:#bdd2ff;
  --green-050:#202d46;
  --light:#25344e;
  --soft:#151c28;
  --focus:#acc9ff;
  --amber:#edbd6d;
  --shadow-sm:0 1px 3px #0003;
  --shadow-md:0 8px 24px #0004;
  --shadow-lg:0 22px 64px #0007;
  --chat-user:#293c5e;
  --chat-answer:#202938;
}
.theme-changing :where(body,.sidebar,.desk-topbar,.mobile-header,.panel,.form-panel,.list-row,
  .calendar-event,.calendar-grid td,input,select,textarea,dialog,.cw-chat-shell,.cw-chat-header,
  .cw-chat-history,.cw-chat-status-row,.cw-chat-status) {
  transition:background-color 320ms ease,color 320ms ease,border-color 320ms ease;
}
.workspace .theme-toggle {
  position:relative;isolation:isolate;flex:0 0 88px;width:88px;height:44px;min-height:44px;
  padding:0;margin:0 0 0 auto;border:0;border-radius:24px;background:transparent;
  cursor:pointer;touch-action:pan-y;user-select:none;-webkit-tap-highlight-color:transparent;
  --thumb-position:44px;
  --toggle-glow:#e0a84b;
  --toggle-icon:#fff8dc;
}
.theme-toggle-track {
  position:absolute;inset:2px 0;border-radius:24px;
  background:linear-gradient(155deg,#c3cad6,#e4e9f0 65%,#f3f6fa);
  box-shadow:inset 2px 3px 6px #172b4d30,inset -1px -1px 2px #fff,0 1px 0 #fff8;
}
.theme-toggle-thumb {
  position:absolute;inset:4px auto 4px 4px;width:36px;border-radius:17px;
  transform:translateX(var(--thumb-position));color:var(--toggle-icon);
  background:linear-gradient(155deg,#ffffff85,#ffffff28 45%,#ffeed03d);
  border:1px solid #ffffffb0;
  box-shadow:inset 0 1px 2px #fff,inset 0 -3px 3px #fff7,0 2px 5px #172b4d33,0 3px 9px color-mix(in srgb,var(--toggle-glow) 45%,transparent);
  backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);
  transition:transform 540ms cubic-bezier(.22,1.4,.45,1),box-shadow 350ms ease,background 350ms ease;
}
.theme-toggle-thumb::after {
  content:"";position:absolute;inset:auto 3px -1px;height:3px;border-radius:50%;
  background:var(--toggle-glow);filter:blur(1px);
  box-shadow:0 0 5px 1px var(--toggle-glow),0 0 12px 2px color-mix(in srgb,var(--toggle-glow) 55%,transparent);
}
.theme-icon { position:absolute;inset:0;margin:auto;filter:drop-shadow(0 0 3px var(--toggle-glow));transition:opacity 260ms ease,transform 480ms cubic-bezier(.22,1,.36,1);pointer-events:none; }
.theme-icon-moon { opacity:0;transform:rotate(-50deg) scale(.5); }
.theme-icon-sun { opacity:1;transform:rotate(0) scale(1);color:#795017;filter:drop-shadow(0 0 2px #fff6); }
html[data-theme=dark] .theme-toggle { --thumb-position:0px;--toggle-glow:#999aff;--toggle-icon:#f3f0ff; }
html[data-theme=dark] .theme-toggle-track { background:linear-gradient(145deg,#080b12,#141925);box-shadow:inset 2px 3px 7px #000b,inset -1px -1px 1px #ffffff12,0 1px 0 #ffffff12; }
html[data-theme=dark] .theme-toggle-thumb { background:linear-gradient(145deg,#ffffff26,#ffffff08 55%,#888aff30);border-color:#ffffff3f;box-shadow:inset 0 1px 2px #ffffff50,inset 0 -3px 3px #cacbff55,0 2px 7px #0007,0 3px 12px #8585ff45; }
html[data-theme=dark] .theme-icon-moon { opacity:1;transform:rotate(0) scale(1); }
html[data-theme=dark] .theme-icon-sun { opacity:0;transform:rotate(65deg) scale(.5); }
.workspace .theme-toggle:hover .theme-toggle-thumb { filter:brightness(1.1); }
.workspace .theme-toggle:focus-visible { outline:2px solid var(--focus);outline-offset:5px; }
.theme-toggle.is-dragging .theme-toggle-thumb { transition:none; }

/* Shared surfaces, including legacy components with fixed light colors. */
html[data-theme=dark] .workspace :is(
  .sidebar,.mobile-header,.mobile-menu,.desk-topbar,.panel,.form-panel,.case-card,
  .cw-chat-modal,.cw-chat-shell,.cw-chat-expand,.cw-chat-manage-panel,.cw-report-panel,
  .cw-activity-panel,.cw-action-card,.report-chart,.app-confirm,.calendar-shell,
  .record-more-actions>summary,.record-more-actions>div,.dropdown-menu,
  .template-card,.filter-bar,.field-filters,.ai-settings-form,.ai-settings-help,
  .relationship-card,.connection-card,.rel-card,.tree-card,.detail-card,
  .intake-upload,.packet-page,.capture-panel,.packet-tools,.review-recap,
  .management-tabs a,.dependency-counts>span,.closed-case-banner
) { background:var(--surface);color:var(--ink);border-color:var(--line); }
html[data-theme=dark] .workspace :is(input:not([type=checkbox],[type=radio],[type=hidden]),textarea,select) {
  background:var(--soft);color:var(--ink);border-color:var(--line);
}
html[data-theme=dark] .workspace :is(input,textarea)::placeholder { color:#8998ae;opacity:1; }
html[data-theme=dark] .workspace :is(label,.form-panel label,.form-aside,.helptext,.field-hint,.field-source,.small,.muted,
  .cw-chat-model,.cw-chat-bottom,.cw-chat-status,.cw-activity-explanation,.cw-activity-panel li,
  .cw-action-state,.cw-action-fields dt,.cw-action-feedback,.cw-manage-archive p,.cw-chat-manage-panel label,
  .cw-chat-history .cw-history-search,.calendar-event-tooltip span) { color:var(--muted); }
html[data-theme=dark] .workspace :is(h1,h2,h3,h4,strong,.cw-chat-shell,.cw-chat-header strong,.cw-manage-heading strong,
  .cw-activity-panel strong,.cw-activity-panel li:has(.cw-assistant-update)>span) { color:var(--ink); }
html[data-theme=dark] .workspace :is(.cw-chat-header,.cw-chat-history,.cw-chat-status,.cw-chat-status-row,
  .cw-chat-reports,.cw-panel-heading,.cw-manage-heading,.cw-manage-archive,.cw-assistant-update,
  .viewer-controls,.evidence-toolbar,.template-tools,.desk-steps,.calendar-outside,.connection-toolbar,
  .relationship-toolbar,.review-recap,.closed-case-banner,.dependency-counts>span) {
  background:var(--soft);border-color:var(--line);
}
html[data-theme=dark] .workspace :is(.cw-chat-titlebar,.cw-report,.cw-chat-page,.calendar-inquiry-row) { border-color:var(--line); }
html[data-theme=dark] .workspace :is(.cw-history-item,.cw-history-tabs button,.cw-manage-heading button) { color:var(--ink); }
html[data-theme=dark] .workspace :is(.cw-history-item:hover,.cw-history-item[aria-current],.cw-history-tabs button[aria-pressed=true],
  .management-tabs a[aria-current],.checklist-filters a[aria-current],.queue-tabs a[aria-current],
  .client-profile-tabs a[aria-current],.nav-selection) { background:var(--light);color:var(--green);border-color:var(--line); }
html[data-theme=dark] .workspace :is(button,.button):not(.secondary,.text-button,.theme-toggle,.cw-history-item,
  .cw-history-tabs button,.cw-activity-toggle,.cw-reports-toggle,.danger-button,.calendar-reminder-close,.helper-launch,.desk-search button) {
  background:var(--design-action,#345dba);color:var(--design-action-text,#fff);border-color:var(--design-action,#547cce);
}
html[data-theme=dark] .workspace :is(.secondary,.record-more-actions>summary) { background:var(--surface);color:var(--green);border-color:var(--line); }
html[data-theme=dark] .workspace .secondary:hover { background:var(--light); }
html[data-theme=dark] .workspace :is(.text-button,.cw-chat-manage summary,.cw-review-label) { color:var(--green); }
html[data-theme=dark] .workspace .cw-reports-toggle { background:var(--light)!important;color:var(--ink)!important; }
html[data-theme=dark] .workspace .cw-activity-toggle { color:var(--ink);background:transparent; }
html[data-theme=dark] .workspace .cw-pending-badge { color:#fff; }
html[data-theme=dark] .workspace .badge { color:#b9c7dd;background:#2a3445; }
html[data-theme=dark] .workspace :is(.badge.accepted,.badge.published,.badge.processing,.badge.active,.badge.ready) { color:#b5cfff;background:#263a5d; }
html[data-theme=dark] .workspace :is(.badge.missing,.badge.failed,.badge.attention,.badge.overdue) { color:#ffb6b6;background:#4a2832; }
html[data-theme=dark] .workspace :is(.badge.review,.badge.warning,.badge.waiting,.badge.awaiting) { color:#f5d195;background:#433825; }
html[data-theme=dark] .workspace .badge.reminder-completed { color:#a7e3ba;background:#233e33; }
html[data-theme=dark] .workspace .calendar-event { background:#25344e;color:var(--ink); }
html[data-theme=dark] .workspace .calendar-event.event-reminder { background:#352b4b;border-color:#b398d9; }
html[data-theme=dark] .workspace .calendar-event.event-submission { background:#332d4e;border-color:#b7a2f0; }
html[data-theme=dark] .workspace .calendar-event:is(.event-document,.event-passport) { background:#413722;border-color:#d4ae62; }
html[data-theme=dark] .workspace .calendar-event.event-follow_up { background:#27394a;border-color:#8fb4d7; }
html[data-theme=dark] .workspace .calendar-event.event-completed { background:#233e33;border-color:#6aaa83;color:#b5e5c4; }
html[data-theme=dark] .workspace :is(.desk-viewer,.region-viewer,.template-canvas,.connection-canvas,.relationships-canvas) { background:#111925;border-color:var(--line); }
html[data-theme=dark] .workspace .viewer-stage { background:#111925 radial-gradient(#2f4058 .75px,transparent .75px) 0 0 / 13px 13px; }
html[data-theme=dark] .workspace .report-chart-row>div { background:var(--line); }
html[data-theme=dark] .workspace .report-chart-row i { background:#7b9edb; }
html[data-theme=dark] .workspace .danger-link { color:#fff!important; }
html[data-theme=dark] .workspace .app-confirm p { color:var(--muted); }
html[data-theme=dark] .workspace :is(.toast,.alert,.notice,.warning-banner) { background:var(--surface);color:var(--ink);border-color:var(--line); }
html[data-theme=dark] .workspace :is(.errorlist,.field-validation-error) { color:#ffb3ad; }
html[data-theme=dark] .workspace :is(.nav-label,.office,.nav-demo,.sidebar-foot,.sidebar-foot>span) { color:var(--muted); }
html[data-theme=dark] .workspace .sidebar nav a { color:#bbc7db; }
html[data-theme=dark] .workspace .sidebar nav a:is([aria-current],:hover) { color:#c5d9ff; }
html[data-theme=dark] .workspace .sidebar-foot { border-color:var(--line); }
@media(max-width:850px) {
  .desk-topbar .theme-toggle { margin-inline-start:auto; }
}
@media(prefers-reduced-motion:reduce) {
  .theme-toggle *,.theme-changing * { transition:none!important;animation:none!important; }
}
@media(forced-colors:active) {
  .workspace .theme-toggle { border:1px solid ButtonText; }
  .theme-toggle-thumb { background:ButtonFace;border:1px solid ButtonText;color:ButtonText; }
}

html[data-theme=dark] .workspace :is(.work-section-heading,.region-heading,.region-inspector,
  .template-workbench,.template-tools,.workflow-path,.workflow-rule,.workflow-save,
  .source-quote,.stats .stat-attention,.notice,.message,pre,.requirement,.case-edit>summary,
  .upload-location-form,.found-information,.found-detail,.linked-stats .metric,.viewer-location,
  .scan-dialog,.scan-footer,.viewer-toolbar,.viewer-bottom,.ocr-drawer pre,.desk-review,
  .conflict-review,.conflict-item dl>div,.identity-card,.match-card,.location-note,.desk-actions,
  .desk-notice,.processing-notice,.intake-alert,.packet-summary,.document-icon,.page-number,
  .cw-chat-reports>[data-chat-reports]) {
  background:var(--surface);color:var(--ink);border-color:var(--line);
}
html[data-theme=dark] .workspace #region-reader { background:var(--paper);color:var(--ink); }
html[data-theme=dark] .workspace .connections-network #relationship-canvas { background:var(--soft); }
html[data-theme=dark] .workspace :is(.queue-open,.client-profile-tabs a:hover,.management-tabs a:hover,
  .mapped-list button,.desk .viewer-controls button,.desk .choice-list button,.desk .back-step) {
  background:var(--light);color:var(--green);border-color:var(--line);
}
html[data-theme=dark] .workspace :is(.badge.waiting_review,.badge.reviewed,.badge.expiring,.badge.due) { color:#f5d195;background:#433825; }
html[data-theme=dark] .workspace .stats>div[class*="tone-"] { background:var(--surface); }
html[data-theme=dark] .workspace .errorlist { background:#4a2832; }
html[data-theme=dark] .workspace .desk :is(.attention-banner,.has-conflict input,.has-missing input) {
  background:#413624;color:#f5d195;border-color:#8b6e37;
}
html[data-theme=dark] .workspace :is(.toast.success,.toast.warning,.toast.error,.toast.info) { background:var(--surface);color:var(--ink); }
html[data-theme=dark] .workspace .calendar-today time { background:#345dba;color:#fff; }

/* Semantic colors must change with the theme, including cards that inherit tones. */
html[data-theme=dark] {
  --red-text:#ffb6b6; --red-bg:#4a2832; --red-line:#995564;
  --review-text:#f5d195; --review-bg:#433825; --review-line:#95763f;
  --done-text:#b5cfff; --done-bg:#263a5d; --done-line:#5275a9;
  --blue-text:#b5cfff; --blue-bg:#263a5d; --blue-line:#5275a9;
  --neutral-text:#bbc7d9; --neutral-bg:#2a3445;
}
html[data-theme=dark] .workspace :is(.pipeline-step,.pipeline-step:hover) {
  background:var(--tone-bg,var(--surface));color:var(--ink);border-color:var(--tone-line,var(--line));
}
html[data-theme=dark] .workspace .pipeline-step strong { color:var(--tone-ink,var(--ink)); }
html[data-theme=dark] .workspace :is(.metric span,.stats .metric .stat-note,
  .work-table small,.client-cell small,.queue-name small,.date-cell small,
  .location-actions small,.metric .stat-note,.case-stats small,.invoice-kpis small) { color:var(--muted); }
html[data-theme=dark] .workspace .source-note { background:var(--soft);color:var(--muted);border-color:var(--line); }
html[data-theme=dark] .workspace .source-label { background:var(--light);color:var(--ink); }
html[data-theme=dark] .workspace tbody tr:hover { background:var(--green-050); }
html[data-theme=dark] .workspace .calendar-grid tbody tr:hover { background:transparent; }
html[data-theme=dark] .workspace .calendar-grid td:hover { background:var(--green-050); }
html[data-theme=dark] .workspace :is(.work-table small.past-date,.past-date) { color:var(--red-text); }
html[data-theme=dark] .workspace :is(.badge,.status-chip):is(.reviewing,.consultation,.unfiled,.review) { background:var(--review-bg);color:var(--review-text); }
html[data-theme=dark] .workspace :is(.badge,.status-chip):is(.filed,.proceeding,.success,.ready,.submitted,.collecting,.new,.contacted,.processing) { background:var(--blue-bg);color:var(--blue-text); }
html[data-theme=dark] .workspace .tone-lost { --tone-line:#536078; }
html[data-theme=dark] .workspace .desk { --muted:#a2b0c5; }
html[data-theme=dark] .workspace .nav-demo { background:var(--light);color:var(--ink);border-color:var(--line); }

html[data-theme=dark] .workspace .case-action-strip { background:var(--green-050);border-color:var(--line); }
html[data-theme=dark] .workspace :is(.requirement p,.card-bottom p) { color:var(--muted); }
html[data-theme=dark] .workspace :is(.case-stats .warning,.sample-tag) { color:var(--review-text); }
html[data-theme=dark] .workspace .sample-tag { background:var(--review-bg);border-color:var(--review-line); }
html[data-theme=dark] .workspace :is(.upload-intro p,.upload-intro .small,.intake-upload form p,.empty p) { color:var(--muted); }
html[data-theme=dark] .workspace .queue-tabs a { color:var(--muted); }
html[data-theme=dark] .workspace .queue-tabs b { color:var(--ink);background:var(--light); }
html[data-theme=dark] .workspace .desk { --green:#9bbcff;--green-600:#bdd2ff;--line:#303b4d; }
html[data-theme=dark] .workspace :is(.packet-progress a,.viewer-download,.cancel-review,details>summary) { color:var(--green); }
html[data-theme=dark] .workspace :is(.file-label small,.action-meta span) { color:var(--muted); }
html[data-theme=dark] .workspace .desk .desk-steps button[aria-current]>span { background:#345dba;border-color:#547cce;color:#fff; }
