/* ════════════════════════════════════════════════════════════════════
   Asadram — база и оболочка
   ════════════════════════════════════════════════════════════════════ */

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

* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv01", "cv03", "ss01";
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

/* Мобильный Chrome прячет адресную строку и меняет 100vh на лету —
   нижняя навигация из-за этого прыгала. 100dvh считает реальную
   видимую высоту, поэтому панель стоит там, где должна. */
.app {
  display: grid;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  grid-template-columns: var(--sidebar-width) 1fr;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}
button { cursor: pointer; -webkit-appearance: none; appearance: none; }
button:disabled { cursor: not-allowed; opacity: .5; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { list-style: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection { background: var(--accent-ring); color: var(--fg); }

/* ── Полосы прокрутки ───────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); background-clip: content-box; }

/* ── Утилиты ────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.clamp-2 {
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.row { display: flex; align-items: center; gap: var(--sp-3); }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; min-width: 0; }
.tnum { font-variant-numeric: tabular-nums; }

/* ════════════════════════════════════════════════════════════════════
   Боковая панель
   ════════════════════════════════════════════════════════════════════ */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
  position: relative;
  z-index: var(--z-base);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--head-height);
  padding: 0 var(--sp-3) 0 var(--sp-4);
  padding-top: var(--safe-top);
  flex: none;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
  letter-spacing: -.025em;
  color: var(--fg);
  user-select: none;
}

.search-wrap { flex: none; padding: var(--sp-3) var(--sp-4); }

.search-field {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-3);
  background: var(--bg-input);
  border-radius: var(--r-full);
  transition: box-shadow var(--dur) var(--ease-out);
}
.search-field:focus-within { box-shadow: 0 0 0 2px var(--accent-ring); }
.search-field input { flex: 1; min-width: 0; font-size: var(--text-base); }
.search-field input::placeholder { color: var(--fg-faint); }
.search-field .ico { color: var(--fg-muted); flex: none; }

/* Панели вкладок: держим все в DOM и переключаем видимость.
   Перерисовка с нуля при каждом переходе и давала задержку. */
.panes { position: relative; flex: 1; min-height: 0; }

.pane {
  position: absolute;
  inset: 0;
  will-change: transform;
  visibility: hidden;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + var(--sp-2));
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out);
}
.pane.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Во время проезда соседи видны — но только во время него */
/* Соседей не показываем вовсе: раньше они мелькали при переключении
   и налезали друг на друга. Едет только активная панель. */
.pane {
  transform: translateX(var(--slide, 0));
  transition: transform var(--dur-slow) var(--ease-spring),
              opacity var(--dur) var(--ease-out);
}
.pane:not(.is-active) { transform: none; }

/* ════════════════════════════════════════════════════════════════════
   Нижняя навигация

   Прибита к низу окна, а не к концу содержимого, и учитывает
   «шторку жестов» на iPhone и Android через safe-area-inset-bottom.
   ════════════════════════════════════════════════════════════════════ */
.bottom-nav {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-nav);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--fg-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  position: relative;
  transition: color var(--dur-fast) var(--ease-out);
  text-decoration: none;
}
.nav-item:hover { text-decoration: none; }
.nav-item .ico { transition: transform var(--dur) var(--ease-spring); }
.nav-item.is-active { color: var(--accent); }
.nav-item.is-active .ico { transform: translateY(-1px) scale(1.06); }

.nav-item .badge {
  position: absolute;
  top: 6px;
  left: 50%;
  margin-left: 4px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--rose-500);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg);
}

/* ════════════════════════════════════════════════════════════════════
   Основная область
   ════════════════════════════════════════════════════════════════════ */
.main {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  color: var(--fg-muted);
  text-align: center;
  padding: var(--sp-8);
}
.empty-state .glyph {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  border-radius: var(--r-2xl);
  background: var(--accent-soft);
  color: var(--accent);
}
.empty-state h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--fg);
}
.empty-state p { max-width: 34ch; font-size: var(--text-sm); }

/* ════════════════════════════════════════════════════════════════════
   Телефон
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }

  .sidebar { border-right: none; }

  /* Переписка выезжает поверх списка — как в родных приложениях.
     Раньше это была отдельная страница, отсюда и «мигание». */
  .main {
    position: fixed;
    inset: 0;
    z-index: var(--z-panel);
    transform: translateX(100%);
    transition: transform var(--dur-slow) var(--ease-out);
    will-change: transform;
  }
  .app.chat-open .main { transform: none; }
  .app.chat-open .sidebar { pointer-events: none; }

  .pane { padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + var(--sp-2)); }
}

@media (min-width: 901px) {
  .bottom-nav {
    position: relative;
    height: var(--nav-height);
    padding-bottom: 0;
  }
  .sidebar { display: grid; grid-template-rows: auto auto 1fr auto; }
  .panes { grid-row: 3; }
  .pane { padding-bottom: var(--sp-3); }
}

/* ── Иконки ─────────────────────────────────────────────────────── */
.ico {
  display: inline-block;
  width: 22px;
  height: 22px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ico-sm { width: 17px; height: 17px; }
.ico-lg { width: 28px; height: 28px; }
.ico-fill { fill: currentColor; stroke: none; }

/* ── Загрузка ───────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: var(--r-full);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(
    100deg,
    var(--bg-input) 30%,
    color-mix(in srgb, var(--bg-input) 60%, var(--bg)) 50%,
    var(--bg-input) 70%
  );
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Заглушка списка чатов, пока идёт первый запрос: экран не пустой
   и не прыгает, когда данные приезжают. */
.skeleton-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
}
.skeleton-row .sk-avatar { width: 52px; height: 52px; border-radius: var(--r-full); }
.skeleton-row .sk-lines { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.skeleton-row .sk-line-1 { height: 12px; width: 42%; }
.skeleton-row .sk-line-2 { height: 11px; width: 72%; }
