/*
 * SIBCOR dashboard — общие дизайн-токены и тёмная тема.
 * Подключается ПОСЛЕ инлайновых стилей страницы и переопределяет токены.
 * Тема хранится в localStorage("sibcor-theme"): "light" | "dark".
 */

:root {
  --bg: #f4f4f3;
  --bg-accent: #ebebea;
  --card: rgba(255, 255, 255, 0.92);
  --card-strong: #ffffff;
  --border: rgba(76, 80, 90, 0.14);
  --accent: #ffd900;
  --accent-2: #d9cf58;
  --accent-soft: rgba(255, 217, 0, 0.16);
  --plan: #8f2f2f;
  --fact: #676b74;
  --fact-anc: #b4ab36;
  --muted: #70747d;
  --text: #3f434b;
  --heading: #45484f;
  --shadow: 0 30px 80px rgba(31, 35, 43, 0.08);
  --shadow-soft: 0 12px 34px rgba(31, 35, 43, 0.08);
  --radius-l: 22px;
  --radius-m: 14px;
  --radius-s: 9px;
}

html[data-theme="dark"] {
  --bg: #16181c;
  --bg-accent: #101216;
  --card: rgba(30, 33, 39, 0.92);
  --card-strong: #23262d;
  --border: rgba(210, 216, 228, 0.14);
  --accent: #e5c400;
  --accent-2: #b8ae44;
  --accent-soft: rgba(229, 196, 0, 0.14);
  --plan: #e08a8a;
  --fact: #aab0bb;
  --fact-anc: #cfc65e;
  --muted: #9aa0ab;
  --text: #d7dae0;
  --heading: #eceef2;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
  --shadow-soft: 0 12px 34px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ---- Тёмная тема: перекрытие «зашитых» светлых поверхностей ---- */
html[data-theme="dark"] body {
  background:
    radial-gradient(circle at top left, rgba(229, 196, 0, 0.07), transparent 22%),
    linear-gradient(180deg, #1a1c21 0%, var(--bg) 34%, var(--bg-accent) 100%);
  color: var(--text);
}
html[data-theme="dark"] body::before { display: none; }
html[data-theme="dark"] header {
  background: linear-gradient(135deg, rgba(229, 196, 0, 0.08), transparent 24%),
    linear-gradient(180deg, rgba(34, 37, 43, 0.98), rgba(26, 28, 33, 0.96));
  color: var(--text);
  border-bottom-color: rgba(210, 216, 228, 0.08);
}
html[data-theme="dark"] header::after { opacity: 0.05; }
html[data-theme="dark"] header h1,
html[data-theme="dark"] .brand-name { color: var(--heading); }
html[data-theme="dark"] .brand-logo {
  filter: brightness(0) invert(1);
}
html[data-theme="dark"] .section-tabs {
  background: rgba(22, 24, 28, 0.9);
  border-bottom-color: rgba(210, 216, 228, 0.1);
}
html[data-theme="dark"] .section-tabs button { color: var(--muted); }
html[data-theme="dark"] .section-tabs a.side-link { color: var(--muted); }
html[data-theme="dark"] .section-tabs a.side-link:hover { color: var(--heading); }
html[data-theme="dark"] .section-tabs button.active,
html[data-theme="dark"] .section-tabs a.side-link.active {
  background: linear-gradient(135deg, #d9c94e, #b8ae44);
  color: #23262d;
}
html[data-theme="dark"] .side-menu {
  background:
    linear-gradient(180deg, rgba(34, 37, 43, 0.92), rgba(26, 28, 33, 0.78)),
    rgba(30, 33, 39, 0.86);
  border-color: rgba(210, 216, 228, 0.12);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.35);
}
html[data-theme="dark"] .side-menu .tab-group-label { color: #9aa0ab; }
html[data-theme="dark"] .kpi {
  background: linear-gradient(180deg, rgba(36, 40, 48, 0.96), rgba(30, 33, 39, 0.92));
  border-color: rgba(210, 216, 228, 0.12);
}
html[data-theme="dark"] .panel,
html[data-theme="dark"] .kpi {
  background: var(--card);
  border-color: var(--border);
}
html[data-theme="dark"] .kpi { box-shadow: none; }
html[data-theme="dark"] .btn-refresh,
html[data-theme="dark"] .btn-link,
html[data-theme="dark"] .btn-export-monthly,
html[data-theme="dark"] .gantt-tool-btn,
html[data-theme="dark"] .period-btn,
html[data-theme="dark"] .period-presets button,
html[data-theme="dark"] .kpi-info,
html[data-theme="dark"] .chart-export,
html[data-theme="dark"] .chart-info,
html[data-theme="dark"] .header-meta-hover {
  background: rgba(44, 48, 56, 0.92);
  border-color: rgba(210, 216, 228, 0.16);
  color: var(--text);
}
html[data-theme="dark"] .btn-refresh:hover:not(:disabled),
html[data-theme="dark"] .gantt-tool-btn:hover,
html[data-theme="dark"] .period-presets button:hover:not(.active) {
  background: rgba(58, 62, 72, 0.95);
  color: var(--heading);
}
html[data-theme="dark"] .btn-primary-header {
  background: linear-gradient(135deg, rgba(229, 196, 0, 0.4), rgba(190, 168, 40, 0.5));
  border-color: rgba(229, 196, 0, 0.35);
  color: #16181c;
}
html[data-theme="dark"] .period-presets button.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #23262d;
}
html[data-theme="dark"] select,
html[data-theme="dark"] input[type="date"] {
  background: rgba(38, 41, 48, 0.95);
  border-color: rgba(210, 216, 228, 0.16);
  color: var(--text);
  box-shadow: none;
}
html[data-theme="dark"] .project-context-select {
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M1 1.2L4 4.1 7 1.2' fill='none' stroke='%23a8adb6' stroke-width='1' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  border: none;
  border-bottom: 1px solid transparent;
  box-shadow: none;
  color: inherit;
}
html[data-theme="dark"] .project-context-select:hover,
html[data-theme="dark"] .project-context-select:focus {
  background-color: transparent;
  border-bottom-color: rgba(210, 216, 228, 0.32);
  box-shadow: none;
}
html[data-theme="dark"] .mode-group {
  background: rgba(38, 41, 48, 0.8);
  border-color: rgba(210, 216, 228, 0.14);
  box-shadow: none;
}
html[data-theme="dark"] .mode-group button { color: var(--muted); }
html[data-theme="dark"] .mode-group button.active {
  background: linear-gradient(135deg, #d9c94e, #b8ae44);
  color: #23262d;
}
html[data-theme="dark"] .chart-box {
  background: linear-gradient(180deg, rgba(33, 36, 42, 0.98), rgba(27, 29, 34, 0.94));
  border-color: rgba(210, 216, 228, 0.12);
  box-shadow: none;
}
html[data-theme="dark"] table th,
html[data-theme="dark"] #summary-table thead th {
  background: #262a31;
  color: #ccd2dc;
}
html[data-theme="dark"] #summary-table th[data-sort]:hover { background: #2d323b; }
html[data-theme="dark"] th, html[data-theme="dark"] td { border-bottom-color: var(--border); }
html[data-theme="dark"] tr.summary-work { background: rgba(38, 41, 48, 0.6); }
html[data-theme="dark"] tr.summary-work td.num,
html[data-theme="dark"] tr.summary-work .work-code { color: #d7dae0; }
html[data-theme="dark"] #summary-table tbody tr.summary-kind:nth-of-type(even) { background: rgba(44, 48, 56, 0.4); }
html[data-theme="dark"] #summary-table tbody tr.summary-kind:hover,
html[data-theme="dark"] #summary-table tbody tr.summary-ancillary:hover { background: rgba(58, 62, 72, 0.6); }
html[data-theme="dark"] .summary-delay-counter {
  background: linear-gradient(180deg, #262a31, #1e2126);
  border-color: var(--border);
}
html[data-theme="dark"] #err {
  background: #3a2224;
  border-color: #6d3a3e;
  color: #f2b8bc;
}
html[data-theme="dark"] .concreting-gantt-layout { background: rgba(30, 33, 39, 0.96); }
html[data-theme="dark"] .concreting-gantt-wbs,
html[data-theme="dark"] #concreting-wbs-scroll { background: #1e2126; }
html[data-theme="dark"] .concreting-gantt-wbs-head-single,
html[data-theme="dark"] .concreting-gantt-dayhead,
html[data-theme="dark"] .concreting-gantt-wbs-head { background: #262a31; color: #ccd2dc; }
html[data-theme="dark"] .concreting-gantt-tree-row { background: #1e2126; color: var(--text); border-bottom-color: rgba(210, 216, 228, 0.08); }
html[data-theme="dark"] .concreting-gantt-tree-row.level-0 { background: #262a31; }
html[data-theme="dark"] .concreting-gantt-tree-row.level-1 { background: #22252b; }
html[data-theme="dark"] .concreting-gantt-tree-row.level-2 { background: #202329; }
html[data-theme="dark"] .concreting-gantt-tree-row.level-leaf { color: #b9bec8; }
html[data-theme="dark"] .concreting-gantt-toggle { color: #ccd2dc; }
html[data-theme="dark"] .concreting-gantt-track.group { background: rgba(44, 48, 56, 0.35); }
html[data-theme="dark"] .concreting-gantt-track.group.level-0 { background: rgba(44, 48, 56, 0.65); }
html[data-theme="dark"] .concreting-gantt-track { border-bottom-color: rgba(210, 216, 228, 0.08); }
html[data-theme="dark"] .concreting-gantt-monthhead span,
html[data-theme="dark"] .concreting-gantt-dayshead span { border-color: rgba(210, 216, 228, 0.1); }
html[data-theme="dark"] .gantt-weekend { background: rgba(210, 216, 228, 0.05); }
html[data-theme="dark"] .concreting-gantt-bar.plan { background: #4a2f33; box-shadow: inset 0 0 0 1px rgba(224, 138, 138, 0.45); }
html[data-theme="dark"] .concreting-gantt-bar.plan .concreting-gantt-bar-label { color: #f0c9c9; }
html[data-theme="dark"] .concreting-gantt-bar.fact { background: #3a3f48; box-shadow: inset 0 0 0 1px rgba(170, 176, 187, 0.45); }
html[data-theme="dark"] .concreting-gantt-bar.fact .concreting-gantt-bar-label { color: #dfe3ea; }
html[data-theme="dark"] .concreting-gantt-legend i.plan { background: #4a2f33; box-shadow: inset 0 0 0 1px rgba(224, 138, 138, 0.45); }
html[data-theme="dark"] .concreting-gantt-legend i.fact { background: #3a3f48; box-shadow: inset 0 0 0 1px rgba(170, 176, 187, 0.45); }
html[data-theme="dark"] .tools-menu-pop,
html[data-theme="dark"] .period-pop,
html[data-theme="dark"] .info-popover,
html[data-theme="dark"] .toast { background: var(--card-strong); border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .tools-menu-pop a { color: var(--text); }
html[data-theme="dark"] .chip {
  background: rgba(229, 196, 0, 0.12);
  border-color: rgba(229, 196, 0, 0.3);
  color: #d9c94e;
}
html[data-theme="dark"] .chip .chip-x { background: rgba(0, 0, 0, 0.3); }
html[data-theme="dark"] .kpi.skeleton {
  background: linear-gradient(100deg, rgba(38, 41, 48, 0.9) 40%, rgba(50, 54, 62, 0.95) 50%, rgba(38, 41, 48, 0.9) 60%);
  background-size: 200% 100%;
}

/* Карта работ: срезы Этаж/Оси/Конструкция + колонки merge-таблицы.
   Кнопки и ячейки зашиты под светлый фон; --text/--heading в dark светлые → текст пропадает. */
html[data-theme="dark"] .workmap-ct-btn,
html[data-theme="dark"] body.chart-workmap .workmap-baseline-actions .wm-base-save {
  background: rgba(44, 48, 56, 0.92);
  border-color: rgba(210, 216, 228, 0.16);
  color: var(--heading);
  box-shadow: none;
}
html[data-theme="dark"] .workmap-ct-btn:hover,
html[data-theme="dark"] .workmap-ct-btn[aria-expanded="true"],
html[data-theme="dark"] body.chart-workmap .workmap-baseline-actions .wm-base-save:hover {
  background: rgba(58, 62, 72, 0.95);
  color: var(--heading);
}
html[data-theme="dark"] .workmap-ct-btn.is-filtered {
  color: #d9c94e;
  border-color: rgba(229, 196, 0, 0.35);
}
html[data-theme="dark"] .workmap-ct-pop {
  background: var(--card-strong);
  border-color: var(--border);
  color: var(--text);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .workmap-ct-pop .wm-ct-pop-actions button { color: #d9c94e; }
html[data-theme="dark"] .workmap-ct-pop label:hover,
html[data-theme="dark"] .workmap-ct-pop .wm-ct-pop-actions button:hover {
  background: rgba(229, 196, 0, 0.12);
}
html[data-theme="dark"] #workmap-link-tip {
  background: #23262d;
  border-color: rgba(210, 216, 228, 0.18);
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
html[data-theme="dark"] .workmap-merge-table { color: var(--text); }
html[data-theme="dark"] .workmap-merge-table th {
  background: #262a31;
  color: #ccd2dc;
  border-bottom-color: rgba(210, 216, 228, 0.1);
  border-right-color: rgba(210, 216, 228, 0.08);
}
html[data-theme="dark"] .workmap-merge-table td {
  background: #1e2126;
  color: var(--text);
  border-bottom-color: rgba(210, 216, 228, 0.08);
  border-right-color: rgba(210, 216, 228, 0.08);
}
html[data-theme="dark"] .workmap-merge-table td.wm-floor {
  background: linear-gradient(180deg, #2a2e36, #242830);
  color: var(--heading);
}
html[data-theme="dark"] .workmap-merge-table td.wm-axis {
  background: #22252b;
  color: var(--text);
}
html[data-theme="dark"] .workmap-merge-table td.wm-axis .wm-place { color: #9aa0ab; }
html[data-theme="dark"] .workmap-merge-table td.wm-ct { color: var(--text); }
html[data-theme="dark"] .workmap-merge-table td.wm-reserve {
  background: #22252b;
  color: var(--heading);
}
html[data-theme="dark"] .workmap-merge-table td.wm-reserve.is-neg {
  color: #ef9a9a;
  background: #3a2224;
}
html[data-theme="dark"] .workmap-merge-table tr.wm-row:nth-child(even) td.wm-ct {
  background: rgba(38, 41, 48, 0.92);
}
html[data-theme="dark"] .workmap-merge-table tr.wm-row:nth-child(even) td.wm-reserve {
  background: #1c1f24;
}
html[data-theme="dark"] .workmap-merge-table tr.wm-row:nth-child(even) td.wm-reserve.is-neg {
  background: #3a2224;
}
html[data-theme="dark"] .workmap-merge-table tr.wm-row.is-total td { background: #262a31; }
html[data-theme="dark"] .workmap-merge-table tr.wm-row.is-total td.wm-floor {
  background: linear-gradient(180deg, #30343c, #2a2e36);
  color: var(--heading);
}
html[data-theme="dark"] .workmap-merge-table tr.wm-row.is-total td.wm-axis {
  background: #2a2e36;
  color: var(--heading);
}
html[data-theme="dark"] .workmap-merge-table tr.wm-row.is-total td.wm-reserve {
  background: #262a31;
  color: var(--muted);
}
html[data-theme="dark"] body.chart-workmap .concreting-gantt-track.workmap-lanes.is-total {
  background: rgba(38, 41, 48, 0.72);
}
html[data-theme="dark"] body.chart-workmap .concreting-gantt-track.workmap-lanes.is-total.is-total-first {
  border-top-color: rgba(210, 216, 228, 0.18);
}
html[data-theme="dark"] .workmap-baseline-svg path.wm-shift-shorter { stroke: #69d07a; }
html[data-theme="dark"] .workmap-baseline-svg polygon.wm-shift-shorter { fill: #69d07a; }
html[data-theme="dark"] .workmap-baseline-svg path.wm-shift-longer { stroke: #ff8a80; }
html[data-theme="dark"] .workmap-baseline-svg polygon.wm-shift-longer { fill: #ff8a80; }
html[data-theme="dark"] .concreting-gantt-legend i.wm-shift-leg.wm-shift-shorter { border-top-color: #69d07a; }
html[data-theme="dark"] .concreting-gantt-legend i.wm-shift-leg.wm-shift-longer { border-top-color: #ff8a80; }
html[data-theme="dark"] .gantt-today-line {
  border-left-color: rgba(120, 168, 220, 0.9);
}
html[data-theme="dark"] .gantt-today-flag {
  background: rgba(72, 118, 168, 0.92);
}
html[data-theme="dark"] body.chart-cpmap .cpmap-wbs-head {
  background: #262a31;
  color: #ccd2dc;
}
html[data-theme="dark"] body.chart-cpmap .cpmap-tree-row { background: #1e2126; color: var(--text); }
html[data-theme="dark"] body.chart-cpmap .cpmap-tree-row.level-0 { background: #262a31; }
html[data-theme="dark"] body.chart-cpmap .cpmap-tree-row.level-1 { background: #22252b; }
html[data-theme="dark"] body.chart-cpmap .cp-diamond.cp-tone-done { background: #69d07a; border-color: #3d8a4a; }
html[data-theme="dark"] body.chart-cpmap .cp-diamond.cp-tone-late { background: #ff8a80; border-color: #c45c5c; }
html[data-theme="dark"] body.chart-cpmap .cp-diamond.cp-tone-crit { background: #e5c400; border-color: #b8ae44; }
html[data-theme="dark"] body.chart-cpmap .cp-diamond.cp-tone-open { background: #7aa3c9; border-color: #5a82a8; }
