/* Область: header-home. Правки под старый дизайн, без inline-стилей.
   Базовые классы (.header/.drawer/.tabbar/.pub-*) уже есть в base.css и public.css —
   здесь только то, чего не хватает новому каркасу (скрытие по [hidden], компактные
   подписи шапки, адаптив меню категорий и модалки города). */

/* ============================================================
   Шапка/слои (task-14, п.1): выпадающее меню «Администратор» не должно
   уходить под липкий .admin-toolbar (z-index 80 в admin-page.css).
   Поднимаем весь .header выше тулбара, но ниже мобильной шторки (90/100)
   и модалок (200): sticky-таблицы, drawer и lightbox не ломаются.
   ============================================================ */

.header {
  z-index: 85;
}

/* ============================== Шапка ============================== */

/* Компактные подписи (≤860px): «Тема», «Профиль», «Админ», «Орг.» — как в старом Header.tsx. */
.pub-header-compact {
  display: none;
}

@media (max-width: 860px) {
  .pub-header-wide {
    display: none;
  }

  .pub-header-compact {
    display: inline;
  }
}

/* Скрытые узлы шапки: классы с display перекрывают атрибут hidden. */
#org-points[hidden],
#org-child-point[hidden],
[data-unread][hidden],
.btn[hidden],
.nav-link[hidden] {
  display: none !important;
}

/* Точка организации в шапке: имя не раздувает кнопку. */
.pub-header-points-btn {
  min-width: 0;
}

.pub-header-points .dropdown-panel {
  min-width: 248px;
}

/* «Мой профиль» — ссылка (кнопка профиля в модалке), но высота пункта как у старого button. */
.dropdown-item[data-profile] {
  line-height: 18px;
}

/* ============================== Композер ============================== */

/* Скрытый typewriter и drag&drop-оверлей: display у классов перекрывает [hidden]. */
.typewriter[hidden],
.loc-hint[hidden],
.loc-chip[hidden],
.cat-chip[hidden],
.dnd-overlay[hidden] {
  display: none !important;
}

/* Круговой прогресс загрузки фото: процент задаётся классом (без inline-стилей). */
.circular-progress.pok-p-0 {
  --p: 0%;
}

.circular-progress.pok-p-10 {
  --p: 10%;
}

.circular-progress.pok-p-20 {
  --p: 20%;
}

.circular-progress.pok-p-30 {
  --p: 30%;
}

.circular-progress.pok-p-40 {
  --p: 40%;
}

.circular-progress.pok-p-50 {
  --p: 50%;
}

.circular-progress.pok-p-60 {
  --p: 60%;
}

.circular-progress.pok-p-70 {
  --p: 70%;
}

.circular-progress.pok-p-80 {
  --p: 80%;
}

.circular-progress.pok-p-90 {
  --p: 90%;
}

.circular-progress.pok-p-100 {
  --p: 100%;
}

/* ============================== Меню категорий (мобильное) ============================== */

@media (max-width: 640px) {
  /* Панель меню категорий — на всю ширину контента (в старом правая колонка уходила за экран).
     Новый мобильный аккордеон (.cat-picker--acc) позиционируется отдельно. */
  .cat-picker:not(.cat-picker--acc) {
    left: -43px;
    right: -43px;
    height: min(62dvh, 420px);
  }

  .cat-col.pub-cat-col-left {
    width: 44%;
    min-width: 130px;
  }

  .pub-cat-grid {
    grid-template-columns: 1fr;
  }

  .pub-cat-crumb {
    padding: 8px 10px 6px;
  }

  .pub-cat-scroll--right {
    padding: 4px 8px 8px;
  }
}

/* ============================== Модалка «Город и районы» ============================== */

/* Старый на мобиле ломается (2 колонки в 358px) — баг не копируем: одна колонка. */
@media (max-width: 640px) {
  .pub-loc-grid {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
    gap: 10px;
  }

  .pub-loc-panel {
    max-height: 34dvh;
  }

  .pub-loc-footer {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

/* ============================================================
   Мобильный shell (2026-11-28): шапка-бургер, drawer с темой,
   нижний tabbar из трёх кнопок, место под него на страницах.
   ============================================================ */

:root {
  /* Высота нижнего меню (task-14, п.21): компактнее на телефоне —
     3 пункта по 46px + отступы 2+2. Итог 50px (+ safe-area). */
  --tabbar-h: 50px;
  --tabbar-space: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

/* ---------- шапка ---------- */

.header-icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 12px;
  color: var(--text);
}

.header-icon-btn svg {
  display: block;
}

.header-avatar {
  display: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--grad);
  color: var(--grad-text);
  font-size: 13px;
  font-weight: 800;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

.header-account-btn {
  gap: 6px;
  padding-left: 6px;
  padding-right: 8px;
}

.header-login-btn {
  flex-shrink: 0;
}

/* Кнопка «Моя организация» в шапке убрана (профиль — в меню аккаунта/drawer). */
.pub-header-org-btn {
  display: none !important;
}

/* ---------- Переключатель темы в шапке (только ПК, пункт 3) ----------
   Одна лаконичная иконка: в светлой теме — луна, в тёмной — солнце. */
.header-theme-btn {
  color: var(--secondary);
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.header-theme-btn:hover {
  color: var(--text);
}

.header-theme-btn.is-dark {
  color: var(--brand);
}

.header-theme-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Скрытый для глаз, но читаемый скринридером текст (состояние темы). */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Логотип по центру мобильной шапки, кнопки — по краям. */
@media (max-width: 860px) {
  /* На телефоне тема переключается в drawer/профиле — иконка в шапке не нужна. */
  .header-theme-btn {
    display: none !important;
  }

  .header-inner.pub-header-inner {
    position: relative;
    padding: 0 10px;
    gap: 6px;
  }

  .pub-header-logo-mobile {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 19px;
    pointer-events: auto;
  }

  .logo-mobile {
    display: flex !important;
  }
}

@media (max-width: 640px) {
  .header-avatar {
    display: inline-flex;
  }

  /* На узком экране аккаунт — аватар с кареткой, без длинных подписей. */
  .header-account-btn .pub-header-wide,
  .header-account-btn .pub-header-compact {
    display: none !important;
  }

  /* Кнопка «Моя организация» в шапке не нужна: профиль организации доступен
     из меню аккаунта/drawer. */
  .pub-header-org-btn {
    display: none !important;
  }

  /* Организации: переключатель точек и ссылку на организацию оставляем в drawer. */
  .pub-header-org-row .pub-header-org-btn,
  .pub-header-org-row .pub-header-child-point,
  .pub-header-org-row .pub-header-points {
    display: none !important;
  }

  .header-inner.pub-header-inner {
    padding: 0 8px;
  }

  .header-login-btn {
    padding-left: 14px;
    padding-right: 14px;
  }
}

/* ---------- drawer: закрытие и переключатель темы ---------- */

.drawer {
  width: min(340px, 86vw);
}

.drawer-close-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  color: var(--secondary);
}

.drawer-close-btn svg {
  display: block;
}

.drawer-body {
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}

.drawer-item:hover {
  background: var(--surface-2);
}

.drawer-theme-ico {
  display: inline-flex;
  width: 19px;
  justify-content: center;
  color: var(--secondary);
  flex-shrink: 0;
}

.theme-ico {
  display: block;
}

html[data-theme='dark'] .theme-ico-moon {
  display: none;
}

html:not([data-theme='dark']) .theme-ico-sun {
  display: none;
}

.theme-switch {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  flex-shrink: 0;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.theme-switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--secondary);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.drawer-theme-toggle[aria-checked='true'] .theme-switch {
  background: color-mix(in srgb, var(--brand) 22%, transparent);
  border-color: var(--brand);
}

.drawer-theme-toggle[aria-checked='true'] .theme-switch-knob {
  transform: translateX(18px);
  background: var(--brand);
}

.drawer-theme-toggle .grow {
  min-width: 0;
}

/* ---------- tabbar: три иконки с подписями (компактно на телефоне) ---------- */

.tabbar {
  height: var(--tabbar-space);
  padding: 2px 8px calc(2px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.06);
  transition: transform var(--t-med) var(--ease), opacity var(--t-fast) var(--ease);
}

.tabbar-inner {
  max-width: 560px;
  margin: 0 auto;
  height: 100%;
  align-items: stretch;
  gap: 2px;
}

.tabbar-item {
  height: 46px;
  min-height: 46px;
  padding: 1px 2px 2px;
  gap: 0;
  justify-content: center;
  border-radius: 12px;
  font-size: 9.5px;
  color: var(--secondary);
  -webkit-tap-highlight-color: transparent;
}

.tabbar-ico {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
}

.tabbar-ico svg {
  display: block;
  width: 21px;
  height: 21px;
}

.tabbar-label {
  font-size: 9.5px;
  line-height: 1.05;
  letter-spacing: 0.01em;
}

.tabbar-item.active {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
}

.tabbar-item:active {
  background: var(--surface-2);
}

.tabbar-item.active:active {
  background: color-mix(in srgb, var(--brand) 18%, transparent);
}

.tabbar-badge {
  position: absolute;
  top: -4px;
  right: -8px;
  left: auto;
  margin: 0;
  min-width: 15px;
  height: 15px;
  border-radius: 8px;
  border: 2px solid var(--bg);
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  box-sizing: content-box;
}

/* Клавиатура открыта — нижнее меню прячется, чтобы не закрывать поля. */
body.keyboard-open .tabbar {
  transform: translateY(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
}

/* ---------- место под таббар на всех страницах ---------- */

@media (max-width: 860px) {
  .page-home,
  .page-shell,
  .page-fixed,
  .admin-shell {
    height: calc(100dvh - var(--tabbar-space));
    min-height: 0;
  }

  .page-scroll {
    height: calc(100dvh - var(--tabbar-space));
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .center-screen {
    min-height: calc(100dvh - var(--tabbar-space));
  }

  .page-fixed-inner {
    padding-bottom: 20px;
  }

  /* Уведомление вплотную к нижнему меню (пункт 1): без лишней полосы.
     safe-area уже входит в --tabbar-space. */
  .toast-wrap {
    bottom: var(--tabbar-space, 58px);
  }

  body.keyboard-open .toast-wrap {
    bottom: 8px;
  }

  body.is-staff .toast-wrap {
    bottom: 16px;
  }

  /* Горизонтальные отступы страниц остаются «жидкими», но плотнее на телефоне. */
  .page-shell .shell-head {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 430px) {
  .page-fixed-inner {
    padding-left: 12px;
    padding-right: 12px;
  }

  .page-scroll .content {
    padding-left: 14px;
    padding-right: 14px;
  }
}

/* ============================================================
   task-7 (2026-11-28): общий shell — staff без нижнего меню,
   иконки в drawer, скрытие шапки/меню при фокусе на форме.
   ============================================================ */

/* Сотрудникам (модератор/суперадмин) нижняя панель не нужна ни на какой
   ширине (пункты 20–22): своё меню у них в шапке/админке. */
.tabbar.tabbar--staff {
  display: none !important;
}

/* Место под нижнее меню сотрудникам не резервируем: страницы и админский
   сайдбар получают полную высоту. */
body.is-staff {
  --tabbar-space: 0px;
}

body.is-staff .toast-wrap {
  bottom: 16px;
}

/* ---------- Иконки в боковом меню (пункт 13) ---------- */

.drawer .dropdown-item {
  min-height: 42px;
  gap: 10px;
}

.drawer .drawer-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  flex-shrink: 0;
  color: var(--secondary);
}

.drawer .drawer-ico svg {
  display: block;
}

.drawer .dropdown-item.danger .drawer-ico {
  color: inherit;
}

.drawer .dropdown-item .grow {
  min-width: 0;
}

.drawer .drawer-item.drawer-theme-toggle .drawer-theme-ico {
  width: 20px;
}

/* ---------- Фокус на полях (пункт 18): шапка и меню прячутся ---------- */

@media (max-width: 860px) {
  .header {
    transition: transform var(--t-med) var(--ease), opacity var(--t-fast) var(--ease);
  }

  .tabbar {
    transition: transform var(--t-med) var(--ease), opacity var(--t-fast) var(--ease);
  }

  .page-home {
    transition: padding-top var(--t-med) var(--ease);
  }

  body.form-focus .header {
    transform: translateY(-102%);
    opacity: 0;
    pointer-events: none;
  }

  body.form-focus .tabbar {
    transform: translateY(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
  }

  /* Контент главной поднимается на освободившееся место — поиск остаётся
     у верхнего края, без пустой полосы под скрытой шапкой. */
  body.form-focus .page-home {
    padding-top: 0;
  }

  body.form-focus .home-center {
    padding-top: 6px;
  }
}
