/* ---------- Капча ---------- */
.captcha-row { display: flex; align-items: center; gap: 8px; margin: 6px 0 8px; }
.captcha-img { background: var(--bg4); border-radius: 10px; width: 200px; height: 64px; overflow: hidden; }
.captcha-img svg { display: block; }

/* ---------- Кнопка «отправить» (видна только на телефоне) ---------- */
.composer .send-btn { display: none; }

/* ---------- Телефон ---------- */
@media (max-width: 640px) {
  html, body { overscroll-behavior: none; }
  body { position: fixed; inset: 0; overflow: hidden; touch-action: pan-x pan-y; }
  #app { position: fixed; inset: 0; height: auto; overflow: hidden; }

  /* Список: только рельса + список чатов, без горизонтальной прокрутки */
  #sidebar { position: static !important; flex: 1; width: auto !important; min-width: 0; padding-bottom: 84px; }
  #main { position: absolute; inset: 0; z-index: 40; transform: translateX(100%); visibility: hidden; transition: transform .28s cubic-bezier(.2,.8,.2,1), visibility 0s .28s; }
  body.mobile-chat #main { transform: none; visibility: visible; transition: transform .28s cubic-bezier(.2,.8,.2,1); }
  body.mobile-chat #sidebar, body.mobile-chat #rail { display: flex; }
  /* Под чатом список только затемняется: сдвиг заставлял его наезжать на панель серверов */
  #rail, #side-head, #side-list { transition: opacity .28s; }
  body.mobile-chat #rail, body.mobile-chat #side-head, body.mobile-chat #side-list { opacity: .35; }
  #main { box-shadow: -12px 0 24px rgba(0,0,0,.35); }
  #userbar { transition: opacity .2s; }
  body.mobile-chat #userbar { display: flex; opacity: 0; pointer-events: none; }

  /* Профиль/участники — отдельный экран поверх чата, без него чат не перекрыт */
  #members, #members.dm-side { display: none !important; }
  body.mobile-members #members:not(.hidden), body.mobile-members #members.dm-side { display: flex !important; flex-direction: column; position: absolute; inset: 52px 0 0 0; width: auto !important; z-index: 45; background: var(--bg2); animation: m-slide-left .25s cubic-bezier(.2,.8,.2,1); overflow-y: auto; }
  body.mobile-members #members .full-btn { position: sticky; bottom: 12px; }

  /* Шапка списка «Сообщения» как в Discord */
  #side-head:has(.m-head) { height: auto; border: 0; padding: 14px 12px 6px; }
  .m-head { width: 100%; }
  .m-title { font-size: 22px; font-weight: 800; margin: 0 4px 12px; }
  .m-actions { display: flex; gap: 8px; align-items: center; }
  .m-round, .m-pill { height: 40px; border: 1px solid var(--border); background: var(--bg3); color: var(--text); border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; transition: transform .12s, background .2s; }
  .m-round { width: 40px; flex-shrink: 0; }
  .m-round.accent { background: var(--accent); border-color: var(--accent); color: #fff; border-radius: 12px; }
  .m-pill { flex: 1; padding: 0 12px; font-size: 14px; }
  .m-round svg, .m-pill svg { width: 20px; height: 20px; }
  #m-search { padding: 4px 12px 8px; animation: m-fade .2s; }
  .side-item { padding: 9px 10px; border-radius: 12px; }
  .side-item .avatar.sm { width: 40px; height: 40px; }

  /* Нижняя карточка пользователя */
  #userbar { left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); width: auto !important; height: 64px; border-radius: 18px; }

  /* Шапка чата */
  .main-head { padding-top: env(safe-area-inset-top); }
  .main-head .title { min-width: 0; }
  .main-head .title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .main-head [data-act="pins"] { display: none; }
  .main-head:has(.tabs) .title { display: none; }
  .main-head .tabs { flex: 1; min-width: 0; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .main-head .tabs .tab { white-space: nowrap; flex-shrink: 0; }

  /* Поле ввода как в Discord: «+», капсула, смайлик и микрофон → стрелка отправки */
  .composer { margin: 0 10px calc(8px + env(safe-area-inset-bottom)); border-radius: 24px; border: 1px solid var(--border); background: var(--input); }
  .composer .inner { align-items: center; padding: 4px 6px; gap: 2px; }
  .composer .inner > .icon-btn { width: 40px; height: 40px; border-radius: 50%; }
  .composer textarea { padding: 10px 6px; font-size: 16px; min-height: 40px; height: 40px; max-height: 120px; line-height: 20px; }
  .composer .send-btn { width: 44px; height: 40px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; place-items: center; flex-shrink: 0; animation: m-pop .18s cubic-bezier(.3,1.6,.5,1); }
  .composer .send-btn svg { width: 20px; height: 20px; }
  .composer.has-text .send-btn { display: grid; }
  .composer.has-text [data-act="voice-msg"] { display: none; }
  .composer.has-text [data-act="emoji"] { margin-right: 2px; }

  /* Панель «+» снизу */
  .m-sheet-wrap { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; animation: m-fade .2s; }
  .m-sheet-wrap.closing { animation: m-fade-out .2s forwards; }
  .m-sheet { width: 100%; background: var(--bg2); border-radius: 22px 22px 0 0; padding: 8px 14px calc(18px + env(safe-area-inset-bottom)); animation: m-slide-up .26s cubic-bezier(.2,.8,.2,1); transition: transform .15s; }
  .m-sheet-wrap.closing .m-sheet { animation: m-slide-down .2s forwards; }
  .m-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--bg4); margin: 0 auto 14px; }
  .m-sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .m-sheet-grid button { background: var(--bg3); border: 0; border-radius: 16px; color: var(--text); padding: 18px 6px 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; font: inherit; font-size: 14px; font-weight: 600; transition: transform .12s; }
  .m-sheet-grid svg { width: 26px; height: 26px; }

  /* Настройки — список с разделами, как в Discord */
  #settings.m-settings { flex-direction: column; }
  #settings.m-settings .m-st-head { display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 8px; flex-shrink: 0; font-size: 18px; }
  #settings.m-settings > .close { display: none; }
  #settings.m-settings nav { width: 100% !important; max-height: none !important; flex: 1; padding: 0 12px 24px !important; background: transparent !important; animation: m-fade .2s; }
  #settings.m-settings nav .grp { padding: 18px 6px 8px; text-transform: none; font-size: 14px; font-weight: 600; color: var(--muted); }
  #settings.m-settings nav .side-item { background: var(--bg2); border-radius: 0; margin: 0 !important; padding: 15px 14px; color: var(--text); font-size: 16px; border-bottom: 1px solid var(--border); }
  #settings.m-settings nav .side-item::after { content: "›"; margin-left: auto; color: var(--faint); font-size: 22px; line-height: 1; }
  #settings.m-settings nav .grp + .side-item { border-radius: 14px 14px 0 0; }
  #settings.m-settings nav .side-item:has(+ .grp), #settings.m-settings nav .side-item:last-child { border-radius: 0 0 14px 14px; border-bottom: 0; }
  #settings.m-settings nav .grp + .side-item:has(+ .grp), #settings.m-settings nav .grp + .side-item:last-child { border-radius: 14px; }
  #settings.m-settings nav .side-item.active { background: var(--bg2); }
  #settings.m-settings nav .side-item[data-st="logout"] { justify-content: center; }
  #settings.m-settings nav .side-item[data-st="logout"]::after { content: none; }
  #settings.m-settings .pane { display: none; padding: 8px 14px 32px !important; max-width: none; }
  #settings.m-settings.m-open nav { display: none; }
  #settings.m-settings.m-open .pane { display: block; flex: 1; animation: m-slide-left .25s cubic-bezier(.2,.8,.2,1); }
  #settings.m-settings .pane > h2:first-child { display: none; }

  /* Модалки — снизу листом */
  .overlay { align-items: end; padding: 0; }
  .overlay > .modal, .overlay > div:first-child { animation: m-slide-up .26s cubic-bezier(.2,.8,.2,1); }

  /* Отклик на нажатие */
  .side-item:active, .m-round:active, .m-pill:active, .m-sheet-grid button:active, .composer .send-btn:active, .icon-btn:active, .rail-item:active, .btn:active { transform: scale(.94); }
  .icon-btn, .btn, .side-item, .rail-item { -webkit-tap-highlight-color: transparent; }
}
@media (min-width: 641px) { .m-st-head { display: none; } }

@keyframes m-slide-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes m-slide-down { to { transform: translateY(100%); } }
@keyframes m-slide-left { from { transform: translateX(30%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes m-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes m-fade-out { to { opacity: 0; } }
@keyframes m-pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .m-sheet, .m-sheet-wrap, #main, #members, .msg { animation: none !important; transition: none !important; } }
