/* CRM-тема Кельвики v2 — «уровень Linear/Stripe/Attio» (02.07.2026).
   Источники значений: исследование crm/rynok-2026-07 + дизайн-воркфлоу
   (Radix Gray — реальные hex; тени Tailwind v4; spacing Stripe; приёмы shadcn:
   карточка светлее фона в тёмной теме, альфа-бордеры, focus-кольцо 3px/50%).
   Бренд: жёлтый #FECE15 ТОЛЬКО фоном с тёмным текстом (чёрный на жёлтом ≈14:1 AAA;
   жёлтый текст на белом ≈1.5:1 — запрещён). Шрифт: Inter self-hosted (tabular-nums
   подтверждён — деньги в таблицах не пляшут). */

/* ───────── Inter (self-hosted, кириллица+латиница) ───────── */
@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/inter/inter-cyrillic-400.74a70a8b71d0.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("../fonts/inter/inter-cyrillic-500.0f5211cce140.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("../fonts/inter/inter-cyrillic-600.40727edfba55.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("../fonts/inter/inter-cyrillic-700.fc4bfa8e4204.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/inter/inter-latin-400.da03732a27e1.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("../fonts/inter/inter-latin-500.51205681a1ba.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("../fonts/inter/inter-latin-600.2ede57db1a3a.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("../fonts/inter/inter-latin-700.8ca0a5155296.woff2") format("woff2"); }

:root {
  /* ── Нейтрали: Radix Gray light (роль по ступени: 1-2 фон, 3-5 компонент,
       6-8 бордеры, 9-10 solid, 11-12 текст) ── */
  --gray-1: #FCFCFC; --gray-2: #F9F9F9; --gray-3: #F0F0F0; --gray-4: #E8E8E8;
  --gray-5: #E0E0E0; --gray-6: #D9D9D9; --gray-7: #CECECE; --gray-8: #BBBBBB;
  --gray-9: #8D8D8D; --gray-10: #838383; --gray-11: #646464; --gray-12: #202020;

  /* ── Акцент: жёлтая шкала, ступень 9 = бренд #FECE15 (Pantone 109C) ── */
  --yellow-1: #FEFDFA; --yellow-2: #FEFBE9; --yellow-3: #FFF8BF; --yellow-4: #FFF099;
  --yellow-5: #FCE674; --yellow-6: #F3D66E; --yellow-7: #E7C364; --yellow-8: #DDA737;
  --yellow-9: #FECE15; --yellow-10: #F3C50A; --yellow-11: #8A6416; --yellow-12: #4C3721;

  /* ── Статусы: пастель-фон + тёмный текст (палитра тегов Notion) ── */
  --ok-bg: #EEF3ED;  --ok-text: #44714E;
  --hot-bg: #FAECEC; --hot-text: #B3382F;

  /* ── Бренд-легаси (старые имена продолжают работать) ── */
  --kp-yellow: var(--yellow-9);
  --kp-yellow-hover: var(--yellow-10);
  --kp-yellow-soft: var(--yellow-2);
  --kp-ink: #141517;              /* сайдбар/шапка — тёплый почти-чёрный, не #000 */
  --kp-paper: #FFFFFF;
  --kp-ink-2: var(--gray-11);
  --kp-ink-3: #7C7C7C;
  --kp-line: var(--gray-4);
  --kp-fog: var(--gray-2);
  --kp-eco: #46A758;              /* Radix green 9 — точки/акценты */
  --kp-hot: #E5484D;              /* Radix red 9 */
  --kp-ok: #2F7C43;
  --kp-amber-text: var(--yellow-11);

  --step-overdue: #E5484D;
  --step-today: #F5B301;
  --step-none: #C7C7C7;

  --kp-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Радиусы: инпут/кнопка меньше карточки — вложенность читается «дорого» */
  --kp-r-sm: 8px; --kp-r: 12px; --kp-r-lg: 16px; --kp-r-pill: 999px;
  --kp-s-1: 8px; --kp-s-2: 16px; --kp-s-3: 24px; --kp-s-4: 32px;

  /* Тени Tailwind v4 — еле заметные, намёк на объём, не декорация */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / .07), 0 1px 2px -1px rgb(0 0 0 / .07);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .08), 0 2px 4px -2px rgb(0 0 0 / .08);
  --kp-shadow-card: var(--shadow-md);
  --kp-shadow-soft: var(--shadow-xs);

  /* Движение: быстро и незаметно (Linear: hover 100-150мс) */
  --t-fast: 120ms ease-out;
  --t-med: 200ms ease-out;

  /* Семантические алиасы (компоненты работают через них) */
  --bg: var(--gray-1);
  --surface: #FFFFFF;
  --surface-2: var(--gray-2);
  --surface-3: var(--gray-3);
  --text: var(--gray-12);
  --text-muted: var(--gray-11);
  --text-faint: #7C7C7C;
  --line: var(--gray-4);
  --line-strong: var(--gray-7);   /* бордер инпутов (Radix роль 7) */
  --accent: var(--yellow-9);
  --focus-ring: 0 0 0 3px rgb(254 206 21 / .30);
}

/* Тёмная тема — НЕ инверсия: отдельная калибровка (Radix Gray dark),
   карточка СВЕТЛЕЕ фона (элевация цветом), бордеры — альфа-оверлей. */
[data-theme="dark"] {
  --gray-1: #111111; --gray-2: #191919; --gray-3: #222222; --gray-4: #2A2A2A;
  --gray-5: #313131; --gray-6: #3A3A3A; --gray-7: #484848; --gray-8: #606060;
  --gray-9: #6E6E6E; --gray-10: #7B7B7B; --gray-11: #B4B4B4; --gray-12: #EEEEEE;

  --ok-bg: #242B26;  --ok-text: #6CBD82;
  --hot-bg: #332523; --hot-text: #E06C60;

  --kp-ink: #0B0C0D;
  --kp-paper: #111111;
  --kp-ink-2: var(--gray-11);
  --kp-ink-3: #8F8F8F;
  --kp-line: rgb(255 255 255 / .10);
  --kp-fog: var(--gray-2);
  --kp-amber-text: #E0B54B;

  --bg: var(--gray-1);
  --surface: var(--gray-2);        /* светлее фона — приём shadcn/Geist */
  --surface-2: var(--gray-3);
  --surface-3: var(--gray-4);
  --text: var(--gray-12);
  --text-muted: var(--gray-11);
  --text-faint: #8F8F8F;
  --line: rgb(255 255 255 / .10);
  --line-strong: rgb(255 255 255 / .16);
  --kp-shadow-card: 0 8px 24px rgb(0 0 0 / .45);
  --shadow-xs: none; --shadow-sm: none; --shadow-md: none; /* глубина цветом, не тенью */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--kp-font);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.006em;
  background: var(--bg);
  color: var(--text);
  font-variant-numeric: tabular-nums;   /* деньги в таблицах не пляшут */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { letter-spacing: -0.014em; font-weight: 600; }

a { color: var(--text); text-decoration-color: var(--accent); }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Шапка-приложение (гостевые страницы) */
.app-header {
  display: flex; align-items: center; gap: 14px;
  background: var(--kp-ink); color: #fff;
  padding: 10px 20px;
}
[data-theme="dark"] .app-header { background: #000; }
.app-header .brand-k {
  background: var(--accent); color: #000; font-weight: 700;
  padding: 2px 9px; border-radius: var(--kp-r-sm);
}
.app-header a { color: #fff; }
.app-header nav { display: flex; gap: 18px; margin-left: 20px; }
.app-header nav a { text-transform: uppercase; font-size: 12px; letter-spacing: .08em; opacity: .85; }
.app-header nav a:hover, .app-header nav a.active { opacity: 1; }
.app-header .spacer { flex: 1; }

main.app-main { padding: 24px; max-width: 1240px; margin: 0 auto; }

/* ───────── Сайдбар: приглушённый, навигация уходит на второй план (Linear) ───────── */
.app { display: flex; align-items: stretch; min-height: 100vh; }
.sidebar {
  flex: 0 0 216px; width: 216px; background: var(--kp-ink); color: #fff;
  display: flex; flex-direction: column; gap: 3px; padding: 14px 10px;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 10px; color: #fff;
  text-decoration: none; padding: 2px 8px 12px; font-weight: 600; font-size: 15px;
  letter-spacing: -0.01em; }
.side-brand .brand-k { background: var(--accent); color: #000; font-weight: 700;
  padding: 1px 8px; border-radius: 7px; }
.side-new { width: 100%; justify-content: center; margin-bottom: 10px; }
.side-nav { display: flex; flex-direction: column; gap: 1px; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border-radius: 7px; color: #9BA1A6; text-decoration: none; font-size: 13px;
  font-weight: 500; transition: background var(--t-fast), color var(--t-fast); }
.side-link:hover { background: rgb(255 255 255 / .06); color: #E6E7E8; }
.side-link.active { background: rgb(255 255 255 / .09); color: #fff; font-weight: 600;
  box-shadow: inset 3px 0 0 var(--kp-yellow); }
.side-link .ic { width: 18px; height: 18px; flex: 0 0 18px; fill: none;
  stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.side-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding-top: 12px; }
.side-user { padding: 4px 10px; line-height: 1.3; }
.side-user-name { display: block; font-size: 13px; color: #D5D7D9; }
.side-user-role { display: block; font-size: 11px; color: #7E8388; }
.side-logout { width: 100%; background: transparent; border: 1px solid rgb(255 255 255 / .18);
  color: #C9CCCE; padding: 6px; border-radius: 7px; cursor: pointer; font: inherit;
  font-size: 13px; transition: background var(--t-fast), color var(--t-fast); }
.side-logout:hover { background: rgb(255 255 255 / .07); color: #fff; }

.content { flex: 1 1 auto; min-width: 0; padding: 22px 28px; max-width: 1280px; }
.content.wide { max-width: none; }
.flash { background: var(--yellow-2); color: var(--yellow-11);
  border: 1px solid var(--yellow-4);
  border-radius: 10px; padding: 9px 14px; margin-bottom: 14px; font-size: 13.5px; }
[data-theme="dark"] .flash { background: #2B2416; color: #E0B54B; border-color: #4A3D1C; }
.content-foot { margin-top: 34px; font-size: 12px; color: var(--text-faint); }
.content-foot a { color: var(--text-faint); }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { flex: none; width: auto; height: auto; position: sticky; top: 0; z-index: 20;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 10px; }
  .side-brand { padding: 4px 6px; } .side-brand-txt { display: none; }
  .side-new { width: auto; margin: 0; }
  .side-nav { flex-direction: row; flex: 1 1 auto; overflow-x: auto; }
  .side-link span { display: none; } .side-link { padding: 9px; }
  .side-link.active { box-shadow: inset 0 -3px 0 var(--kp-yellow); }
  .side-bottom { margin: 0; flex-direction: row; align-items: center; padding: 0; gap: 6px; }
  .side-user { display: none; } .side-logout { width: auto; padding: 7px 12px; }
  .content { padding: 14px; max-width: none; }
}

/* ───────── Кнопки ───────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: var(--kp-r-sm); font-weight: 500;
  font-size: 13.5px; cursor: pointer; text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: background var(--t-fast), border-color var(--t-fast),
              box-shadow var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(0.5px); box-shadow: none; }
.btn:focus-visible { box-shadow: var(--focus-ring); }
.btn-primary { background: var(--yellow-9); color: #141517; border-color: transparent;
  font-weight: 600; }
.btn-primary:hover { background: var(--yellow-10); }

/* ───────── Бейджи состояний: пастель-фон + тёмный текст (Notion-пары) ───────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: var(--kp-r-pill);
  font-size: 11.5px; font-weight: 600; letter-spacing: 0; }
.badge-paid { background: var(--ok-bg); color: var(--ok-text); }
.badge-debt { background: var(--hot-bg); color: var(--hot-text); }
.badge-seg-large { background: var(--yellow-9); color: #201800; }
.badge-seg-medium { background: var(--yellow-2); color: var(--yellow-11);
  border: 1px solid var(--yellow-4); }
[data-theme="dark"] .badge-seg-medium { background: #2B2416; color: #E0B54B; border-color: #4A3D1C; }
.badge-seg-small { background: var(--surface-3); color: var(--text-muted); }

/* ───────── Карточки и таблицы ───────── */
.card { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--kp-r); padding: 16px; box-shadow: var(--shadow-xs); }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 9px 12px;
  border-bottom: 1px solid var(--gray-3); }
table.data th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--gray-9); font-weight: 600; border-bottom-color: var(--line); }
table.data tbody tr { transition: background var(--t-fast); }
table.data tbody tr:hover { background: var(--surface-2); }

/* Маркер следующего шага */
.step-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.step-overdue { background: var(--step-overdue); }
.step-today { background: var(--step-today); }
.step-none { background: var(--step-none); }
.step-ok { background: var(--kp-eco); }

/* ───────── Канбан ───────── */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kanban-col { flex: 0 0 264px; background: var(--surface-2);
  border: 1px solid var(--gray-3); border-radius: var(--kp-r); padding: 8px; }
[data-theme="dark"] .kanban-col { border-color: var(--line); }
.kanban-col-head { font-weight: 600; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  padding: 4px 6px 10px; display: flex; gap: 6px; justify-content: flex-start; align-items: baseline; }
.kanban-count { color: var(--gray-9); font-weight: 600; }
.kanban-sum { margin-left: auto; color: var(--text-faint); font-weight: 500;
  font-size: 11.5px; text-transform: none; letter-spacing: 0; white-space: nowrap; }
.kanban-drop { min-height: 40px; display: flex; flex-direction: column; gap: 8px; }
.kanban-terminals { flex: 0 0 240px; display: flex; flex-direction: column; gap: 8px; }
.kanban-terminal { background: var(--surface-2); border: 1px solid var(--gray-3);
  border-radius: var(--kp-r); padding: 8px; }
.kanban-terminal summary { cursor: pointer; font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }

.deal-card { display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--kp-r-sm); padding: 10px 11px; text-decoration: none; color: var(--text);
  box-shadow: var(--shadow-xs); cursor: grab;
  transition: box-shadow var(--t-fast), transform var(--t-fast), border-color var(--t-fast); }
.deal-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px);
  border-color: var(--gray-6); }
.deal-card-top { display: flex; align-items: center; gap: 6px; font-size: 13.5px; }
.deal-card-title { font-size: 12.5px; color: var(--text-muted); margin: 3px 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-card-meta { display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--text-faint); }
.deal-next { color: var(--yellow-11); }
[data-theme="dark"] .deal-next { color: var(--kp-yellow); }
.deal-card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: var(--kp-r-pill);
  background: var(--surface-3); color: var(--text-muted); white-space: nowrap; }
.tag-paid { background: var(--ok-bg); color: var(--ok-text); }
.tag-debt { background: var(--hot-bg); color: var(--hot-text); }
.drag-ghost { opacity: .4; }

/* Мобильный список по стадиям */
.kanban-mobile { display: none; }
.mobile-stage { background: var(--surface-2); border-radius: var(--kp-r); padding: 8px; margin-bottom: 10px; }
.mobile-stage summary { cursor: pointer; font-weight: 600; font-size: 13.5px; padding: 4px;
  display: flex; justify-content: space-between; }
.mobile-stage .deal-card { margin-top: 8px; cursor: pointer; }

/* ───────── Формы ───────── */
.form-grid { display: grid; gap: 14px; max-width: 560px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row > label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 600; }
.field {
  width: 100%; padding: 8px 11px; font: inherit; letter-spacing: inherit;
  border: 1px solid var(--line-strong); border-radius: var(--kp-r-sm);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field:focus { outline: none; border-color: var(--yellow-8); box-shadow: var(--focus-ring); }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.form-hint { font-size: 12px; color: var(--text-faint); text-transform: none; letter-spacing: 0; }
.form-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .form-cols { grid-template-columns: 1fr; } }

/* Inline-редактирование (клик по значению → форма на месте) */
.editable { cursor: pointer; border-bottom: 1px dashed var(--gray-6); }
.editable:hover { background: var(--surface-2); }
.inline-edit { display: flex; gap: 6px; align-items: center; }
.inline-edit .field { padding: 5px 8px; }
.inline-field { transition: background var(--t-fast); border-radius: 4px; }
.inline-field:hover { background: var(--yellow-1); }
[data-theme="dark"] .inline-field:hover { background: var(--surface-3); }

@media (max-width: 760px) {
  .kanban { display: none; }
  .kanban-mobile { display: block; }
  main.app-main { padding: 14px; }
}

/* Вход и 2FA */
.auth-card { max-width: 380px; margin: 6vh auto 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--kp-r-lg);
  box-shadow: var(--kp-shadow-card); padding: 28px 26px; text-align: center; }
.auth-card h1 { font-size: 22px; margin: 0 0 10px; }
.auth-card .muted { color: var(--text-muted); font-size: 14px; line-height: 1.5; }
.qr-box { margin: 18px auto; width: 200px; height: 200px; }
.qr-box svg { width: 100%; height: 100%; }
.manual-key { margin: 4px 0 16px; font-size: 13px; }
.manual-key summary { cursor: pointer; color: var(--text-faint); }
.secret { display: inline-block; margin-top: 8px; padding: 6px 10px;
  background: var(--surface-2); border-radius: var(--kp-r-sm);
  font-family: ui-monospace, monospace; letter-spacing: .12em; word-break: break-all; }
.otp-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.otp-form input { font-size: 28px; text-align: center; letter-spacing: .35em;
  padding: 12px; border: 1px solid var(--line-strong); border-radius: var(--kp-r);
  background: var(--surface); color: var(--text); }
.btn-link { background: none; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 13px; text-decoration: underline; }

.muted { color: var(--text-muted); }

/* Редактор стадий воронки */
.stages-edit input, .stages-edit select { padding: 6px 8px; border: 1px solid var(--line-strong);
  border-radius: var(--kp-r-sm); background: var(--surface); color: var(--text); font: inherit; }
.stages-edit .stage-new { background: var(--surface-2); }

/* Чек-лист стадии */
.check-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.check-row input { width: 17px; height: 17px; accent-color: var(--accent); }
.check-done { color: var(--text-faint); text-decoration: line-through; }

/* База знаний — markdown */
.wiki-body { line-height: 1.6; font-size: 14.5px; max-width: 72ch; }
.wiki-body h2 { font-size: 19px; margin: 18px 0 8px; }
.wiki-body h3 { font-size: 16px; margin: 16px 0 6px; }
.wiki-body h4 { font-size: 14px; margin: 14px 0 6px; }
.wiki-body p { margin: 8px 0; }
.wiki-body ul { margin: 8px 0; padding-left: 22px; }
.wiki-body li { margin: 3px 0; }
.wiki-body code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px;
  font-family: ui-monospace, monospace; font-size: .92em; }
.wiki-body a { color: var(--text); text-decoration: underline; text-decoration-color: var(--accent); }

/* Конструктор КП */
.quote-item { margin-bottom: 12px; }
.tiers { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tier-pair { display: inline-flex; gap: 4px; }
.tier-pair .field { width: 80px; padding: 5px 7px; }

/* Планёрка — метрики */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--kp-r);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow-xs); }
.metric-num { font-size: 22px; font-weight: 650; line-height: 1.1; letter-spacing: -0.02em; }
.metric-cap { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .05em; font-weight: 600; }
.metric-debt .metric-num { color: var(--kp-hot); }

/* Карточка сделки: компактный правый столбец */
.deal-aside { display: flex; flex-direction: column; gap: 10px; }
.deal-aside .card { padding: 13px 15px; }
.deal-aside .card h3 { font-size: 14px; letter-spacing: -0.01em; margin-bottom: 8px; }
.fold { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--kp-r); padding: 11px 15px; box-shadow: var(--shadow-xs); }
.fold > summary { cursor: pointer; font-weight: 600; font-size: 14px; list-style: none;
  display: flex; align-items: center; gap: 8px; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: "▸"; color: var(--text-faint); font-size: 11px; width: 10px; }
.fold[open] > summary::before { content: "▾"; }
.fold > summary .cnt { margin-left: auto; color: var(--text-faint); font-weight: 400; font-size: 12.5px; }
.fold > *:not(summary) { margin-top: 10px; }

/* ───────── Переписка: тред как в почтовике ───────── */
.msg { display: flex; gap: 10px; margin: 0 0 14px; }
.msg-out { flex-direction: row-reverse; }
.msg-avatar { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; color: #fff; background: var(--gray-9); }
.msg-out .msg-avatar { background: var(--yellow-9); color: #141517; }
.msg-bubble { max-width: 80%; min-width: 240px; padding: 10px 13px;
  border-radius: var(--kp-r); border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow-xs); }
.msg-out .msg-bubble { background: var(--yellow-2); border-color: var(--yellow-4);
  --text: #1B1B1B; --text-faint: #6F684A; color: var(--text); }
.msg-head { font-size: 12px; color: var(--text-faint); margin-bottom: 6px;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.msg-head strong { color: var(--text); font-weight: 600; }
.msg-time { white-space: nowrap; }
.msg-body { white-space: pre-wrap; font-size: 14px; line-height: 1.55; word-break: break-word; }
.msg-atts { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }
.att-chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2);
  font-size: 12.5px; text-decoration: none; color: var(--text); max-width: 100%;
  transition: border-color var(--t-fast), background var(--t-fast); }
.att-chip:hover { border-color: var(--yellow-8); background: var(--surface); }
.att-chip img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.att-ico { font-size: 17px; }
.att-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500; }
.att-size { color: var(--text-faint); font-size: 11.5px; white-space: nowrap; }
.qfold { margin-top: 8px; }
.qfold > summary { cursor: pointer; font-size: 12px; color: var(--text-faint);
  user-select: none; list-style: none; transition: color var(--t-fast); }
.qfold > summary::-webkit-details-marker { display: none; }
.qfold > summary::before { content: "▸ "; font-size: 10px; }
.qfold[open] > summary::before { content: "▾ "; }
.qfold[open] > summary { color: var(--text); }
.msg-quoted { white-space: pre-wrap; font-size: 13px; line-height: 1.45;
  color: var(--text-faint); border-left: 3px solid var(--gray-4);
  padding-left: 10px; margin-top: 6px; word-break: break-word; }

/* ───────── Модалка быстрого создания ───────── */
.modal-overlay { position: fixed; inset: 0; background: rgb(20 21 23 / .40);
  backdrop-filter: blur(2px);
  z-index: 200; display: flex; align-items: flex-start; justify-content: center;
  padding: 7vh 16px 16px; }
.modal-box { background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-md), 0 16px 40px rgb(0 0 0 / .12);
  padding: 18px 20px; width: 600px; max-width: 100%; max-height: 86vh; overflow: auto;
  animation: modal-in 150ms ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(4px) scale(.985); }
  to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-x { background: none; border: 0; cursor: pointer; font-size: 15px;
  color: var(--text-faint); padding: 4px 8px; border-radius: 7px;
  transition: background var(--t-fast), color var(--t-fast); }
.modal-x:hover { background: var(--surface-2); color: var(--text); }

/* Входящие: вся строка кликабельна */
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--surface-2); }

/* Дисциплина потока: чипы-фильтры */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 11px;
  border: 1px solid var(--line-strong); border-radius: var(--kp-r-pill);
  font-size: 12.5px; font-weight: 500; text-decoration: none; color: var(--text);
  background: var(--surface); box-shadow: var(--shadow-xs);
  transition: background var(--t-fast), border-color var(--t-fast); }
.chip:hover { background: var(--surface-2); }
.chip-hot { color: var(--hot-text); border-color: #EBC8C4; background: var(--hot-bg); }
.chip-active { background: var(--kp-ink); color: #fff; border-color: var(--kp-ink); }
.chip-hot.chip-active { background: var(--kp-hot); color: #fff; border-color: var(--kp-hot); }

/* Undo-тосты (батч 9) */
#toast-root { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { display: flex; align-items: center; gap: 14px; background: var(--kp-ink, #1a1a1a);
  color: #fff; border-radius: 10px; padding: 10px 16px; font-size: 14px;
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,.25)); }
.toast-btn { border: 0; background: none; color: #FECE15; font: inherit; font-weight: 700;
  cursor: pointer; padding: 2px 4px; }

/* Палитра Ctrl+K (батч 9) */
#palette-overlay { position: fixed; inset: 0; background: rgba(15,15,15,.45); z-index: 300; }
#palette-box { width: min(580px, 92vw); margin: 12vh auto 0; background: var(--surface, #fff);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0,0,0,.3); }
#palette-input { width: 100%; border: 0; border-bottom: 1px solid var(--line);
  padding: 14px 16px; font: inherit; font-size: 15px; background: var(--surface);
  color: var(--text); outline: none; box-sizing: border-box; }
#palette-results { max-height: 52vh; overflow-y: auto; padding: 6px 0; }
.pal-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); padding: 8px 16px 3px; }
.pal-item { display: flex; justify-content: space-between; gap: 12px; padding: 7px 16px;
  font-size: 14px; color: var(--text); text-decoration: none; }
.pal-item:hover, .pal-item.active { background: var(--surface-2); }
.pal-meta { color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.pal-empty { padding: 16px; color: var(--text-faint); font-size: 14px; }
#palette-hint { border-top: 1px solid var(--line); padding: 7px 16px; font-size: 11.5px;
  color: var(--text-faint); }
.chip-x { border: 0; background: none; cursor: pointer; color: inherit; font-size: 11px;
  padding: 0 0 0 2px; opacity: .55; }
.chip-x:hover { opacity: 1; }

/* ───────── Лента стадий в шапке карточки (волна Г, привычка Битрикса §7) ─────────
   Плашки: пройденные (серая заливка) / текущая (жёлтая — единственное жёлтое
   пятно: бейдж стадии из h1 на десктопе скрыт) / будущие (контур); терминалы —
   зелёная/красная. Клик = смена стадии через гейты move_stage. На узких экранах
   лента скрыта — fallback: select «Стадия» в правой колонке. */
.stage-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0 0 16px; }
.stage-pill { font: inherit; font-size: 12px; font-weight: 500; padding: 4px 12px;
  border-radius: var(--kp-r-pill); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text-faint); cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast); }
.stage-pill:hover { background: var(--surface-2); color: var(--text); }
.stage-pill:disabled { cursor: default; }
.stage-passed { background: var(--surface-3); border-color: transparent; color: var(--text-muted); }
.stage-passed:hover { background: var(--gray-5); }
.stage-current, .stage-current:hover { background: var(--yellow-9);
  border-color: transparent; color: #201800; font-weight: 600; }
.stage-won, .stage-won:hover { background: var(--ok-bg); border-color: transparent; color: var(--ok-text); }
.stage-lost, .stage-lost:hover { background: var(--hot-bg); border-color: transparent; color: var(--hot-text); }
.stage-won.stage-current { background: var(--kp-eco); color: #fff; }
.stage-lost.stage-current { background: var(--kp-hot); color: #fff; }
.stage-strip-sep { width: 1px; align-self: stretch; background: var(--line-strong); margin: 2px 5px; }
.stage-badge-mobile { display: none; }
@media (max-width: 760px) {
  .stage-strip { display: none; }
  .stage-badge-mobile { display: inline-block; }
}

/* Спецификация (батч 10): плотная таблица с инлайн-инпутами */
.spec-table td { padding: 3px 4px; }
.spec-table input.field { padding: 4px 6px; font-size: 13px; width: 100%; box-sizing: border-box; }
.spec-table input[name="qty"] { min-width: 76px; } /* 5-значный тираж виден целиком */
.spec-del { border: 0; background: none; color: var(--text-faint); cursor: pointer;
  font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.spec-del:hover { color: var(--kp-hot); background: var(--surface-2); }
