/* ============================================================
   SmartMedia CRM — дизайн-система skeleton MVP.
   Светлый SaaS: спокойный сине-фиолетовый акцент, мягкие тени,
   умеренный радиус, высокая плотность без перегруза.
   ============================================================ */

:root {
  /* Поверхности */
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e6e8f0;
  --border-strong: #d5d9e4;

  /* Текст */
  --text: #101828;
  --text-2: #475467;
  --muted: #8a94a6;

  /* Акценты */
  --accent: #2a6be6;
  --accent-hover: #1f5ad0;
  --accent-soft: #eaf1fe;
  --violet: #6d5ae6;
  --violet-soft: #f1eefc;

  /* Статусы (палитра dataviz, не переиспользуется под серии) */
  --good: #0ca30c;
  --good-text: #0a7d0a;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-soft: #e8f6e8;
  --warning-soft: #fdf3dc;
  --serious-soft: #fdeee7;
  --critical-soft: #fbe9e9;

  /* Графики (валидированная палитра) */
  --series-1: #2a78d6;
  --seq-250: #86b6ef;
  --seq-350: #5598e7;
  --seq-450: #2a78d6;
  --seq-600: #184f95;
  --grid: #e7e9f0;
  --axis: #c6cbd6;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 28px rgba(16, 24, 40, .12);

  --sidebar-w: 88px;
  --topbar-h: 60px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; font-size: inherit; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

#app { display: flex; height: 100vh; }

#page {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

/* Icon-центричная навигация (GLOBAL-UI-03): узкая колонка ~88px,
   крупная иконка сверху, компактная подпись под ней. Механика
   состояний: нейтральная серая иконка → акцентная при hover/active. */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Узкие боковые поля: активный пункт занимает почти всю ширину */
  padding: 12px 5px;
}

/* Фирменный логотип SMART MEDIA CRM (CLIENTS-UI-11): знак-гряда
   из logo.png, перерисованный в SVG (градиент фиолетовый → индиго
   из оригинала), под ним компактный вертикальный вариант словесной
   части. Горизонтальный lock-up из файла в 88px не помещается. */
.side-logo {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 4px 0 14px;
}
.side-logo .logo-mark { display: block; }
.side-logo .logo-word {
  display: flex; flex-direction: column; align-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
  line-height: 1.25; color: var(--text);
}
.side-logo .logo-word span {
  font-size: 7.5px; font-weight: 600; letter-spacing: .1em;
  color: var(--muted);
}

.side-nav { display: flex; flex-direction: column; gap: 6px; width: 100%; }

.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 4px 10px; border-radius: 12px;
  cursor: pointer; border: none; background: none;
  width: 100%; text-align: center;
  transition: background .18s;
}
/* Слои иконки (GLOBAL-UI-04): в покое монохром, при hover/active —
   брендовая композиция: синий контур + сине-фиолетовый второй слой
   с мягкой заливкой + голубой акцент. Никакой радуги по пунктам. */
.nav-item {
  --ic1: #98a2b3;          /* основной контур */
  --ic2: #aab2c2;          /* второй слой */
  --ic3: #b6bdcb;          /* акцентный штрих */
  --ic2f: transparent;     /* мягкая заливка второго слоя */
}
.nav-item .nav-ico {
  position: relative; display: flex;
}
/* Крупная иконка навигации: 28px — раздел читается мгновенно */
.nav-item .nav-ico svg { width: 28px; height: 28px; }
.nav-ico .l1 { stroke: var(--ic1); transition: stroke .18s; }
.nav-ico .l2 { stroke: var(--ic2); transition: stroke .18s; }
.nav-ico .l3 { stroke: var(--ic3); transition: stroke .18s; }
.nav-ico .l2f { fill: var(--ic2f); transition: fill .18s; }

.nav-item .nav-label {
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
  line-height: 1.1; transition: color .18s;
}

.nav-item:hover {
  background: var(--surface-2);
  --ic1: var(--accent); --ic2: var(--violet); --ic3: #5bb4e5;
  --ic2f: #e6e9fb;
}
.nav-item:hover .nav-label { color: var(--text); }

/* Активный пункт — крупная выразительная подложка почти во всю
   ширину sidebar: текущий раздел считывается мгновенно */
.nav-item.active {
  background: #e7edfc;
  box-shadow: inset 0 0 0 1px #d4e0f8;
  --ic1: var(--accent); --ic2: var(--violet); --ic3: #5bb4e5;
  --ic2f: #d8e1fa;
}
.nav-item.active .nav-label { color: var(--accent); font-weight: 700; }

.nav-item .nav-badge {
  position: absolute; top: -5px; right: -11px;
  background: var(--critical); color: #fff;
  font-size: 9.5px; font-weight: 700; line-height: 1;
  border-radius: 999px; padding: 3px 5px;
  border: 2px solid var(--surface);
}

.side-footer {
  margin-top: auto; border-top: 1px solid var(--border);
  padding-top: 12px; width: 100%;
}
.side-user {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.side-user .u-name { font-weight: 600; font-size: 11px; }
.side-user .u-role { font-size: 10px; color: var(--muted); }

/* Иконки в текстовых строках: одна высота, без разрастания SVG
   (инлайновый SVG без width/height растягивается до 300×150). */
.b-title svg, .d-label svg, .tc-title svg, .tp-label svg,
.a-row svg, .ml-row svg, .potential-note svg,
.generating-box svg, .tp-value svg {
  width: 15px; height: 15px; flex-shrink: 0;
}

/* ---------- Зоны страницы: TOP BAR | WORKSPACE (GLOBAL-UI-01) ----------
   Top bar — белая полоса с названием раздела и page-level controls,
   отделена от рабочей области границей и лёгкой тенью. Workspace —
   серая рабочая зона со своим скроллом, начинается ниже top bar. */

.top-bar {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--topbar-h);
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  flex-shrink: 0; flex-wrap: wrap;
  position: relative; z-index: 20;
}
.top-bar h1 { font-size: 19px; font-weight: 700; margin-right: 2px; }
.top-bar .subtitle { color: var(--muted); font-size: 12.5px; }
.top-bar .spacer { flex: 1; }

/* Отметка автообновления. Тихая по замыслу: она сообщает о свежести
   данных, а не требует действия. Заметной становится только тогда,
   когда связи нет, — молчащая сеть выглядит как отсутствие новых
   сообщений, и это единственный случай, ради которого она здесь. */
.live-mark {
  font-size: 12px; color: var(--muted);
  padding-left: 10px; white-space: nowrap;
}
.live-mark[data-state="failing"] { color: var(--critical); font-weight: 600; }

.workspace {
  flex: 1; min-height: 0; overflow: auto;
  padding: 18px 20px 24px;
}

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  padding: 8px 14px; font-weight: 600; font-size: 13px;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 15px; height: 15px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn-soft:hover { background: #dde9fd; }

.btn-ghost { border-color: transparent; background: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger-ghost { border-color: var(--critical); background: none; color: var(--critical); }
.btn-danger-ghost:hover { background: var(--critical-soft); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  border: none; background: none; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---------- Сегментированный переключатель ---------- */

.seg-control {
  display: inline-flex; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 3px; gap: 2px;
}
.seg-control button {
  border: none; background: none; padding: 6px 13px;
  border-radius: 6px; font-weight: 500; font-size: 13px;
  color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.seg-control button:hover { color: var(--text); }
.seg-control button.active {
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}

/* ---------- Поля ввода ---------- */

.field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-2); margin-bottom: 5px;
}
.select, .input {
  width: 100%; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface);
  padding: 8px 10px; font-size: 13px; outline: none;
}
.select:focus, .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 12px; min-width: 240px;
}
.search-box svg { width: 15px; height: 15px; color: var(--muted); flex-shrink: 0; }
.search-box input { border: none; outline: none; flex: 1; background: none; font-size: 13px; }

/* ---------- Карточки и KPI ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

.kpi-row { display: grid; gap: 14px; }

.kpi-tile { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-tile .k-head { display: flex; align-items: center; gap: 10px; }
.kpi-tile .k-icon {
  width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.kpi-tile .k-icon svg { width: 17px; height: 17px; }
.kpi-tile .k-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.kpi-tile .k-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.kpi-tile .k-sub { font-size: 12px; color: var(--muted); }

/* Компактный вариант KPI — для сводки результата в «Фильтрах» */
.kpi-row.compact .kpi-tile { padding: 11px 14px; gap: 4px; }
.kpi-row.compact .k-value { font-size: 19px; }
.kpi-row.compact .k-icon { width: 28px; height: 28px; border-radius: 7px; }
.kpi-row.compact .k-icon svg { width: 14px; height: 14px; }

/* Semantic identity метрик (FILTERS-UI-06): у карточки с tone-* —
   горизонтальная композиция reference: крупный круглый тонированный
   icon-контейнер слева, центрированный относительно стека
   «название • значение» справа. Слоёная иконка (statIcons, слои
   .p1/.p2/.pf) несёт semantic-цвет; значения остаются тёмными.
   ⓘ — в углу карточки. Плитки без tone (дашборд, задачи) выглядят
   как раньше. */
/* Единый icon language KPI на всю CRM (Задачи, Фильтры, Дашборд):
   свободная слоёная иконка без цветной подложки, круга и рамки —
   один размер и визуальный вес везде. Фирменная violet/indigo/blue
   семья приходит тоном плитки (tone-*), значения остаются тёмными. */
.kpi-tile.k-tinted { flex-direction: row; align-items: center; gap: 12px; }
.kpi-tile.k-tinted .k-icon {
  width: 38px; height: 38px;
  background: none; border-radius: 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.kpi-tile.k-tinted .k-icon svg { width: 30px; height: 30px; }
.kpi-tile.k-tinted .k-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kpi-tile.k-tinted .k-icon .p1 { stroke: var(--tn-1); }
.kpi-tile.k-tinted .k-icon .p2 { stroke: var(--tn-2); }
.kpi-tile.k-tinted .k-icon .pf { fill: var(--tn-2); opacity: .2; }
.kpi-tile.k-tinted .info-btn { position: absolute; top: 8px; right: 8px; }
/* Специфичность выше компактного правила gap: 4px */
.kpi-row.compact .kpi-tile.k-tinted { gap: 12px; }

.kpi-tile.tone-purple { --tn-1: var(--violet); --tn-2: #9d8ff0; --tn-bg: var(--violet-soft); }
.kpi-tile.tone-blue   { --tn-1: var(--accent); --tn-2: #7aa3ee; --tn-bg: var(--accent-soft); }
.kpi-tile.tone-green  { --tn-1: var(--good-text); --tn-2: #4cb04c; --tn-bg: var(--good-soft); }
.kpi-tile.tone-amber  { --tn-1: #b07908; --tn-2: #dfa63e; --tn-bg: var(--warning-soft); }
.kpi-tile.tone-violet { --tn-1: #7b6fd0; --tn-2: #a89ee0; --tn-bg: #f0eefb; }
.kpi-tile.tone-indigo { --tn-1: #5560d8; --tn-2: #7d86e8; --tn-bg: #eceefb; }
.kpi-tile.tone-red    { --tn-1: var(--critical); --tn-2: #e08c8c; --tn-bg: var(--critical-soft); }

/* Кнопка-ⓘ и всплывающее пояснение методики (FILTERS-UX-03) */
.kpi-tile { position: relative; }
.info-btn {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--muted); font-size: 10px; font-weight: 700; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.info-btn:hover { color: var(--accent); border-color: var(--accent); }
.info-pop {
  position: absolute; top: calc(100% - 6px); left: 10px; right: 10px;
  background: #1d2432; color: #fff; font-size: 12px; line-height: 1.5;
  font-weight: 400; border-radius: 8px; padding: 10px 12px;
  box-shadow: var(--shadow-lg); z-index: 60;
}

/* Небольшой поповер под кнопкой top bar (saved filters, произвольный период) */
.pop-anchor { position: relative; }
.popover {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 230px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow-lg); z-index: 80; padding: 6px;
}
.popover .pop-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: none; background: none; text-align: left; cursor: pointer;
  padding: 8px 10px; border-radius: 7px; font-size: 13px; color: var(--text);
}
.popover .pop-item:hover { background: var(--surface-2); }
.popover .pop-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.popover .pop-note { font-size: 11.5px; color: var(--muted); padding: 6px 10px; }

.delta { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical); }
.delta .vs { color: var(--muted); font-weight: 400; }

/* ---------- Бейджи ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
  border-radius: 6px; padding: 2px 8px; white-space: nowrap;
}
.badge-seg-Aplus { background: var(--violet-soft); color: var(--violet); }
.badge-seg-A { background: var(--accent-soft); color: var(--accent); }
.badge-seg-Bplus { background: #fdf0e4; color: #c05c10; }
.badge-seg-B { background: #edf3f9; color: #40607e; }
.badge-seg-C { background: #eef0f4; color: #667085; }
/* «Без класса» (INT-02): нейтральный бейдж для клиентов без сегмента */
.badge-seg-unclassified { background: #eef0f4; color: #98a2b3; }

.badge-temp-HOT { background: var(--critical-soft); color: var(--critical); }
.badge-temp-WARM { background: var(--warning-soft); color: #b07908; }
.badge-temp-COOL { background: #eaf3fb; color: #3d7cb0; }

.badge-rel-green { background: var(--good-soft); color: var(--good-text); }
.badge-rel-yellow { background: var(--warning-soft); color: #b07908; }
.badge-rel-red { background: var(--critical-soft); color: var(--critical); }

.badge-neutral { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* Приоритетов и workflow-статусов в модели задач нет: состояние
   задачи вычисляется из срока (App.taskState) и показывается одной
   системой цветов — просрочено красный, сегодня зелёный, впереди
   синий, нет задач оранжевый. */

/* ---------- Аватары ---------- */

.avatar {
  border-radius: 50%; color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; user-select: none;
}
.avatar.sz-28 { width: 28px; height: 28px; font-size: 11px; }
.avatar.sz-34 { width: 34px; height: 34px; font-size: 13px; }
.avatar.sz-40 { width: 40px; height: 40px; font-size: 15px; }
.avatar.sz-56 { width: 56px; height: 56px; font-size: 21px; }
.avatar.sz-72 { width: 72px; height: 72px; font-size: 26px; }

/* Настоящая фотография профиля Instagram (Р-170). Картинка накрывает
   инициалы, а не заменяет их: пока файл грузится — и если он не
   загрузится вовсе — под ним лежит та же заглушка, что у клиента
   без фото. Дырки в кружке не бывает ни в одном состоянии. */
.avatar-photo { position: relative; overflow: hidden; }
.avatar-photo > img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ---------- Таблицы ---------- */

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; background: var(--surface);
}
.data-table td {
  padding: 11px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; vertical-align: middle;
}
/* Строка клиента — явно кликабельная: тонированный hover на всю
   строку, у открытого в drawer клиента — постоянная подсветка
   с акцентной полосой слева */
.data-table tbody tr { cursor: pointer; transition: background .1s; }
.data-table tbody tr:hover { background: #f1f6fe; }
.data-table tbody tr.selected {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
[data-theme="dark"] .data-table tbody tr:hover { background: rgba(77, 142, 242, .09); }
.data-table .num { font-variant-numeric: tabular-nums; }

.client-cell { display: flex; align-items: center; gap: 10px; }
.client-cell .c-name { font-weight: 600; }
.client-cell .c-user { font-size: 12px; color: var(--muted); }

/* ---------- Пустые состояния ---------- */

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 40px 20px; color: var(--muted); text-align: center;
}
.empty-state svg { width: 36px; height: 36px; opacity: .5; }
.empty-state .e-title { font-weight: 600; color: var(--text-2); font-size: 14px; }
.empty-state .e-hint { font-size: 12.5px; }

/* ---------- Спиннер ---------- */

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Тосты ---------- */

#toast-root {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 200;
  align-items: center; pointer-events: none;
}
.toast {
  background: #1d2432; color: #fff; font-size: 13px; font-weight: 500;
  border-radius: 10px; padding: 10px 18px; box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Drawer «Подробнее» ---------- */

#drawer-root .drawer-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .38);
  z-index: 100; animation: fade-in .15s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }

#drawer-root .drawer-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 92vw;
  background: var(--surface); z-index: 101; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; animation: drawer-in .2s ease-out;
}
@keyframes drawer-in { from { transform: translateX(40px); opacity: 0; } }

.drawer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px; }

.drawer-section { margin-bottom: 18px; }
.drawer-section > h3 {
  font-size: 13px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px;
}
.mock-note {
  font-size: 11.5px; color: var(--muted); background: var(--surface-2);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  padding: 7px 10px; margin-bottom: 14px;
}

/* ---------- Скроллбары ---------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d3d8e2; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: #b9c0cf; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Тултип графиков ---------- */

.chart-tooltip {
  position: fixed; z-index: 150; pointer-events: none;
  background: #1d2432; color: #fff; border-radius: 8px;
  padding: 7px 11px; font-size: 12px; line-height: 1.45;
  box-shadow: var(--shadow-lg); white-space: nowrap;
}
.chart-tooltip .tt-label { color: #aeb6c6; }
.chart-tooltip .tt-value { font-weight: 600; }

/* ============================================================
   DARK THEME (prototype). Та же вёрстка и компоненты — меняется
   только токен-система + точечные адаптации зашитых цветов.
   Направление: deep navy canvas с мягкими ambient-переливами
   (индиго сверху-справа, циан снизу-слева), «воздушные» карточки
   чуть светлее полотна, без стекла и неона.
   ============================================================ */

[data-theme="dark"] {
  color-scheme: dark;   /* нативные select/date тоже темнеют */

  --bg: #0e2233;
  --surface: #16334b;
  --surface-2: #1d3d58;
  --border: #27465f;
  --border-strong: #3a5b7a;

  --text: #eef4fa;
  --text-2: #b8c8d6;
  --muted: #7f95a8;

  --accent: #4d8ef2;
  --accent-hover: #63a0f7;
  --accent-soft: rgba(77, 142, 242, .16);
  --violet: #8d76f7;
  --violet-soft: rgba(141, 118, 247, .15);

  --good: #2fbf62;
  --good-text: #56d385;
  --warning: #f6b43c;
  --serious: #f0906a;
  --critical: #ef6a61;
  --good-soft: rgba(47, 191, 98, .15);
  --warning-soft: rgba(246, 180, 60, .14);
  --serious-soft: rgba(240, 144, 106, .15);
  --critical-soft: rgba(239, 106, 97, .16);

  --series-1: #55a2f0;
  --seq-250: #9cc4f4;
  --seq-350: #6faaee;
  --seq-450: #4a8ee2;
  --seq-600: #2f6cb8;
  --grid: #24425a;
  --axis: #3c5d78;

  --shadow: 0 2px 6px rgba(0, 0, 0, .28), 0 1px 3px rgba(0, 0, 0, .2);
  --shadow-lg: 0 12px 34px rgba(0, 0, 0, .45);

  /* Ambient-полотно: глубина и перелив света, не рекламный градиент.
     Одна и та же fixed-подложка у body и sticky-хедеров доски —
     поэтому патч под хедером сливается с полотном без шва. */
  --canvas-ambient:
    radial-gradient(1100px 700px at 88% -12%, rgba(124, 92, 255, .16), transparent 60%),
    radial-gradient(1000px 650px at -12% 108%, rgba(41, 182, 216, .11), transparent 55%),
    linear-gradient(160deg, #0d2133 0%, #0e1e31 55%, #142743 100%);
}

[data-theme="dark"] body {
  background: var(--canvas-ambient);
  background-attachment: fixed;
}

/* --- Sidebar: отдельный навигационный слой, темнее workspace --- */
[data-theme="dark"] #sidebar { background: #0b1b2b; border-right-color: #1e3950; }
[data-theme="dark"] .nav-item { --ic1: #64809a; --ic2: #587792; --ic3: #4f6d88; }
[data-theme="dark"] .nav-item:hover {
  background: rgba(255, 255, 255, .05);
  --ic1: var(--accent); --ic2: var(--violet); --ic3: #46c1e8;
  --ic2f: rgba(90, 140, 235, .2);
}
[data-theme="dark"] .nav-item.active {
  background: rgba(77, 142, 242, .16);
  box-shadow: inset 0 0 0 1px rgba(77, 142, 242, .3);
  --ic1: #5f9cf5; --ic2: #9d86f8; --ic3: #46c1e8;
  --ic2f: rgba(90, 140, 235, .26);
}
[data-theme="dark"] .nav-item .nav-badge { border-color: #0b1b2b; }

/* --- Top bar: свой navy-тон, тонкая нижняя граница --- */
[data-theme="dark"] .top-bar {
  background: #122a40;
  border-bottom-color: #24435e;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .03);
}

/* --- Мелкие компоненты с зашитыми светлыми цветами --- */
[data-theme="dark"] .btn-soft:hover { background: rgba(77, 142, 242, .28); }
[data-theme="dark"] .info-pop,
[data-theme="dark"] .toast,
[data-theme="dark"] .chart-tooltip {
  background: #234059; border: 1px solid #375b7c;
}
[data-theme="dark"] ::-webkit-scrollbar-thumb { background-color: rgba(150, 180, 205, .32); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background-color: rgba(150, 180, 205, .5); }

/* Бейджи: пастель заменяется полупрозрачным чипом на тёмном */
[data-theme="dark"] .badge-seg-Bplus { background: rgba(232, 135, 58, .17); color: #f0a468; }
[data-theme="dark"] .badge-seg-B { background: rgba(127, 163, 200, .17); color: #a8c4de; }
[data-theme="dark"] .badge-seg-C { background: rgba(150, 163, 180, .15); color: #a8b6c6; }
[data-theme="dark"] .badge-seg-unclassified { background: rgba(150, 163, 180, .12); color: #8b99ab; }
[data-theme="dark"] .badge-temp-WARM { color: #f2c14e; }
[data-theme="dark"] .badge-temp-COOL { background: rgba(90, 160, 215, .16); color: #6fb8e8; }
[data-theme="dark"] .badge-rel-yellow { color: #f2c14e; }

/* Тона KPI-иконок: штрихи ярче, чтобы читались на тёмных кругах */
[data-theme="dark"] .kpi-tile.tone-purple { --tn-2: #ab9bf7; }
[data-theme="dark"] .kpi-tile.tone-blue   { --tn-2: #8fb8f5; }
[data-theme="dark"] .kpi-tile.tone-green  { --tn-2: #74d69c; }
[data-theme="dark"] .kpi-tile.tone-amber  { --tn-1: #e9b04a; --tn-2: #f2ca7b; }
[data-theme="dark"] .kpi-tile.tone-violet { --tn-1: #a08ff0; --tn-2: #bcb0f5; --tn-bg: rgba(160, 143, 240, .15); }
[data-theme="dark"] .kpi-tile.tone-indigo { --tn-1: #939cf2; --tn-2: #b0b7f7; --tn-bg: rgba(147, 156, 242, .15); }
[data-theme="dark"] .kpi-tile.tone-red    { --tn-2: #f5a29b; }
