/* Оболочка установленного приложения (static/js/app_shell.js, разметка —
   templates/_app_shell.html): нижняя панель вкладок, лист «Ещё», плашки и
   подсказки. В обычном браузере на компьютере всё это скрыто — виден только
   неприметный кусок: кнопка «Установить» в меню телефона, когда браузер её
   разрешил. Панель включается классом body.has-tabbar (приложение, ширина до
   820px, вошёл) и CSS-переменной --tabbar-h (её высота) — по ним закреплённые
   снизу элементы встают над панелью. Цвета — токены style.css (светлая и тёмная тема). */

.app-tabbar, .app-sheet, .app-sheet-backdrop, .app-section { display: none; }
[data-install][hidden] { display: none !important; }

/* ---- Плашки «Нет связи» и «Доступна новая версия» (создаёт app_shell.js) ---- */
.app-notices {
  position: fixed; left: 0; right: 0; bottom: var(--tabbar-h, 0px); z-index: 95;
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  padding: 0 0.75rem calc(0.6rem + env(safe-area-inset-bottom, 0px)); pointer-events: none;
}
body.has-tabbar .app-notices { padding-bottom: 0.6rem; }
body.has-pick-bar .app-notices { bottom: calc(var(--tabbar-h, 0px) + 5rem); }
.app-notice {
  pointer-events: auto; display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  max-width: 34rem; width: 100%; min-height: 44px; padding: 0.35rem 0.5rem 0.35rem 1rem;
  border-radius: var(--radius-md); font-size: 0.9rem; line-height: 1.3;
  background: var(--brand-primary); color: var(--text-on-brand);
  box-shadow: 0 6px 22px rgba(20, 33, 58, 0.22);
}
.app-notice[hidden] { display: none; }
.app-notice-offline {
  background: color-mix(in srgb, var(--warning-bg) 70%, var(--surface)); color: var(--warning);
  border: 1px solid var(--warning-border); padding-right: 1rem; box-shadow: none;
}
.app-notice > span { flex: 1 1 auto; }
.app-notice-btn {
  flex: 0 0 auto; min-height: 40px; padding: 0 1rem; border: 0; border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-weight: 650; background: color-mix(in srgb, var(--text-on-brand) 18%, transparent); color: var(--text-on-brand);
}
.app-notice-btn:hover { background: color-mix(in srgb, var(--text-on-brand) 28%, transparent); }
.app-notice-btn:focus-visible, .app-tab:focus-visible, .app-sheet-item:focus-visible, .app-sheet-x:focus-visible {
  outline: 2px solid var(--brand-accent); outline-offset: 2px;
}
.app-notice-btn:focus-visible { outline-color: var(--text-on-brand); }

/* ---- «Установить» в обычном меню телефона ---- */
.nav-install { display: none; }
@media (max-width: 820px) {
  .nav-install {
    display: inline-flex; align-items: center; flex: 0 0 auto; min-height: 2.5rem; padding: 0.45rem 0.85rem;
    border: 1px solid var(--accent-soft-border); border-radius: 999px; cursor: pointer; white-space: nowrap;
    font: inherit; font-weight: 500; font-size: 0.92rem; background: var(--accent-soft); color: var(--brand-accent);
  }
  .nav-install:hover { background: var(--surface-alt); }
  .nav-install:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 2px; }
}

/* ---- Подсказка «Поделиться → На экран Домой» (iPhone) ---- */
.app-snack {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h, 0px) + 1rem + env(safe-area-inset-bottom, 0px)); z-index: 130;
  max-width: min(92vw, 26rem); padding: 0.75rem 1.1rem; border-radius: var(--radius-md); font-size: 0.92rem; line-height: 1.35; text-align: center;
  background: var(--brand-primary); color: var(--text-on-brand); box-shadow: 0 8px 26px rgba(20, 33, 58, 0.28);
  opacity: 0; transform: translate(-50%, 0.5rem); pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease;
}
.app-snack.is-on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
body.has-tabbar .app-snack { bottom: calc(var(--tabbar-h, 0px) + 1rem); }

/* ---- Режим приложения на телефоне ---- */
@media (max-width: 820px) {
  html.wm-app a, html.wm-app button { -webkit-tap-highlight-color: transparent; }

  /* шапка: только логотип и название раздела; меню, имя, «Выйти» и тема — во вкладках и листе «Ещё» */
  html.wm-app .topbar { padding-top: env(safe-area-inset-top, 0px); }
  html.wm-app .topbar-inner:has(.app-section) {
    flex-wrap: nowrap; gap: 0.7rem; padding: 0.45rem 1rem;
    padding-left: max(1rem, env(safe-area-inset-left, 0px)); padding-right: max(1rem, env(safe-area-inset-right, 0px));
  }
  html.wm-app .topbar-inner:has(.app-section) .brand-text,
  html.wm-app .topbar-inner:has(.app-section) .nav-links,
  html.wm-app .topbar-inner:has(.app-section) .user-chip,
  html.wm-app .topbar-inner:has(.app-section) .theme-toggle { display: none; }
  html.wm-app .app-section {
    display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-family: var(--font-heading); font-weight: 650; font-size: 1.08rem; letter-spacing: -0.02em; color: var(--ink);
  }
  html.wm-app .site-footer { display: none; }

  body.has-tabbar { padding-bottom: var(--tabbar-h, 0px); }
  body.has-tabbar.has-pick-bar { padding-bottom: calc(var(--tabbar-h, 0px) + 5rem); }
  body.has-tabbar .pick-bar { bottom: var(--tabbar-h, 0px); padding-bottom: 0.6rem; }
  body.has-tabbar .wm-toast { bottom: calc(var(--tabbar-h, 0px) + 1rem); }
  body.has-tabbar.has-pick-bar .wm-toast { bottom: calc(var(--tabbar-h, 0px) + 5.5rem); }
  body.app-sheet-open { overflow: hidden; }

  /* нижняя панель */
  body.has-tabbar .app-tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .app-tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 56px; min-width: 44px; padding: 4px 2px 5px; border: 0; background: none; cursor: pointer;
    font: inherit; font-size: 0.72rem; font-weight: 600; line-height: 1.15; text-decoration: none;
    color: var(--text-muted);
  }
  .app-tab:hover { text-decoration: none; color: var(--ink); }
  .app-tab-ico {
    position: relative; display: flex; align-items: center; justify-content: center;
    width: 54px; height: 30px; border-radius: 15px; transition: background 0.15s ease;
  }
  .app-ico { width: 24px; height: 24px; }
  .app-tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-tab.is-active { color: var(--brand-accent); }
  .app-tab.is-active .app-tab-ico { background: var(--accent-soft); }
  .app-tab:active .app-tab-ico { background: var(--surface-alt); }
  .app-tab-badge {
    position: absolute; top: -3px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px; background: var(--brand-accent); color: #fff; box-sizing: border-box;
    font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  }
  .app-tab-badge[hidden] { display: none; }

  /* лист «Ещё» снизу */
  body.has-tabbar .app-sheet-backdrop {
    display: block; position: fixed; inset: 0; z-index: 110; background: rgba(8, 12, 20, 0.5);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  body.has-tabbar .app-sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }
  body.has-tabbar .app-sheet {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
    max-height: 85vh; max-height: 85dvh; overflow-y: auto; overscroll-behavior: contain;
    padding: 1.1rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border-top: 1px solid var(--border-strong);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: 0 -14px 36px rgba(0, 0, 0, 0.22);
    transform: translateY(105%); visibility: hidden; transition: transform 0.24s ease, visibility 0s linear 0.24s;
  }
  body.has-tabbar .app-sheet.is-open { transform: translateY(0); visibility: visible; transition: transform 0.24s ease, visibility 0s; }
  .app-sheet::before {
    content: ""; position: absolute; top: 0.45rem; left: 50%; width: 36px; height: 4px; margin-left: -18px;
    border-radius: 2px; background: var(--border-strong);
  }
  .app-sheet-head { display: flex; align-items: center; gap: 0.75rem; padding: 0.25rem 0.25rem 0.75rem; border-bottom: 1px solid var(--border); margin-bottom: 0.4rem; }
  .app-sheet-head .avatar {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    background: var(--brand-accent); color: #fff; font-weight: 650;
  }
  .app-sheet-who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
  .app-sheet-who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
  .app-sheet-who small { color: var(--text-muted); font-size: 0.8rem; }
  .app-sheet-x {
    flex: 0 0 auto; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: 50%; background: none; color: var(--text-secondary); cursor: pointer;
  }
  .app-sheet-x:hover { background: var(--surface-alt); }
  .app-sheet-list { display: flex; flex-direction: column; padding-bottom: 0.4rem; margin-bottom: 0.4rem; border-bottom: 1px solid var(--border); }
  .app-sheet-item {
    display: flex; align-items: center; gap: 0.85rem; width: 100%; min-height: 48px; padding: 0 0.6rem;
    border: 0; border-radius: var(--radius-md); background: none; cursor: pointer; text-align: left; text-decoration: none;
    font: inherit; font-size: 1rem; color: var(--ink);
  }
  .app-sheet-item:hover { background: var(--surface-alt); text-decoration: none; }
  .app-sheet-item.is-active { background: var(--accent-soft); color: var(--brand-accent); font-weight: 600; }
  .app-sheet-item > span:not(.app-tab-badge) { flex: 1 1 auto; }
  .app-sheet-item .app-ico { flex: 0 0 auto; color: var(--text-secondary); }
  .app-sheet-item.is-active .app-ico { color: var(--brand-accent); }
  .app-sheet-item .app-tab-badge { position: static; }
  .app-sheet-logout, .app-sheet-logout .app-ico { color: var(--danger); }
  .app-sheet-row {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 52px; padding: 0 0.6rem;
    color: var(--ink);
  }
  .app-sheet-row .theme-toggle { width: 44px; height: 44px; }
  .app-sheet-row .theme-toggle svg { width: 20px; height: 20px; }
}

@media (hover: none) {
  .app-tab:hover { color: var(--text-muted); }
  .app-tab.is-active:hover { color: var(--brand-accent); }
}
@media (prefers-reduced-motion: reduce) {
  .app-tab-ico, .app-snack, .app-sheet-backdrop,
  body.has-tabbar .app-sheet, body.has-tabbar .app-sheet.is-open, body.has-tabbar .app-sheet-backdrop { transition: none; }
}
