:root {
    --brand: #6b9d6a;
    --bg: #f6f7f5;
    --panel: #ffffff;
    --ink: #1c1e1a;
    --muted: #6d7470;
    --line: #e5e8e3;
    --lead: #dfe8f4;
    --qual: #c5dbf1;
    --meeting: #b2e0b8;
    --deal: #8fc998;
    --junk: #f2b8b5;
    --unqual: #eed9b8;
    --other: #e5e8e3;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
.topbar {
    display: flex; align-items: center; gap: 24px;
    padding: 14px 28px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; color: var(--brand); text-decoration: none; letter-spacing: .3px; }
.logo img { display: block; width: 116px; height: 28px; object-fit: contain; }
.topbar nav { display: flex; gap: 16px; }
.topbar nav a {
    color: var(--ink); text-decoration: none; padding: 6px 10px; border-radius: 6px;
}
.topbar nav a.active { background: var(--brand); color: #fff; }
.topbar nav a:not(.active):hover { background: var(--line); }

/* Контент на всю ширину экрана (раньше был зажат в 1200px по центру). */
main { padding: 24px 28px; max-width: none; margin: 0; }
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 20px 24px;
    margin-bottom: 20px;
}
h2 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; margin-left: 8px; }
.mono { font-family: SF Mono, Menlo, Consolas, monospace; font-size: 12px; }
.strong { font-weight: 600; }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.toolbar label { display: flex; gap: 6px; align-items: center; }
input[type="date"], select {
    padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px;
    background: #fff; font: inherit;
}
.btn {
    padding: 7px 14px; border-radius: 6px;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    text-decoration: none; cursor: pointer; font: inherit;
}
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { filter: brightness(.95); }

.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }
.basis-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.basis-toggle a { padding: 6px 13px; font-size: 13px; color: var(--ink); text-decoration: none; background: #fff; white-space: nowrap; }
.basis-toggle a + a { border-left: 1px solid var(--line); }
.basis-toggle a.active { background: var(--brand); color: #fff; }
.basis-toggle a:not(.active):hover { background: #f1f4ef; }

.headline { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px; }
.headline-cell {
    padding: 22px 24px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: linear-gradient(180deg, #fafbf9 0%, #f1f4ef 100%);
}
.headline-name { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.headline-count { font-size: 40px; font-weight: 700; line-height: 1.1; margin-top: 4px; }
.headline-extra { font-size: 13px; color: var(--muted); margin-top: 2px; }
.headline-cell.cash { background: linear-gradient(180deg, #eaf5ea 0%, #d3e8d0 100%); border-color: var(--brand); }
.headline-cell.drr { background: linear-gradient(180deg, #fdf6ec 0%, #f6e7cf 100%); border-color: #e0b877; }
.headline-extra a { color: inherit; text-decoration: none; border-bottom: 1px dashed currentColor; }
.hint { margin-top: 14px; font-size: 12px; }
.hint code { background: #eee; padding: 2px 5px; border-radius: 3px; font-size: 11px; }
.how-to-read { margin-top: 14px; }
.how-to-read > summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 0; list-style-position: inside; width: fit-content; }
.how-to-read[open] > summary { margin-bottom: 4px; }
.how-to-read > .hint:first-of-type { margin-top: 6px; }

.funnel { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.funnel-cell { padding: 14px; border-radius: 8px; text-align: center; }
.funnel-cell .cat-name { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.funnel-cell .cat-count { font-size: 28px; font-weight: 700; margin: 4px 0; }
.funnel-cell .cat-opp { font-size: 12px; color: var(--muted); }
.cat-lead    { background: var(--lead); }
.cat-qual    { background: var(--qual); }
.cat-meeting { background: var(--meeting); }
.cat-deal    { background: var(--deal); color: #fff; }
.cat-junk    { background: var(--junk); }
.cat-unqual  { background: var(--unqual); }
.cat-other   { background: var(--other); }

table.grid { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.grid th, table.grid td {
    padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left;
}
table.grid th { font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Колонки не переносятся и не сжимаются - ровные ряды (особенно широкая «По каналам»). */
table.grid th, table.grid td { white-space: nowrap; }
/* «По каналам» широкая (14 колонок) - на узкой панели Выручка/ROMI обрезались краем.
   Оборачиваем в .table-scroll: появляется горизонтальная прокрутка, ничего не режется. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 8px; }
.table-scroll table.grid { margin-top: 0; }
.chan-table { table-layout: auto; }
.chan-table th, .chan-table td { padding: 8px 9px; overflow: hidden; text-overflow: ellipsis; }
.chan-table td.num, .chan-table th.num { width: 1%; }   /* числовые - по содержимому, имя канала тянется */
.chan-table tbody tr.lvl1:hover, .chan-table tbody tr.lvl2:hover { background: #f7f9f5; }
.chan-table .caret { display: inline-block; width: 12px; color: var(--muted); font-size: 11px; }
/* Ширина колонок мышкой: грип у правого края заголовка (потяни; двойной клик - сброс к авто). */
.chan-table thead th { position: relative; }
.chan-table thead th .col-resizer {
    position: absolute; top: 0; right: 0; z-index: 3;
    width: 9px; height: 100%; cursor: col-resize; user-select: none;
}
.chan-table thead th .col-resizer::after {
    content: ""; position: absolute; top: 22%; right: 3px;
    height: 56%; width: 2px; border-radius: 1px; background: transparent;
}
.chan-table thead th .col-resizer:hover::after,
.chan-table thead th .col-resizer.dragging::after { background: var(--brand); }
/* первая колонка (Канал) прилипает слева - название видно, когда прокручиваешь к ROMI */
.chan-table th:first-child, .chan-table td:first-child {
    position: sticky; left: 0; z-index: 2; background: var(--panel);
    box-shadow: 1px 0 0 var(--line);
}
.chan-table tbody tr.lvl1:hover td:first-child,
.chan-table tbody tr.lvl2:hover td:first-child { background: #f7f9f5; }
.chan-table tfoot .total-row td:first-child { background: #f4f6f2; }

table.grid tfoot .total-row td {
    border-top: 2px solid var(--ink);
    border-bottom: none;
    background: #f4f6f2;
    font-weight: 700;
    padding-top: 10px;
    padding-bottom: 10px;
}

.save-status { display: inline-block; margin-left: 8px; font-size: 14px; }

a.drilldown {
    color: var(--brand);
    text-decoration: none;
    border-bottom: 1px dashed rgba(107,157,106,0.5);
}
a.drilldown:hover { border-bottom-style: solid; }

.flash {
    padding: 10px 14px; background: #eaf5ea; border-left: 3px solid var(--brand);
    border-radius: 4px; margin-bottom: 14px;
}

/* ── Баннер режима админа (impersonation, СК 4.2.3) ─────────────── */
.impersonate-banner {
    position: sticky; top: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center; gap: 16px;
    padding: 11px 16px;
    background: #f97316;
    color: #fff;
    font-size: 14px; font-weight: 600;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.impersonate-banner form { margin: 0; }
.impersonate-banner .btn {
    padding: 5px 14px; background: #fff; color: #9a3412;
    border: none; font-weight: 700; white-space: nowrap;
}
.impersonate-banner .btn:hover { background: #fff7ed; }
/* Постоянная оранжевая рамка вокруг всего окна — видно что ты в чужом кабинете
   даже при скролле, на любой вкладке. pointer-events:none — не мешает кликам. */
body.impersonating::before {
    content: ""; position: fixed; inset: 0; z-index: 2000;
    border: 3px solid #f97316; pointer-events: none;
}

/* Колонка действий в таблице тенантов: кнопки в ряд. */
.row-actions { display: flex; gap: 8px; align-items: center; }
.row-actions form { margin: 0; }

/* ── Профиль в шапке ───────────────────────────────────────────── */
.profile {
    margin-left: auto; display: flex; align-items: center; gap: 14px;
    font-size: 13px; color: var(--muted);
}
.profile-email { color: var(--ink); font-weight: 600; }
.profile-logout { margin: 0; }
.profile-link {
    color: var(--muted); text-decoration: none; cursor: pointer;
}
.profile-link:hover { color: var(--ink); }
.profile-link.as-link {
    background: none; border: none; padding: 0; font: inherit;
}

/* ── Страница входа ────────────────────────────────────────────── */
.auth-body {
    background: #fff; min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
}
.auth-card {
    width: 100%; max-width: 340px; padding: 8px 4px;
    text-align: center;
}
.auth-brand {
    font-size: 20px; font-weight: 700; color: var(--brand);
    margin-bottom: 28px; letter-spacing: .3px;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; }
.auth-form label span { font-size: 13px; color: var(--muted); }
.auth-form input {
    padding: 9px 12px; border: 1px solid var(--line); border-radius: 6px;
    background: #fff; font: inherit;
}
.auth-form input:focus { outline: none; border-color: var(--brand); }
.btn-primary {
    background: var(--brand); color: #fff; border-color: var(--brand);
}
.btn-primary:hover { filter: brightness(0.95); }
.auth-submit { margin-top: 6px; padding: 10px; }
.auth-error {
    padding: 9px 12px; background: #fdeceb; border-left: 3px solid #d6584f;
    border-radius: 4px; margin-bottom: 16px; color: #a03028; font-size: 13px;
    text-align: left;
}
.auth-ok {
    padding: 9px 12px; background: #eaf5ea; border-left: 3px solid var(--brand);
    border-radius: 4px; margin-bottom: 16px; font-size: 13px;
}
.auth-hint {
    margin-top: 22px; font-size: 12px; color: var(--muted);
}

/* ── Публичные legal-страницы для модерации интеграций ─────────── */
.legal-body {
    background: var(--bg);
    min-height: 100vh;
}
.legal-page {
    max-width: 880px;
    padding: 36px 24px 44px;
}
.legal-logo {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
    text-decoration: none;
    font-weight: 700;
    margin-bottom: 20px;
}
.legal-logo img {
    height: 28px;
    display: block;
}
.legal-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 28px 32px;
}
.legal-kicker {
    margin: 0 0 8px;
    color: var(--brand);
    font-weight: 700;
    font-size: 13px;
}
.legal-card h1 {
    margin: 0 0 6px;
    font-size: 28px;
    line-height: 1.2;
}
.legal-updated {
    margin: 0 0 24px;
    color: var(--muted);
    font-size: 13px;
}
.legal-card h2 {
    margin: 22px 0 8px;
    font-size: 16px;
}
.legal-card p {
    margin: 0 0 10px;
    color: #30342f;
}
.legal-card a,
.legal-links a {
    color: var(--brand);
}
.legal-links {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 16px;
    font-size: 13px;
}
