/* ═══════════════════════════════════════════════════════════
   IMAGO · ADMIN — style.css
   Одна тема — тёмная.
   Размеры — rem/clamp, раскладка — grid/flex + @media.
   ═══════════════════════════════════════════════════════════ */

@layer reset, base, layout, components, utilities;

/* ── Токены ─────────────────────────────────────────────── */
:root {
  --paper:     #141317;
  --surface:   #1C1B21;
  --surface-2: #232228;
  --line:      #2C2B33;
  --line-2:    #3A3942;
  --ink:       #F1EFF4;
  --ink-2:     #A9A6B3;
  --ink-3:     #6F6C79;
  --brand:     #F5C6D4;
  --brand-2:   #E08AA6;
  --brand-ink: #F5C6D4;
  --ok-bg:   rgba(30,142,90,.18);
  --err-bg:  rgba(201,58,63,.18);
  --warn-bg: rgba(184,121,14,.18);
  --info-bg: rgba(46,98,217,.18);
  --ok:   #4CC38A; --err: #F17378; --warn: #E1A23A; --info: #7DA3F5;
  --shadow-1: 0 0 0 1px var(--line);
  --shadow-2: 0 16px 40px -8px rgba(0,0,0,.6), 0 0 0 1px var(--line);
  color-scheme: dark;
  --radius-s: .375rem;
  --radius:   .75rem;
  --radius-l: 1rem;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --rail-w: 15rem;
  --rail-w-compact: 4.25rem;
  --topbar-h: 3.5rem;
}

/* ── Reset ──────────────────────────────────────────────── */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { font-size: 100%; -webkit-text-size-adjust: 100%; }
  body { min-height: 100svh; line-height: 1.5; -webkit-font-smoothing: antialiased; }
  img, svg { display: block; max-width: 100%; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; background: none; border: 0; padding: 0; }
  table { border-collapse: collapse; border-spacing: 0; }
  a { color: inherit; }
  [hidden] { display: none !important; }
  :focus-visible { outline: 2px solid var(--info); outline-offset: 2px; border-radius: var(--radius-s); }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
  }
}

/* ── Base ───────────────────────────────────────────────── */
@layer base {
  body {
    font-family: var(--font);
    font-size: .9375rem;
    color: var(--ink);
    background: var(--paper);
    font-feature-settings: 'tnum' 1, 'cv11' 1;
  }
  h1, h2, h3 { font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
  h1 { font-size: clamp(1.375rem, 1.1rem + 1vw, 1.75rem); }
  h2 { font-size: 1.125rem; }
  h3 { font-size: .9375rem; }
  ::selection { background: var(--brand); color: var(--paper); }
}

/* ═══════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════ */
@layer layout {
  .app {
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    min-height: 100svh;
  }

  /* — Боковая панель — */
  .rail {
    position: sticky; top: 0;
    height: 100svh;
    display: flex; flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 1rem .75rem;
    gap: .5rem;
  }
  .rail__brand {
    display: flex; align-items: center; gap: .625rem;
    padding: .375rem .5rem .875rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: .5rem;
    text-decoration: none;
  }
  .rail__mark {
    width: 2rem; height: 2rem; flex: none;
    border-radius: 50%;
    background: var(--ink);
    color: var(--brand);
    display: grid; place-items: center;
    font-weight: 800; font-size: .75rem; letter-spacing: -.02em;
  }
  .rail__name { font-weight: 700; font-size: .9375rem; line-height: 1.1; }
  .rail__sub  { font-size: .75rem; color: var(--ink-3); }

  .rail__nav { display: flex; flex-direction: column; gap: .125rem; flex: 1; }
  .rail__section {
    font-size: .6875rem; color: var(--ink-3); font-weight: 600;
    padding: .875rem .625rem .375rem;
  }
  .nav-item {
    display: flex; align-items: center; gap: .625rem;
    width: 100%;
    padding: .5625rem .625rem;
    border-radius: var(--radius-s);
    color: var(--ink-2);
    font-weight: 600; font-size: .875rem;
    text-align: left; text-decoration: none;
    transition: background .12s, color .12s;
  }
  .nav-item svg { width: 1.125rem; height: 1.125rem; flex: none; stroke: currentColor; }
  .nav-item:hover { background: var(--surface-2); color: var(--ink); }
  .nav-item[aria-current="page"] {
    background: var(--brand);
    color: var(--ink);
  }
  .nav-item[aria-current="page"] { background: rgba(245,198,212,.16); color: var(--brand); }
  .nav-item__badge {
    margin-left: auto; font-size: .6875rem; font-weight: 700;
    background: var(--surface-2); color: var(--ink-2);
    padding: .0625rem .375rem; border-radius: 999px;
  }

  .rail__foot {
    border-top: 1px solid var(--line);
    padding-top: .625rem;
    display: flex; flex-direction: column; gap: .125rem;
  }

  /* — Верхняя панель (только мобайл) — */
  .topbar {
    display: none;
    position: sticky; top: 0; z-index: 30;
    height: var(--topbar-h);
    align-items: center; gap: .75rem;
    padding: 0 1rem;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .topbar__title { font-weight: 700; flex: 1; }

  /* — Затемнение под мобильной рельсой; на десктопе не участвует в сетке — */
  .scrim { display: none; }

  /* — Контент — */
  .main { min-width: 0; }
  .page { display: none; }
  .page.is-active { display: block; }
  .page__inner {
    width: min(100% - 3rem, 82rem);
    margin-inline: auto;
    padding-block: 1.75rem 3rem;
  }
  .page__head {
    display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem;
    margin-bottom: 1.25rem;
  }
  .page__title { display: flex; align-items: baseline; gap: .625rem; }
  .page__count { font-size: .875rem; color: var(--ink-3); font-weight: 600; }
  .page__actions { display: flex; flex-wrap: nowrap; gap: .5rem; margin-left: auto; align-items: center; }

  /* — Планшет: рельса сжимается до иконок — */
  @media (max-width: 64rem) {
    .app { grid-template-columns: var(--rail-w-compact) minmax(0, 1fr); }
    .rail { padding-inline: .5rem; }
    .rail__name, .rail__sub, .rail__section, .nav-item__label, .nav-item__badge { display: none; }
    .rail__brand { justify-content: center; padding-inline: 0; }
    .nav-item { justify-content: center; padding: .625rem; }
    .nav-item svg { width: 1.25rem; height: 1.25rem; }
  }

  /* — Телефон: рельса выезжает поверх — */
  @media (max-width: 45rem) {
    .app { grid-template-columns: minmax(0, 1fr); }
    .topbar { display: flex; }
    .rail {
      position: fixed; inset: 0 auto 0 0; z-index: 40;
      width: var(--rail-w);
      transform: translateX(-100%);
      transition: transform .22s ease;
      box-shadow: var(--shadow-2);
      padding-inline: .75rem;
    }
    .rail.is-open { transform: none; }
    .rail__name, .rail__sub, .rail__section, .nav-item__label, .nav-item__badge { display: revert; }
    .rail__brand { justify-content: flex-start; padding-inline: .5rem; }
    .nav-item { justify-content: flex-start; padding: .5625rem .625rem; }
    .nav-item svg { width: 1.125rem; height: 1.125rem; }
    .scrim {
      display: block;
      position: fixed; inset: 0; z-index: 35;
      background: rgba(28,27,34,.4);
      opacity: 0; pointer-events: none; transition: opacity .2s;
    }
    .scrim.is-open { opacity: 1; pointer-events: auto; }
    .page__inner { width: min(100% - 2rem, 82rem); padding-block: 1.25rem 2.5rem; }
    .page__actions { flex-wrap: wrap; width: 100%; margin-left: 0; }
  }
}

/* ═══════════════════════════════════════════════════════════
   COMPONENTS
   ═══════════════════════════════════════════════════════════ */
@layer components {

  /* — Кнопки — */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: 2.375rem; padding: 0 .875rem;
    border-radius: var(--radius-s);
    font-weight: 600; font-size: .875rem; white-space: nowrap;
    border: 1px solid var(--line-2);
    background: var(--surface); color: var(--ink);
    transition: background .12s, border-color .12s, transform .06s;
  }
  .btn svg { width: 1rem; height: 1rem; stroke: currentColor; }
  .btn:hover { background: var(--surface-2); }
  .btn:active { transform: translateY(1px); }
  .btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
  .btn--primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
  .btn--primary:hover { background: #2E2D36; }
  .btn--primary { background: var(--brand); color: #1C1B22; border-color: var(--brand); }
  .btn--primary:hover { background: var(--brand-2); }
  .btn--danger { color: var(--err); }
  .btn--danger:hover { background: var(--err-bg); border-color: transparent; }
  .btn--ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
  .btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
  .btn--sm { min-height: 1.875rem; padding: 0 .625rem; font-size: .8125rem; }
  .btn--icon { width: 2.375rem; padding: 0; }
  .btn--icon.btn--sm { width: 1.875rem; }

  /* — Поля — */
  .field { display: flex; flex-direction: column; gap: .375rem; min-width: 0; }
  .field__label { font-size: .8125rem; font-weight: 600; color: var(--ink-2); }
  .field__label small { font-weight: 500; color: var(--ink-3); }
  .field__hint { font-size: .75rem; color: var(--ink-3); line-height: 1.4; }
  .input, .select, .textarea {
    width: 100%;
    min-height: 2.375rem;
    padding: .5rem .75rem;
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-s);
    color: var(--ink);
    transition: border-color .12s, box-shadow .12s;
  }
  .input::placeholder, .textarea::placeholder { color: var(--ink-3); }
  .input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 60%, transparent);
  }
  .textarea { min-height: 6rem; resize: vertical; line-height: 1.5; }
  .select {
    appearance: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236B6875' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .625rem center;
  }
  .search {
    position: relative; min-width: 14rem;
  }
  .search .input { padding-left: 2.25rem; }
  .search svg {
    position: absolute; left: .75rem; top: 50%; translate: 0 -50%;
    width: 1rem; height: 1rem; stroke: var(--ink-3); pointer-events: none;
  }
  .field-row {
    display: grid; gap: .875rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
  }

  /* — Поверхность — */
  .card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
  }
  .card__head {
    display: flex; align-items: center; gap: .75rem;
    padding: .875rem 1.125rem;
    border-bottom: 1px solid var(--line);
  }
  .card__head h2, .card__head h3 { flex: 1; }
  .card__body { padding: 1.125rem; }

  /* — Лента показателей (дашборд) — */
  .ledger {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
    margin-bottom: 1.25rem;
    overflow: hidden;
  }
  .ledger__cell {
    padding: 1.125rem 1.25rem;
    display: flex; flex-direction: column; gap: .25rem;
    border-right: 1px solid var(--line);
    position: relative;
  }
  .ledger__cell:last-child { border-right: 0; }
  .ledger__label { font-size: .8125rem; color: var(--ink-2); font-weight: 600; }
  .ledger__value {
    font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
    font-weight: 800; letter-spacing: -.02em; line-height: 1.1;
  }
  .ledger__sub { font-size: .8125rem; color: var(--ink-3); }
  .ledger__cell--accent .ledger__value { color: var(--brand-ink); }
  .ledger__cell--ok  .ledger__value { color: var(--ok); }
  .ledger__cell--err .ledger__value { color: var(--err); }
  @media (max-width: 45rem) {
    .ledger__cell { border-right: 0; border-bottom: 1px solid var(--line); }
    .ledger__cell:last-child { border-bottom: 0; }
  }

  /* — Воронка и здоровье — */
  .funnel { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: 0; }
  .funnel__step { padding: 1rem 1.25rem; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: .125rem; }
  .funnel__step:last-child { border-right: 0; }
  .funnel__n { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
  .funnel__l { font-size: .8125rem; color: var(--ink-2); font-weight: 600; }
  .funnel__p { font-size: .75rem; color: var(--ink-3); }
  .funnel__bar { height: .25rem; border-radius: 999px; background: var(--line); margin-top: .5rem; overflow: hidden; }
  .funnel__bar i { display: block; height: 100%; background: var(--brand); width: var(--w, 0%); }
  @media (max-width: 45rem) { .funnel__step { border-right: 0; border-bottom: 1px solid var(--line); } .funnel__step:last-child { border-bottom: 0; } }

  .health { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; padding: .875rem 1.25rem; font-size: .8125rem; color: var(--ink-2); align-items: center; }
  .health__item { display: inline-flex; align-items: center; gap: .4rem; }
  .health__dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--ok); }
  .health__dot--warn { background: var(--warn); } .health__dot--err { background: var(--err); }
  .health b { color: var(--ink); font-weight: 700; }

  /* — Кликабельный пользователь — */
  .who--link { cursor: pointer; border-radius: var(--radius-s); margin: -.25rem; padding: .25rem; }
  .who--link:hover { background: var(--surface-2); }
  .who--link:hover .who__name { text-decoration: underline; text-underline-offset: .15em; }
  .avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
  .avatar--lg { width: 3.25rem; height: 3.25rem; font-size: 1rem; }

  /* — Карточка пользователя (выезжает справа) — */
  .modal.drawer { inset: 0; margin: 0 0 0 auto; width: min(100vw, 34rem); height: 100svh; max-height: 100svh; }
  .drawer .modal__panel { width: min(100vw, 34rem); height: 100svh; max-height: 100svh; border-radius: 0; }
  .drawer .modal__body { gap: 1.25rem; }
  .uc-head { display: flex; align-items: center; gap: .875rem; }
  .uc-head__name { font-size: 1.125rem; font-weight: 800; letter-spacing: -.01em; }
  .uc-head__sub { font-size: .8125rem; color: var(--ink-3); display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
  .uc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: .5rem; }
  .uc-stat { padding: .75rem .875rem; border-radius: var(--radius-s); background: var(--surface-2); }
  .uc-stat__v { font-size: 1.125rem; font-weight: 800; letter-spacing: -.01em; }
  .uc-stat__l { font-size: .75rem; color: var(--ink-3); }
  .uc-section { display: flex; flex-direction: column; gap: .5rem; }
  .uc-section h3 { display: flex; align-items: baseline; gap: .5rem; }
  .uc-section h3 small { font-weight: 600; color: var(--ink-3); }
  .uc-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
  .uc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .75rem; align-items: center; padding: .5625rem .75rem; border-bottom: 1px solid var(--line); font-size: .8125rem; }
  .uc-row:last-child { border-bottom: 0; }
  .uc-row__t { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .uc-row__s { font-size: .75rem; color: var(--ink-3); }
  .uc-empty { padding: .875rem; font-size: .8125rem; color: var(--ink-3); text-align: center; }
  .quick { display: flex; flex-wrap: wrap; gap: .375rem; }

  .charts { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); margin-bottom: 1.25rem; }
  .chart { height: 15rem; padding: .5rem 1rem 1rem; }

  /* — Источники — */
  .sources { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); }
  .source {
    padding: .875rem 1rem; border-radius: var(--radius-s);
    background: var(--surface-2);
    display: flex; flex-direction: column; gap: .125rem;
  }
  .source__name { font-size: .8125rem; font-weight: 700; display: flex; align-items: center; gap: .4rem; }
  .source__dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--dot, var(--ink-3)); }
  .source__value { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
  .source__sub { font-size: .75rem; color: var(--ink-3); }

  /* — Таблицы — */
  .table-card { overflow: hidden; }
  .table-scroll { overflow-x: auto; overscroll-behavior-x: contain; }
  .table { width: 100%; font-size: .875rem; }
  .table th, .table td { padding: .6875rem .875rem; text-align: left; vertical-align: middle; }
  .table th {
    font-size: .75rem; font-weight: 700; color: var(--ink-2);
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    position: sticky; top: 0; z-index: 1;
  }
  .table td { border-bottom: 1px solid var(--line); }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
  .table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .table .mono { font-family: var(--mono); font-size: .8125rem; color: var(--ink-2); }
  .table .muted { color: var(--ink-3); }
  .table .strong { font-weight: 700; }
  .table .nowrap { white-space: nowrap; }
  .table .clip { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .table .actions { display: flex; gap: .375rem; justify-content: flex-end; }
  .table .actions-col { width: 1%; }

  .who { display: flex; align-items: center; gap: .625rem; min-width: 0; }
  .avatar {
    width: 2rem; height: 2rem; flex: none; border-radius: 50%;
    display: grid; place-items: center;
    font-size: .75rem; font-weight: 800;
    background: var(--brand); color: var(--ink);
  }
  .who__name { font-weight: 600; line-height: 1.2; }
  .who__sub { font-size: .75rem; color: var(--ink-3); line-height: 1.3; }

  .money { font-weight: 700; font-variant-numeric: tabular-nums; }
  .money--in  { color: var(--ok); }
  .money--acc { color: var(--brand-ink); }

  /* — Бейджи — */
  .badge {
    display: inline-flex; align-items: center; gap: .375rem;
    padding: .1875rem .5625rem;
    border-radius: 999px;
    font-size: .75rem; font-weight: 700; white-space: nowrap;
    background: var(--surface-2); color: var(--ink-2);
  }
  .badge::before { content: ''; width: .375rem; height: .375rem; border-radius: 50%; background: currentColor; }
  .badge--ok   { background: var(--ok-bg);   color: var(--ok); }
  .badge--err  { background: var(--err-bg);  color: var(--err); }
  .badge--warn { background: var(--warn-bg); color: var(--warn); }
  .badge--info { background: var(--info-bg); color: var(--info); }
  .badge--plain::before { display: none; }

  .chip {
    display: inline-block; padding: .125rem .4375rem;
    border-radius: var(--radius-s);
    background: var(--surface-2); color: var(--ink-2);
    font-size: .75rem; font-weight: 600; margin: .0625rem;
  }
  .chip b { color: var(--ink); font-weight: 700; }
  .code {
    font-family: var(--mono); font-weight: 700; letter-spacing: .04em;
    background: var(--surface-2); padding: .125rem .4rem; border-radius: var(--radius-s);
  }

  /* — Тумблер — */
  .switch { position: relative; display: inline-block; width: 2.5rem; height: 1.5rem; flex: none; }
  .switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
  .switch__track {
    position: absolute; inset: 0; border-radius: 999px;
    background: var(--line-2); transition: background .15s;
  }
  .switch__track::after {
    content: ''; position: absolute; top: .1875rem; left: .1875rem;
    width: 1.125rem; height: 1.125rem; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25);
    transition: translate .15s;
  }
  .switch input:checked + .switch__track { background: var(--ok); }
  .switch input:checked + .switch__track::after { translate: 1rem 0; }
  .switch input:focus-visible + .switch__track { outline: 2px solid var(--info); outline-offset: 2px; }

  /* — Пагинация — */
  .pager {
    display: flex; align-items: center; gap: .25rem; flex-wrap: wrap;
    padding: .75rem .875rem;
    border-top: 1px solid var(--line);
  }
  .pager__info { margin-left: auto; font-size: .8125rem; color: var(--ink-3); }
  .pager .btn.is-current { background: var(--ink); color: var(--paper); border-color: var(--ink); }
  .pager .btn.is-current { background: var(--brand); color: #1C1B22; border-color: var(--brand); }

  /* — Пустое состояние / загрузка — */
  .empty {
    display: flex; flex-direction: column; align-items: center; gap: .5rem;
    padding: 3rem 1rem; text-align: center; color: var(--ink-3);
  }
  .empty svg { width: 2.25rem; height: 2.25rem; stroke: var(--line-2); }
  .empty__title { font-weight: 700; color: var(--ink-2); }
  .skeleton { padding: 1rem; display: flex; flex-direction: column; gap: .625rem; }
  .skeleton__line {
    height: .875rem; border-radius: var(--radius-s);
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s linear infinite;
  }
  @keyframes shimmer { to { background-position: -200% 0; } }

  /* — Рассылка — */
  .composer { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
  @media (max-width: 64rem) { .composer { grid-template-columns: minmax(0, 1fr); } }
  .composer__form { display: flex; flex-direction: column; gap: 1.125rem; }

  .audience { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 12.5rem), 1fr)); }
  .audience__opt { position: relative; }
  .audience__opt input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
  .audience__card {
    display: flex; flex-direction: column; gap: .125rem;
    padding: .75rem .875rem;
    border: 1px solid var(--line-2); border-radius: var(--radius-s);
    background: var(--surface);
    transition: border-color .12s, background .12s;
  }
  .audience__title { font-weight: 700; font-size: .875rem; }
  .audience__desc  { font-size: .75rem; color: var(--ink-3); line-height: 1.35; }
  .audience__opt input:checked + .audience__card {
    border-color: var(--ink); background: color-mix(in srgb, var(--brand) 22%, var(--surface));
  }
  .audience__opt input:focus-visible + .audience__card { outline: 2px solid var(--info); outline-offset: 2px; }

  .fmt {
    display: flex; flex-wrap: wrap; align-items: center; gap: .25rem;
    padding: .375rem; border: 1px solid var(--line-2); border-bottom: 0;
    border-radius: var(--radius-s) var(--radius-s) 0 0; background: var(--surface-2);
  }
  .fmt + .textarea { border-top-left-radius: 0; border-top-right-radius: 0; }
  .fmt__btn {
    min-width: 2rem; height: 1.875rem; padding: 0 .5rem;
    display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
    border-radius: var(--radius-s); font-size: .875rem; font-weight: 600; color: var(--ink-2);
    transition: background .12s, color .12s;
  }
  .fmt__btn:hover { background: var(--surface); color: var(--ink); }
  .fmt__btn svg { width: .875rem; height: .875rem; }
  .fmt__sep { width: 1px; height: 1.25rem; background: var(--line-2); margin-inline: .25rem; }
  .fmt__hint { margin-left: auto; font-size: .75rem; color: var(--ink-3); padding-right: .375rem; }
  @media (max-width: 45rem) { .fmt__hint { display: none; } }

  .drop {
    border: 1.5px dashed var(--line-2); border-radius: var(--radius-s);
    padding: 1rem; text-align: center; color: var(--ink-3); font-size: .8125rem;
    display: flex; flex-direction: column; align-items: center; gap: .375rem;
    cursor: pointer; transition: border-color .12s, background .12s;
  }
  .drop:hover, .drop.is-over { border-color: var(--ink); background: var(--surface-2); }
  .drop svg { width: 1.25rem; height: 1.25rem; stroke: currentColor; }
  .drop input { display: none; }
  .drop__file {
    display: flex; align-items: center; gap: .625rem;
    padding: .5rem .75rem; border-radius: var(--radius-s);
    background: var(--surface-2); font-size: .8125rem;
  }
  .drop__file img { width: 2.5rem; height: 2.5rem; object-fit: cover; border-radius: var(--radius-s); }
  .drop__file span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .tg-preview {
    background: #0F1620;
    border-radius: var(--radius);
    padding: 1.25rem 1rem;
    min-height: 16rem;
    display: flex; flex-direction: column; gap: .75rem;
    background-image: radial-gradient(rgba(255,255,255,.05) 1px, transparent 1px);
    background-size: 14px 14px;
  }
  .tg-preview { background-color: #0F1620; }
  .tg-bubble {
    max-width: 22rem;
    background: #212D3B; color: #E8EEF5;
    border-radius: .875rem .875rem .875rem .25rem;
    padding: .5rem .75rem .375rem;
    font-size: .9375rem; line-height: 1.4;
    box-shadow: 0 1px 1px rgba(0,0,0,.08);
    overflow-wrap: anywhere;
  }
  .tg-bubble { background: #212D3B; color: #E8EEF5; }
  .tg-bubble img { border-radius: .5rem; margin: -.5rem -.75rem .5rem; max-width: calc(100% + 1.5rem); width: calc(100% + 1.5rem); }
  .tg-bubble a { color: #67B5F2; }
  .tg-bubble__time { text-align: right; font-size: .6875rem; color: #9AA8B7; margin-top: .125rem; }
  .tg-bubble__empty { color: #98A2AE; font-style: italic; }
  .tg-meta { font-size: .8125rem; color: var(--ink-2); display: flex; flex-direction: column; gap: .25rem; }
  .tg-meta b { color: var(--ink); }

  .notice {
    display: flex; gap: .625rem; align-items: flex-start;
    padding: .75rem .875rem; border-radius: var(--radius-s);
    font-size: .875rem; line-height: 1.45;
    background: var(--surface-2); color: var(--ink-2);
  }
  .notice svg { width: 1.125rem; height: 1.125rem; flex: none; stroke: currentColor; margin-top: .0625rem; }
  .notice--ok   { background: var(--ok-bg);   color: var(--ok); }
  .notice--err  { background: var(--err-bg);  color: var(--err); }
  .notice--info { background: var(--info-bg); color: var(--info); }

  /* — Модалки — */
  .modal { margin: auto; border: 0; padding: 0; background: transparent; max-width: none; max-height: none; }
  .modal::backdrop { background: rgba(28,27,34,.45); backdrop-filter: blur(2px); }
  .modal__panel {
    width: min(100vw - 2rem, 34rem);
    background: var(--surface);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-2);
    color: var(--ink);
    display: flex; flex-direction: column;
    max-height: calc(100svh - 2rem);
  }
  .modal__head {
    display: flex; align-items: center; gap: .75rem;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--line);
  }
  .modal__head h2 { flex: 1; }
  .modal__body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; overflow: auto; }
  .modal__foot {
    display: flex; gap: .5rem; justify-content: flex-end;
    padding: .875rem 1.25rem; border-top: 1px solid var(--line);
  }
  .modal--wide .modal__panel { width: min(100vw - 2rem, 42rem); }

  /* — Тосты — */
  .toasts {
    position: fixed; right: 1rem; bottom: 1rem; z-index: 60;
    display: flex; flex-direction: column; gap: .5rem;
    width: min(100vw - 2rem, 22rem);
  }
  .toast {
    display: flex; gap: .625rem; align-items: flex-start;
    padding: .75rem .875rem; border-radius: var(--radius-s);
    background: var(--ink); color: var(--paper);
    font-size: .875rem; line-height: 1.4;
    box-shadow: var(--shadow-2);
    animation: toast-in .18s ease-out;
  }
  .toast { background: var(--surface-2); color: var(--ink); }
  .toast svg { width: 1.125rem; height: 1.125rem; flex: none; stroke: currentColor; }
  .toast--ok  svg { stroke: #4CC38A; }
  .toast--err svg { stroke: #F17378; }
  @keyframes toast-in { from { opacity: 0; translate: 0 .5rem; } }

  /* — Логин — */
  .login {
    min-height: 100svh;
    display: grid; place-items: center;
    padding: 1.5rem;
    background:
      radial-gradient(60rem 40rem at 10% -10%, color-mix(in srgb, var(--brand) 55%, transparent), transparent 60%),
      var(--paper);
  }
  .login__card {
    width: min(100%, 22rem);
    display: flex; flex-direction: column; gap: 1.25rem;
    padding: 2rem;
  }
  .login__brand { display: flex; align-items: center; gap: .75rem; }
  .login__brand .rail__mark { width: 2.5rem; height: 2.5rem; font-size: .875rem; }
  .login__title { font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; }
  .login__sub { font-size: .8125rem; color: var(--ink-3); }
}

/* ═══════════════════════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════════════════════ */
@layer utilities {
  /* в шапке страницы контролы не растягиваются (слой выше components — иначе проигрывает width:100%) */
  .page__actions .select { width: auto; min-width: 8.5rem; }
  .page__actions .search { flex: 1 1 15rem; max-width: 20rem; }
  .page__actions .search .input { width: 100%; }
  .visually-hidden {
    position: absolute !important; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .stack { display: flex; flex-direction: column; gap: 1.25rem; }
  .row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
  .grow { flex: 1; min-width: 0; }
  .mt-1 { margin-top: .5rem; }
  .text-2 { color: var(--ink-2); }
  .text-3 { color: var(--ink-3); }
  .small { font-size: .8125rem; }
  .icon { width: 1rem; height: 1rem; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
}

/* ═══════════════════════════════════════════════════════════
   ИТЕРАЦИЯ: история, сравнение, активность, адресная рассылка
   ═══════════════════════════════════════════════════════════ */
/* ✦ Вторичный текст осветлён: исходный --ink-3 не проходил AA на тёмных карточках. */
:root { --ink-3: #A09CA9; }
@layer layout {
  .page__actions { flex-wrap: wrap; min-width: 0; }
  .page__head > *, .workspace > *, .composer > * { min-width: 0; }
  .page__actions .input, .page__actions .select { max-width: 100%; }
  .workspace {
    display: grid;
    grid-template-columns: minmax(0,1fr) minmax(0,0fr);
    align-items: start;
    column-gap: 0;
    transition: grid-template-columns .25s ease, column-gap .25s ease;
  }
  .workspace.is-open { grid-template-columns: minmax(0,1fr) minmax(0,.4fr); column-gap: 1.25rem; }
  .workspace__main { grid-row: 1; grid-column: 1; container: workspace-main / inline-size; min-width: 0; }
  .side-panel { grid-column: 2; grid-row: 1; min-width: 0; overflow: clip; opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .25s; }
  .is-open > .side-panel { opacity: 1; visibility: visible; }
  .side-panel__clip { min-height: 0; min-width: 0; overflow: hidden; }
  .side-panel__body { min-width: 0; }
  .side-panel__content { padding: 1rem; display: grid; gap: 1rem; }
  .side-panel .card__head { align-items: center; flex-wrap: nowrap; }
  .side-panel .card__head h2 { font-size: 1rem; overflow-wrap: anywhere; }
  .side-panel .card__head .btn { flex: none; }
  /* В компактном режиме панель раскрывается перед контентом; одна и та же разметка. */
  @media (max-width: 80rem) {
    .workspace, .workspace.is-open { grid-template-columns: minmax(0,1fr); gap: 0; }
    .side-panel { grid-row: 1; grid-column: 1; display: grid; grid-template-rows: 0fr; transition: grid-template-rows .25s ease, opacity .2s ease, visibility .25s; }
    .workspace.is-open > .side-panel { grid-template-rows: 1fr; }
    .workspace__main { grid-row: 2; }
    .side-panel__body { margin-bottom: 1.25rem; }
    .side-panel__content { max-height: 34rem; overflow-y: auto; overscroll-behavior: contain; }
  }
}
@layer components {
  /* При узкой основной колонке карточки реагируют на контейнер, а не весь экран. */
  @container workspace-main (max-width: 48rem) {
    .charts, .composer { grid-template-columns: minmax(0,1fr); }
    .ledger { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .ledger__cell:nth-child(2) { border-right: 0; }
    .ledger__cell:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  }
  @container workspace-main (max-width: 32rem) {
    .ledger { grid-template-columns: minmax(0,1fr); }
    .ledger__cell { border-right: 0; border-bottom: 1px solid var(--line); }
    .ledger__cell:last-child { border-bottom: 0; }
    .funnel { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .funnel__step { border-bottom: 1px solid var(--line); }
  }
  @container workspace-main (max-width: 22rem) {
    .funnel { grid-template-columns: minmax(0,1fr); }
  }
  .chart canvas { max-width: 100%; width: 100%; }
  .health__item { min-width: 0; flex-wrap: wrap; overflow-wrap: anywhere; }

  .dash-status { font-size: .8125rem; color: var(--ink-3); margin-block: -.25rem 1rem; min-height: 1.3em; }
  #dash-archive-banner { margin-bottom: 1rem; flex-wrap: wrap; }
  .section-hint { margin-bottom: 1rem; }
  .snapshot-list, .directory-list { display: grid; gap: .75rem; }
  .snapshot-card { border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; min-width: 0; }
  .snapshot-card.is-selected { border-color: var(--brand); }
  .snapshot-card__open { display: grid; gap: .625rem; width: 100%; text-align: start; padding: .875rem; transition: background .15s ease; overflow-wrap: anywhere; }
  .snapshot-card__open:hover { background: var(--surface-2); }
  .snapshot-card__time { font-size: .875rem; font-weight: 700; }
  .snapshot-card__time small { font-weight: 500; color: var(--ink-3); }
  .snapshot-card__stats { display: flex; flex-wrap: wrap; gap: .5rem 1rem; font-size: .75rem; color: var(--ink-2); }
  .snapshot-card__stats b { display: block; color: var(--ink); font-size: .9375rem; }
  .snapshot-card__open .badge { justify-self: start; }
  .snapshot-card__compare { margin: 0 .875rem .875rem; max-width: calc(100% - 1.75rem); white-space: normal; text-align: start; }
  .comparison { margin-bottom: 1.25rem; scroll-margin-top: 4.5rem; }
  .comparison .card__head { flex-wrap: wrap; gap: .75rem; }
  .comparison .card__body { display: grid; gap: .875rem; }
  .compare-controls { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,13rem),1fr)); gap: .75rem; }
  .compare-controls .select { min-width: 0; width: 100%; }
  .compare-table { min-width: 43rem; font-variant-numeric: tabular-nums; }
  .compare-table th[scope="row"] { text-align: start; font-size: .8125rem; white-space: normal; min-width: 12rem; }
  .delta { font-weight: 700; }
  /* Направление != оценка: рост ошибок не окрашивается «успешным» зелёным. */
  .delta--up { color: var(--info); }
  .delta--down { color: var(--warn); }
  .sort-button { display: inline-flex; align-items: center; gap: .5rem; text-align: inherit; font: inherit; min-height: 2.75rem; }
  .sort-button span { color: var(--ink-3); }
  th[aria-sort="ascending"] .sort-button, th[aria-sort="descending"] .sort-button { color: var(--brand); }
  .activity-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
  .activity-head .select { width: auto; max-width: 100%; }
  #user-activity-body { display: grid; gap: .75rem; min-width: 0; }
  .activity-summary { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,5rem),1fr)); border: 1px solid var(--line); border-radius: var(--radius-s); }
  .activity-summary > div { padding: .625rem; display: grid; gap: .125rem; font-size: .75rem; color: var(--ink-2); }
  .activity-summary b { font-size: 1.125rem; color: var(--ink); }
  .activity-list { border: 1px solid var(--line); border-radius: var(--radius-s); }
  .activity-event { display: flex; flex-wrap: wrap; align-items: baseline; gap: .375rem .75rem; padding: .75rem; border-bottom: 1px solid var(--line); font-size: .8125rem; }
  .activity-event:last-child { border-bottom: 0; }
  .activity-event > div { flex: 1 1 13rem; min-width: 0; overflow-wrap: anywhere; }
  .activity-event__meta { display: block; color: var(--ink-3); font-size: .75rem; }
  .activity-event time { font-size: .75rem; color: var(--ink-3); }
  .directory-card { padding: .75rem; border: 1px solid var(--line-2); border-radius: var(--radius-s); min-width: 0; overflow-wrap: anywhere; }
  .directory-card__name { font-weight: 700; margin-bottom: .25rem; }
  .directory-card__bottom { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; margin-top: .5rem; font-size: .8125rem; }
  .side-pager { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; justify-content: space-between; }
  .user-picker { position: relative; display: grid; gap: .375rem; min-width: 0; }
  .user-picker__menu { position: absolute; inset-inline: 0; top: calc(100% + .25rem); z-index: 20; padding: .375rem; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-2); animation: picker-in .15s ease; }
  .user-picker__options { max-height: min(18rem,40svh); overflow-y: auto; overscroll-behavior: contain; }
  .user-picker__option { padding: .625rem; min-height: 2.75rem; display: grid; gap: .25rem; cursor: pointer; border-radius: var(--radius-s); font-size: .875rem; overflow-wrap: anywhere; }
  .user-picker__option span { font-size: .75rem; color: var(--ink-2); }
  .user-picker__option:hover, .user-picker__option.is-active { background: var(--surface-2); outline: 1px solid var(--line-2); outline-offset: -1px; }
  .user-picker__status { color: var(--ink-3); padding: .5rem; }
  .user-picker__more { margin: .25rem; }
  @keyframes picker-in { from { opacity: 0; transform: translateY(-.25rem); } to { opacity: 1; transform: none; } }
  .who__name, .who__sub, .user-data { overflow-wrap: anywhere; }
  .chart-error { color: var(--warn); }
  #reauth-error { color: var(--err); min-height: 1.5em; }
  .side-panel .btn, .comparison .btn, .side-pager .btn, .user-picker .btn { min-height: 2.75rem; }
  .btn:active:not(:disabled) { transform: translateY(1px); }
  .btn:disabled { cursor: not-allowed; }
  @media (max-width: 45rem) {
    .input, .textarea, .select, .user-picker__input { font-size: 1rem; }
    .page__actions > .btn { min-height: 2.75rem; white-space: normal; }
    .page__actions > .select { flex: 1 1 10rem; }
    .page__actions .search { min-width: 0; }
    .btn--icon { min-width: 2.75rem; min-height: 2.75rem; }
    .modal__foot { flex-wrap: wrap; }
    .uc-row { grid-template-columns: minmax(0,1fr) auto; }
    .uc-row > :last-child { white-space: normal; }
  }
}
@layer utilities {
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; }
  }
}

@layer components {
  /* Длинные аккаунты и крупный пользовательский шрифт не расширяют карточки. */
  .card__head { flex-wrap: wrap; }
  .card__head > *, .drawer .modal__body > *, .uc-head > *, .uc-head__sub > * { min-width: 0; }
  .card__head h2, .card__head h3, .card__head .small { overflow-wrap: anywhere; }
  .comparison .btn, #dash-archive-banner .btn { max-width: 100%; white-space: normal; }
  .sources { grid-template-columns: repeat(auto-fill,minmax(min(100%,9.5rem),1fr)); }
  .source, .source__name { min-width: 0; overflow-wrap: anywhere; }
  .uc-head__name, .uc-head__sub, .uc-stat { overflow-wrap: anywhere; }
  .uc-grid { grid-template-columns: repeat(auto-fit,minmax(min(100%,7.5rem),1fr)); }
  .avatar { color: #1C1B22; }
}
