/* CRM interface theme switch and dark palette. Business documents and print remain light. */
:root{
  --page-bg:var(--page);
  --surface:var(--panel);
  --surface-muted:#f7f9fc;
  --text-muted:var(--muted);
  --control-border:#cfd7e0;
  --control-border-focus:#7ea2d2;
  --control-placeholder:#8a96a3;
  --link:#2f66ad;
}

.crm-theme-switcher{display:flex;align-items:center;margin:0}
.crm-theme-switch{display:inline-flex;align-items:center;gap:5px;min-height:30px;border:0;border-radius:16px;padding:2px 4px;background:transparent;color:var(--muted);cursor:pointer;font:inherit}
.crm-theme-switch:hover{background:#f5f8fc}
.crm-theme-switch:focus-visible{outline:2px solid rgba(79,122,193,.38);outline-offset:1px}
.crm-theme-icon{display:inline-grid;place-items:center;width:14px;height:14px;color:#8a94a1;transition:color .14s ease}
.crm-theme-icon svg{display:block;width:14px;height:14px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
.crm-theme-switch:not(.is-dark) .crm-theme-icon.is-light,.crm-theme-switch.is-dark .crm-theme-icon.is-dark{color:#2f66ad}
.crm-theme-track{position:relative;display:block;width:34px;height:20px;flex:0 0 34px;border:1px solid #4f78b7;border-radius:999px;background:var(--accent);box-shadow:inset 0 1px 2px rgba(22,45,77,.16);transition:background-color .14s ease,border-color .14s ease}
.crm-theme-thumb{position:absolute;top:1px;left:1px;width:16px;height:16px;border-radius:50%;background:#fff;box-shadow:0 1px 3px rgba(22,37,55,.32);transform:translateX(0);transition:transform .16s ease}
.crm-theme-switch.is-dark .crm-theme-thumb{transform:translateX(14px)}
.crm-theme-switch:hover .crm-theme-track{border-color:#365f9f;background:var(--accent-dark)}
.auth-card-header .crm-theme-switcher{flex:0 0 auto}

html[data-theme="dark"]{
  color-scheme:dark;
  --sidebar:#111923;
  --sidebar-hover:#1b2a3a;
  --sidebar-active:#263b52;
  --page:#0f151c;
  --page-bg:#0f151c;
  --panel:#18212b;
  --surface:#18212b;
  --surface-muted:#202b37;
  --text:#d2d9e3;
  --text-primary:#d2d9e3;
  --text-heading:#e7ecf3;
  --text-secondary:#a5b0bf;
  --text-muted:#a5b0bf;
  --muted:#a5b0bf;
  --text-disabled:#748091;
  --text-closed:#8994a3;
  --link-closed:#798ca8;
  --finance-positive:#55b978;
  --finance-negative:#e46565;
  --border:#2c3946;
  --accent:#6f9bdb;
  --accent-dark:#83abe5;
  --link:#8fb8f4;
  --success:#54b878;
  --warning:#d9a552;
  --danger:#df7373;
  --toolbar-bg:#1b2a3b;
  --toolbar-border:#31465d;
  --control-border:#3a4958;
  --control-border-focus:#6e98d1;
  --control-placeholder:#738191;
  --tab-active-bg:#24364a;
  --tab-active-text:#9fc0ef;
}

html[data-theme="dark"],html[data-theme="dark"] body{background:var(--page);color:var(--text)}
html[data-theme="dark"] body{accent-color:var(--accent)}
html[data-theme="dark"] ::selection{background:#355f91;color:#fff}
html[data-theme="dark"] *{scrollbar-color:#445363 #111820}

/* Main shell, navigation and top bar. */
html[data-theme="dark"] .workspace,
html[data-theme="dark"] .content{background:var(--page)}
html[data-theme="dark"] .topbar{background:#151d26;border-color:var(--border)}
html[data-theme="dark"] .topbar-title,
html[data-theme="dark"] .topbar-title-main{color:var(--text)}
html[data-theme="dark"] .topbar-title-subtitle,
html[data-theme="dark"] .topbar-section-icon,
html[data-theme="dark"] .sidebar-toggle,
html[data-theme="dark"] .logout-button{color:var(--muted)}
html[data-theme="dark"] .sidebar-toggle:hover,
html[data-theme="dark"] .logout-button:hover{color:var(--text)}
html[data-theme="dark"] .user-avatar{background:#263b52;color:#a9c8f2}
html[data-theme="dark"] .park-switcher-menu{background:#17212b;border-color:#344252;color:var(--text);box-shadow:0 12px 28px rgba(0,0,0,.48)}
html[data-theme="dark"] .park-switcher-option{background:#17212b;border-color:#283644;color:var(--text)}
html[data-theme="dark"] .park-switcher-option:hover{background:#203044}
html[data-theme="dark"] .park-switcher-option.is-current{background:#24364a;color:#9fc0ef}
html[data-theme="dark"] .park-switcher-option small{color:var(--muted)}
html[data-theme="dark"] .sidebar-backdrop{background:rgba(2,7,12,.62)}

/* Theme and language controls. */
html[data-theme="dark"] .crm-language-switch:hover,
html[data-theme="dark"] .crm-theme-switch:hover{background:#202b37}
html[data-theme="dark"] .crm-language-label,
html[data-theme="dark"] .crm-theme-icon{color:#788696}
html[data-theme="dark"] .crm-language-label.is-active,
html[data-theme="dark"] .crm-theme-switch.is-dark .crm-theme-icon.is-dark{color:#9fc0ef}
html[data-theme="dark"] .crm-language-track,
html[data-theme="dark"] .crm-theme-track{border-color:#789fd1;background:#527eb9}
html[data-theme="dark"] .crm-language-thumb,
html[data-theme="dark"] .crm-theme-thumb{background:#e9eef5;box-shadow:0 1px 4px rgba(0,0,0,.55)}

/* General surfaces and cards. */
html[data-theme="dark"] :where(
  .panel,.form-panel,.dashboard-section,.dashboard-debt,.dashboard-schedule,.dashboard-vehicles,
  .dashboard-vehicle-list,.driver-summary,.vehicle-live-card,.report-summary-grid,.auth-card,
  .crm-modal-card,.crm-help-panel,.crm-process-board,.entity-form-actions,.notification-broadcast-list-area,
  .notification-broadcast-composer,.payment-schedule-page-heading,.yandex-finance-compact,.yandex-profile-mapping,
  .contract-document-menu-popover,.rent-journal-detail-table,.park-settings-provider,.park-schedule-primary-card,
  .park-schedule-notifications,.list-columns-box,.document-capture-card,.document-capture-message,
  .driver-document-import-card,.contract-paused-panel,.gps-link-candidate,.statement-log-status,
  .telegram-topbar-dropdown,.combobox-menu,.due-group-list,.file-upload-progress-box
){background:var(--panel);border-color:var(--border);color:var(--text);box-shadow:none}
html[data-theme="dark"] :where(.panel-header,.crm-modal-header,.crm-modal-footer,.list-footer,.modal-head,.modal-actions){border-color:var(--border)}
html[data-theme="dark"] .panel-header{background:#1b2631}
html[data-theme="dark"] .panel-header h2,
html[data-theme="dark"] .page-heading h1,
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] strong{color:var(--text)}
html[data-theme="dark"] :where(.muted,.cell-secondary,.field-help,.form-help,.modal-note,.group-label,.contract-type){color:var(--muted)}

/* Forms and controls. */
html[data-theme="dark"] :where(input,select,textarea):focus{border-color:var(--control-border-focus);outline-color:rgba(111,155,219,.25)}
html[data-theme="dark"] :where(input,select,textarea):disabled{background:#202a34;color:#748191;border-color:#303d49}
html[data-theme="dark"] input[type="checkbox"]{background:#111a23;border-color:#556575}
html[data-theme="dark"] input[type="checkbox"]:checked{background:var(--accent);border-color:var(--accent)}
html[data-theme="dark"] .button-secondary,
html[data-theme="dark"] .action-link,
html[data-theme="dark"] .search-trigger,
html[data-theme="dark"] .field-icon-button,
html[data-theme="dark"] .mini-action,
html[data-theme="dark"] .quick-action,
html[data-theme="dark"] .crm-icon-button,
html[data-theme="dark"] .form-action-icon,
html[data-theme="dark"] .list-add-action,
html[data-theme="dark"] .list-toolbar .button-add,
html[data-theme="dark"] .panel-header .button-add{background:#18232e;color:#8eb3e7;border-color:#3b5067}
html[data-theme="dark"] :where(.button-secondary,.action-link,.search-trigger,.field-icon-button,.mini-action,.quick-action,.crm-icon-button,.form-action-icon,.list-add-action,.list-toolbar .button-add,.panel-header .button-add):hover:not([disabled]):not(.is-disabled){background:#2a3025;color:#e4bd69;border-color:#75643d}
html[data-theme="dark"] .button-primary{color:#fff;background:#527fbd}
html[data-theme="dark"] .button-primary:hover{background:#648fc8}
html[data-theme="dark"] .link-button,
html[data-theme="dark"] .entity-link,
html[data-theme="dark"] .text-action{color:var(--link)}
html[data-theme="dark"] .file-upload-progress{background:rgba(8,13,18,.78)}
html[data-theme="dark"] .file-upload-progress-bar{background:#2b3947}


/* Dark native form controls. Plain <input> elements without an explicit type are common in CRM forms. */
html[data-theme="dark"] :where(
  input:not([type]),input[type="text"],input[type="search"],input[type="tel"],input[type="number"],
  input[type="date"],input[type="datetime-local"],input[type="time"],input[type="month"],input[type="week"],
  input[type="password"],input[type="email"],input[type="url"],select,textarea
){background:#111a23!important;color:var(--text)!important;border-color:var(--control-border)!important;box-shadow:none!important}
html[data-theme="dark"] :where(
  input:not([type]),input[type="text"],input[type="search"],input[type="tel"],input[type="number"],
  input[type="date"],input[type="datetime-local"],input[type="time"],input[type="month"],input[type="week"],
  input[type="password"],input[type="email"],input[type="url"],select,textarea
):focus{border-color:var(--control-border-focus)!important;outline-color:rgba(111,155,219,.25)!important}
html[data-theme="dark"] :where(
  input:not([type]),input[type="text"],input[type="search"],input[type="tel"],input[type="number"],
  input[type="date"],input[type="datetime-local"],input[type="time"],input[type="month"],input[type="week"],
  input[type="password"],input[type="email"],input[type="url"],select,textarea
):disabled,
html[data-theme="dark"] :where(
  input:not([type]),input[type="text"],input[type="search"],input[type="tel"],input[type="number"],
  input[type="date"],input[type="datetime-local"],input[type="time"],input[type="month"],input[type="week"],
  input[type="password"],input[type="email"],input[type="url"],select,textarea
)[readonly]{background:#202a34!important;color:#8996a4!important;border-color:#303d49!important;opacity:1!important}

/* Lists, toolbars and tables. */
html[data-theme="dark"] .list-toolbar{background:var(--toolbar-bg);border-color:var(--toolbar-border)}
html[data-theme="dark"] th{background:#1b2631;color:#c2ccd7;border-color:var(--border)}
html[data-theme="dark"] td{border-color:var(--border)}
html[data-theme="dark"] tbody tr:hover{background:#1d2934}
html[data-theme="dark"] .empty-cell{color:var(--muted)}
html[data-theme="dark"] .sort-mark{color:#687787}
html[data-theme="dark"] .sort-link.is-active .sort-mark{color:#93b7e8}
html[data-theme="dark"] .pagination a,
html[data-theme="dark"] .pagination span{background:#17212b;border-color:var(--border);color:#aab6c2}
html[data-theme="dark"] .pagination a:hover{background:#213044;border-color:#4b6380;color:#a7c5ed}
html[data-theme="dark"] .pagination .is-current{background:#527fbd;border-color:#527fbd;color:#fff}
html[data-theme="dark"] .pagination .is-disabled{color:#65717d}
html[data-theme="dark"] .crm-configurable-table .list-column-fixed-left,
html[data-theme="dark"] .crm-configurable-table .list-table-actions{background:#18212b}
html[data-theme="dark"] .crm-configurable-table thead .list-column-fixed-left,
html[data-theme="dark"] .crm-configurable-table thead .list-table-actions{background:#1b2631}
html[data-theme="dark"] .crm-configurable-table tbody tr:hover .list-column-fixed-left,
html[data-theme="dark"] .crm-configurable-table tbody tr:hover .list-table-actions{background:#1d2934}
html[data-theme="dark"] .list-columns-item{background:#17212b;border-color:#344454;color:var(--text)}
html[data-theme="dark"] .list-columns-item:hover{background:#203044}
html[data-theme="dark"] .list-columns-dropzone{background:#111820;border-color:#3a4958}

/* Tabs, summaries and dashboard controls. */
html[data-theme="dark"] :where(.section-tabs,.dashboard-tabs,.driver-tabs,.vehicle-tabs,.vehicle-card-tabs){background:#17212b!important;border-color:var(--border)!important}
html[data-theme="dark"] :where(.section-tabs .section-tab,.dashboard-tab,.driver-tab,.vehicle-tab,.vehicle-card-tab){color:#aeb9c5!important;background:#17212b!important;border-color:var(--border)!important}
html[data-theme="dark"] :where(.section-tabs .section-tab,.dashboard-tab,.driver-tab,.vehicle-tab,.vehicle-card-tab):hover{background:#202b37!important;color:var(--text)!important}
html[data-theme="dark"] :where(.section-tabs .section-tab,.dashboard-tab,.driver-tab,.vehicle-tab,.vehicle-card-tab).is-active,
html[data-theme="dark"] :where(.section-tabs .section-tab,.dashboard-tab,.driver-tab,.vehicle-tab,.vehicle-card-tab).active{background:var(--tab-active-bg)!important;color:var(--tab-active-text)!important;border-color:#4c6f99!important;box-shadow:inset 0 -2px 0 #79a3dc!important}
html[data-theme="dark"] .section-tabs .section-tab:last-child{border-right-color:transparent!important}
html[data-theme="dark"] .section-tabs .section-tab.is-disabled{background:#141c25!important;color:#667482!important}
html[data-theme="dark"] .section-tab-count{color:var(--text)!important}
html[data-theme="dark"] .section-tab.is-active .section-tab-count{color:inherit!important}
html[data-theme="dark"] .vehicle-status-item{background:#18212b!important;border-color:var(--border)!important;color:var(--text)!important}
html[data-theme="dark"] .vehicle-status-item:hover{background:#202c38!important}
html[data-theme="dark"] .vehicle-status-item.is-active{background:#24364a!important;box-shadow:inset 0 -2px 0 #79a3dc!important}
html[data-theme="dark"] .vehicle-status-item.is-active .vehicle-status-name{color:#9fc0ef}
html[data-theme="dark"] .vehicle-status-count{color:var(--text)}

/* Dropdowns, popovers, notifications and help. */
html[data-theme="dark"] .telegram-topbar-dropdown{box-shadow:0 14px 35px rgba(0,0,0,.48)}
html[data-theme="dark"] .telegram-topbar-dropdown a{border-color:var(--border);color:var(--text)}
html[data-theme="dark"] .telegram-topbar-dropdown a:hover{background:#203044}
html[data-theme="dark"] .telegram-topbar-empty{color:var(--muted)}
html[data-theme="dark"] .combobox-option{background:#17212b;color:var(--text);border-color:var(--border)}
html[data-theme="dark"] .combobox-option:hover,
html[data-theme="dark"] .combobox-option.is-active{background:#24364a}
html[data-theme="dark"] .crm-action-tooltip,
html[data-theme="dark"] .list-toast{background:#05090d;color:#f0f4f8;box-shadow:0 7px 20px rgba(0,0,0,.5)}
html[data-theme="dark"] .crm-help-panel{box-shadow:-10px 0 28px rgba(0,0,0,.4)}
html[data-theme="dark"] .crm-help-header{background:#1b2631;border-color:var(--border)}
html[data-theme="dark"] .crm-help-content{color:var(--text-primary)}
html[data-theme="dark"] .crm-help-content :where(p,li){color:var(--text-primary)}
html[data-theme="dark"] .crm-help-content strong{color:var(--text-heading)}
html[data-theme="dark"] .crm-help-content code{background:#111820;border-color:#344252;color:#c6d9f0}
html[data-theme="dark"] .crm-process-board{box-shadow:0 10px 30px rgba(0,0,0,.45)}
html[data-theme="dark"] .crm-process-board-summary{background:#1b2631;color:var(--text);border-color:var(--border)}

/* Alerts and status language: same meaning, dark tinted surfaces. */
html[data-theme="dark"] .alert-success{background:#173224;border-color:#315f42;color:#9dd9af}
html[data-theme="dark"] .alert-warning,
html[data-theme="dark"] .alert-info{background:#342b18;border-color:#67552e;color:#e5c57d}
html[data-theme="dark"] .alert-error{background:#3a2022;border-color:#714044;color:#efaaaa}
html[data-theme="dark"] :where(.status-pill,.driver-data-pill,.driver-yandex-status,.driver-withdrawal-status,.collection-status,.entity-link-pill){border-color:#3b4a59}
html[data-theme="dark"] :where(.balance-positive,.status-success){color:#79ca94}
html[data-theme="dark"] :where(.balance-negative,.status-error){color:#ef8d8d}
html[data-theme="dark"] .quick-action.is-available{background:#193126;color:#75c894;border-color:#3d7151}
html[data-theme="dark"] .quick-action.is-missing{background:#18232e;color:#7f8e9e;border-color:#394858}
html[data-theme="dark"] .quick-action.is-print{background:#19283a;color:#90b6e8;border-color:#3d5b7e}
html[data-theme="dark"] tr.is-schedule-changed,
html[data-theme="dark"] .contracts-table tr.is-paused td,
html[data-theme="dark"] .driver-contracts-table tr.is-paused td,
html[data-theme="dark"] .vehicle-contracts-table tr.is-paused td{background:#302b1d;color:#e3c477;border-color:#5d5131}
html[data-theme="dark"] .dashboard-newcomer-table tr.is-critical td{background:#382124;color:#efaaaa}

/* Modal overlay and preview mode. */
html[data-theme="dark"] .crm-modal-backdrop,
html[data-theme="dark"] .modal{background:rgba(2,7,12,.72)}
html[data-theme="dark"] .employee-preview-banner{background:#332b18;border-color:#6a572e;color:#e6ca83}
html[data-theme="dark"] .employee-preview-exit{background:#3b321e;border-color:#705e34;color:#f0d793}

/* Public capture and authentication. */
html[data-theme="dark"] .auth-page,
html[data-theme="dark"] .document-capture-body{background:var(--page)}
html[data-theme="dark"] .auth-card{box-shadow:0 18px 48px rgba(0,0,0,.35)}
html[data-theme="dark"] .auth-card .brand,
html[data-theme="dark"] .document-capture-brand{color:#9fc0ef}
html[data-theme="dark"] .document-capture-header{color:var(--text)}
html[data-theme="dark"] .document-capture-camera,
html[data-theme="dark"] .vehicle-qr-camera{background:#05090d;border-color:#344252}
html[data-theme="dark"] .document-crop-editor{background:#080d12}
html[data-theme="dark"] .document-capture-pages{border-color:var(--border)}
html[data-theme="dark"] .wialon-callback-page{min-height:100vh;margin:0;display:grid;place-items:center;padding:24px;background:var(--page);color:var(--text)}
html[data-theme="dark"] .wialon-callback-page>p{max-width:520px;margin:0;padding:24px;border:1px solid var(--border);border-radius:8px;background:var(--panel)}

/* Template editor chrome becomes dark, while document pages/iframe stay white. */
html[data-theme="dark"] body.template-editor-body{background:#0f151c;color:var(--text)}
html[data-theme="dark"] .template-editor-body .titlebar,
html[data-theme="dark"] .template-editor-body .ribbon-tabs,
html[data-theme="dark"] .template-editor-body .ribbon-panel{background:#18212b;border-color:#2c3946;color:var(--text)}
html[data-theme="dark"] .template-editor-body .brand span{color:var(--text)}
html[data-theme="dark"] .template-editor-body .brand small,
html[data-theme="dark"] .template-editor-body .group-label,
html[data-theme="dark"] .template-editor-body .macro-chip code,
html[data-theme="dark"] .template-editor-body .modal-note{color:var(--muted)}
html[data-theme="dark"] .template-editor-body .ribbon-tab{color:#aeb9c5}
html[data-theme="dark"] .template-editor-body .ribbon-tab:hover{background:#202b37}
html[data-theme="dark"] .template-editor-body .ribbon-tab.active{color:#9fc0ef;border-bottom-color:#79a3dc}
html[data-theme="dark"] .template-editor-body .ribbon-tab.context.design,
html[data-theme="dark"] .template-editor-body .ribbon-tab.context.layout,
html[data-theme="dark"] .template-editor-body .ribbon-tab.context.picture{background:#202a35}
html[data-theme="dark"] .template-editor-body .ribbon-group{border-color:#2c3946}
html[data-theme="dark"] .template-editor-body :where(.tool,.large-tool,.stack-buttons button,.insert-grid button){color:var(--text)}
html[data-theme="dark"] .template-editor-body :where(.tool,.large-tool,.stack-buttons button,.insert-grid button):hover,
html[data-theme="dark"] .template-editor-body :where(.tool,.large-tool).active{background:#24364a;border-color:#4b6583}
html[data-theme="dark"] .template-editor-body :where(
  .titlebar button,.font-family,.font-size-combo,.font-size,.font-size-drop,#block-style,
  .layout-fields input,.size-fields input,.macro-ribbon-search select,.macro-ribbon-search input,
  .macro-ribbon-search button,.macro-chip,.border-controls select,#row-height-mode,.cell-padding-fields input,
  .cell-align-buttons button,.alt-field input,.popover,.table-picker .full-button,.palette-actions button,
  .border-preset,.symbol-grid button,.modal-card,.modal-actions,.form-grid input,.form-grid select,
  .preview-card,.find-layout input,.color-choice,.font-size-menu button,.picture-dimensions input,
  .quick-history-button
){background:#111a23!important;color:var(--text)!important;border-color:#3a4958!important}
html[data-theme="dark"] .template-editor-body :where(.macro-chip,.border-preset,.symbol-grid button,.font-size-menu button,.color-choice):hover{background:#24364a!important}
html[data-theme="dark"] .template-editor-body .workspace{background:#0d1319}
html[data-theme="dark"] .template-editor-body #editor{background:#d8dde3;border-color:#465361}
html[data-theme="dark"] .template-editor-body .preview-card iframe{background:#dfe3e8}
html[data-theme="dark"] .template-editor-body .modal{background:rgba(2,7,12,.72)}

/* Printed pages and generated documents are never recoloured. */
@media print{
  html[data-theme="dark"],html[data-theme="dark"] body{color-scheme:light;background:#fff!important;color:#000!important}
  html[data-theme="dark"] .crm-doc-page,
  html[data-theme="dark"] .print-page,
  html[data-theme="dark"] .return-page,
  html[data-theme="dark"] .wb-page,
  html[data-theme="dark"] .taxi-memo-page,
  html[data-theme="dark"] .page{background:#fff!important;color:#000!important}
}

@media(max-width:600px){
  .crm-theme-switch{gap:4px;padding-left:2px;padding-right:2px}
  .crm-theme-track{width:32px;flex-basis:32px}
  .crm-theme-switch.is-dark .crm-theme-thumb{transform:translateX(12px)}
  .crm-theme-icon{width:13px;height:13px}
  .crm-theme-icon svg{width:13px;height:13px}
}

/* Keep the theme control compact inside standalone headers and the login card. */
.auth-card .crm-theme-switch,
.template-editor-body .titlebar .crm-theme-switch{
  width:auto;
  height:30px;
  min-height:30px;
  margin:0;
  padding:2px 4px;
  border:0;
  border-radius:16px;
  background:transparent;
  color:var(--muted);
  font-weight:400;
}
.auth-card .crm-theme-switch:hover,
.template-editor-body .titlebar .crm-theme-switch:hover{background:#f5f8fc}
html[data-theme="dark"] .auth-card .crm-theme-switch:hover,
html[data-theme="dark"] .template-editor-body .titlebar .crm-theme-switch:hover{background:#202b37!important}
.template-editor-body .crm-theme-switcher{flex:0 0 auto}

/* Remaining CRM component surfaces. */
html[data-theme="dark"] :where(
  .telegram-template-heading,
  .telegram-macro-glossary,.notification-audience-summary,.notification-preview-card,.statement-log-source-card,
  .publication-thumbnail,.publication-edit-image,.crm-help-header,.inspection-day-header,.vehicle-qr-result-details,
  .collection-finished-note,
  .park-settings-provider-heading,.park-schedule-section-heading,.settings-option-grid,.crm-macro-glossary-item,
  .list-columns-fixed-action,.list-table-scroll-proxy,.rate-current
){background:#1b2631;border-color:var(--border);color:var(--text)}

html[data-theme="dark"] :where(
  .document-library-group,.document-modal,.document-add-card,.document-slot-add,.document-file-select,
  .message-editor,.message-editor-emoji,.telegram-template-row,.settings-checkbox-control,
  .inspection-day-option,.gps-link-candidate,.driver-document-import-card,.collection-inline-controls select,
  .notification-broadcast-toolbar,.driver-notification-auto-toggle,.list-export-column
){background:#18212b;border-color:var(--border);color:var(--text)}

html[data-theme="dark"] :where(
  .document-library-group-header,.message-editor-toolbar,.message-editor.is-disabled,
  .message-editor.is-disabled .message-editor-toolbar,.document-thumbnail,.document-capture-page-thumb,
  .driver-photo-thumbnail,.driver-document-import-section,.driver-document-import-icon,
  .inspection-day-option.is-current,.inspection-day-option[disabled],.gps-link-candidate.is-unavailable,
  .list-columns-item.is-required
){background:#202b37;border-color:var(--border);color:var(--muted)}

html[data-theme="dark"] :where(
  .document-add-card:hover,.document-file-select:hover,.document-modal-close:hover,
  .message-editor-toolbar>button:hover,.message-editor-emoji>button:hover,.message-macro-list button:hover,
  .inspection-day-option:hover:not([disabled]),.statement-log-table .is-editable:hover,
  .help-admin-page:hover,.list-columns-dropzone.is-drag-over
){background:#24364a;border-color:#4b6380;color:#bcd2ee}

html[data-theme="dark"] .document-thumbnail.is-image,
html[data-theme="dark"] .document-thumbnail.is-image img,
html[data-theme="dark"] .document-thumbnail.is-pdf,
html[data-theme="dark"] .document-qr{background:#eef2f5;color:#1f2937}

/* Messaging workspaces. */
html[data-theme="dark"] .telegram-chat-thread,
html[data-theme="dark"] .candidate-tab-panel[data-candidate-panel="whatsapp"] .whatsapp-chat-thread{background:#111820;border-color:var(--border)}
html[data-theme="dark"] .telegram-bubble.is-incoming,
html[data-theme="dark"] .candidate-tab-panel[data-candidate-panel="whatsapp"] .whatsapp-bubble{background:#202b37;color:var(--text);border-color:#334252}
html[data-theme="dark"] .telegram-bubble.is-outgoing,
html[data-theme="dark"] .candidate-tab-panel[data-candidate-panel="whatsapp"] .whatsapp-bubble.is-outgoing{background:#20364d;color:#dbe8f8;border-color:#365a7e}
html[data-theme="dark"] .whatsapp-bubble{background:#202b37;color:var(--text)}
html[data-theme="dark"] .whatsapp-bubble.is-outgoing{background:#1d3a2d;color:#d7f0df}
html[data-theme="dark"] .telegram-service-line{background:#2a3540;color:#aeb9c5}
html[data-theme="dark"] .message-editor-body code,
html[data-theme="dark"] .telegram-macro-grid code{background:#111820;color:#c6d9f0;border-color:#344252}
html[data-theme="dark"] .message-editor-toolbar>button.is-active{background:#2a4665;color:#bcd5f5}
html[data-theme="dark"] .message-macro-list button{background:#1b2631;color:var(--text);border-color:var(--border)}
html[data-theme="dark"] .message-template-select{background:#111a23;color:var(--text);border-color:var(--control-border)}

/* Inspections and schedule boards. */
html[data-theme="dark"] .inspection-day-card{background:#18212b;border-color:var(--border)}
html[data-theme="dark"] :where(.inspection-photo-upload-row,.inspection-photo-card){background:var(--panel);border-color:var(--border);color:var(--text)}
html[data-theme="dark"] .inspection-photo-upload-row.is-success{background:#162c21;border-color:#2d6844}
html[data-theme="dark"] .inspection-photo-upload-row.is-error{background:#321d21;border-color:#7a3c45}
html[data-theme="dark"] .inspection-photo-thumbnail{background:#111820}
html[data-theme="dark"] .inspection-day-count{background:#24364a;color:#a9c8f2;border-color:#48698f}
html[data-theme="dark"] .inspection-day-dropzone{background:#111820;border-color:#344252}
html[data-theme="dark"] .inspection-day-card.is-drag-over .inspection-day-dropzone{background:#203044;border-color:#5a7ca2}
html[data-theme="dark"] .inspection-vehicle-chip{background:#20364d;color:#b8d1f0;border-color:#365a7e}
html[data-theme="dark"] .inspection-vehicle-chip:hover{background:#294765}
html[data-theme="dark"] .inspection-vehicle-chip.is-muted{background:#262d35;color:#8793a0;border-color:#3b4651}

/* Yandex, GPS and integration states. */
html[data-theme="dark"] .yandex-driver-alert-warning{background:#342b18;border-color:#67552e;color:#e5c57d}
html[data-theme="dark"] .entity-link-pill{background:#18212b;color:#aeb9c5;border-color:#3a4958}
html[data-theme="dark"] .entity-link-pill.is-linked,
html[data-theme="dark"] .gps-link-candidate.is-current,
html[data-theme="dark"] .gps-link-badge.is-current,
html[data-theme="dark"] .driver-document-import-card.is-filled{background:#193126;color:#91d4a7;border-color:#3d7151}
html[data-theme="dark"] .gps-link-badge.is-busy{background:#3a2022;color:#efaaaa;border-color:#714044}

/* Status pills and collection workflow. */
html[data-theme="dark"] :where(.status-pill.is-muted,.collection-status){background:#26313c;color:#aab6c2;border-color:#3b4a59}
html[data-theme="dark"] .collection-status.is-info{background:#20364d;color:#b8d1f0;border-color:#365a7e}
html[data-theme="dark"] .collection-status.is-accent{background:#2d2a4a;color:#c8c1f3;border-color:#565080}
html[data-theme="dark"] .collection-status.is-schedule{background:#30284a;color:#d0bff4;border-color:#5e4f82}

/* Read-only fields and settings cards. */
html[data-theme="dark"] [data-readonly-panel] :where(input:not([type="hidden"]),select,textarea),
html[data-theme="dark"] .contract-planned-end-input:disabled,
html[data-theme="dark"] .field.is-disabled :where(input,select,textarea){background:#202a34;color:#7d8995;border-color:#303d49}
html[data-theme="dark"] .settings-checkbox-control:hover{background:#202b37}

html[data-theme="dark"] .crm-error-preview-note{
  background:#342b18!important;
  border-color:#67552e!important;
  color:#e5c57d!important;
}

/* 2026-08-06: dark-theme specificity corrections for legacy !important rules. */
html[data-theme="dark"] .dashboard-schedule .schedule-block,
html[data-theme="dark"] .due-group-list{
  background:#18212b!important;
  border-color:var(--border)!important;
}
html[data-theme="dark"] .due-group-toggle{
  background:#18212b!important;
  color:var(--text)!important;
  border-color:var(--border)!important;
}
html[data-theme="dark"] .due-group-toggle:hover{
  background:#202c38!important;
}
html[data-theme="dark"] .dashboard-inspection-row{
  background:#18212b;
  color:var(--text);
  border-color:var(--border);
}
html[data-theme="dark"] .dashboard-inspection-row:hover{
  background:#202c38;
  color:var(--link);
}
html[data-theme="dark"] .dashboard-inspection-row small{color:var(--muted)}

html[data-theme="dark"] :where(
  .entity-form-actions
){
  background:var(--panel)!important;
  border-color:var(--border)!important;
}

html[data-theme="dark"] input[type="checkbox"]:not([hidden]){
  background:#111a23!important;
  border-color:#556575!important;
}
html[data-theme="dark"] input[type="checkbox"]:not([hidden]):checked{
  background:var(--accent)!important;
  border-color:var(--accent)!important;
}

/* Neutral action buttons stay blue at rest instead of retaining a white light-theme fill. */
html[data-theme="dark"] :where(a,button,label,summary).crm-icon-button,
html[data-theme="dark"] :where(a,button,label,summary).quick-action,
html[data-theme="dark"] :where(a,button,label,summary).mini-action,
html[data-theme="dark"] :where(a,button,label,summary).form-action-icon,
html[data-theme="dark"] :where(a,button,label,summary).field-icon-button,
html[data-theme="dark"] :where(a,button,label,summary).list-add-action,
html[data-theme="dark"] :where(a,button,label,summary).modal-control-action,
html[data-theme="dark"] .excel-action{
  background:#18232e!important;
  color:#8eb3e7!important;
  border-color:#3b5067!important;
}

/* Neutral hover/focus: muted amber. */
html[data-theme="dark"] :where(
  .crm-icon-button,.quick-action,.mini-action,.form-action-icon,.field-icon-button,.list-add-action,.modal-control-action,.excel-action
):hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(
  .crm-icon-button,.quick-action,.mini-action,.form-action-icon,.field-icon-button,.list-add-action,.modal-control-action,.excel-action
):focus-visible{
  background:#342b18!important;
  color:#e4bd69!important;
  border-color:#75643d!important;
}

/* Add, save, confirm, edit and expand: muted green. */
html[data-theme="dark"] :where(a,button,label,summary):has(>.crm-action-icon--confirm):hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(a,button,label,summary):has(>.crm-action-icon--confirm):focus-visible,
html[data-theme="dark"] :where(.crm-icon-button,.quick-action).is-payment:hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(.crm-icon-button,.quick-action).is-payment:focus-visible{
  background:#193126!important;
  color:#83d29d!important;
  border-color:#4b8660!important;
}

/* Cancel, delete and collapse: muted red. */
html[data-theme="dark"] :where(a,button,label,summary).crm-icon-button.is-danger:hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(a,button,label,summary).quick-action.is-danger:hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(a,button,label,summary).form-action-icon.is-danger:hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(a,button,label,summary).field-icon-button.is-danger:hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(a,button,label,summary):has(>.crm-action-icon--danger):hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(a,button,label,summary):has(>.crm-action-icon--danger):focus-visible,
html[data-theme="dark"] :where(.crm-icon-button,.quick-action).is-payment-cancel:hover:not([disabled]):not(.is-disabled),
html[data-theme="dark"] :where(.crm-icon-button,.quick-action).is-payment-cancel:focus-visible{
  background:#3a2022!important;
  color:#efaaaa!important;
  border-color:#814a4e!important;
}

html[data-theme="dark"] :where(
  .crm-icon-button,.quick-action,.mini-action,.form-action-icon,.field-icon-button,.list-add-action,.modal-control-action,.excel-action
)[disabled],
html[data-theme="dark"] :where(
  .crm-icon-button,.quick-action,.mini-action,.form-action-icon,.field-icon-button,.list-add-action,.modal-control-action,.excel-action
).is-disabled{
  background:#171e26!important;
  color:#5e6974!important;
  border-color:#2b3540!important;
}

/* 2026-08-06: status indicators must remain visibly green/red/amber in dark mode.
   Legacy light-theme selectors are more specific, so these overrides are explicit. */
html[data-theme="dark"]{
  --status-soft-success-bg:#20372a;
  --status-soft-success-border:#4f7f5e;
  --status-soft-success-text:#a7d7b4;
  --status-soft-danger-bg:#3b2528;
  --status-soft-danger-border:#835054;
  --status-soft-danger-text:#e8b2b2;
  --status-soft-warning-bg:#3a311f;
  --status-soft-warning-border:#7f6a3f;
  --status-soft-warning-text:#e4cb8b;
  --status-soft-info-bg:#203148;
  --status-soft-info-border:#46698d;
  --status-soft-info-text:#a9c8eb;
}

html[data-theme="dark"] .driver-data-status.is-complete span,
html[data-theme="dark"] .driver-photo-status.is-available span,
html[data-theme="dark"] .driver-telegram-status.is-connected span,
html[data-theme="dark"] .driver-yandex-status.is-connected span,
html[data-theme="dark"] .driver-withdrawal-status.is-allowed span{
  background:var(--status-soft-success-bg)!important;
  border-color:var(--status-soft-success-border)!important;
  color:var(--status-soft-success-text)!important;
}

html[data-theme="dark"] .driver-data-status.is-error span,
html[data-theme="dark"] .driver-photo-status.is-missing span,
html[data-theme="dark"] .driver-telegram-status.is-disconnected span,
html[data-theme="dark"] .driver-yandex-status.is-disconnected span,
html[data-theme="dark"] .driver-withdrawal-status.is-blocked span{
  background:var(--status-soft-danger-bg)!important;
  border-color:var(--status-soft-danger-border)!important;
  color:var(--status-soft-danger-text)!important;
}

html[data-theme="dark"] .driver-data-status.is-incomplete span,
html[data-theme="dark"] .driver-yandex-status.is-warning span,
html[data-theme="dark"] .driver-withdrawal-status.is-exempt span{
  background:var(--status-soft-warning-bg)!important;
  border-color:var(--status-soft-warning-border)!important;
  color:var(--status-soft-warning-text)!important;
}

html[data-theme="dark"] .driver-withdrawal-status.is-pending span,
html[data-theme="dark"] .driver-data-status.is-pending span{
  background:var(--status-soft-info-bg)!important;
  border-color:var(--status-soft-info-border)!important;
  color:var(--status-soft-info-text)!important;
}

html[data-theme="dark"] .driver-data-pill.is-complete,
html[data-theme="dark"] .entity-link-pill.is-linked,
html[data-theme="dark"] .statement-log-status.is-success,
html[data-theme="dark"] .driver-photo-source.is-yandex,
html[data-theme="dark"] .status-pill.is-success,
html[data-theme="dark"] .collection-status.is-success{
  background:var(--status-soft-success-bg)!important;
  border-color:var(--status-soft-success-border)!important;
  color:var(--status-soft-success-text)!important;
}

html[data-theme="dark"] .driver-data-pill.is-error,
html[data-theme="dark"] .statement-log-status.is-error,
html[data-theme="dark"] .status-pill.is-danger,
html[data-theme="dark"] .collection-status.is-danger{
  background:var(--status-soft-danger-bg)!important;
  border-color:var(--status-soft-danger-border)!important;
  color:var(--status-soft-danger-text)!important;
}

html[data-theme="dark"] .driver-data-pill.is-incomplete,
html[data-theme="dark"] .entity-link-pill.is-warning,
html[data-theme="dark"] .driver-photo-source.is-manual,
html[data-theme="dark"] .status-pill.is-warning,
html[data-theme="dark"] .collection-status.is-warning{
  background:var(--status-soft-warning-bg)!important;
  border-color:var(--status-soft-warning-border)!important;
  color:var(--status-soft-warning-text)!important;
}


/* 2026-08-06: softer typography and clearer financial amounts in dark mode. */
html[data-theme="dark"] body,
html[data-theme="dark"] table,
html[data-theme="dark"] :where(input,select,textarea){
  color:var(--text-primary)!important;
}

html[data-theme="dark"] :where(
  h1,h2,h3,
  .topbar-title,.topbar-title-main,
  .panel-header h2,.page-heading h1,.form-section-title,
  .crm-modal-header h2,.crm-help-header h2,
  table th
){
  color:var(--text-heading)!important;
}

html[data-theme="dark"] :where(
  .muted,.cell-secondary,.field-help,.form-help,.modal-note,.group-label,.contract-type,
  .detail-label,.vehicle-status-name,.pagination-summary,.topbar-title-subtitle
){
  color:var(--text-secondary)!important;
}

html[data-theme="dark"] :where(input,select,textarea)::placeholder{
  color:var(--text-disabled)!important;
}

/* Closed contracts remain readable but visually secondary, not disabled. */
html[data-theme="dark"] :where(
  .contracts-table,.driver-contracts-table,.vehicle-contracts-table
) tr.is-closed td{
  color:var(--text-closed)!important;
}
html[data-theme="dark"] :where(
  .contracts-table,.driver-contracts-table,.vehicle-contracts-table
) tr.is-closed .entity-link{
  color:var(--link-closed)!important;
}

/* Financial values need stronger contrast than passive status labels. */
html[data-theme="dark"] :where(.balance-positive,.amount-positive,.finance-positive){
  color:var(--finance-positive)!important;
  font-weight:500!important;
}
html[data-theme="dark"] :where(.balance-negative,.amount-negative,.finance-negative){
  color:var(--finance-negative)!important;
  font-weight:500!important;
}

/* Dark document library: remove the light card shell around empty and uploaded slots. */
html[data-theme="dark"] :where(
  .document-slot,
  .document-slot-title,
  .document-slot-actions,
  .document-slot-add
){
  background:#18212b !important;
  border-color:var(--border) !important;
  color:var(--text-primary) !important;
}
html[data-theme="dark"] :where(.document-slots-grid--three,.document-slots-grid--four){
  background:var(--border) !important;
}
html[data-theme="dark"] .document-slot.is-unavailable{
  background:#171f28 !important;
  color:var(--text-disabled) !important;
}
html[data-theme="dark"] .document-slot.is-unavailable .document-slot-title{
  color:var(--text-disabled) !important;
}
html[data-theme="dark"] .document-add-card{
  background:#18212b !important;
  color:#9fc0ef !important;
}
html[data-theme="dark"] .document-add-card:hover{
  background:#24364a !important;
  color:#c4d8f2 !important;
}
html[data-theme="dark"] .document-add-card-icon{
  background:#18232e !important;
  border-color:#3b5067 !important;
  color:#8eb3e7 !important;
}

/* 2026-08-06: final dark-theme corrections for legacy white states. */
html[data-theme="dark"] .contract-document-menu[open] > summary{
  background:#24364a!important;
  color:#9fc0ef!important;
  border-color:#4c6f99!important;
}
html[data-theme="dark"] .contract-document-menu-popover{
  background:#17212b!important;
  border-color:#344454!important;
  box-shadow:0 14px 34px rgba(0,0,0,.5)!important;
}
html[data-theme="dark"] .contract-document-menu-item{
  background:#17212b!important;
  color:var(--text-primary)!important;
  border-bottom-color:var(--border)!important;
}
html[data-theme="dark"] .contract-document-menu-item:hover,
html[data-theme="dark"] .contract-document-menu-item:focus-visible{
  background:#24364a!important;
  color:#9fc0ef!important;
  outline:none;
}

/* Mass notification audience: unavailable rows are muted, never white. */
html[data-theme="dark"] .notification-broadcast-list-area{
  background:var(--panel)!important;
}
html[data-theme="dark"] .notification-driver-table thead th{
  background:#1b2631!important;
  color:var(--text-heading)!important;
}
html[data-theme="dark"] .notification-driver-table tr.is-notification-unavailable,
html[data-theme="dark"] .notification-driver-table tr.is-notification-unavailable:hover,
html[data-theme="dark"] .notification-driver-table tr.is-notification-unavailable td{
  background:#171e26!important;
  color:#7f8a96!important;
}
html[data-theme="dark"] .notification-driver-table tr.is-notification-unavailable .cell-secondary{
  color:#687481!important;
}
html[data-theme="dark"] .notification-driver-table tr.is-notification-unavailable input[type="checkbox"]{
  background:#252d35!important;
  border-color:#46515c!important;
}

/* Driver notification chat uses the dark messaging palette even against more specific legacy rules. */
html[data-theme="dark"] .driver-tab-panel[data-driver-panel="notifications"] .telegram-chat-thread{
  background:#111820!important;
  border-color:var(--border)!important;
}
html[data-theme="dark"] .driver-tab-panel[data-driver-panel="notifications"] .telegram-bubble.is-incoming{
  background:#202b37!important;
  color:var(--text-primary)!important;
  border-color:#334252!important;
}
html[data-theme="dark"] .driver-tab-panel[data-driver-panel="notifications"] .telegram-bubble.is-outgoing{
  background:#20364d!important;
  color:#dbe8f8!important;
  border-color:#365a7e!important;
}
html[data-theme="dark"] .driver-tab-panel[data-driver-panel="notifications"] .telegram-service-line{
  background:#2a3540!important;
  color:#aeb9c5!important;
}
html[data-theme="dark"] .driver-tab-panel[data-driver-panel="notifications"] .telegram-compose{
  background:#18212b!important;
  border-color:var(--border)!important;
}

/* Inline journal details and their pagination must not fall back to light surfaces. */
html[data-theme="dark"] .rent-journal-row.is-selected > td{
  background:#203044!important;
}
html[data-theme="dark"] .rent-journal-detail-row > td,
html[data-theme="dark"] .rent-journal-detail{
  background:#18212b!important;
  color:var(--text-primary)!important;
  border-color:var(--border)!important;
}
html[data-theme="dark"] .rent-journal-detail-table{
  background:#111820!important;
  border-color:var(--border)!important;
}
html[data-theme="dark"] .rent-journal-detail .list-footer{
  background:#18212b!important;
  border-color:var(--border)!important;
  color:var(--text-secondary)!important;
}
html[data-theme="dark"] .rent-journal-detail .pagination-summary,
html[data-theme="dark"] .rent-journal-detail-filter .field > span{
  color:var(--text-secondary)!important;
}

/* Neutral transaction badges and empty values should not appear as white status blocks. */
html[data-theme="dark"] :where(.badge,.transaction-badge,.cashflow-badge,.billing-badge,.balance-operation-category){
  background:#202a35!important;
  border:1px solid #354555!important;
  color:#b6c0cc!important;
  box-shadow:none!important;
}
html[data-theme="dark"] :where(.amount-empty,.cell-empty,.finance-empty,.dash){
  color:var(--text-disabled)!important;
  font-weight:400!important;
}

/* 2026-08-06: document previews keep their original pixels, but the unused canvas is dark. */
html[data-theme="dark"] :where(
  .document-thumbnail,
  .document-thumbnail.is-image,
  .document-thumbnail.is-pdf,
  .document-thumbnail.is-image img,
  .document-pdf-preview
){
  background:#111820!important;
  border-color:#344252!important;
}

/* PDF/QR pages themselves remain light for readability and scanning. */
html[data-theme="dark"] .document-pdf-preview canvas{
  background:#fff!important;
  box-shadow:0 0 0 1px rgba(255,255,255,.12),0 2px 8px rgba(0,0,0,.28);
}

/* Uploaded photographs and scans are never filtered or recoloured. */
html[data-theme="dark"] .document-thumbnail.is-image img{
  filter:none!important;
}

/* 2026-08-06: document upload modal follows the dark palette. */
html[data-theme="dark"] .document-modal{
  background:#18212b!important;
  border-color:#3a4958!important;
  color:var(--text-primary)!important;
  box-shadow:0 18px 48px rgba(0,0,0,.55)!important;
}
html[data-theme="dark"] .document-modal h2{color:var(--text-heading)!important}
html[data-theme="dark"] .document-modal-close{
  background:#18232e!important;
  border-color:#3b5067!important;
  color:#8eb3e7!important;
}
html[data-theme="dark"] .document-modal-close:hover,
html[data-theme="dark"] .document-modal-close:focus-visible{
  background:#342b18!important;
  border-color:#75643d!important;
  color:#e4bd69!important;
}
html[data-theme="dark"] .document-file-select{
  background:#111a23!important;
  border-color:#4a617a!important;
  color:#9fc0ef!important;
}
html[data-theme="dark"] .document-file-select:hover,
html[data-theme="dark"] .document-file-select:focus-within{
  background:#203044!important;
  border-color:#6e98d1!important;
  color:#c4d8f2!important;
}
html[data-theme="dark"] .document-file-name{color:var(--text-secondary)!important}
html[data-theme="dark"] .document-modal-error{color:#efaaaa!important}
