/* ==========================================================================
   Lead Analytics — фирменная тема «Столица списания»
   Один файл, чистый CSS, без сборщиков и внешних CDN.
   Дизайн-система и роли токенов: docs/agents/design/BRAND.md
   ========================================================================== */

/* --- Шрифт Montserrat локально (переменный, кириллица + латиница) --------- */
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/montserrat-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/montserrat-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* --- Токены ---------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* Бренд */
  --brand-900: #012a2e;
  --brand-700: #0a4c52;
  --brand-100: #d7e3e4;
  --gold-700: #9a5203;
  --gold-600: #b56104;
  --gold-500: #d17a04;
  --gold-300: #ffc977;
  --gold-100: #fdefd8;

  /* Поверхности */
  --bg-page: #f0f5fa;
  --bg-surface: #ffffff;
  --bg-surface-2: #f7fafc;
  --bg-dark: var(--brand-900);

  /* Текст */
  --text: #1e293b;
  --text-2: #334155;
  --text-muted: #5b6b7a;
  --text-on-dark: #ffffff;
  --text-on-dark-2: #b9cbcb;

  /* Границы */
  --border: #dce3ea;
  --border-strong: #adb6be;

  /* Статусы */
  --accent: var(--gold-500);
  --accent-hover: var(--gold-700);
  --success: #1e7a3d;
  --success-bg: #e6f4ea;
  --danger: #af2228;
  --danger-hover: #8e1b20;
  --danger-bg: #fbeaea;
  --rejected: #8c4a3c;
  --rejected-bg: #f6eae6;
  --warning: var(--gold-700);
  --warning-bg: var(--gold-100);
  --info: var(--brand-700);
  --info-bg: #e7f0f1;
  --focus: var(--gold-500);

  /* Отступы */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  /* Радиусы */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  /* Тени */
  --shadow-sm: 0 1px 2px rgba(1, 42, 46, 0.06);
  --shadow-md: 0 8px 24px rgba(1, 42, 46, 0.08);
  --shadow-lg: 0 18px 40px rgba(1, 42, 46, 0.12);

  /* Прочее */
  --t-fast: 120ms ease;
  --t-base: 180ms ease;
  --container: 1200px;
  --header-h: 64px;
  --field-h: 44px;
  --font: 'Montserrat', 'Segoe UI', 'PT Sans', system-ui, -apple-system, Arial, sans-serif;
  --mono: 'SFMono-Regular', 'Cascadia Mono', 'Roboto Mono', Consolas, monospace;
}

/* --- Сброс и база ---------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 460px at 88% -12%, rgba(209, 122, 4, 0.10), transparent 60%),
    radial-gradient(900px 420px at -10% 0%, rgba(1, 42, 46, 0.06), transparent 55%),
    var(--bg-page);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; height: auto; }

a { color: var(--brand-700); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

h1, h2, h3 { margin: 0; color: var(--text); letter-spacing: -0.01em; }
h1 { font-size: 30px; font-weight: 700; line-height: 1.2; }
h2 { font-size: 20px; font-weight: 600; line-height: 1.3; }
p { margin: 0 0 var(--sp-4); }
p:last-child { margin-bottom: 0; }

/* Видимый фокус для клавиатуры */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* --- Служебные утилиты ----------------------------------------------------- */
.container {
  width: min(var(--container), calc(100% - var(--sp-7)));
  margin-inline: auto;
}

.page {
  width: min(var(--container), calc(100% - var(--sp-7)));
  margin-inline: auto;
  padding: var(--sp-7) 0 var(--sp-7);
}

.stack > * + * { margin-top: var(--sp-5); }
.stack-sm > * + * { margin-top: var(--sp-3); }
.stack > .page-header { margin-bottom: 0; }
.text-muted { color: var(--text-muted); }
.text-rejected,
.bad { color: var(--rejected); font-weight: 600; }
.error { color: var(--danger); }
.empty { color: var(--text-muted); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-5) 0; }

.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }

.eyebrow {
  margin: 0 0 var(--sp-2);
  color: var(--accent-hover);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hint { color: var(--text-muted); font-size: 13px; }

/* --- Шапка ----------------------------------------------------------------- */
.appbar {
  background: var(--bg-dark);
  color: var(--text-on-dark);
  box-shadow: var(--shadow-sm);
}
.appbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: var(--header-h);
}
.brand { display: inline-flex; align-items: center; gap: var(--sp-3); }
.brand__logo { height: 28px; width: auto; display: block; }
.brand__title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-on-dark-2);
}
.appbar__actions { display: flex; align-items: center; gap: var(--sp-3); }
.appbar__actions form { margin: 0; display: inline-flex; }
.appbar__user { color: var(--text-on-dark-2); font-size: 13px; }

/* Светлая шапка — экраны входа (цветное лого на светлом фоне) */
.appbar--light {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.appbar--light .brand__title { color: var(--text-muted); }

/* --- Заголовок страницы ---------------------------------------------------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-5);
  margin-bottom: var(--sp-5);
}
.page-header__subtitle {
  margin: var(--sp-2) 0 0;
  color: var(--text-muted);
}
.page-header__actions { flex: 0 0 auto; }

/* --- Карточка -------------------------------------------------------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: var(--sp-5);
}
.card--narrow { max-width: 560px; margin-inline: auto; }
.card__header { margin-bottom: var(--sp-4); }
.card__title { font-size: 20px; font-weight: 600; }
.card__hint { margin-top: var(--sp-1); color: var(--text-muted); font-size: 13px; }
.card__footer {
  margin: var(--sp-5) calc(-1 * var(--sp-5)) calc(-1 * var(--sp-5));
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg-surface-2);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* --- Кнопки ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--field-h);
  padding: var(--sp-3) var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--bg-surface-2);
  color: var(--text);
  font: 600 14px/1.1 var(--font);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--t-fast), border-color var(--t-fast),
    color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled,
.btn[aria-disabled='true'],
.btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn--primary { background: var(--brand-900); color: #fff; }
.btn--primary:hover { background: var(--brand-700); color: #fff; }

.btn--accent { background: var(--accent); color: var(--brand-900); }
.btn--accent:hover { background: var(--accent-hover); color: #fff; }

.btn--secondary {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  color: var(--brand-700);
}
.btn--secondary:hover { border-color: var(--brand-700); background: var(--info-bg); color: var(--brand-700); }
.btn--secondary.logout { background: var(--bg-surface); }

.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: var(--danger-hover); color: #fff; }

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--brand-700);
  padding-inline: var(--sp-2);
}
.btn--ghost:hover { background: var(--info-bg); color: var(--brand-700); }

/* «Выйти» в тёмной шапке */
.btn--ghost-light {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.35);
  color: var(--text-on-dark);
  min-height: 38px;
  padding: var(--sp-2) var(--sp-4);
}
.btn--ghost-light:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

.btn--sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn--block { width: 100%; }

/* --- Формы ----------------------------------------------------------------- */
.form { display: grid; gap: var(--sp-4); }
.form__actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-1); }

.field { display: grid; gap: var(--sp-2); }
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.field input,
.field select {
  width: 100%;
  min-height: var(--field-h);
  padding: 0 var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font: 400 16px/1.4 var(--font);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field select { padding-right: var(--sp-5); }
.field input::placeholder { color: var(--text-muted); }
.field input:hover,
.field select:hover { border-color: var(--brand-700); }
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(209, 122, 4, 0.25);
}
.field__error { color: var(--danger); font-size: 13px; }
.field--error input,
.field--error select { border-color: var(--danger); }

/* --- Уведомления ----------------------------------------------------------- */
.alert {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--r-md);
  font-size: 14px;
  background: var(--bg-surface-2);
  color: var(--text-2);
}
.alert p { margin: 0; }
.alert__title { font-weight: 600; }
.alert--error { background: var(--danger-bg); border-color: var(--danger); }
.alert--error .alert__title { color: var(--danger); }
.alert--warning { background: var(--warning-bg); border-color: var(--warning); }
.alert--warning .alert__title { color: var(--warning); }
.alert--success { background: var(--success-bg); border-color: var(--success); }
.alert--success .alert__title { color: var(--success); }
.alert--info { background: var(--info-bg); border-color: var(--info); }
.alert--info .alert__title { color: var(--info); }

/* --- Бейджи ---------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-3);
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg-surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.badge--active { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge--off { background: var(--bg-surface-2); color: var(--text-muted); border-color: var(--border); }
.badge--rejected { background: var(--rejected-bg); color: var(--rejected); border-color: transparent; }
.badge--token,
.badge--pin { background: var(--gold-100); color: var(--accent-hover); border-color: transparent; }

/* --- Таблицы --------------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--r-md);
  -webkit-overflow-scrolling: touch;
}
.data-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table--clients { min-width: 760px; }
.data-table th,
.data-table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.data-table thead th {
  background: var(--bg-surface-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--bg-surface-2); }
.data-table .cell-num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-table .empty { text-align: center; color: var(--text-muted); padding: var(--sp-6); }

.table-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.table-actions form { margin: 0; display: inline-flex; }

.scroll-hint { display: none; margin-top: var(--sp-2); color: var(--text-muted); font-size: 12px; }

/* --- Пагинация таблиц (B-061) ---------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-top: var(--sp-4);
}
.pagination__caption { color: var(--text-muted); font-size: 13px; }
.pagination__pages { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-1); }
.pagination__link,
.pagination__current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  color: var(--text-2);
  font-size: 14px;
  text-decoration: none;
}
.pagination__link:hover { background: var(--bg-surface-2); }
.pagination__link--disabled { opacity: 0.5; pointer-events: none; }
.pagination__current { background: var(--brand-900); border-color: var(--brand-900); color: #fff; font-weight: 600; }
.pagination__ellipsis { padding: 0 var(--sp-1); color: var(--text-muted); }

/* --- Воронка (плитки стадий) ----------------------------------------------- */
.stage-flow {
  display: flex;
  align-items: stretch;
  gap: var(--sp-2);
  overflow-x: auto;
  padding: var(--sp-1) var(--sp-1) var(--sp-3);
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.stage-tile {
  flex: 1 1 112px;
  min-width: 112px;
  scroll-snap-align: start;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-4) var(--sp-3);
  text-align: center;
}
.stage-tile__value { display: block; font-size: 28px; font-weight: 700; line-height: 1; color: var(--brand-900); }
.stage-tile__label { display: block; margin-top: var(--sp-2); font-size: 12px; line-height: 1.3; color: var(--text-muted); }
.stage-arrow { align-self: center; color: var(--border-strong); font-weight: 700; font-size: 20px; flex: 0 0 auto; }
.stage-tile--rejected { border-color: var(--rejected); }
.stage-tile--rejected .stage-tile__value { color: var(--rejected); }
.stage-tile--rejected .stage-tile__label { color: var(--rejected); }
.stage-tile--success { border-color: var(--success); }
.stage-tile--success .stage-tile__value { color: var(--success); }
.stage-tile--success .stage-tile__label { color: var(--success); }

/* --- Одноразовый секрет ---------------------------------------------------- */
.secret-box {
  padding: var(--sp-4);
  border: 1px solid var(--gold-300);
  border-radius: var(--r-md);
  background: var(--gold-100);
}
.secret-box + .secret-box { margin-top: var(--sp-3); }
.secret-box__label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-hover);
}
.secret-box__value {
  display: block;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--brand-900);
  word-break: break-all;
  user-select: all;
}
/* Значение + компактная кнопка «Копировать» (B-056). */
.secret-box__row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.secret-box__row .secret-box__value {
  flex: 1 1 auto;
  min-width: 0;
}
.secret-box__link {
  color: var(--brand-700);
  text-decoration: underline;
  /* Как и у прочих значений: один клик выделяет всю ссылку целиком. */
  user-select: all;
}
.secret-box__link:hover { color: var(--accent-hover); }
.secret-box__copy { flex: 0 0 auto; }
.secret-box__hint { margin: var(--sp-2) 0 0; }
.secret-box__hint[hidden] { display: none; }

/* --- Пустое состояние ------------------------------------------------------ */
.empty-state {
  padding: var(--sp-7) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
}
.empty-state__title { margin: 0 0 var(--sp-2); font-size: 17px; font-weight: 600; color: var(--text); }
.empty-state__text { margin: 0 auto; max-width: 44ch; }
.empty-state__actions { margin-top: var(--sp-4); display: flex; justify-content: center; gap: var(--sp-3); }

/* --- Экран входа ----------------------------------------------------------- */
.auth {
  min-height: calc(100vh - var(--header-h));
  display: grid;
  place-items: center;
  padding: var(--sp-6) var(--sp-4);
}
.auth .card { width: 100%; }
.auth__title { margin-top: var(--sp-1); }

/* --- Загрузка -------------------------------------------------------------- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--bg-surface-2) 25%, var(--border) 37%, var(--bg-surface-2) 63%);
  background-size: 400% 100%;
  border-radius: var(--r-sm);
  animation: skeleton 1.4s ease infinite;
  color: transparent;
}
@keyframes skeleton { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* --- Адаптив --------------------------------------------------------------- */
@media (max-width: 900px) {
  :root { --container: 100%; }
  .page { padding: var(--sp-5) 0 var(--sp-6); }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header__actions { width: 100%; }
}

@media (max-width: 640px) {
  :root { --header-h: 56px; }
  body { font-size: 14px; }
  h1 { font-size: 24px; }
  h2 { font-size: 18px; }
  .page { width: calc(100% - var(--sp-4)); padding-top: var(--sp-4); }
  /* Шапка должна стоять по тем же полям, что и карточки (B-049). */
  .container { width: calc(100% - var(--sp-4)); }
  .card { padding: var(--sp-4); border-radius: var(--r-md); }
  .card__footer { margin: var(--sp-4) calc(-1 * var(--sp-4)) calc(-1 * var(--sp-4)); padding: var(--sp-3) var(--sp-4); }
  .brand__logo { height: 24px; }
  .brand__title { display: none; }
  .appbar__user { display: none; }
  .form__actions .btn { width: 100%; }
  .btn { min-height: var(--field-h); }
  .stage-tile { flex: 0 0 128px; min-width: 128px; padding: var(--sp-3) var(--sp-2); }
  .stage-tile__value { font-size: 24px; }
  .stage-arrow { font-size: 16px; }
  .scroll-hint { display: block; }
  .auth { padding: var(--sp-4) var(--sp-3); }
}

@media (max-width: 380px) {
  .page { width: calc(100% - var(--sp-3)); }
  .container { width: calc(100% - var(--sp-3)); }
  .card { padding: var(--sp-3); }
  .btn { padding-inline: var(--sp-4); }
  .table-actions .btn--sm { width: 100%; }
  .table-actions { flex-direction: column; }
}

@media (min-width: 1280px) {
  .stage-tile { flex: 1 1 120px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Панель фильтров кабинета (B-063 период, B-064 стадии)
   Макет: docs/agents/design/M-002-filters.md
   ========================================================================== */
[hidden] { display: none !important; }

/* Обёртка результатов: одним ответом HTMX обновляются и плитки, и таблица. */
.results { transition: opacity var(--t-fast); }
.results > * + * { margin-top: var(--sp-5); }

/* --- Строка фильтров ------------------------------------------------------- */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.filter-bar__group {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.filter-bar__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

/* --- Выпадающий фильтр (details) ------------------------------------------ */
.filter { position: relative; }
.filter__summary {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--field-h);
  padding: var(--sp-2) var(--sp-4);
  list-style: none;
  cursor: pointer;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast), background-color var(--t-fast), box-shadow var(--t-fast);
}
.filter__summary::-webkit-details-marker { display: none; }
.filter__summary:hover { border-color: var(--brand-700); background: var(--bg-surface-2); }
.filter__summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.filter[open] > .filter__summary {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(209, 122, 4, 0.18);
}
.filter--active > .filter__summary { border-color: var(--accent); }
.filter__summary-label { font-size: 13px; color: var(--text-muted); }
.filter__summary-value { font-size: 14px; font-weight: 600; color: var(--text); }
.filter__summary-range { font-size: 13px; color: var(--text-muted); }
.filter__chevron {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-left: var(--sp-1);
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--t-fast);
}
.filter[open] .filter__chevron { transform: rotate(-135deg); }

/* --- Раскрытая панель ------------------------------------------------------ */
.filter__panel {
  position: absolute;
  top: calc(100% + var(--sp-2));
  left: 0;
  z-index: 30;
  width: min(440px, calc(100vw - var(--sp-5)));
  max-height: min(70vh, 560px);
  overflow: auto;
  padding: var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  -webkit-overflow-scrolling: touch;
}
.filter__panel-head { margin-bottom: var(--sp-3); }
.filter__panel-title { margin: 0; font-size: 17px; font-weight: 600; color: var(--text); }
.filter__panel-body { display: grid; gap: var(--sp-4); }
.filter__panel-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}
.filter__hint { margin: 0; color: var(--text-muted); font-size: 13px; }

/* --- Списки выбора --------------------------------------------------------- */
.filter__options,
.filter__stages,
.filter__group {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.filter__options { display: grid; gap: var(--sp-1); }
.filter__stages { display: grid; gap: var(--sp-3); }
.filter__group { display: grid; gap: var(--sp-1); }

.filter__option,
.filter__check,
.filter__all {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--field-h);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
}
.filter__option:hover,
.filter__check:hover,
.filter__all:hover { background: var(--bg-surface-2); }
.filter__option input,
.filter__check input,
.filter__all input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}
.filter__option input:checked + span,
.filter__check input:checked + span { color: var(--text); font-weight: 600; }
.filter__all {
  margin-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  font-weight: 600;
  color: var(--text);
}
.filter__group-title {
  padding: 0 var(--sp-3);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.filter__group--rejected .filter__group-title { color: var(--rejected); }
.filter__group--rejected .filter__check input:checked + span { color: var(--rejected); }

/* --- Произвольный период --------------------------------------------------- */
.filter__custom { display: none; }
.filter__custom.is-open { display: grid; gap: var(--sp-2); }
.filter__dates { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.filter__dates .field { gap: var(--sp-1); }
.filter__dates .field label { font-size: 12px; }

/* --- Сброс и состояние загрузки -------------------------------------------- */
.filter__reset {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: var(--sp-2) var(--sp-3);
  color: var(--brand-700);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.filter__reset:hover { color: var(--accent-hover); text-decoration: underline; }

.filter-progress {
  display: none;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-muted);
  font-size: 13px;
}
.filter-progress.htmx-request { display: inline-flex; }

/* Во время запроса результаты приглушены и не принимают клики. */
.filter-bar.htmx-request ~ .results { opacity: 0.6; pointer-events: none; }

/* --- Адаптив панели фильтров ----------------------------------------------- */
@media (min-width: 1000px) {
  .filter__summary-range {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 768px) {
  .filter-bar { position: static; }
  .filter-bar__group { width: 100%; }
  .filter { flex: 1 1 auto; }
}

@media (max-width: 640px) {
  .filter-bar { padding: var(--sp-3); border-radius: var(--r-md); }
  .filter { width: 100%; }
  .filter__summary { width: 100%; justify-content: space-between; }
  /* Раскрытая панель — шторка снизу на всю ширину. */
  .filter__panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    max-height: 85vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: var(--sp-4) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px));
  }
  .filter__panel-foot {
    position: sticky;
    bottom: calc(-1 * var(--sp-4));
    margin: var(--sp-4) calc(-1 * var(--sp-4)) calc(-1 * var(--sp-4) - env(safe-area-inset-bottom, 0px));
    padding: var(--sp-3) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px));
    background: var(--bg-surface);
  }
  .filter__panel-foot .btn { width: 100%; }
  .filter__dates { grid-template-columns: 1fr; }
  .filter-bar__actions { width: 100%; justify-content: space-between; }
  /* Диапазон дат в триггере скрываем, чтобы не ломать строку на узком экране. */
  .filter__summary-range { display: none; }
}
