  /* --- Палитра -------------------------------------------------------------
     Светлая тема — база, тёмная ниже перекрывает те же токены. Правило: ни
     одного цвета мимо переменных, иначе ночью вылезет светлое пятно (паритет
     наборов проверяет tests/test_inbox_theme.py). Тему ставит js/00-theme.js
     атрибутом data-theme на <html> — до первой отрисовки, без мигания. */
  :root {
    /* Холодный графит + один кобальтовый акцент (редизайн 2026-07-25).
       Правило: нейтрали без примесей тепла, акцент ровно один. */
    color-scheme: light;
    --bg: #f5f6f8; --panel: #ffffff; --panel2: #f0f1f4; --accent: #3f5bd9;
    --accent2: #3f5bd9; --accent-hover: #3450c4; --text: #191b20; --muted: #737985;
    --in: #eef0f3; --out-text: #ffffff; --unread: #3f5bd9; --danger: #d6493f;
    --border: #e8eaee; --border2: #dcdfe4; --hover: #e9ebef;
    --tint: #e9edfb; --radius: 12px;
    --shadow: 0 1px 2px rgba(24,27,36,.04), 0 8px 24px rgba(24,27,36,.06);
    /* Акцент словами: --accent красит фон (на нём белый текст), --accent-fg —
       текст и иконки на подложке страницы, --accent-ink — текст на --tint.
       Одним цветом не обойтись: что читаемо текстом, то блёкло фоном. */
    --accent-fg: #3f5bd9; --accent-ink: #2b44b5;
    /* Служебные подложки: затемнение под модалками, кольцо фокуса, код. */
    --overlay: rgba(24,27,36,.4); --focus-ring: rgba(63,91,217,.16);
    --code-bg: rgba(24,27,36,.07);
    --scroll: #d5d8de; --scroll-hover: #c0c4cc; --placeholder: #a6abb5;
    --field: #ffffff;
    --mb-bg: #f8f8f6; --mb-dot: #d9d9d4;
    /* Статусы: --ok/--warn/--err — текст и рамки на подложке страницы,
       --*-ink — текст на своей цветной плашке --*-bg. */
    --ok: #2e7d32; --ok-ink: #1d7a3e; --ok-bg: #e8f6ec;
    --warn: #ef6c00; --warn-ink: #9a6b00; --warn-bg: #fdf1dd;
    --err: #c62828; --danger-bg: #fdeeee;
    --gold: #d29a2b; --gold-ink: #b8860b; --gold-bg: #b8860b22;
    --pos: #006300; --bar: #4f83c1; --tree-line: #b3a99d;
    /* Отделы HRM: цвет узла, подложка считается из него через color-mix. */
    --hrm-0: #2e7d32; --hrm-1: #3f5bd9; --hrm-2: #1565c0;
    --hrm-3: #6a4fb3; --hrm-4: #a8790a; --hrm-5: #00838f;
    /* Графики: SVG рисует js/09-analytics.js, цвета берёт отсюда. */
    --chart-grid: #e1e0d9; --chart-axis: #c3c2b7; --chart-label: #737985;
    --chart-sub: #52514e; --chart-dot: #ffffff;
    --ser-1: #4f83c1; --ser-2: #d29a2b; --ser-3: #2f7d46; --ser-4: #5c4fb0;
    /* Теги рубрик и форматов контент-плана (js/15-content.js). */
    --tag-orange-fg: #c2410c; --tag-orange-bg: #ffe4d8;
    --tag-green-fg: #0f7b52; --tag-green-bg: #d8f2e5;
    --tag-brown-fg: #8a5a19; --tag-brown-bg: #f6e8cf;
    --tag-blue-fg: #1d5fd0; --tag-blue-bg: #dde9fc;
    --tag-amber-fg: #c2570a; --tag-amber-bg: #ffe9d1;
    --tag-red-fg: #c02626; --tag-red-bg: #fde2e2;
    --tag-violet-fg: #6d3fc0; --tag-violet-bg: #ece3fb;
  }
  /* Тёмная тема. Включается только явным data-theme="dark": режим «как в
     системе» вычисляет 00-theme.js и всё равно проставляет атрибут — так
     тёмные значения лежат в одном месте, а не дублируются ещё раз под
     @media (prefers-color-scheme: dark). */
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #13151a; --panel: #191c22; --panel2: #222731; --accent: #4f6ae0;
    --accent2: #4f6ae0; --accent-hover: #6076e8; --text: #e5e8ee; --muted: #949cab;
    --in: #222731; --out-text: #ffffff; --unread: #4f6ae0; --danger: #ef6f63;
    --border: #262b34; --border2: #343b46; --hover: #262c36;
    --tint: #26304f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
    --accent-fg: #93a8ff; --accent-ink: #b3c2ff;
    --overlay: rgba(6,8,12,.66); --focus-ring: rgba(95,123,240,.32);
    --code-bg: rgba(255,255,255,.09);
    --scroll: #333944; --scroll-hover: #454d5b; --placeholder: #6a7280;
    --field: #14171d;
    --mb-bg: #dcdcd7; --mb-dot: #c3c3be;
    --ok: #58bb6d; --ok-ink: #79d18d; --ok-bg: #17301f;
    --warn: #e8964a; --warn-ink: #ddab68; --warn-bg: #33291a;
    --err: #ef6f63; --danger-bg: #35201f;
    --gold: #e0aa46; --gold-ink: #dfae52; --gold-bg: #b8860b2e;
    --pos: #5ec072; --bar: #5b8fc9; --tree-line: #454b55;
    --hrm-0: #63b56f; --hrm-1: #8ea4ff; --hrm-2: #61a5e0;
    --hrm-3: #a58ce0; --hrm-4: #d3a63f; --hrm-5: #4fb9c4;
    --chart-grid: #2a2f39; --chart-axis: #3b414c; --chart-label: #949cab;
    --chart-sub: #7d8593; --chart-dot: #191c22;
    --ser-1: #6d9fdb; --ser-2: #dda94a; --ser-3: #55a86e; --ser-4: #8b7ce0;
    --tag-orange-fg: #f0a882; --tag-orange-bg: #3a2418;
    --tag-green-fg: #6fc9a1; --tag-green-bg: #16302a;
    --tag-brown-fg: #d3aa72; --tag-brown-bg: #322619;
    --tag-blue-fg: #8fb2f5; --tag-blue-bg: #1c2740;
    --tag-amber-fg: #e8a86a; --tag-amber-bg: #362619;
    --tag-red-fg: #ef8a8a; --tag-red-bg: #37201f;
    --tag-violet-fg: #b79cf0; --tag-violet-bg: #2a2140;
  }
  * { box-sizing: border-box; margin: 0; }
  body {
    font-family: "Golos Text", -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg); color: var(--text); height: 100vh; height: 100dvh; overflow: hidden;
    -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
    font-variant-numeric: tabular-nums;
  }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 999px;
    border: 3px solid transparent; background-clip: content-box; }
  ::-webkit-scrollbar-thumb:hover { background: var(--scroll-hover); background-clip: content-box; }
  button { font: inherit; cursor: pointer; border: 0; border-radius: 8px;
    transition: background .15s, color .15s, opacity .15s, box-shadow .15s, transform .1s; }
  button:active { transform: scale(.98); }
  :where(button, a, [tabindex]):focus-visible { outline: 2px solid var(--accent);
    outline-offset: 2px; }
  input, textarea, select { font: inherit; color: var(--text); background: var(--field);
    border: 1px solid var(--border2); border-radius: 8px; padding: 11px 13px; outline: none;
    transition: border-color .15s, box-shadow .15s; }
  input::placeholder, textarea::placeholder { color: var(--placeholder); }
  input:focus, textarea:focus, select:focus { border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring); }
  /* Текстовые поля растут по содержимому (высоту выставляет autosize в JS),
     упираются в потолок и только тогда скроллятся — чтобы не листать текст
     в крохотном окошке. min-height — пол: пустое поле показывает две строки
     целиком (в одну «Написать сообщение…» не помещается и обрезается). */
  textarea { max-height: 55vh; overflow-y: auto; min-height: 64px; }

  #login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; height: 100dvh; }
  #login-form { background: var(--panel); padding: 34px 30px; border-radius: 14px;
    display: flex; flex-direction: column; gap: 12px; width: 340px;
    box-shadow: var(--shadow); border: 1px solid var(--border); }
  #login-form h1 { font-size: 21px; font-weight: 700; text-align: center;
    margin-bottom: 8px; letter-spacing: -.02em; }
  #login-form button { background: var(--accent); color: #fff; padding: 12px;
    font-weight: 600; border-radius: 8px; }
  #login-form button:hover { background: var(--accent-hover); }
  #login-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 16px; }

  #app { display: none; height: 100vh; height: 100dvh; }
  #app.active { display: flex; }
  #sidebar { width: 384px; min-width: 300px; background: var(--panel);
    border-right: 1px solid var(--border); display: flex; flex-direction: column; }
  .chip { background: var(--panel2); color: var(--muted); padding: 6px 13px;
    border-radius: 999px; font-size: 13px; font-weight: 500; }
  .chip:hover { background: var(--hover); color: var(--text); }
  .chip.active { background: var(--accent); color: #fff; }
  .chip.active:hover { background: var(--accent-hover); color: #fff; }
  /* «Свой период» в аналитике: поля дат всплывают поверх страницы (в <body>),
     потому что полоса чипов прокручивается и обрезала бы вложенную панель */
  .pay-custom-pop { position: fixed; z-index: 90;
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    padding: 10px; display: flex; gap: 8px; align-items: center;
    box-shadow: 0 8px 24px rgba(0,0,0,.12); }
  .pay-custom-pop[hidden] { display: none; }
  .pay-custom-pop label { display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--muted); white-space: nowrap; }
  .pay-custom-pop input[type="date"] { background: var(--panel2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
    font-size: 13px; font-family: inherit; }
  .pay-custom-pop .pc-apply { padding: 6px 12px; border-radius: 8px; font-size: 13px; }
  .pay-custom-pop .pc-reset { padding: 6px 10px; border-radius: 8px; font-size: 13px;
    color: var(--muted); }
  .pay-custom-pop .pc-reset:hover { color: var(--text); background: var(--hover); }
  @media (max-width: 640px) {
    .pay-custom-pop { flex-wrap: wrap; width: min(92vw, 320px); }
  }
  #new-msg-btn { margin-left: auto; background: var(--accent); color: #fff;
    width: 34px; height: 34px; border-radius: 10px; flex: none;
    display: flex; align-items: center; justify-content: center; }
  #new-msg-btn:hover { background: var(--accent-hover); }
  #new-msg-btn svg { width: 18px; height: 18px; }
  #logout { background: none; color: var(--muted); font-size: 13px; padding: 4px 6px; }
  #logout:hover { color: var(--text); }
  #conv-list { flex: 1; overflow-y: auto; padding: 6px; }
  .conv { display: flex; gap: 12px; padding: 11px 12px; cursor: pointer;
    border-radius: 12px; align-items: center; }
  .conv:hover { background: var(--panel2); }
  .conv.selected { background: var(--tint); }
  .conv.selected .name { color: var(--accent-ink); }
  .avatar { width: 46px; height: 46px; border-radius: 13px; flex: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 19px; font-weight: 600; color: #fff; overflow: hidden; }
  img.avatar { object-fit: cover; }
  .conv-body { flex: 1; min-width: 0; }
  .conv-top { display: flex; justify-content: space-between; gap: 8px; }
  .name { font-weight: 600; font-size: 14.5px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
  .meta { font-size: 12px; color: var(--muted); flex: none; }
  .conv-bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 3px;
    align-items: center; }
  .preview { font-size: 13px; color: var(--muted); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; }
  .badge { background: var(--unread); color: #fff; border-radius: 999px;
    font-size: 12px; min-width: 20px; height: 20px; padding: 0 6px; flex: none;
    display: flex; align-items: center; justify-content: center; font-weight: 600; }
  .src { font-size: 10.5px; padding: 2px 8px; border-radius: 999px; color: #fff; flex: none;
    font-weight: 500; letter-spacing: .01em; }

  /* Закреплённый блок «Новые заявки» над списком диалогов: карточки на этапе
     new, по которым продажник ещё не сделал ни одного действия. */
  #new-leads { flex: none; border-bottom: 1px solid var(--border); display: none; }
  #new-leads.has { display: block; }
  #new-leads-head { display: flex; align-items: center; gap: 8px; cursor: pointer;
    padding: 9px 14px; font-size: 13px; font-weight: 600; user-select: none; }
  #new-leads-head .dot { width: 8px; height: 8px; border-radius: 50%; flex: none;
    background: var(--accent); animation: nl-pulse 1.6s ease-in-out infinite; }
  @keyframes nl-pulse { 50% { opacity: .35; } }
  #new-leads-head .cnt { background: var(--accent); color: #fff; border-radius: 999px;
    font-size: 11.5px; min-width: 19px; height: 19px; padding: 0 6px; display: flex;
    align-items: center; justify-content: center; font-weight: 600; }
  #new-leads-head .tgl { margin-left: auto; color: var(--muted); font-size: 11px;
    transition: transform .15s; }
  #new-leads.collapsed .tgl { transform: rotate(-90deg); }
  #new-leads.collapsed #new-leads-list { display: none; }
  #new-leads-list { max-height: 34vh; overflow-y: auto; padding: 0 6px 6px; }
  .nl-wait { font-size: 11.5px; color: var(--accent-fg); font-weight: 600; flex: none; }
  /* «×» на карточке заявки: убрать из воронки прямо из блока (спам/тест),
     не открывая CRM-доску. На тач-экранах hover нет — кнопка видна всегда. */
  .nl-x { flex: none; width: 24px; height: 24px; border-radius: 7px; background: none;
    color: var(--muted); display: none; align-items: center; justify-content: center;
    font-size: 17px; line-height: 1; }
  #new-leads-list .conv:hover .nl-x { display: flex; }
  .nl-x:hover { color: var(--danger); background: var(--hover); }
  @media (hover: none) { #new-leads-list .conv .nl-x { display: flex; } }

  #main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
  #chat-header { padding: 12px 18px; background: var(--panel);
    border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px;
    min-height: 62px; }
  #back-btn { display: none; background: none; color: var(--muted); padding: 4px; }
  #back-btn svg { width: 22px; height: 22px; }
  #chat-title { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
  #chat-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
  /* Номер телефона контакта (WhatsApp/MAX/из заявки) — клик копирует. */
  .chat-phone { cursor: pointer; font-variant-numeric: tabular-nums; }
  .chat-phone:hover { color: var(--accent-fg); text-decoration: underline; }
  #messages { flex: 1; overflow-y: auto; padding: 20px 18px; display: flex;
    flex-direction: column; gap: 4px; }
  .msg { max-width: 62%; padding: 9px 13px; border-radius: 14px; font-size: 14px;
    line-height: 1.45; white-space: pre-wrap; overflow-wrap: break-word; position: relative;
    box-shadow: 0 1px 1px rgba(24,27,36,.04); }
  .msg-actions { position: absolute; top: -14px; right: 8px; display: none; gap: 4px;
    background: var(--panel); padding: 3px; border-radius: 10px;
    border: 1px solid var(--border); box-shadow: var(--shadow); }
  .msg:hover .msg-actions { display: flex; }
  .msg-actions button { background: none; color: var(--muted); display: flex;
    align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 7px; }
  .msg-actions button svg { width: 15px; height: 15px; }
  .msg-actions button:hover { background: var(--panel2); color: var(--text); }
  .msg-actions button.act-del:hover { background: var(--tint); color: var(--danger); }
  #edit-banner { display: none; align-items: center; gap: 8px; font-size: 13px;
    color: var(--accent-fg); font-weight: 500; }
  #edit-banner svg { width: 15px; height: 15px; flex: none; }
  #edit-banner button { background: var(--panel2); color: var(--muted); font-weight: 500;
    padding: 4px 11px; font-size: 12px; border-radius: 999px; margin-left: 2px; }
  #edit-banner button:hover { background: var(--hover); color: var(--text); }
  .msg.in { background: var(--panel); align-self: flex-start; border: 1px solid var(--border);
    border-bottom-left-radius: 5px; }
  .msg.out { background: var(--accent);
    color: var(--out-text); align-self: flex-end; border-bottom-right-radius: 5px; }
  .msg .time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 4px; }
  .msg.out .time { color: rgba(255,255,255,.78); }
  /* Галочки доставки WhatsApp: ✓ отправлено, ✓✓ доставлено, ✓✓ ярче — прочитано,
     ⚠ — номер не подтверждён usync (могло не дойти). */
  .msg .ticks { margin-left: 5px; letter-spacing: -2px; }
  .msg.out .ticks.read { color: #fff; text-shadow: 0 0 6px rgba(255,255,255,.8); }
  .msg .ticks.warn { color: #ffd166; letter-spacing: 0; font-weight: 700; }
  .msg code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px;
    font-family: "JetBrains Mono", "SF Mono", Consolas, monospace; font-size: 13px; }
  .msg.out code { background: rgba(255,255,255,.22); }
  .att-img { max-width: 320px; max-height: 340px; width: auto; border-radius: 12px;
    display: block; margin: 3px 0; cursor: zoom-in; }
  .att-sticker { max-width: 150px; max-height: 150px; display: block; margin: 3px 0; }
  .att-video { max-width: 320px; max-height: 340px; border-radius: 12px;
    display: block; margin: 3px 0; }
  .msg audio { max-width: 280px; display: block; margin: 4px 0; }
  .att-file { color: inherit; display: inline-flex; align-items: center; gap: 6px;
    margin: 3px 0; word-break: break-all; text-decoration: underline; }
  .att-file svg { width: 15px; height: 15px; flex: none; }
  #attach-btn { background: var(--panel2); color: var(--muted); display: flex;
    align-items: center; justify-content: center; padding: 0 15px; align-self: stretch;
    border-radius: 12px; }
  #attach-btn:hover { background: var(--hover); color: var(--text); }
  #attach-btn svg { width: 19px; height: 19px; }
  #attach-row { display: none; gap: 8px; flex-wrap: wrap; }
  #attach-row.has { display: flex; }
  .pend { position: relative; width: 60px; height: 60px; border-radius: 10px;
    overflow: hidden; border: 1px solid var(--border2); }
  .pend img { width: 100%; height: 100%; object-fit: cover; }
  .pend:has(.pend-file) { width: auto; max-width: 220px; height: auto; }
  .pend-file { display: block; padding: 8px 26px 8px 10px; font-size: 12px;
    background: var(--panel2); white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; }
  .pend button { position: absolute; top: 2px; right: 2px; width: 19px; height: 19px;
    border-radius: 50%; background: rgba(24,27,36,.6); color: #fff; font-size: 11px;
    line-height: 1; padding: 0; display: flex; align-items: center; justify-content: center; }
  .pend button:hover { background: rgba(24,27,36,.85); }
  #composer { display: flex; flex-direction: column; gap: 8px; padding: 12px 18px 14px;
    background: var(--panel); border-top: 1px solid var(--border); }
  #composer-row { display: flex; gap: 10px; align-items: flex-end; }
  #composer textarea { flex: 1; resize: none; max-height: 40vh; border-radius: 14px; }
  #send-btn { background: var(--accent); color: #fff; padding: 0 20px; display: flex;
    align-items: center; justify-content: center; align-self: stretch; border-radius: 12px; }
  #send-btn:hover { background: var(--accent-hover); }
  #send-btn svg { width: 20px; height: 20px; }
  #send-btn:disabled { opacity: .45; cursor: default; }
  #empty-state { flex: 1; display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 14px; }

  /* Модалки (новое сообщение, задача) */
  #modal-overlay, #task-overlay, #emp-overlay, #pay-overlay, #spend-overlay { display: none; position: fixed; inset: 0; background: var(--overlay);
    backdrop-filter: blur(2px); align-items: center; justify-content: center; z-index: 10; }
  #modal-overlay.open, #task-overlay.open, #emp-overlay.open, #pay-overlay.open, #spend-overlay.open { display: flex; }
  #modal, #task-modal, #emp-modal, #pay-modal, #spend-modal { background: var(--panel); border-radius: 20px; padding: 24px; width: 460px;
    max-width: 94vw; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 11px; }
  #spend-modal { width: 560px; }
  /* Плашка режима чтения (аккаунт-читатель). Отдельно от прочих модалок:
     она не форма, а объяснение — узкая карточка с иконкой и одной кнопкой. */
  #ro-overlay { display: none; position: fixed; inset: 0; background: var(--overlay);
    backdrop-filter: blur(2px); align-items: center; justify-content: center; z-index: 40; }
  #ro-overlay.open { display: flex; }
  #ro-modal { background: var(--panel); border-radius: 20px; padding: 26px 24px 20px;
    width: 380px; max-width: 92vw; box-shadow: var(--shadow); text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 10px; }
  #ro-eye { width: 46px; height: 46px; border-radius: 50%; background: var(--tint);
    color: var(--accent-ink); display: flex; align-items: center; justify-content: center; }
  #ro-eye svg { width: 24px; height: 24px; }
  #ro-modal h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
  #ro-modal p { font-size: 14px; color: var(--muted); line-height: 1.45; }
  #ro-modal p.ro-sub { font-size: 13px; }
  #ro-ok { background: var(--accent); color: #fff; padding: 10px 26px; font-weight: 600;
    border-radius: 12px; margin-top: 6px; }
  #ro-ok:hover { background: var(--accent-hover); }
  /* Метка под логином в сайдбаре — чтобы режим был виден до первого клика. */
  .ro-badge { display: inline-block; margin-top: 3px; padding: 1px 7px; border-radius: 999px;
    background: var(--tint); color: var(--accent-ink); font-size: 11px; font-weight: 600;
    white-space: nowrap; }
  #modal h2, #task-modal h2, #emp-modal h2, #pay-modal h2, #spend-modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 4px; letter-spacing: -.02em; }
  #modal label, #task-modal label, #emp-modal label, #pay-modal label, #spend-modal label { font-size: 13px; color: var(--muted); font-weight: 500; }
  #search-results { display: flex; flex-direction: column; gap: 4px; }
  .sr-item { background: var(--panel2); border-radius: 10px; padding: 9px 13px;
    cursor: pointer; font-size: 14px; }
  .sr-item:hover { background: var(--hover); }
  .sr-item.picked { background: var(--tint); box-shadow: inset 0 0 0 1.5px var(--accent); }
  .sr-sub { font-size: 12px; color: var(--muted); }
  #modal-actions, #task-actions, #emp-actions, #pay-actions, #spend-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
  #modal-send, #task-save, #emp-save, #pay-save, #spend-save { background: var(--accent); color: #fff; padding: 10px 22px; font-weight: 600;
    border-radius: 12px; }
  #modal-send:hover, #task-save:hover, #emp-save:hover, #pay-save:hover, #spend-save:hover { background: var(--accent-hover); }
  #modal-send:disabled, #task-save:disabled, #emp-save:disabled, #pay-save:disabled, #spend-save:disabled { opacity: .5; cursor: default; }
  #modal-cancel, #task-cancel, #emp-cancel, #pay-cancel, #spend-cancel { background: var(--panel2); color: var(--text); padding: 10px 18px;
    font-weight: 500; border-radius: 12px; }
  #modal-cancel:hover, #task-cancel:hover, #emp-cancel:hover, #pay-cancel:hover, #spend-cancel:hover { background: var(--hover); }
  #modal-error, #task-error, #emp-error, #pay-error, #spend-error { color: var(--danger); font-size: 13px; min-height: 16px; }
  #pay-error.ok { color: var(--accent-fg); }

  /* Задача: поиск ответственного и дедлайн (время — с клавиатуры) */
  #t-assignee-box { position: relative; }
  #t-assignee-box input { width: 100%; }
  #t-assignee-list { display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
    padding: 4px; max-height: 230px; overflow-y: auto; z-index: 12;
    flex-direction: column; gap: 2px; }
  #t-assignee-list.open { display: flex; }
  #t-assignee-list .sr-item.active { background: var(--tint); }
  #t-due-row { display: flex; gap: 8px; }
  #t-due-row #t-due-date { flex: 1; }
  #t-due-row #t-due-time { width: 92px; text-align: center; }

  /* Шапка сайдбара: поиск + фильтры */
  #sidebar-head { border-bottom: 1px solid var(--border); }
  #search-row { display: flex; gap: 8px; align-items: center; padding: 12px 14px 8px; }
  #search-box { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--panel2);
    border: 1px solid transparent; border-radius: 999px; padding: 0 12px; height: 38px;
    transition: background .15s, border-color .15s, box-shadow .15s; }
  #search-box:focus-within { background: var(--panel); border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring); }
  #search-box > svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
  #search-box input { flex: 1; border: 0; background: none; padding: 0; height: 100%; }
  #search-box input:focus { box-shadow: none; }
  #search-clear { background: none; color: var(--muted); font-size: 17px; line-height: 1;
    padding: 2px 4px; display: none; }
  #search-clear:hover { color: var(--text); }
  #search-box.has #search-clear { display: block; }
  #filter-row { display: flex; align-items: center; gap: 8px; padding: 0 14px 10px; }
  #chips { display: flex; gap: 7px; overflow-x: auto; flex: 1; scrollbar-width: none; }
  #chips::-webkit-scrollbar { display: none; }
  #filter-row #logout { flex: none; }
  .access-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--panel2); color: var(--text); border-radius: 999px; height: 34px;
    font-size: 13px; font-weight: 600; padding: 0 10px; transition: background .15s; }
  .access-btn:hover { background: var(--hover); }
  .access-btn svg { width: 15px; height: 15px; flex: none; color: var(--accent-fg); }
  /* Модалка выдачи доступа */
  #access-overlay { display: none; position: fixed; inset: 0; background: var(--overlay);
    z-index: 60; align-items: center; justify-content: center; }
  #access-overlay.open { display: flex; }
  #access-modal { background: var(--panel); border-radius: 20px; padding: 24px; width: 460px;
    max-width: calc(100vw - 32px); max-height: 90vh; display: flex; flex-direction: column; gap: 12px; }
  #access-modal h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
  #access-modal label { font-size: 13px; color: var(--muted); font-weight: 500; }
  #access-tabs { display: flex; gap: 6px; }
  #access-tabs button { background: var(--panel2); color: var(--muted); padding: 7px 14px;
    border-radius: 10px; font-size: 13px; font-weight: 600; }
  #access-tabs button:hover { background: var(--hover); color: var(--text); }
  #access-tabs button.active { background: var(--accent); color: #fff; }
  #access-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto;
    max-height: 40vh; border: 1px solid var(--border); border-radius: 12px; padding: 6px; }
  #access-list label { display: flex; align-items: center; gap: 9px; padding: 8px 8px;
    border-radius: 9px; cursor: pointer; color: var(--text); font-weight: 500; font-size: 14px; }
  #access-list label:hover { background: var(--hover); }
  #access-list input[type=checkbox] { width: 16px; height: 16px; flex: none; accent-color: var(--accent); }
  #access-empty { color: var(--muted); font-size: 13px; padding: 8px; }
  #access-error { color: var(--danger); font-size: 13px; min-height: 16px; }
  #access-error.ok { color: var(--accent-fg); }
  #access-link { display: flex; gap: 8px; align-items: center; }
  #access-link input { flex: 1; font-size: 12px; padding: 8px 10px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--panel2); color: var(--text); }
  #access-link button { background: var(--panel2); color: var(--text); padding: 8px 14px;
    border-radius: 10px; font-size: 13px; font-weight: 600; white-space: nowrap; }
  #access-link button:hover { background: var(--hover); }
  #access-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
  #access-grant { background: var(--accent); color: #fff; padding: 10px 22px; font-weight: 600; border-radius: 12px; }
  #access-grant:hover { background: var(--accent-hover); }
  #access-grant:disabled { opacity: .5; cursor: default; }
  #access-cancel { background: var(--panel2); color: var(--text); padding: 10px 18px; border-radius: 12px; }
  #access-cancel:hover { background: var(--hover); }

  /* Результаты поиска */
  #search-panel { flex: 1; overflow-y: auto; padding: 6px; display: none; }
  #search-panel.active { display: block; }
  .search-group-title { font-size: 11px; font-weight: 700; letter-spacing: .05em;
    text-transform: uppercase; color: var(--muted); padding: 12px 12px 6px; }
  .search-empty { padding: 30px 14px; text-align: center; color: var(--muted); font-size: 14px; }
  .snippet { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; }
  .snippet mark { background: rgba(63,91,217,.18); color: inherit; border-radius: 3px; padding: 0 1px; }

  /* Кнопки в шапке чата */
  #chat-actions { margin-left: auto; display: flex; gap: 8px; align-items: center;
    overflow-x: auto; scrollbar-width: none; flex: 0 1 auto; padding: 2px; }
  #chat-actions::-webkit-scrollbar { display: none; }
  #chat-titles { min-width: 0; }
  #unread-btn { background: var(--panel2); color: var(--muted); width: 36px; height: 36px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; }
  #unread-btn:hover { background: var(--hover); color: var(--text); }
  #unread-btn svg { width: 18px; height: 18px; }

  /* Что предложено ученику в кабинете (полоса под шапкой диалога, те же
     строки — в карточке воронки, поэтому оформление на классе, не на id) */
  #lms-offer-bar { display: none; flex-direction: column; gap: 3px; font-size: 13px;
    padding: 9px 16px; background: var(--panel2); border-bottom: 1px solid var(--border);
    line-height: 1.45; }
  #lms-offer-bar.on { display: flex; }
  #lms-offer-bar.off { display: none; }
  #crm-m-cabinet { display: flex; flex-direction: column; gap: 3px; line-height: 1.45; }
  .lms-lines b { color: var(--text); }
  .lms-lines .lms-sub { color: var(--muted); }
  .lms-lines .lms-quote { color: var(--muted); font-style: italic;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lms-lines .lms-warn { color: var(--danger); }
  .lms-lines .lms-tariff { color: var(--accent-fg); font-weight: 600; }

  /* Отложенные сообщения */
  #composer { position: relative; }
  #scheduled-bar { display: none; flex-direction: column; gap: 6px; }
  #scheduled-bar.has { display: flex; }
  .sched-item { display: flex; align-items: center; gap: 9px; background: var(--panel2);
    border-radius: 10px; padding: 7px 8px 7px 11px; font-size: 13px; }
  .sched-item > svg { width: 15px; height: 15px; color: var(--accent-fg); flex: none; }
  .sched-when { color: var(--accent-fg); font-weight: 600; flex: none; }
  .sched-text { color: var(--muted); flex: 1; min-width: 0; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; }
  .sched-cancel { background: none; color: var(--muted); width: 24px; height: 24px; flex: none;
    display: flex; align-items: center; justify-content: center; border-radius: 7px; }
  .sched-cancel:hover { background: var(--tint); color: var(--danger); }
  .sched-cancel svg { width: 14px; height: 14px; }
  #schedule-btn { background: var(--panel2); color: var(--muted); display: flex;
    align-items: center; justify-content: center; padding: 0 14px; align-self: stretch;
    border-radius: 12px; }
  #schedule-btn:hover { background: var(--hover); color: var(--text); }
  #schedule-btn svg { width: 19px; height: 19px; }

  /* Поповер планирования */
  #schedule-pop { display: none; position: absolute; bottom: calc(100% - 6px); left: 18px;
    z-index: 8; background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
    box-shadow: var(--shadow); padding: 14px; flex-direction: column; gap: 10px; width: 290px; }
  #schedule-pop.open { display: flex; }
  #schedule-pop label { font-size: 13px; color: var(--muted); font-weight: 500; }
  #schedule-pop .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 2px; }
  #schedule-pop button.primary { background: var(--accent); color: #fff; padding: 8px 14px;
    border-radius: 10px; font-weight: 600; }
  #schedule-pop button.primary:hover { background: var(--accent-hover); }
  #schedule-pop button.ghost { background: var(--panel2); color: var(--text); padding: 8px 12px;
    border-radius: 10px; }
  #schedule-pop button.ghost:hover { background: var(--hover); }

  /* Левый сайдбар-навигация (разделы) */
  #nav { width: 178px; min-width: 178px; background: var(--panel);
    border-right: 1px solid var(--border); display: flex; flex-direction: column;
    padding: 14px 10px 10px; }
  #nav-logo { font-weight: 800; font-size: 15.5px; letter-spacing: -.02em;
    padding: 2px 12px 14px; color: var(--accent-fg); }
  #nav-items { display: flex; flex-direction: column; gap: 3px;
    flex: 0 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: none; }
  #nav-items::-webkit-scrollbar { display: none; }
  .nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border-radius: 10px; background: none; color: var(--muted); font-weight: 500;
    font-size: 14px; text-align: left; position: relative; width: 100%; }
  .nav-item:hover { background: var(--panel2); color: var(--text); }
  .nav-item.active { background: var(--tint); color: var(--accent-ink); font-weight: 600; }
  .nav-item svg { width: 18px; height: 18px; flex: none; }
  .nav-label { flex: 1; }
  .nav-badge { background: var(--unread); color: #fff; border-radius: 999px;
    font-size: 11px; min-width: 19px; height: 19px; padding: 0 5px; display: none;
    align-items: center; justify-content: center; font-weight: 700; }
  .nav-badge.show { display: flex; }
  .nav-badge.overdue { background: var(--danger); }
  /* Раскрывающаяся группа «Аналитика»: стрелка + шторка с подразделами */
  .nav-group { display: flex; flex-direction: column; }
  .nav-chev { margin-left: auto; width: 14px !important; height: 14px !important;
    transition: transform .15s; color: var(--muted); }
  .nav-group.open .nav-chev { transform: rotate(90deg); }
  .nav-group.family > .nav-parent { color: var(--text); }
  .nav-sub { display: none; flex-direction: column; gap: 2px; margin: 2px 0 3px;
    padding-left: 16px; }
  .nav-group.open .nav-sub { display: flex; }
  .nav-sub .nav-item { padding: 8px 12px; font-size: 13px; }
  #nav-spacer { flex: 1; }
  /* Переключатель темы. Стоит отдельным пунктом внизу панели разделов, а не
     внутри #nav-user: на телефоне карточка сотрудника скрыта целиком, а тема
     нужна как раз ночью и с телефона тоже. */
  #theme-toggle { flex: none; }
  #theme-state { margin-left: auto; font-size: 11px; font-weight: 600;
    color: var(--muted); }
  #nav-user { padding: 10px 12px 4px; border-top: 1px solid var(--border);
    font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
  #nav-user-info { flex: 1; min-width: 0; }
  #nav-user-info b { display: block; color: var(--text); font-size: 13px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* CRM: канбан-доска воронки продаж */
  #crm-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #crm-view.active { display: flex; }
  #crm-head { display: flex; align-items: center; gap: 9px; padding: 12px 18px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    min-height: 62px; flex-wrap: wrap; }
  #crm-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; flex: none; }
  /* Вторая ось идёт первой строкой: с неё менеджер начинает («кого я веду
     сегодня»), а фильтр по каналу — уточнение, ему хватает своей строки. */
  #crm-state-chips { display: flex; gap: 7px; margin-left: 6px; }
  #crm-state-chips .chip .cnt { margin-left: 6px; opacity: .65;
    font-variant-numeric: tabular-nums; }
  #crm-chips { display: flex; gap: 7px; margin-left: 0; overflow-x: auto;
    scrollbar-width: none; order: 5; flex: 1 0 100%; padding-bottom: 2px; }
  #crm-chips::-webkit-scrollbar { display: none; }
  #crm-source-f, #crm-assignee-f { padding: 7px 12px; border-radius: 999px;
    font-size: 13px; color: var(--muted); border-color: transparent;
    background: var(--panel2); max-width: 180px; }
  #crm-search { border-radius: 999px; padding: 7px 14px; font-size: 13px;
    width: 170px; background: var(--panel2); border-color: transparent; }
  #crm-trash { display: none; position: fixed; left: 50%; transform: translateX(-50%);
    bottom: 26px; z-index: 40; background: var(--panel); border: 2px dashed var(--danger);
    color: var(--danger); border-radius: 14px; padding: 13px 32px; font-weight: 600;
    font-size: 14px; align-items: center; gap: 9px;
    box-shadow: 0 8px 30px rgba(0,0,0,.14); }
  #crm-trash.show { display: flex; }
  #crm-trash.drop { background: var(--danger); color: #fff; border-style: solid; }
  #crm-trash svg { width: 17px; height: 17px; }
  /* Блоки над доской CRM: «Мини-курс» (оплаты /week) и «Похоже, один
     человек» (дубли карточек) — оба из js/08-crm.js, вид общий. */
  #minicourse-block, #crm-dups-block { flex: none; display: none;
    border-bottom: 1px solid var(--border); padding: 0 18px; }
  #minicourse-block.has, #crm-dups-block.has { display: block; }
  #minicourse-head, #crm-dups-head { display: flex; align-items: center; gap: 8px;
    cursor: pointer; padding: 9px 0; font-weight: 700; font-size: 13px; }
  #minicourse-head .cnt, #crm-dups-head .cnt { background: var(--accent);
    color: #fff; border-radius: 999px; padding: 1px 7px; font-size: 11px; }
  #minicourse-head .tgl, #crm-dups-head .tgl { margin-left: auto;
    color: var(--muted); font-size: 11px; transition: transform .15s; }
  #minicourse-block.collapsed .tgl, #crm-dups-block.collapsed .tgl {
    transform: rotate(-90deg); }
  #minicourse-block.collapsed #minicourse-list,
  #crm-dups-block.collapsed #crm-dups-list { display: none; }
  #minicourse-list, #crm-dups-list { max-height: 32vh; overflow-y: auto;
    padding-bottom: 8px; }
  /* Строка пары дублей: две карточки, по чему совпало и что с этим делать. */
  .dup-row { display: flex; align-items: baseline; gap: 8px; padding: 6px 8px;
    border-radius: 8px; font-size: 13px; flex-wrap: wrap; }
  .dup-row:nth-child(odd) { background: var(--panel2); }
  .dup-row .dup-name { font-weight: 600; cursor: pointer; }
  .dup-row .dup-name:hover { text-decoration: underline; }
  .dup-row .dup-why { color: var(--muted); font-size: 12px; }
  .dup-row .dup-maybe { color: var(--muted); font-size: 12px; border: 1px solid
    var(--border2); border-radius: 5px; padding: 0 4px; }
  .dup-row .dup-acts { margin-left: auto; display: flex; gap: 6px; }
  #crm-m-dups .dup-row { font-size: 12.5px; }
  #crm-m-dups .dup-empty { color: var(--muted); font-size: 12.5px; }
  .mc-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 8px;
    border-radius: 8px; font-size: 13px; flex-wrap: wrap; }
  .mc-row:nth-child(odd) { background: var(--panel2); }
  .mc-row .mc-name { font-weight: 600; }
  .mc-row .mc-muted { color: var(--muted); font-size: 12px; }
  .mc-row .mc-err { color: var(--danger); font-size: 12px; }
  .mc-row .mc-open { margin-left: auto; }
  #crm-board { flex: 1; overflow-x: auto; overflow-y: hidden; display: flex;
    gap: 10px; padding: 14px 18px 16px; align-items: stretch; }
  .crm-col { width: 252px; min-width: 252px; display: flex; flex-direction: column;
    background: var(--panel2); border-radius: var(--radius); max-height: 100%;
    border: 2px solid transparent; transition: border-color .15s; }
  .crm-col.drop { border-color: var(--accent); }
  .crm-col-head { display: flex; align-items: center; gap: 7px; padding: 11px 13px 9px;
    font-size: 12.5px; font-weight: 700; letter-spacing: -.01em; }
  .crm-col-head i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
  .crm-col-head .cnt { margin-left: auto; color: var(--muted); font-weight: 600;
    font-size: 12px; }
  .crm-cards { flex: 1; overflow-y: auto; padding: 0 8px 10px; display: flex;
    flex-direction: column; gap: 7px; }
  .crm-empty { color: var(--muted); font-size: 12px; text-align: center;
    padding: 14px 0; }
  .crm-card { background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; padding: 10px 11px; cursor: pointer;
    box-shadow: 0 1px 1px rgba(24,27,36,.03); }
  .crm-card:hover { border-color: var(--border2); }
  .crm-card.dragging { opacity: .45; }
  .crm-card-top { display: flex; align-items: center; gap: 8px; }
  .crm-card-top .avatar { width: 30px; height: 30px; font-size: 13px; }
  .crm-name { font-weight: 600; font-size: 13.5px; flex: 1; min-width: 0;
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .crm-prev { font-size: 12px; color: var(--muted); margin-top: 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .crm-tags { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap;
    align-items: center; font-size: 10.5px; }
  .crm-tag { background: var(--panel2); color: var(--muted); border-radius: 999px;
    padding: 2px 8px; font-weight: 500; }
  .crm-tag.warn { color: var(--warn-ink); font-weight: 600; }
  .crm-tag.stale { color: var(--danger); font-weight: 600; }
  .crm-age { margin-left: auto; color: var(--muted); font-size: 11px; }
  .crm-age.warn { color: var(--warn-ink); font-weight: 700; }
  .crm-age.stale { color: var(--danger); font-weight: 700; }

  /* Кнопка этапа CRM в шапке диалога + поповер этапов */
  /* Большая текстовая кнопка «Прошёл пробный урок»: видна, когда человек
     записан на пробный, — продажник отмечает прохождение, не забывая. */
  #trial-done-btn { background: var(--accent); color: #fff; height: 38px;
    padding: 0 16px; border-radius: 10px; font-weight: 700; font-size: 14px;
    white-space: nowrap; }
  #trial-done-btn:hover { background: var(--accent-hover); }
  #trial-done-btn:disabled { opacity: .6; }
  #crm-btn { background: var(--panel2); color: var(--muted); height: 36px;
    border-radius: 999px; padding: 0 13px; font-size: 12.5px; font-weight: 600;
    display: flex; align-items: center; gap: 7px; flex: none; max-width: 210px; }
  #crm-btn:hover { background: var(--hover); color: var(--text); }
  #crm-btn.staged { color: var(--text); }
  #crm-btn i { width: 8px; height: 8px; border-radius: 50%; flex: none;
    background: var(--border2); }
  #crm-btn-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .crm-stage-item { display: flex; align-items: center; gap: 9px; }
  .crm-stage-item i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
  .crm-stage-item.cur { background: var(--tint); font-weight: 600; }

  /* Карточка CRM (модалка) */
  #crm-overlay { display: none; position: fixed; inset: 0; background: var(--overlay);
    backdrop-filter: blur(2px); align-items: center; justify-content: center; z-index: 10; }
  #crm-overlay.open { display: flex; }
  #crm-modal { background: var(--panel); border-radius: 20px; padding: 24px;
    width: 480px; max-width: 94vw; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 11px; }
  #crm-modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 0;
    letter-spacing: -.02em; }
  #crm-modal label { font-size: 13px; color: var(--muted); font-weight: 500; }
  #crm-m-history { display: flex; flex-direction: column; gap: 5px; max-height: 150px;
    overflow-y: auto; font-size: 12.5px; color: var(--muted); }
  #crm-m-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px;
    flex-wrap: wrap; align-items: center; }
  #crm-m-save { background: var(--accent); color: #fff; padding: 10px 22px;
    font-weight: 600; border-radius: 12px; }
  #crm-m-save:hover { background: var(--accent-hover); }
  #crm-m-save:disabled { opacity: .5; cursor: default; }
  #crm-m-cancel, #crm-m-open { background: var(--panel2); color: var(--text);
    padding: 10px 16px; font-weight: 500; border-radius: 12px; }
  #crm-m-cancel:hover, #crm-m-open:hover { background: var(--hover); }
  #crm-m-remove { background: none; color: var(--danger); padding: 10px 10px;
    font-weight: 500; margin-right: auto; }
  #crm-m-remove:hover { background: var(--tint); }
  #crm-m-error { color: var(--danger); font-size: 13px; min-height: 16px; }

  /* Задачи */
  #tasks-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #tasks-view.active { display: flex; }
  #tasks-head, #admin-head { display: flex; align-items: center; gap: 10px;
    padding: 12px 18px; background: var(--panel);
    border-bottom: 1px solid var(--border); min-height: 62px; }
  #tasks-head h2, #admin-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
  #tasks-chips { display: flex; gap: 7px; margin-left: 6px; overflow-x: auto;
    scrollbar-width: none; }
  #tasks-chips::-webkit-scrollbar { display: none; }
  #task-new, #emp-new { margin-left: auto; background: var(--accent); color: #fff;
    font-weight: 600; padding: 9px 16px; border-radius: 999px; font-size: 13.5px; flex: none; }
  #task-new:hover, #emp-new:hover { background: var(--accent-hover); }
  #tasks-list { flex: 1; overflow-y: auto; padding: 14px 18px 24px; display: flex;
    flex-direction: column; gap: 8px; max-width: 860px; width: 100%; margin: 0 auto; }
  .tasks-empty { padding: 44px 0; text-align: center; color: var(--muted); font-size: 14px; }
  /* Секции по датам, как в Todoist: жирная дата, приглушённый день недели */
  .t-date-head { display: flex; align-items: baseline; gap: 7px; margin: 12px 2px 2px;
    padding-bottom: 6px; border-bottom: 1px solid var(--border);
    font-size: 14px; font-weight: 700; letter-spacing: -.01em; }
  .t-date-head:first-child { margin-top: 0; }
  .t-date-head .sub { color: var(--muted); font-weight: 500; font-size: 12.5px; }
  .t-date-head .cnt { margin-left: auto; color: var(--muted); font-weight: 600;
    font-size: 12px; background: var(--panel2); border-radius: 999px; padding: 2px 9px; }
  .t-date-head.overdue, .t-date-head.overdue .sub { color: var(--danger); }
  .task { display: flex; gap: 11px; background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px 14px; align-items: flex-start;
    cursor: pointer; box-shadow: 0 1px 1px rgba(24,27,36,.03); }
  .task:hover { border-color: var(--border2); }
  .task.done { opacity: .55; }
  .task.done .t-title { text-decoration: line-through; }
  .t-check { background: none; padding: 0; width: 22px; height: 22px; flex: none;
    border-radius: 50%; border: 2px solid var(--border2); color: transparent;
    display: flex; align-items: center; justify-content: center; margin-top: 1px; }
  .t-check:hover { border-color: var(--unread); color: var(--unread); }
  .task.done .t-check { background: var(--unread); border-color: var(--unread); color: #fff; }
  .t-check svg { width: 13px; height: 13px; }
  .t-body { flex: 1; min-width: 0; }
  .t-title { font-weight: 600; font-size: 14.5px; letter-spacing: -.01em;
    overflow-wrap: break-word; }
  .t-note { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: pre-wrap;
    overflow-wrap: break-word; }
  .t-meta { display: flex; gap: 7px; margin-top: 8px; flex-wrap: wrap; align-items: center;
    font-size: 12px; color: var(--muted); }
  .t-tag { background: var(--panel2); border-radius: 999px; padding: 3px 10px; }
  .t-tag.t-due.overdue { background: var(--tint); color: var(--danger); font-weight: 600; }
  .t-tag.p1 { background: var(--warn-bg); color: var(--warn-ink); font-weight: 600; }
  .t-tag.p2 { background: var(--tint); color: var(--danger); font-weight: 600; }
  .t-note .t-open-dialog { display: inline-block; color: var(--accent-fg); font-weight: 600;
    cursor: pointer; text-decoration: none; }
  .t-note .t-open-dialog:hover { text-decoration: underline; }
  #tasks-head { flex-wrap: wrap; }
  #tasks-assignee { padding: 7px 12px; border-radius: 999px; font-size: 13px;
    color: var(--muted); border-color: transparent; background: var(--panel2);
    max-width: 190px; }
  #notify-btn { background: var(--panel2); color: var(--muted); width: 36px; height: 36px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    flex: none; }
  #notify-btn:hover { background: var(--hover); color: var(--text); }
  #notify-btn svg { width: 17px; height: 17px; }
  /* Модалка подключения ТГ-уведомлений: ссылка настоящая — iOS режет window.open */
  #notify-overlay { display: none; position: fixed; inset: 0; background: var(--overlay);
    backdrop-filter: blur(2px); align-items: center; justify-content: center; z-index: 60; }
  #notify-overlay.open { display: flex; }
  #notify-modal { background: var(--panel); border-radius: 20px; padding: 24px; width: 420px;
    max-width: 94vw; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
  #notify-modal h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
  #notify-text { font-size: 14px; line-height: 1.5; }
  #notify-link { display: block; text-align: center; background: var(--accent); color: #fff;
    padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 15px;
    text-decoration: none; }
  #notify-hint { color: var(--muted); font-size: 12px; }
  #notify-url { font-size: 12px; word-break: break-all; background: var(--panel2);
    border-radius: 10px; padding: 8px 10px; user-select: all; }
  #notify-actions { display: flex; gap: 8px; justify-content: flex-end; }
  #notify-actions button { padding: 9px 14px; border-radius: 10px; background: var(--panel2);
    font-size: 14px; }
  #notify-actions button:hover { background: var(--hover); }
  /* Комментарии в модалке задачи */
  #t-comments { display: none; flex-direction: column; gap: 8px;
    border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px; }
  #t-comments.show { display: flex; }
  #tc-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px;
    overflow-y: auto; }
  .tc-item { background: var(--panel2); border-radius: 10px; padding: 8px 11px;
    font-size: 13px; white-space: pre-wrap; overflow-wrap: break-word; }
  .tc-meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
  #tc-row { display: flex; gap: 8px; }
  #tc-input { flex: 1; min-width: 0; }
  #tc-send { background: var(--panel2); color: var(--muted); padding: 0 14px;
    border-radius: 10px; font-size: 13px; flex: none; }
  #tc-send:hover { background: var(--hover); color: var(--text); }
  .t-conv { color: #fff; border-radius: 999px; padding: 3px 10px; }
  .t-conv:hover { opacity: .85; }
  .t-del { background: none; color: var(--muted); width: 26px; height: 26px; flex: none;
    border-radius: 7px; display: none; align-items: center; justify-content: center; }
  .task:hover .t-del { display: flex; }
  .t-del:hover { background: var(--tint); color: var(--danger); }
  .t-del svg { width: 15px; height: 15px; }
  #task-from-chat, #pay-btn, #cats-btn, #trial-btn, #paylink-btn, #star-btn,
  #snooze-btn { background: var(--panel2); color: var(--muted); width: 36px; height: 36px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; }
  #task-from-chat:hover, #pay-btn:hover, #cats-btn:hover, #trial-btn:hover, #paylink-btn:hover, #star-btn:hover,
  #snooze-btn:hover { background: var(--hover); color: var(--text); }
  #task-from-chat svg, #pay-btn svg, #cats-btn svg, #trial-btn svg, #paylink-btn svg, #star-btn svg,
  #snooze-btn svg { width: 18px; height: 18px; }
  /* Отложенный диалог: кнопка подсвечена, как звезда у избранного. */
  #snooze-btn.snoozed { color: var(--accent-fg); }
  #snooze-btn.snoozed svg { fill: rgba(63,91,217,.15); }
  /* Выдача доступа к пробному — текстовая мини-кнопка «trial» (не звезда:
     звёздочка теперь занята «избранным»). */
  #trial-btn { width: auto; padding: 0 11px; font-size: 11px; font-weight: 800;
    letter-spacing: .06em; text-transform: uppercase; }
  /* Звёздочка «избранного»: активная — залита золотым. */
  #star-btn.starred { color: var(--gold); }
  #star-btn.starred svg { fill: var(--gold); stroke: var(--gold); }
  .star-mark { color: var(--gold); font-size: 12px; flex: none; margin-left: 4px; }
  /* --- HRM: дерево структуры компании (чистый CSS, без библиотек) --- */
  /* Доска с зумом/панорамой как у Miro-доски скриптов: колесо — зум к курсору,
     тащить фон — панорама, кнопки +/−/вписать/100%. */
  #hrm-tools { display: flex; align-items: center; gap: 6px; padding: 6px 12px;
    background: var(--panel); border-bottom: 1px solid var(--border); }
  #hrm-tools button { background: var(--panel2); color: var(--text); width: 30px;
    height: 28px; border-radius: 8px; font-size: 15px; flex: none; }
  #hrm-tools button:hover { background: var(--hover); }
  #hrm-100 { width: auto !important; padding: 0 9px; font-size: 12px !important; }
  #hrm-hint { color: var(--muted); font-size: 12px; margin-left: 8px; }
  #hrm-viewport { flex: 1; overflow: hidden; position: relative; cursor: grab;
    touch-action: none; background: var(--bg) radial-gradient(circle,
      var(--border) 1px, transparent 1px) 0 0 / 26px 26px; }
  #hrm-viewport.panning { cursor: grabbing; }
  #hrm-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0;
    padding: 44px 60px 70px; width: max-content; --hrm-line: var(--tree-line); }
  .hrm-tree { display: flex; justify-content: center; min-width: max-content; }
  .hrm-tree ul { display: flex; justify-content: center; list-style: none;
    margin: 0; padding: 26px 0 0; position: relative; }
  /* Вертикальный отвод вниз от родителя к горизонтальной шине детей. */
  .hrm-tree ul::before { content: ""; position: absolute; top: 0; left: 50%;
    width: 0; height: 26px; border-left: 2px solid var(--hrm-line); }
  .hrm-tree > ul { padding-top: 0; }
  .hrm-tree > ul::before { display: none; }
  .hrm-tree li { display: flex; flex-direction: column; align-items: center;
    position: relative; padding: 26px 7px 0; }
  .hrm-tree > ul > li { padding-top: 0; }
  /* Горизонтальная шина + спуск к каждому ребёнку. */
  .hrm-tree li::before, .hrm-tree li::after { content: ""; position: absolute;
    top: 0; right: 50%; width: 50%; height: 26px;
    border-top: 2px solid var(--hrm-line); }
  .hrm-tree li::after { right: auto; left: 50%;
    border-left: 2px solid var(--hrm-line); }
  .hrm-tree li:only-child::before, .hrm-tree li:only-child::after { display: none; }
  .hrm-tree li:only-child { padding-top: 26px; }
  .hrm-tree > ul > li:only-child { padding-top: 0; }
  .hrm-tree li:first-child::before, .hrm-tree li:last-child::after { border-top: 0; }
  .hrm-tree li:last-child::before { border-right: 2px solid var(--hrm-line);
    border-radius: 0 8px 0 0; }
  .hrm-tree li:first-child::after { border-radius: 8px 0 0 0; }
  .hrm-tree li:only-child { position: relative; }
  .hrm-tree li:only-child:not(:first-child)::before { display: none; }
  .hrm-node { background: var(--panel); border: 1.5px solid var(--border);
    border-radius: 12px; padding: 10px 14px; cursor: pointer; text-align: center;
    min-width: 108px; max-width: 172px; font-size: 13px; font-weight: 600;
    color: var(--text); line-height: 1.25; box-shadow: 0 1px 4px rgba(24,27,36,.05);
    transition: border-color .12s, box-shadow .12s; position: relative; z-index: 1; }
  .hrm-node:hover { border-color: var(--accent);
    box-shadow: 0 4px 14px rgba(24,27,36,.1); }
  .hrm-node.dept { background: var(--tint); border-color: transparent;
    color: var(--accent-ink); text-transform: uppercase; font-size: 11.5px;
    letter-spacing: .05em; font-weight: 800; }
  .hrm-node.dept:hover { border-color: var(--accent); }
  /* Цветовое кодирование отделов: dept-узлы — свой цвет, роли внутри ветки —
     цветная полоска слева, чтобы взгляд сразу находил нужный отдел. */
  .hrm-c0 { --dept: var(--hrm-0); } .hrm-c1 { --dept: var(--hrm-1); }
  .hrm-c2 { --dept: var(--hrm-2); } .hrm-c3 { --dept: var(--hrm-3); }
  .hrm-c4 { --dept: var(--hrm-4); } .hrm-c5 { --dept: var(--hrm-5); }
  .hrm-c0.dept, .hrm-c1.dept, .hrm-c2.dept,
  .hrm-c3.dept, .hrm-c4.dept, .hrm-c5.dept { color: var(--dept);
    background: color-mix(in srgb, var(--dept) 11%, transparent); }
  .hrm-node.hrm-c0:not(.dept), .hrm-node.hrm-c1:not(.dept),
  .hrm-node.hrm-c2:not(.dept), .hrm-node.hrm-c3:not(.dept),
  .hrm-node.hrm-c4:not(.dept), .hrm-node.hrm-c5:not(.dept) {
    border-left: 4px solid var(--dept); }
  .hrm-node .hrm-sub { display: block; font-size: 10.5px; font-weight: 600;
    color: var(--muted); text-transform: none; letter-spacing: 0; margin-top: 2px; }
  /* Верхняя пара: CEO + second-in-command справа, пунктирная связка. */
  .hrm-pair { display: flex; align-items: center; }
  .hrm-dash { width: 26px; border-top: 2px dashed var(--hrm-line); flex: none; }
  .hrm-node.hrm-ceo { border-color: var(--accent); min-width: 130px; }
  /* Модалка карточки роли */
  #hrm-back { display: none; position: fixed; inset: 0; z-index: 80;
    background: var(--overlay); backdrop-filter: blur(2px);
    align-items: center; justify-content: center; }
  #hrm-back.open { display: flex; }
  #hrm-modal { background: var(--panel); border-radius: 16px; padding: 22px 24px;
    width: min(400px, 92vw); box-shadow: 0 18px 48px rgba(24,27,36,.24); }
  #hrm-modal h3 { font-size: 16px; font-weight: 800; margin-bottom: 2px; }
  #hrm-m-dept { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
  .hrm-m-row { display: flex; gap: 10px; margin-top: 10px; font-size: 13.5px; }
  .hrm-m-row b { flex: none; width: 86px; color: var(--muted); font-weight: 600; }
  .hrm-m-row a { color: var(--accent-fg); }
  .hrm-m-empty { color: var(--muted); font-style: italic; }
  #hrm-m-topics { white-space: pre-line; }
  #hrm-m-close { margin-top: 18px; width: 100%; background: var(--panel2);
    color: var(--text); padding: 9px; border-radius: 10px; font-weight: 600; }
  #hrm-m-close:hover { background: var(--hover); }
  #crm-pop, #snooze-pop { display: none; position: absolute; top: 62px; right: 16px;
    z-index: 6;
    background: var(--panel); border-radius: 14px; padding: 6px; min-width: 230px;
    box-shadow: 0 10px 32px rgba(24,27,36,.16); }
  #crm-pop.open, #snooze-pop.open { display: block; }
  #crm-pop { max-height: 70vh; overflow-y: auto; }
  /* Пояснение над списком сроков и метка текущего состояния диалога. */
  .pop-hint { padding: 8px 12px 6px; font-size: 12px; color: var(--muted);
    line-height: 1.4; }
  .pop-sep { height: 1px; background: var(--border); margin: 6px 8px; }
  .snooze-mark { color: var(--muted); }
  .conv-empty { padding: 22px 18px; color: var(--muted); font-size: 13px;
    line-height: 1.5; }
  /* Своя дата в «отложить»: узкая строка под пресетами. */
  .snooze-date { display: flex; gap: 6px; padding: 6px 8px 4px; }
  .snooze-date input { flex: 1; min-width: 0; background: var(--panel2);
    border: 1px solid var(--border); border-radius: 8px; padding: 7px 8px;
    color: var(--text); font: inherit; font-size: 13px; }
  .snooze-date button { padding: 0 12px; border-radius: 8px;
    background: var(--accent); color: #fff; font-size: 13px; }
  .act-item { display: block; width: 100%; text-align: left; padding: 10px 12px;
    border-radius: 10px; font-size: 14px; color: var(--text); }
  .act-item:hover { background: var(--hover); }
  .act-item:disabled { color: var(--muted); cursor: default; }
  #cats-pop { display: none; position: absolute; top: 62px; right: 16px; z-index: 6;
    background: var(--panel); border-radius: 14px; padding: 14px 16px; max-width: 340px;
    box-shadow: 0 10px 32px rgba(24,27,36,.16); font-size: 13px; }
  #cats-pop.open { display: block; }
  #cats-pop b { font-size: 13px; }
  .cat-pill { background: var(--panel2); border-radius: 8px; padding: 3px 9px;
    font-size: 12px; display: inline-block; margin: 2px 3px 2px 0; }
  .cats-date { color: var(--muted); font-size: 11px; margin-top: 8px; }
  #t-conv-info { display: none; align-items: center; gap: 7px; font-size: 13px;
    color: var(--muted); background: var(--panel2); border-radius: 10px; padding: 8px 11px; }
  #t-conv-info.show { display: flex; }

  /* Админка: сотрудники */
  #admin-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #admin-view.active { display: flex; }
  #emp-list { flex: 1; overflow-y: auto; padding: 14px 18px 24px; display: flex;
    flex-direction: column; gap: 8px; max-width: 860px; width: 100%; margin: 0 auto; }
  .emp { background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 13px 15px; display: flex; gap: 12px;
    align-items: flex-start; box-shadow: 0 1px 1px rgba(24,27,36,.03); }
  .emp.inactive { opacity: .5; }
  .emp-body { flex: 1; min-width: 0; }
  .emp-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .emp-login { font-weight: 700; font-size: 14.5px; }
  .emp-role { background: var(--panel2); border-radius: 999px; padding: 3px 10px;
    font-size: 12px; color: var(--muted); }
  .emp-admin { background: var(--accent); color: #fff; border-radius: 999px;
    padding: 3px 10px; font-size: 11px; font-weight: 600; }
  .emp-off { background: var(--panel2); color: var(--danger); border-radius: 999px;
    padding: 3px 10px; font-size: 11px; font-weight: 600; }
  .emp-perms { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.65; }
  .emp-actions { display: flex; gap: 6px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
  .emp-actions button { background: var(--panel2); color: var(--muted); font-size: 12.5px;
    padding: 7px 12px; border-radius: 8px; font-weight: 500; }
  .emp-actions button:hover { background: var(--hover); color: var(--text); }

  /* Чекбокс-таблетки в модалке сотрудника */
  .ck-group { display: flex; flex-wrap: wrap; gap: 6px; }
  /* Групповые права в модалке сотрудника: роли — чекбоксами, люди — поиском */
  .grant-box { display: flex; flex-direction: column; gap: 7px; }
  .grant-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .grant-chip { display: inline-flex; align-items: center; gap: 6px;
    background: var(--tint); color: var(--text); border-radius: 999px;
    padding: 4px 6px 4px 11px; font-size: 13px; font-weight: 500; }
  .grant-chip button { background: none; color: var(--muted); padding: 0 4px;
    font-size: 12px; line-height: 1; }
  .grant-chip button:hover { color: var(--danger); }
  .grant-search { position: relative; }
  .grant-search input { width: 100%; }
  .grant-dd { display: none; position: absolute; top: calc(100% + 4px); left: 0;
    right: 0; background: var(--panel); border-radius: 12px;
    box-shadow: var(--shadow); padding: 4px; max-height: 210px; overflow-y: auto;
    z-index: 12; flex-direction: column; gap: 2px; }
  .grant-dd.open { display: flex; }
  .ck { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2);
    border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer;
    user-select: none; }
  .ck input { accent-color: var(--accent); margin: 0; }
  .ck.on { background: var(--tint); color: var(--accent-ink); font-weight: 500; }
  #pay-plan, #pay-source-type { display: flex; gap: 14px; font-size: 13.5px; padding: 4px 0; flex-wrap: wrap; }
  #pay-plan label, #pay-source-type label { display: inline-flex; align-items: center; gap: 6px;
    margin: 0; color: var(--text); font-weight: 500; font-size: 13.5px; cursor: pointer; }
  /* Источник трафика: поле с подсказками (как поиск ответственного в задаче) */
  #pay-source-box { position: relative; }
  #pay-source-box input { width: 100%; }
  #pay-source-list { display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
    padding: 4px; max-height: 230px; overflow-y: auto; z-index: 12;
    flex-direction: column; gap: 2px; }
  #pay-source-list.open { display: flex; }
  #pay-source-list .sr-item.active { background: var(--tint); }
  #pay-source-list .src-close { position: sticky; top: -4px; margin: -4px -4px 2px;
    padding: 8px 12px; background: var(--panel); color: var(--muted); font-size: 12.5px;
    cursor: pointer; border-bottom: 1px solid var(--border); border-radius: 12px 12px 0 0;
    display: flex; justify-content: space-between; align-items: center; flex: none; }
  #pay-source-list .src-close:hover { color: var(--text); }
  #pay-source-btns { display: flex; gap: 8px; }
  #emp-pass-row { display: flex; gap: 8px; }
  #emp-pass-row input { flex: 1; }
  #emp-gen { background: var(--panel2); color: var(--muted); padding: 0 14px;
    border-radius: 10px; font-size: 13px; }
  #emp-gen:hover { background: var(--hover); color: var(--text); }

  /* Аналитика: воронка по источникам + динамика */
  #analytics-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #analytics-view.active { display: flex; }
  #an-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px;
    background: var(--panel); border-bottom: 1px solid var(--border); min-height: 62px; }
  #an-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; flex: none; }
  #an-chips { display: flex; gap: 7px; margin-left: 6px; overflow-x: auto;
    scrollbar-width: none; }
  #an-chips::-webkit-scrollbar { display: none; }
  #an-spend-btn { margin-left: auto; background: var(--panel2); color: var(--text);
    font-weight: 600; padding: 9px 16px; border-radius: 999px; font-size: 13.5px; flex: none; }
  #an-spend-btn:hover { background: var(--hover); }
  /* Карточки-списки «Общей»: описание + кнопка, сам список — в модалке */
  .an-listcard { display: flex; align-items: center; gap: 16px; }
  .an-listcard-text { flex: 1; min-width: 0; }
  .an-listcard .an-empty { padding: 0; }
  .an-open-btn { flex: none; background: var(--panel2); color: var(--text);
    font-weight: 600; padding: 10px 18px; border-radius: 999px; font-size: 13.5px; }
  .an-open-btn:hover { background: var(--hover); }
  .an-open-btn:disabled { opacity: .5; cursor: default; }
  #anlist-overlay { display: none; position: fixed; inset: 0;
    background: var(--overlay); backdrop-filter: blur(2px);
    align-items: center; justify-content: center; z-index: 30; }
  #anlist-overlay.open { display: flex; }
  #anlist-modal { background: var(--panel); border-radius: 20px; padding: 22px;
    width: 860px; max-width: 94vw; max-height: 88vh; display: flex;
    flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
  #anlist-head { display: flex; align-items: center; gap: 10px; }
  #anlist-head h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; flex: 1; }
  #anlist-close { background: var(--panel2); color: var(--muted); width: 32px;
    height: 32px; border-radius: 50%; font-size: 15px; flex: none; }
  #anlist-close:hover { background: var(--hover); color: var(--text); }
  #anlist-note { font-size: 12.5px; color: var(--muted); }
  #anlist-body { overflow: auto; min-height: 0; }
  #anlist-body table { width: 100%; }
  /* Списки людей — не числовая таблица: всё влево и с переносами, иначе
     nowrap + right-align у .pay-table уносят колонку чипов за край модалки. */
  #anlist-body .pay-table { white-space: normal; }
  #anlist-body .pay-table th, #anlist-body .pay-table td { text-align: left; }
  #anlist-body .pay-table td { overflow-wrap: anywhere; }
  #anlist-body .pay-table td:nth-child(2) { white-space: nowrap; }
  .an-dlg { display: inline-block; color: #fff; border-radius: 999px;
    padding: 3px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
    margin: 1px 4px 1px 0; white-space: nowrap; }
  .an-dlg:hover { filter: brightness(.92); }
  :root[data-theme="dark"] .an-dlg:hover { filter: brightness(1.14); }
  #an-scroll { flex: 1; overflow-y: auto; padding: 16px 18px 28px; }
  #an-inner { max-width: 1080px; width: 100%; margin: 0 auto; display: flex;
    flex-direction: column; gap: 14px; }
  #an-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px; }
  .an-tile { background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px 15px 13px;
    box-shadow: 0 1px 1px rgba(24,27,36,.03); }
  .an-tile .k { font-size: 12.5px; color: var(--muted); font-weight: 500; }
  .an-tile .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 3px; }
  .an-tile .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
  /* Кликабельная плитка (цикл сделки): акцентная рамка + стрелка в углу,
     на ховере приподнимается — видно, что это кнопка, а не просто цифра. */
  .an-tile-link { cursor: pointer; position: relative;
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
    transition: box-shadow .15s ease, transform .15s ease, border-color .15s; }
  .an-tile-link::after { content: "↗"; position: absolute; top: 7px; right: 11px;
    color: var(--accent-fg); font-size: 14px; font-weight: 700; }
  .an-tile-link:hover { border-color: var(--accent); transform: translateY(-1px);
    box-shadow: 0 3px 12px color-mix(in srgb, var(--accent) 22%, transparent); }
  .an-card { background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 15px 17px;
    box-shadow: 0 1px 1px rgba(24,27,36,.03); }
  .an-card h3 { font-size: 14.5px; font-weight: 700; letter-spacing: -.01em;
    margin-bottom: 11px; }
  #an-table-wrap { overflow-x: auto; }
  #an-table { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
  #an-table th { text-align: right; color: var(--muted); font-weight: 600;
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    padding: 6px 10px; border-bottom: 1px solid var(--border2); }
  #an-table th:first-child, #an-table td:first-child { text-align: left; }
  #an-table td { padding: 8px 10px; text-align: right; vertical-align: top;
    border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
  #an-table tbody tr:last-child td { border-bottom: 0; }
  #an-table td .cv { display: block; font-size: 11px; color: var(--muted); }
  #an-table tr.total td { font-weight: 700; border-top: 2px solid var(--border2); }
  #an-table .src-name { font-weight: 600; }
  /* Разбивка источника: блогер и кампания раскрываются кликом по строке. */
  #an-table tr.an-src { cursor: pointer; }
  #an-table tr.an-src:hover td { background: var(--hover, rgba(0,0,0,.03)); }
  #an-table tr.an-sub td { color: var(--muted); }
  #an-table tr.an-sub .src-name { font-weight: 500; }
  #an-table .an-caret { display: inline-block; width: 14px; color: var(--muted); }
  #an-table .an-plat { font-size: 11px; color: var(--muted); border: 1px solid var(--border2);
    border-radius: 6px; padding: 0 5px; margin-left: 6px; }
  /* Этап, который воронка обычно ставит сама: помечен «авто», но кликабелен. */
  .crm-auto-mark { font-size: 10px; color: var(--muted); margin-left: 6px;
    border: 1px solid var(--border2); border-radius: 5px; padding: 0 4px; }
  /* Пометка «карточка переехала на новый этап» в списке диалогов. */
  .stage-mark { font-size: 10.5px; color: #fff; border-radius: 6px;
    padding: 1px 6px; margin-left: 6px; white-space: nowrap; flex: none; }
  .roi-pos { color: var(--pos); }
  .roi-neg { color: var(--danger); }
  .an-empty { color: var(--muted); font-size: 13.5px; padding: 8px 0; }
  #an-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px;
    margin-bottom: 10px; }
  .an-key { display: inline-flex; align-items: center; gap: 7px; color: var(--text); }
  .an-key i { width: 15px; height: 0; border-top: 2.5px solid; border-radius: 2px; }
  #an-chart-box { position: relative; }
  #an-chart { display: block; width: 100%; }
  #an-tip { position: absolute; display: none; background: var(--panel);
    border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
    padding: 8px 11px; font-size: 12px; pointer-events: none; z-index: 5;
    min-width: 160px; }
  #an-tip .tt-date { font-weight: 700; margin-bottom: 4px; }
  #an-tip .tt-row { display: flex; align-items: center; gap: 7px; margin-top: 3px;
    color: var(--muted); }
  #an-tip .tt-row i { width: 11px; height: 0; border-top: 2.5px solid;
    border-radius: 2px; flex: none; }
  #an-tip .tt-row b { margin-left: auto; color: var(--text);
    font-variant-numeric: tabular-nums; }
  /* Разделы аналитики по оплатам: Финансы / Маркетинг / Продукт */
  .pay-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  .pay-view.active { display: flex; }
  .pay-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px;
    background: var(--panel); border-bottom: 1px solid var(--border); min-height: 62px; }
  .pay-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; flex: none; }
  .pay-chips { display: flex; gap: 7px; margin-left: 6px; overflow-x: auto;
    scrollbar-width: none; }
  .pay-chips::-webkit-scrollbar { display: none; }
  .pay-scroll { flex: 1; overflow-y: auto; padding: 16px 18px 28px; }
  .pay-inner { max-width: 1080px; width: 100%; margin: 0 auto; display: flex;
    flex-direction: column; gap: 14px; }
  .pay-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px; }
  .pay-table-wrap { overflow-x: auto; }
  .pay-table { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
  .pay-table th { text-align: right; color: var(--muted); font-weight: 600;
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    padding: 6px 10px; border-bottom: 1px solid var(--border2); }
  .pay-table th:first-child, .pay-table td:first-child { text-align: left; }
  .pay-table td { padding: 8px 10px; text-align: right; vertical-align: top;
    border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
  .pay-table tbody tr:last-child td { border-bottom: 0; }
  .pay-table tr.total td { font-weight: 700; border-top: 2px solid var(--border2); }
  .pay-table .src-name { font-weight: 600; }
  .pay-table td .cv { display: block; font-size: 11px; color: var(--muted); }
  .pay-note { font-size: 12px; color: var(--muted); margin-top: 9px; }
  .pay-chart-box { position: relative; }
  .pay-chart-box svg { display: block; width: 100%; }
  /* Горизонтальные бары (источники, тарифы): magnitude одной меры — один тон */
  .hbar { display: grid; grid-template-columns: minmax(90px, 170px) 1fr auto;
    gap: 7px 10px; align-items: center; font-size: 13px; }
  .hbar .hb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-weight: 600; }
  .hbar .hb-label .hb-sub { display: block; font-size: 11px; color: var(--muted);
    font-weight: 500; }
  .hbar .hb-track { background: var(--panel2); border-radius: 4px; height: 18px;
    position: relative; }
  .hbar .hb-fill { position: absolute; top: 0; bottom: 0; left: 0;
    background: var(--bar); border-radius: 4px; min-width: 2px; }
  .hbar .hb-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
  .hbar .hb-val .cv { display: block; font-size: 11px; color: var(--muted);
    text-align: right; }
  .delta-pos { color: var(--pos); }
  .delta-neg { color: var(--danger); }
  /* Ученики */
  #pupils-search { border-radius: 999px; padding: 7px 14px; font-size: 13px;
    width: 240px; background: var(--panel2); border-color: transparent;
    margin-left: auto; }
  .pay-table td.pup-prog { white-space: normal; min-width: 210px;
    font-size: 12px; text-align: left; }
  .pup-prog-row { padding: 1px 0; color: var(--muted); }
  .pup-prog-row b { color: var(--text); }
  .pup-prog-row.pf-hit b { color: var(--ok-ink); }
  /* Фильтры раздела «Ученики» */
  #pupils-filters { display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
    padding: 9px 18px; background: var(--panel); border-bottom: 1px solid var(--border); }
  .pf-group { display: flex; align-items: center; gap: 6px; font-size: 13px; }
  .pf-label { color: var(--muted); font-size: 12.5px; }
  .fin-pending td { opacity: .62; }
  .fin-badge { background: var(--gold-bg); color: var(--gold-ink); border-radius: 999px;
    padding: 1px 8px; font-size: 11px; white-space: nowrap; }
  /* Продажник: прочерк у строк, где его неоткуда взять (импорт, оплата с сайта) */
  .fin-noseller { color: var(--muted); cursor: help; }
  .fin-sellers { margin-top: 16px; }
  .fin-sellers h4 { margin: 0 0 7px; font-size: 13px; color: var(--muted);
    font-weight: 600; }
  #pf-courses { display: inline-flex; gap: 10px; flex-wrap: wrap; }
  #pf-courses label { display: inline-flex; align-items: center; gap: 4px;
    color: var(--text); cursor: pointer; white-space: nowrap; }
  #pf-prog-range { width: 150px; accent-color: var(--accent); }
  /* Инлайн-правка консультаций */
  .pc-edit { background: none; color: var(--muted); font-size: 12px; padding: 0 3px;
    cursor: pointer; }
  .pc-edit:hover { color: var(--accent-fg); }
  .pc-form { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
  .pc-form input { width: 52px; padding: 3px 6px; border-radius: 7px;
    background: var(--panel2); border: 1px solid var(--border); }
  .pc-form button { background: var(--panel2); border-radius: 7px; padding: 3px 7px; }
  .pc-form button:hover { background: var(--hover); }
  /* Раздел «Скрипты»: доска Miro и инструкции во весь размер */
  #scripts-body { flex: 1; display: flex; min-height: 0; }
  #scripts-body .an-empty { margin: 40px auto; }
  /* Своя доска Miro */
  #mboard { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #mb-tools { display: flex; align-items: center; gap: 6px; padding: 6px 12px;
    background: var(--panel); border-bottom: 1px solid var(--border); }
  #mb-tools button { background: var(--panel2); color: var(--text); width: 30px;
    height: 28px; border-radius: 8px; font-size: 15px; }
  #mb-tools button:hover { background: var(--hover); }
  #mb-hint { color: var(--muted); font-size: 12px; margin-left: 8px; }
  #mb-status { color: var(--muted); font-size: 12px; margin-left: auto; }
  /* Холст доски остаётся светлым в любой теме: стили блоков приходят от Miro
     в расчёте на светлую канву, на тёмной они нечитаемы. Ночью гасим саму
     канву на пару тонов — блоки при этом не трогаем. */
  #mb-viewport { flex: 1; overflow: hidden; position: relative; cursor: grab;
    touch-action: none; background: var(--mb-bg) radial-gradient(circle,
      var(--mb-dot) 1px, transparent 1px) 0 0 / 26px 26px; color: #1a1a1a; }
  #mb-viewport.panning { cursor: grabbing; }
  #mb-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
  .mb-item { position: absolute; box-sizing: border-box; cursor: pointer;
    line-height: 1.35; font-family: inherit; user-select: text; }
  .mb-item:hover { outline: 4px solid var(--accent); outline-offset: 3px; }
  .mb-item .mb-txt { cursor: text; }
  .mb-item ::selection { background: #b5d4ff; }
  .mb-shape { display: flex; align-items: center; overflow: hidden; padding: 10px; }
  .mb-shape .mb-txt { width: 100%; }
  .mb-txt p { margin: 0 0 .5em; }
  .mb-txt p:last-child { margin-bottom: 0; }
  .mb-img img { width: 100%; height: 100%; object-fit: contain; }
  .mb-copied { outline: 4px solid #35976b !important; }
  #mb-toast { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
    background: var(--accent); color: #fff; padding: 8px 16px; border-radius: 999px;
    font-size: 13px; display: none; z-index: 5; }
  #scripts-open { color: var(--muted); font-size: 13px; }
  #scripts-open:hover { color: var(--accent-fg); }
  #scripts-doc { flex: 1; }
  .scr-sec-head { display: flex; align-items: center; gap: 8px; cursor: pointer;
    user-select: none; }
  .scr-sec-head h3 { flex: 1; margin: 0; }
  .scr-caret { color: var(--muted); font-size: 12px; width: 14px; flex: none; }
  .scr-sec-btns { display: flex; gap: 2px; }
  .scr-sec-btns button { background: none; color: var(--muted); padding: 2px 6px; }
  .scr-sec-btns button:hover { color: var(--accent-fg); }
  .scr-sec .scr-body { display: none; white-space: pre-wrap; margin-top: 10px;
    font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
  .scr-quote { background: var(--panel2); border-radius: 6px; padding: 1px 3px; }
  .scr-copy, .scr-copy-all { background: none; color: var(--muted); padding: 0 4px;
    font-size: 13px; cursor: pointer; }
  .scr-copy:hover, .scr-copy-all:hover { color: var(--accent-fg); }
  .scr-sec.open .scr-body { display: block; }
  .scr-form input, .scr-form textarea { width: 100%; background: var(--panel2);
    border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
    font: inherit; }
  .scr-form textarea { min-height: 320px; margin-top: 8px; resize: vertical;
    line-height: 1.5; }
  .scr-actions { margin-top: 8px; display: flex; gap: 8px; }
  #scr-add { align-self: flex-start; }
  /* Контент-план: таблица месяца с инлайн-редактированием */
  #cp-month-nav { display: flex; align-items: center; gap: 4px; }
  #cp-month-nav input { padding: 7px 10px; border-radius: 10px; font-size: 13.5px;
    background: var(--panel2); border-color: transparent; }
  #cp-prev, #cp-next { background: var(--panel2); color: var(--muted); width: 32px;
    height: 34px; border-radius: 10px; font-size: 17px; }
  #cp-prev:hover, #cp-next:hover { background: var(--hover); color: var(--text); }
  #cp-new { margin-left: auto; background: var(--accent); color: #fff;
    font-weight: 600; padding: 9px 16px; border-radius: 999px; font-size: 13.5px; flex: none; }
  #cp-scroll { flex: 1; overflow: auto; padding: 14px 18px 24px; }
  #cp-table { border-collapse: collapse; width: 100%; font-size: 13px; }
  #cp-table th { text-align: left; color: var(--muted); font-weight: 600;
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    padding: 6px 8px; border-bottom: 1px solid var(--border2); white-space: nowrap;
    position: sticky; top: -14px; background: var(--bg); z-index: 2; }
  #cp-table td { padding: 3px 4px; border-bottom: 1px solid var(--border);
    vertical-align: middle; }
  #cp-table input, #cp-table select { width: 100%; border: 1px solid transparent;
    background: none; border-radius: 8px; padding: 6px 7px; font-size: 13px;
    min-width: 0; }
  #cp-table input:hover, #cp-table select:hover { background: var(--panel2); }
  #cp-table input:focus, #cp-table select:focus { background: var(--panel);
    border-color: var(--accent); outline: none; }
  #cp-table input[type="date"] { min-width: 128px; }
  /* Пустая дата — без шумного «дд.мм.гггг»: только иконка календаря.
     В фокусе текст возвращается, чтобы дату можно было набрать руками. */
  #cp-table input[type="date"].empty:not(:focus) { color: transparent;
    width: 36px; min-width: 36px; }
  #cp-table input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: .55; cursor: pointer; }
  /* Дедлайн дизайна: дата + время в одной ячейке, не переносить. */
  #cp-table td.cp-c-ddue { white-space: nowrap; }
  #cp-table td.cp-c-ddue input[type="date"]:not(.empty) { width: 128px; }
  #cp-table input.cp-due-time { width: 80px; min-width: 0; }
  #cp-table input.cp-due-time.empty:not(:focus) { opacity: .45; }
  #cp-table .cp-num { width: 52px; text-align: center; }
  #cp-table td.cp-c-num { width: 56px; }
  #cp-table td.cp-c-title { min-width: 230px; }
  #cp-table td.cp-c-title input { font-weight: 600; }
  #cp-table td.cp-c-rubric { min-width: 152px; }  /* «Преподаватель» целиком */
  #cp-table td.cp-c-format { min-width: 120px; }
  #cp-table td.cp-c-brief { width: 44px; text-align: center; }
  #cp-table td.cp-c-author { min-width: 118px; }
  #cp-table td.cp-c-dformat { min-width: 130px; }
  .cp-status { display: flex; align-items: center; gap: 6px; min-width: 172px; }
  .cp-status i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
  .cp-del { background: none; color: var(--muted); width: 28px; height: 28px;
    border-radius: 8px; display: flex; align-items: center; justify-content: center; }
  .cp-del:hover { background: var(--tint); color: var(--danger); }
  .cp-del svg { width: 14px; height: 14px; }
  .cp-task-dot { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
  #cp-empty { color: var(--muted); font-size: 13.5px; padding: 20px 4px; }
  #cp-table td.cp-c-drag { width: 22px; padding: 3px 0; }
  .cp-grip { cursor: grab; color: var(--muted); font-size: 12px; letter-spacing: -1px;
    padding: 4px 3px; user-select: none; display: inline-block; }
  .cp-grip:hover { color: var(--text); }
  #cp-table tr.dragging { opacity: .4; }
  #cp-table tr.drop-above td { border-top: 2px solid var(--accent); }
  #cp-table tr.drop-below td { border-bottom: 2px solid var(--accent); }
  .cp-title-wrap { display: flex; align-items: center; gap: 2px; }
  .cp-body-btn { background: none; color: var(--muted); width: 26px; height: 26px; flex: none;
    border-radius: 7px; display: flex; align-items: center; justify-content: center; }
  .cp-body-btn:hover { background: var(--hover); color: var(--text); }
  .cp-body-btn.has { color: var(--accent-fg); }
  .cp-body-btn svg { width: 15px; height: 15px; }
  #cp-body-overlay { display: none; position: fixed; inset: 0; background: var(--overlay);
    backdrop-filter: blur(2px); z-index: 70; align-items: center; justify-content: center; }
  #cp-body-overlay.open { display: flex; }
  #cp-body-modal { background: var(--panel); border-radius: 20px; width: min(940px, 95vw);
    height: min(92vh, 920px); display: flex; flex-direction: column; padding: 20px 24px 22px;
    gap: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.18); }
  #cp-body-head { display: flex; align-items: center; gap: 12px; }
  #cp-body-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; flex: 1;
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #cp-body-status { font-size: 12.5px; color: var(--muted); flex: none; }
  #cp-body-close { background: var(--panel2); color: var(--muted); width: 34px; height: 34px;
    border-radius: 10px; font-size: 20px; line-height: 1; flex: none; }
  #cp-body-close:hover { background: var(--hover); color: var(--text); }
  #cp-body-text { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 14px;
    padding: 18px 22px; font: inherit; font-size: 15px; line-height: 1.65;
    background: var(--panel); color: var(--text); }
  #cp-body-text:focus { outline: none; border-color: var(--accent); }
  /* Ads: UTM-ссылки с отслеживанием переходов */
  #ads-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #ads-view.active { display: flex; }
  #ads-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px;
    background: var(--panel); border-bottom: 1px solid var(--border); min-height: 62px; }
  #ads-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; flex: none; }
  #ads-new { margin-left: auto; background: var(--accent); color: #fff;
    font-weight: 600; padding: 9px 16px; border-radius: 999px; font-size: 13.5px; flex: none; }
  #ads-scroll { flex: 1; overflow-y: auto; padding: 16px 18px 28px; }
  #ads-inner { max-width: 1080px; width: 100%; margin: 0 auto; display: flex;
    flex-direction: column; gap: 14px; }
  #ads-form-card label { display: block; font-size: 12.5px; color: var(--muted);
    font-weight: 600; margin: 10px 0 4px; }
  #ads-form-card input { width: 100%; }
  #ads-utm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0 12px; }
  #ads-target { display: flex; gap: 14px; font-size: 13.5px; padding: 4px 0; }
  #ads-target label { display: inline-flex; align-items: center; gap: 6px;
    margin: 0; color: var(--text); font-weight: 500; font-size: 13.5px; cursor: pointer; }
  #ads-error { color: var(--danger); font-size: 12.5px; min-height: 16px; margin-top: 8px; }
  #ads-form-actions { display: flex; gap: 8px; justify-content: flex-end; }
  #ads-table-wrap { overflow-x: auto; }
  #ads-table { border-collapse: collapse; width: 100%; font-size: 13px; }
  #ads-table th { text-align: left; color: var(--muted); font-weight: 600;
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    padding: 6px 10px; border-bottom: 1px solid var(--border2); white-space: nowrap; }
  #ads-table td { padding: 9px 10px; border-bottom: 1px solid var(--border);
    vertical-align: top; font-variant-numeric: tabular-nums; }
  #ads-table tbody tr:last-child td { border-bottom: 0; }
  #ads-table .ads-title { font-weight: 600; }
  #ads-table .ads-dest { display: block; font-size: 11.5px; color: var(--muted);
    max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #ads-table .ads-short { font-family: ui-monospace, monospace; font-size: 12px;
    white-space: nowrap; }
  #ads-table .ads-num { text-align: right; white-space: nowrap; }
  #ads-table th.ads-num { text-align: right; }
  .ads-copy { background: var(--panel2); color: var(--muted); border-radius: 8px;
    padding: 3px 9px; font-size: 12px; margin-left: 6px; }
  .ads-copy:hover { background: var(--hover); color: var(--text); }

  /* Рассылки: email-кампании, цепочки, контакты (фаза 4 EMAIL_SYSTEM_PLAN.md) */
  #email-view, #email-contacts-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #email-view.active, #email-contacts-view.active { display: flex; }
  /* --- Квиз: ответы респондентов, воронка, выгрузка --- */
  #quiz-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #quiz-view.active { display: flex; }
  #quiz-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px;
    background: var(--panel); border-bottom: 1px solid var(--border); min-height: 62px; }
  #quiz-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; flex: none; }
  #quiz-head select { background: var(--panel2); color: var(--text);
    border: 1px solid var(--border); border-radius: 999px; padding: 7px 12px;
    font-size: 13px; }
  #quiz-open { margin-left: auto; color: var(--muted); font-size: 13px;
    text-decoration: none; }
  #quiz-open:hover { color: var(--text); }
  #quiz-csv { background: var(--accent); color: #fff; font-weight: 600;
    padding: 9px 16px; border-radius: 999px; font-size: 13.5px; flex: none; }
  #quiz-scroll { flex: 1; overflow-y: auto; padding: 16px 18px 28px; }
  #quiz-inner { display: flex; flex-direction: column; gap: 14px; max-width: 1180px; }
  .qz-tiles { display: grid; gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .qz-tile { background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 13px 15px; }
  .qz-tile b { display: block; font-size: 24px; font-weight: 700;
    letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
  .qz-tile span { display: block; color: var(--muted); font-size: 12.5px; margin-top: 3px; }
  .qz-tile i { font-style: normal; color: var(--accent-fg); font-size: 12.5px; font-weight: 600; }
  .qz-q { background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px; }
  .qz-q h4 { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
  .qz-q-meta { color: var(--muted); font-size: 12px; margin-bottom: 11px; }
  .qz-bar { display: grid; grid-template-columns: 1fr 58px; gap: 10px;
    align-items: center; margin-bottom: 7px; font-size: 13px; }
  .qz-bar-label { position: relative; padding: 5px 9px; border-radius: 8px;
    background: var(--panel2); overflow: hidden; }
  .qz-bar-label i { position: absolute; inset: 0 auto 0 0; display: block;
    background: color-mix(in srgb, var(--accent) 22%, transparent); }
  .qz-bar-label span { position: relative; }
  .qz-bar-num { text-align: right; color: var(--muted); font-size: 12.5px;
    font-variant-numeric: tabular-nums; }
  #quiz-sessions { overflow-x: auto; }
  #quiz-sessions table { border-collapse: collapse; width: 100%; font-size: 13px; }
  #quiz-sessions th { text-align: left; color: var(--muted); font-weight: 600;
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    padding: 6px 10px; border-bottom: 1px solid var(--border2); white-space: nowrap; }
  #quiz-sessions td { padding: 8px 10px; border-bottom: 1px solid var(--border);
    vertical-align: top; }
  /* --- Соцсети (кросспостинг): список постов + карточка площадок --- */
  #social-view { flex: 1; display: none; flex-direction: column; min-height: 0; }
  #social-view.active { display: flex; }
  .soc-chips { display: flex; flex-wrap: wrap; gap: 8px; }
  .soc-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px;
    border-radius: 999px; font-size: 12.5px; border: 1px solid var(--border2);
    background: var(--panel2, transparent); }
  .soc-chip.on { border-color: var(--ok); color: var(--ok); }
  .soc-chip.off { border-color: var(--border2); color: var(--muted); }
  .soc-post { display: grid; grid-template-columns: 1fr auto; gap: 8px;
    padding: 11px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
  .soc-post:hover { background: var(--hover, rgba(127,127,127,.06)); }
  .soc-post b { font-size: 14px; }
  .soc-post .soc-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px;
    display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .soc-badges { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
  .soc-b { font-size: 11px; padding: 2px 7px; border-radius: 999px;
    border: 1px solid var(--border2); color: var(--muted); white-space: nowrap; }
  .soc-b.done { border-color: var(--ok); color: var(--ok); }
  .soc-b.fail { border-color: var(--err); color: var(--err); }
  .soc-b.wait { border-color: var(--warn); color: var(--warn); }
  .soc-modal { position: fixed; inset: 0; background: var(--overlay); z-index: 60;
    display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px;
    overflow-y: auto; }
  .soc-modal-box { background: var(--panel); border-radius: 14px; width: 100%;
    max-width: 940px; border: 1px solid var(--border); }
  .soc-modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px;
    border-bottom: 1px solid var(--border); position: sticky; top: 0;
    background: var(--panel); border-radius: 14px 14px 0 0; z-index: 2; }
  .soc-modal-body { padding: 16px 18px 22px; display: flex; flex-direction: column; gap: 14px; }
  .soc-tgt { border: 1px solid var(--border2); border-radius: 12px; padding: 12px 13px; }
  .soc-tgt-head { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
  .soc-tgt-head b { font-size: 14px; }
  .soc-prev { white-space: pre-wrap; font-size: 13px; line-height: 1.55;
    background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
    padding: 10px 11px; max-height: 260px; overflow-y: auto; }
  .soc-issue { font-size: 12.5px; margin-top: 6px; }
  .soc-issue.error { color: var(--err); }
  .soc-issue.warn { color: var(--warn); }
  .soc-issue.info { color: var(--muted); }
  .soc-set { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
    gap: 9px 14px; margin-top: 10px; }
  .soc-set label { font-size: 12px; color: var(--muted); display: block; }
  .soc-set input[type=text], .soc-set select { width: 100%; }
  .soc-set .soc-bool { display: flex; align-items: center; gap: 7px; font-size: 13px;
    color: var(--text); margin-top: 14px; }
  .soc-hint { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
  .soc-thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
  .soc-thumbs figure { position: relative; }
  .soc-thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px;
    border: 1px solid var(--border2); }
  .soc-thumbs button { position: absolute; top: -6px; right: -6px; border-radius: 999px;
    width: 22px; height: 22px; padding: 0; line-height: 1; }
  /* Уведомления раздела: плашка вместо браузерного alert() */
  #soc-toasts { position: fixed; right: 18px; bottom: 18px; z-index: 90;
    display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
  .soc-toast { background: var(--panel); border: 1px solid var(--border);
    border-left: 3px solid var(--accent); border-radius: 10px; padding: 11px 13px;
    font-size: 13px; line-height: 1.5; box-shadow: 0 8px 26px rgba(0,0,0,.22);
    white-space: pre-line; animation: socIn .15s ease-out; }
  .soc-toast.err { border-left-color: var(--err); }
  .soc-toast.ok { border-left-color: var(--ok); }
  .soc-toast a { color: var(--accent-fg); }
  .soc-toast button { float: right; margin: -4px -4px 0 8px; padding: 0 6px;
    background: none; color: var(--muted); font-size: 15px; line-height: 1.2; }
  @keyframes socIn { from { opacity: 0; transform: translateY(6px); } }
  .em-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px;
    background: var(--panel); border-bottom: 1px solid var(--border); min-height: 62px; }
  .em-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; flex: none; }
  .primary-pill { background: var(--accent); color: #fff; font-weight: 600;
    padding: 9px 16px; border-radius: 999px; font-size: 13.5px; flex: none; }
  .em-scroll { flex: 1; overflow-y: auto; padding: 16px 18px 28px; }
  .em-inner { max-width: 1080px; width: 100%; margin: 0 auto; display: flex;
    flex-direction: column; gap: 14px; }
  .em-table-wrap { overflow-x: auto; }
  .em-table { border-collapse: collapse; width: 100%; font-size: 13px; }
  .em-table th { text-align: left; color: var(--muted); font-weight: 600;
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    padding: 6px 10px; border-bottom: 1px solid var(--border2); white-space: nowrap; }
  .em-table td { padding: 9px 10px; border-bottom: 1px solid var(--border);
    vertical-align: top; font-variant-numeric: tabular-nums; }
  .em-table tbody tr:last-child td { border-bottom: 0; }
  .em-num { text-align: right; white-space: nowrap; }
  th.em-num { text-align: right; }
  .em-sub { display: block; font-size: 11.5px; color: var(--muted); }
  .em-badge { display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; background: var(--panel2); color: var(--muted); }
  .em-badge.sending { background: var(--tint); color: var(--accent-ink); }
  .em-badge.paused, .em-badge.failed { background: var(--panel2); color: var(--danger); }
  .em-tag { display: inline-block; background: var(--panel2); border-radius: 999px;
    padding: 2px 9px; font-size: 11.5px; margin: 0 4px 4px 0; cursor: pointer; border: 0; }
  .em-tag.active { background: var(--tint); color: var(--accent-ink); font-weight: 600; }
  .em-mini { background: var(--panel2); color: var(--muted); border-radius: 8px;
    padding: 4px 10px; font-size: 12px; flex: none; }
  .em-mini:hover { background: var(--hover); color: var(--text); }
  .em-form label { display: block; font-size: 12.5px; color: var(--muted);
    font-weight: 600; margin: 10px 0 4px; }
  .em-form input, .em-form select { width: 100%; }
  .em-form textarea { width: 100%; min-height: 180px; resize: vertical;
    border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
    font-size: 13px; line-height: 1.5; background: var(--panel); color: var(--text);
    font-family: ui-monospace, monospace; }
  .em-form textarea:focus { outline: none; border-color: var(--accent); }
  .em-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0 12px; }
  .em-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
  .em-error { color: var(--danger); font-size: 12.5px; min-height: 16px; margin-top: 8px; }
  .em-error.ok { color: var(--accent-fg); }
  .em-error.warn { color: var(--warn-ink); line-height: 1.5; }
  .em-stats { display: flex; flex-wrap: wrap; gap: 10px; }
  .em-stat { background: var(--panel2); border-radius: 14px; padding: 10px 16px;
    min-width: 92px; }
  .em-stat b { display: block; font-size: 19px; letter-spacing: -.02em; }
  .em-stat span { font-size: 11.5px; color: var(--muted); }
  .em-step { border: 1px solid var(--border); border-radius: 14px;
    padding: 12px 14px; margin-bottom: 10px; }
  .em-step-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .em-step-head b { font-size: 14px; }
  .em-warn-card { background: var(--tint); border-radius: 14px; padding: 12px 16px;
    font-size: 13px; }

  /* Ссылки на оплату (CRM): каталог позиций + разовые ссылки из диалогов */
  #plp-new { margin-left: auto; background: var(--accent); color: #fff;
    font-weight: 600; padding: 9px 16px; border-radius: 999px; font-size: 13.5px;
    flex: none; }
  #plp-form-actions .primary { background: var(--accent); color: #fff; }
  #plp-form-actions .primary:hover { background: var(--accent-hover); }
  #plp-form-actions .ghost { background: var(--panel2); }
  #plp-form-actions .ghost:hover { background: var(--hover); }
  #crmpay-scroll { flex: 1; overflow-y: auto; padding: 14px 18px; }
  #crmpay-inner { max-width: 1060px; display: flex; flex-direction: column; gap: 14px; }
  .fin-pays-head { display: flex; align-items: center; justify-content: space-between;
    gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
  .fin-pays-head h3 { margin-bottom: 0; }
  .fin-month-nav { display: flex; align-items: center; gap: 6px; }
  .fin-month-nav button { background: var(--panel2); color: var(--muted);
    width: 30px; height: 30px; border-radius: 8px; font-size: 17px; line-height: 1; }
  .fin-month-nav button:hover { background: var(--hover); color: var(--text); }
  .fin-month-nav input { padding: 5px 9px; font-size: 13px; width: auto; }
  /* Правка платежа: карандаш в строке + модалка; удаление — крестик рядом */
  .pe-edit, .pe-del { background: none; color: var(--muted); padding: 2px 7px;
    font-size: 13px; border-radius: 8px; }
  .pe-edit:hover { background: var(--hover); color: var(--text); }
  .pe-del:hover { background: var(--hover); color: var(--danger); }
  #payedit-overlay { display: none; position: fixed; inset: 0; background: var(--overlay);
    backdrop-filter: blur(2px); z-index: 60; align-items: center; justify-content: center; }
  #payedit-overlay.open { display: flex; }
  #payedit-modal { background: var(--panel); border-radius: 20px; padding: 24px; width: 420px;
    max-width: 94vw; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 11px; }
  #payedit-modal h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
  #payedit-modal label { font-size: 13px; color: var(--muted); font-weight: 500; }
  #payedit-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
  #payedit-save { background: var(--accent); color: #fff; padding: 10px 22px;
    font-weight: 600; border-radius: 12px; }
  #payedit-save:hover { background: var(--accent-hover); }
  #payedit-save:disabled { opacity: .5; cursor: default; }
  #payedit-cancel { background: var(--panel2); color: var(--text); padding: 10px 18px;
    font-weight: 500; border-radius: 12px; }
  #payedit-cancel:hover { background: var(--hover); }
  #payedit-error { color: var(--danger); font-size: 13px; min-height: 16px; }
  .pl-table { border-collapse: collapse; width: 100%; font-size: 13px; }
  .pl-table th { text-align: left; color: var(--muted); font-weight: 600;
    padding: 6px 10px; border-bottom: 1px solid var(--border2); white-space: nowrap; }
  .pl-table td { padding: 9px 10px; border-bottom: 1px solid var(--border);
    vertical-align: top; }
  .pl-table tbody tr:last-child td { border-bottom: 0; }
  .pl-table .pl-title { font-weight: 600; }
  .pl-table .pl-sub { display: block; font-size: 11.5px; color: var(--muted); }
  .pl-num { text-align: right; white-space: nowrap; }
  .pl-inactive td { opacity: .45; }
  .pl-badge { display: inline-block; font-size: 11px; font-weight: 600;
    border-radius: 7px; padding: 2px 7px; background: var(--panel2);
    color: var(--muted); }
  .pl-badge.paid { background: var(--ok-bg); color: var(--ok-ink); }
  .pl-badge.expired { background: var(--danger-bg); color: var(--danger); }
  /* Счёт висит дольше двух недель — сделка остывает, видно без вчитывания. */
  .pl-stale { color: var(--danger); font-weight: 600; }
  #plw-count:empty { display: none; }
  #plw-count { margin-left: 8px; }
  #plp-form-card label { display: block; font-size: 13px; color: var(--muted);
    font-weight: 500; margin: 10px 0 4px; }
  #plp-form-card input { width: 100%; }
  #plp-form-actions { display: flex; gap: 10px; justify-content: flex-end;
    margin-top: 12px; }
  #plp-error { color: var(--danger); font-size: 13px; min-height: 16px; }

  /* Очередь «Оплаты на разбор» + модалка зачисления */
  #paq-count { margin-left: 8px; }
  #paq-count:empty { display: none; }
  .paq-reason { color: var(--danger); font-size: 12px; display: block; }
  #payq-overlay { display: none; position: fixed; inset: 0;
    background: var(--overlay); z-index: 60; align-items: center;
    justify-content: center; }
  #payq-overlay.open { display: flex; }
  #payq-modal { background: var(--panel); border-radius: 20px; padding: 24px;
    width: 460px; max-width: calc(100vw - 40px); max-height: 86vh;
    overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
  #payq-modal h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
  #payq-modal label { font-size: 13px; color: var(--muted); font-weight: 500; }
  #payq-modal input { width: 100%; }
  #payq-plan { display: flex; gap: 14px; font-size: 14px; }
  #payq-error { color: var(--danger); font-size: 13px; min-height: 16px; }
  #payq-error.ok { color: var(--accent-fg); }
  #payq-actions { display: flex; gap: 10px; justify-content: flex-end;
    margin-top: 4px; }
  #payq-save { background: var(--accent); color: #fff; padding: 10px 22px;
    font-weight: 600; border-radius: 12px; }
  #payq-save:hover { background: var(--accent-hover); }
  #payq-save:disabled, #payq-ignore:disabled { opacity: .5; cursor: default; }
  #payq-cancel, #payq-ignore { background: var(--panel2); color: var(--text);
    padding: 10px 18px; border-radius: 12px; }

  /* Модалка «Ссылка на оплату» в диалоге */
  #paylink-overlay { display: none; position: fixed; inset: 0;
    background: var(--overlay); z-index: 60; align-items: center;
    justify-content: center; }
  #paylink-overlay.open { display: flex; }
  #paylink-modal { background: var(--panel); border-radius: 20px; padding: 24px;
    width: 480px; max-width: calc(100vw - 40px); max-height: 86vh;
    overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
  #paylink-modal h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
  #paylink-modal label { font-size: 13px; color: var(--muted); font-weight: 500; }
  #pl-provider { display: flex; gap: 14px; font-size: 14px; }
  #pl-provider label { color: var(--text); display: flex; align-items: center; gap: 6px; }
  #pl-result { display: none; background: var(--panel2); border-radius: 12px;
    padding: 10px 12px; font-size: 13px; word-break: break-all; }
  #pl-result.show { display: block; }
  #pl-result .row { display: flex; gap: 8px; margin-top: 8px; word-break: normal; }
  #pl-error { color: var(--danger); font-size: 13px; min-height: 16px; }
  #pl-error.ok { color: var(--accent-fg); }
  #pl-history { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px;
    max-height: 180px; overflow-y: auto; }
  #pl-history .pl-hrow { display: flex; align-items: center; gap: 8px;
    background: var(--panel2); border-radius: 10px; padding: 7px 10px; }
  #pl-history .pl-hrow .grow { flex: 1; min-width: 0; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
  #pl-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
  #pl-create { background: var(--accent); color: #fff; padding: 10px 22px;
    font-weight: 600; border-radius: 12px; }
  #pl-create:hover { background: var(--accent-hover); }
  #pl-create:disabled { opacity: .5; cursor: default; }
  #pl-cancel { background: var(--panel2); color: var(--text); padding: 10px 18px;
    border-radius: 12px; }
  #pl-cancel:hover { background: var(--hover); }
  tr.ads-archived td { opacity: .45; }
  .ads-starts-row td { background: var(--panel2); font-size: 12.5px; }
  .ads-starts-row td > div { padding: 3px 0; }
  /* Модалка расходов */
  #sp-rows { display: flex; flex-direction: column; gap: 7px; }
  .sp-row { display: flex; gap: 8px; align-items: center; }
  .sp-row .sp-src { width: 130px; flex: none; font-size: 13.5px; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sp-row .sp-amt { width: 130px; flex: none; text-align: right; }
  .sp-row .sp-note { flex: 1; min-width: 0; }
  #sp-add-row { display: flex; gap: 8px; margin-top: 2px; }
  #sp-add-src { flex: 1; }
  #sp-add-btn { background: var(--panel2); color: var(--muted); padding: 0 16px;
    border-radius: 10px; font-size: 13px; }
  #sp-add-btn:hover { background: var(--hover); color: var(--text); }

  /* Подсказка к доскам для пальцев: включается только на сенсорных экранах */
  .hint-touch { display: none; }


  /* --- Внутренние рассрочки: конструктор графика и раздел CRM --- */
  /* Вкладки режима — те же, что в модалке выдачи доступа (#access-tabs):
     один способ переключать режим во всём интерфейсе. */
  #pay-kind-tabs, #instnew-tabs { display: flex; gap: 6px; }
  #pay-kind-tabs button, #instnew-tabs button { background: var(--panel2);
    color: var(--muted); padding: 7px 14px; border-radius: 10px; font-size: 13px;
    font-weight: 600; }
  #pay-kind-tabs button:hover, #instnew-tabs button:hover { background: var(--hover);
    color: var(--text); }
  #pay-kind-tabs button.active, #instnew-tabs button.active { background: var(--accent);
    color: #fff; }
  .pay-hint { color: var(--muted); font-weight: 400; }
  /* Блок полей рассрочки внутри окна оплаты: своя подложка, чтобы было видно,
     где кончается общий состав покупки и начинается график. */
  #pay-inst-box { display: none; flex-direction: column; gap: 8px;
    background: var(--panel2); border-radius: 14px; padding: 12px 13px; }
  #pay-inst-box label { font-size: 13px; color: var(--muted); font-weight: 500; }
  #pay-inst-box input[type=date] { width: 100%; }
  .inst-chips { display: flex; flex-wrap: wrap; gap: 6px; }
  .inst-chip { background: var(--panel); color: var(--text);
    border: 1px solid var(--border2); padding: 7px 12px; border-radius: 10px;
    font-size: 13px; font-weight: 600; }
  .inst-chip:hover { border-color: var(--accent); }
  .inst-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
  /* Срок, не делящийся на выбранную частоту: приглушён, но кликабелен —
     нажатие подберёт подходящую частоту и объяснит, что поменялось. */
  .inst-chip.off { opacity: .45; }
  .inst-preview { background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; padding: 10px 12px; font-size: 13px; }
  .inst-sum { font-weight: 700; margin-bottom: 6px; }
  .inst-note-line { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
  .inst-rows { display: flex; flex-direction: column; gap: 3px; }
  /* Строки превью — только внутри .inst-rows: класс .inst-row носят и строки
     таблицы рассрочек (<tr>), а флекс на <tr> схлопывает ячейки в столбик. */
  .inst-rows .inst-row { display: flex; align-items: center; gap: 10px; }
  .inst-rows .inst-row .inst-seq { color: var(--muted); width: 30px; flex: none; }
  .inst-rows .inst-row .inst-when { flex: 1; }
  .inst-rows .inst-row .inst-when.past { color: var(--danger); }
  .inst-rows .inst-row .inst-amt { font-weight: 600;
    font-variant-numeric: tabular-nums; }
  .inst-paid { display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
    color: var(--muted); cursor: pointer; margin: 0; }
  .inst-paid input { accent-color: var(--accent); margin: 0; }
  .inst-warn { color: var(--danger); }
  .inst-empty { color: var(--muted); }
  .inst-hint { color: var(--muted); font-size: 12.5px; line-height: 1.45; }

  /* Раздел CRM → «Рассрочки» */
  #inst-search { flex: 1; max-width: 240px; }
  #inst-new { background: var(--accent); color: #fff; padding: 9px 16px;
    font-weight: 600; border-radius: 10px; margin-left: auto; flex: none; }
  #inst-new:hover { background: var(--accent-hover); }
  #inst-count:empty { display: none; }
  #inst-count { margin-left: 8px; }
  .an-tile.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
  .an-tile.danger .v { color: var(--danger); }
  .chip.danger { color: var(--danger); }
  .chip.danger.active { background: var(--danger); color: #fff; }
  /* Колонки фиксированной ширины: иначе «HSK 1 + HSK 2 + HSK 3» рвётся по
     слову в узкий столбик, а раскрытая карточка распирает таблицу вбок. */
  #inst-table-wrap { overflow-x: auto; }
  .inst-table { table-layout: fixed; min-width: 880px; }
  .inst-table th:nth-child(1), .inst-table td:nth-child(1) { width: 19%; }
  .inst-table th:nth-child(2), .inst-table td:nth-child(2) { width: 23%; }
  .inst-table th:nth-child(3), .inst-table td:nth-child(3) { width: 17%; }
  .inst-table th:nth-child(4), .inst-table td:nth-child(4) { width: 18%; }
  .inst-table th:nth-child(5), .inst-table td:nth-child(5) { width: 13%; }
  .inst-table th:nth-child(6), .inst-table td:nth-child(6) { width: 10%; }
  .inst-table td { overflow-wrap: anywhere; }
  .inst-table tbody tr.inst-row { cursor: pointer; }
  .inst-table tbody tr.inst-row:hover { background: var(--panel2); }
  .inst-table tbody tr.inst-row.open td { border-bottom: 0; }
  /* Полоса внесённого: доля денег, а не платежей — «2 из 3» рядом текстом. */
  .inst-bar { background: var(--panel2); border-radius: 999px; height: 6px;
    width: 130px; max-width: 100%; overflow: hidden; margin-bottom: 4px; }
  .inst-bar i { display: block; height: 100%; background: var(--accent);
    border-radius: 999px; }
  .inst-details-row td { background: var(--panel2); padding: 12px 10px; }
  .inst-details { display: flex; gap: 16px; flex-wrap: wrap; }
  .inst-sch { flex: 1 1 430px; display: flex; flex-direction: column; gap: 4px; }
  .inst-sch-row { display: flex; align-items: center; gap: 10px; background: var(--panel);
    border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px;
    font-size: 13px; }
  /* Ближайший неоплаченный платёж — тот, о котором говорить с клиентом. */
  .inst-sch-row.next { border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent); }
  .inst-sch-row.done { opacity: .8; }
  .inst-sch-row .inst-when { flex: none; width: 92px; }
  .inst-sch-row .inst-amt { flex: none; width: 92px; }
  .inst-sch-row .inst-st { flex: 1; min-width: 120px; }
  .inst-sch-row .inst-act { margin-left: auto; }
  .inst-side { flex: 1 1 250px; display: flex; flex-direction: column; gap: 5px; }
  .inst-side select, .inst-side input { width: 100%; }
  .inst-lbl { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 6px; }
  .inst-side-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
  .inst-del:hover { background: var(--danger-bg); color: var(--danger); }
  .pl-badge.soon { background: var(--warn-bg); color: var(--warn-ink); }

  /* Модалки рассрочки: та же геометрия, что у окна оплаты */
  #instnew-overlay, #instpay-overlay { display: none; position: fixed; inset: 0;
    background: var(--overlay); backdrop-filter: blur(2px);
    align-items: center; justify-content: center; z-index: 11; }
  #instnew-overlay.open, #instpay-overlay.open { display: flex; }
  #instnew-modal, #instpay-modal { background: var(--panel); border-radius: 20px;
    padding: 24px; width: 480px; max-width: 94vw; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 11px; }
  #instnew-modal h2, #instpay-modal h2 { font-size: 18px; font-weight: 700;
    margin-bottom: 4px; letter-spacing: -.02em; }
  #instnew-modal label, #instpay-modal label { font-size: 13px; color: var(--muted);
    font-weight: 500; }
  #instnew-modal input, #instnew-modal select, #instpay-modal input { width: 100%; }
  #instnew-modal input[type=checkbox], #instnew-modal input[type=radio],
  #instpay-modal input[type=checkbox] { width: auto; flex: none; }
  #instnew-plan { display: flex; gap: 14px; font-size: 13.5px; padding: 4px 0;
    flex-wrap: wrap; }
  #instnew-plan label { display: inline-flex; align-items: center; gap: 6px; margin: 0;
    color: var(--text); font-weight: 500; font-size: 13.5px; cursor: pointer; }
  #instnew-actions, #instpay-actions { display: flex; gap: 10px;
    justify-content: flex-end; margin-top: 8px; }
  #instnew-save, #instpay-save { background: var(--accent); color: #fff;
    padding: 10px 22px; font-weight: 600; border-radius: 12px; }
  #instnew-save:hover, #instpay-save:hover { background: var(--accent-hover); }
  #instnew-save:disabled, #instpay-save:disabled { opacity: .5; cursor: default; }
  #instnew-cancel, #instpay-cancel { background: var(--panel2); color: var(--text);
    padding: 10px 18px; font-weight: 500; border-radius: 12px; }
  #instnew-cancel:hover, #instpay-cancel:hover { background: var(--hover); }
  #instnew-error, #instpay-error { color: var(--danger); font-size: 13px;
    min-height: 16px; }
  #instnew-error.ok, #instpay-error.ok { color: var(--accent-fg); }

  @media (max-width: 720px) {
    #app { flex-direction: column; }
    /* Нижняя панель разделов. Пунктов много (до 15 с раскрытыми группами) —
       поэтому ряд горизонтально скроллится, а не сжимается в нечитаемую кашу:
       у каждого пункта есть минимальная ширина под палец. */
    #nav { order: 3; width: 100%; min-width: 0; flex: none; flex-direction: row; border-right: 0;
      border-top: 1px solid var(--border); align-items: stretch;
      padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
      overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
      overscroll-behavior-x: contain; }
    #nav::-webkit-scrollbar { display: none; }
    #nav-logo, #nav-spacer, #nav-user { display: none; }
    #theme-state { display: none; }
    /* Тема прилипает к правому краю панели: ряд разделов длинный, а ночью
       кнопка нужна сразу, без пролистывания до конца. */
    #theme-toggle { position: sticky; right: 0; flex: none; width: 64px;
      background: var(--panel); box-shadow: -10px 0 10px -4px var(--panel); }
    #nav-items { flex-direction: row; flex: 1 0 auto; gap: 0;
      overflow: visible; }   /* ряд прокручивает сам #nav */
    .nav-item { flex-direction: column; gap: 2px; font-size: 10px; padding: 7px 4px;
      flex: 1 0 64px; min-width: 64px; align-items: center; justify-content: center;
      border-radius: 8px; line-height: 1.15; }
    .nav-item svg { width: 20px; height: 20px; }
    .nav-label { flex: none; text-align: center; }
    /* Подразделы аналитики: тап по «Аналитике» раскрывает их прямо в нижней панели */
    .nav-group { display: contents; }
    .nav-chev { display: none; }
    .nav-sub { display: none; }
    .nav-group.open .nav-sub { display: contents; }
    .nav-sub .nav-item { padding: 7px 4px; font-size: 10px; }
    .nav-badge { position: absolute; top: 1px; right: calc(50% - 21px); }
    #sidebar { width: 100%; flex: 1; min-height: 0; }
    #main { flex: 1; min-height: 0; }
    #app[data-view="dialogs"].chat-open #sidebar { display: none !important; }
    #app[data-view="dialogs"]:not(.chat-open) #main { display: none !important; }
    #back-btn { display: block; }

    /* --- Общее: поля ввода 16px, иначе iOS зумит страницу при фокусе --- */
    input:not([type=checkbox]):not([type=radio]):not([type=range]),
    select, textarea { font-size: 16px !important; }
    /* Списки не должны тянуть за собой pull-to-refresh соседнего экрана */
    #conv-list, #messages, #search-panel, .pay-scroll, #an-scroll, #ads-scroll,
    #cp-scroll, #crmpay-scroll, #tasks-list, #emp-list, #crm-board {
      overscroll-behavior: contain; }
    /* Таблицы шире экрана — их обёртки скроллятся пальцем */
    .pay-table-wrap, #an-table-wrap, #ads-table-wrap, #plp-table-wrap,
    #pll-table-wrap, #tpay-table-wrap, #cp-table-wrap, #anlist-body {
      -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }

    /* --- Логин --- */
    #login-form { width: 100%; max-width: 360px; margin: 0 16px; padding: 26px 20px; }

    /* --- Шапки разделов: переносятся в 2 строки вместо обрезки --- */
    #tasks-head, #admin-head, #ads-head, #an-head, #crm-head, .pay-head,
    #pupils-filters { flex-wrap: wrap; gap: 8px; padding: 9px 12px; min-height: 0; }
    #tasks-head h2, #admin-head h2, #ads-head h2, #an-head h2, #crm-head h2,
    .pay-head h2 { font-size: 16px; }
    #an-chips, .pay-chips, #crm-chips, #tasks-chips { margin-left: 0; order: 5;
      flex: 1 0 100%; padding-bottom: 2px; }
    #crm-search, #pupils-search { width: 100%; margin-left: 0; order: 6; }
    #tasks-assignee, #crm-source-f, #crm-assignee-f { max-width: none; flex: 1 1 130px; }
    #cp-month-nav { flex: 1 1 auto; }
    #cp-month-nav input { flex: 1; min-width: 0; }
    #pf-prog-range { flex: 1; width: auto; min-width: 120px; }
    .pf-group { flex-wrap: wrap; }

    /* --- Контент разделов: поля уже, плитки мельче --- */
    .pay-scroll, #an-scroll, #ads-scroll, #crmpay-scroll { padding: 12px 10px 24px; }
    #cp-scroll { padding: 12px 10px 20px; }
    #tasks-list, #emp-list { padding: 12px 10px 20px; }
    .an-card { padding: 13px 12px; }
    .an-card h3 { font-size: 14px; }
    #an-tiles, .pay-tiles { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
      gap: 8px; }
    .an-tile { padding: 10px 12px 11px; }
    .an-tile .v { font-size: 19px; }
    .an-listcard { flex-direction: column; align-items: stretch; gap: 12px; }
    .an-open-btn { width: 100%; padding: 12px 18px; }
    .hbar { grid-template-columns: minmax(76px, 118px) 1fr auto; font-size: 12px;
      gap: 6px 8px; }
    .pay-table, #an-table, #ads-table { font-size: 12.5px; }
    .pay-table th, #an-table th, #ads-table th { padding: 6px 8px; }
    .pay-table td, #an-table td, #ads-table td { padding: 8px 8px; }
    #ads-table .ads-dest { max-width: 200px; }

    /* --- Модалки: снизу вверх, во всю ширину (лист снизу) --- */
    #modal-overlay, #task-overlay, #emp-overlay, #pay-overlay, #spend-overlay,
    #crm-overlay, #payedit-overlay, #paylink-overlay, #access-overlay,
    #anlist-overlay, #cp-body-overlay, #payq-overlay { align-items: flex-end; }
    #modal, #task-modal, #emp-modal, #pay-modal, #spend-modal, #crm-modal,
    #payedit-modal, #paylink-modal, #access-modal, #anlist-modal, #cp-body-modal,
    #payq-modal {
      width: 100%; max-width: 100%; border-radius: 20px 20px 0 0;
      max-height: 92dvh; overflow-y: auto;
      padding: 18px 14px calc(18px + env(safe-area-inset-bottom, 0px)); }
    #cp-body-modal { height: 88dvh; }
    #modal-actions, #task-actions, #emp-actions, #pay-actions, #spend-actions,
    #crm-m-actions, #payedit-actions, #pl-actions, #access-actions,
    #ads-form-actions, #plp-form-actions { flex-wrap: wrap; }
    #modal-send, #task-save, #emp-save, #pay-save, #spend-save, #crm-m-save,
    #payedit-save, #pl-create, #access-grant { flex: 1 1 auto; padding: 12px 18px; }
    #modal-cancel, #task-cancel, #emp-cancel, #pay-cancel, #spend-cancel,
    #crm-m-cancel, #payedit-cancel, #pl-cancel, #access-cancel {
      flex: 1 1 auto; padding: 12px 16px; }
    #hrm-modal { width: 100%; max-width: 100%; border-radius: 20px 20px 0 0;
      max-height: 88dvh; overflow-y: auto;
      padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px)); }
    #hrm-back { align-items: flex-end; }
    #anlist-modal { max-height: 88dvh; }


    /* --- Рассрочки: график и карточка в один столбец --- */
    #instnew-overlay, #instpay-overlay { align-items: flex-end; }
    #instnew-modal, #instpay-modal { width: 100%; max-width: 100%;
      border-radius: 20px 20px 0 0; max-height: 92dvh;
      padding: 18px 14px calc(18px + env(safe-area-inset-bottom, 0px)); }
    #instnew-actions, #instpay-actions { flex-wrap: wrap; }
    #instnew-save, #instpay-save, #instnew-cancel, #instpay-cancel {
      flex: 1 1 auto; padding: 12px 16px; }
    #inst-search { max-width: none; order: 6; flex: 1 1 100%; }
    #inst-chips .chip { white-space: nowrap; }
    #inst-new { margin-left: 0; }
    .inst-details { flex-direction: column; gap: 10px; }
    .inst-sch-row { flex-wrap: wrap; gap: 6px; }
    .inst-sch-row .inst-when, .inst-sch-row .inst-amt { width: auto; }
    .inst-sch-row .inst-act { width: 100%; margin-left: 0; }
    .inst-bar { width: 100%; }

    /* --- Диалоги --- */
    #chat-header { padding: 8px 10px; gap: 8px; }
    #chat-titles { min-width: 0; flex: 1; }
    #chat-title, #chat-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* Кнопок в шапке до восьми — ряд скроллится, а не выдавливает заголовок */
    #chat-actions { gap: 6px; overflow-x: auto; scrollbar-width: none;
      -webkit-overflow-scrolling: touch; max-width: 62vw; }
    #chat-actions::-webkit-scrollbar { display: none; }
    #trial-done-btn { font-size: 12.5px; padding: 0 12px; height: 36px; }
    #messages { padding: 14px 12px; }
    .msg { max-width: 86%; }
    .att-img, .att-video { max-width: 100%; }
    #composer { padding: 8px 10px 10px; gap: 7px; }
    #composer-row { gap: 7px; }
    /* Кнопки уже — иначе на узком экране плейсхолдер поля не помещается */
    #attach-btn, #schedule-btn { padding: 0 10px; }
    #send-btn { padding: 0 14px; }
    #composer textarea { padding: 10px 11px; }
    #search-row { padding: 10px 12px 8px; }
    #filter-row { padding: 0 12px 9px; }
    #schedule-pop { left: 10px; right: 10px; width: auto; }

    /* --- CRM: колонки шириной почти в экран, с прилипанием --- */
    #crm-board { padding: 10px 12px 14px; scroll-snap-type: x mandatory; gap: 8px; }
    .crm-col { width: 80vw; min-width: 80vw; scroll-snap-align: start; }

    /* --- HRM и доска Miro: крупные кнопки, подсказки под жесты --- */
    #hrm-tools, #mb-tools { padding: 6px 8px; gap: 5px; }
    #hrm-tools button, #mb-tools button { width: 38px; height: 34px; font-size: 17px; }
    #mb-status { font-size: 11px; }
    #crm-btn { max-width: 130px; }

    /* --- Скрипты: инструкции --- */
    #scripts-tabs { flex: 1 0 100%; display: flex; gap: 6px; }
    .scr-sec-head h3 { font-size: 14px; }
  }

  /* Сенсорные экраны: то, что на десктопе показывается по наведению,
     иначе на телефоне недоступно в принципе. */
  @media (hover: none) and (pointer: coarse) {
    .t-del { display: flex; }
    .msg.show-act .msg-actions { display: flex; }
    .msg-actions button { width: 32px; height: 32px; }
    .msg-actions { top: -16px; }
    /* Ручка перетаскивания строк контент-плана: на тач крупнее и без
       перехвата жеста браузером (порядок постов двигается пальцем). */
    .cp-grip { font-size: 15px; padding: 8px 6px; touch-action: none; }
    /* Подсказки к доскам: вместо «колесо/мышка» — жесты пальцем */
    #hrm-hint, #mb-hint { display: none; }
    .hint-touch { display: inline; color: var(--muted); font-size: 11.5px;
      margin-left: 6px; }
    /* Доска Miro: пальцем ведём холст, а не выделяем текст (тап копирует блок) */
    .mb-item, .mb-item .mb-txt { user-select: none; cursor: pointer; }
  }
