/* Tenant admin — base layout & shared components.
 *
 * Consumes tokens.css. No literal colours / fonts / radii allowed here;
 * always reference --c-*, --radius-*, --font-*.
 *
 * Page-specific styles (per-TV world, kinds picker, auth, modal) live in
 * their own files and extend this base. */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================ Layout */

.app {
  display: grid;
  grid-template-columns: var(--size-sidebar) 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* Subgrid: sidebar (brand+nav) and main (topbar+content) share the app's
 * two rows. Row 1 auto-sizes to max(brand, topbar) and row 2 fills. That
 * way the first nav item and the page H1 are always on the same Y line
 * regardless of brand or topbar heights — no margin tuning. */
.sidebar {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: subgrid;
  background: var(--c-card);
  border-right: 1px solid var(--c-border);
  padding: 14px 6px;
  gap: 4px;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px;
  text-decoration: none;
  color: inherit;
  grid-row: 1;
}

.sidebar__brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-button);
  background: linear-gradient(135deg, #818CF8 0%, var(--c-primary) 100%);
  display: grid;
  place-items: center;
  color: var(--c-primary-on);
  flex-shrink: 0;
}

.sidebar__brand-mark svg { width: 15px; height: 15px; }

.sidebar__brand-name {
  font-family: var(--font-brand);
  font-size: var(--fs-h3);
  font-weight: var(--fw-semibold);
  color: var(--c-primary);
  line-height: 1.2;
}

.sidebar__brand-tag {
  font-size: var(--fs-meta);
  color: var(--c-text-hint);
  letter-spacing: 0.10px;
}

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; grid-row: 2; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-button);
  text-decoration: none;
  color: var(--c-text-secondary);
  font-size: 15px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.1px;
}
.sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar__link:hover { background: var(--c-surface-muted); }
.sidebar__link.is-active {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: var(--fw-medium);
}
/* Утилитарная ссылка прижата к низу ЭКРАНА (не контента). Сайдбар — subgrid,
 * его высота = высота страницы, поэтому margin-top:auto прижимал бы QR к концу
 * длинной страницы (нужно было скроллить). Фиксируем к низу вьюпорта в колонке
 * сайдбара. На ≤900px сайдбар display:none — эта ссылка скрывается вместе с ним. */
.sidebar__link--footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: var(--size-sidebar);
  margin: 0;
  padding: 12px 20px;
  background: var(--c-card);
  border-top: 1px solid var(--c-border);
  border-right: 1px solid var(--c-border);
  color: var(--c-text-hint);
  font-size: 14px;
}

/* ============================================================ Topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding: 0 var(--gutter);
  height: var(--size-topbar);
  background: transparent;
  color: var(--c-text-secondary);
  font-size: var(--fs-ui);
}

/* Mobile-only shell (topbar + bottom nav). Hidden on desktop. */
.mobile-topbar { display: none; }
.mobile-nav    { display: none; }

.topbar__user { display: flex; align-items: center; gap: 12px; }
.topbar__user b { color: var(--c-text); font-weight: var(--fw-medium); }
.topbar__logout {
  padding: 8px 16px;
  font-size: var(--fs-ui);
  font-weight: var(--fw-semibold);
  margin-left: 4px;
}

.topbar__dev,
.topbar__menu {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-pill);
  color: var(--c-text-secondary);
  text-decoration: none;
  font-size: var(--fs-ui);
  cursor: pointer;
}
.topbar__dev:hover, .topbar__menu:hover { border-color: var(--c-primary); color: var(--c-primary); }

.topbar__menu-dd {
  position: relative;
}
.topbar__menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 20;
}
.topbar__menu-dd[data-open="true"] .topbar__menu-list { display: flex; }
.topbar__menu-list a {
  padding: 8px 10px;
  border-radius: var(--radius-button);
  text-decoration: none;
  color: var(--c-text-secondary);
  font-size: var(--fs-ui);
}
.topbar__menu-list a:hover { background: var(--c-primary-soft); color: var(--c-primary); }

.impersonate-flag {
  background: var(--c-warn-soft);
  color: var(--c-warn);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-meta);
}

.linkbtn {
  background: transparent;
  border: none;
  color: var(--c-primary);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ============================================================ Content */

.main {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: subgrid;
  min-width: 0;
}

.content {
  /* padding-top matches .sidebar__link padding-top so the H1 baseline
   * lines up with the first nav item's text baseline. */
  padding-top: 6px;
  padding-right: var(--gutter);
  padding-bottom: 40px;
  padding-left: var(--gutter);
  grid-row: 2;
  min-width: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  /* flex-start выравнивает ряд кнопок по верхней линии h1. center
   * визуально вешал кнопки между h1 и subtitle (h1 наверху, кнопки
   * посередине — разные уровни). flex-end (старое) клал их на нижнюю
   * линию subtitle — то же самое наоборот. */
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0; }
/* Subtitle глобально имеет margin: 0 0 18px. В page-head нижний отступ
 * лишний (сам .page-head даёт margin-bottom 18px ниже), а вот 4px
 * сверху нужен, чтобы subtitle не прилипал к h1. */
.page-head .subtitle { margin: 4px 0 0; }
.page-head .row-actions { display: flex; gap: 10px; }
/* В .row-actions встречаются скрытые <form> для POST-submit'ов (см.
 * world_detail.html / world.html — form-rotate-code, form-unbind-tv,
 * form-delete-tv и т.д.). Без своего контента они flex-item'ы шириной
 * 0, но слева+справа от них применяется `gap` → визуально двойной
 * отступ между кнопками. Убираем из flex flow. JS form.submit()
 * работает независимо.
 *
 * !important нужен потому что у этих форм в шаблонах стоит inline
 * `style="display:inline"` (legacy паттерн, чистить по всему дереву
 * не хочется), а inline бьёт обычный класс. */
.row-actions > form:empty { display: none !important; }

h1 {
  font-family: var(--font-ui);
  font-size: var(--fs-display);
  font-weight: var(--fw-bold);
  letter-spacing: -0.2px;
  color: var(--c-text);
  margin: 0 0 4px;
}
h2 {
  font-size: var(--fs-h2);
  font-weight: var(--fw-bold);
  color: var(--c-text);
  margin: 0 0 12px;
}
h3 {
  font-size: var(--fs-h3);
  font-weight: var(--fw-semibold);
  color: var(--c-text);
  margin: 0 0 10px;
}
.subtitle {
  color: var(--c-text-secondary);
  font-size: var(--fs-ui);
  margin: 0 0 18px;
}
.hint { color: var(--c-text-hint); font-size: var(--fs-meta); letter-spacing: 0.1px; }

/* ============================================================ Card */

.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px;
}

.card--soft  { background: var(--c-surface-muted); }
.card--alert { background: var(--c-err-soft); border-color: var(--c-err-border); }
.card--info  { background: var(--c-primary-soft); border-color: transparent; }
.card--warn  { background: var(--c-warn-soft); border-color: transparent; }

.metric {
  font-size: 30px;
  font-weight: var(--fw-medium);
  color: var(--c-text);
  margin: 0;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.metric-label {
  display: block;
  color: var(--c-text-hint);
  font-size: var(--fs-meta);
  margin-top: 6px;
}

/* Grids */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap-card); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap-card); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap-card); }
.grid-auto-220 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(216px, 1fr));
  gap: var(--gap-card);
}

.branch-home__head {
  align-items: flex-start;
}

.branch-home__grid {
  margin-bottom: var(--gap-card);
  grid-template-columns: repeat(auto-fill, minmax(300px, 390px));
}

.branch-home__tile {
  gap: 0;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}

.branch-home__tile:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 3px;
}

.branch-home__link {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  color: inherit;
  text-decoration: none;
}
.branch-home__identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.branch-home__tile:hover {
  border-color: var(--c-primary);
  background: var(--c-surface-muted);
}

.branch-home__pin {
  color: var(--c-primary);
}

.branch-home__pin svg {
  width: 20px;
  height: 20px;
}

.branch-home__access {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
  border-top: 1px solid var(--c-border);
  background: var(--c-card);
}
.branch-home__pin-block { display: grid; gap: 7px; }
.branch-home__access-label {
  color: var(--c-text-secondary);
  font-size: var(--fs-meta);
  font-weight: var(--fw-semibold);
}
.branch-home__code {
  display: flex;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  width: max-content;
  cursor: text;
  user-select: text;
}
.branch-home__code span {
  width: 31px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--c-primary) 28%, var(--c-border));
  border-radius: 9px;
  background: var(--c-card);
  color: var(--c-text);
  font-size: 20px;
  line-height: 1;
  box-shadow: none;
}
.branch-home__code-empty { color: var(--c-text-secondary); font-size: var(--fs-ui); }
.branch-home__copy {
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  padding: 0;
  color: var(--c-text-secondary);
  background: transparent;
  font: inherit;
  font-size: var(--fs-ui);
  cursor: pointer;
}
.branch-home__copy img { width: 14px; height: 14px; flex: 0 0 auto; }
.branch-home__copy:hover { color: var(--c-primary); }
.branch-home__copy:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 3px;
  border-radius: 4px;
}
.branch-home__copy.is-copied { color: var(--c-ok); }
.branch-home__copy.is-copied img { display: none; }
.branch-home__reset {
  flex: 0 0 auto;
  min-height: 38px;
  background: var(--c-card);
}

/* Плашка PIN в зале — организация с одной точкой (списка филиалов нет).
 * Классы цифр/копирования переиспользуются из .branch-home__*, здесь
 * только раскладка карточки: на десктопе текст и код в ряд, на телефоне
 * (основной способ захода в админку) — колонкой, кнопка на всю ширину. */
.pin-plate {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  margin-bottom: var(--gap-card);
}
.pin-plate__main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}
.pin-plate__copy { min-width: 0; }
.pin-plate__title { margin: 0 0 4px; font-size: var(--fs-h2); }
.pin-plate__hint {
  margin: 0;
  color: var(--c-text-secondary);
  font-size: var(--fs-ui);
  line-height: 1.45;
}
.pin-plate__hint a { color: var(--c-primary); font-weight: var(--fw-semibold); }
.pin-plate__access { display: grid; gap: 7px; justify-items: start; }
.pin-plate__reset {
  flex: 0 0 auto;
  min-height: 38px;
  background: var(--c-card);
}

@media (max-width: 900px) {
  .pin-plate {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .pin-plate__main { flex-direction: column; align-items: stretch; }
  .pin-plate__access { justify-items: center; }
  .pin-plate__reset { width: 100%; }
}

.print-alert.branch-home__guide {
  margin: 0 0 20px;
  max-width: 760px;
}
.branch-home__guide a { color: #9A6400; font-weight: var(--fw-semibold); }

.branch-scope {
  display: grid;
  justify-items: start;
  gap: 5px;
  margin: 0 0 22px;
  color: var(--c-text-secondary);
  font-size: var(--fs-ui);
}
.branch-scope__back { margin: 0; }
.branch-scope__back a { color: var(--c-text-secondary); text-decoration: none; }
.branch-scope__back a:hover { color: var(--c-primary); }
.branch-scope__title {
  color: var(--c-text);
  font-size: var(--fs-display);
  font-weight: var(--fw-bold);
  line-height: 1.12;
  letter-spacing: -0.4px;
}

.branch-access {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
  padding: 18px 22px;
  border-color: color-mix(in srgb, var(--c-primary) 22%, var(--c-border));
  background: color-mix(in srgb, var(--c-primary) 4%, var(--c-card));
}
.branch-access__copy { min-width: 0; }
.branch-access__eyebrow { color: var(--c-primary); font-size: var(--fs-meta); font-weight: var(--fw-semibold); }
.branch-access h2 { margin: 4px 0; font-size: 22px; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.branch-access p { margin: 0; color: var(--c-text-secondary); font-size: var(--fs-ui); }
.branch-access__reset { flex: 0 0 auto; background: transparent; }

.branch-home__empty {
  max-width: 560px;
  padding: 28px;
}

@media (max-width: 720px) {
  .branch-home__access, .branch-access { align-items: stretch; flex-direction: column; }
  .branch-home__reset, .branch-access__reset { width: 100%; }
  .branch-scope { margin-top: -4px; gap: 4px; }
  .branch-home__code span { width: 38px; height: 42px; font-size: 22px; }
}

/* ============================================================ Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-button);
  padding: 8px 16px;
  font: inherit;
  font-size: var(--fs-ui);
  font-weight: var(--fw-medium);
  cursor: pointer;
  text-decoration: none;
  background: var(--c-card);
  color: var(--c-text);
}
.btn:hover { border-color: var(--c-border-strong); }

.btn--primary {
  background: var(--c-primary);
  color: var(--c-primary-on);
  border-color: var(--c-primary);
}
.btn--primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }

.btn--ghost {
  background: var(--c-card);
  border-color: var(--c-border);
  color: var(--c-text-secondary);
}

.btn--danger {
  background: var(--c-err-soft);
  border-color: var(--c-err-border);
  color: var(--c-err);
}
.btn--danger:hover { background: var(--c-err); color: var(--c-primary-on); }

.btn--pill { border-radius: var(--radius-pill); padding: 8px 18px; }

/* Компактная кнопка внутри карточек (Figma: h28, radius 14, 10/600).
 * radius-pill при высоте 28px даёт ту же геометрию, что 14px в макете. */
.btn--sm {
  height: 28px;
  padding: 0 12px;
  gap: 6px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-meta);
  font-weight: var(--fw-semibold);
}
.btn--sm svg { width: 12px; height: 12px; flex-shrink: 0; }

/* Messenger brand buttons (Telegram / WhatsApp / MAX). */
.btn--tg {
  background: #2AABEE;
  border-color: #2AABEE;
  color: #FFFFFF;
}
.btn--tg:hover { background: #1E8BBF; border-color: #1E8BBF; }

.btn--wa {
  background: #25D366;
  border-color: #25D366;
  color: #FFFFFF;
}
.btn--wa:hover { background: #1FB957; border-color: #1FB957; }

.btn--max {
  background: #8C57E8;
  border-color: #8C57E8;
  color: #FFFFFF;
}
.btn--max:hover { background: #7340D4; border-color: #7340D4; }

/* ============================================================ Badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-meta);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.1px;
  background: var(--c-surface-muted);
  color: var(--c-text-secondary);
  /* inline-flex с padding выравнивается по baseline'у внутреннего
   * текста — снаружи кажется, что бейдж «упал» ниже строки. middle
   * прижимает его центр к x-height строки → визуально на одной линии
   * с соседним текстом. */
  vertical-align: middle;
}
.badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.badge--ok    { background: var(--c-ok-soft);  color: var(--c-ok); }
.badge--err   { background: var(--c-err);      color: var(--c-primary-on); }
.badge--err-soft { background: var(--c-err-soft); color: var(--c-err); }
.badge--warn  { background: var(--c-warn-soft); color: var(--c-warn); }
.badge--info  { background: var(--c-primary-soft); color: var(--c-primary); }

/* ============================================================ Flash */

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-card);
  margin-bottom: 16px;
  font-size: var(--fs-body);
  border: 1px solid transparent;
}
.flash-error { background: var(--c-err-soft);  color: var(--c-err);  border-color: var(--c-err-border); }
.flash-warn  { background: var(--c-warn-soft); color: var(--c-warn); }
.flash-ok    { background: var(--c-ok-soft);   color: var(--c-ok); }

/* ============================================================ Toasts */
/* Floating, self-dismissing notifications. Дизайн строго по макету деки
 * (Admin Dis Review V3, слайд «Снэкбары»): success = тёмная пилюля +
 * зелёная галка в круге-обводке; error = светло-розовая + красный крест
 * в круге-обводке. Только эти два варианта. */

.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(400px, calc(100vw - 36px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-radius: 18px;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast.is-in { opacity: 1; transform: none; }
.toast.is-out { opacity: 0; transform: translateY(-8px) scale(0.98); }
.toast__icon {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: grid;
  place-items: center;
}
.toast__icon svg { width: 15px; height: 15px; }
.toast__msg {
  flex: 1;
  font-size: 15px;
  line-height: 1.35;
  font-weight: var(--fw-bold);
}

.toast--ok { background: #2E2E2E; color: #FFFFFF; }
.toast--ok .toast__icon { color: var(--c-ok); }

.toast--error {
  background: var(--c-err-soft);
  color: var(--c-err);
}
.toast--error .toast__icon { color: var(--c-err); }

@media (max-width: 900px) {
  .toast-stack {
    top: auto;
    bottom: calc(94px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    left: 12px;
    width: auto;
  }
}
@media (prefers-reduced-motion: reduce) {
  .toast, .toast.is-in, .toast.is-out {
    transition: opacity 0.15s linear;
    transform: none;
  }
}

/* ============================================================ Support FAB */

.support-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--c-primary);
  color: var(--c-primary-on);
  font: inherit;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-fab);
  display: grid;
  place-items: center;
}

.support-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 20, 24, 0.38);
}
.support-modal[hidden] { display: none; }
.support-dialog {
  width: min(520px, 100%);
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-pop);
}
.support-dialog .page-head { align-items: flex-start; margin-bottom: 14px; }
.support-dialog h2 { margin: 0 0 4px; }
.support-dialog .hint { margin: 0; }

/* ============================================================ Forms */

label.field {
  display: block;
  margin-bottom: 12px;
  color: var(--c-text-secondary);
  font-size: var(--fs-ui);
}
label.field input,
label.field textarea,
label.field select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-input);
  font: inherit;
  font-size: var(--fs-body);
  color: var(--c-text);
}
label.field textarea { resize: vertical; }
label.field input:focus,
label.field textarea:focus,
label.field select:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}

/* ============================================================ Misc */

code {
  background: var(--c-primary-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: var(--fs-ui);
  color: var(--c-primary);
}

table.rows {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-body);
  background: var(--c-card);
  border-radius: var(--radius-card);
  overflow: hidden;
}
table.rows th, table.rows td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-border);
}
table.rows th {
  font-weight: var(--fw-semibold);
  color: var(--c-text-hint);
  background: var(--c-surface-muted);
  font-size: var(--fs-meta);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.rows tr:last-child td { border-bottom: none; }

/* ============================================================ TV card */

.tv-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  text-decoration: none;
  color: inherit;
  position: relative;
}
a.tv-card:hover {
  border-color: var(--c-primary);
  background: var(--c-surface-muted);
}
.tv-card.is-offline { background: var(--c-err-soft); border-color: var(--c-err-border); }

/* Плитка перестала быть ссылкой — курсор обычный. */
.tv-card--static { cursor: default; }

/* Карандаш возле имени экрана. */
.tv-card__name { display: flex; align-items: center; gap: 6px; }
.tv-card__edit {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--c-text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.tv-card__edit svg { width: 13px; height: 13px; }
.tv-card__edit:hover { color: var(--c-primary); }

/* Кнопка перезапуска прижата к низу плитки независимо от длины текста. */
.tv-card__action {
  margin-top: auto;
  padding-top: 10px;
}

.tv-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.tv-card__icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-button);
  background: var(--c-primary-soft);
  color: var(--c-primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.tv-card.is-offline .tv-card__icon { background: var(--c-err-border); color: var(--c-err); }
.tv-card__icon svg { width: 20px; height: 20px; }

.tv-card__name {
  font-size: var(--fs-body);
  font-weight: var(--fw-bold);
  letter-spacing: 0.13px;
  color: var(--c-text);
  margin: 0;
}
.tv-card__sub {
  color: var(--c-text-secondary);
  font-size: var(--fs-ui);
  margin: 0;
}
.tv-card__sub--world { color: var(--c-text-secondary); }
.tv-card__sub--world strong {
  color: var(--c-text);
  font-weight: var(--fw-semibold);
}

.incident-banner {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 14px;
  background: var(--c-err-soft);
  border: 1px solid var(--c-err-border);
  border-radius: var(--radius-card);
  margin-bottom: var(--gap-card);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.incident-banner:hover { background: #FBE3E3; border-color: var(--c-err); }
.incident-banner__text { flex: 1 1 auto; min-width: 0; }
.incident-banner__chevron {
  width: 8px;
  height: 12px;
  color: var(--c-err);
  flex-shrink: 0;
  transition: transform 0.15s;
}
.incident-banner:hover .incident-banner__chevron { transform: translateX(2px); }
.incident-banner__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-card);
  background: var(--c-err-border);
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}
.incident-banner__title {
  color: var(--c-err);
  font-size: var(--fs-body);
  font-weight: var(--fw-semibold);
  margin: 0 0 4px;
}
.incident-banner__body {
  color: var(--c-text-hint);
  font-size: var(--fs-meta);
  margin: 0;
  line-height: 1.5;
}

.section-title {
  font-size: var(--fs-h3);
  font-weight: var(--fw-bold);
  margin: 24px 0 12px;
}
#screens { scroll-margin-top: 76px; }

/* ============================================================ FAQ */

.faq-group { margin-bottom: 20px; }
.faq-group__title {
  font-size: var(--fs-h3);
  font-weight: var(--fw-bold);
  color: var(--c-text);
  margin: 0 0 10px;
}
.faq-item {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-pill);
  margin-bottom: 8px;
  overflow: hidden;
}
.faq-item[open] {
  border-radius: var(--radius-card);
}
.faq-item__q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  cursor: pointer;
  list-style: none;
  font-size: var(--fs-body);
  color: var(--c-text);
  min-height: 56px;
}
.faq-item__q:hover { background: var(--c-surface-muted); }
.faq-item__q::-webkit-details-marker { display: none; }
.faq-item__q::after {
  content: "›";
  font-size: 18px;
  color: var(--c-text-hint);
  transform: rotate(90deg);
  transition: transform 0.18s;
  flex-shrink: 0;
}
.faq-item[open] > .faq-item__q::after { transform: rotate(-90deg); }
.faq-item__a {
  padding: 4px 18px 18px;
  color: var(--c-text-secondary);
  font-size: var(--fs-body);
  line-height: 1.5;
}
.faq-item__bullets {
  margin: 0;
  padding-left: 20px;
  white-space: normal;
}
.faq-item__bullets li { margin-bottom: 4px; }
.faq-item__bullets li:last-child { margin-bottom: 0; }

/* ============================================================ Mobile (≤900px)
 *
 * Layout switches: desktop sidebar + topbar are hidden; a sticky mobile
 * topbar (brand + ⋯ menu) and a fixed bottom tab nav take over. See
 * tenant/_mobile_topbar.html and tenant/_mobile_nav.html. */

@media (max-width: 900px) {
  :root {
    --gutter: 16px;
    --gap-card: 14px;
    /* Bigger typography on phones — matches login/auth scale so the whole
     * admin reads at the same comfort level. */
    --fs-display: 26px;
    --fs-h2:      18px;
    --fs-h3:      16px;
    --fs-body:    16px;
    --fs-ui:      15px;
    --fs-meta:    13px;
  }

  /* Buttons + form controls bump to match the login screen. */
  .btn { padding: 12px 18px; font-size: var(--fs-ui); }
  .btn--pill { padding: 12px 20px; }
  .btn--block-mobile { display: block; width: 100%; }
  label.field input,
  label.field textarea,
  label.field select { padding: 14px 16px; }
  .users-form .btn { padding: 14px 22px; font-size: 16px; }
  .auth__submit, .auth__input { /* already handled in auth.css */ }

  .app { grid-template-columns: 1fr; grid-template-rows: none; }
  .sidebar { display: none; }
  .topbar  { display: none; }
  .main {
    grid-column: 1;
    grid-row: auto;
    display: flex;
    flex-direction: column;
  }
  .content { grid-row: auto; }

  /* Thicker borders so blocks are more visible on small screens. */
  .card,
  .tv-card,
  .faq-item,
  .users-table tr,
  .overlay__dialog,
  .auth__card,
  .auth__input,
  .auth__channel,
  .kind-pick__card,
  .print-alert,
  .incident-banner { border-width: 1.5px; }

  /* iOS Safari zooms input on focus when font-size < 16px. Force 16px
   * globally for text-like inputs across the admin so taps stay calm. */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select { font-size: 16px; }

  /* ---------- Mobile topbar ---------- */

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 10px var(--gutter);
    background: var(--c-bg);
    border-bottom: 1px solid var(--c-border);
  }
  .mobile-topbar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
  }
  .mobile-topbar__mark {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-button);
    background: linear-gradient(135deg, #818CF8 0%, var(--c-primary) 100%);
    display: grid;
    place-items: center;
    color: var(--c-primary-on);
    flex-shrink: 0;
  }
  .mobile-topbar__mark svg { width: 14px; height: 14px; }
  .mobile-topbar__name {
    font-family: var(--font-brand);
    font-size: 18px;
    font-weight: var(--fw-semibold);
    color: var(--c-primary);
    letter-spacing: -0.2px;
  }
  .mobile-topbar__more {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-button);
    background: var(--c-card);
    border: 1px solid var(--c-border);
    color: var(--c-text-secondary);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
  }
  .mobile-topbar__menu-list { right: 0; left: auto; min-width: 220px; }
  .mobile-topbar__user {
    padding: 10px 12px 6px;
    border-bottom: 1px solid var(--c-border);
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .mobile-topbar__user strong {
    color: var(--c-text);
    font-size: var(--fs-body);
    word-break: break-all;
  }
  .mobile-topbar__menu-action {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 8px 10px;
    border-radius: var(--radius-button);
    font: inherit;
    color: var(--c-text-secondary);
    cursor: pointer;
  }
  .mobile-topbar__menu-action:hover {
    background: var(--c-primary-soft);
    color: var(--c-primary);
  }
  .mobile-topbar__menu-action--logout { color: var(--c-err); }
  .mobile-topbar__menu-action--logout:hover { background: var(--c-err-soft); color: var(--c-err); }

  /* ---------- Bottom tab nav ---------- */

  .mobile-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: 82px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 4px;
    background: var(--c-card);
    border-top: 1.5px solid var(--c-border);
  }
  .mobile-nav__link {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 6px;
    border-radius: var(--radius-button);
    text-decoration: none;
    color: var(--c-text-secondary);
    font-size: 14px;
    line-height: 1.1;
    font-weight: var(--fw-medium);
  }
  .mobile-nav__link svg { width: 30px; height: 30px; }
  .mobile-nav__link.is-active {
    background: var(--c-primary-soft);
    color: var(--c-primary);
    font-weight: var(--fw-medium);
  }

  /* ---------- Content + FAB spacing ---------- */

  .content {
    padding: 14px var(--gutter) calc(104px + env(safe-area-inset-bottom, 0px));
  }
  .support-fab {
    right: 16px;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
    font-size: 22px;
  }

  /* ---------- Page-level adaptations ---------- */

  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 14px;
  }
  .page-head .row-actions { flex-wrap: wrap; gap: 8px; }
  /* min-width: 0 — даёт flex-кнопкам право сжиматься ниже их текстовой
   * ширины (без этого «Архивировать» распирает ряд). flex-basis:
   * calc((100% - 8px) / 2) кладёт кнопки 2-в-ряд, последняя нечётная
   * растягивается на всю строку (`flex-grow: 1`). */
  .page-head .row-actions .btn {
    flex: 1 1 calc((100% - 8px) / 2);
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .grid-2,
  .grid-3,
  .grid-4 { grid-template-columns: 1fr; }
  /* On phones, cards become a vertical list — more breathing room and
   * names/badges aren't truncated. */
  .grid-auto-220 { grid-template-columns: 1fr; gap: 10px; }

  h1 { font-size: var(--fs-display); line-height: 1.2; letter-spacing: -0.3px; }
  .metric { font-size: 30px; }
  .section-title { margin: 18px 0 10px; }

  table.rows {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}


/* ============================================================ Print-alert */
/* Warning/info card used on /admin/kinds ("Перед печатью") and on the
 * world page ("Как работают сюжеты"). */

.print-alert {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 16px 18px;
  background: #FFF8F1;
  border: 1px solid #FFE7C0;
  border-radius: var(--radius-card);
  margin-bottom: 18px;
}
.print-alert__icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: #FFE7C0;
  color: #FFFFFF;
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}
.print-alert__title {
  margin: 0 0 6px;
  font-size: var(--fs-h3);
  font-weight: var(--fw-bold);
  color: #F59E0B;
}
.print-alert__body {
  margin: 0;
  padding-left: 0;
  font-size: var(--fs-body);
  color: #5F4A1C;
  line-height: 1.5;
}
ul.print-alert__body,
ol.print-alert__body { padding-left: 18px; list-style-position: outside; }
.print-alert__body li { margin-bottom: 2px; }
.print-alert__body li:last-child { margin-bottom: 0; }
.print-alert__body li::marker { color: #F59E0B; }

/* ============================================================ Users page */

.users-table-wrap {
  background: var(--c-card);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  margin-bottom: var(--gap-card);
}
.users-table { margin: 0; }

.users-form .field { margin-bottom: 14px; }
.users-form .btn { margin-top: 4px; }

/* Mobile: stacked card layout instead of horizontal scroll. */
@media (max-width: 720px) {
  .users-table-wrap {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }
  table.users-table {
    display: block;
    background: transparent;
    border-radius: 0;
    overflow: visible;
  }
  table.users-table thead { display: none; }
  table.users-table tbody { display: block; }
  table.users-table tr {
    display: block;
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-card);
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-card);
  }
  table.users-table tr:last-child { margin-bottom: 0; }
  table.users-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border: none;
    white-space: normal;
    word-break: break-word;
  }
  table.users-table td::before {
    content: attr(data-label);
    color: var(--c-text-hint);
    font-size: var(--fs-meta);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
  }
  table.users-table td.muted { color: var(--c-text-secondary); }

  .users-table__badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    max-width: 65%;
  }
  .users-table__badges .badge { white-space: nowrap; flex-shrink: 0; }
}

/* Desktop — inline row of badges with same wrapping behaviour. */
.users-table__badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}
.users-table__badges .badge { white-space: nowrap; }
