/* Кабинет Merilix — компоненты.
   Две раскладки, как у Roistat:
   .page--report  сплошные белые панели во всю ширину, без скруглений, фон #f7f8f9
   .page--dash    скруглённые карточки с тенью на фоне #f1f2f3                    */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 24px;
  color: var(--text);
  background: var(--bg-report);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

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

.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 60;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
  background: var(--bg-topbar); color: var(--text-invert);
}
.topbar__burger {
  width: 22px; height: 22px; border: 0; background: none; cursor: pointer;
  color: #aeb3bd; font-size: 14px; line-height: 1; padding: 0;
}
.topbar__logo { font-size: 17px; letter-spacing: .2px; }
.topbar__logo b { color: var(--primary); font-weight: 400; }
.topbar__project {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 210px; height: 26px; padding: 0 8px;
  background: #2a2e3a; border: 1px solid #414654; border-radius: 4px;
  font-size: 13px; color: #e6e8ec; cursor: pointer;
}
.topbar__icon {
  width: 26px; height: 26px; border-radius: 4px; border: 0; cursor: pointer;
  background: #2a2e3a; color: #cfd3da; font-size: 12px;
}
.topbar__spacer { flex: 1; }
.topbar__meta { font-size: 13px; color: #aeb3bd; }
.btn-support {
  height: 28px; padding: 0 12px; border: 0; border-radius: 4px;
  background: var(--primary); color: #fff; font-size: 13px; cursor: pointer;
}
.topbar__bell { position: relative; }
.topbar__bell i {
  position: absolute; top: -5px; right: -6px; min-width: 15px; height: 15px;
  border-radius: 8px; background: var(--danger); color: #fff;
  font-size: 9px; font-style: normal; line-height: 15px; text-align: center; padding: 0 3px;
}
.topbar__avatar { width: 26px; height: 26px; border-radius: 50%; background: #4a4e59;
  display: grid; place-items: center; font-size: 11px; }

/* ======================= Боковое меню =============================== */

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 50;
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  padding-top: 6px;
  display: flex; flex-direction: column;
}
.sidebar__items { flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  min-height: var(--nav-item-h); padding: 8px 6px 8px 12px;
  color: var(--text-invert); font-size: var(--fs-nav); line-height: 14px;
}
.nav-item:hover { background: var(--bg-sidebar-hover); text-decoration: none; }
.nav-item.is-active { background: var(--bg-sidebar-active); }
.nav-item__icon { width: 15px; flex: 0 0 15px; text-align: center; opacity: .92; font-size: 13px; }
.nav-item__new {
  font-size: 8px; line-height: 10px; background: var(--primary); color: #fff;
  border-radius: 2px; padding: 0 3px; margin-left: auto;
}
.nav-sep { height: 1px; margin: 6px 12px; background: rgba(255,255,255,.12); }
.nav-item--muted { color: #b9bdc6; }
.sidebar__collapse {
  height: 34px; border: 0; background: none; cursor: pointer;
  color: #aeb3bd; font-size: 13px; text-align: left; padding-left: 14px;
}
.sidebar__collapse:hover { background: var(--bg-sidebar-hover); }

/* ======================= Оболочка контента ========================== */

.shell { padding: var(--topbar-h) 0 0 var(--sidebar-w); min-height: 100%; }

.crumbs {
  display: flex; align-items: center; gap: 8px;
  height: var(--crumbs-h); padding: 8px 20px;
  background: #fff; font-size: var(--fs-base);
}
.crumbs span.sep { color: #b6bcbf; }

.page--report { background: var(--bg-report); }
.page--dash   { background: var(--bg-dash); padding: 0 16px 40px; }

/* ---- Панель отчёта (белая, во всю ширину, высота 52) ---- */

.rtoolbar {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  height: var(--rtoolbar-h); padding: 0 30px 0 12px;
  background: #fff; box-shadow: var(--shadow-panel);
}
.rtoolbar__star { border: 0; background: none; cursor: pointer; color: #b6bcbf; font-size: 15px; }
.rtoolbar__name {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-h1); color: var(--text-muted); cursor: pointer; white-space: nowrap;
}
.icon-btn {
  width: 30px; height: 30px; border: 0; border-radius: 4px; background: none;
  cursor: pointer; color: var(--text-muted); font-size: 14px;
}
.icon-btn:hover { background: rgba(27,42,48,.05); }
.rtab {
  height: 36px; padding: 8px 12px; border: 0; border-radius: 4px; background: none;
  font-size: 12px; line-height: 20px; color: var(--text-muted); cursor: pointer; white-space: nowrap;
}
.rtab:hover, .rtab.is-active { background: var(--bg-tab-active); }
.rtoolbar__spacer { flex: 1; }
.btn-ai {
  height: 30px; padding: 0 14px; border: 0; border-radius: 4px; cursor: pointer;
  background: linear-gradient(90deg, #a855f7, #6d5cf0); color: #fff; font-size: 13px;
}

/* ---- Панель периода (белая, высота 48) ---- */

.ptoolbar {
  display: flex; align-items: center; gap: 2px;
  height: var(--period-h); padding: 0 16px 0 20px;
  background: #fff; box-shadow: var(--shadow-panel);
}
.arrow-btn {
  width: 30px; height: 30px; border: 0; background: none; cursor: pointer;
  color: var(--text-muted); font-size: 15px; border-radius: 4px;
}
.arrow-btn:hover { background: rgba(27,42,48,.05); }
.datepick {
  display: flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 8px; border-radius: 4px;
  font-size: var(--fs-base); cursor: pointer; white-space: nowrap;
}
.datepick:hover { background: rgba(27,42,48,.05); }
.preset {
  border: 0; background: none; cursor: pointer;
  font-size: 13px; color: var(--link); padding: 12px 14px;
}
.preset:hover { text-decoration: underline; }
.preset.is-active { color: var(--text); font-weight: 700; text-decoration: none; cursor: default; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px;
  color: var(--text); cursor: pointer; margin-left: 10px; white-space: nowrap; }
.ptoolbar__spacer { flex: 1; }
.ptoolbar__div { width: 1px; height: 24px; background: #e4e6e8; margin: 0 6px; }

/* Переключатель базы дат — наш элемент, у Roistat его нет */
.switch { display: inline-flex; border-radius: 4px; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--line-input); }
.switch button {
  border: 0; background: #fff; cursor: pointer; font-size: 13px;
  color: var(--text-faint); padding: 6px 12px;
}
.switch button.is-active { background: var(--primary); color: #fff; }

/* ---- Плашки свежести ---- */

.flash { display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 20px; font-size: 13px; line-height: 18px; }
.flash--warn   { background: var(--warn-bg);   color: #7a5510; }
.flash--danger { background: var(--danger-bg); color: #8d2b2e; }
/* панели периода и плашки идут во всю ширину и на дашборде */
.page--dash > .ptoolbar, .page--dash > .flash { margin: 0 -16px; }

/* ======================= Панель графика ============================= */

.chartpanel { display: flex; background: #fff; box-shadow: var(--shadow-panel); }
.chartpanel__main { flex: 1; min-width: 0; padding-bottom: 8px; }
.chartpanel__head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 8px 16px; font-size: 13px;
}
.chartpanel__head .link { color: var(--link); cursor: pointer; }
.btn-outline {
  height: 26px; padding: 0 10px; border-radius: 4px; border: 0; background: #fff;
  box-shadow: inset 0 0 0 1px var(--line-input); color: var(--link);
  font-size: 12px; cursor: pointer;
}
.chartbox { position: relative; }
.chartbox__svg { position: relative; width: 100%; height: 280px; cursor: crosshair; }
.chart { display: block; }
.chart .grid { stroke: #eceeef; stroke-width: 1; }
.chart .axis { fill: var(--text-faint); font-size: 10px; }
.chart .band { fill: #f7f8f9; }
.chart .ln { fill: none; stroke-width: 1.5; }
.chart .cursor { stroke: #cccccc; stroke-width: 1; }
.chart .hover-dot { stroke: #fff; stroke-width: 1.5; }
.chart .act { stroke: #c9ced1; stroke-width: 1; stroke-dasharray: 3 3; }
.chart .act-flag { fill: #eef0f2; }
.chart .act-txt { fill: #8f989c; font-size: 9px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 8px; }
.legend-chip { height: 20px; padding: 0 8px; border: 0; border-radius: var(--radius-chip);
  font-size: var(--fs-chip); line-height: 20px; color: #fff; cursor: pointer; }

/* Переключатель «% / единицы» — наш элемент, у Roistat только % */
.modes { display: inline-flex; border-radius: 4px; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--line-input); }
.modes button { border: 0; background: #fff; cursor: pointer; font-size: 12px;
  color: var(--text-faint); padding: 4px 10px; }
.modes button.is-active { background: var(--primary); color: #fff; }
.modes button:disabled { color: #c2c7ca; cursor: not-allowed; }

/* Тултип графика */
.tip { position: absolute; display: none; width: 240px; z-index: 6; pointer-events: none;
  background: rgba(255, 255, 255, .92); border-radius: 4px;
  box-shadow: 0 3px 15px rgba(27, 42, 48, .2); }
.tip__head { padding: 5px 10px; font-size: 14px; font-weight: 600; text-align: right; }
.tip__body { padding: 6px 10px 6px; }
.tip__row { display: flex; align-items: center; gap: 8px; height: 18px; font-size: 13px; }
.tip__dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; }
.tip__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip__val { font-variant-numeric: tabular-nums; }
.tip__act { margin-top: 4px; padding-top: 4px; border-top: 1px solid #eceeef;
  font-size: 12px; color: var(--text-faint); }

/* ---- Правая панель метрик ---- */

.metricpanel {
  width: var(--metricpanel-w); flex: 0 0 var(--metricpanel-w);
  border-left: 1px solid var(--line-cell); padding: 8px 10px; background: #fff;
}
.metricpanel__head { display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-dim); }
.metricpanel__head .icon-btn { width: 22px; height: 22px; font-size: 12px; }
.metricpanel__search {
  width: 100%; height: 28px; margin: 6px 0 8px; padding: 0 8px 0 24px;
  border: 0; border-radius: 4px; font-size: 13px; color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-input);
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><circle cx='5' cy='5' r='3.6' fill='none' stroke='%238f989c'/><path d='M7.8 7.8 11 11' stroke='%238f989c' fill='none'/></svg>") no-repeat 7px 50%;
}
.chips { display: flex; flex-direction: column; align-items: flex-start; gap: 5px;
  max-height: 300px; overflow-y: auto; }
.chip {
  flex: 0 0 auto;
  height: 20px; padding: 0 8px; border-radius: var(--radius-chip); border: 0;
  font-size: var(--fs-chip); line-height: 20px; cursor: pointer;
  background: none; color: var(--text-faint);
  box-shadow: inset 0 0 0 1px var(--line-input);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.is-on { color: #fff; }

/* ======================= Таблица отчёта ============================= */

.tablepanel { background: #fff; box-shadow: var(--shadow-panel); }
.table-scroll { overflow-x: auto; }

table.rep { width: 100%; border-collapse: collapse; font-size: var(--fs-table); }
table.rep th, table.rep td {
  padding: 0 8px; white-space: nowrap; border-left: 1px solid var(--line-cell);
}
table.rep th:first-child, table.rep td:first-child { border-left: 0; }

table.rep thead th {
  height: var(--head-h); padding-top: 6px; padding-bottom: 8px;
  font-size: var(--fs-thead); font-weight: 600; color: var(--text);
  text-align: center; vertical-align: middle; white-space: normal; line-height: 14px;
  background: #fff; position: sticky; top: 0; z-index: 3; cursor: pointer; user-select: none;
}
table.rep thead th:first-child { text-align: left; }
table.rep thead th .sort { color: #c2c7ca; margin-left: 3px; font-size: 10px; }
table.rep thead th.is-sorted .sort { color: var(--text); }
table.rep thead th.is-muted { color: #b6bcbf; cursor: not-allowed; }

table.rep tbody tr { height: var(--row-h); }
table.rep tbody td {
  border-top: 1px solid var(--line-row); text-align: right;
  font-variant-numeric: tabular-nums; color: var(--text);
}
table.rep tbody td:first-child { text-align: left; }
table.rep tbody tr:hover td { background: var(--bg-row-hover); }

tr.total td { background: var(--bg-total); font-size: var(--fs-total); font-weight: 600;
  position: sticky; top: var(--head-h); z-index: 2; }
tr.total:hover td { background: var(--bg-total); }
tr.total .total__label { font-size: 12px; font-weight: 400; color: var(--text-dim); }
.total__tools { display: flex; gap: 10px; color: #b6bcbf; font-size: 12px; }

/* Закреплённая первая колонка + её граница, как у Roistat */
table.rep th:first-child, table.rep td:first-child {
  position: sticky; left: 0; z-index: 1; background: #fff;
  min-width: 340px; max-width: 340px; box-shadow: var(--shadow-sticky);
}
table.rep thead th:first-child { z-index: 4; }
tr.total td:first-child { background: var(--bg-total); z-index: 3; }
table.rep tbody tr:hover td:first-child { background: var(--bg-row-hover); }
.th-search { float: right; color: #b6bcbf; font-size: 12px; }

/* Лучшее и худшее значение в колонке — подчёркивание, как у Roistat */
.v { display: inline-block; }
.v--max { border-bottom: 1px solid var(--max); }
.v--min { border-bottom: 1px solid var(--min); }
.v--link { border-bottom: 1px solid #cfd3d6; cursor: pointer; }

/* Первая колонка: «+», иконка канала, имя, бейджи */
.rowname { display: flex; align-items: center; gap: 6px; overflow: hidden; }
.expander {
  width: 12px; flex: 0 0 12px; border: 0; background: none; cursor: pointer;
  color: #6a7478; font-size: 13px; line-height: 12px; padding: 0; text-align: center;
}
.chan-ico { width: 14px; height: 14px; flex: 0 0 14px; border-radius: 50%;
  display: inline-block; }
.rowname__text { overflow: hidden; text-overflow: ellipsis; }
.pin { color: #c2c7ca; font-size: 10px; }
.sup { font-size: 8px; vertical-align: super; color: var(--text-faint); letter-spacing: .3px; }
tr[data-level="2"] .rowname { padding-left: 18px; }
tr[data-level="3"] .rowname { padding-left: 36px; }
tr.is-collapsed-child { display: none; }

.badge { display: inline-block; padding: 0 5px; border-radius: 3px;
  font-size: 9px; line-height: 14px; vertical-align: 2px;
  background: #eef0f2; color: var(--text-faint); margin-left: 4px; }
.badge--utm { background: #eaf3ff; color: var(--link); }
.badge--manual { background: #fdf1e3; color: #9a6414; }

.empty { color: #c2c7ca; }

/* Инлайн-бар доли в ячейке-«якоре» */
.cellbar { position: relative; display: block; height: 20px; width: 128px; margin-left: auto;
  background: var(--bg-track); border-radius: var(--radius-sm); overflow: hidden; }
.cellbar__fill { position: absolute; inset: 0 auto 0 0; background: var(--bg-bar); }
.cellbar__pct  { position: absolute; left: 4px; top: 0; font-size: var(--fs-micro);
  line-height: 20px; color: var(--text-faint); }
.cellbar__val  { position: absolute; right: 4px; top: 0; line-height: 20px; }

.note { font-size: 12px; color: var(--text-faint); padding: 10px 20px; }

/* ======================= Дашборд: карточки ========================== */

.cards { display: grid; gap: var(--gap); margin-top: var(--gap); }
.cards--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cards--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card { background: var(--bg-card); border: 1px solid var(--line-soft);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card); padding: 14px 20px 16px; }
.card__title { font-size: var(--fs-title); font-weight: 700; }
.card__hint  { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.card__value { font-size: 24px; font-weight: 700; line-height: 30px; margin-top: 6px;
  font-variant-numeric: tabular-nums; letter-spacing: -.2px; }
.card__value.is-empty { color: #b6bcbf; font-weight: 400; }
.card__sub { font-size: 13px; color: var(--text-muted); margin-top: 1px; }
.card__pair { display: flex; gap: 26px; margin-top: 6px; }
.card__pair .k { font-size: 12px; color: var(--text-faint); }
.card__pair .v2 { font-size: 19px; font-weight: 700; line-height: 25px; font-variant-numeric: tabular-nums; }
.spark { display: block; width: 100%; height: 44px; margin-top: 6px; }
.section-title { font-size: 12px; font-weight: 700; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .4px; margin: 22px 0 -6px; }

/* Виджет ТОПа: список слева, кольцо справа */
.wtop { display: flex; gap: 12px; align-items: center; margin-top: 10px; }
.toplist { flex: 1; min-width: 0; border-collapse: collapse; font-size: var(--fs-table); }
.toplist td { padding: 4px 4px; border-top: 1px solid #eceeef; }
.toplist tr:first-child td { border-top: 0; }
.toplist td:first-child { display: flex; align-items: center; gap: 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toplist td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.toplist thead td { color: var(--text-faint); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; display: inline-block; }
.donut { width: 190px; height: 190px; flex: 0 0 190px; }
.donut text.t1 { fill: var(--text-faint); font-size: 11px; }
.donut text.t2 { fill: var(--text); font-size: 15px; font-weight: 700; }

/* ======================= Телефон (спец. 2.6) ======================== */

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  .shell { padding-left: 0; }
  .cards--4, .cards--3, .cards--2 { grid-template-columns: 1fr; }
  .rtoolbar, .ptoolbar { flex-wrap: wrap; height: auto; padding: 6px 12px; }
  .metricpanel { display: none; }
  .wtop { flex-direction: column; }
  .donut { width: 160px; height: 160px; flex: 0 0 160px; }

  table.rep thead { display: none; }
  table.rep, table.rep tbody, table.rep tr, table.rep td { display: block; width: auto; }
  table.rep tbody tr { height: auto; padding: 10px 14px; border-top: 1px solid var(--line-row); }
  table.rep tbody td { border: 0; text-align: right; display: flex;
    justify-content: space-between; gap: 12px; padding: 2px 0; white-space: normal; }
  table.rep tbody td::before { content: attr(data-label); color: var(--text-faint); text-align: left; }
  table.rep th:first-child, table.rep td:first-child {
    position: static; max-width: none; min-width: 0; box-shadow: none; }
  table.rep tbody td:first-child { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
  table.rep tbody td:first-child::before { content: none; }
  table.rep td.m-hide { display: none; }
  tr.total td { position: static; }
  .cellbar { width: 100%; max-width: 140px; }
}

/* ==================== Вход и пустые состояния (блок 2а) ==================== */

.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-dash);
}

.auth__card {
  width: 100%;
  max-width: 420px;
  padding: 32px;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.auth__brand {
  margin-bottom: 24px;
  font-size: 19px;
  letter-spacing: .2px;
  color: var(--text);
}

.auth__brand b { color: var(--primary); font-weight: 400; }

.auth__title {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.25;
  color: var(--text);
}

.auth__lead {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-muted);
}

.auth__form { display: flex; flex-direction: column; gap: 8px; }

.auth__label { font-size: 12px; color: var(--text-faint); }

.auth__input {
  height: 40px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-input);
  border-radius: var(--radius-sm);
}

.auth__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(50, 70, 211, .12);
}

.auth__submit {
  height: 40px;
  margin-top: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-invert);
  background: var(--primary);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.auth__submit:hover { background: var(--brand-accent); }

.auth__hint {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--text-faint);
}

.topbar__logout { display: inline-flex; margin: 0; }

.empty-state {
  max-width: 620px;
  margin: 72px auto;
  padding: 40px;
  text-align: center;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.empty-state__title {
  margin-bottom: 10px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.empty-state__text {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
}
