:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #172033;
    --text-muted: #667085;
    --text-soft: #8a94a6;
    --line: #e5e9f0;
    --line-strong: #d6dce7;
    --brand: #1457d9;
    --brand-hover: #0f46b6;
    --brand-soft: #eaf1ff;
    --navy: #172033;
    --navy-2: #253047;
    --success: #12805c;
    --danger: #b42318;
    --warning: #b54708;
    --radius-lg: 16px;
    --radius-md: 10px;
    --shadow-card: 0 18px 45px rgba(22, 32, 51, 0.08);
    --shadow-soft: 0 8px 24px rgba(22, 32, 51, 0.06);
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    min-width: 1120px;
    margin: 0;
    font-size: 15px;
    font-family: Inter, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at 18% -10%, rgba(20, 87, 217, 0.10), transparent 34rem),
        linear-gradient(180deg, #fbfcff 0, var(--bg) 340px);
    color: var(--text);
}

.app-shell {
    width: min(1680px, 100%);
    margin: 0 auto;
    padding: 28px 28px 40px;
}

.app-hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 22px;
}

.app-hero__eyebrow {
    margin: 0 0 8px;
    color: var(--brand);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.app-hero h1 {
    margin: 0;
    color: var(--text);
    font-size: 36px;
    line-height: 1.08;
    letter-spacing: 0;
}

.app-hero__subtitle {
    max-width: 760px;
    margin: 10px 0 0;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1.5;
}

.app-hero__meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 11px;
    border: 1px solid rgba(20, 87, 217, 0.18);
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 13px;
    font-weight: 800;
}

.status-pill--muted {
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.75);
    color: var(--text-muted);
}

.header {
    position: sticky;
    top: 12px;
    z-index: 50;
    background: rgba(255, 255, 255, 0.88);
    padding: 16px;
    border: 1px solid rgba(214, 220, 231, 0.85);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(18px);
    margin-bottom: 28px;
    display: flex;
    gap: 14px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group--preset {
    width: 100%;
}

.filter-group label {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-muted);
}

.filter-group input {
    height: 42px;
    padding: 9px 11px;
    font-size: 15px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.filter-group input:hover {
    border-color: #b9c3d3;
}

.filter-group input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(20, 87, 217, 0.12);
}

.filter-group input.date-input {
    min-width: 11em;
    font-variant-numeric: tabular-nums;
}

.filter-group input.input-pct {
    width: 5em;
    font-variant-numeric: tabular-nums;
}

.header-spacer {
    width: 20px;
    flex-shrink: 0;
}

.preset-group,
.delta-mode {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.preset-btn {
    min-height: 42px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-muted);
    box-shadow: none;
}

.preset-btn:hover,
.preset-btn.is-active {
    background: var(--brand-soft);
    color: var(--brand);
    box-shadow: none;
}

button {
    min-height: 42px;
    padding: 11px 19px;
    background: var(--brand);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 15px;
    font-weight: 800;
    transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
    background: var(--brand-hover);
    box-shadow: 0 10px 20px rgba(20, 87, 217, 0.18);
    transform: translateY(-1px);
}

button:focus-visible,
summary:focus-visible {
    outline: 3px solid rgba(20, 87, 217, 0.24);
    outline-offset: 2px;
}

button:active {
    transform: translateY(0);
}

.summary-panel {
    margin-bottom: 28px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.78);
    box-shadow: var(--shadow-soft);
}

.summary-panel[hidden] {
    display: none !important;
}

.summary-panel__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.summary-panel h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.25;
}

.summary-panel p {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 14px;
}

.delta-mode {
    justify-content: flex-end;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
}

.delta-mode label {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    gap: 5px;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.delta-mode input {
    accent-color: var(--brand);
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 12px;
}

.summary-card {
    min-height: 108px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
}

.summary-card__label {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 800;
}

.summary-card__value {
    margin-top: 10px;
    color: var(--text);
    font-size: 27px;
    line-height: 1.1;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.summary-card__delta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 9px;
    font-size: 13px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.summary-card__delta.is-good {
    color: var(--success);
}

.summary-card__delta.is-bad {
    color: var(--danger);
}

.summary-card__delta.is-flat {
    color: var(--text-soft);
}

.heatmap-legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 14px;
    color: var(--text-muted);
    font-size: 13px;
}

.heatmap-legend__title {
    color: var(--text);
    font-weight: 800;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 5px;
    border-radius: 50%;
    vertical-align: -1px;
}

.legend-dot--neutral {
    background: rgba(20, 87, 217, 0.22);
}

.legend-dot--good {
    background: rgba(18, 128, 92, 0.24);
}

.legend-dot--bad {
    background: rgba(180, 35, 24, 0.22);
}

/* overflow:hidden на table ломает position:sticky у шапки — скругление и тень на оболочке */
.table-shell {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    font-size: 15px;
    overflow-x: auto;
    overflow-y: visible;
}

.dashboard-section {
    margin-bottom: 32px;
}

.dashboard-section__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-bottom: 12px;
}

.dashboard-section__title {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
    font-weight: 700;
    color: var(--text);
}

.dashboard-section__toggle {
    min-height: 34px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 14px;
}

.dashboard-section__toggle:hover {
    background: var(--surface-muted);
    color: var(--text);
    box-shadow: none;
}

.dashboard-section.is-collapsed .dashboard-section__body {
    display: none;
}

.dashboard-empty-state {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 96px;
    padding: 22px 24px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.52);
    color: var(--text-muted);
}

.dashboard-empty-state strong {
    color: var(--text);
    font-size: 16px;
}

.dashboard-empty-state span {
    max-width: 620px;
    font-size: 15px;
    line-height: 1.45;
}

.dashboard-empty-state.is-hidden {
    display: none;
}

/* Дубликат шапки таблицы у верхнего края окна при прокрутке страницы */
.global-sticky-thead-host {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    pointer-events: none;
    box-shadow: 0 12px 26px rgba(22, 32, 51, 0.16);
}

.global-sticky-thead-host__scroll {
    overflow-x: auto;
    overflow-y: hidden;
    pointer-events: auto;
    background: var(--navy);
    -webkit-overflow-scrolling: touch;
}

.global-sticky-thead-table {
    margin: 0;
    display: table;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    /* не min-width:100% — иначе шапка растягивается на всю ширину окна шире таблицы */
}

/*
 * У этой таблицы тот же класс .report-table, что и у основных отчётов — чтобы совпали стили шапки.
 * Правило table.report-table { display: none } для «ещё не показанных» отчётов иначе скрывало бы всю липкую шапку.
 * width: 100% у отчётов здесь отключаем — ширина задаётся из JS по фактической таблице.
 */
#global-sticky-thead-table.report-table {
    display: table !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
}

.global-sticky-thead-table thead th {
    position: static;
}

.global-sticky-thead-table thead th:first-child {
    border-top-left-radius: 0;
}

.global-sticky-thead-table thead th:last-child {
    border-top-right-radius: 0;
}

td.dashboard-empty-cell {
    text-align: left;
    color: var(--text-muted);
    font-size: 14px;
    padding: 20px 14px;
    background: var(--surface-muted);
}

/* Таргет: группа и вложенные кампании */
tr.row-targeted-group td {
    background: #f7f9fd;
    font-weight: 700;
}

/*
 * Список кампаний группы — отдельная область прокрутки: колёсико над блоком крутит только его,
 * вне блока — прокрутка страницы (overscroll-behavior: contain).
 */
.td-campaigns-scroll-wrap {
    padding: 0 !important;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    background: var(--surface);
}

.targeted-campaign-scroll {
    max-height: min(52vh, 520px);
    overflow-y: auto;
    overflow-x: auto;
    overscroll-behavior: contain;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    box-sizing: border-box;
}

.targeted-campaign-inner-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    font-size: 14px;
    margin: 0;
}

.targeted-campaign-inner-table th,
.targeted-campaign-inner-table td {
    padding: 10px 10px;
    text-align: right;
    border-bottom: 1px solid var(--line);
    border-left: 1px solid #edf1f6;
    overflow-wrap: break-word;
    word-break: break-word;
}

.targeted-campaign-inner-table td:first-child {
    text-align: left;
    border-left: none;
}

.group-expand-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 8px 0 0;
    padding: 0;
    min-width: 26px;
    min-height: 24px;
    font-size: 14px;
    line-height: 1;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.group-expand-btn:hover {
    background: var(--brand-soft);
    color: var(--brand);
    box-shadow: none;
}

.cell-group-label {
    white-space: normal;
    vertical-align: middle;
}

.td-campaign-nested {
    padding-left: 22px !important;
    box-shadow: inset 3px 0 0 #cdd6e5;
}

table.report-table {
    display: none;
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
}

/*
 * Начальные доли ширины колонок (сумма 100%). То же для «Без статистики».
 * Порядок: Кампания, Показы, Клики, CTR, Расход, CPC, Заказы, Выкупы, CR, Ср. чек, Выручка, Сумма по заказам, ДРР.
 */
/* Кампания */
.table-shell > table col:nth-child(1) {
    width: 18%;
}

/* Показы */
.table-shell > table col:nth-child(2) {
    width: 10%;
}

/* Клики */
.table-shell > table col:nth-child(3) {
    width: 7%;
}

/* CTR */
.table-shell > table col:nth-child(4) {
    width: 4%;
}

/* Расход */
.table-shell > table col:nth-child(5) {
    width: 9%;
}

/* CPC */
.table-shell > table col:nth-child(6) {
    width: 5%;
}

/* Заказы */
.table-shell > table col:nth-child(7) {
    width: 5%;
}

/* Выкупы */
.table-shell > table col:nth-child(8) {
    width: 5%;
}

/* CR */
.table-shell > table col:nth-child(9) {
    width: 4%;
}

/* Ср. чек */
.table-shell > table col:nth-child(10) {
    width: 6%;
}

/* Выручка */
.table-shell > table col:nth-child(11) {
    width: 8%;
}

/* Сумма по заказам */
.table-shell > table col:nth-child(12) {
    width: 13%;
}

/* ДРР */
.table-shell > table col:nth-child(13) {
    width: 6%;
}

/*
 * Шапка в потоке документа; «липкость» к верху экрана — у #global-sticky-thead-host (см. app.js),
 * с переключением контекст / таргет при прокрутке.
 */
table.report-table thead th {
    /* relative — контекст для .col-resize-handle (absolute); static ломал привязку ручки к ячейке */
    position: relative;
    background: var(--navy);
    color: #fff;
    box-shadow: none;
    vertical-align: middle;
    min-width: 0;
    padding: 13px 14px 13px 10px;
    overflow: visible;
}

table.report-table thead .th-wrap {
    display: flex;
    flex-flow: row wrap;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

table.report-table thead th:first-child .th-wrap {
    justify-content: flex-start;
}

table.report-table thead .th-label {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    line-height: 1.25;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
    text-align: center;
    font-size: 13px;
    letter-spacing: 0.01em;
}

table.report-table thead th:first-child .th-label {
    text-align: left;
}

table.report-table thead .th-sort-btns {
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    align-self: flex-start;
    gap: 3px;
    flex: 0 0 auto;
}

table.report-table thead .th-sort-btn {
    margin: 0;
    min-height: 22px;
    padding: 0 6px;
    font-size: 10px;
    line-height: 1.15;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
}

table.report-table thead .th-sort-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    box-shadow: none;
    transform: none;
}

table.report-table thead .th-sort-btn.is-active {
    background: rgba(255, 255, 255, 0.26);
    border-color: #fff;
    font-weight: bold;
}

table.report-table .col-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    margin-right: -7px;
    height: 100%;
    cursor: col-resize;
    z-index: 8;
    touch-action: none;
    box-sizing: border-box;
}

table.report-table .col-resize-handle:hover {
    background: rgba(255, 255, 255, 0.16);
}

body.is-col-resizing {
    cursor: col-resize;
    user-select: none;
}

body.is-col-resizing * {
    cursor: col-resize !important;
}

table.report-table thead th:first-child {
    border-top-left-radius: var(--radius-lg);
}

table.report-table thead th:last-child {
    border-top-right-radius: var(--radius-lg);
}

table.report-table tbody tr:last-child td:first-child {
    border-bottom-left-radius: var(--radius-lg);
}

table.report-table tbody tr:last-child td:last-child {
    border-bottom-right-radius: var(--radius-lg);
}

thead {
    color: white;
}

th,
td {
    padding: 14px 11px;
    text-align: right;
    border-bottom: 1px solid var(--line);
    border-left: 1px solid #edf1f6;
    overflow-wrap: break-word;
    word-break: break-word;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

th {
    text-align: center;
}

th:first-child,
td:first-child {
    text-align: left;
    border-left: none;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

tr.row-total td {
    border-top: 0;
    border-bottom: 2px solid var(--navy);
    background: #eef3fb;
    font-weight: bold;
}

tbody tr:not(.row-total):hover td {
    background-color: #f8fbff !important;
}

.diff-pos {
    color: var(--success);
    font-size: 13px;
    font-weight: bold;
    margin-left: 5px;
}

.diff-neg {
    color: var(--danger);
    font-size: 13px;
    font-weight: bold;
    margin-left: 5px;
}

.diff-pct {
    font-size: 12px;
    font-weight: bold;
    margin-left: 2px;
    white-space: nowrap;
}

/* Три строки в метрике: значение P2 → |Δ| → % к P1 */
.metric-cell-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    line-height: 1.3;
}

.metric-cell-stack .metric-cell-value {
    font-weight: 700;
    color: var(--text);
}

.metric-cell-stack .metric-cell-abs,
.metric-cell-stack .metric-cell-pct {
    font-size: 13px;
    font-weight: bold;
    margin-left: 0;
}

.metric-cell-stack .diff-zero,
.metric-cell-stack .diff-na {
    color: var(--text-soft);
}

.loading {
    width: fit-content;
    min-width: 280px;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    display: none;
    margin: 20px auto;
    padding: 12px 18px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.no-stats-panel {
    margin-top: 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 0 16px 16px;
}

.no-stats-panel[hidden] {
    display: none !important;
}

.no-stats-summary {
    cursor: pointer;
    font-weight: 800;
    font-size: 16px;
    padding: 14px 0;
    list-style: none;
    user-select: none;
}

.no-stats-summary::-webkit-details-marker {
    display: none;
}

.no-stats-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    font-size: 13px;
    font-weight: bold;
    background: var(--brand-soft);
    border-radius: 999px;
    color: var(--brand);
    vertical-align: middle;
}

.no-stats-hint {
    font-size: 14px;
    color: var(--text-muted);
    margin: -4px 0 12px;
    line-height: 1.35;
}

.no-stats-container {
    margin-top: 4px;
}

.no-stats-table-shell {
    margin-top: 0;
}

.no-stats-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    font-size: 14px;
}

.no-stats-table thead th {
    position: static;
    background: var(--navy-2);
    color: #fff;
    box-shadow: none;
    vertical-align: middle;
    border-radius: 0 !important;
}

.no-stats-table th,
.no-stats-table td {
    padding: 10px 8px;
    text-align: right;
    border-bottom: 1px solid var(--line);
    border-left: 1px solid #edf1f6;
}

@media (max-width: 1280px) {
    .app-shell {
        padding: 22px 18px 32px;
    }

    .app-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .header {
        position: static;
    }

    .filter-group--preset {
        min-width: 100%;
    }

    .summary-panel__head {
        flex-direction: column;
    }

    .summary-cards {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }
}

.no-stats-table th:first-child,
.no-stats-table td:first-child {
    text-align: left;
    border-left: none;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}
