:root {
  --bg: #0b0b0c;
  --panel: #1a1a1c;
  --panel-2: #242427;
  --panel-3: #2d2d31;
  --accent: #1a7cf5;
  --accent-2: #3a94ff;
  --accent-soft: #5cc8ff;
  --text: #f1f1f3;
  --text-dim: #8d8d96;
  --bubble-out: #1f5fc4;
  --bubble-in: #262629;
  --border: rgba(255,255,255,0.07);
  --radius: 26px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- Auth ---------- */
.auth-screen {
  height: 100vh;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at top, #0f2a52, #0b0b0c 70%);
}
.auth-cancel-add {
  position: absolute; top: 18px; right: 18px; width: 38px; height: 38px; border-radius: 50%;
  background: var(--panel-2); color: var(--text); border: none; font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; z-index: 20;
  transition: background .15s ease;
}
.auth-cancel-add:hover { background: var(--panel-3); }
.auth-card {
  width: 340px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 28px; padding: 32px 28px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.auth-logo { margin-bottom: 10px; }
.auth-logo img { width: 84px; height: 84px; display: block; margin: 0 auto; filter: drop-shadow(0 8px 24px rgba(26,124,245,0.35)); }
.rail-logo { width: 46px; height: 46px; margin-bottom: 14px; display: block; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 20px; }
.auth-tabs { display: flex; background: var(--panel-2); border-radius: 14px; padding: 3px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; background: none; border: none; color: var(--text-dim);
  padding: 9px 0; border-radius: 11px; cursor: pointer; font-size: 14px;
}
.auth-tab.active { background: var(--accent); color: white; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 16px; border-radius: 14px; font-size: 14px; outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-form button {
  margin-top: 6px; background: var(--accent); border: none; color: white;
  padding: 12px; border-radius: 14px; font-size: 15px; cursor: pointer; font-weight: 600;
}
.auth-form button:hover { background: var(--accent-2); }
.auth-error { color: #ff6b6b; font-size: 12px; min-height: 14px; text-align: left; }

/* ---------- App layout: три плавающие панели ---------- */
.app { display: flex; gap: 10px; height: 100vh; padding: 10px; }

.rail, .sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 100%;
}

/* левая колонка */
.rail {
  width: 84px; flex-shrink: 0;
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: 18px 6px 14px;
}
.rail-top, .rail-bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.rail-item {
  width: 100%; background: none; border: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-size: 11px; cursor: pointer; padding: 6px 0; border-radius: 14px;
}
.rail-item.active { color: var(--accent-soft); }
.rail-item:hover { color: var(--text); }
.me-name {
  font-size: 11px; color: var(--text-dim); max-width: 72px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
}
#logout-btn {
  background: none; border: none; color: var(--text-dim); font-size: 20px; cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%;
}
#logout-btn:hover { color: var(--text); background: var(--panel-2); }

.avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 17px; flex-shrink: 0;
  overflow: hidden;
}
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.small { width: 40px; height: 40px; font-size: 14px; }
.rail .avatar { width: 44px; height: 44px; font-size: 15px; }

/* список чатов */
.sidebar { width: 340px; min-width: 280px; display: flex; flex-direction: column; overflow: hidden; }

.sidebar-header {
  position: relative; display: flex; align-items: center; justify-content: center;
  padding: 18px 16px 8px;
}
.sidebar-title { font-weight: 600; font-size: 16px; }
#new-chat-btn {
  position: absolute; right: 14px; top: 50%; transform: translateY(-35%);
  background: none; border: none; color: var(--accent-soft); font-size: 20px; cursor: pointer;
  width: 36px; height: 36px; border-radius: 50%;
}
#new-chat-btn:hover { background: var(--panel-2); }

.search-box { padding: 8px 14px 10px; }
.search-box input {
  width: 100%; background: transparent; border: 1px solid rgba(255,255,255,0.14);
  color: var(--text); padding: 11px 18px; border-radius: 22px; font-size: 14px; outline: none;
  text-align: center;
}
.search-box input::placeholder { color: var(--text-dim); }
.search-box input:focus { border-color: var(--accent); text-align: left; }

.search-results, .conversation-list { overflow-y: auto; flex: 1; padding: 0 8px 10px; }

.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; margin-bottom: 2px;
  cursor: pointer; border-radius: 18px;
}
.list-item:hover { background: var(--panel-2); }
.list-item.active { background: var(--accent); }
.list-item.active .list-item-sub,
.list-item.active .list-item-time { color: rgba(255,255,255,0.8); }
.list-item.active .unread-badge { background: #fff; color: var(--accent); }

.list-item-info { flex: 1; min-width: 0; position: relative; }
.list-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.list-item-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-time { font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.list-item-sub {
  font-size: 14px; color: var(--text-dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 28px;
}

.section-label {
  padding: 10px 12px 4px; font-size: 12px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* ---------- Chat panel ---------- */
.chat-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim); text-align: center; gap: 10px;
}
.chat-empty-icon { font-size: 48px; }

.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* строка шапки: две отдельные плавающие «таблетки» — контакт и кнопки */
.chat-header-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; align-self: stretch; }

.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 20px 6px 8px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 30px; cursor: pointer;
  flex: 1; min-width: 0;
}
.chat-header-info { min-width: 0; }
.chat-header-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-status { font-size: 12px; color: var(--text-dim); }
.chat-header-status.online { color: var(--accent-soft); }

/* кнопки звонков и меню — отдельная «таблетка» справа */
.chat-header-actions {
  display: flex; align-items: center; gap: 2px; flex-shrink: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 30px; padding: 4px;
}
.chh-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none; flex-shrink: 0;
  background: transparent; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.chh-btn:hover { color: var(--text); background: var(--panel-2); }
.chh-btn.small { width: 30px; height: 30px; font-size: 16px; }

.chh-menu-wrap { position: relative; }
.chh-dropdown {
  position: absolute; top: 46px; right: 0; z-index: 20;
  min-width: 220px; padding: 6px; background: var(--panel-3);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.45);
}
.chh-item {
  padding: 11px 14px; border-radius: 11px; font-size: 14.5px; cursor: pointer;
}
.chh-item:hover { background: var(--panel-2); }

/* поиск по переписке */
.chat-search {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; margin: -2px 0 6px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 24px; align-self: stretch;
}
.chat-search-ico { color: var(--text-dim); flex-shrink: 0; }
.chat-search input {
  flex: 1; background: transparent; border: none; color: var(--text);
  padding: 8px 0; font-size: 14px; outline: none;
}
.chat-search input::placeholder { color: var(--text-dim); }
.chat-search-count { font-size: 12px; color: var(--text-dim); flex-shrink: 0; white-space: nowrap; }

.msg-row.search-match .bubble { box-shadow: 0 0 0 2px rgba(255,255,255,0.18) inset; }
.msg-row.search-current .bubble { box-shadow: 0 0 0 2px var(--accent-soft) inset; }

/* модалка «поделиться контактом» */
.share-list { width: 100%; max-height: 50vh; overflow-y: auto; margin-top: 4px; }
.share-list .list-item { padding: 9px 10px; }

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

.day-sep { display: flex; justify-content: center; margin: 14px 0 10px; }
.day-sep span {
  font-size: 13px; color: var(--text); background: rgba(255,255,255,0.08);
  padding: 3px 12px; border-radius: 12px;
}

.msg-row { display: flex; }
.msg-row.out { justify-content: flex-end; }

.bubble {
  max-width: 60%; padding: 8px 13px 6px; border-radius: 18px;
  font-size: 15px; line-height: 1.4; position: relative;
  word-wrap: break-word; white-space: pre-wrap;
}
.msg-row.in .bubble { background: var(--bubble-in); border-bottom-left-radius: 6px; }
.msg-row.out .bubble { background: var(--bubble-out); border-bottom-right-radius: 6px; }

.bubble-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 3px;
  font-size: 11px; color: rgba(255,255,255,0.55); margin-top: 3px;
}
.bubble-meta .ticks {
  flex-shrink: 0; fill: none; stroke: rgba(255,255,255,0.55);
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
  transition: stroke 0.15s ease;
}
.bubble-meta.read .ticks { stroke: #5ac8fa; }

.typing-indicator { font-size: 12px; color: var(--accent-soft); padding: 0 22px 6px; height: 18px; }

/* поле ввода — «таблетка» */
.message-form {
  display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 30px;
}
.message-form input[type="text"] {
  flex: 1; background: transparent; border: none; color: var(--text);
  padding: 10px 8px; font-size: 15px; outline: none;
}
.message-form input[type="text"]::placeholder { color: var(--text-dim); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--accent); color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--accent-2); }

/* ---------- Attachments ---------- */
.attach-btn {
  width: 42px; height: 42px; border-radius: 50%; border: none; flex-shrink: 0;
  background: transparent; color: var(--text-dim); font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.attach-btn:hover { color: var(--text); background: var(--panel-2); }

.bubble.has-img { padding: 4px 4px 6px; max-width: min(60%, 380px); }
.bubble.has-img .bubble-meta { padding: 0 9px; }
.bubble.has-img .bubble-text { padding: 6px 9px 0; }
.msg-img { display: block; max-width: 100%; max-height: 360px; border-radius: 14px; cursor: zoom-in; }

.file-card { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 200px; }
.file-icon {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.file-info { min-width: 0; }
.file-name { font-size: 14px; font-weight: 600; word-break: break-all; }
.file-size { font-size: 12px; color: rgba(255,255,255,0.6); }
.bubble-text { white-space: pre-wrap; }
.file-card + .bubble-text { margin-top: 6px; }

.drop-overlay {
  position: absolute; inset: 0; z-index: 10; border-radius: var(--radius);
  background: rgba(11,11,12,0.88); border: 2px dashed var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text); pointer-events: none;
}
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 95vw; max-height: 95vh; border-radius: 8px; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #38383d; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* узкие экраны: прячем левую колонку */
/* ---------- Settings ---------- */
.sidebar-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#settings-view { display: none; }
.app.settings-open #chats-view { display: none; }
.app.settings-open #settings-view { display: flex; }
.app.settings-open #chat-empty, .app.settings-open #chat-active { display: none !important; }

.rail .avatar { cursor: pointer; transition: box-shadow .15s ease; }
.rail .avatar.ring { box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--accent); }
.body-hidden { display: none; }
.no-ticks .bubble-meta .ticks { display: none; }

.settings-scroll { flex: 1; overflow-y: auto; padding: 0 8px 14px; }
.chev { color: var(--text-dim); font-size: 20px; line-height: 1; }

.accounts-strip { margin: 0; }
.accounts-strip:not(:empty) { margin: -4px 0 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.account-row {
  display: flex; align-items: center; gap: 14px; padding: 9px 14px;
  border-radius: 18px; cursor: pointer;
}
.account-row:hover { background: var(--panel-2); }
.account-row .avatar { width: 46px; height: 46px; font-size: 16px; flex-shrink: 0; }
.account-row-info { flex: 1; min-width: 0; }
.account-row-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-row-sub { font-size: 13px; color: var(--text-dim); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-row.add .account-row-name { color: var(--accent); font-weight: 500; }
.account-badge {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.menu-ico-plus {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); color: var(--accent); font-size: 24px; font-weight: 400; line-height: 1;
}

.profile-card {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; margin: 6px 0 10px;
  border-radius: 18px; cursor: pointer;
}
.profile-card:hover { background: var(--panel-2); }
.avatar.big { width: 70px; height: 70px; font-size: 24px; }
.avatar.huge { width: 110px; height: 110px; font-size: 38px; }
.profile-info { flex: 1; min-width: 0; }
.profile-name { font-weight: 600; font-size: 17px; }
.profile-user { font-size: 14px; color: var(--text-dim); margin-top: 2px; }

.menu-group { margin-bottom: 14px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; padding: 7px 12px;
  border-radius: 20px; cursor: pointer; font-size: 15px;
}
.menu-item:hover { background: var(--panel-2); }
.menu-item.active { background: var(--accent); color: white; }
.menu-item.active .chev, .menu-item.active .menu-value { color: rgba(255,255,255,0.8); }
.menu-item.danger .menu-label { color: #ff6b6b; }
.menu-ico {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.menu-label { flex: 1; }
.menu-value { color: var(--text-dim); font-size: 14px; }

/* правая панель настроек */
.settings-detail { display: none; flex: 1; min-height: 0; flex-direction: column; }
.app.settings-open .settings-detail { display: flex; }
.sd-header { position: relative; display: flex; align-items: center; justify-content: center; height: 52px; flex-shrink: 0; }
.sd-title { font-weight: 600; font-size: 16px; }
#sd-back {
  position: absolute; left: 0; top: 4px; width: 44px; height: 44px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  font-size: 26px; line-height: 1; cursor: pointer; padding-bottom: 3px;
}
#sd-back:hover { background: var(--panel-2); }
.sd-body { flex: 1; overflow-y: auto; padding: 10px 0 30px; }
.sd-wrap { max-width: 700px; margin: 0 auto; }
.sd-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; margin: 22px 16px 8px; }
.sd-card { background: var(--panel-2); border-radius: 18px; overflow: hidden; }
.sd-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; font-size: 15px; cursor: pointer;
}
.sd-row + .sd-row { border-top: 1px solid var(--border); }
.sd-row.danger { color: #ff6b6b; }
.sd-value { color: var(--text-dim); }
.sd-empty { text-align: center; color: var(--text-dim); margin-top: 80px; }
.sd-profile { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 20px; }

.switch { width: 46px; height: 28px; border-radius: 14px; background: #3a3a3f; position: relative; flex-shrink: 0; transition: background .15s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #1a1a1c; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on i { transform: translateX(18px); background: #fff; }

.check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid #4a4a50;
  display: flex; align-items: center; justify-content: center; font-size: 13px; color: transparent;
}
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.swatches { display: flex; gap: 14px; padding: 18px 16px; flex-wrap: wrap; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 3px var(--panel-2), 0 0 0 5px #fff; }

/* профиль */
.text-btn {
  position: absolute; right: 16px; top: 50%; transform: translateY(-30%);
  background: none; border: none; color: var(--accent-soft); font-size: 15px; cursor: pointer;
}
.sd-action {
  position: absolute; right: 0; top: 4px; height: 44px; padding: 0 18px; border-radius: 22px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  font-size: 15px; cursor: pointer;
}
.sd-action:hover { background: var(--panel-2); }

.sd-card + .sd-card, .sd-card + .sd-label { margin-top: 14px; }
.sd-profile { gap: 4px; margin-bottom: 22px; }
.sd-profile-name { font-size: 22px; font-weight: 600; margin-top: 10px; }
.sd-profile-status { font-size: 14px; color: var(--text-dim); }

.sd-info { padding: 12px 16px; }
.sd-info + .sd-info { border-top: 1px solid var(--border); }
.sd-info-label { font-size: 13px; color: var(--text-dim); margin-bottom: 3px; }
.sd-info-value { font-size: 16px; word-break: break-word; white-space: pre-wrap; }
.sd-info-value.accent { color: var(--accent-soft); }

.avatar.large { width: 64px; height: 64px; font-size: 22px; }
.sd-edit-head { display: flex; align-items: center; gap: 14px; padding: 12px 16px; }

/* аватар в режиме редактирования профиля — значок камеры поверх */
.avatar-edit-wrap { position: relative; width: 64px; height: 64px; flex-shrink: 0; cursor: pointer; }
.avatar-edit-wrap .avatar.large { width: 100%; height: 100%; }
.avatar-cam {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(0,0,0,0.38);
  color: rgba(255,255,255,0.92);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, opacity .15s ease;
}
.avatar-edit-wrap:hover .avatar-cam { background: rgba(0,0,0,0.52); }
.avatar-cam.busy { background: rgba(0,0,0,0.6); animation: avatar-pulse 1s ease-in-out infinite; }
@keyframes avatar-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.sd-input {
  width: 100%; background: transparent; border: none; outline: none;
  color: var(--text); font: inherit; font-size: 16px; padding: 14px 16px;
}
.sd-edit-head .sd-input { padding: 10px 0; }
.sd-textarea { resize: none; display: block; line-height: 1.4; }
.sd-user-row { display: flex; align-items: center; padding-left: 16px; }
.sd-user-row .sd-input { padding-left: 2px; }
.sd-at { color: var(--text-dim); font-size: 16px; }
.sd-hint { font-size: 12px; color: var(--text-dim); margin: 8px 16px 0; line-height: 1.4; }
.sd-error { color: #ff6b6b; font-size: 13px; margin: 12px 16px 0; min-height: 16px; }
.sd-logout { margin-top: 22px !important; }

.sd-date {
  background: var(--panel-3); color: var(--text); border: none; border-radius: 10px;
  padding: 7px 10px; font: inherit; font-size: 15px; color-scheme: dark; outline: none;
}
.chat-header { cursor: pointer; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 28px;
  padding: 28px 20px 20px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.modal-info { width: 100%; margin-top: 18px; }
.modal-close {
  margin-top: 16px; width: 100%; padding: 13px; border: none; border-radius: 16px;
  background: var(--panel-2); color: var(--text); font-size: 15px; cursor: pointer;
}
.modal-close:hover { background: var(--panel-3); }

/* календарь */
.cal-backdrop { position: fixed; inset: 0; z-index: 95; background: rgba(0,0,0,0.55); }
.cal-pop {
  position: fixed; width: 350px; padding: 12px 12px 14px;
  background: #1f1f22; border: 1px solid var(--border); border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { text-align: center; cursor: pointer; padding: 2px 10px; border-radius: 10px; }
.cal-title:hover { background: var(--panel-2); }
.cal-month { font-size: 15px; font-weight: 600; }
.cal-year { font-size: 12px; color: var(--text-dim); }
.cal-nav {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--accent-soft); font-size: 24px; line-height: 1;
  cursor: pointer; padding-bottom: 3px;
}
.cal-nav:disabled { opacity: .3; cursor: default; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-grid.cols4 { grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.cal-day {
  height: 42px; border: none; border-radius: 50%; background: transparent;
  color: var(--text); font: inherit; font-size: 15px; cursor: pointer;
}
.cal-day:hover:not(:disabled) { background: var(--panel-3); }
.cal-day.pill { border-radius: 16px; height: 46px; }
.cal-day.weekend { color: #ff5d4d; }
.cal-day.other { opacity: .55; }
.cal-day:disabled { opacity: .25; cursor: default; }
.cal-day.sel, .cal-day.sel:hover { background: var(--accent); color: #fff; opacity: 1; }

/* приватность */
.check.bare:not(.on) { border-color: transparent; }
.sd-link { color: var(--accent-soft); cursor: pointer; }
.sd-add { color: var(--accent-soft); font-size: 15px; }
.avatar.tiny { width: 34px; height: 34px; font-size: 12px; }
.sd-user { justify-content: flex-start; }
.sd-uinfo { flex: 1; min-width: 0; }
.sd-uname { font-size: 15px; }
.sd-usub { font-size: 12px; color: var(--text-dim); }
.sd-none { padding: 12px 16px; }
.sd-x { background: none; border: none; color: var(--text-dim); font-size: 15px; cursor: pointer; padding: 6px; }
.sd-x:hover { color: #ff6b6b; }
.sd-search .sd-input { border-bottom: 1px solid var(--border); }

@media (max-width: 860px) {
  .sidebar { width: 280px; }
}

/* ---------- Пружинка на «таблетке» шапки чата ---------- */
.chat-header { transition: transform .15s ease, background .15s ease; }
.chat-header:hover { background: var(--panel-2); }
.chat-header:active { transform: scale(.965); }
.chat-header.spring { animation: pill-spring .5s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes pill-spring {
  0%   { transform: scale(.95); }
  45%  { transform: scale(1.025); }
  72%  { transform: scale(.994); }
  100% { transform: scale(1); }
}
#chat-avatar { cursor: pointer; }

/* ---------- Страница профиля собеседника ---------- */
.contact-detail {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; background: var(--bg);
  animation: cd-in .3s cubic-bezier(.22, 1, .36, 1);
}
.contact-detail.closing { animation: cd-out .2s ease forwards; }
@keyframes cd-in  { from { opacity: 0; transform: translateX(30px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes cd-out { to { opacity: 0; transform: translateX(30px) scale(.98); } }
.app.settings-open .contact-detail { display: none !important; }
.cd-header { position: relative; height: 52px; flex-shrink: 0; display: flex; align-items: center; }
.cd-back {
  width: 44px; height: 44px; border-radius: 50%; margin-top: 4px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  font-size: 26px; line-height: 1; cursor: pointer; padding-bottom: 3px;
}
.cd-back:hover { background: var(--panel-2); }
.cd-body { flex: 1; overflow-y: auto; padding: 0 0 30px; }
.cd-wrap { max-width: 700px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; }
.avatar.cd-avatar { width: 130px; height: 130px; font-size: 44px; transition: transform .3s cubic-bezier(.34, 1.56, .64, 1); }
.avatar.cd-avatar.clickable { cursor: pointer; }
.avatar.cd-avatar.clickable:hover { transform: scale(1.05); }
.cd-name { font-size: 22px; font-weight: 600; margin-top: 14px; text-align: center; }
.cd-status { font-size: 14px; color: var(--text-dim); margin-top: 4px; }
.cd-status.online { color: var(--accent-soft); }
.cd-actions { display: flex; gap: 12px; width: 100%; margin: 22px 0 16px; }
.cd-action {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 8px; border: none; border-radius: 18px;
  background: var(--panel-2); color: var(--accent-soft); font-size: 13px; cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.cd-action:hover { background: var(--panel-3); }
.cd-action:active { transform: scale(.95); }
.cd-info { width: 100%; }

/* ---------- Просмотр аватарок ---------- */
.av-viewer {
  position: fixed; inset: 0; z-index: 110; background: rgba(0, 0, 0, 0.92);
  display: flex; flex-direction: column; animation: av-fade .2s ease;
}
@keyframes av-fade { from { opacity: 0; } to { opacity: 1; } }
.av-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 30px 30px 10px; }
.av-img { max-width: 100%; max-height: 100%; border-radius: 10px; object-fit: contain; }
.av-img.pop { animation: av-pop .3s cubic-bezier(.22, 1, .36, 1); }
@keyframes av-pop { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: scale(1); } }
.av-bar {
  flex-shrink: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 16px; padding: 12px 20px 18px;
}
.av-who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.av-who-name { font-weight: 600; font-size: 15px; color: #fff; }
.av-who-date { font-size: 13px; color: var(--text-dim); }
.av-thumbs { display: flex; gap: 6px; max-width: 50vw; overflow-x: auto; padding: 4px; scrollbar-width: none; }
.av-thumbs::-webkit-scrollbar { display: none; }
.av-thumb {
  width: 56px; height: 64px; object-fit: cover; border-radius: 8px; flex-shrink: 0;
  opacity: .55; cursor: pointer; transition: opacity .15s ease, transform .2s ease;
}
.av-thumb:hover { opacity: .85; }
.av-thumb.on { opacity: 1; transform: scale(1.08); box-shadow: 0 0 0 2px var(--accent-soft); }
.av-close {
  justify-self: end; width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, 0.12); color: #fff; font-size: 16px; cursor: pointer;
}
.av-close:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- Время внутри пузыря, как в Telegram ---------- */
.bubble.plain { display: flow-root; }
.bubble.plain .bubble-meta {
  float: right; margin: 8px 0 -3px 12px; line-height: 1.2;
  position: relative; top: 1px; white-space: nowrap;
}

/* ---------- Меню «Создать» ---------- */
#new-chat-btn { display: flex; align-items: center; justify-content: center; }
.nc-menu {
  position: fixed; z-index: 95; min-width: 240px; padding: 6px;
  background: var(--panel-3); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  transform-origin: top left; animation: nc-pop .22s cubic-bezier(.34, 1.4, .64, 1);
}
@keyframes nc-pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }
.nc-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border-radius: 12px; font-size: 15px; cursor: pointer; color: var(--text);
}
.nc-item svg { color: var(--text-dim); flex-shrink: 0; }
.nc-item:hover { background: var(--panel-2); }

/* ---------- Кружок «в сети» у аватарки ---------- */
.avatar-wrap { position: relative; flex-shrink: 0; display: flex; }
.online-dot {
  position: absolute; right: -1px; bottom: -1px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-soft); border: 2.5px solid var(--panel);
  transform: scale(0); transition: transform .25s cubic-bezier(.34, 1.56, .64, 1);
  pointer-events: none;
}
.avatar-wrap.online .online-dot { transform: scale(1); }
.list-item:hover .online-dot { border-color: var(--panel-2); }
.list-item.active .online-dot { border-color: var(--accent); background: #fff; }
.search-results .online-dot { border-color: var(--panel); }

/* ---------- Кружок с числом непрочитанных, как в Telegram ---------- */
.unread-badge {
  position: absolute; right: 0; bottom: -4px;
  display: inline-flex; align-items: center; justify-content: center;
  height: 19px; min-width: 19px; padding: 0 5px; box-sizing: border-box;
  background: var(--accent); color: white;
  border-radius: 10px; line-height: 1; font-size: 11px; font-weight: 700;
}

/* ---------- Вход по номеру телефона (в стиле Telegram) ---------- */
.auth-screen { background: var(--panel); }
.auth-stage { width: 100%; max-width: 440px; padding: 0 20px; }
.auth-step { display: flex; flex-direction: column; align-items: center; text-align: center; animation: auth-in .3s ease; }
@keyframes auth-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.auth-step.hidden { display: none; }
.auth-logo-round { width: 150px; height: 150px; object-fit: contain; margin-bottom: 20px; filter: drop-shadow(0 10px 30px rgba(26, 124, 245, 0.3)); }
.auth-logo-round.small { width: 110px; height: 110px; }
.auth-title { font-size: 30px; font-weight: 600; margin: 0 0 10px; }
.auth-title.small { font-size: 22px; margin: 0 0 18px; }
.auth-hint { color: var(--text-dim); font-size: 15px; margin: 0 0 24px; max-width: 380px; }
.phone-card { position: relative; width: 100%; max-width: 380px; background: var(--panel-2); border-radius: 18px; }
.country-btn {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  background: none; border: none; border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 17px; cursor: pointer; text-align: left;
}
.country-name { flex: 1; }
.country-chev { color: var(--text-dim); }
.country-flag { font-size: 20px; line-height: 1; }
.phone-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.phone-code { font-weight: 600; font-size: 17px; }
.phone-row input {
  flex: 1; min-width: 0; background: none; border: none; outline: none;
  color: var(--text); font-size: 17px; letter-spacing: .03em;
}
.country-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 10; max-height: 320px; overflow-y: auto;
  background: var(--panel-3); border: 1px solid var(--border); border-radius: 18px; padding: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); text-align: left;
}
.country-list.hidden { display: none; }
.country-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; cursor: pointer; font-size: 15px; }
.country-item:hover { background: var(--panel-2); }
.country-item-name { flex: 1; }
.country-item-code { color: var(--text-dim); }
.auth-error.center { text-align: center; min-height: 18px; margin-top: 10px; }
.auth-primary {
  margin-top: 8px; width: 100%; max-width: 380px; padding: 13px; border: none; border-radius: 16px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: opacity .2s ease, background .2s ease;
}
.auth-primary:hover:not(:disabled) { background: var(--accent-2); }
.auth-primary:disabled { opacity: .35; cursor: default; }
.auth-form.wide { width: 100%; max-width: 380px; }
.auth-links { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 30px; }
.auth-links a { color: var(--accent-soft); font-size: 15px; cursor: pointer; }
.auth-links a:hover { text-decoration: underline; }

/* QR-заглушка */
.qr-box { position: relative; width: 230px; height: 230px; padding: 14px; box-sizing: border-box; background: #fff; border-radius: 22px; margin-bottom: 22px; }
.qr-box svg { width: 100%; height: 100%; display: block; }
.qr-logo { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; transform: translate(-50%, -50%); border-radius: 50%; box-shadow: 0 0 0 5px #fff; }
.qr-steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 14px; max-width: 380px; text-align: left; font-size: 15px; }
.qr-steps li { display: flex; align-items: center; gap: 12px; }
.qr-num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.qr-soon { margin-top: 18px; font-size: 13px; color: var(--text-dim); max-width: 340px; }

/* ---------- Шаг «код подтверждения» ---------- */
.code-field { position: relative; width: 100%; max-width: 380px; margin-top: 6px; }
.code-field label {
  position: absolute; top: -9px; left: 18px; padding: 0 6px; z-index: 1;
  background: var(--panel); color: var(--accent-soft); font-size: 13px;
}
.code-field input {
  width: 100%; box-sizing: border-box; padding: 16px 18px; background: none;
  border: 2px solid var(--accent); border-radius: 16px; color: var(--text);
  font-size: 22px; letter-spacing: .4em; text-align: center; outline: none;
}
.edit-phone { color: var(--text-dim); font-size: 22px; cursor: pointer; margin-left: 6px; }
.edit-phone:hover { color: var(--text); }
.auth-links a.disabled { color: var(--text-dim); cursor: default; }
.auth-links a.disabled:hover { text-decoration: none; }

/* ---------- Аватарка владельца номера на шаге с паролем ---------- */
.avatar.auth-avatar {
  width: 120px; height: 120px; font-size: 42px; margin: 0 auto 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}


/* ======================================================================
   Мобильная раскладка (телефоны): как в Telegram
   список чатов на весь экран, чат выезжает поверх, снизу панель вкладок
   ====================================================================== */
.chh-back, .rail-label { display: none; }

@media (max-width: 760px) {
  body, .auth-screen { height: var(--app-h, 100dvh); }
  .auth-screen { overflow-y: auto; align-items: flex-start; }
  .auth-stage { margin: auto; padding: 24px 20px; }
  .auth-logo-round { width: 110px; height: 110px; margin-bottom: 14px; }
  .auth-logo-round.small { width: 88px; height: 88px; }
  .auth-title { font-size: 26px; }
  .auth-cancel-add { top: calc(12px + env(safe-area-inset-top)); }

  /* iOS приближает страницу, если шрифт поля меньше 16px */
  input[type="text"], input[type="tel"], input[type="password"], textarea, .sd-input, .sd-date {
    font-size: 16px !important;
  }

  .app { display: block; position: relative; height: var(--app-h, 100dvh); padding: 0; overflow: hidden; }

  /* список чатов — на весь экран */
  .sidebar {
    width: 100%; min-width: 0; height: 100%;
    border: none; border-radius: 0; background: var(--bg);
  }
  .sidebar-header { padding: calc(14px + env(safe-area-inset-top)) 16px 6px; }
  .sidebar-title { font-size: 17px; }
  .search-box { padding: 6px 14px 8px; }
  .search-results, .conversation-list { padding: 0 6px calc(104px + env(safe-area-inset-bottom)); }
  .settings-scroll { padding: 0 6px calc(104px + env(safe-area-inset-bottom)); }
  .list-item { padding: 10px 12px; border-radius: 0; margin-bottom: 0; }
  .list-item:hover { background: transparent; }
  .list-item:active { background: var(--panel-2); }
  .list-item.active { background: transparent; }
  .list-item.active .list-item-sub, .list-item.active .list-item-time { color: var(--text-dim); }
  .list-item.active .unread-badge { background: var(--accent); color: #fff; }
  .list-item.active .online-dot { border-color: var(--panel); background: var(--accent-soft); }
  .list-item .avatar { width: 58px; height: 58px; font-size: 19px; }
  .list-item-name { font-size: 16px; }
  .list-item-sub { font-size: 15px; }

  /* левая колонка превращается в плавающую панель вкладок снизу */
  .rail {
    position: fixed; z-index: 20; left: 14px; right: 14px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: auto; height: 66px; padding: 6px;
    flex-direction: row; justify-content: space-around; align-items: center;
    border-radius: 34px; background: rgba(28, 28, 31, 0.86);
    -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
  .rail-top, .rail-bottom { flex: 1; flex-direction: row; justify-content: center; height: 100%; gap: 0; }
  .rail-logo, .me-name { display: none; }
  .rail-item, .rail-bottom {
    flex: 1; height: 100%; border-radius: 28px; justify-content: center;
    flex-direction: column; align-items: center; gap: 3px; padding: 0;
  }
  .rail-item { font-size: 11px; }
  .rail-top { padding: 0; }
  .rail-item svg { width: 24px; height: 24px; }
  .rail .avatar { width: 28px; height: 28px; font-size: 11px; }
  .rail .avatar.ring { box-shadow: 0 0 0 2px var(--accent-soft); }
  .rail-label { display: block; font-size: 11px; color: var(--text-dim); }
  .app:not(.settings-open) .rail-item { background: var(--panel-3); }
  .app.settings-open .rail-item { background: none; color: var(--text-dim); }
  .app.settings-open .rail-bottom { background: var(--panel-3); }
  .app.settings-open .rail-bottom .rail-label { color: var(--accent-soft); }

  /* панель справа: чат или раздел настроек, выезжает поверх списка */
  .chat-panel {
    position: fixed; z-index: 30; top: 0; left: 0; width: 100%; height: var(--app-h, 100dvh);
    background: var(--bg); transform: translateX(100%); visibility: hidden;
    transition: transform .3s cubic-bezier(.22, 1, .36, 1), visibility 0s linear .3s;
    padding: calc(8px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom));
  }
  .app.chat-open:not(.settings-open) .chat-panel,
  .app.settings-open.detail-open .chat-panel {
    transform: none; visibility: visible; transition-delay: 0s;
  }
  .chat-empty { display: none; }

  /* шапка чата */
  .chh-back {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--panel); border: 1px solid var(--border); color: var(--text);
    font-size: 26px; line-height: 1; cursor: pointer; padding-bottom: 3px;
  }
  .chat-header-row { gap: 8px; }
  .chat-header { padding: 4px 14px 4px 5px; gap: 10px; }
  #chh-video, #chh-call { display: none; }
  .chat-header-actions { padding: 2px; }

  .messages { padding: 8px 4px; }
  .bubble { max-width: 82%; }
  .bubble.has-img { max-width: min(82%, 320px); }
  .message-form { margin-top: 4px; }
  .typing-indicator { padding: 0 14px 4px; }

  /* профиль собеседника и настройки поверх всего */
  .contact-detail { padding-top: calc(8px + env(safe-area-inset-top)); padding-left: 8px; padding-right: 8px; }
  .sd-body { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }

  .modal-card { max-width: 100%; }
  .cal-pop { max-width: calc(100vw - 16px); }
  .av-bar { grid-template-columns: 1fr auto; }
  .av-thumbs { display: none; }
}
.app.kb-open .rail { transform: translateY(130%); opacity: 0; pointer-events: none; } .rail { transition: transform .2s ease, opacity .2s ease; }
