/* ═══════════════════════════════════════════════════════════════════════════
   Дизайн-система «Планування маркетингу».

   Інструмент, у якому дивляться на числа годинами, тому все підпорядковано
   одному: дані голосні, обгортка тиха. Кольором позначаємо лише те, що щось
   означає (мінус, факт, редаговане), решта — відтінки сірого.
   ═════════════════════════════════════════════════════════════════════════ */

/* ── Токени ──────────────────────────────────────────────────────────────── */

:root {
    color-scheme: light;

    --n0:  #ffffff;  --n25: #fbfcfd;  --n50: #f4f6f9;  --n100:#edf0f4;
    --n150:#e4e8ee;  --n200:#d8dee6;  --n300:#c1c9d4;  --n400:#98a2b0;
    --n500:#6d7788;  --n600:#4e5766;  --n700:#39414e;  --n800:#242b35;
    --n900:#141920;

    --bg:          var(--n50);
    --panel:       var(--n0);
    --panel-sub:   var(--n25);
    --line:        var(--n150);
    --line-strong: var(--n300);
    --ink:         var(--n800);
    --ink-2:       var(--n600);
    --muted:       var(--n500);
    --faint:       var(--n400);
    --surface-2:   var(--n100);   /* смуги, ховер, чипи */
    --hover:       var(--n100);
    --toast-bg:    var(--n800);
    --toast-ink:   var(--n0);

    --accent:      #2f5fd0;
    --accent-hi:   #2750b6;
    --accent-ink:  #ffffff;
    --accent-soft: #eaf0fd;
    --accent-line: #c3d4f7;

    --good:      #0e7a4d;  --good-soft: #e7f4ec;  --good-bar: #7fc0a0;
    --bad:       #c2352a;  --bad-soft:  #fdedeb;  --bad-bar:  #e2a09a;
    --warn:      #92650a;  --warn-soft: #fcf5e4;

    /* Місяць факту: не «підсвітка», а окрема смуга даних, тому колір теплий
       і тримається за всю колонку, а не за окрему клітинку. */
    --fact:      #fdf9ef;  --fact-line: #ecdcb4;

    --edit:      #f6fafe;  /* натяк, що сюди можна писати */
    --row-hover: #f4f8fe;

    --dlg-veil:  rgba(16, 24, 40, .42);

    --shadow-1: 0 1px 2px rgba(16,24,40,.06);
    --shadow-2: 0 6px 16px -4px rgba(16,24,40,.12), 0 2px 5px -2px rgba(16,24,40,.06);
    --shadow-pane: 6px 0 8px -8px rgba(16,24,40,.28);

    --r-xs: 4px; --r-sm: 6px; --r: 9px; --r-lg: 13px; --r-pill: 999px;
    --topbar-h: 56px;
    --nav-w: 218px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

/* Темна тема: перевизначаємо тільки семантичні токени, шкала сірого
   перевертається. Ручний перемикач має бути сильнішим за системний. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg:          #0f1319;
        --panel:       #161b23;
        --panel-sub:   #1b212b;
        --line:        #262e3a;
        --line-strong: #3a4553;
        --ink:         #e4e8ee;
        --ink-2:       #b6bfcc;
        --muted:       #8b95a5;
        --faint:       #6b7585;
        --surface-2:   #222a35;
        --hover:       #202834;
        --toast-bg:    #2d3745;
        --toast-ink:   #f2f5f8;

        --accent:      #5b8bf0;
        --accent-hi:   #79a1f6;
        --accent-ink:  #0f1319;
        --accent-soft: #1b2739;
        --accent-line: #2c4372;

        --good: #4fbe8b;  --good-soft: #12281f;  --good-bar: #2f7355;
        --bad:  #f0837a;  --bad-soft:  #2a1715;  --bad-bar:  #8a3d36;
        --warn: #d6ac5a;  --warn-soft: #29220f;

        --fact:      #23201a;  --fact-line: #4a3f28;
        --edit:      #1a212b;
        --row-hover: #1c2430;

        --dlg-veil:  rgba(0, 0, 0, .62);
        --shadow-1: 0 1px 2px rgba(0,0,0,.4);
        --shadow-2: 0 6px 16px -4px rgba(0,0,0,.55), 0 2px 5px -2px rgba(0,0,0,.4);
        --shadow-pane: 8px 0 10px -10px rgba(0,0,0,.8);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg:          #0f1319;
    --panel:       #161b23;
    --panel-sub:   #1b212b;
    --line:        #262e3a;
    --line-strong: #3a4553;
    --ink:         #e4e8ee;
    --ink-2:       #b6bfcc;
    --muted:       #8b95a5;
    --faint:       #6b7585;
    --surface-2:   #222a35;
    --hover:       #202834;
    --toast-bg:    #2d3745;
    --toast-ink:   #f2f5f8;

    --accent:      #5b8bf0;
    --accent-hi:   #79a1f6;
    --accent-ink:  #0f1319;
    --accent-soft: #1b2739;
    --accent-line: #2c4372;

    --good: #4fbe8b;  --good-soft: #12281f;  --good-bar: #2f7355;
    --bad:  #f0837a;  --bad-soft:  #2a1715;  --bad-bar:  #8a3d36;
    --warn: #d6ac5a;  --warn-soft: #29220f;

    --fact:      #23201a;  --fact-line: #4a3f28;
    --edit:      #1a212b;
    --row-hover: #1c2430;

    --dlg-veil:  rgba(0, 0, 0, .62);
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 6px 16px -4px rgba(0,0,0,.55), 0 2px 5px -2px rgba(0,0,0,.4);
    --shadow-pane: 8px 0 10px -10px rgba(0,0,0,.8);
}

/* ── База ────────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

/* Цифри в таблицях мусять ставати одна під одну — інакше колонку неможливо
   читати згори вниз. Це не косметика, це головна вимога до фінансової сітки. */
table, .num, .card .value, .kpi-value, input.cell { font-variant-numeric: tabular-nums; }

h2 { font-size: 20px; line-height: 1.25; letter-spacing: -.01em; margin: 0 0 6px; font-weight: 620; }
h3 { font-size: 13px; margin: 0; font-weight: 620; letter-spacing: -.005em; }
p  { margin: 0 0 12px; }

.page-hint {
    color: var(--muted); font-size: 13px; line-height: 1.55;
    margin: 0 0 20px; max-width: 74ch;
}
.note { font-size: 12px; color: var(--muted); font-weight: 400; }

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

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-radius: var(--r-xs);
}

/* ── Логін ───────────────────────────────────────────────────────────────── */

.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 24px;
    background:
        radial-gradient(1000px 600px at 50% -10%, var(--accent-soft), transparent 70%),
        var(--bg);
}
.login-box {
    background: var(--panel); border: 1px solid var(--line);
    padding: 30px 28px; border-radius: var(--r-lg); width: 100%; max-width: 360px;
    box-shadow: var(--shadow-2); display: flex; flex-direction: column; gap: 16px;
}
.login-box h1 {
    font-size: 18px; margin: 0 0 4px; font-weight: 620; letter-spacing: -.01em;
}
.login-box label {
    display: flex; flex-direction: column; gap: 6px;
    font-size: 12px; color: var(--muted); font-weight: 520;
}
.login-box input {
    padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
    font: 14px var(--font); color: var(--ink); background: var(--panel);
}
.login-box input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-box button {
    margin-top: 4px; padding: 10px; background: var(--accent); color: var(--accent-ink);
    border: 0; border-radius: var(--r-sm); font: 520 14px var(--font); cursor: pointer;
}
.login-box button:hover { background: var(--accent-hi); }
.login-error {
    color: var(--bad); font-size: 13px; background: var(--bad-soft);
    border: 1px solid var(--bad); border-radius: var(--r-sm); padding: 8px 10px;
}

/* ── Верхня панель ───────────────────────────────────────────────────────── */

.topbar {
    display: flex; align-items: center; gap: 14px; padding: 0 16px; height: var(--topbar-h);
    background: var(--panel); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 30;
}
.brand {
    display: flex; align-items: center; gap: 9px;
    font-weight: 620; font-size: 14px; letter-spacing: -.01em; white-space: nowrap;
}
.brand-mark {
    width: 24px; height: 24px; flex: none; border-radius: 7px;
    background: var(--accent); color: var(--accent-ink);
    display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.spacer { flex: 1; }

.field-inline { display: flex; align-items: center; gap: 7px; }
.field-label {
    font-size: 11px; color: var(--muted); text-transform: uppercase;
    letter-spacing: .06em; font-weight: 600;
}
.scenario-pick { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.scenario-pick select, select.inline, .control {
    padding: 5px 9px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
    font: 13px var(--font); max-width: 300px;
    color: var(--ink); background: var(--panel);
}
.scenario-pick select:focus, select.inline:focus, .control:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Смуга показників. Тримається у шапці навмисно: сенс застосунку в тому, щоб
   правити число на будь-якій сторінці й одразу бачити, куди поїхав результат. */
.kpi-strip { display: flex; align-items: stretch; gap: 0; margin-left: 4px; }
.kpi {
    display: flex; flex-direction: column; justify-content: center; gap: 1px;
    padding: 0 14px; border-left: 1px solid var(--line); min-width: 118px;
}
.kpi:first-child { border-left: 0; }
.kpi-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--faint); font-weight: 600; white-space: nowrap;
}
.kpi-value {
    font-size: 14px; font-weight: 620; line-height: 1.2; white-space: nowrap;
    display: flex; align-items: baseline; gap: 6px;
}
.kpi-delta {
    font-size: 11px; font-weight: 600; padding: 1px 5px; border-radius: var(--r-pill);
    animation: kpi-pop .35s ease-out;
}
.kpi-delta.up   { color: var(--good); background: var(--good-soft); }
.kpi-delta.down { color: var(--bad);  background: var(--bad-soft); }
.kpi-delta.fade { opacity: 0; transition: opacity 1.2s ease-in; }
@keyframes kpi-pop { from { transform: translateY(-4px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .kpi-delta { animation: none; } }

.icon-btn {
    width: 30px; height: 30px; flex: none; display: grid; place-items: center;
    border: 1px solid transparent; border-radius: var(--r-sm); background: transparent;
    color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }

/* ── Каркас ──────────────────────────────────────────────────────────────── */

.layout { display: flex; align-items: flex-start; }

.nav {
    width: var(--nav-w); flex: none; padding: 16px 10px 40px;
    position: sticky; top: var(--topbar-h); align-self: flex-start;
    max-height: calc(100vh - var(--topbar-h)); overflow-y: auto;
    display: flex; flex-direction: column; gap: 1px;
}
.nav-group {
    font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
    color: var(--faint); font-weight: 650; padding: 14px 12px 5px;
}
.nav-group:first-child { padding-top: 0; }
.nav-item {
    position: relative; padding: 7px 12px; border-radius: var(--r-sm); cursor: pointer;
    color: var(--ink-2); text-decoration: none; font-size: 13.5px; font-weight: 480;
    display: block; user-select: none;
}
.nav-item:hover { background: var(--hover); color: var(--ink); }
.nav-item.active {
    background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.nav-item.active::before {
    content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px;
    border-radius: 0 3px 3px 0; background: var(--accent);
}

/* Рамка сторінок одного сценарію.
   Це не прикраса: сторінки всередині правлять ОБРАНИЙ сценарій, а пункти над
   рамкою працюють над усіма. Рамка з перемикачем у шапці робить видимим те,
   на що подіє клац, — раніше це доводилось тримати в голові. */
.nav-scope {
    margin-top: 18px; padding: 4px; border: 1px solid var(--line);
    border-radius: var(--r); background: var(--panel-sub);
    display: flex; flex-direction: column; gap: 1px;
}
.nav-scope-head {
    display: flex; flex-direction: column; gap: 5px; padding: 8px 8px 10px;
}
.nav-scope-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
    color: var(--faint); font-weight: 650;
}
.nav-scope-head select { width: 100%; }
.nav-scope .nav-item { margin: 0 4px; }

/* На загальних сторінках рамка приглушена: сторінки в ній лишаються доступні
   (це шлях назад у сценарій), але видно, що зараз ти не там. */
body[data-scope="global"] .nav-scope { opacity: .72; }
body[data-scope="global"] .topbar .kpi-strip { display: none; }
.nav-sep { height: 1px; background: var(--line); margin: 10px 12px; }

.content {
    flex: 1; min-width: 0; padding: 22px 24px 80px;
    max-width: calc(100vw - var(--nav-w));
}
.loading {
    color: var(--muted); padding: 44px 0; font-size: 13px;
    display: flex; align-items: center; gap: 9px;
}
.loading::before {
    content: ""; width: 13px; height: 13px; border-radius: 50%;
    border: 2px solid var(--line-strong); border-top-color: var(--accent);
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading::before { animation: none; } }

@media (max-width: 900px) {
    .layout { flex-direction: column; }
    .nav {
        width: 100%; position: static; max-height: none; flex-direction: row;
        flex-wrap: wrap; gap: 4px; padding: 10px 14px;
        border-bottom: 1px solid var(--line); background: var(--panel);
    }
    .nav-group, .nav-sep { display: none; }
    .content { padding: 16px 14px 60px; max-width: 100vw; }
    .kpi-strip { display: none; }
}

/* ── Панелі ──────────────────────────────────────────────────────────────── */

.panel {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
    margin-bottom: 16px; box-shadow: var(--shadow-1);
}
.panel-head {
    display: flex; align-items: center; gap: 10px; padding: 11px 14px;
    border-bottom: 1px solid var(--line);
    border-radius: var(--r) var(--r) 0 0; background: var(--panel-sub);
}
.panel-body { padding: 14px; }
.panel > .scroll-x:first-child,
.panel > .panel-body:first-child { border-radius: var(--r) var(--r) 0 0; }
.panel > .scroll-x:last-child { border-radius: 0 0 var(--r) var(--r); }
.panel.off { opacity: .55; }
.panel.off .panel-head { background: repeating-linear-gradient(
    -45deg, var(--panel-sub), var(--panel-sub) 8px, var(--surface-2) 8px, var(--surface-2) 16px); }

/* Прокрутка живе всередині панелі: так шапка таблиці й колонка з назвами
   лишаються на місці, поки бігаєш по місяцях. Excel-подібно і навмисно. */
.scroll-x {
    overflow: auto; max-height: min(72vh, 760px);
    overscroll-behavior: contain; border-radius: inherit;
}

/* ── Таблиці ─────────────────────────────────────────────────────────────── */

table.data {
    border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px;
}
table.data th, table.data td {
    padding: 6px 10px; text-align: right; white-space: nowrap;
    border-bottom: 1px solid var(--line); background: var(--panel);
}
table.data th:first-child, table.data td:first-child { text-align: left; }

table.data thead th {
    position: sticky; top: 0; z-index: 3;
    background: var(--panel-sub); color: var(--muted);
    font-weight: 600; font-size: 11px; letter-spacing: .02em; line-height: 1.3;
    border-bottom: 1px solid var(--line-strong); vertical-align: bottom;
    padding-top: 8px; padding-bottom: 7px;
}
table.data thead th .note { display: block; font-size: 10px; margin-top: 1px; color: var(--faint); }

/* Заморожена перша колонка — назва рядка не має зникати при скролі вправо. */
table.data th:first-child, table.data td:first-child {
    position: sticky; left: 0; z-index: 2;
    border-right: 1px solid var(--line-strong);
    max-width: 360px; white-space: normal;
}
table.data thead th:first-child { z-index: 4; }
.name-col { min-width: 246px; }

table.data tbody tr:hover > td { background: var(--row-hover); }
table.data tbody tr:last-child > td { border-bottom: 0; }

/* Заголовок блоку рядків. Текст загорнутий у власний sticky-елемент, інакше
   при скролі вправо назва групи їде за межі екрана разом із коміркою. */
tr.row-group > td {
    background: var(--surface-2); padding: 0; box-shadow: none;
    border-bottom: 1px solid var(--line); border-top: 1px solid var(--line);
}
tr.row-group .sticky-label {
    display: inline-block; position: sticky; left: 0; padding: 6px 10px;
    font-weight: 650; font-size: 10.5px; text-transform: uppercase;
    letter-spacing: .07em; color: var(--ink-2);
}
tr.row-strong > td {
    font-weight: 650;
    border-top: 1px solid var(--line-strong);
    background: var(--panel-sub);
}
/* Підсумок теж буває від'ємним — колір не має губитись під жирним. */
tr.row-strong > td.neg { color: var(--bad); }
tr.row-strong > td.pos { color: var(--good); }
tr.row-strong:hover > td { background: var(--row-hover); }

td.neg, .neg { color: var(--bad); }
td.pos, .pos { color: var(--good); }

/* Колонка факту — не підсвітка рядка, а вертикальна смуга даних. */
.fact-col { background: var(--fact) !important; }
thead .fact-col { border-bottom-color: var(--fact-line); }
tr:hover > .fact-col { filter: brightness(.985); }

tr.off > td { opacity: .5; }

/* Неповний місяць у зведеному P&L: його покривають не всі обрані ринки — один
   ще не стартував, інший уже вийшов за горизонт. Число тут правильне, але не
   порівнюване з сусіднім, і читати падіння як спад продажів було б помилкою.
   Тому приглушуємо, а не фарбуємо: це не помилка й не тривога, це неповнота. */
td.partial, th.partial { color: var(--muted); background: var(--surface-2); }
th.partial { border-bottom-color: var(--line-strong); }

/* Клітинка у відсотках: значок «%» після поля, щоб не гадати, 80 це чи 0,8. */
.pct-cell { position: relative; display: inline-block; }
.pct-cell::after {
    content: "%"; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    font-size: 11px; color: var(--faint); pointer-events: none;
}
.pct-cell input.cell { padding-right: 18px; }

/* «Протягнути вправо». Кнопка виринає лише під курсором або з клавіатури:
   у сітці сотні клітинок, і постійна стрілка в кожній зробила б її рябою. */
.cell-wrap { position: relative; display: inline-block; }
.cell-wrap .fill-right {
    position: absolute; right: -4px; top: 50%; transform: translateY(-50%);
    border: 0; background: none; cursor: pointer; padding: 0 3px;
    font-size: 12px; line-height: 1; color: var(--faint);
    opacity: 0; transition: opacity .12s;
}
.cell-wrap:hover .fill-right,
.cell-wrap:focus-within .fill-right { opacity: 1; }
.cell-wrap .fill-right:hover { color: var(--accent); }
.cell-wrap.pct-cell input.cell { padding-right: 26px; }
.cell-wrap.pct-cell::after { right: 16px; }

/* Рядок-продовження: склад набору під самим набором. Тон панелі, а не рядка,
   бо це не ще одна позиція каталогу, а її розкриття. */
tr.row-sub > td { background: var(--panel-sub); }

/* Згортання блоку сутності. Стрілка повертається, а не міняє символ: так
   видно, що це той самий елемент у двох станах, а не дві різні кнопки. */
.fold {
    border: 0; background: none; cursor: pointer; padding: 0 4px;
    color: var(--faint); font-size: 13px; line-height: 1;
    transition: transform .12s, color .12s;
}
.fold.open { transform: rotate(90deg); color: var(--ink-2); }
.fold:hover { color: var(--accent); }
.fold-head { cursor: pointer; }
.fold-head:hover { background: var(--hover); }

/* Нотатка сценарію — «навіщо він і чим відрізняється».
   Тихіша за назву, бо це пояснення, а не заголовок; але не .note, бо її
   читають, а не ковзають по ній очима. */
.sc-note {
    font-size: 12.5px; line-height: 1.5; color: var(--ink-2);
    border-left: 2px solid var(--line-strong); padding-left: 10px;
    margin: 0 0 14px;
}
.sc-note-inline { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Журнал змін ─────────────────────────────────────────────────────────── */
/* Перша колонка в системі заморожена й переносить рядки (max-width + normal),
   бо там зазвичай довгі назви показників. Дата — інша річ: розбита на три
   рядки, вона перестає читатись. Селектор із таблицею навмисно: без нього
   правило заморозки виграє за специфічністю. */
table.data td.audit-time, table.data th.audit-time {
    white-space: nowrap; min-width: 118px; max-width: none;
    font-variant-numeric: tabular-nums; color: var(--muted);
}
.audit-was { color: var(--muted); text-decoration: line-through; }
.audit-kind {
    display: inline-block; padding: 2px 7px; border-radius: var(--r-pill);
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.audit-kind.edit { background: var(--surface-2); color: var(--ink-2); }
.audit-kind.add  { background: var(--good-soft); color: var(--good); }
.audit-kind.del  { background: var(--bad-soft);  color: var(--bad); }

/* ── Довідник показників ─────────────────────────────────────────────────── */

/* Назва показника як точка входу в довідку. Знак питання блідий і виринає
   лише під курсором: у фінансовій сітці сотні назв, і сотня яскравих значків
   зробила б таблицю нечитабельною. */
.gloss { cursor: help; border-bottom: 1px dashed var(--line-strong); }
.gloss:hover { border-bottom-color: var(--accent); color: var(--accent); }
.gloss-mark {
    font-style: normal; font-size: 9px; font-weight: 700; vertical-align: super;
    margin-left: 3px; color: var(--faint); opacity: 0;
    transition: opacity .12s;
}
.gloss:hover .gloss-mark { opacity: 1; color: var(--accent); }

.gloss-pop {
    position: absolute; z-index: 60; width: min(420px, calc(100vw - 24px));
    background: var(--panel); border: 1px solid var(--line-strong);
    border-radius: var(--r); box-shadow: var(--shadow-2);
}
.gloss-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 12px; border-bottom: 1px solid var(--line);
    background: var(--panel-sub); border-radius: var(--r) var(--r) 0 0;
    font-size: 13px; font-weight: 620; color: var(--ink);
}
.gloss-x {
    border: 0; background: none; cursor: pointer; font-size: 17px; line-height: 1;
    color: var(--faint); padding: 0 2px;
}
.gloss-x:hover { color: var(--ink); }
.gloss-body { padding: 12px; display: flex; flex-direction: column; gap: 11px; }
.gloss-sec p { margin: 3px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }
.gloss-key {
    font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--faint); font-weight: 650;
}
/* Посилання у формулі — теж вхід у довідку: з «Виручки разом» видно, з чого
   вона складається, і кожен доданок відкривається так само. */
.gloss-ref { color: var(--accent); cursor: pointer; font-weight: 600; }
.gloss-ref:hover { text-decoration: underline; }
.gloss-src { color: var(--faint); }

/* ── Майстер: стежка кроків і картки вибору ──────────────────────────────── */

/* Стежка показує не лише де ти зараз, а й скільки лишилось: у майстрі з
   невідомою довжиною люди кидають на другому кроці. Пройдені кроки клікабельні
   — повернутись і перевірити відповідь має бути дешевше, ніж почати спочатку. */
.steps { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; }
.step {
    display: flex; align-items: center; gap: 7px; padding: 7px 12px;
    border: 1px solid var(--line); border-radius: var(--r-pill);
    background: var(--panel); font-size: 12px; color: var(--muted);
    white-space: nowrap;
}
.step-num {
    width: 18px; height: 18px; flex: none; display: grid; place-items: center;
    border-radius: 50%; background: var(--surface-2); color: var(--muted);
    font-size: 10px; font-weight: 700;
}
.step.done { color: var(--ink-2); cursor: pointer; }
.step.done .step-num { background: var(--good-soft); color: var(--good); }
.step.done:hover { border-color: var(--line-strong); background: var(--hover); }
.step.now {
    color: var(--accent-ink); background: var(--accent); border-color: var(--accent);
    font-weight: 600;
}
.step.now .step-num { background: rgba(255, 255, 255, .25); color: var(--accent-ink); }

/* Картка вибору — «клас персонажа»: великий клікабельний блок із назвою,
   поясненням і наслідком, а не рядок у випадному списку. */
.choice-grid {
    display: grid; gap: 10px; margin-bottom: 16px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.choice {
    text-align: left; padding: 14px; border: 1px solid var(--line);
    border-radius: var(--r); background: var(--panel); cursor: pointer;
    display: flex; flex-direction: column; gap: 6px; font: inherit; color: inherit;
    transition: border-color .12s, background .12s;
}
.choice:hover { border-color: var(--line-strong); background: var(--panel-sub); }
.choice.picked { border-color: var(--accent); background: var(--accent-soft); }
.choice-title { font-size: 14px; font-weight: 620; color: var(--ink); }
.choice-note { font-size: 12px; color: var(--muted); line-height: 1.45; }
.choice-meta { font-size: 11px; color: var(--faint); margin-top: auto; }

/* Смуга показників майстра — та сама, що в шапці, але на всю ширину панелі. */
.kpi-strip.wide { margin: 0; padding: 4px 0; }
.kpi-strip.wide .kpi { min-width: 150px; padding: 6px 18px; }
.kpi-strip.wide .kpi-value { font-size: 17px; }

/* ── Редаговані клітинки ─────────────────────────────────────────────────── */

input.cell {
    width: 88px; padding: 3px 7px; border: 1px solid transparent; border-radius: var(--r-xs);
    text-align: right; font: inherit; color: var(--ink);
    background: var(--edit); box-shadow: inset 0 -1px 0 var(--line);
    transition: box-shadow .12s, background .12s;
}
input.cell:hover { border-color: var(--line-strong); box-shadow: none; }
input.cell:focus {
    border-color: var(--accent); background: var(--panel); outline: none;
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input.cell.wide { width: 100%; text-align: left; }
input.cell.saving {
    background: var(--warn-soft); border-color: var(--warn);
}
input.cell::placeholder { color: var(--faint); }
/* У колонці факту поле бере колір колонки: смуга даних має читатись суцільною. */
.fact-col input.cell { background: var(--fact); }
.fact-col input.cell:focus { background: var(--panel); }
/* Назва сутності в шапці панелі — теж поле, але має виглядати як заголовок. */
.panel-head input.cell.wide {
    font-size: 14px; font-weight: 620; max-width: 300px; background: transparent;
    box-shadow: none; padding: 3px 6px;
}
.panel-head input.cell.wide:hover { background: var(--edit); }

.switch {
    display: inline-flex; align-items: center; gap: 7px; flex-wrap: nowrap;
    font-size: 13px; color: var(--ink-2); cursor: pointer; vertical-align: middle;
}
.switch input[type="checkbox"] {
    accent-color: var(--accent); width: 15px; height: 15px; flex: none; margin: 0; cursor: pointer;
}
/* Вимикач і назва — сусіди в одній клітинці, тож клітинка не переносить рядок. */
table.data td:has(> .switch) { white-space: nowrap; }
table.data td:has(> .switch) > input.cell.wide { width: 320px; vertical-align: middle; }
/* Табличка атрибутів усередині панелі — поле має бути придатним для тексту. */
.panel-body input.cell.wide { min-width: 340px; }
.off { opacity: .55; }

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 6px 12px; min-height: 30px;
    border: 1px solid var(--line-strong); background: var(--panel); border-radius: var(--r-sm);
    cursor: pointer; font: 500 13px var(--font); color: var(--ink); text-decoration: none;
    white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--hover); border-color: var(--faint); }
.btn:active { transform: translateY(.5px); }
.btn + .btn { margin-left: 6px; }

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

.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--hover); color: var(--ink); border-color: transparent; }

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

.btn-sm { padding: 2px 8px; min-height: 24px; font-size: 12px; }

/* ── Картки показників ───────────────────────────────────────────────────── */

.cards {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; margin-bottom: 18px;
}
.card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
    padding: 12px 15px 13px; min-width: 172px; flex: 0 1 auto;
    box-shadow: var(--shadow-1);
}
.card .label {
    font-size: 10.5px; color: var(--muted); text-transform: uppercase;
    letter-spacing: .06em; font-weight: 600;
}
.card .value {
    font-size: 22px; font-weight: 640; margin-top: 5px; letter-spacing: -.02em; line-height: 1.15;
}
/* Смуга керування сторінкою: не показники, а важелі перегляду. */
.toolbar {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
    padding: 10px 14px; margin-bottom: 18px; box-shadow: var(--shadow-1);
}
.toolbar .scenario-pick { gap: 8px; }

.tag {
    display: inline-block; padding: 2px 8px; border-radius: var(--r-pill);
    background: var(--surface-2); border: 1px solid var(--line);
    font-size: 11px; font-weight: 500; color: var(--ink-2); white-space: nowrap;
}
.tag-accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

/* ── Тост ────────────────────────────────────────────────────────────────── */

.toast {
    position: fixed; right: 18px; bottom: 18px; z-index: 60;
    background: var(--toast-bg); color: var(--toast-ink);
    padding: 10px 15px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500;
    box-shadow: var(--shadow-2);
    opacity: 0; transform: translateY(10px); transition: .18s ease-out; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--bad); color: #fff; }

/* ── Торнадо чутливості ──────────────────────────────────────────────────── */
/* Дві половини однієї шкали з нулем посередині: ліворуч ефект зсуву вниз,
   праворуч — вгору. Так видно і силу важеля, і його симетричність. */

.tor-cell { padding: 4px 8px !important; }
.tor-half {
    display: inline-block; width: 50%; height: 14px; vertical-align: middle; position: relative;
}
.tor-half.left  { text-align: right; }
.tor-half.right { text-align: left; border-left: 1px solid var(--line-strong); }
.tor-bar {
    display: inline-block; height: 14px; border-radius: 2px; min-width: 2px;
    vertical-align: top;
}
.tor-bar.down { background: var(--bad-bar); }
.tor-bar.up   { background: var(--good-bar); }
.tor-half.left  .tor-bar { border-radius: 2px 0 0 2px; }
.tor-half.right .tor-bar { border-radius: 0 2px 2px 0; }

.panel-body ul { margin: 6px 0 0; padding-left: 18px; }
.panel-body li { margin-bottom: 4px; }
code {
    font: 12px/1 var(--mono); background: var(--surface-2); border: 1px solid var(--line);
    padding: 2px 5px; border-radius: var(--r-xs); color: var(--ink-2);
}

/* Групи календаря дотиків: «всім» проти індивідуальних допродажів сегмента.
   Заголовок несе розділення, тому він має відриватись від попереднього блоку
   сильніше, ніж панелі одна від одної. */
.ltv-group {
    margin: 28px 0 4px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    font-size: 15px;
}
.ltv-group:first-of-type { margin-top: 8px; border-top: 0; padding-top: 0; }

/* Теґ-попередження: механізм вимкнено вручну. Це не стан даних, а стан
   МОДЕЛІ — «тут розрахунок не діє», — тому він має читатись інакше, ніж
   звичайний теґ із числом. */
.tag.tag-warn { background: var(--warn-soft); color: var(--warn); }

/* ── Діалог ──────────────────────────────────────────────────────────────
   Замінює системні prompt/confirm. Системне вікно вміє рівно одне поле й не
   знає ні про списки, ні про підказки — через це «додати дотик» питало двома
   вікнами поспіль. */
.dlg-back {
    position: fixed; inset: 0; z-index: 100;
    background: var(--dlg-veil);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.dlg-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 18px 48px -12px rgba(0, 0, 0, .35), 0 2px 8px rgba(0, 0, 0, .12);
    width: min(440px, 100%);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    display: flex; flex-direction: column;
}
.dlg-head { padding: 18px 22px 0; }
.dlg-head h3 { font-size: 15px; }
.dlg-hint { margin: 8px 22px 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.dlg-body { padding: 18px 22px 4px; display: flex; flex-direction: column; gap: 14px; }
.dlg-field { display: flex; flex-direction: column; gap: 5px; }
.dlg-field > span:first-child { font-size: 12px; color: var(--muted); }
.dlg-field .note { font-size: 11.5px; }
.dlg-req { color: var(--bad); font-weight: 700; }
.dlg-field .cell.wide { width: 100%; text-align: left; }
/* Обов'язкове поле, яке лишили порожнім: форма не закривається мовчки. */
.dlg-field .cell.bad { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.dlg-foot {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 18px 22px 20px; margin-top: auto;
}
@media (max-width: 520px) {
    .dlg-back { padding: 12px; align-items: flex-end; }
    .dlg-card { width: 100%; }
}

/* Хто зайшов — у шапці. Роль поки нічого не обмежує, але має бути видно:
   інакше «Адміністратор» читався б як захист, якого ще немає. */
.whoami { display: inline-flex; align-items: center; gap: 8px; margin-right: 4px; }

/* Екран згоди OAuth ділить розмітку зі сторінкою входу — окремий вигляд був
   би другим описом того самого. Різниця лише в тому, що тут дві кнопки. */
.login-box ul { margin: 4px 0 18px; padding-left: 18px; line-height: 1.6; }
.login-box .note { text-align: left; }
.login-box button.secondary { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.login-box button.secondary:hover { background: var(--surface-2); color: var(--ink); }
.login-box form { display: flex; flex-direction: column; gap: 8px; }
