/* ============ База: сброс, типографика, каркас приложения ============ */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--head-h) + 12px); background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs-md);
  line-height: var(--lh); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga", "calt";
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent-strong); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; display: block; }
svg { display: block; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sr-only:focus { position: fixed !important; top: 8px; left: 8px; width: auto; height: auto; clip: auto; z-index: var(--z-toast); padding: 8px 14px; border-radius: var(--r-full); background: var(--btn-bg); color: var(--btn-fg); }
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 18px; height: 18px; stroke-width: 1.7; }
.icon.xs { width: 15px; height: 15px; stroke-width: 1.8; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.row { display: flex; align-items: center; gap: var(--s2); }
.row.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: var(--s3); grid-template-columns: minmax(0, 1fr); }
.spacer { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.center { text-align: center; }
.mono { font-family: var(--font-mono); font-size: .92em; }
/* Подпись капителью — фирменный приём для заголовков разделов */
.caps { font-size: 11px; font-weight: 600; letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--muted); }
/* Антиква — заголовки страниц, имена в шапках, крупные числа */
.display { font-family: var(--font-display); font-weight: 400; letter-spacing: -.005em; }

/* ------------------------------ Каркас ------------------------------ */
/* Бумага, на ней — один лист (колонка содержимого) с тонкими краями. Слева — навигация,
   справа — рекомендации; обе лежат прямо на бумаге, без карточек.
   Планшет: рельс из значков | лист. Телефон: лист во весь экран + панели сверху и снизу. */
.shell {
  max-width: calc(var(--nav-w) + var(--main-w) + var(--aside-w) + 2 * 28px + 48px); margin: 0 auto; padding: 0 24px;
  display: grid; column-gap: 28px; align-items: start;
  grid-template-columns: var(--nav-w) minmax(0, var(--main-w)) var(--aside-w);
  grid-template-areas: "nav main aside";
}
.shell.wide { grid-template-columns: var(--nav-w) minmax(0, 1fr); grid-template-areas: "nav main"; max-width: var(--shell-wide-w); }
.shell > * { min-width: 0; }
.main {
  grid-area: main; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; align-content: start;
  min-height: 100vh; min-height: 100dvh; background: var(--surface);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line); padding-bottom: 64px;
  animation: sheet-in var(--t-slow) var(--ease-out) both;
}
.main:focus { outline: none; }
/* На широких страницах (настройки, сообщения, админка) лист — с полями внутри */
.shell.wide .main { padding: 0 28px 40px; gap: var(--s4); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(6px); } }
.aside { grid-area: aside; position: sticky; top: 0; display: grid; gap: var(--s8); padding: 18px 0 32px; max-height: 100vh; overflow-y: auto; scrollbar-width: none; }
.aside::-webkit-scrollbar { display: none; }
.topbar, .tabbar { display: none; }

/* Навигация: текст и значок; выбранный раздел — чернилами, с ромбом-«запонкой» слева */
/* Панель — отдельная скруглённая карточка в тонкой рамке, с отступом от краёв экрана */
.sidenav {
  grid-area: nav; position: sticky; top: 12px; height: calc(100vh - 24px); height: calc(100dvh - 24px); margin: 12px 0; display: flex; flex-direction: column; gap: 2px;
  padding: 16px 10px; overflow-y: auto; scrollbar-width: none;
  border: 1px solid var(--line-strong); border-radius: 22px; background: color-mix(in srgb, var(--surface) 65%, var(--bg));
  box-shadow: 0 18px 40px -30px rgba(0, 0, 0, .55);
}
.sidenav::-webkit-scrollbar { display: none; }
.nav-links { display: grid; gap: 1px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 14px 22px; color: var(--text); }
.brand:hover { color: var(--text); }
.brand .logo { width: 36px; height: 36px; flex: none; transition: transform var(--t) var(--ease); }
.brand:hover .logo { transform: rotate(-6deg); }
.brand .logo svg { width: 100%; height: 100%; }
.brand b { font-family: var(--font-display); font-weight: 400; font-size: 26px; letter-spacing: -.01em; line-height: 1; }
.navlink {
  position: relative; display: flex; align-items: center; gap: 14px; height: 44px; padding: 0 14px; border-radius: var(--r-full);
  color: var(--text-2); font-weight: 500; font-size: var(--fs-md); background: none; border: 0; width: 100%; text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}
.navlink:hover { background: color-mix(in srgb, var(--text) 5%, transparent); color: var(--text); }
.navlink[aria-current="page"] { color: var(--text); font-weight: 650; }
.navlink[aria-current="page"] .icon { stroke-width: 2.1; }
.navlink[aria-current="page"]::before {
  content: ""; position: absolute; left: -3px; top: 50%; width: 7px; height: 7px; background: var(--accent);
  transform: translateY(-50%) rotate(45deg); border-radius: 1.5px; animation: pin-in var(--t) var(--ease-out);
}
@keyframes pin-in { from { transform: translateY(-50%) rotate(45deg) scale(0); } }
.navlink .count {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-full);
  background: var(--like); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.navlink .count:empty { display: none; }
.nav-sep { height: 1px; background: var(--line); margin: 8px 14px; }
.nav-cta { margin-top: 18px; }
.nav-account {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--r-full);
  background: none; color: var(--text); text-align: left; transition: background var(--t-fast);
}
.nav-account:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.nav-account .who { flex: 1; min-width: 0; display: grid; line-height: 1.25; }
.nav-account .who b { font-weight: 600; font-size: var(--fs-sm); }
.nav-account .who span { font-size: var(--fs-xs); color: var(--muted); }
.nav-account > .icon { color: var(--muted); }

/* Планшет: навигация — рельс из значков, правая колонка скрыта */
@media (max-width: 1199px) {
  .shell { grid-template-columns: var(--rail-w) minmax(0, var(--main-w)); grid-template-areas: "nav main"; column-gap: 20px; max-width: calc(var(--rail-w) + var(--main-w) + 20px + 48px); }
  .shell.wide { grid-template-columns: var(--rail-w) minmax(0, 1fr); max-width: 1180px; }
  .shell.wide .main { padding: 0 20px 32px; }
  .aside { display: none; }
  .sidenav { align-items: center; padding: 14px 0; }
  .brand { padding: 4px 0 18px; }
  .brand b, .navlink span, .nav-cta span, .nav-account .who, .nav-account > .icon { display: none; }
  .navlink { justify-content: center; padding: 0; width: 48px; height: 48px; }
  .navlink[aria-current="page"]::before { left: -9px; }
  .navlink .count { position: absolute; top: 5px; right: 3px; min-width: 18px; height: 18px; font-size: 10.5px; padding: 0 5px; }
  .nav-cta { width: 48px; height: 48px; padding: 0; border-radius: 50%; }
  .nav-account { width: auto; padding: 6px; border-radius: 50%; }
}
/* Кнопка «раскрыть / скрыть панель» — в шапке панели рядом с логотипом */
.nav-head { display: flex; align-items: flex-start; gap: 4px; }
.nav-head .brand { flex: 1; min-width: 0; }
.nav-toggle {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px; margin: 4px 4px 0 0; border: 0; border-radius: 50%;
  background: none; color: var(--muted); transition: background var(--t-fast), color var(--t-fast), transform var(--t) var(--ease);
}
.nav-toggle:hover { background: color-mix(in srgb, var(--text) 6%, transparent); color: var(--text); }
.nav-toggle[aria-expanded="true"] .icon { transform: scaleX(-1); }
@media (max-width: 1199px) {
  .nav-head { flex-direction: column; align-items: center; gap: 0; }
  .nav-toggle { margin: -6px 0 10px; }
}
/* Широкий экран, панель свёрнута: тот же рельс из значков, что на планшете */
@media (min-width: 1200px) {
  html.nav-rail .shell { grid-template-columns: var(--rail-w) minmax(0, var(--main-w)) var(--aside-w); max-width: calc(var(--rail-w) + var(--main-w) + var(--aside-w) + 2 * 28px + 48px); }
  html.nav-rail .shell.wide { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  html.nav-rail .sidenav { align-items: center; padding: 14px 0; }
  html.nav-rail .nav-head { flex-direction: column; align-items: center; gap: 0; }
  html.nav-rail .nav-toggle { margin: -6px 0 10px; }
  html.nav-rail .brand { padding: 4px 0 18px; }
  html.nav-rail .brand b, html.nav-rail .navlink span, html.nav-rail .nav-cta span, html.nav-rail .nav-account .who, html.nav-rail .nav-account > .icon { display: none; }
  html.nav-rail .navlink { justify-content: center; padding: 0; width: 48px; height: 48px; }
  html.nav-rail .navlink[aria-current="page"]::before { left: -9px; }
  html.nav-rail .navlink .count { position: absolute; top: 5px; right: 3px; min-width: 18px; height: 18px; font-size: 10.5px; padding: 0 5px; }
  html.nav-rail .nav-cta { width: 48px; height: 48px; padding: 0; border-radius: 50%; }
  html.nav-rail .nav-account { width: auto; padding: 6px; border-radius: 50%; }
}
/* Планшет, панель раскрыта: полная панель с подписями поверх страницы */
@media (min-width: 760px) and (max-width: 1199px) {
  html.nav-open .sidenav {
    position: fixed; left: 12px; top: 12px; bottom: 12px; z-index: calc(var(--z-nav) + 2); width: var(--nav-w); height: auto; margin: 0;
    align-items: stretch; padding: 14px 12px; background: var(--surface); box-shadow: 24px 0 60px -20px rgba(0, 0, 0, .55);
    animation: nav-slide .22s var(--ease-out);
  }
  html.nav-open::after { content: ""; position: fixed; inset: 0; z-index: calc(var(--z-nav) + 1); background: var(--overlay); animation: fade var(--t); }
  html.nav-open .nav-head { flex-direction: row; align-items: flex-start; gap: 4px; }
  html.nav-open .nav-toggle { margin: 4px 0 0; }
  html.nav-open .brand { padding: 4px 14px 22px; }
  html.nav-open .brand b, html.nav-open .navlink span, html.nav-open .nav-cta span, html.nav-open .nav-account > .icon { display: inline; }
  html.nav-open .nav-account .who { display: grid; }
  html.nav-open .navlink { justify-content: flex-start; padding: 0 14px; width: 100%; height: 44px; }
  html.nav-open .navlink[aria-current="page"]::before { left: -3px; }
  html.nav-open .navlink .count { position: static; margin-left: auto; min-width: 20px; height: 20px; font-size: 11px; padding: 0 6px; }
  html.nav-open .nav-cta { width: 100%; height: auto; padding: 0 18px; border-radius: var(--r-full); }
  html.nav-open .nav-account { width: 100%; padding: 8px 10px; border-radius: var(--r-full); }
}
@keyframes nav-slide { from { transform: translateX(-24px); opacity: 0; } }
/* Телефон: лист — весь экран */
@media (max-width: 759px) {
  body, html { background: var(--surface); }
  .shell, .shell.wide { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main"; padding: 0 0 calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); gap: 0; max-width: none; }
  .main, .shell.wide .main { border: 0; padding: 0 0 16px; min-height: 0; }
  .shell.wide .main { padding: 0 16px 16px; }
  .sidenav { display: none; }
  .topbar {
    display: flex; position: sticky; top: 0; z-index: var(--z-nav); align-items: center; gap: var(--s2); height: calc(54px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
    background: var(--glass); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .hide-mobile { display: none !important; }
  .topbar .brand { padding: 0; }
  .topbar .brand .logo { width: 30px; height: 30px; }
  .topbar .brand b { font-size: 23px; display: inline; }
  .topbar-acct { width: 40px; height: 40px; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav);
    justify-content: space-around; align-items: center; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 0 max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
    background: var(--glass); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    position: relative; flex: 1; display: grid; place-items: center; height: 100%; max-width: 88px; color: var(--muted); background: none; border: 0;
    -webkit-tap-highlight-color: transparent; transition: color var(--t-fast);
  }
  .tabbar .icon { width: 25px; height: 25px; }
  .tabbar [aria-current="page"] { color: var(--text); }
  .tabbar [aria-current="page"] .icon { stroke-width: 2.1; }
  .tabbar [aria-current="page"]::after { content: ""; position: absolute; bottom: 8px; width: 5px; height: 5px; background: var(--accent); transform: rotate(45deg); border-radius: 1px; }
  .tabbar .fab { flex: none; width: 50px; height: 38px; max-width: none; border-radius: var(--r-full); background: var(--btn-bg); color: var(--btn-fg); transition: transform var(--t-fast) var(--ease); }
  .tabbar .fab:active { transform: scale(.94); }
  .tabbar .fab .icon { width: 21px; height: 21px; stroke-width: 2.2; }
  .tabbar .count { position: absolute; top: 8px; left: calc(50% + 5px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 99px; background: var(--like); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface); }
  .tabbar .count:empty { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Страницы без навигации (вход, регистрация) — лист на бумаге */
.auth-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: max(28px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom)); }
.auth-card { width: 100%; max-width: var(--panel-w-sm); animation: sheet-in var(--t-slow) var(--ease-out) both; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: var(--s6); text-align: center; }
.auth-brand p { max-width: 32ch; }
.auth-brand .logo { width: 56px; height: 56px; color: var(--text); margin-bottom: 6px; }
.auth-brand h1 { font-family: var(--font-display); font-weight: 400; font-size: var(--fs-3xl); letter-spacing: -.01em; line-height: 1.1; }
.auth-card a:not(.btn) { color: var(--accent-strong); font-weight: 600; }
@media (max-width: 759px) { .auth-brand h1 { font-size: var(--fs-2xl); } }

/* ===== Экран первой загрузки (#pj-boot, вставляет сервер; показ решает theme-init.js) =====
   Только при первом заходе / после обновления сайта и только если загрузка дольше ~0,35 с. */
#pj-boot { display: none; }
html[data-boot] #pj-boot {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-content: center; justify-items: center; gap: 18px;
  padding: 24px; background: var(--bg); color: var(--text); text-align: center;
  opacity: 0; animation: pj-boot-in .3s var(--ease-out) .35s forwards;
}
.pj-boot-logo {
  width: 64px; height: 47px; background: var(--text); animation: pj-boot-breathe 1.6s ease-in-out infinite;
  -webkit-mask: url(/assets/img/logo.svg) center / contain no-repeat; mask: url(/assets/img/logo.svg) center / contain no-repeat;
}
#pj-boot p { display: none; max-width: 32ch; margin: 0; }
html[data-boot="first"] #pj-boot p.first, html[data-boot="update"] #pj-boot p.update { display: grid; gap: 6px; }
#pj-boot b { font-family: var(--font-display); font-weight: 400; font-size: var(--fs-xl); letter-spacing: -.01em; }
#pj-boot span { color: var(--muted); font-size: var(--fs-sm); line-height: 1.45; }
.pj-boot-bar { position: relative; display: block; width: 140px; height: 3px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.pj-boot-bar i { position: absolute; inset: 0 auto 0 0; width: 40%; border-radius: inherit; background: var(--accent); animation: pj-boot-run 1.1s var(--ease) infinite; }
@keyframes pj-boot-in { to { opacity: 1; } }
@keyframes pj-boot-breathe { 50% { transform: scale(.94); opacity: .8; } }
@keyframes pj-boot-run { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) { .pj-boot-logo, .pj-boot-bar i { animation: none; } html[data-boot] #pj-boot { animation-duration: .01s; } }

/* Мобильное приложение (mobile/, класс ставит core/app.js): на планшете страница начинается под строкой
   состояния — на телефоне это уже делают верхняя и нижняя панели (env(safe-area-inset-*)). */
@media (min-width: 760px) { html.pj-native body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); } }
html.pj-native { -webkit-tap-highlight-color: transparent; }
