/* ─────────────────────────────────────────────────────────────────────
   Dark theme — OpenAI-style.
   Activated by setting data-theme="dark" on <html> (or <body>).
   Overrides CSS variables and a curated set of hard-coded surface
   colors used across public.css / dashboard.css.
   ───────────────────────────────────────────────────────────────────── */

html[data-theme="dark"],
html[data-theme="dark"] body.public-shell {
  color-scheme: dark;

  --bg: #212121;
  --bg-accent: #1a1a1a;
  --surface: #2a2a2a;
  --surface-soft: #232323;
  --border: #3a3a3a;
  --text: #ececec;
  --muted: #9b9b9b;
  --primary: #22c55e;
  --primary-deep: #16a34a;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-card: 0 12px 28px rgba(0, 0, 0, 0.55);
  --sidebar-bg: #171717;
  --sidebar-text: #c9c9c9;
  --sidebar-active: rgba(34, 197, 94, 0.18);

  background: var(--bg);
  color: var(--text);
}

html[data-theme="dark"] body.public-shell {
  background: var(--bg) !important;
  color: var(--text) !important;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
html[data-theme="dark"] .app-topbar {
  background: #181818 !important;
  border-bottom: 1px solid var(--border) !important;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

html[data-theme="dark"] .app-topbar .navbar-brand {
  color: #22c55e !important;
  -webkit-text-stroke: 1px #22c55e !important;
}

html[data-theme="dark"] .app-topbar .text-muted,
html[data-theme="dark"] .text-muted,
html[data-theme="dark"] small,
html[data-theme="dark"] .small {
  color: var(--muted) !important;
}

html[data-theme="dark"] .fw-semibold,
html[data-theme="dark"] .fw-bold {
  color: var(--text);
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
html[data-theme="dark"] .app-sidebar-card,
html[data-theme="dark"] .app-sidebar-col,
html[data-theme="dark"] .app-sidebar-card .card-header,
html[data-theme="dark"] .app-sidebar-card .app-sidebar-nav {
  background-color: var(--sidebar-bg) !important;
}

html[data-theme="dark"] .app-sidebar-link,
html[data-theme="dark"] .app-sidebar-nav .list-group-item {
  color: #e5e5e5 !important;
}

html[data-theme="dark"] .app-sidebar-link:hover,
html[data-theme="dark"] .app-sidebar-link:focus {
  background: rgba(255, 255, 255, 0.06) !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .app-sidebar-link.active,
html[data-theme="dark"] .app-sidebar-link.active:hover {
  background: var(--sidebar-active) !important;
  color: #ffffff !important;
  border-left-color: #22c55e !important;
}

/* ── Cards & containers ──────────────────────────────────────────── */
html[data-theme="dark"] .card {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

html[data-theme="dark"] .card-header,
html[data-theme="dark"] .card-footer {
  background: var(--surface-soft);
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .list-group-item {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .list-group-item.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #0b1220;
}

html[data-theme="dark"] hr {
  border-color: var(--border);
  opacity: 1;
}

/* ── Headings & links ────────────────────────────────────────────── */
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6 {
  color: var(--text);
}

html[data-theme="dark"] a {
  color: #4ade80;
}

html[data-theme="dark"] a:hover {
  color: #86efac;
}

/* Шапка страницы (.page-header из dashboard.css): светлая линия под
   заголовком и тёмно-серые неактивные вкладки на тёмном фоне не читались. */
html[data-theme="dark"] .page-header {
  border-bottom-color: var(--border);
}

html[data-theme="dark"] .page-header__tabs .nav-link {
  color: var(--muted);
}

html[data-theme="dark"] .page-header__tabs .nav-link:hover,
html[data-theme="dark"] .page-header__tabs .nav-link.active {
  color: var(--primary);
}

html[data-theme="dark"] .page-header__tabs .nav-link.active::after {
  background: var(--primary);
}

/* ── Forms ───────────────────────────────────────────────────────── */
html[data-theme="dark"] .form-label {
  color: #cbd5e1;
}

/* Bootstrap-дефолт form-text — почти чёрный, на тёмном фоне не читается. */
html[data-theme="dark"] .form-text {
  color: var(--muted);
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] textarea.form-control,
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="date"].form-control,
html[data-theme="dark"] input[type="date"].form-select {
  background-color: #1f1f1f;
  border-color: #3a3a3a;
  color: var(--text);
}

html[data-theme="dark"] .form-control::placeholder,
html[data-theme="dark"] textarea.form-control::placeholder {
  color: #6b7280;
}

/* Префиксы/суффиксы полей ($, %, ед. изм.) — общий Bootstrap-класс;
   без правила в тёмной теме оставался белый «островок» у поля. */
html[data-theme="dark"] .input-group-text {
  background-color: #2a2a2a;
  border-color: #3a3a3a;
  color: #cbd5e1;
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus,
html[data-theme="dark"] textarea.form-control:focus,
html[data-theme="dark"] input[type="date"]:focus {
  background-color: #1f1f1f;
  border-color: var(--primary);
  color: var(--text);
  box-shadow: 0 0 0 0.2rem rgba(34, 197, 94, 0.18);
}

/* Невалидное поле (Bootstrap .is-invalid): правила выше по специфичности
   перебивали красную рамку — в тёмной теме ошибку было видно только по
   тексту под полем, а в фокусе рамка становилась зелёной. */
html[data-theme="dark"] .form-control.is-invalid,
html[data-theme="dark"] .form-select.is-invalid {
  border-color: var(--danger);
}

html[data-theme="dark"] .form-control.is-invalid:focus,
html[data-theme="dark"] .form-select.is-invalid:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 0.2rem rgba(239, 68, 68, 0.25);
}

/* Заблокированные поля (например, клиент/юнит привязанной записи
   календаря) должны отличаться от обычных, как в светлой теме. */
html[data-theme="dark"] .form-control:disabled,
html[data-theme="dark"] .form-select:disabled,
html[data-theme="dark"] textarea.form-control:disabled {
  background-color: #2a2a2a;
  border-color: #3a3a3a;
  color: var(--muted);
  opacity: 1;
}

html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) hue-rotate(180deg) brightness(0.95);
  background-color: rgba(34, 197, 94, 0.18);
}

html[data-theme="dark"] input[type="date"]::-webkit-datetime-edit {
  color: var(--text);
}

html[data-theme="dark"] .ss-date-input {
  background-color: #1f1f1f !important;
  border-color: #3a3a3a !important;
  color: var(--text) !important;
}

/* ── Sidebar search ──────────────────────────────────────────────── */
html[data-theme="dark"] .app-global-search-wrap .form-control {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: #e5e5e5;
}

html[data-theme="dark"] .app-global-search-wrap .form-control::placeholder {
  color: #8b8b8b;
}

html[data-theme="dark"] .app-global-search-results {
  background: #2a2a2a;
  border-color: var(--border);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .gs-group {
  border-bottom-color: var(--border);
}

html[data-theme="dark"] .gs-category {
  color: var(--muted);
}

html[data-theme="dark"] .gs-item {
  color: var(--text);
}

html[data-theme="dark"] .gs-item:hover {
  background: #353535;
  color: #86efac;
}

html[data-theme="dark"] .gs-empty {
  color: var(--muted);
}

/* ── Tables ──────────────────────────────────────────────────────── */
html[data-theme="dark"] .table {
  --bs-table-color: var(--text);
  --bs-table-bg: transparent;
  color: var(--text);
}

html[data-theme="dark"] .table > :not(caption) > * > * {
  border-bottom-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .table > thead > tr > th {
  background: #1f1f1f;
  color: #cbd5e1;
  border-bottom-color: var(--border);
}

html[data-theme="dark"] .table > tbody > tr:nth-child(odd) {
  background-color: #262626;
}

html[data-theme="dark"] .table > tbody > tr:nth-child(even) {
  background-color: #2a2a2a;
}

html[data-theme="dark"] .table > tbody > tr:hover > td {
  background-color: #333333 !important;
}

html[data-theme="dark"] .table > tbody > tr:focus-within > td {
  background-color: #3a3a3a !important;
}

/* Раскрываемые строки (.table-row-groups): зебра по записям-<tbody>,
   строка-деталь — своя поверхность, без hover основной таблицы. */
html[data-theme="dark"] .table.table-row-groups > tbody:nth-of-type(odd) > tr {
  background-color: #262626;
}

html[data-theme="dark"] .table.table-row-groups > tbody:nth-of-type(even) > tr {
  background-color: #2a2a2a;
}

html[data-theme="dark"] .table > tbody > tr.table-detail-row > td,
html[data-theme="dark"] .table > tbody > tr.table-detail-row:hover > td,
html[data-theme="dark"] .table > tbody > tr.table-detail-row:focus-within > td {
  background-color: #1f1f1f !important;
}

html[data-theme="dark"] .row-toggle:hover,
html[data-theme="dark"] .row-toggle:focus-visible {
  background: #3a3a3a;
}

/* Склад: строки ниже / близко к минимальному остатку (Parts, min stock) */
html[data-theme="dark"] .table > tbody > tr.stock-row--below > td {
  background-color: rgba(239, 68, 68, 0.12);
}

html[data-theme="dark"] .table > tbody > tr.stock-row--below > td:first-child {
  box-shadow: inset 3px 0 0 #f87171;
}

html[data-theme="dark"] .table > tbody > tr.stock-row--near > td {
  background-color: rgba(245, 158, 11, 0.12);
}

html[data-theme="dark"] .table > tbody > tr.stock-row--near > td:first-child {
  box-shadow: inset 3px 0 0 #fbbf24;
}

/* ── AI assistant widget ─────────────────────────────────────────── */
html[data-theme="dark"] .assistant-panel {
  background: #1c1c1c;
  border-color: var(--border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .assistant-panel-header,
html[data-theme="dark"] .assistant-input-row {
  border-color: var(--border);
}

html[data-theme="dark"] .assistant-msg-assistant {
  background: #2a2a2a;
  color: var(--text);
}

html[data-theme="dark"] .assistant-msg-error {
  background: rgba(220, 53, 69, 0.18);
  color: #f1959f;
}

/* Section header rows (Standard Reports etc.) */
html[data-theme="dark"] .table > tbody > tr.table-section-row > td {
  background-color: #1f1f1f !important;
  color: #cbd5e1;
}

html[data-theme="dark"] .table > tbody > tr.table-section-row:hover > td,
html[data-theme="dark"] .table > tbody > tr.table-section-row:focus-within > td {
  background-color: #1f1f1f !important;
}

/* tfoot — totals rows */
html[data-theme="dark"] .table > tfoot > tr > th,
html[data-theme="dark"] .table > tfoot > tr > td {
  background-color: #1f1f1f;
  color: var(--text);
  border-top-color: var(--border);
}

html[data-theme="dark"] .table > tfoot > tr > td.text-muted,
html[data-theme="dark"] .table > tfoot .text-muted {
  color: var(--muted) !important;
}

html[data-theme="dark"] .sortable-th:hover {
  background: rgba(255, 255, 255, 0.05);
}

html[data-theme="dark"] tr[role="button"]:hover > td {
  background-color: rgba(34, 197, 94, 0.08);
}

/* ── Buttons ─────────────────────────────────────────────────────── */
html[data-theme="dark"] .btn {
  box-shadow: none;
}

html[data-theme="dark"] .btn-primary {
  --bs-btn-bg: #2a2a2a;
  --bs-btn-border-color: #3a3a3a;
  --bs-btn-color: #ececec;
  --bs-btn-hover-bg: #353535;
  --bs-btn-hover-border-color: #4a4a4a;
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: #1f1f1f;
  --bs-btn-active-border-color: #2a2a2a;
}

html[data-theme="dark"] .btn-secondary {
  --bs-btn-bg: #2a2a2a;
  --bs-btn-border-color: #3a3a3a;
  --bs-btn-color: #d4d4d4;
  --bs-btn-hover-bg: #353535;
  --bs-btn-hover-border-color: #4a4a4a;
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: #1f1f1f;
}

html[data-theme="dark"] .btn-light {
  --bs-btn-bg: #2a2a2a;
  --bs-btn-border-color: #3a3a3a;
  --bs-btn-color: #ececec;
  --bs-btn-hover-bg: #353535;
  --bs-btn-hover-border-color: #4a4a4a;
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: #1f1f1f;
}

html[data-theme="dark"] .btn-outline-primary,
html[data-theme="dark"] .btn-outline-secondary,
html[data-theme="dark"] .btn-outline-dark,
html[data-theme="dark"] .btn-outline-light {
  --bs-btn-bg: transparent;
  --bs-btn-border-color: #4a4a4a;
  --bs-btn-color: #ececec;
  --bs-btn-hover-bg: #353535;
  --bs-btn-hover-border-color: #5a5a5a;
  --bs-btn-hover-color: #fff;
  /* нажатое/активное состояние (тумблер видов календаря и т.п.) должно читаться */
  --bs-btn-active-bg: #3a3f47;
  --bs-btn-active-border-color: #6b7280;
  --bs-btn-active-color: #fff;
}

html[data-theme="dark"] .btn-success {
  --bs-btn-bg: #16a34a;
  --bs-btn-border-color: #16a34a;
  --bs-btn-hover-bg: #15803d;
  --bs-btn-hover-border-color: #15803d;
}

html[data-theme="dark"] .btn-outline-success {
  --bs-btn-bg: transparent;
  --bs-btn-color: #4ade80;
  --bs-btn-border-color: #166534;
  --bs-btn-hover-bg: #16a34a;
  --bs-btn-hover-color: #fff;
}

html[data-theme="dark"] .btn-outline-danger {
  --bs-btn-bg: transparent;
  --bs-btn-color: #f87171;
  --bs-btn-border-color: #7f1d1d;
  --bs-btn-hover-bg: #b91c1c;
  --bs-btn-hover-color: #fff;
}

/* В светлой теме у outline-warning/info белый фон (public.css) — без этих
   правил в тёмной теме они горели белыми «островками» (Send for Authorization). */
html[data-theme="dark"] .btn-outline-warning {
  --bs-btn-bg: transparent;
  --bs-btn-color: #fbbf24;
  --bs-btn-border-color: #78350f;
  --bs-btn-hover-bg: #d97706;
  --bs-btn-hover-border-color: #d97706;
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: #b45309;
  --bs-btn-active-border-color: #b45309;
  --bs-btn-active-color: #fff;
}

html[data-theme="dark"] .btn-outline-info {
  --bs-btn-bg: transparent;
  --bs-btn-color: #67e8f9;
  --bs-btn-border-color: #155e75;
  --bs-btn-hover-bg: #0891b2;
  --bs-btn-hover-border-color: #0891b2;
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: #0e7490;
  --bs-btn-active-border-color: #0e7490;
  --bs-btn-active-color: #fff;
}

/* ── Filter / utility surfaces ───────────────────────────────────── */
html[data-theme="dark"] .wo-filter-form {
  background: #232323;
  border-color: var(--border);
}

html[data-theme="dark"] .wo-filter-form .date-preset-select,
html[data-theme="dark"] .wo-filter-form .date-range-group,
html[data-theme="dark"] .wo-filter-form .date-range-group .date-filter-input {
  background: #1f1f1f !important;
  border-color: #3a3a3a !important;
  color: var(--text) !important;
}

html[data-theme="dark"] .wo-filter-form .date-range-group .input-group-text {
  background: #2a2a2a;
  color: #cbd5e1;
}

html[data-theme="dark"] .wo-table-group-row td {
  color: #4ade80;
  background-color: rgba(34, 197, 94, 0.12);
}

html[data-theme="dark"] .table > tbody > tr.wo-table-group-row:hover > td {
  background-color: rgba(34, 197, 94, 0.12) !important;
}

html[data-theme="dark"] .wo-inwork-group > tr > td {
  background-color: rgba(34, 197, 94, 0.06);
}

html[data-theme="dark"] .wo-inwork-group > tr:last-child > td {
  border-bottom-color: rgba(34, 197, 94, 0.4);
}

html[data-theme="dark"] .wo-totals-box {
  background: linear-gradient(135deg, #232323 0%, #1c1c1c 100%) !important;
  border: 1px solid var(--border) !important;
  color: var(--text);
}

html[data-theme="dark"] .wo-totals-box > span {
  background: #2f2f2f !important;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45) !important;
}

html[data-theme="dark"] .wo-totals-box strong {
  color: #4ade80;
}

html[data-theme="dark"] .dashboard-legend-row {
  color: #cbd5e1 !important;
}

/* Soften decorative blurred blobs inside dashboard cards. */
html[data-theme="dark"] .dashboard-async-card .card-body::before {
  background: radial-gradient(circle, rgba(34, 197, 94, 0.18) 0%, transparent 70%);
  opacity: 0.35;
}

html[data-theme="dark"] .dashboard-async-card .card-body::after {
  background: radial-gradient(circle, rgba(56, 189, 248, 0.16) 0%, transparent 70%);
  opacity: 0.30;
}

html[data-theme="dark"] #dashOutstandingBalance {
  background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

html[data-theme="dark"] .dashboard-goal-progress {
  background: #2a2a2a;
}

html[data-theme="dark"] .dashboard-donut-center .small,
html[data-theme="dark"] .dashboard-donut-center .text-muted {
  color: var(--muted) !important;
}

html[data-theme="dark"] .dashboard-donut-center .fw-semibold {
  color: var(--text);
}

/* Пончики: тёмный трек незаполненной части (переменные из dashboard.css). */
html[data-theme="dark"] body.public-shell {
  --donut-track: #3a3a3a;
  --donut-track-2: #2f2f2f;
}

/* Пончики: «дырка» и её ободок — в тёмных поверхностях вместо белого. */
html[data-theme="dark"] .dashboard-donut::after,
html[data-theme="dark"] .dashboard-goal-mini-ring::after {
  background: radial-gradient(circle at 50% 30%, #2f2f2f 0%, #262626 70%, #1f1f1f 100%);
  box-shadow:
    inset 0 0 0 1px rgba(70, 70, 70, 0.9),
    inset 0 6px 14px rgba(0, 0, 0, 0.35);
}

/* ── Labor hours trend (график часов в карточке Goals) ───────────── */
html[data-theme="dark"] {
  /* Неоновые оттенки под тёмную поверхность — свечение линий берёт эти же
     токены через color-mix (см. dashboard.css). */
  --rb-hours-actual: #4da3ff;
  --rb-hours-invoiced: #ff7a45;
  --rb-hours-uattend: #2ee6a3;
  --rb-hours-grid: #333333;
  --rb-hours-axis: #4a4a4a;
  --rb-hours-surface: #2a2a2a;
}

/* Пончики: неоновое свечение ярче на тёмном фоне. */
html[data-theme="dark"] .dashboard-donut {
  filter:
    drop-shadow(0 0 12px rgba(34, 197, 94, 0.55))
    drop-shadow(0 0 30px rgba(239, 68, 68, 0.28));
}
html[data-theme="dark"] .dashboard-dual-ring-outer {
  filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.55));
}
html[data-theme="dark"] .dashboard-dual-ring-inner {
  filter: drop-shadow(0 0 10px rgba(34, 197, 94, 0.55));
}
html[data-theme="dark"] .dashboard-goal-mini-ring {
  filter: drop-shadow(0 0 14px rgba(129, 140, 248, 0.45));
}
html[data-theme="dark"] #dashGoalLaborRing { filter: drop-shadow(0 0 14px rgba(251, 191, 36, 0.5)); }
html[data-theme="dark"] #dashGoalPartsRing { filter: drop-shadow(0 0 14px rgba(56, 189, 248, 0.5)); }
html[data-theme="dark"] #dashGoalTotalRing { filter: drop-shadow(0 0 14px rgba(52, 211, 153, 0.5)); }

/* Пончики: читаемость в тёмной теме — тёмный «зазор» дуального кольца,
   тёмные ореолы легенды, светлый текст процентов. */
html[data-theme="dark"] .dashboard-dual-gap {
  border-color: #262626;
  box-shadow:
    inset 0 0 0 1px rgba(74, 74, 74, 0.9),
    0 1px 2px rgba(0, 0, 0, 0.4);
}
html[data-theme="dark"] .dashboard-dot {
  box-shadow: 0 0 0 2px rgba(38, 38, 38, 0.9), 0 0 6px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .dashboard-goal-mini-percent {
  background: linear-gradient(135deg, #f1f5f9 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
html[data-theme="dark"] .dashboard-donut-percent {
  background: linear-gradient(135deg, rgba(46, 46, 46, 0.85) 0%, rgba(34, 34, 34, 0.6) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(82, 82, 82, 0.85),
    0 2px 6px rgba(0, 0, 0, 0.4);
  color: #4ade80;
}
/* Белый глянец-блик поверх колец приглушаем — на тёмном он засвечивал сегменты. */
html[data-theme="dark"] .dashboard-donut::before,
html[data-theme="dark"] .dashboard-goal-mini-ring::before,
html[data-theme="dark"] .dashboard-dual-ring-outer::before,
html[data-theme="dark"] .dashboard-dual-ring-inner::before {
  opacity: 0.35;
}

html[data-theme="dark"] .dashboard-hours-section {
  border-top-color: var(--border);
}

html[data-theme="dark"] .dashboard-hours-tick {
  fill: #9b9b9b;
}

html[data-theme="dark"] .dashboard-hours-crosshair {
  stroke: #6b7280;
}

html[data-theme="dark"] .dashboard-hours-tooltip {
  background: rgba(35, 35, 35, 0.97);
  border-color: var(--border);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .dashboard-hours-tooltip-head,
html[data-theme="dark"] .dashboard-hours-tooltip-row strong {
  color: var(--text);
}

html[data-theme="dark"] .dashboard-hours-tooltip-name,
html[data-theme="dark"] .dashboard-hours-tooltip-delta {
  color: var(--muted);
}

/* ── Раскрытые работы WO в истории юнита ─────────────────────────── */
html[data-theme="dark"] .wo-labors-panel {
  background: var(--surface-soft);
  border-top-color: var(--border);
}

html[data-theme="dark"] .wo-labors-item {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-soft);
}

html[data-theme="dark"] .wo-labors-item-title {
  color: var(--text);
}

html[data-theme="dark"] .wo-labors-item-icon {
  background: rgba(34, 197, 94, 0.16);
  color: #4ade80;
}

html[data-theme="dark"] .wo-labors-hours-badge {
  background: rgba(129, 140, 248, 0.18);
  color: #a5b4fc;
}

html[data-theme="dark"] .wo-labors-item-total {
  color: var(--muted);
}

html[data-theme="dark"] .wo-labors-item-total strong {
  color: var(--text);
}

/* ── Flatpickr ──────────────────────────────────────────────────── */
html[data-theme="dark"] .flatpickr-calendar {
  background: #2a2a2a;
  border-color: var(--border);
  color: var(--text);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .flatpickr-months {
  background: #1f1f1f;
}

html[data-theme="dark"] .flatpickr-weekdays {
  background: #232323;
}

html[data-theme="dark"] span.flatpickr-weekday {
  color: #cbd5e1;
}

html[data-theme="dark"] .flatpickr-day {
  color: var(--text);
  background: transparent;
}

html[data-theme="dark"] .flatpickr-day:hover {
  background: #353535;
  border-color: #353535;
}

html[data-theme="dark"] .flatpickr-day.selected,
html[data-theme="dark"] .flatpickr-day.startRange,
html[data-theme="dark"] .flatpickr-day.endRange {
  background: var(--primary);
  border-color: var(--primary);
  color: #0b1220;
}

html[data-theme="dark"] .flatpickr-day.today {
  border-color: var(--primary);
  color: #4ade80;
}

html[data-theme="dark"] .flatpickr-day.flatpickr-disabled,
html[data-theme="dark"] .flatpickr-day.prevMonthDay,
html[data-theme="dark"] .flatpickr-day.nextMonthDay {
  color: #555;
}

/* ── Modals / dropdowns / popovers ──────────────────────────────── */
html[data-theme="dark"] .modal-content {
  background: #232323;
  border: 1px solid var(--border);
  color: var(--text);
}

html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
  border-color: var(--border);
  background: #1f1f1f;
  color: var(--text);
}

html[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(1.6);
}

html[data-theme="dark"] .dropdown-menu {
  background: #2a2a2a;
  border-color: var(--border);
  color: var(--text);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .dropdown-item {
  color: var(--text);
}

html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .dropdown-item:focus {
  background: #353535;
  color: #fff;
}

html[data-theme="dark"] .dropdown-divider {
  border-color: var(--border);
}

/* ── Code / preformatted text (email view, addresses) ─────────────── */
html[data-theme="dark"] pre {
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--border) !important;
}

html[data-theme="dark"] code {
  color: #f472b6;
}

/* ── Alerts / badges ─────────────────────────────────────────────── */
html[data-theme="dark"] .alert {
  background: #232323;
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .alert-success {
  background: rgba(34, 197, 94, 0.10);
  border-color: rgba(34, 197, 94, 0.30);
  color: #86efac;
}

html[data-theme="dark"] .alert-danger {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.30);
  color: #fca5a5;
}

html[data-theme="dark"] .alert-warning {
  background: rgba(245, 158, 11, 0.10);
  border-color: rgba(245, 158, 11, 0.30);
  color: #fcd34d;
}

html[data-theme="dark"] .alert-info {
  background: rgba(56, 189, 248, 0.10);
  border-color: rgba(56, 189, 248, 0.30);
  color: #7dd3fc;
}

html[data-theme="dark"] .badge.bg-light,
html[data-theme="dark"] .badge.text-bg-light {
  background: #2a2a2a !important;
  color: var(--text) !important;
}

/* Бэджи в тёмной теме — приглушённый фон + светлый текст вместо
   сплошных ярких заливок Bootstrap (единый вид со статусами портала).
   Покрывает text-bg-*, bg-* и bg-*-subtle варианты. */
html[data-theme="dark"] .badge.text-bg-success,
html[data-theme="dark"] .badge.bg-success,
html[data-theme="dark"] .badge.bg-success-subtle {
  background: rgba(34, 197, 94, 0.16) !important;
  color: #4ade80 !important;
}

html[data-theme="dark"] .badge.text-bg-secondary,
html[data-theme="dark"] .badge.bg-secondary,
html[data-theme="dark"] .badge.bg-secondary-subtle {
  background: rgba(148, 163, 184, 0.16) !important;
  color: #cbd5e1 !important;
}

html[data-theme="dark"] .badge.text-bg-primary,
html[data-theme="dark"] .badge.bg-primary,
html[data-theme="dark"] .badge.bg-primary-subtle {
  background: rgba(59, 130, 246, 0.18) !important;
  color: #93c5fd !important;
}

html[data-theme="dark"] .badge.text-bg-warning,
html[data-theme="dark"] .badge.bg-warning,
html[data-theme="dark"] .badge.bg-warning-subtle {
  background: rgba(245, 158, 11, 0.16) !important;
  color: #fbbf24 !important;
}

html[data-theme="dark"] .badge.text-bg-danger,
html[data-theme="dark"] .badge.bg-danger,
html[data-theme="dark"] .badge.bg-danger-subtle {
  background: rgba(239, 68, 68, 0.16) !important;
  color: #f87171 !important;
}

html[data-theme="dark"] .badge.text-bg-info,
html[data-theme="dark"] .badge.bg-info,
html[data-theme="dark"] .badge.bg-info-subtle {
  background: rgba(56, 189, 248, 0.16) !important;
  color: #7dd3fc !important;
}

html[data-theme="dark"] .badge.text-bg-dark,
html[data-theme="dark"] .badge.bg-dark {
  background: rgba(255, 255, 255, 0.10) !important;
  color: #e5e5e5 !important;
}

/* ── Nav tabs / pagination ──────────────────────────────────────── */
html[data-theme="dark"] .nav-tabs {
  border-bottom-color: var(--border);
}

html[data-theme="dark"] .nav-tabs .nav-link {
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}

html[data-theme="dark"] .nav-tabs .nav-link:hover {
  color: var(--text);
  border-color: var(--border);
}

html[data-theme="dark"] .nav-tabs .nav-link.active {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border) var(--border) var(--surface);
}

html[data-theme="dark"] .page-link {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .page-link:hover {
  background: #353535;
  color: #fff;
}

html[data-theme="dark"] .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
  color: #0b1220;
}

html[data-theme="dark"] .page-item.disabled .page-link {
  background: var(--surface-soft);
  color: #555;
}

/* ── Sidebar footer + theme toggle button ───────────────────────── */
.app-sidebar-card {
  display: flex;
  flex-direction: column;
}

.app-sidebar-footer {
  flex: 0 0 auto;
  margin-top: auto;
  padding: 0.55rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: var(--sidebar-bg);
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #e5e5e5;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.theme-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.theme-toggle-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  flex: 0 0 1.1rem;
}

.theme-toggle-btn svg {
  width: 100%;
  height: 100%;
}

.theme-toggle-icon-sun,
.theme-toggle-label-dark {
  display: none;
}

.theme-toggle-icon-moon,
.theme-toggle-label-light {
  display: inline-block;
}

.theme-toggle-label {
  white-space: nowrap;
}

html[data-theme="dark"] .theme-toggle-icon-sun,
html[data-theme="dark"] .theme-toggle-label-dark {
  display: inline-block;
}

html[data-theme="dark"] .theme-toggle-icon-moon,
html[data-theme="dark"] .theme-toggle-label-light {
  display: none;
}

/* Collapsed sidebar: hide label, center icon */
.app-shell.sidebar-collapsed .app-sidebar-footer {
  padding: 0.45rem;
}

.app-shell.sidebar-collapsed .theme-toggle-btn {
  justify-content: center;
  padding: 0.62rem 0.45rem;
}

.app-shell.sidebar-collapsed .theme-toggle-label {
  display: none;
}

/* ── Calendar (appointments board) ────────────────────────────────
   Grid colours live in CSS variables on .cal-grid (calendar.css);
   block colours come from the status settings and pick their own text
   colour by luminance, so only the surfaces need overriding here. */
html[data-theme="dark"] .cal-grid {
  --cal-line: #3a3a3a;
  --cal-line-soft: #2d2d2d;
  --cal-head-bg: #1e1e1e;
  --cal-body-bg: #232323;
  --cal-col-hover: rgba(255, 255, 255, 0.035);
  --cal-today-bg: rgba(34, 197, 94, 0.07);
  --cal-now: #f28b82;
}

html[data-theme="dark"] .cal-col-head.is-clickable:hover {
  background: #262626;
}

html[data-theme="dark"] .cal-col-head.is-today .cal-dom {
  color: #0b1220;
}

html[data-theme="dark"] .cal-mech-legend-btn:hover,
html[data-theme="dark"] .cal-mech-legend-btn.is-active {
  background: #1e1e1e;
  color: var(--text);
}

html[data-theme="dark"] .cal-event {
  border-color: rgba(0, 0, 0, 0.4);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .cal-event:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.7);
}

html[data-theme="dark"] .cal-event.is-dragging,
html[data-theme="dark"] .cal-event.is-resizing {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.8);
}

html[data-theme="dark"] .cal-mech-chip {
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}

/* Status board: columns sit on the darker surface, cards on the lighter one. */
html[data-theme="dark"] .cal-board-col {
  background: #1e1e1e;
}

html[data-theme="dark"] .cal-board-count {
  background: #333333;
  color: #cbd5e1;
}

html[data-theme="dark"] .cal-card:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.7);
}

html[data-theme="dark"] .cal-card.is-ghost {
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.8);
}

html[data-theme="dark"] .cal-live.is-live .cal-live-dot {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22);
}

html[data-theme="dark"] .cal-event-wo {
  background: rgba(0, 0, 0, 0.45);
  color: #f1f1f1;
}

html[data-theme="dark"] .cal-linked-wo,
html[data-theme="dark"] .cal-tag {
  background: #1e1e1e;
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .cal-search .form-control[readonly]:not(:disabled) {
  background-color: #2a2a2a;
  color: var(--muted);
}

html[data-theme="dark"] .cal-search .list-group-item-action:hover,
html[data-theme="dark"] .cal-search .list-group-item-action:focus {
  background: #333333;
  color: var(--text);
}

html[data-theme="dark"] .cal-search .list-group-item.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #0b1220;
}

html[data-theme="dark"] .cal-status-btn:focus-visible {
  box-shadow: 0 0 0 0.2rem rgba(34, 197, 94, 0.3);
}

html[data-theme="dark"] #apptOverlapHint {
  color: #f59e0b;
}

/* -- WO header / Customer info / Timeline / Attachments -- */
html[data-theme="dark"] .wo-header { background: #1e1e1e !important; border-color: var(--border) !important; color: var(--text); }
html[data-theme="dark"] .wo-header .text-muted { color: var(--muted) !important; }
html[data-theme="dark"] #customerInfoBlock,
html[data-theme="dark"] .bg-light-subtle { background-color: #1e1e1e !important; border-color: var(--border) !important; color: var(--text); }
html[data-theme="dark"] #customerInfoBlock .text-muted { color: var(--muted) !important; }
html[data-theme="dark"] #workOrderDatesBlock .bg-white,
html[data-theme="dark"] .bg-white { background-color: #1e1e1e !important; color: var(--text); }
html[data-theme="dark"] #workOrderDatesBlock .border { border-color: var(--border) !important; }
html[data-theme="dark"] .attachments-block { background: #1e1e1e !important; border-color: var(--border) !important; color: var(--text); }
html[data-theme="dark"] .att-item { background: #2a2a2a !important; border-color: var(--border) !important; }
html[data-theme="dark"] .att-item .att-name { background: #232323 !important; color: var(--muted) !important; border-top-color: var(--border) !important; }
html[data-theme="dark"] .att-item .att-pdf-thumb { background: #2a2a2a !important; }

/* -- WO totals chips -- */
html[data-theme="dark"] .wo-totals-chip {
  background: #2a2a2a !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .wo-totals-chip strong {
  color: #4ade80 !important;
}
html[data-theme="dark"] .wo-totals-chip.wo-grand-total {
  background: linear-gradient(135deg, #14532d, #166534) !important;
  border-color: #22c55e !important;
  color: #ffffff !important;
}
html[data-theme="dark"] .wo-totals-chip.wo-grand-total strong {
  color: #ffffff !important;
}

/* -- WO labor cards -- */
html[data-theme="dark"] .wo-labor.card {
  background: #1e1e1e !important;
  border-color: var(--border) !important;
  color: var(--text);
}
html[data-theme="dark"] .wo-labor .wo-labor-header {
  border-bottom-color: var(--border) !important;
}

/* -- Select2 (work-order enhanced + generic) -- */
html[data-theme="dark"] .work-order-enhanced-select + .select2-container .select2-selection--single,
html[data-theme="dark"] .select2-container--default .select2-selection--single,
html[data-theme="dark"] .select2-container--default .select2-selection--multiple {
  background: #1f1f1f !important;
  border-color: #3a3a3a !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .work-order-enhanced-select + .select2-container .select2-selection__rendered,
html[data-theme="dark"] .select2-container--default .select2-selection__rendered,
html[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered {
  color: var(--text) !important;
}
html[data-theme="dark"] .work-order-enhanced-select + .select2-container--open .select2-selection--single,
html[data-theme="dark"] .work-order-enhanced-select + .select2-container--focus .select2-selection--single {
  background: #1f1f1f !important;
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 0.2rem rgba(34,197,94,0.18) !important;
}
html[data-theme="dark"] .work-order-enhanced-select + .select2-container--disabled .select2-selection--single {
  background: #2a2a2a !important;
  color: var(--muted) !important;
}
html[data-theme="dark"] .work-order-enhanced-select + .select2-container .select2-selection__arrow b {
  border-color: #cbd5e1 transparent transparent transparent !important;
}
html[data-theme="dark"] .select2-dropdown,
html[data-theme="dark"] .select2-dropdown.ss-work-order-select2-dropdown {
  background: #1f1f1f !important;
  border-color: #3a3a3a !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .select2-container--default .select2-results__option {
  color: var(--text) !important;
  background: transparent !important;
}
html[data-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected],
html[data-theme="dark"] .select2-container--default .select2-results__option--highlighted {
  background: rgba(34,197,94,0.18) !important;
  color: #ffffff !important;
}
html[data-theme="dark"] .select2-container--default .select2-results__option[aria-selected=true],
html[data-theme="dark"] .select2-container--default .select2-results__option--selected {
  background: #2a2a2a !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .select2-search--dropdown {
  background: #1f1f1f !important;
  padding: 6px !important;
}
html[data-theme="dark"] .select2-search--dropdown .select2-search__field {
  background: #161616 !important;
  border-color: #3a3a3a !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .select2-dropdown .select2-results,
html[data-theme="dark"] .select2-dropdown .select2-results__options {
  background: #1f1f1f !important;
}

/* -- Integrations modal (uAttend etc.) --------------------------- */
html[data-theme="dark"] .integration-modal .input-group-text {
  background: #2a2a2a;
  border-color: #3a3a3a;
  color: #cbd5e1;
}
html[data-theme="dark"] .integration-modal .form-control,
html[data-theme="dark"] .integration-modal .form-control:focus {
  background: #1f1f1f;
  border-color: #3a3a3a;
  color: var(--text);
}
html[data-theme="dark"] .integration-modal .form-control::placeholder {
  color: #6b7280;
}
html[data-theme="dark"] .integration-modal hr {
  border-color: var(--border);
  opacity: 0.6;
}
html[data-theme="dark"] .integration-modal .table tbody tr,
html[data-theme="dark"] .integration-modal .table tbody td {
  background: transparent;
  color: var(--text);
  border-color: transparent;
}
html[data-theme="dark"] .integration-modal .table tbody tr:hover td {
  background: #2a2a2a;
}


/* -- Parts search dropdown (work order details) ------------------ */
html[data-theme="dark"] .parts-dd {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
  color: var(--text);
}

html[data-theme="dark"] .parts-dd-item {
  border-bottom-color: var(--border);
}

html[data-theme="dark"] .parts-dd-item:hover,
html[data-theme="dark"] .parts-dd-item:focus,
html[data-theme="dark"] .parts-dd-item.is-active {
  background: #353535;
}

html[data-theme="dark"] .parts-dd-item-onetime {
  background: #232323;
}

html[data-theme="dark"] .parts-dd-item-alt {
  background: #232323;
  border-left-color: var(--border);
}

html[data-theme="dark"] .cross-ref-alt-item {
  border-left-color: var(--border);
}

html[data-theme="dark"] .parts-dd-item-onetime:hover,
html[data-theme="dark"] .parts-dd-item-onetime:focus,
html[data-theme="dark"] .parts-dd-item-onetime.is-active {
  background: #2f2f2f;
}

html[data-theme="dark"] .parts-dd-title {
  color: var(--text);
}

html[data-theme="dark"] .parts-dd-meta,
html[data-theme="dark"] .parts-dd-empty {
  color: var(--muted);
}

/* -- SweetAlert2 popups & toasts -------------------------------- */
html[data-theme="dark"] .swal2-popup {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card) !important;
}

html[data-theme="dark"] .swal2-title,
html[data-theme="dark"] .swal2-html-container {
  color: var(--text) !important;
}

html[data-theme="dark"] .swal2-toast {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55) !important;
}

html[data-theme="dark"] .swal2-toast .swal2-title {
  color: var(--text) !important;
}

html[data-theme="dark"] .swal2-timer-progress-bar {
  background: rgba(34, 197, 94, 0.35) !important;
}

html[data-theme="dark"] .swal2-close {
  color: var(--muted) !important;
}

html[data-theme="dark"] .swal2-close:hover {
  color: var(--text) !important;
}

/* Строка ошибки под формой в диалоге (Receive Order, Return и т.п.) */
html[data-theme="dark"] .swal2-validation-message {
  background: rgba(239, 68, 68, 0.14) !important;
  color: var(--text) !important;
}

html[data-theme="dark"] .swal2-container.swal2-backdrop-show {
  background: rgba(0, 0, 0, 0.65) !important;
}

/* ── Icon tiles: тёмные варианты ───────────────────────────────────── */
html[data-theme="dark"] .icon-tile-green { background: rgba(34, 197, 94, 0.14); color: #4ade80; }
html[data-theme="dark"] .icon-tile-amber { background: rgba(245, 158, 11, 0.14); color: #fbbf24; }
html[data-theme="dark"] .icon-tile-sage  { background: rgba(45, 139, 88, 0.16);  color: #6ee7a8; }
html[data-theme="dark"] .icon-tile-blue  { background: rgba(59, 130, 246, 0.14); color: #7ab8ff; }
html[data-theme="dark"] .icon-tile-red   { background: rgba(239, 68, 68, 0.14);  color: #f87171; }

/* ── VIN-валидация: тёмный вариант подсветки ───────────────────────── */
html[data-theme="dark"] .vin-checking {
  border-color: #4a8cff !important;
  background-color: rgba(59, 130, 246, 0.15) !important;
}

/* ── Скроллбары в тёмной теме ──────────────────────────────────────── */
html[data-theme="dark"] {
  scrollbar-color: #4a4a4a #1f1f1f;
}

html[data-theme="dark"] ::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

html[data-theme="dark"] ::-webkit-scrollbar-track {
  background: transparent;
}

html[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #4a4a4a;
  border-radius: 8px;
  border: 2px solid #212121;
}

html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: #5a5a5a;
}

/* ── Публичная страница авторизации работ: тёмные варианты ─────────── */
html[data-theme="dark"] .auth-card .card-header {
  background: #14532d;
  color: #ffffff;
}

html[data-theme="dark"] .auth-status-approved { background: rgba(34, 197, 94, 0.18);  color: #4ade80; }
html[data-theme="dark"] .auth-status-declined { background: rgba(239, 68, 68, 0.18);  color: #f87171; }
html[data-theme="dark"] .auth-status-pending  { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }

/* ── Клиентский портал: тёмные варианты ────────────────────────────── */
html[data-theme="dark"] .portal-header { background: #14532d; }
html[data-theme="dark"] .portal-card { border-color: var(--border); background: var(--surface); }
html[data-theme="dark"] .portal-attachment-name { color: var(--text); }
html[data-theme="dark"] .portal-section-title { color: #4ade80; border-bottom-color: #2f6b47; }
html[data-theme="dark"] .portal-tabs .nav-link { color: #6ee7a8; }
html[data-theme="dark"] .portal-tabs .nav-link.active { color: #4ade80; border-bottom-color: #4ade80; }
html[data-theme="dark"] .badge-status-open     { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
html[data-theme="dark"] .badge-status-paid     { background: rgba(34, 197, 94, 0.18);  color: #4ade80; }
html[data-theme="dark"] .badge-status-pending  { background: rgba(148, 163, 184, 0.20); color: #cbd5e1; }
html[data-theme="dark"] .badge-status-approved { background: rgba(34, 197, 94, 0.18);  color: #4ade80; }
html[data-theme="dark"] .badge-status-declined { background: rgba(239, 68, 68, 0.18);  color: #f87171; }

/* ── Flex tables ── */
[data-theme="dark"] .ft-gear { color: #93a0b5; border-color: #2a3446; }
[data-theme="dark"] .ft-gear:hover,
[data-theme="dark"] .ft-gear:focus {
  color: #7fb3fa;
  border-color: rgba(96, 165, 250, 0.5);
  background: rgba(96, 165, 250, 0.08);
}
[data-theme="dark"] .ft-resize-handle::after { background: rgba(148, 163, 184, 0.3); }

[data-theme="dark"] .ft-menu {
  background: #171e2b;
  border-color: #2a3446;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}
[data-theme="dark"] .ft-menu__title { color: #7d8aa0; }
[data-theme="dark"] .ft-menu__item { color: #d6deeb; }
[data-theme="dark"] .ft-menu__item:hover { background: rgba(96, 165, 250, 0.1); }

[data-theme="dark"] .ft-menu__reset {
  border-color: #2a3446;
  color: #93a0b5;
}
[data-theme="dark"] .ft-menu__reset:hover { background: rgba(255, 255, 255, 0.06); color: #d6deeb; }

[data-theme="dark"] .ft-resize-handle:hover::after,
[data-theme="dark"] body.ft-resizing .ft-resize-handle::after { background: rgba(96, 165, 250, 0.7); }
[data-theme="dark"] th:last-child > .ft-resize-handle::after { background: transparent; }
[data-theme="dark"] th:last-child > .ft-resize-handle:hover::after,
[data-theme="dark"] body.ft-resizing th:last-child > .ft-resize-handle::after { background: rgba(96, 165, 250, 0.7); }

/* ── Activity Journal ── */
html[data-theme="dark"] .journal-row--technical td { color: var(--muted); }
html[data-theme="dark"] .journal-row--failed td:first-child { box-shadow: inset 3px 0 0 #f87171; }
html[data-theme="dark"] .journal-expand-hint { color: #80868b; }
html[data-theme="dark"] .journal-details-cell { background: #1e1e1e; color: var(--text); }
html[data-theme="dark"] .journal-old { color: #f87171; text-decoration-color: rgba(248, 113, 113, .5); }
html[data-theme="dark"] .journal-new { color: #4ade80; }
html[data-theme="dark"] .journal-payload { background: #121212; border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .journal-table .badge.text-bg-light { background: #2a2a2a !important; color: var(--text) !important; border-color: var(--border) !important; }

/* ── Roles & Permissions (roles.css) ───────────────────────────────
   Один набор rp-* классов у страницы Settings → Roles и у модалки
   Users & Roles → Permissions. Тёмные значения токенов roles.css плюс
   поверхности, заданные там жёстко (#fff, светлые градиенты, тёмный
   текст). Цветные варианты (is-allow / is-checked / is-partial…)
   повторены явно — общие правила ниже их перебили бы. */
html[data-theme="dark"] {
  --rp-brand: #22c55e;
  --rp-brand-soft: rgba(34, 197, 94, 0.14);
  --rp-brand-soft-2: rgba(34, 197, 94, 0.32);
  --rp-brand-dark: #16a34a;
  --rp-danger: #f87171;
  --rp-danger-soft: rgba(239, 68, 68, 0.16);
  --rp-warn: #fbbf24;
  --rp-warn-soft: rgba(245, 158, 11, 0.16);
  --rp-muted: #9b9b9b;
  --rp-border: #3a3a3a;
  --rp-border-strong: #4a4a4a;
  --rp-bg-soft: #2f2f2f;
  --rp-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --rp-shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .rp-page-title,
html[data-theme="dark"] .rp-card-header .rp-title,
html[data-theme="dark"] .rp-role-name,
html[data-theme="dark"] .rp-group-title,
html[data-theme="dark"] .rp-perm-label,
html[data-theme="dark"] .rp-empty-title,
html[data-theme="dark"] .rp-up-stat .rp-up-stat-value {
  color: var(--text);
}

html[data-theme="dark"] .rp-card {
  background: var(--surface);
}

html[data-theme="dark"] .rp-card-header,
html[data-theme="dark"] .rp-editor-toolbar {
  background: var(--surface-soft);
}

html[data-theme="dark"] .rp-role-row.is-active .rp-role-icon {
  background: #16a34a;
  color: #fff;
}

/* Теги ролей */
html[data-theme="dark"] .rp-tag-protected { border-color: rgba(245, 158, 11, 0.35); }
html[data-theme="dark"] .rp-tag-system {
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
  border-color: rgba(129, 140, 248, 0.35);
}
html[data-theme="dark"] .rp-tag-users {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
  border-color: #3a3a3a;
}

/* Поля: имя роли, поиск прав */
html[data-theme="dark"] .rp-name-input,
html[data-theme="dark"] .rp-search input {
  background: #1f1f1f;
  border-color: #3a3a3a;
  color: var(--text);
}
html[data-theme="dark"] .rp-name-input::placeholder,
html[data-theme="dark"] .rp-search input::placeholder {
  color: #6b7280;
}
html[data-theme="dark"] .rp-name-input:focus,
html[data-theme="dark"] .rp-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}
html[data-theme="dark"] .rp-name-input:disabled {
  background: #2a2a2a;
  color: var(--muted);
}
html[data-theme="dark"] .rp-meta-line code {
  background: #1f1f1f;
  color: #cbd5e1;
}

/* Кнопки */
html[data-theme="dark"] .rp-btn-primary,
html[data-theme="dark"] .rp-btn-success {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}
html[data-theme="dark"] .rp-btn-primary:hover:not(:disabled),
html[data-theme="dark"] .rp-btn-success:hover:not(:disabled) {
  background: #15803d;
  border-color: #15803d;
}
html[data-theme="dark"] .rp-btn-outline {
  background: transparent;
  color: var(--text);
  border-color: #4a4a4a;
}
html[data-theme="dark"] .rp-btn-outline:hover:not(:disabled) {
  background: #353535;
  border-color: #5a5a5a;
}
html[data-theme="dark"] .rp-btn-danger {
  background: transparent;
  color: #f87171;
  border-color: #7f1d1d;
}
html[data-theme="dark"] .rp-btn-ghost:hover:not(:disabled) {
  color: var(--text);
}

/* Дерево прав роли */
html[data-theme="dark"] .rp-group,
html[data-theme="dark"] .rp-group-head {
  background: var(--surface-soft);
}
html[data-theme="dark"] .rp-group:hover { border-color: #4a4a4a; }
html[data-theme="dark"] .rp-group.is-open .rp-group-head { background: #1f1f1f; }
html[data-theme="dark"] .rp-group-count { background: #333333; }
html[data-theme="dark"] .rp-group-count.is-partial { background: var(--rp-brand-soft); color: #4ade80; }
html[data-theme="dark"] .rp-group-count.is-full { background: #16a34a; color: #fff; }
html[data-theme="dark"] .rp-mini-btn {
  background: transparent;
  color: #cbd5e1;
}
html[data-theme="dark"] .rp-mini-btn:hover {
  background: var(--rp-brand-soft);
  border-color: var(--rp-brand-soft-2);
  color: #4ade80;
}
html[data-theme="dark"] .rp-perm.is-checked .rp-perm-label { color: #86efac; }

/* Модалка прав пользователя: сводка, таблица, пилюли, тумблеры */
html[data-theme="dark"] .rp-up-stat { background: var(--surface); }
html[data-theme="dark"] .rp-up-stat.is-allow .rp-up-stat-value { color: #4ade80; }
html[data-theme="dark"] .rp-up-stat.is-deny .rp-up-stat-value { color: #f87171; }
html[data-theme="dark"] .rp-up-stat.is-eff .rp-up-stat-value { color: #93c5fd; }

/* Строка-заголовок группы прав — как .table-section-row: не реагирует на hover */
html[data-theme="dark"] .rp-up-table tbody tr.rp-up-group td,
html[data-theme="dark"] .rp-up-table tbody tr.rp-up-group:hover td {
  background: #1f1f1f !important;
  color: #cbd5e1;
}

html[data-theme="dark"] .rp-pill-yes { color: #4ade80; }
html[data-theme="dark"] .rp-pill-no {
  background: rgba(148, 163, 184, 0.12);
  color: #9b9b9b;
}
html[data-theme="dark"] .rp-pill-effective-on {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

html[data-theme="dark"] .rp-toggle .slider { background: #4a4a4a; }
html[data-theme="dark"] .rp-toggle .slider::before {
  background: #f1f1f1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ── Education Center (/education) ─────────────────────────────────
   Основа education.css строится на --surface/--border/--text/--muted,
   которые уже переопределены выше; здесь — только жёстко заданные
   оттенки выносок, трека прогресса, kbd и подложки скриншотов. */
html[data-theme="dark"] {
  --edu-accent-soft: rgba(34, 197, 94, 0.14);
  --edu-ring-track: #3a3a3a;
  --edu-tip-bg: rgba(34, 197, 94, 0.1);
  --edu-tip-border: rgba(34, 197, 94, 0.35);
  --edu-tip-icon: #4ade80;
  --edu-warn-bg: rgba(245, 158, 11, 0.1);
  --edu-warn-border: rgba(245, 158, 11, 0.35);
  --edu-warn-icon: #fbbf24;
  --edu-note-bg: rgba(59, 130, 246, 0.1);
  --edu-note-border: rgba(59, 130, 246, 0.35);
  --edu-note-icon: #7ab8ff;
  --edu-kbd-bg: #333333;
  --edu-kbd-border: #4a4a4a;
  --edu-shot-bg: #1a1a1a;
}
html[data-theme="dark"] .edu-hero-title,
html[data-theme="dark"] .edu-lesson-title,
html[data-theme="dark"] .edu-module-title,
html[data-theme="dark"] .edu-step-title,
html[data-theme="dark"] .edu-lesson-body,
html[data-theme="dark"] .edu-lesson-body h2,
html[data-theme="dark"] .edu-summary-title,
html[data-theme="dark"] .edu-ring-inner strong,
html[data-theme="dark"] .edu-ring-meta,
html[data-theme="dark"] .edu-ui,
html[data-theme="dark"] .edu-toc-list a,
html[data-theme="dark"] .edu-search-item,
html[data-theme="dark"] .edu-lesson-row-link,
html[data-theme="dark"] .edu-module,
html[data-theme="dark"] .edu-module:hover,
html[data-theme="dark"] .edu-path-list li a {
  color: var(--text);
}
html[data-theme="dark"] .edu-module-icon { background: var(--edu-accent-soft); color: #4ade80; }
html[data-theme="dark"] .edu-step-num { background: var(--primary); color: #0b1220; }
html[data-theme="dark"] .edu-lesson-row.is-done .edu-lesson-row-num,
html[data-theme="dark"] .edu-toc-list li.is-done .edu-toc-mark { color: #0b1220; }
html[data-theme="dark"] .edu-toc-list li.is-current a { color: #4ade80; }
html[data-theme="dark"] .edu-search-item mark { background: rgba(34, 197, 94, 0.3); }
html[data-theme="dark"] .edu-shot-link { border-color: var(--border); }
html[data-theme="dark"] .edu-shot-link img { filter: brightness(0.96); }
html[data-theme="dark"] .edu-lightbox img { background: #2a2a2a; }
html[data-theme="dark"] .edu-status-chip.is-done { color: #4ade80; border-color: rgba(34, 197, 94, 0.4); }
html[data-theme="dark"] .edu-path-list li.is-done a { color: var(--muted); }
html[data-theme="dark"] .assistant-shot { background: #1a1a1a; border-color: var(--border); }
html[data-theme="dark"] .assistant-lesson-link,
html[data-theme="dark"] .assistant-edu-link { color: #4ade80; }
