/* ============ E2E Chat — Telegram-like light theme ============ */

:root {
  --accent: #2aabee;
  --accent-dark: #1f95d8;
  --bg-side: #ffffff;
  --bg-chat: #e7edf4;
  --bubble-in: #ffffff;
  --bubble-out: #d6ecff;
  --text: #1c2b3a;
  --muted: #8696a8;
  --border: #e3e8ef;
  --online: #4fae4e;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg-chat);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.45; }
.center { text-align: center; }

.screen { height: 100vh; }

/* ---------- аватары ---------- */
.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px; flex-shrink: 0;
  user-select: none;
}
.avatar.sm { width: 38px; height: 38px; font-size: 15px; }

/* ---------- регистрация ---------- */
#auth-screen { display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #eef4fb, #dfe9f5); }
.auth-card {
  width: min(420px, calc(100vw - 32px));
  background: #fff; border-radius: 20px; padding: 34px 32px;
  box-shadow: 0 18px 50px rgba(28, 43, 58, .16);
}
.auth-logo { font-size: 44px; text-align: center; }
.auth-card h1 { margin: 10px 0 6px; text-align: center; font-size: 26px; }
.auth-card > p { margin: 0 0 20px; text-align: center; font-size: 13.5px; line-height: 1.5; }

.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
#reg-username {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1.5px solid var(--border); border-radius: 12px; outline: none;
  transition: border-color .15s;
}
#reg-username:focus { border-color: var(--accent); }

.btn-primary {
  margin-top: 14px; width: 100%; padding: 12px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
  border: none; border-radius: 12px; cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--accent-dark); }

.auth-notes { margin: 18px 0 0; padding-left: 16px; }
.auth-notes li { margin-bottom: 6px; }

/* ---------- каркас приложения ---------- */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: 300px; min-width: 240px; background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}

.side-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.side-me-info { display: flex; flex-direction: column; min-width: 0; }
.side-me-info b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.e2e-badge {
  align-self: flex-start; margin-top: 2px;
  background: #e8f4ec; color: #2f9e44; font-size: 10.5px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; letter-spacing: .3px;
}

.chat-list { flex: 1; overflow-y: auto; }

/* ---------- сайдбар: поиск по чатам/пользователям ---------- */
.side-search { padding: 8px 10px 6px; border-bottom: 1px solid var(--border); }
.side-search input {
  width: 100%; padding: 7px 14px; font-size: 13.5px; color: var(--text);
  background: #f2f6fa; border: 1px solid transparent; border-radius: 999px; outline: none;
  transition: border-color .15s, background .15s;
}
.side-search input::placeholder { color: var(--muted); }
.side-search input:focus { background: #fff; border-color: var(--accent); }

.chat-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; cursor: pointer; border-radius: 10px; margin: 2px 6px;
}
.chat-item:hover { background: #f1f5fa; }
.chat-item.active { background: var(--accent); color: #fff; }
.chat-item.active .muted { color: rgba(255,255,255,.85); }

.chat-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-item-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.online-dot { width: 9px; height: 9px; border-radius: 50%; background: #c3ccd8; flex-shrink: 0; }
.online-dot.on { background: var(--online); }

.unread-badge {
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 999px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
}
.chat-item.active .unread-badge { background: #fff; color: var(--accent); }

.side-foot { padding: 10px 14px; border-top: 1px solid var(--border); line-height: 1.5; }

/* ---------- чат ---------- */
#chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; }
.empty-pill { background: rgba(255,255,255,.8); padding: 7px 16px; border-radius: 999px; font-size: 13.5px; color: var(--muted); box-shadow: 0 2px 8px rgba(28,43,58,.08); }

#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(42,171,238,.06) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(42,171,238,.05) 0 2px, transparent 3px),
    var(--bg-chat);
  background-size: 90px 90px, 130px 130px;
}

.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--border);
}
.chat-head-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head-info b { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: #f1f5fa; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

#back-btn { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px max(8%, 14px); display: flex; flex-direction: column; gap: 5px; }

.day-sep { align-self: center; margin: 10px 0 6px; background: rgba(255,255,255,.75); color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 3px 12px; border-radius: 999px; }

.bubble {
  position: relative;
  max-width: min(480px, 78%);
  background: var(--bubble-in); border-radius: var(--radius);
  padding: 7px 11px 6px; box-shadow: 0 1px 2.5px rgba(28,43,58,.10);
}
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 5px; }
.bubble.in { align-self: flex-start; border-bottom-left-radius: 5px; }

.bubble-text { white-space: pre-wrap; word-break: break-word; font-size: 14.8px; line-height: 1.38; }
.bubble-meta { display: inline-flex; gap: 4px; align-items: center; float: right; margin: 9px -3px -2px 8px; color: var(--muted); font-size: 11px; user-select: none; }
.bubble.out .bubble-meta { color: #6d9dbf; }

.tick { letter-spacing: -2.5px; font-weight: 700; }
.tick.pending { opacity: .45; }

/* ---------- composer ---------- */
#composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 9px max(8%, 14px) 13px; background: transparent;
}
#input {
  flex: 1; resize: none; max-height: 132px;
  border: 1px solid var(--border); border-radius: 16px;
  padding: 10px 14px; font-size: 14.8px; line-height: 1.4; outline: none;
  background: #fff; font-family: inherit; color: var(--text);
}
#input:focus { border-color: rgba(42,171,238,.55); }

#send-btn {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .15s, transform .1s;
}
#send-btn:hover { background: var(--accent-dark); }
#send-btn:active { transform: scale(.94); }
#send-btn svg { width: 23px; height: 23px; fill: #fff; stroke: none; }

/* ---------- диалог safety code ---------- */
dialog {
  border: none; border-radius: 18px; padding: 26px 24px;
  width: min(460px, calc(100vw - 32px)); box-shadow: 0 24px 70px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(15, 25, 35, .45); }
dialog h2 { margin: 0 0 8px; font-size: 19px; }
dialog h3 { margin: 18px 0 6px; font-size: 14.5px; }

.scheme { background: #f2f7fc; border-radius: 10px; padding: 9px 12px; line-height: 1.5; }

.safety-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16.5px; letter-spacing: 1px; text-align: center;
  background: #f2f7fc; border-radius: 10px; padding: 14px 10px; margin-top: 8px;
}

.fp-grid { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.fp-grid code { display: block; font-size: 10.5px; color: var(--text); opacity: .75; word-break: break-all; margin-top: 2px; }

dialog menu { list-style: none; padding: 0; margin: 20px 0 0; display: flex; justify-content: center; }
dialog .btn-primary { width: auto; min-width: 160px; margin-top: 0; }

/* ---------- диалоги: вторичная кнопка (ghost) и двухкнопочные строки ---------- */
.btn-ghost {
  width: auto; min-width: 96px; margin-top: 0; padding: 12px 18px;
  background: transparent; color: var(--text); font-size: 15px; font-weight: 600;
  border: none; border-radius: 12px; cursor: pointer; transition: background .15s;
}
.btn-ghost:hover { background: #f1f5fa; }
dialog menu.two { justify-content: flex-end; gap: 10px; }
dialog menu.two .btn-primary { min-width: 0; padding: 12px 18px; }

/* ---------- диалоги: поля и подписи ---------- */
dialog .field-label { margin-top: 14px; }
#ng-name {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1.5px solid var(--border); border-radius: 12px; outline: none;
  background: #fff; color: var(--text); transition: border-color .15s;
}
#ng-name:focus { border-color: var(--accent); }
dialog .dlg-sub { margin-top: 14px; font-weight: 600; }

/* ---------- диалоги: выбор участников (checkbox / radio) ---------- */
.member-pick {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 260px; overflow-y: auto; margin-top: 8px; padding-right: 4px;
}
.pick-row { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; cursor: pointer; }
.pick-row:hover { background: #f1f5fa; }
.pick-row input { width: 16px; height: 16px; margin: 0; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
.pick-av { flex-shrink: 0; }
.pick-name {
  font-size: 14.5px; font-weight: 500; min-width: 0; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- диалог «Участники»: строки и метка создателя ---------- */
.members-view .member-row { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; }
.creator-tag {
  margin-left: auto; flex-shrink: 0; white-space: nowrap;
  font-size: 10.5px; font-weight: 700; color: #2f9e44; background: #e8f4ec;
  padding: 2px 7px; border-radius: 999px;
}

/* ---------- сайдбар: разделы «Группы» / «Личные чаты» ---------- */
.list-section {
  padding: 10px 14px 4px; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .2px;
}
.list-hint { padding: 4px 16px; line-height: 1.5; }
.chat-item-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-new { margin-left: auto; }

/* ---------- групповые пузыри: имя отправителя ---------- */
.bubble-sender { font-size: 12.5px; font-weight: 700; margin-bottom: 2px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #2b3a49; color: #fff; font-size: 13.5px;
  padding: 10px 18px; border-radius: 12px; box-shadow: 0 8px 26px rgba(0,0,0,.28);
  z-index: 50; max-width: min(480px, calc(100vw - 40px)); text-align: center;
}

/* ---------- composer: кнопка вложения (📎) ---------- */
#attach-btn {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%;
  background: #fff; color: var(--muted); border: 1px solid var(--border);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
#attach-btn:hover { background: #f1f5fa; color: var(--accent); }
#attach-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- действия над своим сообщением (✏️ / 🗑️) ---------- */
.bubble-actions {
  position: absolute; top: -13px; right: -7px;
  display: flex; gap: 3px; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.bubble:hover > .bubble-actions,
.bubble:focus-within > .bubble-actions { opacity: 1; pointer-events: auto; }
.msg-action {
  width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(28,43,58,.22);
  border: none; cursor: pointer; font-size: 13.5px; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.msg-action:hover { background: #f1f5fa; }

/* ---------- медиа в пузыре ---------- */
.bubble-media { margin: 2px 0 3px; line-height: 0; }
.bubble-media img {
  max-width: min(360px, 72vw); max-height: 340px;
  border-radius: 10px; display: block; box-shadow: 0 1px 3px rgba(28,43,58,.18);
}
.media-name {
  font-size: 11.5px; color: var(--muted); margin-top: 4px;
  word-break: break-all; user-select: none;
}
.bubble.out .media-name { color: #6d9dbf; }

/* ---------- удалённое сообщение / пометка «изменено» ---------- */
.deleted-mark { color: var(--muted) !important; font-style: italic; opacity: .85; }
.edited-mark { font-style: italic; opacity: .72; margin-right: 3px; }

/* ---------- proof of possession: строка в safety-диалоге и метки участников ---------- */
.proof-line {
  margin-top: 10px; padding: 8px 12px; border-radius: 10px;
  font-size: 13px; font-weight: 600; line-height: 1.4;
}
.proof-line.ok { background: #e8f4ec; color: #2f9e44; }
.proof-line.warn { background: #fdf3e3; color: #b7791f; }
.proof-tag {
  margin-left: auto; flex-shrink: 0; font-size: 12.5px; font-weight: 700;
  color: #2f9e44; padding-right: 6px;
}
.proof-tag.warn { color: #b7791f; }

/* ---------- диалог редактирования: поле ввода ---------- */
#edit-input {
  width: 100%; min-height: 84px; margin-top: 12px; padding: 12px 14px;
  font-size: 15px; line-height: 1.4; border: 1.5px solid var(--border); border-radius: 12px;
  outline: none; background: #fff; color: var(--text); resize: vertical; font-family: inherit;
}
#edit-input:focus { border-color: var(--accent); }

/* ---------- скроллбары ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #c3ccd8; border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- мобильная вёрстка ---------- */
@media (max-width: 720px) {
  #sidebar { width: 100%; min-width: 0; border-right: none; position: absolute; inset: 0 auto 0 0; z-index: 5; }
  #app.chat-open #sidebar { display: none; }
  #back-btn { display: flex; }
  .messages, #composer { padding-left: 12px; padding-right: 12px; }
}

/* ============ v3 auth: вкладки вход/регистрация, сброс пароля, статус ============ */
.auth-tabs {
  display: flex; background: #f1f5fa; border-radius: 12px;
  padding: 4px; margin-bottom: 18px;
}
.auth-tab {
  flex: 1; padding: 9px 0; font-size: 14.5px; font-weight: 600; color: var(--muted);
  background: none; border: none; border-radius: 9px; cursor: pointer;
  transition: background .15s, color .15s;
}
.auth-tab.active { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(28,43,58,.12); }

/* общие поля карточки авторизации (вход / регистрация / сброс) */
.auth-card input,
.auth-card textarea {
  width: 100%; padding: 12px 14px; font-size: 15px; margin-top: 2px;
  border: 1.5px solid var(--border); border-radius: 12px; outline: none;
  background: #fff; color: var(--text); transition: border-color .15s; font-family: inherit;
}
.auth-card input:focus,
.auth-card textarea:focus { border-color: var(--accent); }
#fp-phrase {
  font-size: 13px !important; line-height: 1.5; word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.forgot-note { margin-bottom: 4px; line-height: 1.5; }
.field-hint { margin: 6px 0 12px; line-height: 1.45; }
.auth-status { margin-top: 12px; text-align: center; line-height: 1.45; min-height: 0; }
.auth-link-row { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; font-size: 13px; }
.auth-link-row a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-link-row a:hover { text-decoration: underline; }

/* ============ пикер смайлов ============ */
#chat-view { position: relative; }
#emoji-btn {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%;
  background: #fff; color: var(--muted); border: 1px solid var(--border);
  cursor: pointer; font-size: 20px; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
#emoji-btn:hover { background: #f1f5fa; }
#emoji-picker {
  position: absolute; left: max(8%, 64px); bottom: 72px; z-index: 20;
  width: min(320px, calc(100vw - 32px)); max-height: 210px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  background: #fff; border-radius: 14px; padding: 8px;
  box-shadow: 0 10px 34px rgba(28,43,58,.22);
}
.emoji-cell {
  font-size: 20px; line-height: 1; padding: 6px 0; margin: 0;
  border: none; background: none; cursor: pointer; border-radius: 6px;
}
.emoji-cell:hover { background: #f1f5fa; }

/* ============ диалоги восстановления / аккаунт (секретные данные) ============ */
.warn-note {
  margin-top: 0; padding: 9px 12px; border-radius: 10px; line-height: 1.45;
  background: #fdf3e3; color: #b7791f; font-weight: 600;
}
.secret-box { margin-top: 6px; padding: 12px 14px; background: #f2f7fc; border-radius: 10px; }
.secret-code {
  display: block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px; line-height: 1.6; word-break: break-all; color: var(--text); user-select: all;
}
.code-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.code-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; background: #f2f7fc; border-radius: 8px; padding: 6px 9px; user-select: all;
}
.copy-btn { display: inline-block; margin-top: 8px; width: auto; min-width: 0; padding: 8px 14px; font-size: 13.5px; }
.cp-btn { width: auto; min-width: 200px; margin-top: 10px; display: block; }
.btn-danger {
  width: auto; min-width: 0; margin-top: 0; padding: 12px 18px;
  background: #e5484d; color: #fff; font-size: 15px; font-weight: 600;
  border: none; border-radius: 12px; cursor: pointer; transition: filter .15s;
}
.btn-danger:hover { filter: brightness(.93); }
#me-avatar { cursor: pointer; }

/* диалог аккаунта высокий — прокрутка */
#account-dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: min(86vh, 780px); overflow-y: auto;
}
