/* ==========================================================================
   БРЕНД — все цвета и шрифт правятся здесь (брендбук Vynohradov Agency).
   Остальной файл использует только эти переменные.
   ========================================================================== */
:root {
  color-scheme: light;

  /* Палитра брендбука */
  --brand-blue: #0000c2;
  --brand-lime: #bbf543;
  --brand-dark: #404040;
  --brand-white: #ffffff;
  --brand-blue-soft: #e8e8fb;   /* светло-синий: трек полосы, ховеры */

  /* Поверхности и текст */
  --bg: #f2f2f0;                /* фон страницы */
  --surface-1: var(--brand-white);
  --border: #e6e6e2;
  --grid: #ececea;              /* сетка графиков */
  --text-primary: var(--brand-dark);
  --text-secondary: #6b6b6b;
  --text-muted: #767676;
  --text-on-blue: var(--brand-white);
  --text-on-blue-muted: rgba(255, 255, 255, .75);
  --text-on-lime: var(--brand-blue);
  --accent: var(--brand-blue);
  --error: #c62828;
  --notice-bg: var(--brand-white);
  --notice-border: var(--brand-lime);

  /* Каналы: акцент-бар карточки, линии графиков, полоса структуры */
  --channel-total: var(--brand-dark);
  --channel-site: var(--brand-blue);
  --channel-instagram: var(--brand-lime);
  --channel-tiktok: #d6124a;          /* TikTok: малиновый, отличим и от синего, и от лаймового */
  --channel-tiktok-on-blue: #ff9ab4;  /* подпись TikTok на синей плашке */
  --channel-google: #0f9d8a;          /* Google (только расходы): бирюзовый, не путается с бюджетом-оранжевым */
  --channel-google-on-blue: #7fe3d3;
  /* График «Продажі та бюджет»: бюджет — контрастный к синему цвет затрат */
  --chart-revenue: var(--brand-blue);
  --chart-budget: #f26b1d;
  /* «Середній чек по каналах»: загальний — оранжевый пунктир, отдельно от бюджета */
  --chart-avg-total: #ff9500;
  --text-on-orange: var(--brand-dark);
  --chart-line-width: 2.5;

  /* Шрифт */
  --font: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --weight-heading: 800;        /* Montserrat ExtraBold */
  --weight-strong: 700;
  --weight-medium: 500;

  /* Геометрия */
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --sidebar-width: 72px;
  --gutter: 28px;
}

/* ==========================================================================
   База
   ========================================================================== */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--bar-h, 0px) + 12px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; }
p { margin: 0; }
.muted { color: var(--text-muted); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Сайдбар (десктоп)
   ========================================================================== */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 24px 0; background: var(--brand-blue); color: var(--text-on-blue);
}
.sidebar-nav { display: flex; flex-direction: column; gap: 14px; }
.nav-icon {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 1.5px solid var(--text-on-blue-muted); border-radius: var(--radius-sm); color: var(--text-on-blue);
}
.nav-icon:hover { background: rgba(255, 255, 255, .12); }
.nav-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-logo { width: 40px; height: 40px; display: block; }

.page { margin-left: var(--sidebar-width); padding: var(--gutter); max-width: calc(1280px + var(--sidebar-width)); }

/* ==========================================================================
   Шапка
   ========================================================================== */
.topbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 16px 24px; margin-bottom: 18px; }
.title-block { display: flex; align-items: center; gap: 14px; min-width: 0; }
.title-logo, .title-block > .logo-link { display: none; }
.title-text { min-width: 0; }
.page-title { font-size: 26px; line-height: 1.15; font-weight: var(--weight-heading); text-transform: uppercase; letter-spacing: .01em; }
.project-name { font-size: 14px; font-weight: var(--weight-medium); color: var(--text-secondary); margin-top: 4px; }
#project-select {
  margin-top: 6px; max-width: 100%; padding: 6px 32px 6px 12px; cursor: pointer;
  font-weight: var(--weight-medium); color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-pill);
}
#project-select[hidden], .project-name[hidden] { display: none; }
.project-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.project-row #project-select { margin-top: 0; }
.project-row .project-name { margin-top: 0; }
.title-text .project-row { margin-top: 6px; }

/* Кнопка «+» — новий проєкт (только у кого есть право projects.create) */
.add-project-btn {
  flex: none; display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; cursor: pointer;
  color: var(--accent); background: var(--surface-1); border: 1px solid var(--border); border-radius: 50%;
  transition: border-color .15s, background .15s, color .15s;
}
.add-project-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.add-project-btn:hover { background: var(--brand-blue); border-color: var(--brand-blue); color: var(--text-on-blue); }
.add-project-btn[hidden] { display: none; }

/* Модальное окно «Новий проєкт» */
.modal {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; overflow: auto;
  color: var(--text-primary); background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .2);
}
.modal::backdrop { background: rgba(20, 20, 40, .45); }
.modal-body { display: flex; flex-direction: column; gap: 16px; padding: 22px 24px 24px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.access-note {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; font-size: 13px;
  background: var(--brand-blue-soft); border-left: 4px solid var(--brand-blue); border-radius: var(--radius-sm);
}
.access-note-title { font-weight: var(--weight-heading); color: var(--accent); }
.access-email { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 2px; }
.access-email code {
  min-width: 0; overflow-wrap: anywhere; padding: 6px 10px; font: 600 13px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-primary); background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; user-select: all;
}
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field-label { padding: 0; font-size: 12px; font-weight: var(--weight-strong); color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.field-hint { font-size: 12px; color: var(--text-muted); }
.field input[type="url"], .field input[type="text"] {
  width: 100%; min-height: 40px; padding: 8px 12px; font-size: 14px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.field input:focus { outline: none; border-color: var(--accent); }
.field input[type="date"] { align-self: flex-start; }
.primary-btn {
  align-self: flex-start; min-height: 40px; padding: 8px 20px; cursor: pointer;
  font-weight: var(--weight-strong); color: var(--text-on-blue); background: var(--brand-blue);
  border: 0; border-radius: var(--radius-pill);
}
.primary-btn:hover { filter: brightness(1.15); }
.primary-btn:disabled { cursor: progress; opacity: .6; }
.ap-details { display: flex; flex-direction: column; gap: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.ap-details[hidden] { display: none; }
.ap-found { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.ap-found-title { font-weight: var(--weight-strong); overflow-wrap: anywhere; }
.ap-channels { display: flex; flex-wrap: wrap; gap: 8px; }
.ap-channels label {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; cursor: pointer; font-weight: var(--weight-medium);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
}
.ap-channels label:has(input:checked) { border-color: var(--accent); color: var(--accent); background: var(--brand-blue-soft); }
.ap-channels input { accent-color: var(--brand-blue); margin: 0; }
.ap-warning, .ap-error { padding: 10px 14px; font-size: 13px; border-radius: var(--radius-sm); }
.ap-warning { background: #fff6e5; border-left: 4px solid #ff9500; }
.ap-error { color: #9b1c1c; background: #fdecec; border-left: 4px solid #d93025; }
.ap-warning[hidden], .ap-error[hidden] { display: none; }
@media (max-width: 600px) { .modal-body { padding: 18px 16px 20px; } }

.topbar-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.user-block { position: relative; }
.user-block[hidden] { display: none; }
.user-btn {
  display: inline-flex; align-items: center; gap: 10px; padding: 4px 14px 4px 4px; cursor: pointer; text-align: left;
  font: inherit; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-pill);
  transition: border-color .15s;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { border-color: var(--accent); }
.user-btn .avatar[hidden] + .user-info { padding-left: 10px; }
.user-btn .chevron { flex: none; color: var(--text-muted); transition: transform .15s; }
.user-btn[aria-expanded="true"] .chevron { transform: rotate(180deg); color: var(--accent); }
.user-info { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-name { font-size: 14px; font-weight: var(--weight-heading); color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; font-weight: var(--weight-medium); color: var(--text-secondary); margin-top: 2px; }
.user-role[hidden] { display: none; }
.avatar { flex: none; border-radius: 50%; object-fit: cover; }
.avatar[hidden] { display: none; }
.user-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50; min-width: 220px; padding: 8px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
}
.user-menu[hidden] { display: none; }
.user-menu-handle { padding: 6px 10px 8px; font-size: 13px; color: var(--text-secondary); border-bottom: 1px solid var(--border); }
.user-menu-handle[hidden] { display: none; }
.user-menu-section { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.user-menu-label { font-size: 11px; font-weight: var(--weight-medium); color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.user-menu-projects { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; font-weight: var(--weight-strong); color: var(--text-primary); }
.user-menu-projects li + li { margin-top: 4px; }
.user-menu-item {
  display: block; width: 100%; margin-top: 6px; padding: 8px 10px; cursor: pointer; text-align: left;
  font: inherit; font-size: 13px; font-weight: var(--weight-medium); color: var(--text-primary);
  background: none; border: 0; border-radius: var(--radius-sm);
}
.user-menu-item:hover { background: var(--brand-blue-soft); color: var(--accent); }
a.user-menu-item { text-decoration: none; }
.user-menu-item[hidden] { display: none; }
.text-btn {
  cursor: pointer; font-size: 13px; font-weight: var(--weight-medium); padding: 5px 14px;
  color: var(--text-primary); background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-pill);
}
.text-btn:hover { border-color: var(--accent); color: var(--accent); }

.date-pills { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; }
.range { display: inline-flex; align-items: center; gap: 6px; }
.range[hidden] { display: none; }
.range-label[hidden] { display: none; }
/* Режим «Місяць»: у даты нет своих стрелок — ими листается название месяца рядом. */
.range.date-only .icon-btn { display: none; }
.month-label { justify-content: center; min-width: 150px; white-space: nowrap; }
.pill, input[type="date"] {
  display: inline-flex; align-items: center; min-height: 38px; padding: 7px 16px;
  font-size: 13px; font-weight: var(--weight-strong); color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.pill:empty { display: none; }
.icon-btn {
  width: 38px; height: 38px; cursor: pointer; font-size: 18px; line-height: 1;
  color: var(--text-primary); background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ==========================================================================
   Период
   ========================================================================== */
.filters { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 18px; }
/* Панель периода всегда на экране: тип периода + даты. */
#period-bar {
  position: sticky; top: 0; z-index: 5;
  margin-inline: calc(-1 * var(--gutter)); padding: 10px var(--gutter); background: var(--bg);
  transition: box-shadow .15s;
}
/* Прилипшая панель без подложки (как на телефоне): видны только кнопки и поля, промежутки пропускают клики к контенту. */
#period-bar.stuck { background: transparent; pointer-events: none; }
#period-bar.stuck :is(button, input, .pill) { pointer-events: auto; box-shadow: 0 2px 8px rgba(0, 0, 0, .14); }
/* Под кнопками — затемнение с размытием, плавно уходящее вниз, чтобы белые кнопки читались поверх дашборда. */
#period-bar.stuck::before {
  content: ""; position: absolute; inset: 0 0 -14px; z-index: -1; pointer-events: none;
  background: rgba(10, 12, 40, .42); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent); mask-image: linear-gradient(to bottom, #000 72%, transparent);
}
#period-bar.stuck #custom-controls .muted { color: var(--text-on-blue); }
.filters-label { display: none; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  cursor: pointer; padding: 8px 18px; font-size: 13px; font-weight: var(--weight-medium);
  color: var(--text-primary); background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.segmented button:hover { border-color: var(--accent); }
.segmented button[aria-pressed="true"] { background: var(--brand-blue); border-color: var(--brand-blue); color: var(--text-on-blue); font-weight: var(--weight-strong); }
.sync { color: var(--text-muted); font-size: 12px; }

.notice {
  margin: 0 0 18px; padding: 12px 16px; background: var(--notice-bg);
  border: 1px solid var(--border); border-left: 5px solid var(--notice-border); border-radius: var(--radius-sm);
}

/* ==========================================================================
   Hero — главный результат (синий блок)
   ========================================================================== */
.hero {
  display: grid; grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr)); gap: 0;
  margin-bottom: 22px; padding: 24px 26px; border-radius: var(--radius);
  background: var(--brand-blue); color: var(--text-on-blue);
}
.hero:empty { display: none; }
.hero-main { padding-right: 24px; }
.hero-label { font-size: 12px; font-weight: var(--weight-heading); text-transform: uppercase; letter-spacing: .08em; }
.hero-value { font-size: 40px; line-height: 1.15; font-weight: var(--weight-heading); margin: 10px 0 6px; overflow-wrap: anywhere; }
.hero-caption { font-size: 13px; color: var(--text-on-blue-muted); }
/* На мобильном KPI-колонки заменяет одна строка: «Замовлення 567 · Середній чек … · ROAS …». */
.hero-caption-mobile { display: none; margin-top: 8px; font-size: 12px; color: var(--text-on-blue-muted); }
.hero-kpi { padding: 0 20px; border-left: 1px solid rgba(255, 255, 255, .25); display: flex; flex-direction: column; min-width: 0; }
.hero-kpi-label { font-size: 13px; color: var(--text-on-blue-muted); }
.hero-kpi-value { font-size: 24px; font-weight: var(--weight-heading); margin-top: 10px; overflow-wrap: anywhere; }
.hero-pills { justify-content: center; gap: 10px; }
.hero-pills-mobile { display: none; }
.hero-romi {
  padding: 7px 14px; text-align: center; white-space: nowrap;
  font-size: 13px; font-weight: var(--weight-heading); border-radius: var(--radius-pill);
  background: var(--brand-lime); color: var(--text-on-lime);
}

/* ==========================================================================
   Карточки каналов
   ========================================================================== */
.cards { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.card { min-width: 0; padding: 20px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { font-size: 18px; font-weight: var(--weight-heading); }
.accent { flex: none; width: 5px; height: 22px; border-radius: 3px; background: var(--channel-total); }
.accent.s1 { background: var(--channel-site); }
.accent.s2 { background: var(--channel-instagram); }
.accent.s3 { background: var(--channel-tiktok); }
.accent.s4 { background: var(--channel-google); }

.card-revenue { padding-bottom: 14px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.card-revenue-label { font-size: 12px; color: var(--text-secondary); }
.card-revenue-value { font-size: 28px; line-height: 1.2; font-weight: var(--weight-heading); overflow-wrap: anywhere; }

.kpis { display: none; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 14px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.kpi-label { font-size: 11px; font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); }
.kpi-label[title] { cursor: help; }
.kpi-value { font-size: 24px; line-height: 1.2; font-weight: var(--weight-heading); color: var(--brand-blue); overflow-wrap: anywhere; }

.rows { margin: 0; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 4px 0; }
.row dt { color: var(--text-secondary); }
.row dt[title] { cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }
.row dd { margin: 0; text-align: right; font-weight: var(--weight-strong); white-space: nowrap; }
.rows .sep { border-top: 1px solid var(--border); margin: 8px 0; }
/* Одна сводная карточка на всю ширину — показатели в две колонки, чтобы не тянуть строки через весь экран. */
.cards.single .rows { columns: 2; column-gap: 48px; }
.cards.single .row { break-inside: avoid; }
.cards.single .rows .sep { display: none; }
.only-mobile { display: none; }

/* ==========================================================================
   Структура продаж + заказы (лаймовый блок)
   ========================================================================== */
.summary { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; margin-bottom: 14px; }
.summary:empty { display: none; }
.summary.single { grid-template-columns: minmax(0, 1fr); }
.structure { padding: 20px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.structure-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; font-weight: var(--weight-heading); }
.structure-head h2 { font-size: 16px; font-weight: var(--weight-heading); }
.structure-bar { display: flex; height: 18px; overflow: hidden; border-radius: var(--radius-pill); background: var(--brand-blue-soft); }
.structure-bar span { display: block; height: 100%; }
.structure-legend { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-top: 14px; font-size: 13px; font-weight: var(--weight-strong); }
.dot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; vertical-align: 0; }

.orders-block {
  padding: 20px 22px; border-radius: var(--radius); min-width: 0;
  background: var(--brand-lime); color: var(--text-on-lime);
}
.orders-value { font-size: 20px; font-weight: var(--weight-heading); text-transform: uppercase; overflow-wrap: anywhere; }
.orders-split { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 8px; font-size: 13px; font-weight: var(--weight-strong); }
/* Полоса структуры заказов на лаймовом фоне: сайт — синий, инстаграм — белый (лаймовый слился бы с фоном). */
.orders-split .dot { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.orders-bar { height: 12px; margin-top: 12px; background: rgba(0, 0, 0, .08); }

/* Сравнение среднего чека и цены заказа по каналам */
.avg-compare { margin-bottom: 30px; }
.compare-table { margin-top: 0; }
.compare-table td { font-weight: var(--weight-strong); }
.compare-table td:first-child { font-weight: var(--weight-medium); color: var(--text-secondary); }
.compare-table td.compare-diff { font-weight: var(--weight-medium); color: var(--text-secondary); }
.compare-total td { background: var(--bg); }
.compare-name { display: inline-flex; align-items: center; font-weight: var(--weight-strong); color: var(--text-primary); }
/* Значения — плашкой цвета канала; лучший канал помечен бейджем «кращий». */
.val-pill { display: inline-block; padding: 1px 9px; border-radius: var(--radius-pill); font-weight: var(--weight-heading); }
.val-pill.avg { background: var(--chart-avg-total); color: var(--text-on-orange); }
.val-pill.s1 { background: var(--channel-site); color: var(--text-on-blue); }
.val-pill.s2 { background: var(--channel-instagram); color: var(--text-on-lime); }
.val-pill.s3 { background: var(--channel-tiktok); color: var(--brand-white); }
.val-pill.s4 { background: var(--channel-google); color: var(--brand-white); }
.best-badge {
  display: inline-block; margin-right: 6px; padding: 1px 7px; border: 1.5px solid currentColor; border-radius: var(--radius-pill);
  font-size: 10px; font-weight: var(--weight-heading); text-transform: uppercase; letter-spacing: .04em; color: var(--accent); vertical-align: 1px;
}
.swatch.avg { background: var(--chart-avg-total); }
.swatch.avg.dashed { background: repeating-linear-gradient(90deg, var(--chart-avg-total) 0 4px, transparent 4px 6px); }
/* Карточки сравнения — только на телефоне, вместо широкой таблицы. */
.compare-cards { display: none; }
.compare-card { padding: 12px 0; border-bottom: 1px solid var(--border); }
.compare-card:last-child { border-bottom: 0; }
.compare-card-head { margin-bottom: 6px; }
.compare-card-row { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 3px 0; }
.compare-card-label { color: var(--text-secondary); }
.compare-card-value { justify-self: end; font-weight: var(--weight-strong); }
.compare-card-diff { grid-column: 1 / -1; justify-self: end; font-size: 12px; color: var(--text-muted); }
.orders-period { margin-top: 14px; font-size: 12px; color: var(--brand-dark); }

.footnote { margin: 0 0 30px; font-size: 12px; color: var(--text-muted); }

/* ==========================================================================
   Динамика
   ========================================================================== */
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.section-title { font-size: 22px; font-weight: var(--weight-heading); text-transform: uppercase; letter-spacing: .01em; }
.panel { padding: 22px 24px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.panel-divider { border-top: 1px solid var(--border); margin: 18px 0 4px; }
.chart-title { margin: 6px 0 8px; font-size: 16px; font-weight: var(--weight-heading); }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 360px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 13px; font-weight: var(--weight-strong); }
.legend span { display: inline-flex; align-items: center; }
.swatch { display: inline-block; width: 12px; height: 12px; margin-right: 8px; border-radius: 3px; }
.swatch.s0 { background: var(--channel-total); }
.swatch.s1 { background: var(--channel-site); }
.swatch.s2 { background: var(--channel-instagram); }
.swatch.s3 { background: var(--channel-tiktok); }
.swatch.s4 { background: var(--channel-google); }
.swatch.rev { background: var(--chart-revenue); }
.swatch.bud { background: var(--chart-budget); }

.table-view { margin-top: 18px; }
.table-view summary { cursor: pointer; font-weight: var(--weight-strong); color: var(--accent); }
.table-scroll { overflow-x: auto; margin-top: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 11px; font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); }

.band {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px;
  margin-top: 14px; padding: 10px 20px; border-radius: var(--radius-sm);
  background: var(--brand-blue); color: var(--text-on-blue); font-size: 12px;
}
.band-legend { display: flex; flex-wrap: wrap; gap: 6px 36px; font-weight: var(--weight-heading); text-transform: uppercase; letter-spacing: .03em; }
.band-legend .s1 { color: var(--text-on-blue); }
.band-legend .s2 { color: var(--brand-lime); }
.band-legend .s3 { color: var(--channel-tiktok-on-blue); }
.band-legend .s4 { color: var(--channel-google-on-blue); }
.card-note { margin: 12px 0 0; font-size: 13px; }

/* ==========================================================================
   Вход и «Доступ ще не надано»
   ========================================================================== */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 400px; text-align: center; padding: 32px 26px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
}
.login-logo { width: 72px; height: 72px; margin: 0 auto 14px; display: block; }
.login-card h1 { margin-bottom: 10px; font-size: 20px; font-weight: var(--weight-heading); text-transform: uppercase; }
.login-card [hidden] { display: none; }
.tg-widget { min-height: 48px; margin-top: 16px; display: flex; justify-content: center; }
.qr { width: 220px; max-width: 100%; margin: 16px auto 0; padding: 8px; background: var(--brand-white); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.qr svg { display: block; width: 100%; height: auto; }
.tg-btn {
  display: inline-block; margin-top: 16px; padding: 11px 22px; border-radius: var(--radius-sm);
  background: var(--brand-blue); color: var(--text-on-blue); font-weight: var(--weight-strong); text-decoration: none;
}
.login-status { min-height: 1.45em; margin: 12px 0 0; color: var(--text-secondary); }
.link-btn {
  display: block; margin: 12px auto 0; padding: 4px; border: 0; background: none; cursor: pointer;
  font-size: 13px; color: var(--text-muted); text-decoration: underline;
}
.login-error { color: var(--error); margin: 16px 0 0; }

/* ==========================================================================
   Главная: синий фон брендбука, крупный белый текст, акцент — лайм
   ========================================================================== */
.home-page {
  position: relative; overflow-x: clip;
  min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column;
  padding: 24px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  background: var(--brand-blue); color: var(--text-on-blue);
}
/* Декор: кольца как круг логотипа, уходят за край экрана. */
.home-page::before, .home-page::after {
  content: ''; position: absolute; z-index: 0; pointer-events: none; border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .14);
}
.home-page::before { width: 72vmax; height: 72vmax; top: -30vmax; right: -24vmax; }
.home-page::after { width: 44vmax; height: 44vmax; top: -16vmax; right: -10vmax; border-color: rgba(187, 245, 67, .35); }
.home-page > * { position: relative; z-index: 1; }
.home-page a { color: inherit; }
.home-page :focus-visible { outline-color: var(--brand-lime); }
.home-bar { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
/* Шапка выше основного блока: иначе на телефоне (где .home-main во всю ширину) он перекрывает выпадающее меню и тапы не доходят. */
.home-page > .home-bar { z-index: 2; }
.home-logo { display: block; flex: none; }
.home-logo img { display: block; width: 52px; height: 52px; }
.home-nav { position: relative; }
.home-menu-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 20px 9px 16px; cursor: pointer;
  font: inherit; font-weight: var(--weight-strong); color: inherit; background: none;
  border: 1.5px solid var(--text-on-blue-muted); border-radius: var(--radius-pill); transition: background .15s;
}
.home-menu-btn:hover, .home-menu-btn[aria-expanded="true"] { background: rgba(255, 255, 255, .12); }
.home-menu-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.home-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50; min-width: 220px; padding: 6px;
  background: var(--brand-white); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}
.home-menu[hidden] { display: none; }
.home-page .home-menu-item {
  display: block; padding: 11px 14px; border-radius: var(--radius-sm);
  font-weight: var(--weight-heading); text-transform: uppercase; text-decoration: none; color: var(--brand-blue);
}
.home-page .home-menu-item:hover { background: var(--brand-lime); }
.home-menu-empty { padding: 11px 14px; font-size: 14px; color: var(--brand-blue); opacity: .7; }

.home-main { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 48px 0; max-width: 1180px; }
.home-title {
  font-size: clamp(37px, 7.42vw, 104px); line-height: .98; font-weight: var(--weight-heading);
  text-transform: uppercase; letter-spacing: .03em; overflow-wrap: anywhere;
}
/* Интервал у всех букв и слов заголовка один (.03em); шрифт уменьшен на ~7%, чтобы строки остались прежней ширины. */
.home-accent { color: var(--brand-lime); }
/* Компьютер: две строки ровным блоком — ширина по самой длинной строке, вторая растягивается по краям,
   так что «Growth»/«fashion» начинаются, а «партнер»/«брендів» заканчиваются на одной вертикали. */
@media (min-width: 601px) {
  .home-title { width: fit-content; max-width: 100%; }
  .home-title-line { display: block; text-align: justify; text-align-last: justify; white-space: nowrap; }
}
.home-by { font-style: italic; margin-top: 18px; font-size: clamp(16px, 2vw, 22px); font-weight: var(--weight-medium); color: var(--text-on-blue-muted); }
.home-by a { color: var(--text-on-blue); text-decoration-color: var(--brand-lime); text-underline-offset: 4px; }
.home-slogan {
  margin-top: clamp(28px, 5vw, 48px); max-width: 820px; padding-left: 18px; border-left: 4px solid var(--brand-lime);
  font-size: clamp(22px, 3.4vw, 42px); line-height: 1.3; font-weight: var(--weight-heading); font-style: italic;
}
/* «а впливаємо на дохід» — белая подложка, синий текст; при переносе подложка на каждой строке.
   Отрицательный margin гасит padding подложки, чтобы пробел перед «а» был таким же, как между остальными словами. */
.home-highlight {
  padding: 0 .22em; margin: 0 -.22em; border-radius: 6px; background: var(--brand-white); color: var(--brand-blue);
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
/* На широком экране фраза не рвётся (иначе «а» остаётся одна на строке); на телефоне переносится. */
@media (min-width: 601px) { .home-highlight { white-space: nowrap; } }

.home-contacts { padding-top: 20px; border-top: 1px solid rgba(255, 255, 255, .2); }
.home-contacts-label { font-size: 12px; font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: .08em; color: var(--text-on-blue-muted); }
.home-chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.home-chip {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0; padding: 9px 16px 9px 12px;
  border: 1.5px solid var(--text-on-blue-muted); border-radius: var(--radius-pill);
  font-weight: var(--weight-strong); text-decoration: none; transition: background .15s, color .15s;
}
.home-chip:hover { background: var(--brand-white); color: var(--brand-blue); }
.home-chip svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }
.home-chip svg .dot { fill: currentColor; stroke: none; }
.home-chip-role { font-weight: var(--weight-medium); opacity: .75; }
.home-chip-arrow { margin-left: 2px; color: var(--brand-lime); }
.home-chip:hover .home-chip-arrow { color: inherit; }

/* Телефон: заголовок во всю ширину экрана, контакты — на всю ширину. */
@media (max-width: 600px) {
  .home-page { padding-top: 16px; }
  .home-logo img { width: 44px; height: 44px; }
  .home-main { padding: 36px 0 32px; }
  .home-title { font-size: 15.8vw; line-height: .95; }
  .home-by { margin-top: 14px; }
  .home-slogan { margin-top: 28px; padding-left: 14px; font-size: 7vw; line-height: 1.5; }
  .home-highlight { padding: .02em .18em; margin: 0 -.18em; }
  .home-chips { flex-direction: column; }
  .home-chip { padding: 13px 16px; font-size: 15px; }
  .home-chip-arrow { margin-left: auto; font-size: 18px; }
}

/* Появление главной (контакты выезжают блоком вместе с линией, кнопки — следом): элементы по очереди выплывают слева направо (порядок — --i, шаг 90 мс), кольца проявляются.
   fill-mode backwards: после анимации transform не остаётся, выпадающее меню и ховеры работают как раньше. */
@keyframes home-in { from { opacity: 0; transform: translateX(-48px); } to { opacity: 1; transform: none; } }
/* Строки заголовка на телефоне — строчные элементы, transform к ним не применяется: сдвигаем через left. */
@keyframes home-in-inline { from { opacity: 0; left: -48px; } to { opacity: 1; left: 0; } }
@keyframes home-rings-in { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
.home-logo { --i: 0; }
.home-nav { --i: 1; }
.home-title-line:first-child { --i: 2; }
.home-title-line:last-child { --i: 3; }
.home-by { --i: 4; }
.home-slogan { --i: 5; }
.home-contacts { --i: 6; }
.home-chip:nth-child(1) { --i: 7; }
.home-chip:nth-child(2) { --i: 8; }
.home-chip:nth-child(3) { --i: 9; }
.home-logo, .home-nav, .home-by, .home-slogan, .home-contacts, .home-chip {
  animation: home-in .7s cubic-bezier(.22, 1, .36, 1) calc(var(--i) * 90ms + 80ms) backwards;
}
.home-title-line { position: relative; animation: home-in-inline .8s cubic-bezier(.22, 1, .36, 1) calc(var(--i) * 90ms + 80ms) backwards; }
@media (min-width: 601px) { .home-title-line { animation-name: home-in; } }
.home-page::before, .home-page::after { animation: home-rings-in 1.4s cubic-bezier(.22, 1, .36, 1) backwards; }
.home-page::after { animation-delay: .25s; }
@media (prefers-reduced-motion: reduce) {
  .home-logo, .home-nav, .home-title-line, .home-by, .home-slogan, .home-contacts, .home-chip,
  .home-page::before, .home-page::after { animation: none; }
}

/* Логотип в дашборде и на входе — ссылка на главную. */
.logo-link { display: block; flex: none; }

/* ==========================================================================
   Адаптив
   ========================================================================== */
@media (max-width: 1100px) {
  .hero { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 20px; }
  .hero-main { grid-column: 1 / -1; padding-right: 0; }
  .hero-kpi:nth-child(2) { border-left: 0; padding-left: 0; }
}

@media (min-width: 901px) and (max-width: 1500px) {
  .cards.many { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Мобильный макет: без сайдбара, один столбец, синяя шапка-карточка. */
@media (max-width: 900px) {
  :root { --gutter: 16px; }
  /* Навигация по странице на телефоне — плавающая панель снизу (сводка / графики). */
  .sidebar {
    inset: auto auto calc(12px + env(safe-area-inset-bottom)) 50%; width: auto; transform: translateX(-50%);
    flex-direction: row; padding: 8px 20px; border-radius: var(--radius-pill); box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  }
  .sidebar-nav { flex-direction: row; gap: 14px; }
  .sidebar-logo, .sidebar-logo-link { display: none; }
  .page { margin-left: 0; padding-bottom: calc(var(--gutter) + 72px); }

  .topbar { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 12px; }
  .title-block {
    margin: calc(-1 * var(--gutter)) calc(-1 * var(--gutter)) 0; padding: 18px var(--gutter);
    background: var(--brand-blue); color: var(--text-on-blue);
  }
  .title-logo { display: block; flex: none; width: 36px; height: 36px; }
  .title-block > .logo-link { display: block; }
  .title-text { display: flex; flex-direction: column; }
  .page-title { order: 2; font-size: 12px; font-weight: var(--weight-medium); text-transform: none; letter-spacing: 0; color: var(--text-on-blue-muted); margin-top: 2px; }
  .project-name { order: 1; margin: 0; font-size: 16px; font-weight: var(--weight-heading); text-transform: uppercase; color: var(--text-on-blue); }
  #project-select {
    order: 1; margin: 0; padding: 4px 28px 4px 10px; font-weight: var(--weight-heading); text-transform: uppercase;
    color: var(--text-on-blue); background-color: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .35);
  }
  #project-select option { color: var(--text-primary); background: var(--surface-1); text-transform: none; }
  .title-text .project-row { order: 1; margin-top: 0; }
  .add-project-btn {
    order: 2; width: 28px; height: 28px;
    color: var(--text-on-blue); background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .35);
  }
  .topbar-right { align-items: stretch; }
  .user-block { align-self: flex-end; max-width: 100%; }
  .user-btn { max-width: 100%; }
  .date-pills { justify-content: flex-start; }
  .date-pills .pill, .date-pills input[type="date"] { min-height: 36px; padding: 6px 12px; }
  .date-pills .icon-btn { width: 36px; height: 36px; }
  .month-label { min-width: 0; flex: 1; }
  .sync { text-align: right; }

  .filters { flex-direction: column; flex-wrap: nowrap; align-items: stretch; padding: 14px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); }
  /* На телефоне панель — белая карточка; прилипнув, растягивается на всю ширину и прячет подпись «Період». */
  #period-bar { margin-inline: 0; padding: 12px 14px; gap: 8px; background: var(--surface-1); }
  #period-bar.stuck { margin-inline: calc(-1 * var(--gutter)); border-radius: 0 0 var(--radius) var(--radius); border-top: 0; }
  #period-bar.stuck .filters-label { display: none; }
  /* Прилипшая панель компактнее: все типы периода в одну строку. */
  #period-bar.stuck { padding-block: 8px; gap: 6px; }
  #period-bar.stuck .segmented { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; }
  #period-bar.stuck .segmented button { padding: 6px 2px; font-size: 11px; }
  /* Прилипшая панель без белой подложки (затемнение — в общих стилях #period-bar.stuck). */
  #period-bar.stuck { padding-inline: var(--gutter); border: 0; }
  #period-bar.stuck .segmented button:not([aria-pressed="true"]) { background: var(--surface-1); border-color: var(--border); }
  /* Даты и подпись периода всегда в одну строку — длинная подпись ужимается, а не переносит блок. */
  .date-pills { flex-wrap: nowrap; gap: 6px; }
  .date-pills .range { flex: none; gap: 4px; }
  .date-pills input[type="date"] { flex: none; padding-inline: 8px; font-size: 12px; }
  .date-pills .icon-btn { width: 32px; }
  #month-controls { flex: 1; min-width: 0; }
  /* «Період»: диапазон видно в двух полях, отдельная подпись не помещается. */
  #custom-controls { flex: 1; min-width: 0; }
  #custom-controls input[type="date"] { flex: 1; min-width: 0; }
  #custom-controls:not([hidden]) ~ .range-label { display: none; }
  /* Шрифт подписей ужимает fitLabel() в app.js (до 10px); многоточие — последний запас. */
  .date-pills .month-label, .date-pills .range-label {
    display: block; flex: 1; min-width: 0; padding-inline: 6px; line-height: 22px;
    text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .date-pills .range-label[hidden] { display: none; }
  .filters-label { display: block; font-size: 11px; font-weight: var(--weight-heading); text-transform: uppercase; letter-spacing: .06em; }
  .segmented { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .segmented button { padding: 8px 4px; font-size: 12px; background: var(--bg); border-color: transparent; }

  .hero { display: block; padding: 18px; margin-bottom: 14px; }
  .hero-value { font-size: 30px; }
  .hero-kpi { display: none; }
  .hero-caption-mobile { display: block; }
  .hero-pills-mobile { display: flex; flex-wrap: wrap; justify-content: flex-start; margin-top: 12px; }

  .cards { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .cards.single .rows { columns: 1; }
  .cards.single .rows .sep { display: block; }
  .card { padding: 16px; }
  .card-revenue, .only-desktop { display: none; }
  .kpis { display: grid; }
  .only-mobile { display: flex; }

  .summary, .summary.single { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .avg-compare .table-scroll { display: none; }
  .compare-cards { display: block; }
  .section-title { font-size: 18px; }
  .panel { padding: 16px; }
  .chart-box { height: 210px; }
  .chart-box.tall { height: 320px; }
}

@media (max-width: 400px) {
  .segmented { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hero-value { font-size: 26px; }
}


/* ==========================================================================
   Раздел «Агенція» (agency.html): та же сетка и токены, что у дашборда
   ========================================================================== */
/* Категориальная палитра таргетологов (диаграммы, рейтинги): проверена валидатором на различимость, в т.ч. при дальтонизме. */
:root {
  --cat-1: #2f3fe8; --cat-2: #f26b1d; --cat-3: #1baf7a; --cat-4: #d6124a;
  --cat-5: #2a9df4; --cat-6: #eda100; --cat-7: #7b3fc9; --cat-other: #a3a3a0;
}
.agency-page input[type="month"] {
  min-height: 38px; padding: 7px 12px; font-size: 13px; font-weight: var(--weight-strong);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
}

/* Панель: разделы слева, период справа (на узком экране — в две строки). Прилипание и затемнение — общие стили #period-bar. */
.ag-period { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.ag-tabs { display: flex; gap: 6px; }
.ag-tabs a {
  padding: 9px 18px; border-radius: var(--radius-pill); text-decoration: none;
  font-size: 13px; font-weight: var(--weight-heading); text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-primary); background: var(--surface-1); border: 1px solid var(--border);
}
.ag-tabs a:hover { border-color: var(--accent); color: var(--accent); }
.ag-tabs a[aria-current="page"] { background: var(--brand-lime); border-color: var(--brand-lime); color: var(--brand-blue); }
#period-bar.stuck .ag-tabs a { pointer-events: auto; box-shadow: 0 2px 8px rgba(0, 0, 0, .14); }
.nav-label { display: none; }
.sidebar .nav-icon[aria-current="page"] { background: var(--brand-lime); border-color: var(--brand-lime); color: var(--brand-blue); }

/* Год и месяц: «‹ [Рік ▾ 2026] ›». Активный выбор — синяя рамка; вне режима год/месяц — приглушены. */
.ag-pickers { display: flex; flex-wrap: wrap; gap: 8px; }
.ag-picker { display: inline-flex; align-items: center; gap: 4px; }
.ag-picker .icon-btn:disabled { opacity: .4; cursor: default; border-color: var(--border); color: var(--text-primary); }
.ag-select {
  position: relative; display: inline-flex; flex-direction: column; justify-content: center; min-height: 38px; min-width: 128px;
  padding: 3px 30px 3px 12px; cursor: pointer;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.ag-select::after {
  content: ''; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px; margin-top: -5px; pointer-events: none;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg);
}
.ag-select-label { font-size: 9.5px; line-height: 1.1; font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.ag-select select {
  appearance: none; -webkit-appearance: none; padding: 0; margin: 0; border: 0; background: none; cursor: pointer; outline: none;
  font-size: 13px; font-weight: var(--weight-heading); color: var(--text-primary);
}
.ag-picker.active .ag-select { border-color: var(--brand-blue); background: var(--brand-blue); color: var(--text-on-blue); }
.ag-picker.active .ag-select select { color: var(--text-on-blue); }
.ag-picker.active .ag-select select option { color: var(--text-primary); background: var(--surface-1); }
.ag-picker.active .ag-select-label { color: var(--text-on-blue-muted); }
.ag-select:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
#period-bar.stuck .ag-select { pointer-events: auto; box-shadow: 0 2px 8px rgba(0, 0, 0, .14); }
#custom-range[hidden] { display: none; }

/* Hero: сумма в ₴ компактнее, $ — рядом в той же строке. */
.agency-page .hero-value { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; font-size: 30px; }
.ag-hero-usd { font-size: 20px; font-weight: var(--weight-strong); color: var(--text-on-blue-muted); }
.ag-hero-sub { margin-left: 8px; font-size: 14px; font-weight: var(--weight-strong); color: var(--text-on-blue-muted); }
.hero-kpi[title] { cursor: help; }
.ag-cards { --cols: 3; }
.ag-section { margin: 30px 0; }
.ag-section.ag-first { margin-top: 4px; }
.ag-note { margin-top: 12px; font-size: 12px; color: var(--text-muted); }
.ag-pos { color: var(--brand-blue); font-weight: var(--weight-strong); }
.ag-neg { color: var(--channel-tiktok); font-weight: var(--weight-strong); }

.swatch.ag-rev, .swatch.ag-new { background: var(--brand-blue); }
.swatch.ag-fee { background: var(--chart-budget); }
.swatch.ag-profit, .swatch.ag-active { background: var(--brand-dark); height: 3px; border-radius: 2px; }
.swatch.ag-ret { background: var(--brand-lime); }
.swatch.ag-left { background: var(--channel-tiktok); }
.swatch.ag-sal { background: var(--chart-budget); }
.swatch.ag-cost { background: var(--brand-dark); }
.swatch.ag-prof { background: var(--brand-blue); }
.swatch.ag-loss { background: var(--channel-tiktok); }
.swatch.ag-nopnl { background: var(--cat-other); }
.ag-legend-row { margin: 4px 0 10px; }

/* ---------- Фінансовий звіт ---------- */
.ag-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-bottom: 20px; }
.ag-seg[hidden] { display: none; }
.ag-dot { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; }
.ag-dot.sal { background: var(--chart-budget); }
.ag-dot.cost { background: var(--brand-dark); }
.ag-dot.profit { background: var(--brand-blue); }
.ag-dot.loss { background: var(--channel-tiktok); }

/* «Куди йде виручка»: одна полоса = 100% выручки. */
.ag-structure { margin-bottom: 24px; }
.ag-structure-bar { display: flex; gap: 2px; height: 22px; overflow: hidden; border-radius: var(--radius-pill); background: var(--brand-blue-soft); }
.ag-structure-bar span { display: block; height: 100%; }
.ag-structure-bar .sal { background: var(--chart-budget); }
.ag-structure-bar .cost { background: var(--brand-dark); }
.ag-structure-bar .profit { background: var(--brand-blue); }
.ag-structure-legend { display: flex; flex-wrap: wrap; gap: 10px 32px; margin-top: 12px; font-size: 13px; }
.ag-structure-legend > div { display: inline-flex; align-items: center; gap: 8px; }
.ag-structure-legend b { font-weight: var(--weight-heading); }

/* Статьи за период: название · полоса доли · сумма · % від виручки. */
.ag-statement { border-top: 1px solid var(--border); }
.ag-st-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(60px, 200px) 140px 72px; gap: 16px; align-items: center;
  padding: 9px 8px; border-bottom: 1px solid var(--border);
}
.ag-st-head { padding-block: 7px; font-size: 11px; font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); }
.ag-st-head .ag-st-pct { color: var(--text-secondary); font-weight: var(--weight-strong); }
.ag-st-label { min-width: 0; }
.ag-st-label > span { display: inline-block; padding-left: 14px; }
.ag-st-value, .ag-st-pct { text-align: right; white-space: nowrap; }
.ag-st-value { font-weight: var(--weight-strong); }
.ag-st-pct { font-weight: var(--weight-heading); color: var(--brand-blue); }
.ag-st-pct small { display: block; font-size: 10px; line-height: 1.1; font-weight: var(--weight-medium); color: var(--text-muted); }
.ag-st-bar { height: 8px; overflow: hidden; border-radius: var(--radius-pill); background: var(--brand-blue-soft); }
.ag-st-head .ag-st-bar { background: none; }
.ag-st-bar span { display: block; height: 100%; border-radius: var(--radius-pill); background: var(--brand-blue); }
.ag-st-bar span.neg { background: var(--channel-tiktok); }
.ag-st-strong { font-weight: var(--weight-heading); }
.ag-st-strong .ag-st-value { font-weight: var(--weight-heading); }
.ag-st-hl { background: var(--brand-blue-soft); border-radius: var(--radius-sm); border-bottom-color: transparent; font-weight: var(--weight-heading); color: var(--brand-blue); }
.ag-st-hl .ag-st-value { font-weight: var(--weight-heading); }
.ag-st-hl .ag-st-bar { background: var(--surface-1); }
.ag-depth-1 { font-size: 13px; color: var(--text-secondary); background: #fafaf8; }
.ag-depth-1 .ag-st-label { padding-left: 22px; }
.ag-depth-1 .ag-st-bar span { background: #6b6be0; }
.ag-depth-2 { font-size: 12.5px; color: var(--text-secondary); background: #f6f6f3; }
.ag-depth-2 .ag-st-label { padding-left: 44px; }
.ag-depth-2 .ag-st-bar span { background: #a5a5ee; }
.ag-depth-1 .ag-st-pct, .ag-depth-2 .ag-st-pct { font-weight: var(--weight-strong); }

/* План / факт: карточки с кольцом выполнения и помесячным сравнением (контур — план, заливка — факт). */
.ag-plan { margin-top: 26px; }
.ag-plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.ag-plan-card { min-width: 0; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: #fafaf8; }
.ag-plan-head { display: flex; align-items: center; gap: 18px; }
.ag-ring { position: relative; flex: none; width: 92px; height: 92px; }
.ag-ring svg { display: block; width: 100%; height: 100%; }
.ag-ring circle { fill: none; stroke-width: 9; }
.ag-ring .track { stroke: var(--brand-blue-soft); }
.ag-ring .val { stroke: var(--chart-budget); stroke-linecap: round; }
.ag-ring.done .val { stroke: var(--brand-blue); }
.ag-ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 19px; font-weight: var(--weight-heading); }
.ag-plan-info { min-width: 0; }
.ag-plan-label { font-size: 12px; font-weight: var(--weight-heading); text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); }
.ag-plan-fact { margin-top: 2px; font-size: 22px; font-weight: var(--weight-heading); overflow-wrap: anywhere; }
.ag-plan-sub { font-size: 12px; color: var(--text-muted); }
.ag-plan-gap { display: inline-block; margin-top: 6px; padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: var(--weight-strong); }
.ag-plan-gap.pos { background: var(--brand-blue-soft); color: var(--brand-blue); }
.ag-plan-gap.neg { background: #ffe2c7; color: #8a3b00; }
.ag-bullets { display: flex; gap: 6px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); overflow-x: auto; }
.ag-bullet { flex: 1 0 30px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: default; }
.ag-bullet-pct { font-size: 10px; font-weight: var(--weight-heading); white-space: nowrap; }
.ag-bullet-pct.ok { color: var(--brand-blue); }
.ag-bullet-pct.miss { color: #b34700; }
.ag-bullet-area { position: relative; width: 100%; max-width: 34px; height: 90px; }
.ag-bullet-area i { position: absolute; bottom: 0; display: block; border-radius: 4px 4px 0 0; }
.ag-bullet-area .plan { left: 0; right: 0; border: 1.5px dashed var(--text-muted); border-bottom: 0; }
.ag-bullet-area .fact { left: 25%; right: 25%; }
.ag-bullet-area .fact.ok { background: var(--brand-blue); }
.ag-bullet-area .fact.miss { background: var(--chart-budget); }
.ag-bullet-m { font-size: 10px; color: var(--text-secondary); white-space: nowrap; }

/* Таблица по месяцам */
.ag-table td { font-weight: var(--weight-medium); }
.ag-table .ag-name { font-weight: var(--weight-strong); white-space: normal; min-width: 140px; }
.ag-table .ag-name .ag-dot { margin-right: 8px; }
.ag-cell-sub { display: block; font-size: 11px; color: var(--text-muted); }
.ag-pnl tr.ag-sub td { color: var(--text-secondary); font-size: 13px; }
.ag-pnl tr.ag-sub td:first-child { padding-left: 24px; }
.ag-pnl tr.ag-person td:first-child { padding-left: 40px; }
.ag-pnl tr.ag-strong td { font-weight: var(--weight-heading); }
.ag-pnl tr.ag-line td { border-top: 2px solid var(--border); }
.ag-pnl tr.ag-hl td { background: var(--brand-blue-soft); color: var(--brand-blue); }
.ag-pnl td.ag-total { background: var(--bg); font-weight: var(--weight-heading); }
.ag-pnl tr.ag-hl td.ag-total { background: var(--brand-blue); color: var(--text-on-blue); }
.ag-pnl td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface-1); }
.ag-pnl tr.ag-hl td:first-child { background: var(--brand-blue-soft); }
.ag-pnl tr:not(.ag-hl):hover td { background: #fafaf8; }
.ag-toggle { padding: 0; cursor: pointer; font: inherit; color: inherit; background: none; border: 0; text-align: left; }
.ag-toggle::before { content: '▸'; display: inline-block; width: 14px; color: var(--accent); transition: transform .15s; }
.ag-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
.ag-toggle:hover { color: var(--accent); }

.ag-share { display: inline-block; width: 46px; height: 6px; margin-right: 8px; vertical-align: 2px; overflow: hidden; border-radius: var(--radius-pill); background: var(--brand-blue-soft); }
.ag-share span { display: block; height: 100%; background: var(--brand-blue); }

/* ---------- Клієнти ---------- */
.ag-status { display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: var(--weight-strong); }
.ag-status.active { background: var(--brand-lime); color: var(--text-on-lime); }
.ag-status.at_risk { background: #ffe2c7; color: #8a3b00; }
.ag-status.left { background: var(--bg); color: var(--text-secondary); }
.ag-count { margin-left: 4px; opacity: .7; }
.ag-unpaid td { color: var(--channel-tiktok); }
.ag-more { margin-top: 14px; }

/* ---------- Таргетологи ---------- */
.ag-donuts, .ag-ratings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.ag-donut-box { position: relative; height: 330px; margin: 4px 0 0; }
.ag-donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.ag-donut-center b { font-size: 20px; font-weight: var(--weight-heading); }
.ag-donut-center span { font-size: 12px; color: var(--text-muted); }

.ag-rank { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 14px; }
.ag-rank li { display: flex; align-items: flex-start; gap: 12px; }
.ag-place {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  font-size: 13px; font-weight: var(--weight-heading); color: var(--text-secondary); background: var(--bg);
}
.ag-place.top-1 { background: var(--brand-lime); color: var(--brand-blue); }
.ag-place.top-2 { background: var(--brand-blue); color: var(--text-on-blue); }
.ag-place.top-3 { background: var(--brand-blue-soft); color: var(--brand-blue); }
.ag-rank-main { flex: 1; min-width: 0; }
.ag-rank-top { display: flex; align-items: center; gap: 8px; }
.ag-rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--weight-strong); }
.ag-rank-top b { font-weight: var(--weight-heading); white-space: nowrap; }
.ag-rank-track { height: 6px; margin: 6px 0 4px; overflow: hidden; border-radius: var(--radius-pill); background: var(--brand-blue-soft); }
.ag-rank-track span { display: block; height: 100%; border-radius: var(--radius-pill); }
.ag-rank-track.churn span { background: var(--channel-tiktok); }
.ag-rank-sub { font-size: 12px; color: var(--text-muted); }

@media (max-width: 1100px) {
  .ag-cards { --cols: 1; }
}
@media (max-width: 900px) {
  /* Телефон: разделы — в нижнем плавающем меню с подписями; в прилипшей панели остаётся только период. */
  .ag-tabs { display: none; }
  .ag-period { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 8px; }
  .agency-page .sidebar { padding: 6px 8px; }
  .agency-page .sidebar-nav { gap: 4px; }
  .agency-page .nav-icon { text-decoration: none; width: auto; height: auto; padding: 6px 14px; gap: 2px; border: 0; border-radius: var(--radius-pill); }
  .agency-page .nav-icon svg { width: 20px; height: 20px; }
  .agency-page .nav-label { display: block; font-size: 10px; font-weight: var(--weight-strong); line-height: 1.1; }

  /* Телефон: KPI остаются видны — сеткой 3 в ряд под выручкой. */
  .agency-page .hero { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr); row-gap: 14px; }
  .agency-page .hero-value { font-size: 24px; gap: 0 10px; margin: 6px 0 4px; }
  .ag-hero-usd { font-size: 16px; }
  .agency-page .hero-kpi-value { white-space: nowrap; }
  /* Шапка: крупно «Агенція», подзаголовок мелко (у дашборда наоборот — там крупно название проекта). */
  .agency-page .page-title, .access-page .page-title { order: 1; margin: 0; font-size: 16px; font-weight: var(--weight-heading); text-transform: uppercase; color: var(--text-on-blue); }
  .agency-page .project-name, .access-page .project-name { order: 2; margin-top: 2px; font-size: 12px; font-weight: var(--weight-medium); text-transform: none; color: var(--text-on-blue-muted); }
  .agency-page .hero-kpi { display: flex; padding: 0 10px; }
  .agency-page .hero-kpi:nth-child(2) { padding-left: 0; }
  .agency-page .hero-kpi-label { font-size: 11px; }
  .agency-page .hero-kpi-value { font-size: 16px; margin-top: 6px; }
  .ag-hero-sub { display: block; margin: 2px 0 0; font-size: 12px; }
  .agency-page .segmented { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* Прилипшая панель: все пресеты периода в одну строку. */
  .agency-page #period-bar.stuck .segmented { grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr)); }
  .agency-page .date-pills .range { flex: 1; }
  .agency-page input[type="month"] { flex: 1; min-width: 0; padding-inline: 8px; font-size: 12px; }
  .agency-page .section-head .segmented { width: 100%; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .agency-page .ag-seg { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ag-pickers { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
  .ag-picker { min-width: 0; gap: 3px; }
  .ag-picker .icon-btn { flex: none; width: 30px; height: 38px; }
  .ag-select { flex: 1; min-width: 0; padding-right: 24px; padding-left: 8px; }
  .ag-select::after { right: 9px; }
  .ag-select select { width: 100%; font-size: 12px; text-overflow: ellipsis; }
  #period-bar.stuck .ag-select-label { display: none; }
  #period-bar.stuck .ag-select, #period-bar.stuck .ag-picker .icon-btn { min-height: 34px; height: 34px; }
  .ag-plan-grid { grid-template-columns: minmax(0, 1fr); }
  .ag-plan-card { padding: 14px; }
  .ag-ring { width: 78px; height: 78px; }
  .ag-ring b { font-size: 16px; }
  .ag-plan-fact { font-size: 19px; }
  .ag-bullets { gap: 2px; }
  .ag-bullet { flex-basis: 22px; }
  .ag-bullet-pct, .ag-bullet-m { font-size: 8.5px; letter-spacing: -.02em; }
  .ag-bullet-area { height: 70px; }
  .agency-page .ag-seg button:not([aria-pressed="true"]) { background: var(--bg); }

  .ag-donuts, .ag-ratings { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .ag-donut-box { height: 290px; }
}
@media (max-width: 600px) {
  /* Статьи на телефоне: название · сумма · %, полоса доли — тонкой линией под строкой. */
  .ag-st-row { grid-template-columns: minmax(0, 1fr) auto 56px; grid-template-areas: "label value pct" "bar bar bar"; gap: 6px 10px; padding: 9px 6px; }
  .ag-st-label { grid-area: label; }
  .ag-st-value { grid-area: value; }
  .ag-st-pct { grid-area: pct; }
  .ag-st-bar { grid-area: bar; height: 4px; }
  .ag-st-head { grid-template-areas: "label value pct"; font-size: 10px; letter-spacing: .02em; }
  .ag-st-head .ag-st-bar { display: none; }
  .ag-depth-1 .ag-st-label { padding-left: 14px; }
  .ag-depth-2 .ag-st-label { padding-left: 28px; }
  .ag-structure-legend { display: grid; gap: 6px; }
  .ag-structure-legend > div { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; gap: 8px; }
}
@media (max-width: 400px) {
  .agency-page .hero-value { font-size: 22px; }
}

/* ---------- Керування доступом (/access) ---------- */
.acc-back { display: inline-block; text-decoration: none; }
.acc-back:hover { color: var(--accent); }
.acc-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.acc-count { display: inline-block; min-width: 20px; padding: 0 6px; font-size: 11px; line-height: 18px; text-align: center; border-radius: var(--radius-pill); background: var(--brand-blue-soft); color: var(--accent); }
.acc-count-new { background: var(--brand-lime); color: var(--text-on-lime); font-weight: var(--weight-heading); }
.acc-count[hidden] { display: none; }
.segmented button[aria-pressed="true"] .acc-count:not(.acc-count-new) { background: rgba(255, 255, 255, .2); color: var(--text-on-blue); }
.acc-search {
  width: min(320px, 100%); padding: 8px 14px; font: inherit; font-size: 13px; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-pill);
}
.acc-search:focus { outline: none; border-color: var(--accent); }
.acc-list { display: flex; flex-direction: column; gap: 8px; }
.acc-list[hidden] { display: none; }
.acc-row {
  display: grid; grid-template-columns: 40px minmax(160px, 1fr) minmax(0, 2fr) auto; align-items: center; gap: 12px 16px;
  padding: 14px 16px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
}
.acc-row .avatar { width: 40px; height: 40px; }
.acc-avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  font-weight: var(--weight-heading); color: var(--accent); background: var(--brand-blue-soft);
}
.acc-who { min-width: 0; }
.acc-name { font-weight: var(--weight-strong); overflow-wrap: anywhere; }
.acc-handle { font-size: 12px; overflow-wrap: anywhere; }
.acc-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; font-size: 13px; }
.acc-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.acc-badge {
  display: inline-block; padding: 2px 10px; font-size: 12px; font-weight: var(--weight-strong);
  color: var(--accent); background: var(--brand-blue-soft); border-radius: var(--radius-pill);
}
.acc-badge-owner { color: var(--text-on-lime); background: var(--brand-lime); }
.acc-badge-role { color: var(--text-on-blue); background: var(--brand-blue); }
.acc-badge-none { color: var(--text-muted); background: transparent; border: 1px dashed var(--border); }
.acc-chip { display: inline-block; padding: 2px 9px; font-size: 12px; border: 1px solid var(--border); border-radius: var(--radius-pill); }
.acc-locked { font-size: 12px; }
.acc-empty { padding: 28px 16px; text-align: center; background: var(--surface-1); border: 1px dashed var(--border); border-radius: var(--radius); }
.acc-error { margin-bottom: 12px; padding: 10px 14px; font-size: 13px; color: #9b1c1c; background: #fdecec; border-left: 4px solid #d93025; border-radius: var(--radius-sm); }
.acc-error[hidden] { display: none; }
.primary-btn.acc-small { padding: 6px 16px; font-size: 13px; }
.acc-danger:hover { color: #c62828; border-color: #c62828; }
.acc-dialog-sub { margin-top: -8px; font-size: 13px; overflow-wrap: anywhere; }
.acc-presets { display: flex; flex-direction: column; gap: 8px; }
.acc-preset {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: center; padding: 10px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.acc-preset:has(input:checked) { border-color: var(--accent); background: var(--brand-blue-soft); }
.acc-preset input { accent-color: var(--brand-blue); margin: 0; }
.acc-preset-name { font-size: 14px; font-weight: var(--weight-strong); }
.acc-preset-desc { grid-column: 2; font-size: 12px; color: var(--text-secondary); }
.acc-dialog-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.acc-dialog-actions [hidden] { display: none; }
#acc-projects-field[hidden] { display: none; }
@media (max-width: 760px) {
  .acc-row { grid-template-columns: 40px minmax(0, 1fr); }
  .access-page .acc-toolbar .segmented { flex-wrap: nowrap; }
  .acc-status, .acc-actions { grid-column: 1 / -1; }
  .acc-actions { justify-content: flex-start; }
  .acc-search { width: 100%; }
}

/* ---------- Прирост к прошлому периоду ---------- */
.delta { display: inline-block; margin-left: 6px; padding: 0 6px; font-size: 11px; line-height: 17px; font-weight: var(--weight-strong); white-space: nowrap; vertical-align: middle; border-radius: var(--radius-pill); }
.delta.up { color: #11703a; background: #e3f6e9; }
.delta.down { color: #b42318; background: #fdecec; }
.delta.flat { color: var(--text-secondary); background: var(--surface-2, #f1f1f4); }
.card-revenue-value .delta { font-size: 12px; line-height: 20px; }
.hero .delta { background: rgba(255, 255, 255, .92); }
.hero-value .delta { font-size: 13px; line-height: 22px; }
.kpis .delta { margin: 4px 0 0; }

/* ---------- Каналы визуально: цветная полоса сверху и подкрашенная шапка карточки ---------- */
.card[class*="ch-s"] { border-top-width: 4px; }
.card.ch-s0 { border-top-color: var(--channel-total); }
.card.ch-s1 { border-top-color: var(--channel-site); }
.card.ch-s2 { border-top-color: var(--channel-instagram); }
.card.ch-s3 { border-top-color: var(--channel-tiktok); }
.card.ch-s4 { border-top-color: var(--channel-google); }
.card[class*="ch-s"] .card-head { margin: -20px -20px 14px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.card.ch-s0 .card-head { background: #f1f1f4; }
.card.ch-s1 .card-head { background: var(--brand-blue-soft); }
.card.ch-s2 .card-head { background: #f3fde0; }
.card.ch-s3 .card-head { background: #fde8ee; }
.card.ch-s4 .card-head { background: #e2f5f2; }

/* ---------- Таблица по дням: группы каналов и подсветка цены заказа ---------- */
#ts-table th.ts-group { text-align: center; font-weight: var(--weight-heading); border-bottom: 3px solid var(--channel-total); }
#ts-table th.ts-group.s1 { border-bottom-color: var(--channel-site); background: var(--brand-blue-soft); }
#ts-table th.ts-group.s2 { border-bottom-color: var(--channel-instagram); background: #f3fde0; }
#ts-table th.ts-group.s3 { border-bottom-color: var(--channel-tiktok); background: #fde8ee; }
#ts-table th.ts-group.s4 { border-bottom-color: var(--channel-google); background: #e2f5f2; }
#ts-table th.ts-group.s0 { background: #f1f1f4; }
#ts-table th.ts-first, #ts-table td[data-first], #ts-table th.ts-group { border-left: 2px solid var(--border); }
#ts-table td.heat { background: color-mix(in srgb, #e3f6e9 calc((1 - var(--heat)) * 100%), #f9c9c4 calc(var(--heat) * 100%)); }
/* Колонка с датой закреплена: при горизонтальной прокрутке таблицы остаётся слева, с тенью у края. */
#ts-table .ts-date {
  position: sticky; left: 0; z-index: 2; text-align: left;
  background: var(--surface-1); box-shadow: inset -1px 0 0 var(--border), 6px 0 8px -6px rgba(0, 0, 0, .18);
}
#ts-table thead .ts-date { z-index: 3; }
/* Шапка таблицы закреплена: у таблицы своя высота с прокруткой внутри (sticky работает только в своём блоке прокрутки).
   Вторая строка шапки стоит под первой — её отступ (--ts-head1) ставит JS по фактической высоте первой строки. */
.table-view .table-scroll { max-height: min(75vh, 720px); overflow: auto; overscroll-behavior: contain; }
#ts-table thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-1); }
#ts-table thead tr:nth-child(2) th { top: var(--ts-head1, 0px); }
#ts-table thead th.ts-group.s0 { background: #f1f1f4; }
#ts-table thead th.ts-group.s1 { background: var(--brand-blue-soft); }
#ts-table thead th.ts-group.s2 { background: #f3fde0; }
#ts-table thead th.ts-group.s3 { background: #fde8ee; }
#ts-table thead th.ts-group.s4 { background: #e2f5f2; }
#ts-table thead tr:nth-child(2) th { box-shadow: inset 0 -1px 0 var(--border), 0 6px 8px -6px rgba(0, 0, 0, .18); }
#ts-table thead .ts-date { left: 0; z-index: 4; }
