/* ============================================================
   Травиночка — база: сброс, типографика, каркас, сцена (v0.14)
   ============================================================ */

*,
*::before,
*::after { box-sizing: border-box; }

html { height: 100%; }

/* Плавные переходы между страницами (MPA, прогрессивное улучшение) */
@view-transition { navigation: auto; }

body.app {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: var(--lh-tight); }

h1, h2, h3, .brand__name, .page-head__title, .chat__title {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1, h2 { text-wrap: balance; }
p { text-wrap: pretty; }

a { color: var(--text-link); text-decoration: none; }
a:hover { color: var(--text-primary); }

img { max-width: 100%; }

hr { border: 0; border-top: 1px solid var(--border); }

/* --- Утилиты --- */

.sr-only {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: var(--sp-3); top: -48px; z-index: var(--z-skip);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-sm);
  background: var(--bg-accent); color: var(--text-primary);
  transition: top var(--transition-fast);
}
.skip-link:focus { top: var(--sp-3); }

.u-container {
  width: 100%;
  max-width: var(--content-w);
  margin-inline: auto;
  padding-inline: var(--sp-6);
}

/* --- Доступность и отклик --- */

:focus-visible {
  outline: 2px solid var(--grass-300);
  outline-offset: 2px;
  box-shadow: var(--glow-focus);
}

::selection {
  background: oklch(0.65 0.115 148 / 0.4);
  color: var(--moon-50);
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
summary:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   Ночная сцена: звёзды, светлячки, луна.
   Примитивы для лендинга и auth-страниц; сами элементы —
   декорация, не перехватывают события и скрыты от скринридеров.
   ============================================================ */

.scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

.scene__star {
  position: absolute;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: var(--moon-100);
  opacity: 0.6;
  animation: scene-twinkle var(--dur, 4.5s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.scene__firefly {
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--firefly-300);
  box-shadow:
    0 0 6px 1px var(--firefly-glow),
    0 0 18px 4px var(--firefly-glow-soft);
  opacity: 0;
  animation:
    scene-drift var(--dur, 16s) ease-in-out infinite alternate,
    scene-pulse calc(var(--dur, 16s) / 3) ease-in-out infinite;
  animation-delay: var(--delay, 0s), var(--delay, 0s);
}

@keyframes scene-twinkle {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.12; }
}

@keyframes scene-drift {
  from { translate: 0 0; }
  to { translate: var(--dx, 42px) var(--dy, -28px); }
}

@keyframes scene-pulse {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
  .scene__star { animation: none; opacity: 0.4; }
  .scene__firefly { animation: none; opacity: 0.5; }
}

/* --- Появление при прокрутке (только где поддерживается) --- */

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .reveal {
      animation: scene-reveal linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 58%;
    }
  }
}

@keyframes scene-reveal {
  from { opacity: 0; translate: 0 26px; }
  to { opacity: 1; translate: 0 0; }
}

/* ============================================================
   Каркас приложения
   ============================================================ */

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden; /* скролл только у .main — сайдбар не «плывёт» */
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto; /* профиль и длинные страницы скроллятся здесь */
}

/* --- Сайдбар --- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-3);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  position: relative;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar__head { display: flex; align-items: center; justify-content: space-between; padding: 2px var(--sp-2) var(--sp-3); }

.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand__name { font-size: var(--fs-lg); font-weight: 650; letter-spacing: 0.2px; color: var(--text-primary); }
.brand__mark { display: block; filter: drop-shadow(0 2px 6px oklch(0 0 0 / 0.35)); }

.nav__caption {
  margin: var(--sp-4) 10px var(--sp-1);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-muted);
}

.nav__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }

.nav__item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: var(--sp-2) 10px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: var(--fs-md);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav__item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav__item.is-active { background: var(--bg-accent-subtle); color: var(--text-primary); }
.nav__item--button {
  border: 0; background: none; cursor: pointer; text-align: left;
  font: inherit; color: var(--text-muted);
}
.nav__item--button:hover { color: var(--text-primary); }
.nav__item .icon { flex: 0 0 auto; color: currentColor; opacity: 0.75; }
.nav__text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav__badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--bg-accent); color: var(--moon-50);
  font-size: 11px; font-weight: 650;
}
.nav__badge.is-empty { display: none; }

.sidebar__foot {
  margin-top: auto; padding: var(--sp-3) 10px 2px;
  font-size: var(--fs-xs); color: var(--text-muted); opacity: 0.8;
}

.nav-toggle, .nav-close {
  display: none; align-items: center; justify-content: center;
  width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg-raised); color: var(--text-primary);
  cursor: pointer;
}

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: var(--z-backdrop);
  background: oklch(0.08 0.015 170 / 0.62);
  backdrop-filter: blur(2px);
}

/* --- Панель участников --- */

.chat-layout { display: flex; flex: 1; min-height: 0; }

.members {
  width: var(--members-w);
  flex: 0 0 var(--members-w);
  padding: var(--sp-4) var(--sp-3);
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: none;
}

.members__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.members__list li { display: flex; align-items: center; }
.members__list li .member { flex: 1; min-width: 0; }

.members__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: 2px var(--sp-2) var(--sp-3);
}
.members__head .nav__caption { margin: 0; flex: 1 1 auto; min-width: 0; }
.members__close { display: none; }

/* Затемнение под панелью участников (только мобильный) */
.members-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: calc(var(--z-members) - 1);
  background: oklch(0.08 0.015 170 / 0.62);
  backdrop-filter: blur(2px);
}

.member {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: var(--fs-md);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.member:hover { background: var(--bg-hover); color: var(--text-primary); }
.member__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member__dm {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border-radius: var(--r-xs);
  color: var(--text-muted);
}
.member__dm:hover { color: var(--text-link); background: var(--bg-accent-subtle); }
.member__dot {
  width: 8px; height: 8px; flex: 0 0 auto;
  border-radius: 50%; background: var(--ok-500);
  box-shadow: 0 0 0 3px oklch(0.73 0.12 155 / 0.15);
}

.members-toggle { display: inline-flex; }

@media (min-width: 861px) {
  .app.room-page.members-open .members,
  .app.has-members.members-open .members {
    display: block;
  }
}

/* --- Скроллбары --- */

.chat__log::-webkit-scrollbar, .sidebar::-webkit-scrollbar,
.room-grid::-webkit-scrollbar { width: 10px; }

.chat__log::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb,
.room-grid::-webkit-scrollbar-thumb {
  background: var(--moss-800); border-radius: 8px;
  border: 2px solid var(--night-900);
}

.chat__log::-webkit-scrollbar-track, .sidebar::-webkit-scrollbar-track,
.room-grid::-webkit-scrollbar-track { background: transparent; }

/* --- Заголовки страниц --- */

.page-head { padding: var(--sp-5) var(--sp-6) var(--sp-2); }
.page-head__title { margin: 0 0 2px; font-size: var(--fs-xl); font-weight: 650; }
.page-head__sub { margin: 0; color: var(--text-muted); font-size: var(--fs-md); }

.empty-note { padding: var(--sp-6); color: var(--text-muted); }

/* --- Адаптив каркаса --- */

@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: var(--z-sidebar);
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform var(--transition-med);
    box-shadow: none;
  }
  .app.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-2); }
  .app.nav-open .sidebar-backdrop { display: block; }

  .nav-toggle { display: inline-flex; position: fixed; z-index: 45; top: 10px; left: 10px; }
  .nav-close { display: inline-flex; }

  .members {
    position: fixed; z-index: var(--z-members);
    inset: 0 0 0 auto;
    width: min(300px, 84vw); flex-basis: auto;
    transform: translateX(100%);
    transition: transform var(--transition-med);
    box-shadow: none;
    padding-top: max(var(--sp-4), var(--safe-top));
  }
  .app.members-open .members {
    display: block;
    transform: translateX(0);
    z-index: var(--z-members);
    box-shadow: var(--shadow-2);
  }
  .app.members-open .members-backdrop { display: block; }
  .members__close { display: inline-flex; }
  .members-toggle { display: inline-flex; }

  /* body.app — выше специфичность, чем .page-head из components.css (v0.13),
     иначе заголовки страниц залезают под fixed-гамбургер (top 10 + 44px). */
  body.app .page-head { padding-top: 62px; }
  .chat__head { padding-left: 60px; }
}

/* Safe areas для телефонов с вырезами */
body.app {
  padding-bottom: var(--safe-bottom);
}
