/* Оформление Mini App.

   Все цвета — из themeParams Telegram, разложенные в CSS-переменные на :root
   (см. applyTheme в app.js). Фолбэки в var(...) нужны только на случай запуска
   вне Telegram; внутри клиента их всегда перекрывает реальная тема, поэтому
   отдельной «тёмной темы» здесь нет — тему целиком диктует клиент. */

:root {
  --tg-bg: #ffffff;
  --tg-text: #000000;
  --tg-hint: #707579;
  --tg-link: #2481cc;
  --tg-button: #2481cc;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f4f4f5;
  --tg-header-bg: #ffffff;
  --tg-section-bg: #ffffff;
  --tg-section-separator: rgba(128, 128, 128, 0.22);

  --good: #16a34a;   /* мы дешевле */
  --bad:  #dc2626;   /* мы дороже */

  --radius: 12px;
  --radius-lg: 16px;
  --gap: 12px;

  /* Кривые из emil-design-eng: штатные ease-in/ease-out CSS слишком слабые,
     ощущаются вязкими на коротких UI-анимациях. */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  /* Тень строим из --tg-text, а не из чёрного: на тёмной теме text светлый,
     color-mix даёт мягкое свечение вместо непрозрачной чёрной кляксы поверх
     и без того тёмного фона — единственный способ теням работать на обеих
     темах без отдельной тёмной ветки. */
  --shadow-sm: 0 1px 2px color-mix(in srgb, var(--tg-text) 7%, transparent);
  --shadow-md:
    0 1px 2px color-mix(in srgb, var(--tg-text) 6%, transparent),
    0 6px 16px color-mix(in srgb, var(--tg-text) 9%, transparent);
  --shadow-lg:
    0 4px 10px color-mix(in srgb, var(--tg-text) 8%, transparent),
    0 16px 40px color-mix(in srgb, var(--tg-text) 14%, transparent);

  /* Тонкая яркая кромка сверху карточек — «стекло ловит свет», как в
     apple-design (см. §12): едва заметно, но добавляет объём плоским плашкам. */
  --edge-top: inset 0 1px 0 color-mix(in srgb, var(--tg-text) 6%, transparent);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--tg-bg);
  color: var(--tg-text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Приглушённый текст берём из темы Telegram, но не опускаем ниже AA:
   штатные hint_color и в светлой, и в тёмной палитре дают ~4.2:1 на мелком
   кегле — этого не хватает. Подмешиваем основной цвет текста, поэтому оттенок
   остаётся «тише» окружения, но читается. */
.muted { color: color-mix(in srgb, var(--tg-hint) 62%, var(--tg-text)); }
.small { font-size: 13px; }
.good  { color: var(--good); }
.bad   { color: var(--bad); }
.num   { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- состояния во весь экран ---------- */

/* Атрибут hidden обязан побеждать display у любого блока ниже: без этого
   .center-state { display:flex } перекрывает hidden и заставка остаётся висеть
   поверх уже загруженного приложения. */
[hidden] { display: none !important; }

.center-state {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 24px;
  text-align: center;
}
.center-state h1 { font-size: 20px; margin: 0; }
.center-state p  { margin: 0; max-width: 34ch; }
.big-icon { font-size: 44px; line-height: 1; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--tg-section-separator);
  border-top-color: var(--tg-button);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

/* ---------- вкладки ---------- */

.tabs {
  display: flex;
  /* ≥12px — см. комментарий у .dialog-actions: на pointer:coarse .tab
     расширяет зону нажатия на 6px в каждую сторону, иначе соседние вкладки
     делят перекрывающуюся зону нажатия. */
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  overflow-x: auto;
  background: var(--tg-bg);
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 1px 0 var(--tg-section-separator);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  flex: 0 0 auto;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;          /* «пилюли» — как в остальной навигации */
  background: transparent;
  color: color-mix(in srgb, var(--tg-hint) 45%, var(--tg-text));
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.16s var(--ease-out), background-color 0.16s var(--ease-out),
              transform 0.12s var(--ease-out);
}
.tab[aria-selected="true"] {
  background: var(--tg-button);
  color: color-mix(in srgb, var(--tg-button-text) 88%, var(--tg-button-contrast, #000));
  box-shadow: var(--shadow-sm);
}

/* ---------- содержимое экрана ---------- */

#screen { padding: 12px; }

.screen-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;   /* заголовки крупнее — тянем чуть плотнее (apple-design §15) */
  margin: 4px 0 12px;
}
.screen-sub { margin: -8px 0 12px; }

/* плитки со сводкой */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 8px;
  margin-bottom: var(--gap);
}
.stat {
  position: relative;
  overflow: hidden;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 12px 8px 11px;
  text-align: center;
  box-shadow: var(--shadow-sm), var(--edge-top);
  /* Каждая плитка входит по очереди — см. .stats > * ниже. */
  animation: stat-in 0.36s var(--ease-out) backwards;
}
.stats > *:nth-child(1) { animation-delay: 0ms; }
.stats > *:nth-child(2) { animation-delay: 35ms; }
.stats > *:nth-child(3) { animation-delay: 70ms; }
.stats > *:nth-child(4) { animation-delay: 105ms; }
.stats > *:nth-child(5) { animation-delay: 140ms; }
/* Второй ряд («мы дороже»/«мы дешевле») — ровно 2 колонки на всю ширину,
   не через auto-fit(88px): на 390px он давал бы 4+1 вместо 3+2. Отдельный
   блок ближе к первому ряду, чем к следующему за ним контенту. */
.stats-compare {
  grid-template-columns: repeat(2, 1fr);
  margin-top: -4px;
}
.stats-compare > *:nth-child(1) { animation-delay: 105ms; }
.stats-compare > *:nth-child(2) { animation-delay: 140ms; }
@keyframes stat-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
}
/* Цветная кромка сверху — тот же good/bad, что и у числа, но приглушённый:
   плитка читается по смыслу ещё до того, как взгляд дошёл до цифры. */
.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: color-mix(in srgb, var(--tg-hint) 35%, transparent);
}
.stat:has(.stat-num.good)::before { background: var(--good); }
.stat:has(.stat-num.bad)::before { background: var(--bad); }
.stat-num { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 11px; color: color-mix(in srgb, var(--tg-hint) 62%, var(--tg-text)); margin-top: 3px; }
@media (prefers-reduced-motion: reduce) {
  .stat { animation: none; }
}

/* фильтры */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: var(--gap);
}
.filters input, .filters select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--tg-section-separator);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font: inherit;
  font-size: 16px;   /* < 16px заставляет iOS зумить при фокусе */
}
.filters select { flex: 0 1 40%; }

/* таблица */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm), var(--edge-top);
}
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--tg-section-separator);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
/* Зебра едва заметна (3%) — не полосатый вид 90-х, а лёгкая опора для глаза
   на широких таблицах цен, где взгляд идёт по строке через 5-6 колонок. */
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--tg-text) 3%, transparent); }
thead th {
  position: sticky;
  top: 0;
  background: var(--tg-secondary-bg);
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--tg-hint) 55%, var(--tg-text));
  font-weight: 700;
  user-select: none;
  box-shadow: 0 1px 0 var(--tg-section-separator);
}
th.sortable-col { cursor: pointer; transition: color 0.12s var(--ease-out); }
th.sortable-col:active { color: var(--tg-text); }
th[aria-sort]::after { color: var(--tg-link); font-weight: 700; }
th[aria-sort="ascending"]::after  { content: " ↑"; }
th[aria-sort="descending"]::after { content: " ↓"; }

tbody tr[data-clickable] { cursor: pointer; transition: background-color 0.12s var(--ease-out); }
tbody tr[data-clickable]:active td { background: var(--tg-section-separator); }
@media (hover: hover) and (pointer: fine) {
  tbody tr[data-clickable]:hover td { background: color-mix(in srgb, var(--tg-text) 5%, transparent); }
}

.cell-name {
  white-space: normal;
  min-width: 160px;
  max-width: 260px;
}

.vbadge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--tg-bg);
  border: 1px solid color-mix(in srgb, var(--tg-hint) 30%, var(--tg-section-separator));
  font-size: 11px;
  font-weight: 500;
}

/* карточки */
.card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: var(--gap);
  box-shadow: var(--shadow-sm), var(--edge-top);
}
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }

.price-row {
  display: flex;
  justify-content: space-around;
  text-align: center;
  gap: 8px;
}
.price-big { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--tg-button);
  /* button_text_color из темы Telegram даёт на штатном button_color около
     4.1:1 — ниже AA для нашего кегля. Подмешиваем к нему немного контрастного
     тона (--tg-button-contrast выставляет applyTheme по яркости кнопки),
     сохраняя задуманный темой цвет, но дотягивая читаемость. */
  color: color-mix(in srgb, var(--tg-button-text) 88%, var(--tg-button-contrast, #000));
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

/* Нажатие — одно и то же на всех кликабельных поверхностях: лёгкое сжатие
   вместо мгновенного скачка прозрачности, чтобы кнопка ощущалась отзывчивой.
   Кривая из emil-design-eng: штатный ease на 0.12s ощущается вязким, у
   ease-out разгон мгновенный — ровно то, что нужно для 100-160ms фидбека
   нажатия (см. таблицу длительностей в скилле). */
.btn, .tab, .hub-item, .list-item:not(.static), tbody tr[data-clickable] {
  transition: transform 0.12s var(--ease-out), opacity 0.12s var(--ease-out),
              background-color 0.12s var(--ease-out), box-shadow 0.12s var(--ease-out);
}
.btn:active, .tab:active, .hub-item:active, .list-item:not(.static):active {
  transform: scale(0.96);
}
@media (prefers-reduced-motion: reduce) {
  .btn, .tab, .hub-item, .list-item:not(.static), tbody tr[data-clickable] {
    transition-duration: 0.01ms;
  }
  .btn:active, .tab:active, .hub-item:active, .list-item:not(.static):active {
    transform: none;
  }
}
/* Раньше фон совпадал с .card (--tg-secondary-bg) и тонкая рамка почти не
   видна поверх такого же фона — на карточке «Чистки» кнопки «Очистить» /
   «Показать и удалить» читались как обычный текст, не как кнопки. Берём
   --tg-bg (обычно контрастирует с --tg-secondary-bg) и рамку потемнее, плюс
   тень — чтобы поверхность отделялась от карточки на глаз, а не по описанию. */
.btn-neutral {
  background: var(--tg-bg);
  color: var(--tg-text);
  border: 1px solid color-mix(in srgb, var(--tg-hint) 40%, var(--tg-section-separator));
  box-shadow: var(--shadow-sm);
}
.btn-neutral:active { background: var(--tg-secondary-bg); }
.btn-danger { background: var(--bad); color: #fff; }

/* увеличиваем зону нажатия, не раздувая саму кнопку */
@media (pointer: coarse) {
  .btn, .tab { position: relative; }
  .btn::after, .tab::after {
    content: "";
    position: absolute;
    inset: -6px;
  }
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--tg-hint);
}

details { margin-top: var(--gap); }
details summary {
  cursor: pointer;
  padding: 10px 12px;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  font-weight: 500;
}
details[open] summary { border-radius: var(--radius) var(--radius) 0 0; }

.chart-box { position: relative; height: 240px; }

.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }

.trend {
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

/* ================= админские экраны ================= */

/* корневое меню управления */
.hub { display: flex; flex-direction: column; gap: 8px; }
.hub-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm), var(--edge-top);
}
.hub-item:active { transform: scale(0.98); background: color-mix(in srgb, var(--tg-text) 4%, var(--tg-secondary-bg)); }
.hub-icon {
  font-size: 20px;
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 11px;
  background: color-mix(in srgb, var(--tg-button) 12%, var(--tg-bg));
}
.hub-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.hub-title { font-weight: 600; }
.hub-chevron { font-size: 20px; }

/* списки */
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.list-item.static { box-shadow: none; cursor: default; }
.list-item:not(.static):active { transform: scale(0.98); background: color-mix(in srgb, var(--tg-text) 4%, var(--tg-secondary-bg)); }
/* Строка доступов несёт две кнопки в .row-actions разом («Сделать
   наблюдателем» + «Отозвать») — рядом с именем на узком экране это сжимало
   .list-main до переноса в 2-3 строки посреди имени. Переносим сами кнопки
   под имя, а не сжимаем его: .list-item становится колонкой, только когда
   внутри есть многокнопочный .row-actions, — обычные списки-переходы (с
   одной стрелкой) эту раскладку не трогают. */
.list-item:has(.row-actions) {
  flex-wrap: wrap;
  align-items: flex-start;
}
.list-item:has(.row-actions) .row-actions {
  flex: 1 0 100%;
  justify-content: flex-start;
}
.list-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.list-title { font-weight: 500; overflow-wrap: anywhere; }
.badge-count {
  flex: 0 0 auto;
  min-width: 28px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--tg-bg);
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
/* gap ≥ 12px: у .btn на pointer:coarse зона нажатия расширена на 6px в
   каждую сторону (см. правило ниже) — при меньшем зазоре расширенные зоны
   соседних кнопок перекрываются, и по центру непонятно, какая сработает. */
.row-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

.section-head { font-size: 15px; margin: 18px 0 8px; }

/* формы */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field input, .field select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--tg-section-separator);
  background: var(--tg-bg);
  color: var(--tg-text);
  font: inherit;
  font-size: 16px;      /* иначе iOS зумит поле при фокусе */
}
.field input.is-off { opacity: 0.45; }
.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: color-mix(in srgb, var(--tg-hint) 45%, var(--tg-text));
  cursor: pointer;
  padding: 2px 0;
}
.toggle input { width: 17px; height: 17px; accent-color: var(--tg-button); }
.inline-field { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.inline-field input { width: 62px; padding: 5px 8px; border-radius: 8px;
  border: 1px solid var(--tg-section-separator); background: var(--tg-bg);
  color: var(--tg-text); font: inherit; font-size: 16px; text-align: center; }

.inline-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: var(--bad);
  font-size: 13px;
}

.btn.wide { width: 100%; margin-bottom: var(--gap); }
.btn.small-btn { padding: 6px 12px; font-size: 13px; }

/* пары внутри категории */
.pair-list { display: flex; flex-direction: column; }
.pair {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--tg-secondary-bg);
  margin-bottom: 6px;
  transition: background-color 0.8s ease, box-shadow 0.18s var(--ease-out),
              transform 0.18s var(--ease-out);
  /* touch-action: pan-y здесь обязателен — при перетаскивании только этого
     элемента нельзя, чтобы сам браузер параллельно скроллил страницу и
     конфликтовал с pointermove-обработчиком (см. Admin.category в admin.js). */
  touch-action: pan-y;
}
/* Переход с экрана обслуживания подсвечивает конкретную пару на пару секунд —
   иначе список из десятков одинаковых строк не даёт понять, куда смотреть. */
.pair-highlight { background: color-mix(in srgb, var(--tg-button) 22%, var(--tg-secondary-bg)); }
@media (prefers-reduced-motion: reduce) {
  .pair { transition-duration: 0.01ms; }
}

/* Хват для сортировки. Раньше align-self:stretch растягивал его на всю высоту
   строки (а строки — двух-трёхстрочные, с именем и двумя ссылками), и хват
   визуально центрировался где-то посреди адреса, оторванный от заголовка —
   выглядело как случайная точка, а не ручка для перетаскивания. Пиновим к
   верху вровень с первой строкой названия — так глаз сразу читает его как
   часть строки, не как отдельный декор.
   44×44 зона на pointer:coarse — не просто иконка: меньшая цель на телефоне
   промахивается и вместо драга открывает «Изменить». */
.pair-drag {
  flex: 0 0 auto;
  align-self: flex-start;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: color-mix(in srgb, var(--tg-hint) 65%, var(--tg-text));
  background: color-mix(in srgb, var(--tg-text) 5%, transparent);
  cursor: grab;
  touch-action: none;   /* сам хват — драг, а не скролл страницы */
  margin: -2px 0 -2px -4px;
}
@media (pointer: coarse) {
  .pair-drag { width: 40px; height: 40px; margin: -10px 0 -10px -12px; }
}
.pair-drag::before {
  content: "⠿";
  font-size: 16px;
  line-height: 1;
}
.pair-drag:active { cursor: grabbing; color: var(--tg-text); background: color-mix(in srgb, var(--tg-text) 10%, transparent); }
/* Пока пар меньше двух, менять порядок нечего — хват не рисуем вовсе, а не
   гасим наполовину: неактивная ручка выглядела бы как баг, а не как факт. */
.pair-list.no-reorder .pair-drag { display: none; }

/* Поднятая во время драга пара: тень и лёгкий наклон читаются как «сейчас в
   воздухе», а не просто «сдвинутая строка» — тот же язык, что у .dialog. */
.pair.is-dragging {
  position: relative;
  z-index: 10;
  background: var(--tg-bg);
  box-shadow: var(--shadow-lg);
  transform: scale(1.02);
  transition: none;   /* во время драга положение ведёт JS 1:1 за пальцем — CSS-transition мешала бы (apple-design §3) */
}
/* Остальные строки уступают место мягче, чем «прыжок» — тот же ease-out. */
.pair-list.is-reordering .pair:not(.is-dragging) {
  transition: transform 0.18s var(--ease-out);
}
@media (prefers-reduced-motion: reduce) {
  .pair.is-dragging { transform: none; }
}
/* .pair-content — постоянная обёртка над view()/edit(): сама не участвует
   в раскладке содержимого, а лишь передаёт flex:1 дальше, поэтому её
   собственный display остаётся flex + wrap, как раньше был у .pair. */
.pair-content { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.pair-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pair-name { font-weight: 500; overflow-wrap: anywhere; }
.pair-line { display: flex; flex-direction: column; }
.pair-line span:last-child { overflow-wrap: anywhere; font-size: 13px; }
/* gap ≥ 12px — см. комментарий у .row-actions: «Изменить»/«Удалить» иначе
   делят перекрывающуюся зону нажатия на pointer:coarse. */
.pair-actions { display: flex; gap: 12px; flex: 0 0 auto; flex-wrap: wrap; }
.pair-edit { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.add-pair { margin-top: var(--gap); }
.danger-zone { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--tg-section-separator); }

/* настройки */
.setting-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.setting-label { font-weight: 500; }
.setting-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.setting-row input {
  flex: 1; min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--tg-section-separator);
  background: var(--tg-bg);
  color: var(--tg-text);
  font: inherit; font-size: 16px;
  font-variant-numeric: tabular-nums;
}

/* обслуживание */
.detail-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--tg-section-separator);
  overflow-wrap: anywhere;
}
.detail-row:last-child { border-bottom: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.action-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--tg-section-separator);
}
.action-row:last-child { border-bottom: 0; }
.action-row > div:first-child { flex: 1; min-width: 0; }

/* диалог подтверждения */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.2s var(--ease-out);
}
.overlay.overlay-in { opacity: 1; }
.dialog {
  width: 100%;
  max-width: 340px;
  max-height: 80dvh;
  overflow-y: auto;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--tg-bg);
  color: var(--tg-text);
  box-shadow: var(--shadow-lg);
  /* scale(0.95), не 0 — ничего не появляется из пустоты (emil-design-eng). */
  transform: translateY(10px) scale(0.95);
  transition: transform 0.24s var(--ease-out);
  transform-origin: center;   /* модалка не привязана к точке нажатия — центр верен (apple-design §7) */
}
.overlay.overlay-in .dialog { transform: translateY(0) scale(1); }
@media (prefers-reduced-motion: reduce) {
  .overlay, .dialog { transition-duration: 0.01ms; backdrop-filter: none; }
}
.dialog h2 { margin: 0 0 10px; font-size: 17px; }
.dialog p { margin: 0 0 8px; font-size: 14px; overflow-wrap: anywhere; }
/* gap ≥ 12px: та же причина, что у .row-actions/.pair-actions — на
   pointer:coarse .btn расширяет зону нажатия на 6px в каждую сторону, а тут
   это «Отмена» вплотную к «Удалить», самому частому разрушительному действию. */
.dialog-actions { display: flex; gap: 12px; margin-top: 16px; }
.dialog-actions .btn { flex: 1; }

/* плашки-уведомления */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 200;
  max-width: min(90vw, 420px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--tg-text);
  color: var(--tg-bg);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: translate(-50%, 12px) scale(0.96);
  opacity: 0;
  transition: opacity 0.22s var(--ease-out), transform 0.22s var(--ease-out);
  pointer-events: none;
}
.toast.toast-in { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.bad { background: var(--bad); color: #fff; }
@media (prefers-reduced-motion: reduce) {
  .toast { transition-duration: 0.01ms; }
}

/* Метка поля: сам <label> обнимает input, поэтому раскладку задаём здесь. */
.field-label { display: flex; flex-direction: column; gap: 4px; }

/* Заголовок категории кликабелен — переименование на месте. */
.screen-title.editable { cursor: pointer; }
.screen-title.editable::after {
  content: " ✏️";
  font-size: 0.7em;
  opacity: 0.55;
}
.rename-form { margin-bottom: var(--gap); }
