:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1c2733;
  --border: #0b1219;
  --text: #e8eef5;
  --muted: #7d8e9e;
  --accent: #2ea6ff;
  --accent-2: #5288c1;
  --out: #2b5278;
  --in: #182533;
  --danger: #e05555;
  --ok: #4fd18b;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  overflow: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; line-height: 1.45; }

/* ---------- Онбординг ---------- */
.onboarding {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 20% 0%, rgba(46,166,255,.12), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, rgba(82,136,193,.10), transparent 60%),
    var(--bg);
}
.onboard-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: 20px;
  padding: 32px 26px;
  box-shadow: 0 24px 70px rgba(0,0,0,.45);
  text-align: center;
}
.logo { font-size: 44px; margin-bottom: 8px; }
.onboard-card h1 { font-size: 24px; font-weight: 650; margin-bottom: 6px; }
.onboard-card .muted { margin-bottom: 22px; font-size: 13.5px; }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 14px; line-height: 1.5; }

input[type="text"], textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid rgba(255,255,255,.07);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
  outline: none;
  transition: border-color .15s;
}
input[type="text"]:focus, textarea:focus { border-color: var(--accent-2); }
textarea { resize: none; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn.primary { background: var(--accent); color: #04121f; width: 100%; }
.btn.ghost { background: transparent; color: var(--text); }
.btn.ghost:hover { background: rgba(255,255,255,.06); }
.btn.danger { background: rgba(224,85,85,.14); color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 12.5px; }

/* ---------- Каркас ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, #2ea6ff, #5288c1);
  color: #04121f;
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px;
  flex: none;
  user-select: none;
}
.avatar.small { width: 36px; height: 36px; font-size: 14px; }
.me-text { min-width: 0; }
.me-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-id { font-size: 11.5px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }

.icon-btn {
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
  font-size: 20px; line-height: 1;
  display: grid; place-items: center;
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: rgba(255,255,255,.07); color: var(--text); }
.icon-btn.back { display: none; }

.search-wrap { padding: 10px 12px; }
.search-wrap input { background: var(--panel-2); font-size: 14px; }

.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.chat-item {
  display: flex; gap: 11px; align-items: center;
  padding: 10px; border-radius: 11px; cursor: pointer;
}
.chat-item:hover { background: rgba(255,255,255,.04); }
.chat-item.active { background: rgba(46,166,255,.12); }
.chat-item .meta { flex: 1; min-width: 0; }
.chat-item .row1 { display: flex; justify-content: space-between; gap: 8px; }
.chat-item .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .time { font-size: 11px; color: var(--muted); flex: none; }
.chat-item .preview { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-item .badge {
  background: var(--accent); color: #04121f;
  font-size: 11px; font-weight: 700; border-radius: 10px;
  padding: 1px 6px; min-width: 18px; text-align: center;
}
.chat-item .unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

.side-foot {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(79,209,139,.6); }
.link-btn { margin-left: auto; background: none; border: 0; color: var(--accent-2); cursor: pointer; font: inherit; font-size: 12px; }

/* ---------- Чат ---------- */
.chat-pane { position: relative; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  color: var(--muted); text-align: center; padding: 20px;
}
.empty-icon { font-size: 46px; opacity: .5; margin-bottom: 6px; }
.empty-state h2 { font-size: 17px; color: var(--text); font-weight: 600; }

.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-height: 60px;
}
.chat-peer { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.peer-name { font-weight: 600; font-size: 14.5px; }
.peer-status { font-size: 12px; color: var(--muted); }
.peer-status.online { color: var(--ok); }
.chat-actions { display: flex; gap: 2px; }

.messages {
  flex: 1; overflow-y: auto;
  padding: 18px 16px 10px;
  display: flex; flex-direction: column; gap: 3px;
  background:
    radial-gradient(600px 400px at 50% 0%, rgba(46,166,255,.04), transparent 70%),
    var(--bg);
}
.msg { display: flex; margin: 2px 0; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: min(72%, 560px);
  background: var(--in);
  padding: 7px 11px 6px;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  font-size: 14.5px;
  line-height: 1.35;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  position: relative;
}
.msg.out .bubble {
  background: var(--out);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 4px;
}
.bubble .stamp {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; color: rgba(232,238,245,.55);
  margin-left: 8px; float: right; margin-top: 6px;
  user-select: none;
}
.bubble .state { font-size: 10px; }
.bubble .state.sent { color: rgba(232,238,245,.6); }
.bubble .state.delivered { color: #8fd0ff; }
.bubble .state.failed { color: #ff9b9b; }

.day-sep { text-align: center; margin: 14px 0 6px; font-size: 11.5px; color: var(--muted); }

.typing-indicator { padding: 4px 18px; font-size: 12px; color: var(--accent-2); min-height: 20px; }

.composer {
  display: flex; align-items: flex-end; gap: 9px;
  padding: 10px 14px 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; max-height: 140px; min-height: 42px;
  padding: 11px 14px; border-radius: 20px;
  background: var(--panel-2); font-size: 14.5px;
  line-height: 1.3;
}
.send-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: var(--accent); color: #04121f;
  font-size: 17px; cursor: pointer; flex: none;
  display: grid; place-items: center;
}
.send-btn:disabled { opacity: .4; cursor: default; }

/* ---------- Модалки ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4,10,16,.72);
  display: grid; place-items: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-card {
  width: 100%; max-width: 420px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.modal-card h3 { margin-bottom: 6px; font-size: 17px; }
.modal-card .muted { margin-bottom: 14px; }
.modal-card input + input { margin-top: 9px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.error { color: var(--danger); font-size: 12.5px; margin-top: 10px; }
.profile-row { margin: 12px 0; }
.copy-row { display: flex; gap: 8px; align-items: center; margin-top: 5px; }
.copy-row code {
  flex: 1; background: var(--panel-2); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Звонок ---------- */
.call-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: radial-gradient(600px 400px at 50% 20%, rgba(46,166,255,.16), transparent 70%), #08111a;
  display: grid; place-items: center;
}
.call-card { text-align: center; }
.call-avatar {
  width: 104px; height: 104px; border-radius: 50%;
  margin: 0 auto 18px;
  background: linear-gradient(135deg, #2ea6ff, #5288c1);
  color: #04121f; font-size: 42px; font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 0 0 10px rgba(46,166,255,.08);
}
.call-name { font-size: 22px; font-weight: 650; margin-bottom: 6px; }
.call-status { color: var(--muted); font-size: 14px; min-height: 20px; }
.call-timer { color: var(--accent-2); font-size: 14px; margin-top: 4px; min-height: 20px; font-variant-numeric: tabular-nums; }
.call-buttons { display: flex; gap: 18px; justify-content: center; margin-top: 34px; }
.call-btn {
  width: 62px; height: 62px; border-radius: 50%;
  border: 0; font-size: 24px; cursor: pointer;
  display: grid; place-items: center;
  color: #fff;
}
.call-btn.accept { background: #3ec46d; }
.call-btn.decline, .call-btn.hangup { background: #e05555; }
.call-btn.mute { background: #2a3948; }
.call-btn.mute.off { background: #e05555; }
.call-btn:hover { filter: brightness(1.12); }

/* ---------- Видеозвонок ---------- */
.call-video {
  width: min(72vw, 720px);
  max-height: 58vh;
  border-radius: 16px;
  background: #000;
  margin: 0 auto 16px;
  display: block;
}
.call-video.local {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 170px;
  max-height: 130px;
  margin: 0;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 10px;
  z-index: 70;
}
.call-video.local.off { opacity: .35; }

/* ---------- Файлы ---------- */
.bubble.file-bubble {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  min-width: 200px;
}
.file-icon { font-size: 26px; line-height: 1; }
.file-meta { min-width: 0; flex: 1; }
.file-name { font-size: 13.5px; font-weight: 600; word-break: break-all; }
.file-size { font-size: 11.5px; color: rgba(232,238,245,.55); margin: 2px 0 4px; }
.file-download {
  display: inline-block;
  font-size: 12.5px;
  color: #8fd0ff;
  text-decoration: none;
  border: 1px solid rgba(143,208,255,.4);
  border-radius: 8px;
  padding: 3px 10px;
}
.file-download:hover { background: rgba(143,208,255,.12); }
.file-progress { font-size: 11.5px; color: rgba(232,238,245,.6); }

.composer .icon-btn.attach { font-size: 19px; align-self: flex-end; margin-bottom: 3px; }

/* ---------- Доступ закрыт ---------- */
.denied {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
}
.denied-card { max-width: 360px; }
.denied-icon { font-size: 48px; margin-bottom: 12px; }
.denied-card h2 { font-size: 20px; margin-bottom: 8px; }

/* ---------- Тост ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #24313f; color: var(--text);
  padding: 10px 16px; border-radius: 10px;
  font-size: 13px; z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

/* ---------- Поиск пользователей ---------- */
.user-results {
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 10px;
  background: var(--panel-2);
}
.user-item {
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.user-item:last-child { border-bottom: 0; }
.user-item:hover { background: rgba(46,166,255,.10); }
.user-item-name { font-size: 13.5px; font-weight: 600; }
.user-item-id {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, Consolas, monospace;
}

/* ---------- Мобильная адаптация ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .chat-pane { display: none; }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .chat-pane { display: flex; }
  .icon-btn.back { display: grid; }
  .bubble { max-width: 84%; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.10); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.18); }
::-webkit-scrollbar-track { background: transparent; }
