/* Generated by frontend/build.mjs; edit frontend/ui sources. */
/* Shared semantic colors. Module adapters translate older component names. */
:root {
  color-scheme: light;
  --ui-bg: #f5f8fa;
  --ui-surface: #fff;
  --ui-raised: #f0f5f7;
  --ui-inset: #eaf0f3;
  --ui-text: #203642;
  --ui-muted: #536b79;
  --ui-subtle: #596f7c;
  --ui-border: #d4e0e6;
  --ui-accent: #176b59;
  --ui-action: #236e5e;
  --ui-action-text: #fff;
  --ui-accent-soft: #e6f3ee;
  --ui-danger: #a33636;
  --ui-danger-soft: #fff0ee;
  --ui-warning: #805517;
  --ui-warning-soft: #fff6df;
  --ui-info: #245aa2;
  --ui-info-soft: #eaf2ff;
  --ui-focus: #278a74;
  --ui-radius: 12px;
  --ui-shadow: 0 12px 38px #17333f1a;
}
@media screen {
  html[data-crm-theme='dark'] {
    color-scheme: dark;
    --ui-bg: #101a22;
    --ui-surface: #182630;
    --ui-raised: #20323e;
    --ui-inset: #14212b;
    --ui-text: #e8eff4;
    --ui-muted: #a9bac7;
    --ui-subtle: #9aafbd;
    --ui-border: #3c5261;
    --ui-accent: #78d9bf;
    --ui-action: #236e5e;
    --ui-action-text: #fff;
    --ui-accent-soft: #1d3b35;
    --ui-danger: #ffb4ac;
    --ui-danger-soft: #442c31;
    --ui-warning: #f1cf89;
    --ui-warning-soft: #3c3425;
    --ui-info: #a7cbff;
    --ui-info-soft: #23364d;
    --ui-focus: #8de2ce;
    --ui-shadow: 0 18px 54px #0005;
  }
}
@media print {
  html {
    color-scheme: light !important;
  }
  .crm-appearance,
  .crm-ai-launcher,
  .crm-ai-dialog {
    display: none !important;
  }
}

/* Bridge legacy variables to semantic tokens; remove per module after migration. */
@media screen, print {
  html[data-crm-theme] {
    --ink: var(--ui-text);
    --text: var(--ui-text);
    --muted: var(--ui-muted);
    --green: var(--ui-accent);
    --line: var(--ui-border);
    --paper: var(--ui-bg);
    --pale: var(--ui-accent-soft);
    --red: var(--ui-danger);
    --homa-bg: var(--ui-bg);
    --homa-surface: var(--ui-surface);
    --homa-text: var(--ui-text);
    --homa-muted: var(--ui-muted);
    --homa-soft: var(--ui-raised);
    --homa-line: var(--ui-border);
    --homa-line-strong: var(--ui-border);
    --homa-teal: var(--ui-accent);
    --homa-teal-soft: var(--ui-accent-soft);
    --homa-blue: var(--ui-info);
    --homa-blue-soft: var(--ui-info-soft);
    --homa-green: var(--ui-accent);
    --homa-green-soft: var(--ui-accent-soft);
    --homa-amber: var(--ui-warning);
    --homa-amber-soft: var(--ui-warning-soft);
    --homa-red: var(--ui-danger);
    --homa-red-soft: var(--ui-danger-soft);
    --body-fg: var(--ui-text);
    --body-bg: var(--ui-bg);
    --body-quiet-color: var(--ui-muted);
    --body-loud-color: var(--ui-text);
    --darkened-bg: var(--ui-inset);
    --selected-bg: var(--ui-raised);
    --selected-row: var(--ui-accent-soft);
    --hairline-color: var(--ui-border);
    --border-color: var(--ui-border);
    --link-fg: var(--ui-info);
    --link-hover-color: var(--ui-accent);
    --link-selected-fg: var(--ui-accent);
    --close-button-bg: var(--ui-raised);
    --primary: var(--ui-action);
    --secondary: #225665;
    --accent: #d4ece4;
    --primary-fg: #fff;
    --header-color: #fff;
    --header-branding-color: #fff;
    --header-link-color: #fff;
    --breadcrumbs-fg: var(--ui-text);
    --breadcrumbs-link-fg: var(--ui-info);
    --breadcrumbs-bg: var(--ui-raised);
    --error-fg: var(--ui-danger);
    --message-success-bg: var(--ui-accent-soft);
    --message-warning-bg: var(--ui-warning-soft);
    --message-error-bg: var(--ui-danger-soft);
    --button-bg: var(--ui-action);
    --button-hover-bg: #1c5c4e;
    --default-button-bg: var(--ui-action);
    --default-button-hover-bg: #1c5c4e;
    --close-button-bg: #526773;
    --close-button-hover-bg: #354e5d;
    --bs-body-bg: var(--ui-bg);
    --bs-body-color: var(--ui-text);
    --bs-border-color: var(--ui-border);
    --bs-secondary-color: var(--ui-muted);
    --bs-tertiary-bg: var(--ui-raised);
  }
}

#crm-appearance {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  vertical-align: middle;
  margin: 0 8px;
  padding: 4px 8px;
  border: 1px solid var(--ui-border);
  border-radius: 20px;
  background: var(--ui-surface);
  color: var(--ui-text);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.8;
  box-sizing: border-box;
  direction: inherit;
}
#crm-appearance > span {
  font: 19px/1 sans-serif;
  color: var(--ui-accent);
}
#crm-appearance select {
  appearance: auto;
  display: block;
  width: auto;
  min-width: 64px;
  height: 30px;
  max-width: 86px;
  margin: 0;
  padding: 2px 0;
  border: 0;
  border-radius: 0;
  background: transparent !important;
  color: var(--ui-text) !important;
  font: inherit;
  cursor: pointer;
  box-shadow: none;
}
#crm-appearance option {
  background: var(--ui-surface);
  color: var(--ui-text);
}
#crm-appearance:focus-within {
  outline: 3px solid var(--ui-focus);
  outline-offset: 3px;
}
#crm-appearance select:focus-visible {
  outline: none;
}
#crm-appearance.crm-appearance-floating {
  position: fixed;
  inset: 12px 16px auto auto;
  z-index: 1035;
  box-shadow: var(--ui-shadow);
}
.crm-appearance-host {
  flex-wrap: wrap;
}
.app-header.crm-appearance-host:has(.app-brand) {
  grid-template-columns: 210px minmax(200px, 1fr) auto auto;
}
@media (max-width: 600px) {
  #crm-appearance {
    margin: 4px;
    gap: 4px;
    padding: 3px 6px;
    font-size: 11px;
  }
  #crm-appearance select {
    min-width: 56px;
  }
  .crm-appearance-host {
    gap: 10px !important;
  }
}

/* Bootstrap/admin and shared form, table, navigation and status primitives. */
@media screen {
  html[data-crm-theme='dark'] body {
    background: var(--ui-bg) !important;
    color: var(--ui-text) !important;
  }
  html[data-crm-theme='dark'] :is(h1, h2, h3, h4, h5, h6, legend, label, .form-label) {
    color: var(--ui-text);
  }
  html[data-crm-theme='dark']
    :is(
      .card,
      .modal-content,
      .dropdown-menu,
      .popover,
      .offcanvas,
      .list-group-item,
      dialog,
      .an-card,
      .kpi-card,
      .ai-stat,
      .ai-stat-card,
      .ai-settings-card,
      .ai-section,
      .api-activity-block,
      .api-activity-row,
      .home-tile,
      .module,
      .submit-row,
      .inline-group,
      .results,
      .delivery-card,
      .verify-main
    ) {
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
    box-shadow: none;
  }
  html[data-crm-theme='dark']
    :is(
      .bg-white,
      .bg-light,
      .card-header,
      .card-footer,
      .modal-header,
      .modal-footer,
      .table-light,
      .accordion-button,
      .accordion-body,
      .well,
      .jumbotron,
      .pagination .page-link,
      .list-group-item-action:hover,
      .inline-related h3,
      .selector-available h2,
      .selector-chosen h2
    ) {
    background: var(--ui-raised) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(.navbar-zone, #header, #sidebar, .masthead, .app-header, .homa-appbar) {
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .navbar-brand,
      .navbar-dark .navbar-nav .nav-link,
      #sidebar a,
      #header a,
      .back-link,
      .back-crm,
      .crm-link,
      .system-name,
      .app-name
    ) {
    color: var(--ui-text) !important;
  }
  html[data-crm-theme='dark']
    :is(a:not([class]), .text-button, .text-primary, .text-info, .link-primary, .signature-link) {
    color: var(--ui-info) !important;
  }
  html[data-crm-theme='dark'] :is(.text-dark, .text-black, .text-body, .text-black-50) {
    color: var(--ui-text) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .text-muted,
      .text-secondary,
      .text-body-secondary,
      .muted,
      .hint,
      .field-help,
      .form-text,
      .help,
      .helptext,
      .optional,
      .eyebrow,
      .page-footer,
      .filter-help,
      .back-link small,
      .delta-note,
      .an-note
    ) {
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme='dark'] :is(p, small) {
    color: inherit;
  }
  html[data-crm-theme='dark']
    :is(
      input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='button']):not(
          [type='submit']
        ):not([type='color']),
      textarea,
      select,
      .form-control,
      .form-select,
      .select2-selection,
      .select2-dropdown,
      .input-group-text,
      .vTextField,
      .vLargeTextField
    ) {
    background: var(--ui-inset) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark'] :is(input, textarea)::placeholder {
    color: var(--ui-subtle) !important;
    opacity: 1;
  }
  html[data-crm-theme='dark'] :is(input, textarea, select):disabled {
    background: var(--ui-raised) !important;
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme='dark'] input:is([type='checkbox'], [type='radio'], [type='range']) {
    accent-color: var(--ui-accent);
  }
  html[data-crm-theme='dark']
    :is(
      .select2-container--default .select2-selection--single .select2-selection__rendered,
      .select2-results__option,
      .select2-selection__choice
    ) {
    color: var(--ui-text);
    background-color: var(--ui-surface);
  }
  html[data-crm-theme='dark']
    :is(
      .btn-light,
      .btn-light2,
      .btn-outline-dark,
      .btn-outline-secondary,
      .btn-outline-light,
      .secondary,
      .export-button,
      .cf-secondary,
      .icon-button,
      .homa-button-secondary
    ) {
    background: var(--ui-raised) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .btn-zone,
      .btn-primary,
      .btn-success,
      .primary,
      .cf-primary,
      .homa-button,
      .homa-brand-mark,
      .homa-button-success
    ) {
    background: var(--ui-action) !important;
    color: var(--ui-action-text) !important;
    border-color: var(--ui-action) !important;
  }
  html[data-crm-theme='dark']
    :is(.btn-zone, .btn-primary, .btn-success, .primary, .cf-primary, .homa-button):hover {
    background: #2b826e !important;
    color: #fff !important;
  }
  html[data-crm-theme='dark'] :is(.btn-outline-primary, .btn-outline-success) {
    color: var(--ui-accent) !important;
    border-color: var(--ui-accent) !important;
    background: transparent !important;
  }
  html[data-crm-theme='dark'] .btn-outline-danger {
    color: var(--ui-danger);
    border-color: var(--ui-danger);
    background: transparent;
  }
  html[data-crm-theme='dark'] .btn-outline-danger:hover {
    background: var(--ui-danger-soft);
  }
  html[data-crm-theme='dark'] input[type='file']::file-selector-button {
    background: var(--ui-raised);
    color: var(--ui-text);
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark'] :is(table, .table) {
    color: var(--ui-text) !important;
    --bs-table-bg: transparent;
    --bs-table-accent-bg: transparent;
    --bs-table-color: var(--ui-text);
    --bs-table-striped-color: var(--ui-text);
    --bs-table-hover-color: var(--ui-text);
  }
  html[data-crm-theme='dark'] :is(th, thead td) {
    background: var(--ui-raised) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark'] :is(td, tbody th) {
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(tbody tr:nth-child(even), .table-striped tbody tr:nth-of-type(odd)) {
    background: color-mix(in srgb, var(--ui-raised) 40%, transparent) !important;
  }
  html[data-crm-theme='dark'] :is(tbody tr:hover, .table-hover tbody tr:hover) {
    background: var(--ui-raised) !important;
  }
  html[data-crm-theme='dark'] :is(.text-success, .good, .delta.up, .cf-inflow-value) {
    color: var(--ui-accent) !important;
  }
  html[data-crm-theme='dark']
    :is(.text-danger, .bad, .danger-text, .errorlist, .field-error, .cf-negative) {
    color: var(--ui-danger) !important;
  }
  html[data-crm-theme='dark'] :is(.text-warning) {
    color: var(--ui-warning) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .alert-success,
      .success,
      .badge.ready,
      .badge.issued,
      .badge.public,
      .delta.up,
      .homa-chip.success,
      .status.verified
    ) {
    background: var(--ui-accent-soft) !important;
    color: var(--ui-accent) !important;
    border-color: #3e6b5e !important;
  }
  html[data-crm-theme='dark']
    :is(
      .alert-danger,
      .alert-error,
      .form-error,
      .inline-error,
      .mail-error,
      .error,
      .warning.error,
      .badge.revoked,
      .delta.down,
      .homa-chip.danger,
      .message.error
    ) {
    background: var(--ui-danger-soft) !important;
    color: var(--ui-danger) !important;
    border-color: #805253 !important;
  }
  html[data-crm-theme='dark']
    :is(
      .alert-warning,
      .warning,
      .notice.warning,
      .an-warn,
      .pending-banner,
      .pending-note,
      .homa-chip.warning,
      .cf-warnings
    ) {
    background: var(--ui-warning-soft) !important;
    color: var(--ui-warning) !important;
    border-color: #77613c !important;
  }
  html[data-crm-theme='dark']
    :is(
      .alert-info,
      .badge,
      .status.neutral,
      .range-chip,
      .pill,
      .tag,
      .chip,
      .delta.flat,
      .notice,
      .api-activity-badge
    ) {
    background: var(--ui-info-soft);
    color: var(--ui-info);
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark']
    :is(.nav-tabs .nav-link, .nav-tabs > li > a, .tabs button, .folder-button, .folders button) {
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .nav-tabs .nav-link.active,
      .tabs button.selected,
      .folder-button.active,
      .folders button.active,
      .page-item.active .page-link,
      .select2-results__option--highlighted
    ) {
    background: var(--ui-accent-soft) !important;
    color: var(--ui-accent) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .datepicker-plot-area,
      .datepicker-plot-area .datepicker-day-view,
      .datepicker-plot-area .datepicker-month-view,
      .datepicker-plot-area .datepicker-year-view,
      .datepicker-plot-area .datepicker-navigator,
      .datepicker-plot-area .toolbox,
      .calendarbox,
      .clockbox
    ) {
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    .datepicker-plot-area
    :is(button, .table-days td span, .table-days th, .month-item, .year-item) {
    background: transparent !important;
    color: var(--ui-text) !important;
  }
  html[data-crm-theme='dark'] .datepicker-plot-area .selected span {
    background: var(--ui-action) !important;
    color: #fff !important;
  }
  html[data-crm-theme='dark'] .datepicker-plot-area .other-month span {
    color: var(--ui-subtle) !important;
  }
  html[data-crm-theme='dark'] :is(.brand img, .app-brand img, .logo-me) {
    background: #fff;
    border-radius: 6px;
    padding: 3px;
  }
  html[data-crm-theme='dark']
    :is(hr, .border, .border-top, .border-bottom, .border-start, .border-end, fieldset) {
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark'] :is(pre, code):not(.crm-ai-message-text) {
    background: var(--ui-inset);
    color: var(--ui-text);
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark'] :is(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid var(--ui-focus);
    outline-offset: 3px;
  }
  html[data-crm-theme='dark'] ::selection {
    background: #376a60;
    color: #fff;
  }
  html[data-crm-theme='dark'] dialog::backdrop {
    background: #030b12b8;
    backdrop-filter: blur(5px);
  }
  html[data-crm-theme='dark'] .btn-close {
    filter: invert(1);
  }
}

/* Sales, finance, Homa, attendance and legacy CRM screens. */
@media screen {
  html[data-crm-theme='dark']
    :is(
      .ai-chat-settings,
      .ai-stat-row > div,
      .ai-settings-panel,
      .mini-split .part,
      .kpi-card,
      .preset-chips button,
      .toggle-chips button,
      .cf-panel,
      .cf-kpi,
      .cf-model-card,
      .cf-model-weights span,
      .homa-admin-request,
      .homa-loan-card,
      .report-text,
      .filters,
      .filter-help,
      .day-times,
      .location-panel
    ) {
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .k-value,
      .mini-split .v,
      .an-section-title,
      .ai-settings-title,
      .cf-kpi-number,
      .history-summary strong,
      .clock,
      .day-times strong,
      .homa-metric-value
    ) {
    color: var(--ui-text) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .k-label,
      .k-sub,
      .k-value small,
      .mini-split .t,
      .mini-split .s,
      .delta-note,
      .cf-eyebrow,
      .cf-chart-meta,
      .cf-kpi-note,
      .cf-current span,
      .cf-interval,
      .day-times span,
      .clock-caption,
      .identity span,
      .table-footer,
      .record-username,
      .date-day,
      .coordinates,
      .out-date,
      .report-phase,
      .report-hint,
      .ai-settings-header .small
    ) {
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .preset-chips button.active,
      .toggle-chips button.active,
      .cf-chart-tabs button[aria-pressed='true'],
      .cf-presets button[aria-pressed='true']
    ) {
    background: var(--ui-accent-soft) !important;
    color: var(--ui-accent) !important;
    border-color: #407765 !important;
  }
  html[data-crm-theme='dark'] .cf {
    --cf-ink: var(--ui-text);
    --cf-muted: var(--ui-muted);
    --cf-line: var(--ui-border);
    --cf-green: var(--ui-accent);
    --cf-red: var(--ui-danger);
  }
  html[data-crm-theme='dark'] .cf-kpi-featured {
    background: #20493f !important;
    color: #fff !important;
    border-color: #45786b !important;
  }
  html[data-crm-theme='dark'] .cf-kpi-featured :is(small, .cf-kpi-note) {
    color: #c9e4dc !important;
  }
  html[data-crm-theme='dark']
    :is(
      .cf-current,
      .cf-tag,
      .cf-chart-tabs,
      .cf-chart-readout,
      .cf-presets button,
      .cf-status,
      .editing
    ) {
    background: var(--ui-raised) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark'] :is(.cf-table .cf-scheduled, .cf-warnings) {
    background: var(--ui-warning-soft) !important;
    color: var(--ui-warning) !important;
  }
  html[data-crm-theme='dark'] :is(.cf-table tr.cf-negative-row, .cf-error) {
    background: var(--ui-danger-soft) !important;
    color: var(--ui-danger) !important;
  }
  html[data-crm-theme='dark'] .cf-chart text {
    fill: var(--ui-muted);
  }
  html[data-crm-theme='dark'] .cf-chart rect[fill='#f3f8f5'] {
    fill: #203b37;
  }
  html[data-crm-theme='dark'] .cf-chart path[fill='#cce5da'] {
    fill: #396859;
  }
  html[data-crm-theme='dark'] .cf-chart line {
    stroke: var(--ui-border);
  }
  html[data-crm-theme='dark'] .cf-chart :is(path, circle)[stroke='#147d73'] {
    stroke: #78d9bf;
  }
  html[data-crm-theme='dark'] .cf-chart :is(path, circle)[stroke='#a46b46'] {
    stroke: #efba91;
  }
  html[data-crm-theme='dark'] .cf-chart circle[fill='#147d73'] {
    fill: #78d9bf;
  }
  html[data-crm-theme='dark'] .cf-chart circle[fill='#a46b46'] {
    fill: #efba91;
  }
  html[data-crm-theme='dark'] .cf-chart circle[fill='white'] {
    fill: var(--ui-surface);
  }
  html[data-crm-theme='dark'] .cf-legend-band {
    background: #396859;
  }
  html[data-crm-theme='dark'] :is(.cf-legend-solid, .cf-legend-dash) {
    border-color: var(--ui-accent);
  }
  html[data-crm-theme='dark'] #an_loading {
    background: #101a22b8;
  }
  html[data-crm-theme='dark']
    :is(#map-placeholder, .map-wrap, .report-minimum, .report-timer, .avatar, .round-icon) {
    background: var(--ui-raised);
    color: var(--ui-accent);
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark'] #map-placeholder {
    background: linear-gradient(135deg, #20323e, #14242e);
  }
  html[data-crm-theme='dark']
    :is(.map-check, .leaflet-popup-content-wrapper, .leaflet-popup-tip, .leaflet-control-zoom a) {
    background: var(--ui-surface);
    color: var(--ui-text);
  }
  html[data-crm-theme='dark'] .leaflet-control-attribution {
    background: #fff;
    color: #33434e;
  }
  html[data-crm-theme='dark'] .leaflet-control-attribution a {
    color: #17658c !important;
  }
  html[data-crm-theme='dark'] :is(.homa-rule-icon, .homa-chip.neutral, .homa-mini-grid > div) {
    background: var(--ui-raised);
    color: var(--ui-text);
  }
  html[data-crm-theme='dark'] [style*='background-color: #fff'],
  html[data-crm-theme='dark'] [style*='background: white'] {
    background-color: var(--ui-surface) !important;
  }
}

/* Meetings, files, mail, documents, endpoint administration and personal notes. */
@media screen {
  html[data-crm-theme='dark']
    :is(
      .meeting-card,
      .empty,
      .archive-panel,
      .speaker-card,
      .asset-row,
      .file-main,
      .action-menu,
      .upload-panel,
      .wizard-shell,
      .address-card,
      .ready-address,
      .mail-content,
      .message-pane,
      .mail-sidebar,
      .message-row,
      .sidebar,
      .letter-row,
      .editor-top,
      .inspector,
      .format-toolbar,
      .signature-card,
      .replay-kpis > div,
      #people-results,
      #drop-hint
    ) {
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .intro-strip,
      .archive-note,
      .join-banner,
      .type-icon,
      .mode-options label:has(input:checked),
      .minutes-sharing,
      .welcome-panel,
      .mail-sidebar,
      .message-toolbar,
      .compose-footer,
      .pending-banner,
      .file-location,
      .search-box,
      .search,
      .paper-workspace,
      .steps .current span,
      .steps .done span,
      .account-avatar,
      .folder-button .folder-count
    ) {
    background: var(--ui-raised) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .meeting-card:hover,
      .file-row:hover,
      .file-row.menu-active,
      .message-row:hover,
      .action-menu button:hover,
      .action-menu button:focus-visible,
      .move-folder:hover,
      .letter-row:hover
    ) {
    background: var(--ui-raised) !important;
  }
  html[data-crm-theme='dark'] :is(.message-row.active, .file-nav > button.selected) {
    background: var(--ui-accent-soft) !important;
    color: var(--ui-accent) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .card-bottom,
      .time,
      .person small,
      .minutes-section p,
      .minutes-section ul,
      .transcript-row p,
      .speaker-card blockquote,
      .file-meta,
      .file-mobile-meta,
      .account-label small,
      .log-meta,
      .link-row small,
      .header-caption,
      .list-head,
      .list-note,
      .nav-label,
      .sidebar-caption,
      .row-preview,
      .message-date,
      .message-from,
      .attachment-chip small,
      .replay-link-row small,
      .replay-table small,
      .privacy-note
    ) {
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .replay-kpis strong,
      .minutes-section h3,
      .transcript-row time,
      .file-label > button:hover
    ) {
    color: var(--ui-accent) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .replay-links,
      .replay-stats,
      .replay-link-row,
      .minutes-sharing-footer,
      .speaker-card,
      .card-bottom,
      .transcript-row,
      .asset-row,
      .archive-tabs,
      .meeting-card,
      .file-row,
      .message-row,
      .message-toolbar,
      .compose-footer,
      .attachment-chip
    ) {
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark']
    :is(
      .attachment-chip,
      .event pre,
      .log-event pre,
      .format-toolbar button:hover,
      .signing-code-box,
      .verified-line
    ) {
    background: var(--ui-inset) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark'] :is(.privacy-note, .card-photo-frame, .card-photo-guide) {
    background: var(--ui-raised);
    color: var(--ui-muted);
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark'] :is(.replay-page, .room-page) {
    background: var(--ui-bg) !important;
  }
  html[data-crm-theme='dark'] .toast {
    background: #d9ede7 !important;
    color: #173b30 !important;
  }
  html[data-crm-theme='dark'] #crm-note {
    background: var(--ui-surface);
    border-color: var(--ui-border);
    color: var(--ui-text);
    box-shadow: var(--ui-shadow);
  }
  html[data-crm-theme='dark'] #crm-note .crm-note-header {
    background: var(--ui-raised);
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark']
    #crm-note
    :is(
      .crm-note-grip,
      .crm-note-icon,
      .crm-note-footer,
      .crm-note-footer button,
      [data-note-count]
    ) {
    color: var(--ui-muted);
  }
  html[data-crm-theme='dark'] #crm-note :is(textarea, .crm-note-editor) {
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
  }
  html[data-crm-theme='dark'] :is(#crm-note-settings, .crm-note-conflict, .crm-note-voice-message) {
    background: var(--ui-raised) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
  }
  html[data-crm-theme='dark'] #crm-note-settings :is(h2, label, button) {
    color: var(--ui-text);
  }
  html[data-crm-theme='dark'] body:has(.scroll) > main > section,
  html[data-crm-theme='dark'] body:has(form input[name='notice']) > main {
    background: var(--ui-surface) !important;
    border-color: var(--ui-border);
    color: var(--ui-text);
  }
  /* Paper and captured media are content, not themed application surfaces. */
  html[data-crm-theme='dark']
    :is(
      .letter-page,
      .contract-readable-body,
      .contract-document,
      .invoice-print,
      .signature-canvas-section canvas,
      #public-canvas,
      #saved-signature,
      #delivery-signature
    ) {
    background: #fff !important;
    color: #24323d !important;
    color-scheme: light;
  }
  html[data-crm-theme='dark']
    :is(.letter-page, .contract-readable-body, .contract-document, .invoice-print) {
    --ui-text: #24323d;
    --ui-muted: #536b79;
    --ui-border: #b8c5cf;
    --ui-info: #245aa2;
    --ui-accent: #176b59;
  }
  html[data-crm-theme='dark']
    :is(.letter-page, .contract-readable-body, .contract-document, .invoice-print)
    :is(th, thead td) {
    background: #edf2f5 !important;
    border-color: #b8c5cf !important;
  }
  html[data-crm-theme='dark']
    :is(.letter-page, .contract-readable-body, .contract-document, .invoice-print)
    :is(tbody tr, tbody tr:hover) {
    background: transparent !important;
  }
  html[data-crm-theme='dark'] iframe {
    color-scheme: light;
  }
}

/* Homa still owns its layout; its hard-coded surfaces resolve here. */
@media screen {
  html[data-crm-theme='dark']
    :is(
      .homa-panel,
      .homa-metric,
      .homa-list-item,
      .homa-rule,
      .homa-step,
      .homa-empty,
      .homa-table-wrap,
      .homa-message
    ) {
    background: var(--ui-surface);
    border-color: var(--ui-border);
    color: var(--ui-text);
  }
  html[data-crm-theme='dark']
    :is(
      .homa-check,
      .homa-mini-grid > div,
      .homa-button-secondary,
      .homa-user .homa-icon-button,
      .homa-progress
    ) {
    background: var(--ui-raised) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark']
    :is(
      .homa-nav a,
      .homa-rule-text,
      .homa-rule span:last-child,
      .homa-field label,
      .homa-check label
    ) {
    color: var(--ui-text);
  }
  html[data-crm-theme='dark'] :is(.homa-step.active, .homa-step.done) {
    background: var(--ui-accent-soft);
    color: var(--ui-accent);
    border-color: #407765;
  }
  html[data-crm-theme='dark'] .homa-button-danger {
    background: var(--ui-danger-soft) !important;
    color: var(--ui-danger) !important;
    border-color: #805253 !important;
  }
}

@media screen {
  html[data-crm-theme='dark'] .recon {
    --ink: var(--ui-text);
    --muted: var(--ui-muted);
    --line: var(--ui-border);
    --teal: var(--ui-accent);
    --pale: var(--ui-accent-soft);
  }
  html[data-crm-theme='dark']
    :is(
      .recon-panel,
      .statement-sheet,
      .statement-choice,
      #recon-exports,
      .date-fields,
      .ledger-exports summary,
      .candidate-tools summary,
      .recon-secondary,
      .quiet-button,
      .inspect-button,
      .pick-button
    ) {
    background: var(--ui-surface) !important;
    color: var(--ui-text);
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark'] :is(.match-footer, .payment-options) {
    background: var(--ui-raised);
  }
  html[data-crm-theme='dark']
    :is(
      .statement-choice[aria-pressed='true'],
      .selection-chip,
      .match-modes button[aria-pressed='true'],
      .pick-button[aria-pressed='true']
    ) {
    background: var(--ui-accent-soft) !important;
    color: var(--ui-accent) !important;
  }
  html[data-crm-theme='dark'] :is(.recon-alert, #match-error, .recon-remove) {
    background: var(--ui-danger-soft);
    color: var(--ui-danger);
  }
  html[data-crm-theme='dark'] .recon .recon-primary {
    background: var(--ui-action);
    color: var(--ui-action-text);
    border-color: var(--ui-action);
  }
  html[data-crm-theme='dark'] .recon a {
    color: var(--ui-info);
  }
  html[data-crm-theme='dark'] :is(#recon-status, #model-feedback, .entry-warning) {
    color: var(--ui-warning);
  }
  html[data-crm-theme='dark'] .bank-table tr {
    --row-bg: var(--ui-surface);
    --status-ink: var(--ui-muted);
  }
  html[data-crm-theme='dark'] .bank-table .tone-matched {
    --row-bg: var(--ui-accent-soft);
    --status-ink: var(--ui-accent);
  }
  html[data-crm-theme='dark'] .bank-table .tone-missing {
    --row-bg: var(--ui-danger-soft);
    --status-ink: var(--ui-danger);
  }
  html[data-crm-theme='dark'] .bank-table .tone-attention {
    --row-bg: var(--ui-warning-soft);
    --status-ink: var(--ui-warning);
  }
  html[data-crm-theme='dark'] .bank-table .tone-fee {
    --row-bg: var(--ui-raised);
    --status-ink: var(--ui-muted);
  }
  html[data-crm-theme='dark'] .bank-table :is(.row-index, .no-amount) {
    color: var(--ui-muted);
  }
}

/* Legacy captions and controls share semantic colors in BOTH appearances. */
@media screen {
  html[data-crm-theme]
    :is(
      .text-muted,
      .text-secondary,
      .hint,
      .field-help,
      .form-text,
      .help,
      .helptext,
      .optional,
      .eyebrow,
      .page-footer,
      .filter-help,
      .header-caption,
      .nav-label,
      .list-head,
      .list-note,
      .file-table-header,
      .file-meta,
      .file-size,
      .file-status,
      .logging-info,
      .account-label small,
      .sidebar-foot small,
      .clock-caption,
      .today-label,
      .day-times span,
      .action-help,
      .map-heading > span,
      .map-footer span,
      .history-heading p,
      .page-heading p,
      .identity span:not(.avatar),
      .filters label,
      .date-input > span,
      .step-caption,
      .assurance-note,
      .field,
      .empty-hint,
      .letter-sender,
      .letter-number,
      .letter-date,
      .message-date,
      .row-preview,
      .file-mobile-meta,
      .table-footer,
      .privacy-note,
      .section-heading p,
      .ai-stat span,
      .homa-metric-note,
      .sidebar-caption,
      .pagination span,
      .message-from,
      #message-from,
      .sender-line time,
      .recipient-lines,
      .field small,
      #page-count,
      .welcome-foot,
      .welcome-panel p,
      .subtle-note,
      .account-address,
      .row-sender,
      .row-time,
      .list-tools,
      .list-empty,
      .message-empty p,
      .compose-from,
      .compose-from strong,
      .recipient-field label,
      .replay-shell header p,
      .replay-controls small,
      .replay-notice,
      #folder-owner,
      #save-state
    ) {
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme]
    :is(
      .empty p,
      .empty-symbol,
      .search > span,
      .crm-link,
      .back-crm,
      .file-nav > button,
      .account-label,
      .folders button,
      .folders button span,
      .text-button,
      .steps li,
      .enrollment-steps li
    ) {
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme] :is(.empty strong, .ai-stat strong, thead th, .card-header) {
    color: var(--ui-text) !important;
  }
  html[data-crm-theme]
    :is(
      .folders button.active,
      .folders button.active span,
      .file-nav > button.selected,
      .account-avatar,
      .avatar,
      .steps .current,
      .steps .done,
      .enrollment-steps .done
    ) {
    color: var(--ui-accent) !important;
  }
  html[data-crm-theme] :is(.account-avatar, .avatar, .steps b) {
    background: var(--ui-accent-soft);
    color: var(--ui-accent);
  }
  html[data-crm-theme] :is(.steps li b, .enrollment-steps li b) {
    background: var(--ui-raised);
    color: var(--ui-text);
  }
  html[data-crm-theme] :is(.steps .current b, .steps .done b) {
    background: var(--ui-accent-soft);
    color: var(--ui-accent);
  }
  html[data-crm-theme] .primary {
    background: var(--ui-action);
    color: var(--ui-action-text);
  }
  html[data-crm-theme] .primary:hover {
    background: #1c5c4e;
  }
  html[data-crm-theme] :is(.pending-note, .warning) {
    color: var(--ui-warning);
    background: var(--ui-warning-soft);
  }
  html[data-crm-theme] :is(.status.neutral, .badge) {
    color: var(--ui-info);
    background: var(--ui-info-soft);
  }
  html[data-crm-theme] :is(.ai-chat-settings a, .an-page a:not(.btn)) {
    color: var(--ui-info);
  }
  html[data-crm-theme] #crm-note :is(.crm-note-footer, .crm-note-footer button, [data-note-count]) {
    color: var(--ui-muted);
  }
  html[data-crm-theme]
    .crm-ai
    :is(
      .crm-ai-eyebrow,
      .crm-ai-header,
      .crm-ai-header small,
      .crm-ai-intro p,
      .crm-ai-message-label,
      .crm-ai-status,
      .crm-ai-footnote
    ) {
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme] .crm-ai textarea::placeholder {
    color: var(--ui-subtle) !important;
  }
  html[data-crm-theme] .empty-state > span {
    color: var(--ui-muted);
  }
  html[data-crm-theme] :is(.draft-watermark, .pending-signature) {
    color: #596f7c;
  }
  html[data-crm-theme='dark'] .message-body {
    color: var(--ui-text);
  }
  html[data-crm-theme='light']
    :is(.btn-outline-secondary, .btn-outline-primary, .nav-tabs .nav-link) {
    color: var(--ui-info);
  }
  html[data-crm-theme='light'] :is(.btn-outline-secondary:hover, .btn-outline-primary:hover) {
    background: var(--ui-action);
    color: var(--ui-action-text);
  }
  html[data-crm-theme='light'] :is(#mainbar table td a:not(.btn), .art-spark) {
    color: var(--ui-accent);
  }
}

@media screen {
  html[data-crm-theme='dark'] .crm-ai {
    --ai-ink: var(--ui-text);
    --ai-accent: var(--ui-accent);
    color: var(--ui-text);
  }
  html[data-crm-theme='dark'] .crm-ai .crm-ai-dialog {
    background: transparent !important;
    color: var(--ui-text) !important;
    box-shadow: var(--ui-shadow);
  }
  html[data-crm-theme='dark'] .crm-ai :is(.crm-ai-panel, .crm-ai-compose) {
    background: var(--ui-surface);
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark'] .crm-ai .crm-ai-header {
    border-color: var(--ui-border);
    color: var(--ui-muted);
  }
  html[data-crm-theme='dark']
    .crm-ai
    :is(
      .crm-ai-eyebrow,
      .crm-ai-header small,
      .crm-ai-intro p,
      .crm-ai-status,
      .crm-ai-message-label,
      .crm-ai-footnote
    ) {
    color: var(--ui-muted) !important;
  }
  html[data-crm-theme='dark'] .crm-ai :is(.crm-ai-close, .crm-ai-intro > span) {
    background: var(--ui-raised);
    color: var(--ui-accent);
  }
  html[data-crm-theme='dark']
    .crm-ai
    :is(
      .crm-ai-message,
      .crm-ai-starters button,
      .crm-ai-form,
      .crm-ai-header button,
      .crm-ai-reload,
      .crm-ai-sources a
    ) {
    background: var(--ui-inset);
    color: var(--ui-text) !important;
    border-color: var(--ui-border);
  }
  html[data-crm-theme='dark'] .crm-ai .crm-ai-message[data-role='user'] {
    background: var(--ui-accent-soft);
    border-color: #3e695c;
  }
  html[data-crm-theme='dark'] .crm-ai .crm-ai-send {
    background: var(--ui-action);
    color: #fff;
  }
  html[data-crm-theme='dark'] .crm-ai .crm-ai-orb {
    background:
      radial-gradient(at 20% 0%, #454674, transparent 65%),
      linear-gradient(135deg, #233846, #204339);
    color: #a0e5d3;
    border-color: #49636d;
  }
  html[data-crm-theme='dark'] .crm-ai .crm-ai-error {
    background: var(--ui-danger-soft);
    color: var(--ui-danger);
  }
  html[data-crm-theme='dark'] .crm-ai textarea {
    background: transparent !important;
  }
  html[data-crm-theme] .crm-ai textarea:focus-visible {
    outline: none;
  }
  html[data-crm-theme='dark'] .crm-ai-form:focus-within {
    border-color: var(--ui-focus);
    box-shadow: 0 0 0 3px #78d9bf26;
  }
}
