:root {
  --bg: #0f1720;
  --bg-2: #16212c;
  --bg-3: #1d2b38;
  --line: #26384a;
  --text: #e8eef4;
  --muted: #8ea3b6;
  --accent: #35c39a;
  --accent-2: #2aa387;
  --mine: #1f6f5a;
  --danger: #e0576b;
  --radius: 14px;
  --side-w: 320px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); min-height: 1em; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0; }

/* ---------- вход ---------- */
.auth-screen {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px; gap: 14px;
  background: radial-gradient(1000px 600px at 50% -10%, #17394a 0%, var(--bg) 60%);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 20px; padding: 26px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand h1 { font-size: 22px; margin: 0; }
.brand p { margin: 2px 0 0; font-size: 13px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231c; font-weight: 800; font-size: 22px;
}
.brand-mark.big { width: 72px; height: 72px; font-size: 36px; border-radius: 20px; margin: 0 auto 12px; }
.tabs { display: flex; gap: 4px; background: var(--bg-3); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 9px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer;
}
.tab.active { background: var(--bg); color: var(--text); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.row { flex-direction: row; align-items: flex-start; gap: 8px; font-size: 12px; line-height: 1.35; }
label.row input { width: auto; margin-top: 2px; }
input, textarea {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font: inherit; outline: none; width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); }
/* поле с «глазиком»: показать/скрыть пароль */
.pwd { position: relative; display: block; width: 100%; }
.pwd input { padding-right: 40px; }
.pwd-eye {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  background: transparent; border: 0; padding: 4px 6px; border-radius: 8px;
  color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer;
}
.pwd-eye:hover { color: var(--text); }
.btn {
  border: 0; border-radius: 10px; padding: 11px 14px; font: inherit;
  font-weight: 600; cursor: pointer; background: var(--bg-3); color: var(--text);
}
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #06231c; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); font-weight: 500; }
.btn.ghost:hover { color: var(--text); border-color: var(--accent); }
.btn.small { padding: 7px 10px; font-size: 12px; }
.btn.round { border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 18px; }
.btn.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.foot { font-size: 12px; }

/* ---------- приложение ---------- */
.app { display: flex; height: 100dvh; }
/* Когда сверху висит баннер «резервный адрес», сдвигаем приложение вниз. */
.has-banner .app { margin-top: 34px; height: calc(100dvh - 34px); }
.has-banner .auth-screen { padding-top: 58px; }
.sidebar {
  width: var(--side-w); flex: none; background: var(--bg-2);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-name { font-weight: 600; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--bg-3); color: var(--accent); font-weight: 700;
}
.avatar.sm { width: 34px; height: 34px; font-size: 14px; }
.icon-btn { background: transparent; border: 0; color: var(--muted); font-size: 19px; cursor: pointer; padding: 6px; border-radius: 8px; }
.icon-btn:hover { color: var(--text); background: var(--bg-3); }
.side-actions { padding: 12px 14px; }
.side-actions .btn { width: 100%; }
.conv-list { flex: 1; overflow-y: auto; }
.conv {
  display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--bg-3);
  align-items: center;
}
.conv:hover { background: var(--bg-3); }
.conv.active { background: #14313d; }
.conv-body { min-width: 0; flex: 1; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  background: var(--accent); color: #06231c; font-size: 11px; font-weight: 700;
  border-radius: 20px; padding: 1px 7px; min-width: 20px; text-align: center;
}
.side-foot { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.side-foot .btn { flex: 1; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.empty { flex: 1; display: grid; place-items: center; text-align: center; }
.empty h2 { margin: 0 0 6px; }

.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.chat-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.chat-actions { display: flex; gap: 4px; }
.only-mobile { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }

.msg { max-width: min(70%, 560px); }
.msg.mine { align-self: flex-end; }
.msg.theirs { align-self: flex-start; }
.bubble {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 9px 12px; word-wrap: break-word; white-space: pre-wrap;
}
.msg.mine .bubble { background: var(--mine); border-color: transparent; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.msg.mine .msg-meta { justify-content: flex-end; }
.msg.decrypt-failed .bubble { background: #40222a; border-color: var(--danger); font-style: italic; color: #f0b7c0; }
.msg.deleted .bubble { background: transparent; border-style: dashed; color: var(--muted); font-style: italic; }
.del-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 11px; padding: 0; }
.del-btn:hover { color: var(--danger); }
.sender-name { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }

.typing { padding: 0 20px 4px; height: 16px; }

.composer { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--bg-2); align-items: flex-end; }
.composer textarea { resize: none; max-height: 140px; }

/* ---------- модалки ---------- */
.modal { position: fixed; inset: 0; background: rgba(3, 8, 12, .6); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; width: 100%; max-width: 460px; max-height: 88dvh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 14px; }
.modal-card .btn { margin-top: 4px; }
.list { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--bg-3); border-radius: 10px; }
.person { font-weight: 600; }
.code { font-family: ui-monospace, monospace; letter-spacing: 1px; color: var(--accent); font-size: 13px; }
.invite-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.invite-line .muted { font-size: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- мобильный ---------- */
@media (max-width: 720px) {
  .sidebar { width: 100%; position: absolute; inset: 0; z-index: 10; }
  .app.chat-open .sidebar { display: none; }
  .main { position: absolute; inset: 0; }
  .app:not(.chat-open) .main { display: none; }
  .only-mobile { display: inline-block; }
  .msg { max-width: 85%; }
}
