/* ╔══════════════════════════════════════════════════════╗
   ║  ТЕНЬ — app.css  (v3 чистовой)                      ║
   ╚══════════════════════════════════════════════════════╝ */

/* ── ПЕРЕМЕННЫЕ ─────────────────────────────────────────── */
:root {
  --bg: #080a0f;
  --sidebar: #0b0d14;
  --surface: #0e1117;
  --panel: #131720;
  --border: #1a2030;
  --accent: #00e5a0;
  --blue: #3d9cf0;
  --danger: #ff4757;
  --text: #e2e8f0;
  --muted: #7a8fa8;
  --me-bg: #0a2a1c;
  --me-brd: rgba(0,229,160,.2);
  --sidebar-w:300px;
  --vbar-w: 60px;
  color-scheme: dark;
}

/* ── СБРОС ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Manrope', sans-serif; }

/* ── КОРНЕВОЙ ЛЕЙАУТ ─────────────────────────────────────── */
#app { display: flex; height: 100dvh; width: 100%; align-items: stretch; min-height: 0; }
/* chat-zone сдвинут на полную ширину sidebar (vbar + список) */
#chat-zone { margin-left: var(--sidebar-w); }

/* Нижняя панель сайдбара — прижата к низу */
/* ── ВЕРТИКАЛЬНАЯ НАВИГАЦИОННАЯ ПАНЕЛЬ ──────────────────── */
#vbar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--vbar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(8px, env(safe-area-inset-top, 8px)) 0 max(8px, env(safe-area-inset-bottom, 8px));
  z-index: 20;
  gap: 2px;
  overflow: visible;
}
#vbar-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer; margin-bottom: 4px; flex-shrink: 0; overflow: hidden;
  transition: border-color .15s;
}
#vbar-avatar:hover { border-color: var(--accent); }
.vbar-sep { display: none; }
.vbar-spacer { flex: 1; }
.vbar-btn {
  width: 44px; height: 44px; border-radius: 12px;
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted); flex-shrink: 0; position: relative;
  transition: background .15s, color .15s;
  font-family: 'Manrope', sans-serif;
}
.vbar-btn:hover { background: rgba(255,255,255,.06); }
.vbar-btn.active { color: var(--accent); background: rgba(0,229,160,.08); }
.vbar-btn span { font-size: 6.5px; font-family: 'JetBrains Mono', monospace; letter-spacing: .4px; }
.vbar-badge {
  position: absolute; top: 7px; right: 7px;
  background: var(--danger); color: #fff; border-radius: 7px;
  font-size: 8px; font-weight: 700; font-family: 'JetBrains Mono', monospace;
  min-width: 14px; height: 14px; padding: 0 3px;
  display: flex; align-items: center; justify-content: center;
}

/* ── САЙДБАР ────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  left: var(--vbar-w); top: 0; bottom: 0;
  width: calc(var(--sidebar-w) - var(--vbar-w));
  min-width: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .25s ease;
  z-index: 15;
}

.sidebar-top {
  padding: 8px 12px 0;
  padding-top: max(8px, env(safe-area-inset-top, 8px));
  border-bottom: none;
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.logo-text { font-family: 'JetBrains Mono', monospace; font-size: 16px; font-weight: 700; letter-spacing: 3px; color: var(--text); }
.logo-text .accent { color: var(--accent); }

/* Поиск чатов */
.chats-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.chats-scroll::-webkit-scrollbar { width: 3px; }
.chats-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Строка чата */
.chat-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.03); transition: background .12s, transform .18s ease; position: relative; }
.chat-row:hover  { background: rgba(255,255,255,.03); }
.chat-row.active { background: rgba(0,229,160,.06); border-left: 2px solid var(--accent); }
.chat-row.pending { opacity: .65; }

.chat-row-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--panel); border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 700;
  color: var(--accent); flex-shrink: 0; letter-spacing: 1px; overflow: hidden;
}
.chat-row-info { flex: 1; min-width: 0; }
.chat-row-code {
  font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 700;
  color: var(--text); letter-spacing: .8px; white-space: nowrap; overflow: hidden;
  -webkit-mask-image: linear-gradient(to right,black 80%,transparent 100%);
  mask-image: linear-gradient(to right,black 80%,transparent 100%);
}
.chat-row-preview { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.chat-row-time { font-size: 10px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.unread-badge { background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.lock-badge { width: 18px; height: 18px; border-radius: 9px; background: var(--panel); border: 1px solid var(--accent); display: flex; align-items: center; justify-content: center; color: var(--accent); }

.sidebar-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 32px 20px; text-align: center; }
.sidebar-empty-text { font-size: 12px; line-height: 1.6; }

/* Нижняя панель сайдбара уже определена выше с safe-area */

/* ── ЗОНА ЧАТА ──────────────────────────────────────────── */
#chat-zone { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; overflow: hidden; }

/* Заглушка */
#no-chat { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; overflow: hidden; }
#matrix-canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .4; pointer-events: none; }
.no-chat-content { position: relative; z-index: 1; text-align: center; }
.no-chat-logo { font-family: 'JetBrains Mono', monospace; font-size: 40px; font-weight: 700; letter-spacing: 6px; color: var(--border); margin-bottom: 10px; }
.no-chat-text { font-size: 13px; color: var(--muted); line-height: 1.7; }

/* Активный чат */
#active-chat { display: none; flex-direction: column; flex: 1; min-height: 0; position: relative; }

/* Шапка чата */
.chat-top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0; overflow: hidden; min-height: 0;
}
.back-btn { display: flex; background: none; border: none; color: var(--accent); cursor: pointer; padding: 6px; border-radius: 8px; flex-shrink: 0; transition: opacity .15s; }
.back-btn:hover { opacity: .7; }
.chat-top-info { display: flex; align-items: center; flex: 1; min-width: 0; overflow: hidden; max-width: calc(100% - 130px); }
.chat-top-status { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.online-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 4px var(--accent); animation: blink 2.5s infinite; flex-shrink: 0; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* Кнопки шапки — flex-wrap чтобы не ломалась верстка на iPhone */
.top-actions { display: flex; gap: 3px; flex-shrink: 0; align-items: center; margin-left: auto; }

/* Участники */
.users-bar { display:none !important; flex-wrap:wrap; gap:6px; padding:6px 12px; background:var(--surface); border-bottom:1px solid var(--border); max-height:80px; overflow-y:auto; }
.users-bar::-webkit-scrollbar { display: none; }
.user-chip { font-size: 10px; font-weight: 600; padding: 3px 9px; border-radius: 20px; white-space: nowrap; background: var(--surface); border: 1px solid var(--border); color: var(--muted); display: flex; align-items: center; gap: 4px; }
.user-chip.me { border-color: var(--accent); color: var(--accent); }
.admin-crown { font-size: 8px; color: #000; background: var(--accent); font-family: 'JetBrains Mono', monospace; font-weight: 700; border-radius: 3px; padding: 1px 4px; letter-spacing: .5px; }

/* Сообщения */
.msgs { flex: 1; overflow-y: auto; padding: 14px 18px 8px; display: flex; flex-direction: column; gap: 2px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.msgs::-webkit-scrollbar { width: 3px; }
.msgs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.date-divider { text-align: center; font-size: 10px; color: rgba(0,229,160,.4); font-family: 'JetBrains Mono', monospace; margin: 10px 0 6px; display: flex; align-items: center; gap: 8px; }
.date-divider::before, .date-divider::after { content: ''; flex: 1; height: 1px; background: rgba(0,229,160,.12); }

/* Группа сообщений — ВАЖНО: width:100% для Safari */
.grp { display: flex; flex-direction: column; margin-bottom: 6px; width: 100%; animation: fadeUp .18s ease; }
.grp.me    { align-items: flex-end; }
.grp.them  { align-items: flex-start; }

.grp-nick { font-size: 12px; font-weight: 700; font-family: 'JetBrains Mono', monospace; margin-bottom: 3px; padding: 0 8px; }
.me   .grp-nick { color: var(--accent); }
.them .grp-nick { color: var(--blue); }

.bubble { max-width: 68%; padding: 9px 13px; border-radius: 16px; font-size: 12px; line-height: 1.55; word-break: break-word; position: relative; }
.me   .bubble { background: var(--me-bg);  border: 1px solid var(--me-brd);  border-bottom-right-radius: 4px; }
.them .bubble { background: var(--panel);  border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.bubble-footer { display: flex; align-items: center; gap: 5px; margin-top: 4px; justify-content: flex-end; }
.msg-time { font-size: 12px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.read-mark { display: flex; align-items: center; }
.status-icon { height: 10px; flex-shrink: 0; }

/* Индикатор печатает */
.typing-bar { padding: 3px 18px; font-size: 11px; color: var(--muted); font-style: italic; min-height: 20px; flex-shrink: 0; }

/* Поле ввода */
.input-wrap {
  background: transparent;
  border-top: none;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0;
  position: relative;
}
/* Линия-разделитель снизу чата — тонкая зелёная черта вместо плашки */
.input-wrap::before {
  content: '';
  position: absolute;
  top: 8px; left: 12px; right: 12px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,229,160,.2) 30%, rgba(0,229,160,.35) 50%, rgba(0,229,160,.2) 70%, transparent);
}
.input-wrap::after {
  content: '';
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 12px; right: 12px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,229,160,.2) 30%, rgba(0,229,160,.35) 50%, rgba(0,229,160,.2) 70%, transparent);
}

.emoji-toggle { width: 38px; height: 38px; border-radius: 50%; background: rgba(0,0,0,.35); border: 1.5px solid rgba(0,229,160,.35); color: rgba(0,229,160,.8); cursor: pointer; padding: 0; line-height: 1; flex-shrink: 0; transition: all .15s; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.emoji-toggle:hover, .emoji-toggle.active { background: rgba(0,229,160,.18); color: var(--accent); border-color: var(--accent); }

.attach-btn { width: 38px; height: 38px; border-radius: 50%; background: rgba(0,0,0,.35); border: 1.5px solid rgba(0,229,160,.35); color: rgba(0,229,160,.8); cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all .15s; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.attach-btn:hover { background: rgba(0,229,160,.18); color: var(--accent); border-color: var(--accent); }

textarea#msg {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0 4px;
  font-size: 12px;
  font-family: 'Manrope', sans-serif;
  color: var(--text);
  outline: none;
  resize: none;
  max-height: 72px;
  min-height: 40px;
  overflow-y: auto;
  transition: border-color .3s, box-shadow .3s;
  line-height: 40px;
  scrollbar-width: none;
  caret-color: var(--accent);
}
textarea#msg:focus {
  box-shadow: none;
  line-height: 1.5;
  padding: 11px 4px;
}
textarea#msg::placeholder {
  color: rgba(122,143,168,0.5);
  font-style: normal;
  text-align: center;
}
textarea#msg::-webkit-scrollbar { display: none; }

.voice-btn { width: 38px; height: 38px; border-radius: 50%; background: rgba(0,0,0,.35); border: 1.5px solid rgba(0,229,160,.35); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all .15s; color: rgba(0,229,160,.8); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.voice-btn:hover { background: rgba(0,229,160,.18); color: var(--accent); }
.voice-btn.recording { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse-rec 1s infinite; }
@keyframes pulse-rec { 0%,100%{opacity:1} 50%{opacity:.6} }

.send-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all .15s; }
.send-btn:hover { background: #00cc8f; transform: scale(1.05); }
.send-btn:active { transform: scale(.95); }

/* Голосовое */
.voice-msg { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 16px; min-width: 180px; }
.me   .voice-msg { background: var(--me-bg);  border: 1px solid var(--me-brd); }
.them .voice-msg { background: var(--panel);  border: 1px solid var(--border); }
.voice-play { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: #000; transition: background .15s; }
.voice-play:hover { background: #00cc8f; }
.voice-waveform { flex: 1; height: 22px; display: flex; align-items: center; gap: 2px; }
.voice-waveform span { display: inline-block; width: 3px; border-radius: 2px; background: var(--accent); opacity: .5; }
.voice-duration { font-size: 11px; color: var(--muted); font-family: 'JetBrains Mono', monospace; white-space: nowrap; }

/* Файлы */
.file-msg { display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-width: 180px; max-width: 100%; }
.file-icon { width: 36px; height: 36px; border-radius: 10px; background: rgba(0,229,160,.1); border: 1px solid rgba(0,229,160,.2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 18px; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 10px; color: var(--muted); margin-top: 2px; }
.file-dl { background: none; border: none; color: var(--accent); cursor: pointer; padding: 5px; border-radius: 5px; display: flex; flex-shrink: 0; transition: background .15s; }
.file-dl:hover { background: rgba(0,229,160,.1); }
.img-preview { max-width: 240px; max-height: 180px; border-radius: 10px; cursor: zoom-in; display: block; object-fit: cover; }

/* Эмодзи панель */
.emoji-panel { position: absolute; bottom: 60px; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); display: none; flex-wrap: wrap; gap: 2px; padding: 10px 12px; max-height: 180px; overflow-y: auto; z-index: 10; }
.emoji-panel.open { display: flex; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 2px; }

/* Баннер комнаты */
.room-banner { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; display: flex; flex-direction: row; align-items: center; gap: 12px; }
.rb-label { display:none; }
.rb-code  { font-family: 'JetBrains Mono', monospace; font-size: 15px; font-weight: 700; letter-spacing: 3px; color: var(--accent); flex-shrink:0; }
.rb-note  { font-size: 10px; color: var(--muted); flex:1; }
.rb-copy  { font-size: 10px; font-weight: 700; color: var(--accent); cursor: pointer; background: none; border: none; padding: 0; font-family: 'JetBrains Mono', monospace; flex-shrink:0; white-space:nowrap; letter-spacing:.5px; }
.rb-copy:hover { text-decoration: underline; }

/* ── МОДАЛ ──────────────────────────────────────────────── */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; backdrop-filter: blur(4px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 26px 22px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; animation: fadeUp .2s ease; box-sizing: border-box; overflow: hidden; }
.modal-logo { text-align: center; margin-bottom: 4px; }
.modal-logo-name { font-family: 'JetBrains Mono', monospace; font-size: 22px; font-weight: 700; letter-spacing: 4px; }
.modal-logo-sub  { font-size: 10px; color: var(--muted); letter-spacing: 2px; text-transform: uppercase; margin-top: 4px; }
.field-label { font-size: 10px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }

/* Инпуты — без автозаполнения паролей */
input[type=text], input[type=search] {
  width: 100%; background: var(--panel); border: 1.5px solid var(--border); border-radius: 10px;
  padding: 11px 14px; font-size: 14px; font-family: 'Manrope', sans-serif;
  color: var(--text); outline: none; transition: border-color .2s; -webkit-appearance: none;
}
input[type=text]:focus, input[type=search]:focus { border-color: var(--accent); }
input[type=text]::placeholder, input[type=search]::placeholder { color: var(--muted); }
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--panel) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text); border-color: var(--accent) !important;
}

.btn { width: 100%; padding: 12px; border: none; border-radius: 10px; font-size: 14px; font-weight: 700; font-family: 'Manrope', sans-serif; cursor: pointer; transition: all .15s; }
.btn-green { background: var(--accent); color: #000; }
.btn-green:hover { background: #00cc8f; }
.btn-green:active { transform: scale(.98); }
.btn-green:disabled { opacity: .5; cursor: not-allowed; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.join-row { display: flex; gap: 8px; }
.join-row input { width: 110px; min-width: 90px; flex: none; font-family: 'JetBrains Mono', monospace; letter-spacing: 2px; text-transform: uppercase; font-size: 14px; text-align: center; }
.join-row .btn { flex: 1; padding: 11px 10px; font-size: 13px; white-space: nowrap; min-width: 0; }

.privacy-note { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.7; word-break: break-word; overflow-wrap: break-word; }
.privacy-note em { color: var(--accent); font-style: normal; }

/* ── ОБЩИЕ КНОПКИ ───────────────────────────────────────── */
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 7px; border-radius: 8px; display: flex; align-items: center; justify-content: center; transition: color .15s, background .15s; flex-shrink: 0; }
.icon-btn:hover { color: var(--text); background: var(--panel); }
.icon-btn.active { color: var(--accent); }

/* ── МОДАЛ — ФИКС ПЕРЕПОЛНЕНИЯ НА IPHONE ────────────────── */
/* Все дети модала не должны выходить за его границы */
.modal > * { max-width: 100%; box-sizing: border-box; }
/* anon-note: перенос текста вместо расширения */
#anon-note {
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-sizing: border-box;
  hyphens: auto;
}
/* Строка «текущий профиль» в модале — не растягивается */
/* Ник в модале — ellipsis если не влезает */
#modal-nick-display {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

/* ── ТОСТ ───────────────────────────────────────────────── */
.toast { position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(10px); background: var(--panel); border: 1px solid var(--accent); border-radius: 8px; padding: 9px 18px; font-size: 12px; color: var(--accent); font-family: 'JetBrains Mono', monospace; opacity: 0; transition: all .25s; pointer-events: none; white-space: nowrap; z-index: 999; max-width: calc(100vw - 32px); text-align: center; overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── ЛОАДЕР ─────────────────────────────────────────────── */
.loader { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 9999; opacity: 0; pointer-events: none; transition: opacity .3s; }
.loader.show { opacity: 1; pointer-events: all; }
.loader-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin: 0 4px; animation: bounce .8s infinite; }
.loader-dot:nth-child(2) { animation-delay: .15s; }
.loader-dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100%{transform:scale(.8);opacity:.4} 40%{transform:scale(1.2);opacity:1} }

/* ── ЛАЙТБОКС ───────────────────────────────────────────── */
#lightbox { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.92); display: none; align-items: center; justify-content: center; cursor: zoom-out; }
#lightbox img { max-width: 95vw; max-height: 95vh; border-radius: 8px; object-fit: contain; }
#lightbox.open { display: flex; }

/* ── РЕАКЦИИ ────────────────────────────────────────────── */
.reactions-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; padding: 0 2px; }
.reaction-chip { display: inline-flex; align-items: center; gap: 3px; background: rgba(0,229,160,.07); border: 1px solid rgba(0,229,160,.18); border-radius: 12px; padding: 2px 6px 2px 3px; cursor: pointer; transition: all .15s; user-select: none; font-size: 11px; color: var(--accent); font-weight: 600; line-height: 1.2; }
.reaction-chip.mine { background: rgba(0,229,160,.15); border-color: rgba(0,229,160,.45); }
.reaction-chip:active { transform: scale(.9); }
.reaction-chip svg { width: 13px; height: 13px; flex-shrink: 0; }

/* Попап реакций — управляется классом .open, БЕЗ inline стилей */
#reaction-popup {
  position: fixed; z-index: 500;
  display: none; flex-direction: row; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 6px; gap: 2px;
  box-shadow: 0 4px 24px rgba(0,0,0,.55);
  max-width: calc(100vw - 16px);
}
#reaction-popup.open { display: flex; }
.rp-btn { width: 22px; height: 22px; padding: 1px; background: none; border: none; border-radius: 6px; cursor: pointer; transition: background .15s; display: flex; align-items: center; justify-content: center; }
.rp-btn:hover { background: rgba(0,229,160,.12); }

/* ── ДОК-ВКЛАДКИ ────────────────────────────────────────── */
.doc-tab { background: none; border: 1px solid var(--border); color: var(--muted); font-size: 11px; font-weight: 600; font-family: 'Manrope', sans-serif; padding: 4px 10px; border-radius: 6px; cursor: pointer; transition: all .15s; white-space: nowrap; }
.doc-tab:hover, .doc-tab.active { border-color: var(--accent); color: var(--accent); background: rgba(0,229,160,.07); }
.doc-h1    { font-family: 'JetBrains Mono', monospace; font-size: 16px; font-weight: 700; color: var(--accent); letter-spacing: 1px; margin: 0 0 14px; }
.doc-h2    { font-size: 12px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); margin: 18px 0 8px; }
.doc-p     { color: #94a3b8; margin-bottom: 10px; line-height: 1.7; }
.doc-ul    { color: #94a3b8; padding-left: 16px; margin-bottom: 10px; }
.doc-ul li { margin-bottom: 5px; line-height: 1.6; }
.doc-accent{ color: var(--accent); }
.doc-border{ border-top: 1px solid var(--border); margin: 14px 0; }

/* ── КАРТОЧКА ПОЛЬЗОВАТЕЛЯ ──────────────────────────────── */
.person-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; transition: background .12s; }
.person-card:hover { background: rgba(255,255,255,.03); }
.person-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--panel); border: 1.5px solid var(--border); display: flex; align-items: center; justify-content: center; font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 700; color: var(--accent); flex-shrink: 0; overflow: hidden; }
.person-nick { font-size: 13px; font-weight: 700; font-family: 'JetBrains Mono', monospace; letter-spacing: .5px; }
.person-bio  { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ── НАСТРОЙКИ ──────────────────────────────────────────── */
.settings-row { display: flex; align-items: center; gap: 12px; background: none; border: none; width: 100%; padding: 12px 10px; border-radius: 12px; cursor: pointer; text-align: left; transition: background .12s; color: var(--text); -webkit-appearance: none; }
.settings-row:hover { background: rgba(255,255,255,.04); }
.settings-row-icon { width: 34px; height: 34px; border-radius: 10px; background: rgba(0,229,160,.08); border: 1px solid rgba(0,229,160,.15); display: flex; align-items: center; justify-content: center; color: var(--accent); flex-shrink: 0; }
.settings-row-text  { flex: 1; min-width: 0; }
.settings-row-title { font-size: 13px; font-weight: 600; color: var(--text); }
.settings-row-sub   { font-size: 11px; color: var(--muted); margin-top: 1px; }
/* Явный цвет стрелки-шеврона — переопределяет синий системный цвет iOS */
.settings-row > svg:last-child { color: var(--accent); flex-shrink: 0; }

/* ── ПОИСК В САЙДБАРЕ ───────────────────────────────────── */
#nick-search-results { padding: 0 8px 8px; flex-shrink: 0; }
.search-section-label { font-size: 9px; letter-spacing: 2px; color: var(--muted); padding: 8px 4px 4px; font-family: 'JetBrains Mono', monospace; }
.nick-result { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; border-radius: 8px; transition: background .12s; }
.nick-result:hover { background: rgba(0,229,160,.06); }
.nick-result-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--panel); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: var(--accent); font-family: 'JetBrains Mono', monospace; flex-shrink: 0; overflow: hidden; }
.nick-result-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.nick-result-name  { font-size: 12px; font-weight: 600; }
.nick-result-bio   { font-size: 10px; color: var(--muted); }
.nick-result-badge { font-size: 9px; letter-spacing: 1px; color: var(--accent); background: rgba(0,229,160,.1); border-radius: 4px; padding: 1px 5px; font-family: 'JetBrains Mono', monospace; margin-left: auto; flex-shrink: 0; }

/* ── АНИМАЦИИ ───────────────────────────────────────────── */
@keyframes fadeUp { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

/* ── МОБИЛЬНЫЙ ──────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --sidebar-w: 100%; --vbar-w: 60px; }

  /* vbar: прижата к левому краю, full height */
  #vbar {
    width: var(--vbar-w);
    height: auto;
    top: 0;
    bottom: 0;
    /* padding-top выровнен с chat-top чтобы аватарка совпадала с кнопкой назад */
    padding-top: max(8px, env(safe-area-inset-top, 8px));
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
  }
  #vbar::-webkit-scrollbar { display: none; }

  /* sidebar: от vbar до правого края, полный экран по высоте */
  #sidebar {
    left: var(--vbar-w);
    right: 0;
    width: auto;
    top: 0;
    bottom: 0;
    height: auto;
    transform: translateX(0);
    transition: transform .25s ease, opacity .25s;
  }
  #sidebar.hidden {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
  }

  /* chat-zone: fixed, от vbar до правого края */
  #chat-zone {
    position: fixed;
    left: var(--vbar-w); right: 0; top: 0; bottom: 0;
    z-index: 10;
    margin-left: 0;
  }
  #chat-zone.hidden { display: none !important; }

  /* Кнопка назад в шапке чата */
  .back-btn { display: flex !important; }
  #no-chat  { display: none !important; }

  .bubble { max-width: 82%; }
  .msgs   { padding: 12px 10px 8px; }
  textarea#msg { font-size: 12px; }

  /* Модал и оверлеи */
  #modal-overlay { padding: 12px; align-items: center; padding-top: max(12px, env(safe-area-inset-top, 12px)); }
  .modal { padding: 20px 16px; gap: 12px; max-width: 100%; }
  .modal-logo-name { font-size: 18px; letter-spacing: 3px; }
  .join-row input { width: 100px; min-width: 80px; font-size: 13px; letter-spacing: 1px; }
  .join-row .btn  { font-size: 12px; padding: 11px 8px; }
  .privacy-note { font-size: 10px; }
  
}

/* ── ПЛАНШЕТ / СРЕДНИЙ ЭКРАН ────────────────────────────── */
@media (max-width: 768px) {
  .top-actions { max-width: 160px; }
  .top-actions button { font-size: 9px; padding: 4px 7px; }
}

/* ── iOS PWA (standalone) — safe area для статус-бара ────── */
@media (display-mode: standalone) {
  .sidebar-top {
    padding-top: max(20px, env(safe-area-inset-top, 20px));
  }
  .chat-top {
    padding-top: max(12px, env(safe-area-inset-top, 12px));
  }
  #modal-overlay {
    padding-top: max(48px, calc(env(safe-area-inset-top, 20px) + 20px));
  }
  .input-wrap {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }
  /* sidebar-bottom уже fixed с padding-bottom:env(safe-area-inset-bottom) */
}


/* ── ВОЛНЫ В ФОНЕ ЧАТА ──────────────────────────────────────── */
#chat-wave-canvas { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; z-index:0; opacity:.35; }
#active-chat .chat-top { position:relative; z-index:2; }
#active-chat .users-bar { position:relative; z-index:1; }
#active-chat #pinned-msg-bar { position:relative; z-index:2; }
#active-chat .msgs { position:relative; z-index:2; }
#active-chat .typing-bar { position:relative; z-index:2; }
#active-chat .input-wrap { position:relative; z-index:2; }
#active-chat .emoji-panel { z-index:3; }
#active-chat #rename-dialog { z-index:4; }
#active-chat #voice-preview { z-index:3; }
#active-chat #file-preview { z-index:3; }

/* ── ПРОЗРАЧНЫЙ РЕЖИМ ВВОДА ─────────────────────────────── */
/* Кнопки в прозрачном input-wrap — тёмный фон чтобы читались */
.input-wrap .emoji-toggle,
.input-wrap .attach-btn,
.input-wrap .voice-btn {
  background: rgba(8,10,15,0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.input-wrap .send-btn {
  box-shadow: 0 0 16px rgba(0,229,160,0.3);
  align-self: center;
  flex-shrink: 0;
}

/* При печати — лёгкое свечение снизу */
#active-chat.typing-mode .input-wrap::before {
  background: linear-gradient(90deg, transparent, rgba(0,229,160,.15) 20%, rgba(0,229,160,.5) 50%, rgba(0,229,160,.15) 80%, transparent);
  animation: input-glow 2s ease-in-out infinite;
}
@keyframes input-glow {
  0%,100% { opacity: .6; }
  50%      { opacity: 1;  }
}

/* ── ПАНЕЛЬ ЭМОДЗИ НАД КЛАВИАТУРОЙ ─────────────────────── */
.emoji-panel {
  max-height: 200px;
  overflow-y: auto;
  background: rgba(8,10,15,0.95) !important;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0,229,160,0.2) !important;
}
.emoji-panel.open {
  display: flex !important;
}
#emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  justify-content: flex-start;
}

/* ── ЭФФЕКТ ЗАПИСИ АУДИО ────────────────────────────────── */
.voice-btn.recording {
  background: var(--danger) !important;
  border-color: var(--danger) !important;
  color: #fff !important;
  position: relative;
  overflow: visible !important;
}
/* Пульсирующие кольца вокруг кнопки записи */
.voice-btn.recording::before,
.voice-btn.recording::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--danger);
  animation: rec-ring 1.4s ease-out infinite;
}
.voice-btn.recording::after {
  inset: -10px;
  animation-delay: .7s;
}
@keyframes rec-ring {
  0%   { opacity: .8; transform: scale(1); }
  100% { opacity: 0;  transform: scale(1.6); }
}
/* Полоска визуализации записи над кнопкой */
#rec-indicator {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(8,10,15,0.92);
  border: 1px solid rgba(255,71,87,0.4);
  border-radius: 20px;
  padding: 6px 16px;
  z-index: 50;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
#rec-indicator.active { display: flex; }
.rec-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  animation: rec-dot-pulse 1s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes rec-dot-pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.4;transform:scale(.7)} }
.rec-bars {
  display: flex; align-items: center; gap: 2px; height: 20px;
}
.rec-bar {
  width: 3px; border-radius: 2px; background: var(--danger);
  animation: rec-bar-wave 1.2s ease-in-out infinite;
}
.rec-bar:nth-child(1){animation-delay:.0s; height:6px}
.rec-bar:nth-child(2){animation-delay:.15s;height:14px}
.rec-bar:nth-child(3){animation-delay:.3s; height:10px}
.rec-bar:nth-child(4){animation-delay:.45s;height:18px}
.rec-bar:nth-child(5){animation-delay:.6s; height:8px}
.rec-bar:nth-child(6){animation-delay:.75s;height:14px}
.rec-bar:nth-child(7){animation-delay:.9s; height:6px}
@keyframes rec-bar-wave {
  0%,100%{transform:scaleY(.4);opacity:.6}
  50%{transform:scaleY(1);opacity:1}
}
.rec-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--danger); font-weight: 700;
  min-width: 36px;
}


/* Android navigation bar fix */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .input-wrap {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  #vbar {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* Кнопки в списке контактов */
.contact-action-btn {
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: opacity .1s, transform .1s, background .1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.contact-action-btn:active {
  opacity: .65;
  transform: scale(.93);
}
.contact-action-btn.btn-chat {
  background: var(--accent);
  border: none;
  color: #000;
}
.contact-action-btn.btn-chat:active {
  background: #00c488;
}
.contact-action-btn.btn-call {
  background: none;
  border: 1.5px solid var(--accent);
  color: var(--accent);
}
.contact-action-btn.btn-call:active {
  background: rgba(0,229,160,.15);
}

/* ИИ-психолог — поле ввода как в основном чате */
#ai-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0 4px;
  font-size: 12px;
  font-family: 'Manrope', sans-serif;
  color: var(--text);
  outline: none;
  resize: none;
  max-height: 72px;
  min-height: 40px;
  overflow-y: auto;
  line-height: 40px;
  caret-color: var(--accent);
  width: 100%;
  scrollbar-width: none;
}
#ai-input::placeholder { color: var(--muted); }
#ai-input::-webkit-scrollbar { display: none; }
#ai-input-wrap::before {
  content: '';
  position: absolute;
  top: 0; left: 12px; right: 12px;
  height: 1px;
  background: var(--border);
}

/* Кнопки удаления в списках — только десктоп */
@media (min-width: 641px) {
  .chat-row, .contact-item {
    position: relative;
  }
  .delete-btn-desktop {
    display: flex;
    opacity: 0;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: rgba(255,71,87,.12);
    border: none;
    color: #ff4757;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: opacity .15s, background .15s;
    z-index: 10;
    flex-shrink: 0;
  }
  .chat-row:hover .delete-btn-desktop,
  .contact-item:hover .delete-btn-desktop {
    opacity: 1;
  }
  .delete-btn-desktop:hover {
    background: rgba(255,71,87,.25);
  }
  /* Отодвигаем мета-блок чата чтобы не перекрывал крестик */
  .chat-row:hover .chat-row-meta {
    margin-right: 28px;
  }
  /* Отодвигаем кнопки контакта чтобы не перекрывали крестик */
  .contact-item:hover .contact-action-btn:last-of-type {
    margin-right: 28px;
  }
}
@media (max-width: 640px) {
  .delete-btn-desktop { display: none !important; }
}

/* Оптимизация рендера */
#chats-scroll, #sb-section-contacts {
  contain: content;
}
.chat-row {
  contain: layout style;
}
