/* ============================================================================
   Профи — Print Forms. Тема и компоненты.
   Токены цвета взяты один-в-один из doc/ui/theme/crm-prototype.html.
   ПРАВИЛО: цветной текст и иконки — только через --*-fg.
   --ok/--warn/--crit/--info/--violet/--accent — ЗАЛИВКА.
   --accent-ink — текст поверх сплошной заливки акцентом.
   ========================================================================== */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --num-font: inherit;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 18px; --radius-sm: 12px; --radius-btn: 14px; --radius-pill: 999px;
  --shadow: 0 1px 2px rgba(92,97,102,.05), 0 8px 24px -12px rgba(92,97,102,.16);
  --shadow-lift: 0 2px 4px rgba(92,97,102,.07), 0 16px 34px -14px rgba(92,97,102,.24);
  --bg: #f0f2f4; --surface: #ffffff; --surface-2: #eaedf0; --border: #e0e3e6;
  --text: #5c6166; --text-muted: #57687f;
  --accent: #f29718; --accent-ink: #3a2600; --accent-fg: #985c09;
  --ok: #86b300; --warn: #f2a300; --crit: #e5484d; --info: #55b4d4; --violet: #a37acc;
  --ok-fg: #567300; --warn-fg: #916100; --crit-fg: #c21c21; --info-fg: #24728d; --violet-fg: #834bba;
}
:root[data-theme="dark"] {
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.55);
  --shadow-lift: 0 2px 6px rgba(0,0,0,.4), 0 18px 40px -16px rgba(0,0,0,.65);
}
/* --- САЙДКАР (Графит 1) --- */
:root[data-style="graphite1"][data-theme="light"] {
  --bg: #f0f2f4; --surface: #ffffff; --surface-2: #eaedf0; --border: #e0e3e6;
  --text: #5c6166; --text-muted: #57687f; --accent: #a85f10; --accent-ink: #ffffff;
  --ok: #86b300; --warn: #f2a300; --crit: #e5484d; --info: #55b4d4; --violet: #a37acc;
  --accent-fg: #93530e; --ok-fg: #567300; --warn-fg: #916100; --crit-fg: #c21c21; --info-fg: #24728d; --violet-fg: #834bba;
}
:root[data-style="graphite1"][data-theme="dark"] {
  --bg: #2a2c2e; --surface: #383a3c; --surface-2: #44474b; --border: #4c4f53;
  --text: #bfbdb6; --text-muted: #9ba4b1; --accent: #ffd580; --accent-ink: #2a2c2e;
  --ok: #aad94c; --warn: #ff8f40; --crit: #f07178; --info: #39bae6; --violet: #d2a6ff;
  --accent-fg: #ffd580; --ok-fg: #b0dc58; --warn-fg: #ffb27b; --crit-fg: #f6a8ac; --info-fg: #77d0ee; --violet-fg: #ddbbff;
}
/* --- БЕЛЛИНИ (Пудровая роза) --- */
:root[data-style="roza"][data-theme="light"] {
  --bg: #f8e8e8; --surface: #ffffff; --surface-2: #f6dede; --border: #eecccc;
  --text: #5c6166; --text-muted: #806060; --accent: #ed988b; --accent-ink: #5a2a24;
  --ok: #86b300; --warn: #f2a300; --crit: #e5484d; --info: #55b4d4; --violet: #a37acc;
  --accent-fg: #ab4a42; --ok-fg: #567300; --warn-fg: #916100; --crit-fg: #b23b34; --info-fg: #24728d; --violet-fg: #834bba;
}
:root[data-style="roza"][data-theme="dark"] {
  --bg: #2e282a; --surface: #383234; --surface-2: #443c3f; --border: #51484b;
  --text: #ecdfe1; --text-muted: #bda3a7; --accent: #ed988b; --accent-ink: #2a1a18;
  --ok: #aad94c; --warn: #ffb454; --crit: #f07178; --info: #7ec8d6; --violet: #d2a6ff;
  --accent-fg: #ed988b; --ok-fg: #aad94c; --warn-fg: #ffb454; --crit-fg: #f2888d; --info-fg: #7ec8d6; --violet-fg: #d2a6ff;
}
/* --- МОХИТО (Шалфей) --- */
:root[data-style="shalfey"] { --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif; --radius: 22px; --radius-sm: 14px; --radius-btn: 999px; }
:root[data-style="shalfey"][data-theme="light"] {
  --bg: #f6f5ef; --surface: #fffefb; --surface-2: #efeee6; --border: #e5e2d6;
  --text: #2a2b25; --text-muted: #746f61; --accent: #3f8f6a; --accent-ink: #ffffff;
  --ok: #2f8f5f; --warn: #c1852f; --crit: #c85f52; --info: #3d7fa0; --violet: #a37acc;
  --accent-fg: #317053; --ok-fg: #25714b; --warn-fg: #895e21; --crit-fg: #a94236; --info-fg: #336a85; --violet-fg: #834bba;
}
:root[data-style="shalfey"][data-theme="dark"] {
  --bg: #25241c; --surface: #2d2c25; --surface-2: #363328; --border: #433f2c;
  --text: #ecebe0; --text-muted: #a8a595; --accent: #74b494; --accent-ink: #131711;
  --ok: #6bb98d; --warn: #d6a558; --crit: #d47f72; --info: #6fa3c0; --violet: #d2a6ff;
  --accent-fg: #74b494; --ok-fg: #6bb98d; --warn-fg: #d6a558; --crit-fg: #d88b7f; --info-fg: #76a8c3; --violet-fg: #d2a6ff;
}
/* --- БЛЮ ЛАГУНА (Сапфир) --- */
:root[data-style="sapfir"] { --font: system-ui, "Segoe UI", -apple-system, sans-serif; --num-font: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace; --radius: 13px; --radius-sm: 9px; --radius-btn: 10px; }
:root[data-style="sapfir"][data-theme="light"] {
  --bg: #eef2f7; --surface: #ffffff; --surface-2: #e7ecf3; --border: #d6dde7;
  --text: #16212f; --text-muted: #5f6b7a; --accent: #2563c9; --accent-ink: #ffffff;
  --ok: #1f9d6b; --warn: #c8871f; --crit: #d24d4d; --info: #2f74c0; --violet: #a37acc;
  --accent-fg: #235ebe; --ok-fg: #17734f; --warn-fg: #8c5e16; --crit-fg: #b82f2f; --info-fg: #2964a6; --violet-fg: #834bba;
}
:root[data-style="sapfir"][data-theme="dark"] {
  --bg: #171d28; --surface: #1e2635; --surface-2: #262e40; --border: #343f52;
  --text: #e5e9f0; --text-muted: #8b98a9; --accent: #4f8ff0; --accent-ink: #0a0f16;
  --ok: #34b581; --warn: #d69b3f; --crit: #e26565; --info: #5c95e6; --violet: #d2a6ff;
  --accent-fg: #609af1; --ok-fg: #34b581; --warn-fg: #d69b3f; --crit-fg: #e57575; --info-fg: #669ce8; --violet-fg: #d2a6ff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #2a2c2e; --surface: #383a3c; --surface-2: #44474b; --border: #4c4f53;
    --text: #bfbdb6; --text-muted: #9ba4b1; --accent: #e6b450; --accent-ink: #2a2c2e;
    --ok: #aad94c; --warn: #ffb454; --crit: #f07178; --info: #39bae6; --violet: #d2a6ff;
    --accent-fg: #ebc372; --ok-fg: #b0dc58; --warn-fg: #ffbe6a; --crit-fg: #f6a8ac; --info-fg: #77d0ee; --violet-fg: #ddbbff;
  }
}
/* Палитра для графиков — базовые (нейтральные) значения ниже переопределяются
   для каждого data-style лёгкой тонировкой под акцент темы (см. блок ниже), чтобы
   графики визуально принадлежали своей теме, а не выглядели одинаково везде:
   --s1…--s4 — 4 основных цвета серий (--s5 оставлен только для обратной совместимости
   со старыми круговыми списками в модуле печатных форм, для новых графиков не брать).
   --n1/--n2 — нейтральные серые для неосновной информации (прошлый период, промежуточные
   этапы воронки и т.п.): --n1 — приглушённый (уходит в фон), --n2 — более заметный. */
:root { --s1:#2a78d6; --s2:#eb6834; --s3:#19a372; --s4:#c18300; --s5:#e46494; --n1:#c3c8ce; --n2:#7d8791; }
:root[data-theme="dark"] { --s1:#468adb; --s2:#cf5416; --s3:#189669; --s4:#b57e00; --s5:#e87ba4; --n1:#565b60; --n2:#9aa2ab; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) { --s1:#468adb; --s2:#cf5416; --s3:#189669; --s4:#b57e00; --s5:#e87ba4; --n1:#565b60; --n2:#9aa2ab; } }
/* Тонировка серий графиков под акцент каждой темы (color-mix вместо ручного подбора
   hex на 4 темы × 2 режима — доля тонирования достаточно мала, чтобы не портить
   различимость серий для дальтонизма, но достаточна, чтобы графики читались «в цвет»
   текущей темы, а не как один и тот же набор красок поверх любого фона). */
:root[data-style="graphite1"][data-theme="light"] { --s1: color-mix(in srgb, #2a78d6 86%, var(--accent) 14%); --s2: color-mix(in srgb, #eb6834 86%, var(--accent) 14%); --s3: color-mix(in srgb, #19a372 86%, var(--accent) 14%); --s4: color-mix(in srgb, #c18300 86%, var(--accent) 14%); --n1: color-mix(in srgb, #c3c8ce 92%, var(--accent) 8%); --n2: color-mix(in srgb, #7d8791 92%, var(--accent) 8%); }
:root[data-style="graphite1"][data-theme="dark"] { --s1: color-mix(in srgb, #468adb 90%, var(--accent) 10%); --s2: color-mix(in srgb, #cf5416 90%, var(--accent) 10%); --s3: color-mix(in srgb, #189669 90%, var(--accent) 10%); --s4: color-mix(in srgb, #b57e00 90%, var(--accent) 10%); --n1: color-mix(in srgb, #565b60 90%, var(--accent) 10%); --n2: color-mix(in srgb, #9aa2ab 90%, var(--accent) 10%); }
:root[data-style="roza"][data-theme="light"] { --s1: color-mix(in srgb, #2a78d6 86%, var(--accent) 14%); --s2: color-mix(in srgb, #eb6834 86%, var(--accent) 14%); --s3: color-mix(in srgb, #19a372 86%, var(--accent) 14%); --s4: color-mix(in srgb, #c18300 86%, var(--accent) 14%); --n1: color-mix(in srgb, #c3c8ce 92%, var(--accent) 8%); --n2: color-mix(in srgb, #7d8791 92%, var(--accent) 8%); }
:root[data-style="roza"][data-theme="dark"] { --s1: color-mix(in srgb, #468adb 90%, var(--accent) 10%); --s2: color-mix(in srgb, #cf5416 90%, var(--accent) 10%); --s3: color-mix(in srgb, #189669 90%, var(--accent) 10%); --s4: color-mix(in srgb, #b57e00 90%, var(--accent) 10%); --n1: color-mix(in srgb, #565b60 90%, var(--accent) 10%); --n2: color-mix(in srgb, #9aa2ab 90%, var(--accent) 10%); }
:root[data-style="shalfey"][data-theme="light"] { --s1: color-mix(in srgb, #2a78d6 86%, var(--accent) 14%); --s2: color-mix(in srgb, #eb6834 86%, var(--accent) 14%); --s3: color-mix(in srgb, #19a372 86%, var(--accent) 14%); --s4: color-mix(in srgb, #c18300 86%, var(--accent) 14%); --n1: color-mix(in srgb, #c3c8ce 92%, var(--accent) 8%); --n2: color-mix(in srgb, #7d8791 92%, var(--accent) 8%); }
:root[data-style="shalfey"][data-theme="dark"] { --s1: color-mix(in srgb, #468adb 90%, var(--accent) 10%); --s2: color-mix(in srgb, #cf5416 90%, var(--accent) 10%); --s3: color-mix(in srgb, #189669 90%, var(--accent) 10%); --s4: color-mix(in srgb, #b57e00 90%, var(--accent) 10%); --n1: color-mix(in srgb, #565b60 90%, var(--accent) 10%); --n2: color-mix(in srgb, #9aa2ab 90%, var(--accent) 10%); }
:root[data-style="sapfir"][data-theme="light"] { --s1: color-mix(in srgb, #2a78d6 86%, var(--accent) 14%); --s2: color-mix(in srgb, #eb6834 86%, var(--accent) 14%); --s3: color-mix(in srgb, #19a372 86%, var(--accent) 14%); --s4: color-mix(in srgb, #c18300 86%, var(--accent) 14%); --n1: color-mix(in srgb, #c3c8ce 92%, var(--accent) 8%); --n2: color-mix(in srgb, #7d8791 92%, var(--accent) 8%); }
:root[data-style="sapfir"][data-theme="dark"] { --s1: color-mix(in srgb, #468adb 90%, var(--accent) 10%); --s2: color-mix(in srgb, #cf5416 90%, var(--accent) 10%); --s3: color-mix(in srgb, #189669 90%, var(--accent) 10%); --s4: color-mix(in srgb, #b57e00 90%, var(--accent) 10%); --n1: color-mix(in srgb, #565b60 90%, var(--accent) 10%); --n2: color-mix(in srgb, #9aa2ab 90%, var(--accent) 10%); }
/* --crit/--warn — насыщенные, для бейджей/текста (--*-fg) и иконок; на графике
   (заливки/линии-предупреждения/отклонения) берём смягчённые варианты ниже —
   смешаны с поверхностью карточки, чтобы красно-оранжевая палитра ошибок не
   била в глаза сплошным пятном на графике, как это уместно для точечного бейджа. */
:root { --chart-crit: color-mix(in srgb, var(--crit) 70%, var(--surface) 30%); --chart-warn: color-mix(in srgb, var(--warn) 70%, var(--surface) 30%); }

/* color-scheme сообщает браузеру, в какой палитре рисовать нативные виджеты
   (скроллбары, спиннеры number-инпутов) — без этого Chrome красит их светлой
   OS-темой поверх тёмного фона страницы. */
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) { color-scheme: dark; } }

/* ==================== БАЗА ==================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.015em; color: var(--text); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-fg); outline-offset: 2px; border-radius: 4px; }
/* Скроллбар в тон темы (Firefox через scrollbar-color/width, Chrome/Safari — псевдоэлементы). */
* { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: content-box; }
/* Нативные стрелки шага у number-инпутов не стилизуются кросс-браузерно и
   выглядят чужеродно на тёмной теме — убираем их, значение всё равно
   правится вводом и стрелками клавиатуры. */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline-offset: 1px; }
.nav a:focus-visible, .chip:focus-visible { outline-offset: -2px; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 100; padding: 9px 16px;
  background: var(--accent); color: var(--accent-ink); border-radius: var(--radius-sm); font-weight: 600; }
.skip:focus { left: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--text-muted); }
.num { font-variant-numeric: tabular-nums; font-family: var(--num-font); }
.mono { font-family: var(--mono); font-size: .92em; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ==================== ОБОЛОЧКА ==================== */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.appbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border); z-index: 30;
}
.appbar-title h2 { font-size: 17px; line-height: 1.1; }
.appbar-title .sub { font-size: 12px; color: var(--text-muted); }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border: 0; cursor: pointer;
  background: transparent; color: var(--text-muted); border-radius: var(--radius-sm); transition: all .16s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.xs { width: 24px; height: 24px; }
.icon-btn.xs svg { width: 14px; height: 14px; }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn:disabled:hover { background: transparent; color: var(--text-muted); }
.step-move-group { gap: 0; background: var(--surface-2); border-radius: var(--radius-sm); padding: 2px; }
.icon-btn.move-btn { width: 20px; height: 20px; }
.icon-btn.move-btn svg { width: 12px; height: 12px; }
.icon-btn.move-btn:disabled { cursor: default; }
.shell { flex: 1; display: flex; min-height: 0; }
.side {
  width: 232px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px 12px 12px; display: flex; flex-direction: column; overflow-y: auto; transition: width .2s ease;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 16px; min-height: 30px; }
.brand .logo { width: 32px; height: 32px; flex: none; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 15px; }
.brand b { font-size: 15px; white-space: nowrap; }
.brand .sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.nav-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); padding: 14px 10px 6px; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  position: relative; display: flex; align-items: center; gap: 11px; padding: 9px 11px; min-height: 40px;
  border-radius: var(--radius-sm); color: var(--text-muted); font-size: 13.5px; font-weight: 500; transition: all .16s ease;
}
.nav a::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 3px; height: 20px; border-radius: 0 3px 3px 0;
  background: var(--accent); transform: translateY(-50%) scaleY(0); opacity: 0; transition: transform .18s ease, opacity .18s ease;
}
.nav a:hover::before, .nav a.active::before { transform: translateY(-50%) scaleY(1); opacity: 1; }
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--accent-fg); font-weight: 600; }
.nav a.disabled { opacity: .42; cursor: default; }
.nav a.disabled:hover { background: none; color: var(--text-muted); }
.nav a.disabled:hover::before { transform: translateY(-50%) scaleY(0); opacity: 0; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--text-muted); background: var(--surface-2); padding: 1px 8px; border-radius: var(--radius-pill); font-variant-numeric: tabular-nums; }
.nav a.active .count { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); color: var(--accent-fg); }
.side-user-wrap { position: relative; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm);
  width: 100%; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.side-user:hover { background: var(--surface-2); }
.menu.up { top: auto; bottom: calc(100% + 8px); }
.side-user .ava { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: #514ac4; color: #fff; font-size: 12px; font-weight: 700; }
.side-user .meta b { font-size: 13.5px; display: block; }
.side-user .meta span { font-size: 12px; color: var(--text-muted); }
/* Схлопывание сайдбара в узкую полосу — только десктоп; на мобильном сайдбар
   всегда выезжает во всю ширину (см. блок «АДАПТИВ» ниже), поэтому здесь
   отсекаем эффект по min-width, а не полагаемся на снятие класса. */
@media (min-width: 881px) {
  .app.nav-collapsed .side { width: 74px; }
  .app.nav-collapsed .brand { justify-content: center; }
  .app.nav-collapsed .brand .txt, .app.nav-collapsed .nav-txt,
  .app.nav-collapsed .nav-label, .app.nav-collapsed .nav .count,
  .app.nav-collapsed .side-user .meta { display: none; }
  .app.nav-collapsed .nav a { justify-content: center; padding-left: 0; padding-right: 0; }
  .app.nav-collapsed .nav a::before { display: none; }
  .app.nav-collapsed .side-user { justify-content: center; }
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main-scroll { flex: 1; overflow-y: auto; padding: 20px 22px; }
.main-flush { flex: 1; min-height: 0; display: flex; }

/* ==================== КНОПКИ И ПОЛЯ ==================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-size: 13.5px; font-weight: 600;
  padding: 9px 16px; border: 0; border-radius: var(--radius-btn); cursor: pointer; white-space: nowrap;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); transition: all .18s ease;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.btn:active { transform: none; }
.btn.secondary { background: var(--surface); color: var(--text); box-shadow: none; border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--accent-fg); color: var(--accent-fg); filter: none; }
.btn.ghost { background: transparent; color: var(--text-muted); box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); filter: none; transform: none; }
.btn.danger { background: transparent; color: var(--crit-fg); border: 1px solid color-mix(in srgb, var(--crit) 40%, transparent); box-shadow: none; }
.btn.danger:hover { background: color-mix(in srgb, var(--crit) 12%, var(--surface)); filter: none; }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .fl { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 11.5px; color: var(--text-muted); }
.input, .select, .textarea {
  width: 100%; font-size: 13.5px; padding: 9px 13px; border-radius: var(--radius-sm); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); transition: border-color .16s ease, box-shadow .16s ease;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); outline: none; }
.textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
.select { appearance: none; cursor: pointer; padding-right: 34px;
  background-image: linear-gradient(45deg,transparent 50%,var(--text-muted) 50%),linear-gradient(135deg,var(--text-muted) 50%,transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.input-icon .input { padding-left: 36px; }
/* Инлайн-редактирование (S.inlineEdit / локальный inlineSelect): в режиме отображения
   значение помечено пунктирным подчёркиванием — достаточно заметно, чтобы отличить от
   обычного текста, но не выглядит отдельным полем ввода, пока по нему не кликнули. */
[data-edit]:not(select):not(input):not(textarea), [data-edit-sel], [data-edit-label] {
  border-radius: 5px; padding: 1px 5px; margin: -1px -5px; cursor: text;
  text-decoration: underline; text-decoration-style: dotted;
  text-decoration-color: color-mix(in srgb, var(--text-muted) 55%, transparent);
  text-underline-offset: 3px; transition: background-color .14s ease, text-decoration-color .14s ease;
}
[data-edit-sel], [data-edit-label] { cursor: pointer; }
[data-edit]:not(select):not(input):not(textarea):hover, [data-edit-sel]:hover, [data-edit-label]:hover,
[data-edit]:not(select):not(input):not(textarea):focus-visible, [data-edit-sel]:focus-visible, [data-edit-label]:focus-visible {
  background: var(--surface-2); text-decoration-color: var(--accent-fg);
}
.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.check input { position: absolute; opacity: 0; }
.check .box { width: 18px; height: 18px; border-radius: 6px; border: 1.5px solid var(--border); background: var(--surface);
  flex: none; display: grid; place-items: center; transition: all .16s ease; }
.check .box svg { width: 12px; height: 12px; color: var(--accent-ink); opacity: 0; transform: scale(.6); transition: all .16s ease; }
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box svg { opacity: 1; transform: scale(1); }
.check input:focus-visible + .box { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 40px; height: 23px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); transition: all .2s ease; flex: none; position: relative; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .2s cubic-bezier(.4,0,.2,1); }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(17px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.seg { display: inline-flex; gap: 3px; padding: 3px; background: var(--surface-2); border-radius: var(--radius-sm); }
.seg button { font-size: 13px; font-weight: 600; border: 0; cursor: pointer; padding: 6px 13px; border-radius: calc(var(--radius-sm) - 3px);
  color: var(--text-muted); background: transparent; transition: all .18s ease; display: inline-flex; align-items: center; gap: 7px; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg a { font-size: 13px; font-weight: 600; text-decoration: none; padding: 6px 13px; border-radius: calc(var(--radius-sm) - 3px);
  color: var(--text-muted); background: transparent; transition: all .18s ease; display: inline-flex; align-items: center; gap: 7px; }
.seg a:hover { color: var(--text); }
.seg a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg .swatch { width: 11px; height: 11px; border-radius: 50%; }
.seg svg { width: 16px; height: 16px; display: block; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-family: inherit; font-size: 12.5px; font-weight: 500;
  padding: 5px 11px; border-radius: var(--radius-pill); background: var(--surface-2); color: var(--text);
  border: 1px solid transparent; cursor: pointer; transition: all .16s ease; }
.chip:hover { border-color: var(--border); }
.chip[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent-fg);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent); font-weight: 600; }
.chip .x { opacity: .6; }

/* ==================== МЕНЮ ==================== */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 200px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lift); padding: 6px;
  opacity: 0; visibility: hidden; transform: translateY(-6px); z-index: 40;
  transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s; }
.menu.open { opacity: 1; visibility: visible; transform: translateY(0); transition: opacity .16s ease, transform .16s ease, visibility 0s linear 0s; }
.menu.left { right: auto; left: 0; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--text); font-size: 13.5px; padding: 9px 10px; border-radius: 8px; cursor: pointer; text-decoration: none; box-sizing: border-box; }
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu button svg, .menu a svg { width: 16px; height: 16px; color: var(--text-muted); flex: none; }
.menu .sep { height: 1px; background: var(--border); margin: 6px 2px; }
.menu button.danger, .menu button.danger svg { color: var(--crit-fg); }
.menu-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: 9px 10px 4px; }
.menu .swatch { width: 13px; height: 13px; border-radius: 50%; flex: none; border: 1px solid color-mix(in srgb, var(--text) 25%, transparent); }
/* название темы из нескольких слов не переносится */
.menu .nm { white-space: nowrap; }
#theme-menu, #sys-menu { min-width: 234px; }
.menu button .chk, .menu a .chk { margin-left: auto; width: 15px; height: 15px; color: var(--accent-fg); opacity: 0; }
.menu button[aria-checked="true"] .chk, .menu a[aria-current="page"] .chk { opacity: 1; }
.theme-btn { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: var(--radius-sm); }
.theme-btn:hover { border-color: var(--accent-fg); }
.theme-btn .swatch { width: 13px; height: 13px; border-radius: 50%; flex: none; }
.theme-btn span { white-space: nowrap; }
.theme-btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.theme-btn.accent:hover { filter: brightness(1.06); border-color: var(--accent); }

/* ==================== ПЛАШКИ СТАТУСОВ ==================== */
.badge { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: var(--radius-pill); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.w { min-width: 17ch; }
.badge.plain::before { display: none; }
.badge-btn { min-width: 190px; border: 1px solid transparent; font-family: inherit; cursor: pointer;
  transition: filter .14s ease, border-color .14s ease; }
.badge-btn .badge-chev { width: 12px; height: 12px; margin-left: auto; opacity: .6; flex: none; }
.badge-btn:hover { filter: brightness(0.94); border-color: color-mix(in srgb, currentColor 30%, transparent); }
:root[data-theme="dark"] .badge-btn:hover { filter: brightness(1.25); }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .badge-btn:hover { filter: brightness(1.25); } }
.badge-btn:focus-visible { outline: none; border-color: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 25%, transparent); }
.b-draft   { color: var(--text);      background: var(--surface-2); }
.b-review  { color: var(--warn-fg);   background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.b-live    { color: var(--ok-fg);     background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.b-archive { color: var(--text-muted); background: var(--surface-2); }
.b-broken  { color: var(--crit-fg);   background: color-mix(in srgb, var(--crit) 14%, var(--surface)); }
.b-calc    { color: var(--violet-fg); background: color-mix(in srgb, var(--violet) 14%, var(--surface)); }
.b-info    { color: var(--info-fg);   background: color-mix(in srgb, var(--info) 14%, var(--surface)); }
.b-accent  { color: var(--accent-fg); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.flow { row-gap: 8px; }
.flow svg { width: 13px; height: 13px; flex: none; }

/* Тип тега — маленькая моноширинная метка */
.ttype { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 6px; background: var(--surface-2); color: var(--text-muted); white-space: nowrap; }
.ttype svg { width: 12px; height: 12px; }
.ttype.calc { background: color-mix(in srgb, var(--violet) 14%, var(--surface)); color: var(--violet-fg); }

/* ==================== КАРТОЧКИ / ТАБЛИЦЫ ==================== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: clip; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 14.5px; }
.card-head .sub { font-size: 12px; color: var(--text-muted); }
.card-body { padding: 16px; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.toolbar .grow { flex: 1; min-width: 150px; }
.toolbar.plain { border-bottom: 0; padding: 0 0 14px; }
.table-wrap { overflow: auto; max-height: 60vh; }
.table-wrap.fill { max-height: none; flex: 1 1 auto; min-height: 0; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted);
  font-weight: 600; padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface);
  position: sticky; top: 0; z-index: 2; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--num-font); }
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody td svg { width: 16px; height: 16px; flex: none; color: var(--text-muted); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background-color .14s ease; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr.selected { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
thead th.sortable { padding: 0; }
thead th.sortable > button { display: inline-flex; align-items: center; gap: 5px; width: 100%; border: 0; cursor: pointer;
  background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; padding: 11px 16px; }
thead th.sortable.num > button { justify-content: flex-end; }
thead th.sortable > button:hover { color: var(--text); }
thead th.sortable .arr { width: 12px; height: 12px; opacity: 0; transition: opacity .16s ease, transform .16s ease; }
thead th.sortable > button:hover .arr { opacity: .45; }
thead th[aria-sort] > button { color: var(--accent-fg); }
thead th[aria-sort] .arr { opacity: 1; }
thead th[aria-sort="descending"] .arr { transform: rotate(180deg); }
.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 46px 24px; text-align: center; }
.empty svg { width: 38px; height: 38px; color: var(--text-muted); opacity: .55; }
.empty b { font-size: 14.5px; }
.empty span { font-size: 13px; color: var(--text-muted); max-width: 330px; }
.pager { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); flex-wrap: wrap; }

/* ==================== РАБОЧАЯ ОБЛАСТЬ (split) ==================== */
.workspace { display: flex; width: 100%; min-height: 0; }
.ws-list { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.ws-splitter { flex: none; width: 14px; cursor: col-resize; display: flex; align-items: center; justify-content: center;
  position: relative; touch-action: none; background: var(--bg); }
.ws-splitter::before { content: ""; width: 4px; height: 42px; border-radius: 999px; background: var(--border); transition: background-color .16s ease; }
.ws-splitter:hover::before, .ws-splitter.drag::before, .ws-splitter:focus-visible::before { background: var(--accent-fg); }
.ws-splitter:focus-visible { outline: 2px solid var(--accent-fg); outline-offset: -3px; border-radius: 8px; }
.ws-details { flex: none; flex-basis: 46%; min-width: 0; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--border); }
.workspace.dragging * { user-select: none; }
.ws-panel-closed .ws-details, .ws-panel-closed .ws-splitter { display: none; }
.ws-scroll { overflow-y: auto; flex: 1; padding: 16px 18px; }
.ws-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex: none; }
.ws-head h3 { font-size: 17px; }
.ws-head .meta { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 18px; flex: none; overflow-x: auto; }
.subtabs button { border: 0; background: transparent; color: var(--text-muted); font-size: 13.5px; font-weight: 600;
  padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all .16s ease; white-space: nowrap; }
.subtabs button:hover { color: var(--text); }
.subtabs button.active { color: var(--accent-fg); border-bottom-color: var(--accent-fg); }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px 20px; }
.kv.one { grid-template-columns: 1fr; }
.kv .k { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.kv .v { font-size: 13.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sec { margin-bottom: 22px; }
.sec > h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 10px; }

/* ==================== ДЕРЕВО ТЕГОВ ==================== */
.tree { padding: 6px 8px 20px; font-size: 13.5px; }
.tree ul { list-style: none; margin: 0; padding-left: 17px; position: relative; }
.tree > ul { padding-left: 2px; }
.tree ul ul::before { content: ""; position: absolute; left: 6px; top: 0; bottom: 6px; width: 1px; background: var(--border); }
.tnode { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 9px; cursor: pointer;
  min-height: 34px; transition: background-color .14s ease; }
.tnode:hover { background: var(--surface-2); }
.tnode.sel { background: color-mix(in srgb, var(--accent) 13%, var(--surface)); }
.tnode.sel .tname { color: var(--accent-fg); font-weight: 600; }
.tnode .tw { width: 20px; height: 20px; flex: none; display: grid; place-items: center; border: 0; background: transparent;
  color: var(--text-muted); border-radius: 5px; cursor: pointer; }
.tnode .tw:hover { background: color-mix(in srgb, var(--text) 10%, transparent); }
.tnode .tw svg { width: 13px; height: 13px; transition: transform .16s ease; }
.tnode.open > .tw svg { transform: rotate(90deg); }
.tnode .ico { width: 16px; height: 16px; flex: none; color: var(--text-muted); }
.tnode.grp .ico { color: var(--accent-fg); }
.tnode .tname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tnode .tcode { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
.tnode .tail { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: none; }
.tnode .used { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tnode[hidden] { display: none; }
.tree li.collapsed > ul { display: none; }

/* ==================== ФОРМУЛЫ ==================== */
.formula { font-family: var(--mono); font-size: 13px; line-height: 1.7; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; }
.formula:focus { outline: none; border-color: var(--accent-fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.tok-tag { color: var(--info-fg); background: color-mix(in srgb, var(--info) 14%, var(--surface)); border-radius: 5px; padding: 1px 5px; }
.tok-tag.calc { color: var(--violet-fg); background: color-mix(in srgb, var(--violet) 14%, var(--surface)); }
.tok-fn { color: var(--accent-fg); font-weight: 700; }
.tok-num { color: var(--ok-fg); }
.tok-str { color: var(--warn-fg); }
.tok-err { color: var(--crit-fg); text-decoration: underline wavy; }
.fn-palette { display: flex; flex-wrap: wrap; gap: 6px; }
.fn-chip { font-family: var(--mono); font-size: 12px; padding: 4px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; transition: all .14s ease; }
.fn-chip:hover { border-color: var(--accent-fg); color: var(--accent-fg); }
.deps { display: flex; flex-direction: column; gap: 4px; }
.dep { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px; background: var(--surface-2); font-size: 12.5px; }
.dep svg { width: 15px; height: 15px; flex: none; color: var(--text-muted); }
.dep:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }
.dep b { font-weight: 600; }
.dep .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep .lvl { width: 18px; text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.callout { display: flex; gap: 10px; padding: 11px 13px; border-radius: var(--radius-sm); font-size: 12.5px; line-height: 1.5; }
.callout svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.callout.ok { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); color: var(--ok-fg); }
.callout.warn { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); color: var(--warn-fg); }
.callout.crit { background: color-mix(in srgb, var(--crit) 12%, var(--surface)); color: var(--crit-fg); }
.callout.info { background: color-mix(in srgb, var(--info) 12%, var(--surface)); color: var(--info-fg); }

/* ==================== ЛИСТ ДОКУМЕНТА (A4) ==================== */
.paper-wrap { background: var(--bg); padding: 18px; overflow: auto; flex: 1; }
.paper {
  width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto 16px; padding: 20mm 18mm;
  background: #fff; color: #1c1f22; box-shadow: var(--shadow-lift); border-radius: 2px;
  font-family: "Times New Roman", Georgia, serif; font-size: 11.5pt; line-height: 1.45;
}
.paper h1 { font-size: 15pt; text-align: center; margin-bottom: 6mm; color: #1c1f22; letter-spacing: 0; }
.paper h2 { font-size: 12pt; margin: 6mm 0 3mm; color: #1c1f22; }
.paper p { margin: 0 0 3mm; text-align: justify; }
.paper .center { text-align: center; }
.paper .right { text-align: right; }
.paper table { font-size: 10.5pt; margin: 4mm 0; }
.paper table th, .paper table td { border: 1px solid #98a0a8; padding: 2mm 3mm; text-transform: none; letter-spacing: 0;
  color: #1c1f22; background: transparent; font-size: 10.5pt; }
.paper table th { background: #eef0f2; font-weight: 700; }
.paper .sign { display: flex; justify-content: space-between; gap: 10mm; margin-top: 10mm; }
.paper .sign > div { flex: 1; }
.paper .line { border-bottom: 1px solid #1c1f22; display: inline-block; min-width: 45mm; }
.paper .small { font-size: 9pt; color: #555f68; }
.paper-scale { transform-origin: top center; }
.tagref { border-radius: 4px; padding: 0 3px; font-family: var(--mono); font-size: .82em; white-space: nowrap;
  background: #dbeaf5; color: #1c4f6b; border: 1px solid #a9cbe0; cursor: pointer; }
.tagref.calc { background: #ece0f7; color: #59357f; border-color: #cbb0e6; }
.tagref.miss { background: #fadada; color: #8f1d20; border-color: #e9a8aa; }
.tagref.blk { background: #e6e9ec; color: #3f474e; border-color: #c3c9cf; font-style: italic; }
.filled { background: #eaf5e2; border-radius: 3px; padding: 0 2px; box-shadow: inset 0 -1px 0 #b6d79c; }
.paper.plain .filled { background: transparent; box-shadow: none; padding: 0; }

/* ==================== МОДАЛКА / ТОСТ / ЯЩИК ==================== */
.overlay { position: fixed; inset: 0; background: rgba(20,22,25,.45); backdrop-filter: blur(2px); display: grid;
  place-items: center; z-index: 50; opacity: 0; visibility: hidden; transition: opacity .18s ease, visibility 0s linear .18s; padding: 20px; }
.overlay.open { opacity: 1; visibility: visible; transition: opacity .18s ease, visibility 0s linear 0s; }
.modal { width: min(560px, 100%); max-height: 88vh; overflow-y: auto; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lift); transform: translateY(10px) scale(.985); transition: transform .18s ease; }
.modal.wide { width: min(880px, 100%); }
.overlay.open .modal { transform: none; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); }
.stub-wrap { position: relative; }
.stub-blur { filter: blur(4px); pointer-events: none; user-select: none; }
.stub-caption { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; text-align: center; padding: 16px;
  font-weight: 600; font-size: 15px; color: var(--text); background: color-mix(in srgb, var(--surface) 55%, transparent); }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 15px; border-radius: var(--radius-sm); font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lift); animation: toast-in .22s ease; max-width: 380px; }
.toast svg { width: 17px; height: 17px; flex: none; }
.toast.ok svg { color: var(--ok-fg); } .toast.crit svg { color: var(--crit-fg); } .toast.info svg { color: var(--info-fg); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ==================== СЕТКИ / KPI ==================== */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* Плитки разной высоты: CSS grid кладёт их построчно и оставляет пустоты под
   короткими карточками в строке. .masonry раскладывает карточки по колонкам
   (порядок в DOM), балансируя высоту колонок, — без пустот по вертикали. */
.masonry { column-gap: 14px; }
.masonry > * { break-inside: avoid; margin: 0 0 14px; }
.masonry.m2 { column-count: 2; }
.masonry.m3 { column-count: 3; }
.masonry.m4 { column-count: 4; }
@media (max-width: 1100px) { .masonry.m3, .masonry.m4 { column-count: 2; } }
@media (max-width: 700px) { .masonry.m2, .masonry.m3, .masonry.m4 { column-count: 1; } }
.kpi { padding: 15px 16px; }
.kpi .lbl { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.kpi .val { font-size: 26px; font-weight: 700; font-family: var(--num-font); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .dlt { font-size: 12px; margin-top: 4px; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-muted); }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 5px; }
.timeline { display: flex; flex-direction: column; }
.tl { display: flex; gap: 12px; padding: 9px 0; }
.tl .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--accent); }
.tl .dot.ok { background: var(--ok); } .tl .dot.crit { background: var(--crit); } .tl .dot.muted { background: var(--border); }
.tl .body { font-size: 13px; min-width: 0; }
.tl .body .t { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
/* Вертикальный жизненный цикл сделки — точки этапов соединены линией сверху вниз,
   рядом с каждой точкой название этапа и его статус (дата/«текущий этап»/«этап впереди»). */
.tl-v { display: flex; flex-direction: column; }
.tl-v-item { display: flex; align-items: flex-start; gap: 10px; position: relative; padding-bottom: 16px; }
.tl-v-item:last-child { padding-bottom: 0; }
.tl-v-item:not(:last-child)::after { content: ''; position: absolute; left: 4px; top: 13px; bottom: -3px; width: 1px; background: var(--border); }
.tl-v-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 4px; background: var(--accent); }
.tl-v-item .dot.ok { background: var(--ok); } .tl-v-item .dot.crit { background: var(--crit); } .tl-v-item .dot.muted { background: var(--border); }
.tl-v-item .body { display: flex; flex-direction: row; align-items: baseline; gap: 6px; min-width: 0; flex-wrap: wrap; }
.tl-v-item .lbl { font-size: 13px; font-weight: 600; color: var(--text); }
.tl-v-item .note { font-size: 11.5px; color: var(--text-muted); }
.tl-v-item.cur .lbl { color: var(--accent-fg); }
.tl-v-item.cur .dot { outline: 3px solid var(--accent-fg); outline-offset: 1px; }
.tl-v-item.cur .dot.crit { outline-color: var(--crit-fg); }
.filerow { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; }
.filerow > svg { width: 18px; height: 18px; color: var(--accent-fg); flex: none; }
.filerow svg { width: 16px; height: 16px; flex: none; }
.filerow input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
.stat-icon { width: 20px; height: 20px; color: var(--accent-fg); flex: none; }
a.filerow, label.filerow { transition: border-color .16s ease, background-color .16s ease; }
a.filerow:hover, label.filerow:hover { border-color: var(--accent-fg); }
.filerow.disabled { opacity: .42; cursor: not-allowed; }
.filerow.disabled:hover { border-color: var(--border); }
.tl svg { width: 15px; height: 15px; flex: none; }
.card-body > .grid a.filerow b { display: block; }
/* Таблицы со многими колонками не должны сжимать первую колонку в лапшу */
table.wide { min-width: 720px; }
.dropzone { border: 1.5px dashed var(--border); border-radius: var(--radius-sm); padding: 22px; text-align: center;
  color: var(--text-muted); font-size: 13px; transition: all .16s ease; cursor: pointer; width: 100%;
  max-height: 110px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; gap: 8px; }
.dropzone:hover, .dropzone.over { border-color: var(--accent-fg); color: var(--accent-fg); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.dropzone svg { width: 18px; height: 18px; flex: none; }

@media (max-width: 1100px) {
  /* flex-basis: auto на .ws-details растягивал панель деталей по контенту
     (список может быть длинным), а .ws-list с flex: 1 1 0 в столбце сжимался
     до 0 — список сделок/тегов/итд был вообще не виден. Обеим панелям нужна
     собственная ограниченная высота с внутренней прокруткой. */
  .workspace { flex-direction: column; overflow-y: auto; }
  .ws-list { flex: 0 0 auto; height: 46vh; min-height: 260px; }
  .ws-details {
    flex: 0 0 auto !important; height: auto; max-height: 46vh; overflow-y: auto;
    border-left: 0; border-top: 1px solid var(--border);
  }
  .ws-splitter { display: none; }
}

/* ==================== ЭКРАН ВХОДА ==================== */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-card { width: min(380px, 100%); }
.login-card .card-body { display: flex; flex-direction: column; gap: 16px; padding: 22px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding-bottom: 2px; }
.login-brand .logo { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 18px; }
.login-brand b { font-size: 16px; }
.login-brand .sub { font-size: 12px; color: var(--text-muted); }
.login-err { display: flex; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12.5px;
  background: color-mix(in srgb, var(--crit) 12%, var(--surface)); color: var(--crit-fg); }
.login-err[hidden] { display: none; }
.login-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -4px 0 4px; flex-wrap: wrap; }
.login-foot a { font-size: 12.5px; color: var(--accent-fg); font-weight: 600; }
.login-foot a:hover { text-decoration: underline; }
.login-hint { font-size: 11.5px; color: var(--text-muted); text-align: center; line-height: 1.5; }

/* ==================== АДАПТИВ: МОБИЛЬНЫЙ ЭКРАН ====================
   Десктопная раскладка (>880px) не меняется — правила ниже включаются
   только по max-width. Сайдбар на мобильном становится выезжающей панелью
   поверх контента (.app.nav-open), а не режимом «схлопнуть до 74px». */
.side-backdrop { display: none; }
@media (max-width: 880px) {
  .side-backdrop {
    display: block; position: fixed; inset: 0; z-index: 44;
    background: rgba(20,22,25,.45); opacity: 0; visibility: hidden;
    transition: opacity .18s ease, visibility 0s linear .18s;
  }
  .app.nav-open .side-backdrop { opacity: 1; visibility: visible; transition: opacity .18s ease; }

  .side {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 45; width: min(280px, 84vw);
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lift);
  }
  .app.nav-open .side { transform: translateX(0); }
  #nav-toggle { width: 40px; height: 40px; }

  .appbar { padding: 8px 10px; gap: 8px; flex-wrap: wrap; row-gap: 6px; }
  .appbar-title { order: 3; flex-basis: 100%; min-width: 0; }
  .appbar-title h2 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .appbar-title .sub { display: none; }
  .seg[aria-label="Режим оформления"] { display: none; }
  .seg[aria-label="Система"] a { font-size: 0; padding: 8px; gap: 0; }
  .seg[aria-label="Система"] a svg { width: 18px; height: 18px; }
  .theme-btn span { display: none; }

  .main-scroll { padding: 14px 12px; }
  .kv { grid-template-columns: 1fr; }
  thead th, tbody td { padding: 9px 10px; }
  .modal, .modal.wide { width: min(560px, 100%); }
  .modal-body { padding: 14px; }
}
@media (max-width: 480px) {
  .paper-wrap { padding: 10px; }
}
