/* ============================================================
   MyGram — дизайн-система (37: полный дизайн-пасс, 01.10)
   Тёмная тема по умолчанию + светлая (body.light), «под Telegram».
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel2: #202c39;
  --panel3: #2b3b4d;
  --bubble-me: #2b5278;
  --bubble-them: #182533;
  --accent: #5eb5f7;
  --accent-hover: #4aa3e6;
  --accent-soft: rgba(94, 181, 247, .16);
  --active-item: #2b5278;
  --active-text: #ffffff;
  --active-sub: rgba(255, 255, 255, .78);
  --text: #eef3f8;
  --muted: #7f93a5;
  --border: #223042;
  --green: #4fae4e;
  --red: #e05252;
  --badge: #4fae4e;
  --shadow-sm: 0 6px 20px rgba(0, 0, 0, .28);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .45);
  --chip: rgba(255, 255, 255, .10);
  --inset: rgba(0, 0, 0, .18);
  --meta-me: rgba(255, 255, 255, .62);
  --read: #7ee0a3;
  --check-delivered: rgba(255, 255, 255, .92);
  --toast-bg: #26313d;
  --toast-text: #ffffff;
  --overlay: rgba(0, 0, 0, .58);
  --pattern: rgba(255, 255, 255, .03);
  --ring: rgba(94, 181, 247, .30);
  --danger-soft: rgba(255, 70, 70, .14);
  --danger-line: rgba(255, 80, 80, .45);
  --danger-text: #ffb4b4;
}
body.light {
  --bg: #e7ebf0;
  --panel: #ffffff;
  --panel2: #f1f4f8;
  --panel3: #e7edf3;
  --bubble-me: #e3ffce;
  --bubble-them: #ffffff;
  --accent: #3f97e0;
  --accent-hover: #2f86cc;
  --accent-soft: rgba(63, 151, 224, .14);
  --active-item: #4082bc;
  --active-text: #ffffff;
  --active-sub: rgba(255, 255, 255, .8);
  --text: #15202b;
  --muted: #6f7b88;
  --border: #e2e8ef;
  --green: #2fae57;
  --red: #dd4a4a;
  --badge: #34b233;
  --shadow-sm: 0 6px 20px rgba(30, 50, 70, .10);
  --shadow-lg: 0 24px 64px rgba(30, 50, 70, .18);
  --chip: rgba(30, 60, 90, .08);
  --inset: rgba(30, 60, 90, .05);
  --meta-me: #4d7a2a;
  --read: #157a3d;
  --check-delivered: #334455;
  --toast-bg: #22303f;
  --toast-text: #ffffff;
  --overlay: rgba(15, 25, 40, .45);
  --pattern: rgba(40, 80, 120, .05);
  --ring: rgba(63, 151, 224, .25);
  --danger-soft: rgba(255, 70, 70, .08);
  --danger-line: rgba(220, 80, 80, .4);
  --danger-text: #c04545;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
button {
  font: inherit; cursor: pointer; border: none; background: none; color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
input, textarea { font: inherit; -webkit-tap-highlight-color: transparent; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============ ЭКРАН ВХОДА ============ */
#auth {
  height: 100vh; height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(900px 600px at 15% -10%, #1c2c3d 0%, transparent 60%),
    radial-gradient(700px 500px at 110% 110%, #16283a 0%, transparent 55%),
    var(--bg);
  padding: 16px;
}
body.light #auth {
  background:
    radial-gradient(900px 600px at 15% -10%, #ffffff 0%, transparent 60%),
    linear-gradient(160deg, #eef3f9, #dfe7f1);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px; padding: 30px 26px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  width: 76px; height: 76px; margin: 0 auto 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  background: linear-gradient(135deg, #5eb5f7 0%, #2b6cb0 100%);
  box-shadow: 0 10px 26px rgba(94, 181, 247, .35);
}
.auth-card h1 { text-align: center; font-size: 27px; font-weight: 800; letter-spacing: .2px; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 20px; }
.auth-tabs { display: flex; background: var(--panel2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.auth-tabs button {
  flex: 1; padding: 9px; border-radius: 9px; color: var(--muted); font-weight: 600;
  transition: background .15s ease, color .15s ease;
}
.auth-tabs button:hover { color: var(--text); }
.auth-tabs button.on { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(94, 181, 247, .4); }
#auth input {
  width: 100%; padding: 12px 14px; margin-bottom: 10px;
  background: var(--panel2); color: var(--text);
  border: 1px solid transparent; border-radius: 12px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
#auth input::placeholder { color: var(--muted); }
#auth input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.auth-err { color: var(--red); font-size: 13px; margin-bottom: 10px; }
#auth-btn {
  width: 100%; padding: 13px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15.5px;
  transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
  box-shadow: 0 4px 14px rgba(94, 181, 247, .35);
}
#auth-btn:hover { background: var(--accent-hover); box-shadow: 0 6px 18px rgba(94, 181, 247, .45); }
#auth-btn:active { transform: scale(.98); }
.auth-note { margin-top: 16px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* ============ КАРКАС ============ */
#app { display: flex; height: 100vh; height: 100dvh; }

/* ============ САЙДБАР ============ */
#sidebar {
  width: 320px; min-width: 270px;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sb-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); position: relative; }
.me-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px; background: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}
.me-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.me-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-ver { font-size: 11px; color: var(--muted); }
/* 37c: меню «⋮» на главном экране — 1 кнопка вместо 4 иконок (как в шапке чата) */
#btn-sidemenu { font-size: 20px; font-weight: 700; width: 36px; height: 36px; border-radius: 50%; }
#side-menu {
  position: absolute; top: 56px; right: 10px; z-index: 50;
  min-width: 248px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 2px;
}
/* 37c: пункты меню — акцент у «Проверить обновление», красный у «Выйти» */
.hm-upd { color: var(--accent); font-weight: 600; }
body.light .hm-upd { color: #1d6fc0; }
.hm-danger { color: var(--danger-text); }
.sb-actions { display: flex; gap: 8px; padding: 10px 12px 8px; }
.sb-actions button {
  flex: 1; padding: 9px 6px; font-size: 12.5px; font-weight: 600;
  background: var(--panel2); color: var(--text); border-radius: 10px;
  transition: background .15s ease, transform .12s ease;
}
.sb-actions button:hover { background: var(--panel3); }
.sb-actions button:active { transform: scale(.97); }
.sb-search { padding: 2px 12px 10px; }
.sb-search input {
  width: 100%; padding: 10px 14px 10px 36px; font-size: 13.5px;
  background: var(--panel2); color: var(--text);
  border: 1px solid transparent; border-radius: 11px; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238494a6' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center; background-size: 15px;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.sb-search input::placeholder { color: var(--muted); }
.sb-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
#chat-list { flex: 1; overflow-y: auto; padding: 2px 6px 12px; }

.chat-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin: 1px 0; cursor: pointer; border-radius: 11px;
  position: relative;
  transition: background .15s ease;
}
.chat-item:hover { background: var(--panel2); }
.chat-item.active { background: var(--active-item); }
.chat-item.active .chat-title, .chat-item.active .chat-preview { color: var(--active-text); }
.chat-item.active .chat-preview { color: var(--active-sub); }
.chat-item.active .dot-online { border-color: var(--active-item); }
.chat-item.active .badge { background: #fff; color: var(--active-item); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 17px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}
.chat-main { flex: 1; min-width: 0; }
.chat-title { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-preview {
  font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; margin-top: 2px;
}
.badge {
  background: var(--badge); color: #fff; font-size: 11.5px; font-weight: 700;
  min-width: 21px; height: 21px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center; padding: 0 7px;
  flex: none; box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}
.dot-online {
  width: 12px; height: 12px; border-radius: 50%; background: var(--green); flex: none;
  position: absolute; left: 47.5px; top: 45.5px;
  border: 2.5px solid var(--panel);
}

/* ============ ОБЛАСТЬ ЧАТА ============ */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
#empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); gap: 14px; padding: 24px; text-align: center;
}
.empty-icon {
  width: 104px; height: 104px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 48px; background: var(--panel2); box-shadow: inset 0 0 0 1px var(--border);
}
#empty > div:nth-child(2) { font-size: 15px; font-weight: 600; color: var(--text); opacity: .85; }
.empty-sub { font-size: 13px; }

#chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#chat-head {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.peer-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}
/* 39: аватарка — фото в круглой рамке (все места: список, шапка, «я», участники, профиль) */
.avatar, .peer-avatar, .me-avatar, .prof-av { overflow: hidden; }
.avatar img, .peer-avatar img, .me-avatar img, .prof-av img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.peer-info { flex: 1; min-width: 0; }
.peer-name { font-weight: 700; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-status { font-size: 12.5px; color: var(--muted); }
.peer-status.on { color: var(--green); }
/* 37b: меню действий «⋮» (как в Telegram) — 1 кнопка в шапке + выпадающее меню */
#btn-headmenu { font-size: 20px; font-weight: 700; line-height: 1; }
#head-menu {
  position: absolute; top: 54px; right: 8px; z-index: 40;
  min-width: 232px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 2px;
}
.hm-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  font-size: 14.5px; font-weight: 500; text-align: left; white-space: nowrap;
  transition: background .15s ease, transform .12s ease;
}
.hm-item:hover { background: var(--panel3); }
.hm-item:active { background: var(--panel2); transform: scale(.985); }
.hm-ico { font-size: 17px; width: 24px; text-align: center; flex: none; }
.icon-btn {
  font-size: 18px; width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, transform .12s ease;
}
.icon-btn:hover { background: var(--panel3); }
.icon-btn:active { transform: scale(.92); }
.icon-btn:disabled { opacity: .45; cursor: default; }
.icon-btn:disabled:hover { background: none; }

#msgs {
  flex: 1; overflow-y: auto;
  padding: 14px clamp(12px, 6%, 96px);
  display: flex; flex-direction: column; gap: 3px;
  background-image: radial-gradient(var(--pattern) 1.2px, transparent 1.4px);
  background-size: 22px 22px;
}
.msg { display: flex; }
.msg.mine { justify-content: flex-end; }
.bubble {
  max-width: 70%; padding: 8px 12px 6px; border-radius: 15px;
  background: var(--bubble-them);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .10);
}
.msg.mine .bubble { background: var(--bubble-me); border-bottom-right-radius: 5px; }
.msg.theirs .bubble { border-bottom-left-radius: 5px; }
.bubble-body { display: flex; flex-direction: column; gap: 6px; }
.msg-text { white-space: pre-wrap; word-break: break-word; font-size: 14.6px; line-height: 1.38; }
.msg-from { font-weight: 700; font-size: 13px; }
.msg-err { color: #ffce5c; font-size: 12.5px; }
.msg-meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 5px;
  font-size: 11px; color: var(--muted); margin-top: 3px;
}
.msg.mine .msg-meta { color: var(--meta-me); }
.msg-del, .msg-edit, .msg-pin {
  background: none; border: none; padding: 4px 5px; margin-left: 1px; border-radius: 6px;
  font-size: 12px; line-height: 1; cursor: pointer;
  transition: opacity .15s ease, background .15s ease, transform .12s ease;
}
.msg-del { opacity: .5; }
.msg-del:hover { opacity: 1; background: rgba(255, 255, 255, .14); }
.msg-edit { opacity: .5; }
.msg-edit:hover { opacity: 1; background: rgba(255, 255, 255, .14); }
.msg-pin { opacity: .35; }
.msg-pin:hover { opacity: .9; background: rgba(255, 255, 255, .10); }
.msg-pin.on { opacity: 1; }
body.light .msg-del:hover, body.light .msg-edit:hover { background: rgba(0, 0, 0, .08); }
body.light .msg-pin:hover { background: rgba(0, 0, 0, .06); }
.msg-del:active, .msg-edit:active, .msg-pin:active { transform: scale(.9); }
/* Отметки: delivered = ярче; read = зелёный */
.msg-checks { font-size: 11px; line-height: 1; letter-spacing: -1px; }
.msg.mine .msg-checks.delivered { color: var(--check-delivered); }
.msg.mine .msg-checks.read { color: var(--read); }
.edited-mark { font-style: italic; opacity: .75; }

/* Вспышка при переходе к закреплённому */
.msg-flash { border-radius: 15px; animation: msgflash 1.4s ease-out; }
@keyframes msgflash { 0%, 60% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }

/* Баннер закреплённого сообщения */
#pin-banner {
  display: flex; align-items: center; gap: 8px;
  margin: 8px clamp(12px, 6%, 96px) 0; padding: 9px 13px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  font-size: 13.5px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, background .15s ease;
}
#pin-banner:hover { border-color: var(--accent); }
#pin-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
#pin-unpin {
  background: none; border: none; padding: 3px 8px; border-radius: 7px; opacity: .6; cursor: pointer;
  transition: opacity .15s ease, background .15s ease;
}
#pin-unpin:hover { opacity: 1; background: var(--panel3); }

/* Модалка редактирования */
#edit-modal {
  position: fixed; inset: 0; background: var(--overlay); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#edit-input {
  width: 100%; padding: 11px 13px; margin-bottom: 14px;
  background: var(--panel2); color: var(--text); border: 1px solid transparent; border-radius: 11px;
  outline: none; resize: vertical; min-height: 74px; font-family: inherit; font-size: 14.5px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#edit-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
#edit-ok { background: var(--accent); color: #fff; }
#edit-cancel { color: var(--muted); }

/* ============ МЕДИА ============ */
.media-img { max-width: 280px; max-height: 340px; border-radius: 12px; display: block; cursor: pointer; }
.media-vid { max-width: 300px; max-height: 340px; border-radius: 12px; display: block; background: #000; }
.media-retry {
  margin-top: 4px; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  background: var(--chip); color: var(--text);
}
.media-retry:hover { background: var(--panel3); }

/* Лайтбокс: полноэкранный просмотр картинки */
#lightbox {
  position: fixed; inset: 0; z-index: 1000; display: none;
  background: rgba(0, 0, 0, .93); align-items: center; justify-content: center;
  padding: 16px; box-sizing: border-box; cursor: zoom-out; touch-action: none;
}
#lightbox.on { display: flex; }
#lightbox img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 8px; cursor: default; touch-action: none;
  transition: transform .08s ease-out; will-change: transform;
}
.lb-close {
  position: absolute; top: 14px; right: 14px; z-index: 2;
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, .16); color: #fff; font-size: 20px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, transform .12s ease;
}
.lb-close:hover { background: rgba(255, 255, 255, .28); }
.lb-close:active { transform: scale(.92); }

.file-attach {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--inset); border-radius: 12px; min-width: 200px;
}
.file-ico { font-size: 26px; }
.file-meta { flex: 1; min-width: 0; }
.file-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.file-dl {
  font-size: 17px; width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; flex: none;
  transition: background .15s ease, transform .12s ease;
}
.file-dl:hover { background: rgba(255, 255, 255, .15); }
.file-dl:active { transform: scale(.9); }
.file-loading { font-size: 12.5px; color: var(--muted); padding: 4px 0; }

/* 20: голосовые сообщения */
.voice-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--inset); border-radius: 12px; min-width: 220px; flex-wrap: wrap;
}
.voice-audio { max-width: 230px; width: 100%; height: 38px; }
.icon-btn.rec-on { background: #d64545; color: #fff; animation: recPulse 1.1s ease-in-out infinite; }
.icon-btn.rec-on:hover { background: #e05252; }
@keyframes recPulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }

#typing-ind { padding: 2px 14px; font-size: 12.5px; color: var(--muted); min-height: 22px; opacity: 0; transition: opacity .2s ease; }
#typing-ind:not(:empty) { opacity: 1; }

/* ============ ИНПУТ ============ */
#inputbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
}
#msg-input {
  flex: 1; min-width: 0;
  padding: 12px 16px; font-size: 14.5px;
  background: var(--panel2); color: var(--text);
  border: 1px solid transparent; border-radius: 22px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
#msg-input::placeholder { color: var(--muted); }
#msg-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
#msg-input:disabled { opacity: .6; }
.send-btn {
  width: 46px; height: 46px; flex: none; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(94, 181, 247, .35);
  transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
}
.send-btn:hover { background: var(--accent-hover); box-shadow: 0 6px 18px rgba(94, 181, 247, .5); }
.send-btn:active { transform: scale(.92); }

/* ============ МОДАЛКИ ============ */
#modal-overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 400px; max-height: 90vh; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 20px;
  box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: 14px; font-size: 17.5px; font-weight: 700; }
#g-name {
  width: 100%; padding: 11px 13px; margin-bottom: 12px;
  background: var(--panel2); color: var(--text); border: 1px solid transparent; border-radius: 11px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#g-name:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
#g-list { max-height: 240px; overflow-y: auto; margin-bottom: 12px; display: flex; flex-direction: column; gap: 2px; }
.g-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; transition: background .15s ease; }
.g-item:hover { background: var(--panel3); }
.g-item input { width: 18px; height: 18px; accent-color: var(--accent); }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-btns button {
  padding: 10px 18px; border-radius: 10px; font-weight: 600;
  transition: background .15s ease, color .15s ease, transform .12s ease;
}
.modal-btns button:active { transform: scale(.97); }
#modal-ok, #edit-ok, #prof-save { background: var(--accent); color: #fff; box-shadow: 0 3px 10px rgba(94, 181, 247, .35); }
#modal-ok:hover, #edit-ok:hover, #prof-save:hover { background: var(--accent-hover); }
#modal-cancel, #edit-cancel, #prof-cancel { color: var(--muted); }

/* 39: профиль — имя на русском + аватарка */
#profile-modal {
  position: fixed; inset: 0; background: var(--overlay); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.prof-av-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 12px 0 16px; }
.prof-av {
  width: 96px; height: 96px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 42px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
}
.prof-av-acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.prof-field { margin: 0 0 4px; }
.prof-field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.prof-field input {
  width: 100%; padding: 11px 14px; font-size: 15px; font-family: inherit;
  background: var(--panel2); color: var(--text); border: 1px solid transparent; border-radius: 11px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.prof-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
#modal-cancel:hover, #edit-cancel:hover { background: var(--panel3); color: var(--text); }
#protect-ok { background: var(--accent); color: #fff; }
#protect-ok:hover { background: var(--accent-hover); }
#protect-cancel { color: var(--muted); }
#protect-cancel:hover { background: var(--panel3); color: var(--text); }
#protect-status { margin-bottom: 10px; }
#protect-modal .adm-note { line-height: 1.55; margin-bottom: 8px; }

/* ============ ЗВОНОК ============ */
#call-modal {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, #101b28 0%, #0a1017 100%);
  display: flex; align-items: center; justify-content: center;
}
.call-wrap {
  width: 100%; max-width: 420px; text-align: center; padding: 20px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.call-peer { font-size: 32px; font-weight: 800; color: #fff; letter-spacing: .3px; }
.call-status { color: #9fb3c8; font-size: 15px; min-height: 22px; }
.call-videos { width: 100%; position: relative; }
#remote-video { width: 100%; border-radius: 16px; background: #000; aspect-ratio: 16/10; object-fit: cover; }
#local-video {
  position: absolute; right: 12px; bottom: 12px;
  width: 32%; max-width: 130px; aspect-ratio: 3/4; object-fit: cover;
  border-radius: 12px; border: 2px solid rgba(255, 255, 255, .35); background: #222;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.call-btns { display: flex; gap: 14px; }
.call-btns button {
  padding: 12px 24px; border-radius: 13px; font-weight: 700; font-size: 15px;
  background: rgba(255, 255, 255, .12); color: #fff;
  transition: background .15s ease, transform .12s ease;
}
.call-btns button:hover { background: rgba(255, 255, 255, .2); }
.call-btns button:active { transform: scale(.96); }
#btn-accept { background: var(--green); box-shadow: 0 6px 18px rgba(79, 174, 78, .4); }
#btn-accept:hover { background: #5cbe5b; }
#btn-decline.danger { background: var(--red); box-shadow: 0 6px 18px rgba(224, 82, 82, .4); }
#btn-decline.danger:hover { background: #e86262; }
.call-controls { display: flex; gap: 18px; margin-top: 6px; }
.call-controls button {
  width: 58px; height: 58px; border-radius: 50%;
  background: rgba(255, 255, 255, .14); color: #fff; font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, transform .12s ease;
}
.call-controls button:hover { background: rgba(255, 255, 255, .25); }
.call-controls button:active { transform: scale(.92); }
.call-controls button.off { background: rgba(255, 255, 255, .08); opacity: .6; }
#btn-hangup.danger-round { background: var(--red); width: 64px; height: 64px; box-shadow: 0 8px 22px rgba(224, 82, 82, .45); }
#btn-hangup.danger-round:hover { background: #e86262; }

/* ============ ДИАГНОСТИКА ============ */
#diag-modal {
  position: fixed; inset: 0; z-index: 150; background: var(--overlay);
  display: flex; align-items: center; justify-content: center; padding: 16px; box-sizing: border-box;
}
#diag-modal.hidden { display: none; }
.diag-wrap {
  width: 100%; max-width: 580px; max-height: 92vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 18px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-lg);
}
.diag-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.diag-head h3 { margin: 0; font-size: 16.5px; font-weight: 700; color: var(--text); }
#diag-close {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%; border: none;
  background: var(--panel3); color: var(--text); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, transform .12s ease;
}
#diag-close:hover { background: var(--border); }
#diag-close:active { transform: scale(.92); }
.diag-body {
  white-space: pre-wrap; word-break: break-word;
  font-size: 13px; line-height: 1.55; font-family: Consolas, Menlo, monospace;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  max-height: 52vh; overflow: auto; color: var(--text);
}
.diag-foot { display: flex; gap: 8px; }
.diag-foot button {
  flex: 1; padding: 12px; border-radius: 11px; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
  transition: background .15s ease, transform .12s ease;
}
.diag-foot button:hover { background: var(--accent-hover); }
.diag-foot button:active { transform: scale(.98); }
#diag-copy { background: var(--panel3); color: var(--text); }
#diag-copy:hover { background: var(--border); }
.notif-diag {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  background: var(--panel2); display: flex; flex-direction: column; gap: 8px;
}
.notif-diag-title { font-size: 14px; font-weight: 700; color: var(--text); }
.notif-diag-status {
  white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.5;
  font-family: Consolas, Menlo, monospace; color: var(--text);
}
.notif-diag-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.notif-diag-btns button {
  flex: 1; min-width: 140px; padding: 10px; border-radius: 10px; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
  transition: background .15s ease, transform .12s ease;
}
.notif-diag-btns button:hover { background: var(--accent-hover); }
.notif-diag-btns button:active { transform: scale(.98); }
#btn-notif-perm { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
#btn-notif-perm:hover { background: var(--panel3); }
.notif-diag-hint { font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* ============ УПРАВЛЕНИЕ ГРУППОЙ (админ-модалка) — 37b дизайн ============ */
#admin-modal { position: fixed; inset: 0; z-index: 120; background: var(--overlay); display: flex; align-items: center; justify-content: center; padding: 16px; }
.adm-wrap {
  width: min(480px, 94vw); max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 18px; box-shadow: var(--shadow-lg);
}
/* Шапка: аватар + имя + «N участников» + круглый ✕ */
.adm-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.adm-head-av {
  width: 46px; height: 46px; flex: 0 0 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 21px;
}
.adm-head-info { flex: 1; min-width: 0; }
.adm-head h3 { margin: 0; font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adm-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
#admin-close {
  border: none; background: var(--panel3); color: var(--text); width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 50%; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, transform .12s ease;
}
#admin-close:hover { background: var(--border); }
#admin-close:active { transform: scale(.9); }
/* Заголовки секций */
.adm-sec-label {
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 8px; padding: 0 2px;
}
.adm-sec-danger { color: var(--danger-text); }
/* Участники — карточный список */
.adm-list {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 14px;
  padding: 4px; margin-bottom: 16px;
}
.adm-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px;
  transition: background .15s ease;
}
.adm-row:hover { background: var(--panel3); }
.adm-row .avatar { flex: none; }
.adm-mid { flex: 1; min-width: 0; }
.adm-name {
  font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.adm-badge {
  font-size: 10.5px; padding: 2.5px 9px; border-radius: 999px;
  background: var(--chip); color: var(--muted);
  font-weight: 700; flex: none; letter-spacing: .02em;
}
.adm-badge.owner { background: rgba(255, 196, 0, .22); color: #ffd24d; }
body.light .adm-badge.owner { color: #9a6400; background: rgba(255, 180, 0, .22); }
.adm-badge.admin { background: rgba(80, 160, 255, .22); color: #7cc0ff; }
body.light .adm-badge.admin { color: #1d6fc0; background: rgba(60, 140, 255, .18); }
.adm-btns { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 205px; }
.adm-chip {
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 11px; font-size: 12px; cursor: pointer;
  background: var(--panel); color: var(--text); font-weight: 600;
  transition: background .15s ease, border-color .15s ease, transform .12s ease, opacity .15s ease;
}
.adm-chip:hover { background: var(--panel3); border-color: var(--accent); }
.adm-chip.off { background: rgba(255, 90, 90, .16); border-color: rgba(255, 90, 90, .45); color: var(--danger-text); }
.adm-chip.danger { background: transparent; border-color: var(--danger-line); color: var(--danger-text); }
.adm-chip.danger:hover { background: var(--danger-soft); }
.adm-chip.role { background: rgba(90, 160, 255, .14); border-color: rgba(90, 160, 255, .4); color: #7cc0ff; }
body.light .adm-chip.role { background: rgba(60, 140, 255, .14); color: #1d6fc0; }
.adm-chip:active { opacity: .8; transform: scale(.95); }
/* Права участников */
.adm-perms { margin-bottom: 16px; }
.adm-perms-card {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 14px; padding: 4px;
}
.adm-p {
  display: flex; gap: 10px; align-items: center; font-size: 14px; padding: 10px;
  border-radius: 10px; cursor: pointer; transition: background .15s ease;
}
.adm-p:hover { background: var(--panel3); }
.adm-p input { accent-color: var(--accent); width: 17px; height: 17px; flex: none; }
.adm-p span { flex: 1; }
.adm-note { font-size: 12px; color: var(--muted); margin: 8px 2px 0; line-height: 1.5; }
/* 36 + 37b: «Опасная зона» — красная карточка (удаление: владелец/админ) */
.adm-danger {
  background: rgba(255, 70, 70, .07); border: 1px solid var(--danger-line);
  border-radius: 14px; padding: 12px 14px;
}
body.light .adm-danger { background: rgba(255, 70, 70, .05); }
.adm-danger .adm-note { margin: 0 0 10px; }
.adm-delbtn {
  width: 100%; border: 1px solid var(--danger-line); border-radius: 12px;
  background: rgba(255, 70, 70, .14); color: var(--danger-text); padding: 12px 14px;
  font-size: 14px; font-weight: 700; cursor: pointer;
  transition: background .15s ease, transform .12s ease;
}
.adm-delbtn:hover { background: rgba(255, 70, 70, .26); }
body.light .adm-delbtn:hover { background: rgba(255, 70, 70, .18); }
.adm-delbtn:active { opacity: .85; transform: scale(.99); }
/* Мобилка: кнопки действий переносятся под имя */
@media (max-width: 420px) {
  .adm-row { flex-wrap: wrap; }
  .adm-btns { max-width: none; width: 100%; justify-content: flex-start; }
}

/* ============ TOAST ============ */
#toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--toast-bg); color: var(--toast-text);
  padding: 12px 20px; border-radius: 13px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .22s ease, transform .22s ease; z-index: 200;
  max-width: min(88vw, 480px); text-align: center;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .38);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ СКРОЛЛБАРЫ ============ */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--panel3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ============ МОБИЛКА ============ */
@media (max-width: 780px) {
  #sidebar { width: 100%; min-width: 0; border-right: none; }
  #main { display: none; }
  body.chat-open #sidebar { display: none; }
  body.chat-open #main { display: flex; }
  #msgs { padding: 10px 3%; }
  .bubble { max-width: 84%; }
  #pin-banner { margin-left: 3%; margin-right: 3%; }
  #chat-head { padding: 6px 8px; }
  #btn-headmenu { width: 40px; height: 40px; font-size: 21px; }
  #inputbar { padding-left: 8px; padding-right: 8px; }
  .sb-search input { padding-left: 38px; }
}

/* ============ ДОСТУПНОСТЬ ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============ 41.3: 2FA (экран входа + профиль) ============ */
#auth-2fa { margin-top: 12px; }
#auth-2fa input { margin-bottom: 8px; letter-spacing: 2px; font-size: 16px; text-align: center; }
#auth-2fa .auth-note { margin-top: 8px; font-size: 11.5px; }
/* 41.4: заголовок + ПЕРВИЧНАЯ кнопка (была маленькая «adm-chip»-подобная — неочевидно) */
#auth-2fa .tfa-login-title { margin: 0 0 10px; font-size: 14.5px; font-weight: 700; text-align: center; }
#auth-2fa-btn {
  width: 100%; padding: 13px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15.5px;
  box-shadow: 0 4px 14px rgba(94, 181, 247, .35);
  transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
}
#auth-2fa-btn:hover { background: var(--accent-hover); box-shadow: 0 6px 18px rgba(94, 181, 247, .45); }
#auth-2fa-btn:active { transform: scale(.98); }
#auth-2fa-btn:disabled { opacity: .6; cursor: default; }

.prof-sec { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.prof-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-weight: 600; font-size: 14px; }
#tfa-box { margin-top: 6px; }
#tfa-box input { margin: 6px 0 8px; letter-spacing: 2px; }
.tfa-secretrow { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.tfa-secretrow code {
  flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 13px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 10px; word-break: break-all; user-select: all;
}
#tfa-codes-list { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0; }
.tfa-code {
  font-family: ui-monospace, Consolas, monospace; font-size: 13px; font-weight: 600;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; user-select: all;
}
#tfa-result .adm-note { margin-bottom: 6px; }
/* 41.4: крупные заметные кнопки действий 2FA в профиле (были мелкие «adm-chip») */
.tfa-primary-btn {
  width: 100%; margin-top: 10px; padding: 13px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 0 4px 14px rgba(94, 181, 247, .35);
  transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
}
.tfa-primary-btn:hover { background: var(--accent-hover); box-shadow: 0 6px 18px rgba(94, 181, 247, .45); }
.tfa-primary-btn:active { transform: scale(.98); }
.tfa-primary-btn:disabled { opacity: .6; cursor: default; }
.tfa-danger-btn {
  width: 100%; margin-top: 10px; padding: 13px; border-radius: 12px;
  background: rgba(255, 90, 90, .16); border: 1px solid rgba(255, 90, 90, .45);
  color: var(--danger-text); font-weight: 700; font-size: 15px;
  transition: background .15s ease, transform .12s ease;
}
.tfa-danger-btn:hover { background: var(--danger-soft); }
.tfa-danger-btn:active { transform: scale(.98); }
