/* ═══════════════════════════════════════════════════════════════════════════
   style.css — точка входа. Порядок важен: base → layout → chat → calls.
   Лучше подключать эти 4 файла <link>-ами в index.html (параллельная загрузка),
   а этот файл оставить только для адаптива/утилит — см. заметку ниже.
   ═══════════════════════════════════════════════════════════════════════════ */


/* ═══════════════════════════════════════════════════════════════════════════
   Утилиты
   ═══════════════════════════════════════════════════════════════════════════ */
.hidden { display: none !important; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.no-select { user-select: none; }

/* Скелетон-заглушки при загрузке списков (опционально из JS) */
.skeleton {
  position: relative; overflow: hidden;
  background: var(--bg4); border-radius: var(--radius-sm); color: transparent !important;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
  transform: translateX(-100%);
  animation: skeleton-shine 1.4s ease-in-out infinite;
}
@keyframes skeleton-shine { to { transform: translateX(100%); } }

/* Мобильный «щиток» под панелью участников */
.members-backdrop {
  position: fixed; inset: 0; z-index: calc(var(--z-modal) - 10);
  background: rgba(0,0,0,0.6);
  opacity: 0; pointer-events: none;
  transition: opacity var(--ease);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Планшет: 641–900px
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) and (min-width: 641px) {
  :root { --sidebar-w: 200px; }

  .f-nick, .gm-name { font-size: 15px; }
  .msg-bar-wrap { padding: 0 12px 20px; }
  .g-msg { padding-right: 24px; }

  /* Панель участников группы — поверх чата, а не в потоке */
  .group-chat-body { position: relative; }
  .group-members-panel {
    position: absolute; top: 0; right: 0; bottom: 0; z-index: 5;
    box-shadow: -8px 0 24px rgba(0,0,0,0.35);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Мобилка: ≤640px — один экран за раз (сайдбар ↔ чат)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  :root {
    --sidebar-w: calc(100vw - var(--rail-w));
    --header-h: 48px;
  }

  html, body { font-size: 15px; }
  #app-screen { position: relative; }

  /* ── Сайдбар: во всю ширину, чат — скрыт ── */
  .sidebar {
    width: 100%; min-width: 100%;
    position: absolute; inset: 0; z-index: 3;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
  .chat-main {
    position: absolute; inset: 0; z-index: 2;
    width: 100%;
  }

  /* Чат открыт → JS ставит .sidebar.hidden (или .chat-window.active) */
  .sidebar.hidden { transform: translateX(-16%); opacity: 0; pointer-events: none; }
  #app-screen:has(.chat-window.active) .sidebar,
  #app-screen:has(.chat-window[style*="display: flex"]) .sidebar {
    transform: translateX(-16%); opacity: 0; pointer-events: none;
  }

  /* Кнопка «назад» в шапке чата */
  .back-btn { display: flex; width: 32px; height: 32px; margin-left: -8px; color: var(--text2); }
  .back-btn svg { width: 24px; height: 24px; }
  .back-btn:hover { color: var(--text-h); }
  .chat-head { padding-left: 12px; gap: 6px; }
  .chat-head .icon-btn { margin: 0 2px; }
  .chat-head-nick { font-size: 15px; }
  .chat-head-status { display: none; }
  #group-chat-members-count { display: flex; }

  /* Рельса чуть уже, кнопки меньше */
  :root { --rail-w: 64px; }
  .rail-btn { width: 44px; height: 44px; }
  .rail-pill { left: -10px; }

  /* Поиск и списки */
  .search-box { padding: 0 8px; }
  .search-drop { left: 4px; right: 4px; max-height: 60dvh; }
  .friend-item { min-height: 46px; }
  .group-voice-channel { margin-left: 40px; flex-basis: calc(100% - 40px); }
  .sidebar-footer { height: calc(var(--user-panel-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); }

  /* Сообщения и ввод */
  .messages, .group-messages { padding-top: 8px; }
  .g-msg { padding: 2px 12px 2px 12px; gap: 12px; }
  .g-msg .msg-del-btn { right: 8px; }
  .g-msg-av { width: 36px; height: 36px; font-size: 14px; }
  .g-msg-av-slot { width: 36px; }
  .g-msg-hover-time { display: none; }           /* на тач-устройстве hover нет */
  .msg-system { padding-left: 24px; padding-right: 12px; }
  .msg-divider { margin-left: 12px; margin-right: 12px; }
  .chat-welcome { padding: 12px 12px 4px; }
  .chat-welcome-av { width: 64px; height: 64px; font-size: 26px; }
  .chat-welcome-title { font-size: 24px; line-height: 30px; }
  .msg-bar-wrap { padding: 0 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .msg-bar { min-height: 44px; padding-left: 12px; }
  .g-msg-text.jumbo { font-size: 40px; }
  .md-pre { max-width: 100%; }

  /* Голосовая плашка над чатом */
  .group-voice-bar { min-height: 96px; padding: 12px 12px; }
  .group-voice-actions { position: static; transform: none; margin-top: 4px; }
  .group-voice-member-avatar { width: 40px; height: 40px; font-size: 14px; }

  /* Панель участников — выезжает справа поверх чата */
  .group-chat-body { position: relative; }
  .group-members-panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: calc(var(--z-modal) - 5);
    width: min(85vw, 300px); min-width: 0;
    box-shadow: -8px 0 24px rgba(0,0,0,0.45);
    transform: translateX(0);
    transition: transform 0.2s ease;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .group-members-panel.hidden { display: flex; transform: translateX(100%); pointer-events: none; }
  #app-screen:has(.group-members-panel:not(.hidden)) .members-backdrop { opacity: 1; pointer-events: auto; }

  /* Модалки — bottom-sheet */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box {
    max-width: none; max-height: 92dvh;
    border-radius: 12px 12px 0 0;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    animation: sheet-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .modal-box::before {                              /* «ручка» сверху */
    content: ""; display: block; width: 36px; height: 4px; border-radius: 2px;
    background: var(--bg5); margin: -8px auto 12px;
  }
  .modal-profile::before { display: none; }
  .modal-footer { margin: 16px -16px calc(-16px - env(safe-area-inset-bottom, 0px)); padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-radius: 0; }
  .modal-profile-header::before { left: -16px; right: -16px; }
  .modal-box.call-incoming-box { border-radius: 12px 12px 0 0; padding: 28px 20px calc(24px + env(safe-area-inset-bottom, 0px)); }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

  /* Всплывашки */
  .delete-confirm-popup { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); width: calc(100vw - 24px); justify-content: center; }
  .transient-notice { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .conn-banner { padding-top: calc(6px + env(safe-area-inset-top, 0px)); }

  /* Auth */
  .auth-box { padding: 24px 20px; max-width: none; }
  .auth-title { font-size: 22px; }
}

/* Очень узкие экраны */
@media (max-width: 360px) {
  :root { --rail-w: 56px; }
  .rail-btn { width: 40px; height: 40px; }
  .rail-btn svg { width: 20px; height: 20px; }
  /* Не прятать единственный вход в аудиозвонок на узком экране. */
  #btn-call-video, #btn-group-call-video, #btn-group-info { display: none; }
  .chat-head-actions { flex-shrink: 0; }
  .call-incoming-actions { gap: 20px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Доступность и прочее
   ═══════════════════════════════════════════════════════════════════════════ */
@media (prefers-contrast: more) {
  :root { --text3: #b5bac1; --text4: #949ba4; --divider: #5c5e66; }
  .friend-item.active, .gm-item:hover { outline: 1px solid var(--text2); outline-offset: -1px; }
}

@media print {
  .sidebar, .chat-head-actions, .msg-bar-wrap, .call-overlay, .modal-overlay,
  .conn-banner, .transient-notice, .msg-del-btn { display: none !important; }
  html, body { overflow: visible; background: #fff; color: #000; }
  .messages, .group-messages { overflow: visible; }
}