/* CRM «Философия Отдыха»: собственный слой поверх Basecoat 1.0.2.
 * Дизайн-система описана в .interface-design/system.md.
 * Без сборки, без CDN, без inline-стилей (CSP style-src 'self').
 * Basecoat подключается раньше, его переменные переопределяются здесь. */

/* --- Шрифт ------------------------------------------------------------------ */

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url("../fonts/inter/inter-cyrillic-ext-wght-normal.woff2") format("woff2");
    unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url("../fonts/inter/inter-cyrillic-wght-normal.woff2") format("woff2");
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url("../fonts/inter/inter-latin-ext-wght-normal.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
        U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url("../fonts/inter/inter-latin-wght-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
        U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* --- Токены: светлая тема «берёзовая кора и хвоя» ------------------------------ */

:root {
    /* Поверхности */
    --birch: #f6f6f3;          /* холст страницы и боковая панель */
    --paper: #ffffff;          /* карточки и таблицы */
    --paper-sunk: #f1f1ed;     /* полосы, шапки таблиц, поля ввода чуть глубже */
    --paper-hover: #f3f4f0;

    /* Текст: четыре уровня */
    --ink: #1b1f1d;
    --ink-2: #464d49;
    --ink-3: #6b726e;
    --ink-4: #9aa19d;         /* только разделители и иконки: контраст ниже 4.5:1 */

    /* Линии */
    --line: rgba(27, 38, 31, 0.1);
    --line-soft: rgba(27, 38, 31, 0.06);
    --line-strong: rgba(27, 38, 31, 0.18);

    /* Единственный акцент: хвоя */
    --pine: #1d6b58;
    --pine-hover: #175747;
    --pine-ink: #ffffff;
    --pine-wash: #e7f1ed;
    --pine-text: #17604f;

    /* Три канала атрибуции, одинаковые во всех графиках и итогах */
    --channel-campaigns: #1d6b58;   /* с рассылок: хвоя, это вклад CRM */
    --channel-aggregators: #d09036; /* через агрегаторы: смола */
    --channel-organic: #8a97a8;     /* органика: озёрный туман */

    /* Смысловые цвета */
    --warn-wash: #fbf2de;
    --warn-ink: #7a4b0e;
    --warn-line: rgba(176, 116, 22, 0.28);
    --danger: #b3261e;
    --danger-wash: #fcebea;
    --danger-line: rgba(179, 38, 30, 0.24);
    --ok-ink: #17604f;
    --ok-wash: #e7f1ed;

    /* Графики */
    --chart-grid: rgba(27, 38, 31, 0.07);
    --chart-tick: #6b726e;
    --chart-neutral: #7d8782;

    /* Размеры */
    --radius-control: 6px;
    --radius-panel: 10px;
    --sidebar-w: 248px;
    --content-max: 1180px;
    --row-h: 44px;

    /* Сопоставление с переменными Basecoat */
    --radius: 0.5rem;
    --background: var(--birch);
    --foreground: var(--ink);
    --card: var(--paper);
    --card-foreground: var(--ink);
    --popover: var(--paper);
    --popover-foreground: var(--ink);
    --primary: var(--pine);
    --primary-foreground: var(--pine-ink);
    --secondary: var(--paper-sunk);
    --secondary-foreground: var(--ink);
    --muted: var(--paper-sunk);
    --muted-foreground: var(--ink-3);
    --accent: var(--paper-sunk);
    --accent-foreground: var(--ink);
    --destructive: var(--danger);
    --border: var(--line);
    --input: var(--line-strong);
    --ring: var(--pine);
    --font-sans: "Inter", ui-sans-serif, system-ui, "Segoe UI", Arial, sans-serif;

    color-scheme: light;
}

/* --- Тёмная тема «ночной лес» ------------------------------------------------ */

.dark {
    --birch: #111412;
    --paper: #171b19;
    --paper-sunk: #0e1110;
    --paper-hover: #1d2220;

    --ink: #e7ebe8;
    --ink-2: #b7beba;
    --ink-3: #8b938f;
    --ink-4: #5f6763;

    --line: rgba(255, 255, 255, 0.08);
    --line-soft: rgba(255, 255, 255, 0.05);
    --line-strong: rgba(255, 255, 255, 0.15);

    --pine: #4fb39a;
    --pine-hover: #63c2aa;
    --pine-ink: #0b1c17;
    --pine-wash: rgba(79, 179, 154, 0.13);
    --pine-text: #6cc6ae;

    --channel-campaigns: #4fb39a;
    --channel-aggregators: #e2a653;
    --channel-organic: #8f9db2;

    --warn-wash: rgba(226, 166, 83, 0.12);
    --warn-ink: #edc486;
    --warn-line: rgba(226, 166, 83, 0.3);
    --danger: #f08a80;
    --danger-wash: rgba(240, 138, 128, 0.12);
    --danger-line: rgba(240, 138, 128, 0.3);
    --ok-ink: #6cc6ae;
    --ok-wash: rgba(79, 179, 154, 0.13);

    --chart-grid: rgba(255, 255, 255, 0.07);
    --chart-tick: #8b938f;
    --chart-neutral: #8e9993;

    --secondary: #202624;
    --muted: #202624;
    --accent: #202624;
    --input: rgba(255, 255, 255, 0.14);

    color-scheme: dark;
}

/* --- Основа ----------------------------------------------------------------- */

html {
    font-family: var(--font-sans);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    margin: 0;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--birch);
    font-feature-settings: "cv11", "ss01";
}

h1, h2, h3 {
    color: var(--ink);
    text-wrap: balance;
    margin: 0;
}

h1 {
    font-size: 24px;
    line-height: 32px;
    font-weight: 650;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 16px;
    line-height: 24px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

h3 {
    font-size: 14px;
    line-height: 20px;
    font-weight: 600;
}

p {
    margin: 0;
    text-wrap: pretty;
}

ul, ol {
    margin: 0;
    padding: 0;
}

a {
    color: var(--pine-text);
    text-decoration: none;
    border-radius: 2px;
}

a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

:focus-visible {
    outline: 2px solid var(--pine);
    outline-offset: 2px;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--paper-sunk);
    color: var(--ink);
    border: 1px solid var(--line-soft);
}

small {
    font-size: 12px;
    color: var(--ink-3);
}

strong {
    font-weight: 600;
}

.num,
.tabular {
    font-variant-numeric: tabular-nums;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.muted {
    color: var(--ink-3);
}

/* «Перейти к содержимому»: видна только в фокусе с клавиатуры */
.skip-link {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 100;
    padding: 8px 14px;
    border-radius: var(--radius-control);
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 0 0 2px var(--pine);
    transform: translateY(-200%);
}

.skip-link:focus {
    transform: none;
}

.crm-main:focus {
    outline: none;
}

/* Без JS переключатель темы ничего не делает, поэтому скрыт */
html:not(.js) [data-theme-toggle] {
    display: none;
}

/* --- Каркас: боковая панель + контент ---------------------------------------- */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
}

.crm-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px 12px 16px;
    border-right: 1px solid var(--line);
    background: var(--birch);
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 4px;
    color: var(--ink);
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--pine);
    color: var(--pine-ink);
}

.brand-mark svg {
    width: 20px;
    height: 20px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-name {
    font-size: 14px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 12px;
    color: var(--ink-3);
}

.crm-nav {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-group-title {
    padding: 0 10px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 0 10px;
    border-radius: var(--radius-control);
    color: var(--ink-2);
    font-weight: 500;
    transition: background-color 120ms ease-out, color 120ms ease-out;
}

.nav-link svg {
    flex: none;
    width: 18px;
    height: 18px;
    color: var(--ink-3);
}

.nav-link:hover {
    background: var(--paper-hover);
    color: var(--ink);
    text-decoration: none;
}

.nav-link[aria-current="page"] {
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 0 0 1px var(--line);
}

.nav-link[aria-current="page"] svg {
    color: var(--pine);
}

.sidebar-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-top: 12px;
    border-top: 1px solid var(--line-soft);
}

.sidebar-foot form {
    margin: 0;
}

.nav-button {
    width: 100%;
    border: 0;
    background: transparent;
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.theme-label-dark,
.dark .theme-label-light {
    display: none;
}

.dark .theme-label-dark {
    display: inline;
}

.icon-sun,
.dark .icon-moon {
    display: none;
}

.dark .icon-sun {
    display: block;
}

.crm-topbar {
    display: none;
}

.app-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.crm-main {
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 28px 32px 64px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.crm-main--narrow {
    max-width: 440px;
    padding-top: 12vh;
}

/* --- Плашка тестового режима -------------------------------------------------- */

.crm-test-mode-banner {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 36px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--warn-ink);
    background: var(--warn-wash);
    border-bottom: 1px solid var(--warn-line);
    text-align: center;
}

.crm-test-mode-banner::before {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--channel-aggregators);
    box-shadow: 0 0 0 3px var(--warn-line);
}

/* --- Заголовок страницы ------------------------------------------------------- */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;
}

.page-head > div {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.page-head > .cluster,
.panel-head > .scenario-status,
.page-head > div > .cluster {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.page-lead {
    color: var(--ink-3);
    max-width: 68ch;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--ink-3);
}

.back-link svg {
    width: 16px;
    height: 16px;
}

.back-link:hover {
    color: var(--ink);
}

/* --- Панели (карточки разделов) ---------------------------------------------- */

.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-panel);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.panel--flush {
    padding: 0;
    gap: 0;
}

.panel--flush > .panel-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line-soft);
}

.panel--flush > .panel-body {
    padding: 16px 20px;
}

.panel--flush > .panel-note {
    padding: 12px 20px 16px;
}

.panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 16px;
}

.panel-head > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.panel-meta {
    color: var(--ink-3);
    font-size: 13px;
}

.panel-count {
    color: var(--ink-3);
    font-weight: 500;
}

.panel-note {
    color: var(--ink-3);
    font-size: 13px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stack--lg {
    gap: 24px;
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-top: 8px;
}

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

.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: inherit;
}

.panel > .table-container {
    margin: 0 -20px;
    width: calc(100% + 40px);
}

.panel > .table-container:last-child {
    margin-bottom: -20px;
    border-radius: 0 0 var(--radius-panel) var(--radius-panel);
}

.panel .bleed {
    margin: 0 -20px -20px;
    width: calc(100% + 40px);
    border-radius: 0 0 var(--radius-panel) var(--radius-panel);
    border-top: 1px solid var(--line-soft);
}

.panel--flush > .table-container {
    margin: 0;
    width: 100%;
}

.panel--flush > .table-container:last-child {
    margin-bottom: 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.table th,
.table td {
    height: var(--row-h);
    padding: 10px 12px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--line-soft);
    white-space: normal;
}

.table th:first-child,
.table td:first-child {
    padding-left: 20px;
}

.table th:last-child,
.table td:last-child {
    padding-right: 20px;
}

.table thead th {
    height: 40px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-3);
    background: var(--paper-sunk);
    border-bottom: 1px solid var(--line);
    white-space: normal;
    line-height: 1.3;
}

.table tbody tr {
    transition: background-color 120ms ease-out;
}

.table tbody tr:hover {
    background: var(--paper-hover);
}

.table tbody tr:last-child > * {
    border-bottom: 0;
}

.table .num,
.table th.num {
    text-align: right;
    white-space: nowrap;
}

.table thead th.num {
    white-space: normal;
}

.table td a {
    font-weight: 500;
}

.table tr.total-row > * {
    font-weight: 600;
    background: var(--paper-sunk);
    border-top: 1px solid var(--line);
    color: var(--ink);
}

.table .cell-muted,
.table .cell-sub {
    color: var(--ink-3);
}

.table .cell-sub {
    display: block;
    font-size: 12px;
}

.table .cell-wrap {
    min-width: 160px;
    max-width: 420px;
}

.table .cell-nowrap {
    white-space: nowrap;
}

.table .pct {
    display: block;
    color: var(--ink-3);
    font-size: 12px;
    line-height: 16px;
}

.table .crm-error,
.crm-tasks .crm-error {
    display: block;
}

/* --- Кнопки, поля, формы (поверх Basecoat) --------------------------------------- */

.btn {
    height: 36px;
    padding: 0 14px;
    gap: 8px;
    border-radius: var(--radius-control);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 120ms ease-out, color 120ms ease-out, box-shadow 120ms ease-out, transform 100ms ease-out;
}

.btn:active {
    transform: scale(0.98);
}

.btn:hover {
    text-decoration: none;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn:not([data-variant]),
.btn[data-variant="primary"] {
    background: var(--pine);
    color: var(--pine-ink);
}

.btn:not([data-variant]):hover,
.btn[data-variant="primary"]:hover {
    background: var(--pine-hover);
}

.btn[data-variant="outline"] {
    background: var(--paper);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    box-shadow: none;
}

.btn[data-variant="outline"]:hover {
    background: var(--paper-hover);
}

.btn[data-variant="ghost"] {
    color: var(--ink-2);
}

.btn[data-variant="destructive"] {
    background: var(--danger-wash);
    color: var(--danger);
}

.btn[data-size="icon"] {
    width: 36px;
    padding: 0;
}

.btn[data-size="sm"] {
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 420px;
}

.field--wide {
    max-width: 640px;
}

.field > label,
.field-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
}

.field > small,
.field-hint {
    font-size: 12.5px;
    color: var(--ink-3);
    line-height: 1.45;
}

.field > input,
.field > select,
.field > textarea,
.input,
.select,
.textarea {
    font: inherit;
    font-size: 14px;
    color: var(--ink);
    background-color: var(--paper-sunk);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-control);
    box-shadow: none;
}

.field > input,
.input:not([type="radio"]):not([type="checkbox"]),
.field > select,
select.select {
    height: 38px;
}

.field > input,
.input:not([type="radio"]):not([type="checkbox"]) {
    padding: 0 12px;
    width: 100%;
}

.field > select,
select.select {
    width: 100%;
}

.dark .field > input,
.dark .input:not([type="radio"]):not([type="checkbox"]),
.dark .field > select,
.dark select.select,
.dark .field > textarea,
.dark .textarea {
    background-color: var(--paper-sunk);
}

.field > input:focus-visible,
.field > select:focus-visible,
.field > textarea:focus-visible,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
    outline: none;
    border-color: var(--pine);
    box-shadow: 0 0 0 3px var(--pine-wash);
}

.field > textarea,
.textarea {
    padding: 10px 12px;
    line-height: 1.55;
    min-height: 160px;
    width: 100%;
    resize: vertical;
}

.field > input[type="file"] {
    height: auto;
    padding: 8px;
}

.field > input[type="file"]::file-selector-button {
    height: 28px;
    margin-right: 12px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: 5px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

.field-invalid > input,
.field-invalid > select {
    border-color: var(--danger);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 20px;
    max-width: 760px;
}

.form-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid .field {
    max-width: none;
}

.form-grid .span-2 {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.crm-inline-form {
    display: inline-flex;
    margin: 0;
}

/* Отмена кампании отодвинута от «Подтвердить запуск», чтобы не промахнуться */
.campaign-actions .campaign-cancel {
    margin-left: auto;
}

/* Радио и флажки */

.choice-group {
    border: 0;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.choice-group > legend {
    margin-bottom: 8px;
    padding: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
}

.choice-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.choice {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--paper);
    cursor: pointer;
    transition: border-color 120ms ease-out, background-color 120ms ease-out;
}

.choice:hover {
    border-color: var(--line-strong);
}

.choice:has(input:checked) {
    border-color: var(--pine);
    background: var(--pine-wash);
}

.choice input {
    accent-color: var(--pine);
    width: 16px;
    height: 16px;
    margin: 0;
    flex: none;
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
}

.month-grid .choice {
    justify-content: flex-start;
    padding: 8px 12px;
}

/* --- Сообщения ---------------------------------------------------------------- */

.crm-flash {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.crm-flash > li,
.crm-flash-error,
.crm-flash-info,
.crm-warning {
    display: block;
    padding: 12px 16px;
    border-radius: var(--radius-control);
    border: 1px solid var(--line);
    font-size: 14px;
    line-height: 1.5;
    background: var(--paper);
}

.crm-flash > li.crm-flash-success,
.crm-flash > li.crm-flash-info,
.crm-flash-info {
    color: var(--ok-ink);
    background: var(--ok-wash);
    border-color: transparent;
}

.crm-flash > li.crm-flash-error,
.crm-flash-error {
    color: var(--danger);
    background: var(--danger-wash);
    border-color: var(--danger-line);
}

.crm-flash > li.crm-flash-warning,
.crm-warning {
    color: var(--warn-ink);
    background: var(--warn-wash);
    border-color: var(--warn-line);
}

ul.crm-flash-error,
ul.crm-warning {
    list-style: disc;
    padding-left: 34px;
}

ul.crm-flash-error > li + li,
ul.crm-warning > li + li {
    margin-top: 4px;
}

.crm-flash-error > p + form,
.crm-flash-error > p + p,
.crm-flash-error > form + p {
    margin-top: 12px;
}

.crm-error {
    color: var(--danger);
    font-size: 12.5px;
}

.crm-caveat {
    color: var(--ink-3);
    font-size: 13px;
    max-width: 78ch;
}

/* --- Бейджи статусов ------------------------------------------------------------ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    background: var(--paper-sunk);
    color: var(--ink-2);
    border: 1px solid var(--line-soft);
    vertical-align: middle;
}

.badge[data-tone="ok"] {
    background: var(--ok-wash);
    color: var(--ok-ink);
    border-color: transparent;
}

.badge[data-tone="warn"] {
    background: var(--warn-wash);
    color: var(--warn-ink);
    border-color: transparent;
}

.badge[data-tone="danger"] {
    background: var(--danger-wash);
    color: var(--danger);
    border-color: transparent;
}

.badge[data-tone="ok"]::before,
.badge[data-tone="warn"]::before,
.badge[data-tone="danger"]::before,
.badge[data-tone="off"]::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge[data-tone="off"] {
    color: var(--ink-3);
}

/* --- Точки каналов атрибуции ---------------------------------------------------- */

.channel {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.channel::before {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--ink-4);
}

.channel[data-channel="campaigns"]::before { background: var(--channel-campaigns); }
.channel[data-channel="aggregators"]::before { background: var(--channel-aggregators); }
.channel[data-channel="organic"]::before { background: var(--channel-organic); }

/* --- Период дашборда ------------------------------------------------------------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 16px;
}

.crm-period-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    margin: 0;
}

.crm-period-form .field {
    width: 160px;
}

.crm-period-presets {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: 8px;
    background: var(--paper-sunk);
    border: 1px solid var(--line-soft);
}

.crm-period-presets a {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 12px;
    border-radius: 6px;
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.crm-period-presets a:hover {
    color: var(--ink);
    text-decoration: none;
    background: var(--paper-hover);
}

.crm-period-presets a[aria-current="true"] {
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 0 0 1px var(--line);
}

/* --- Итоги периода: сигнатурная полоса атрибуции и KPI --------------------------------- */

.outcome {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.outcome-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 16px;
}

.outcome-total {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.outcome-total-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-3);
}

.outcome-total-value {
    font-size: 32px;
    line-height: 40px;
    font-weight: 650;
    letter-spacing: -0.025em;
    font-variant-numeric: tabular-nums;
}

.split-bar {
    display: block;
    width: 100%;
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--paper-sunk);
}

.split-bar rect[data-channel="campaigns"] { fill: var(--channel-campaigns); }
.split-bar rect[data-channel="aggregators"] { fill: var(--channel-aggregators); }
.split-bar rect[data-channel="organic"] { fill: var(--channel-organic); }

.outcome-empty {
    margin: 0;
    font-size: 13px;
    color: var(--ink-3);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    border-top: 1px solid var(--line-soft);
    margin: 0 -20px -20px;
}

.kpi {
    display: grid;
    grid-template-areas:
        "label"
        "value"
        "sub"
        "extra";
    align-content: start;
    gap: 4px;
    padding: 16px 20px 20px;
    margin: 0;
}

.kpi + .kpi {
    border-left: 1px solid var(--line-soft);
}

.kpi-label {
    grid-area: label;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
}

.kpi-value {
    grid-area: value;
    font-size: 24px;
    line-height: 32px;
    font-weight: 650;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.kpi-sub {
    grid-area: sub;
    font-size: 13px;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

.kpi-extra {
    grid-area: extra;
    font-size: 12.5px;
    color: var(--ink-3);
}

.kpi-share {
    font-variant-numeric: tabular-nums;
    color: var(--ink-3);
}

/* Короткие показатели «подпись: значение» */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.stat {
    display: grid;
    grid-template-areas:
        "label"
        "value";
    gap: 2px;
    padding: 14px 16px;
    border-radius: 8px;
    background: var(--paper-sunk);
    margin: 0;
}

.stat-label {
    grid-area: label;
    font-size: 12.5px;
    color: var(--ink-3);
}

.stat-value {
    grid-area: value;
    font-size: 20px;
    line-height: 28px;
    font-weight: 600;
    letter-spacing: -0.015em;
    font-variant-numeric: tabular-nums;
}

.stat-value small {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0;
}

/* Список «подпись - значение» в строку */

.kv {
    display: flex;
    flex-direction: column;
}

.kv > p {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line-soft);
}

.kv > p:last-child {
    border-bottom: 0;
}

.kv-key {
    color: var(--ink-3);
}

.kv-value {
    text-align: right;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* --- Графики ------------------------------------------------------------------ */

.crm-chart-box {
    position: relative;
    height: 260px;
    width: 100%;
}

.chart-legend,
.panel-head > .chart-legend {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 12.5px;
    color: var(--ink-2);
}

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

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 20px;
    border: 1px dashed var(--line-strong);
    border-radius: 8px;
    color: var(--ink-3);
}

.empty-state > p {
    color: var(--ink-2);
}

.panel--flush > .empty-state {
    margin: 16px 20px 20px;
}

/* --- Предпросмотр сообщения --------------------------------------------------------- */

.crm-message-preview {
    white-space: pre-wrap;
    max-width: 44ch;
    padding: 12px 14px;
    border-radius: 12px 12px 12px 4px;
    background: var(--paper-sunk);
    border: 1px solid var(--line-soft);
    font-size: 14px;
    line-height: 1.55;
    color: var(--ink);
}

.message-frame {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    border-radius: 8px;
    background: var(--birch);
    border: 1px solid var(--line-soft);
}

.message-frame-label {
    font-size: 12px;
    color: var(--ink-3);
}

.var-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--ink-2);
}

.var-list li {
    display: flex;
    gap: 8px;
    align-items: baseline;
}

/* --- Списки --------------------------------------------------------------------- */

.plain-list {
    list-style: none;
    display: flex;
    flex-direction: column;
}

.plain-list > li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    min-height: var(--row-h);
    padding: 10px 0;
    border-bottom: 1px solid var(--line-soft);
}

.plain-list > li:last-child {
    border-bottom: 0;
}

.summary-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
}

.summary-list > li {
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--paper-sunk);
    font-weight: 500;
    color: var(--ink);
}

.bullet-list {
    list-style: disc;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--ink-2);
}

/* «Требует внимания» */

.attention-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.attention-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--warn-wash);
    border: 1px solid var(--warn-line);
    color: var(--warn-ink);
}

.attention-item strong {
    color: var(--ink);
}

.all-clear {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--ok-wash);
    color: var(--ok-ink);
    font-weight: 500;
}

.all-clear svg {
    width: 18px;
    height: 18px;
    flex: none;
}

/* Сценарии */

.crm-scenario-card .scenario-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.scenario-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 20px 32px;
}

.scenario-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

.scenario-form .field {
    flex: 1 1 220px;
    max-width: 300px;
}

.scenario-facts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    color: var(--ink-2);
}

/* Постраничная навигация */

.crm-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.crm-pagination a,
.crm-pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: var(--radius-control);
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
}

.crm-pagination a:hover {
    background: var(--paper-hover);
    text-decoration: none;
}

.crm-pagination a.crm-page-current {
    background: var(--paper);
    color: var(--ink);
    font-weight: 600;
    box-shadow: 0 0 0 1px var(--line-strong);
}

/* Поиск гостей */

.search-field {
    position: relative;
    max-width: 480px;
}

.search-field svg {
    position: absolute;
    left: 12px;
    top: 50%;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    color: var(--ink-3);
    pointer-events: none;
    z-index: 1;
}

.search-field .input.input {
    height: 42px;
    padding-left: 38px;
    background: var(--paper);
}

.search-hint {
    color: var(--ink-3);
    font-size: 13px;
}

/* Вход */

.login-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 28px;
}

.login-card .field {
    max-width: none;
}

.login-card .btn {
    width: 100%;
    height: 40px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

/* --- Адаптивность --------------------------------------------------------------- */

@media (max-width: 1100px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .kpi + .kpi {
        border-left: 0;
        border-top: 1px solid var(--line-soft);
    }

    .grid-2,
    .grid-3,
    .scenario-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: minmax(0, 1fr);
    }

    .crm-topbar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        height: 56px;
        padding: 0 12px 0 16px;
        background: var(--birch);
        border-bottom: 1px solid var(--line);
    }

    .crm-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 50;
        width: min(300px, 86vw);
        transform: translateX(-100%);
        /* Закрытая панель скрыта и от Tab: visibility выключается после выезда */
        visibility: hidden;
        transition: transform 220ms cubic-bezier(0.23, 1, 0.32, 1), visibility 0s linear 220ms;
        box-shadow: none;
    }

    .nav-open .crm-sidebar {
        transform: none;
        visibility: visible;
        transition-delay: 0s;
        box-shadow: 0 0 0 1px var(--line), 0 16px 48px rgba(0, 0, 0, 0.18);
    }

    /* Без JS (класс js ставит theme-init.js) меню стоит потоком над содержимым,
     * кнопка «Открыть меню» не нужна */
    html:not(.js) .crm-sidebar {
        position: static;
        width: auto;
        height: auto;
        transform: none;
        visibility: visible;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    html:not(.js) [data-nav-toggle] {
        display: none;
    }

    .nav-scrim {
        position: fixed;
        inset: 0;
        z-index: 40;
        background: rgba(10, 14, 12, 0.36);
        border: 0;
        opacity: 0;
        pointer-events: none;
        transition: opacity 200ms ease-out;
    }

    .nav-open .nav-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .crm-test-mode-banner {
        top: 56px;
    }

    .crm-main {
        padding: 20px 16px 48px;
        gap: 20px;
    }

    .panel {
        padding: 16px;
    }

    .panel.panel--flush {
        padding: 0;
    }

    .panel--flush > .panel-head,
    .panel--flush > .panel-body {
        padding-left: 16px;
        padding-right: 16px;
    }

    .panel > .table-container {
        margin: 0 -16px;
        width: calc(100% + 32px);
    }

    .panel > .table-container:last-child {
        margin-bottom: -16px;
    }

    .kpi-grid,
    .panel .bleed {
        margin: 0 -16px -16px;
    }

    .panel .bleed {
        width: calc(100% + 32px);
    }

    .table th:first-child,
    .table td:first-child {
        padding-left: 16px;
    }

    .table th:last-child,
    .table td:last-child {
        padding-right: 16px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .month-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .toolbar {
        align-items: stretch;
    }

    .crm-period-form .field {
        width: calc(50% - 4px);
    }

    h1 {
        font-size: 22px;
        line-height: 28px;
    }

    .outcome-total-value {
        font-size: 28px;
        line-height: 36px;
    }

    .attention-item {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (min-width: 901px) {
    .nav-scrim {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0ms !important;
        scroll-behavior: auto !important;
    }
}
