/* Цвета светлой и тёмной темы. Тема — атрибут data-theme на <html>. */
:root {
  color-scheme: light;
  --grad: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --grad-soft: linear-gradient(135deg, rgba(99,102,241,.14), rgba(168,85,247,.14));
  --accent: #6366f1;
  --accent-2: #a855f7;
  --bg: #eef0fb;
  --blob-1: rgba(99,102,241,.35);
  --blob-2: rgba(168,85,247,.30);
  --blob-3: rgba(56,189,248,.22);
  --glass: rgba(255,255,255,.68);
  --glass-strong: rgba(255,255,255,.86);
  --glass-border: rgba(255,255,255,.75);
  --surface: #fff;
  --surface-2: rgba(99,102,241,.07);
  --hover: rgba(99,102,241,.08);
  --active: rgba(99,102,241,.14);
  --border: rgba(30,30,60,.09);
  --input-bg: rgba(255,255,255,.75);
  --input-border: rgba(30,30,60,.12);
  --text: #16172b;
  --text-2: #5e6078;
  --text-3: #8b8da3;
  --bubble: rgba(255,255,255,.92);
  --bubble-text: var(--text);
  --bubble-mine-time: rgba(255,255,255,.78);
  --day-bg: rgba(255,255,255,.7);
  --placeholder: #d7d8e6;
  --secondary-btn: rgba(30,30,60,.07);
  --secondary-btn-text: #2a2b40;
  --danger: #e11d48;
  --online: #22c55e;
  --shadow: 0 8px 30px rgba(40,40,90,.10);
  --shadow-sm: 0 1px 3px rgba(40,40,90,.10);
  --drop-bg: rgba(238,240,251,.88);
  --radius: 16px;
  --radius-sm: 12px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b14;
  --blob-1: rgba(99,102,241,.28);
  --blob-2: rgba(168,85,247,.22);
  --blob-3: rgba(14,165,233,.12);
  --glass: rgba(22,22,36,.62);
  --glass-strong: rgba(26,26,42,.9);
  --glass-border: rgba(255,255,255,.07);
  --surface: #171726;
  --surface-2: rgba(255,255,255,.05);
  --hover: rgba(255,255,255,.05);
  --active: rgba(129,140,248,.18);
  --border: rgba(255,255,255,.08);
  --input-bg: rgba(255,255,255,.06);
  --input-border: rgba(255,255,255,.10);
  --text: #eceaf6;
  --text-2: #a3a3bd;
  --text-3: #75758f;
  --bubble: rgba(40,40,62,.88);
  --day-bg: rgba(40,40,62,.75);
  --placeholder: #34344d;
  --secondary-btn: rgba(255,255,255,.08);
  --secondary-btn-text: #eceaf6;
  --danger: #fb7185;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --drop-bg: rgba(11,11,20,.88);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Страница целиком не прокручивается: скроллятся только список чатов и сообщения. */
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed; inset: 0; height: 100dvh;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
  transition: background-color .3s, color .3s;
}
button, input, select { font: inherit; }
button {
  border: 0; border-radius: var(--radius-sm); padding: 9px 16px; cursor: pointer;
  background: var(--secondary-btn); color: var(--secondary-btn-text);
  transition: transform .12s, background-color .2s, opacity .2s, box-shadow .2s;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary, .send {
  background: var(--grad); color: #fff; font-weight: 600;
  box-shadow: 0 6px 16px rgba(99,102,241,.32);
}
.primary:hover, .send:hover { box-shadow: 0 8px 22px rgba(124,92,246,.42); }
.secondary { background: var(--secondary-btn); color: var(--secondary-btn-text); }
input {
  border: 1px solid var(--input-border); border-radius: var(--radius-sm); padding: 10px 12px; width: 100%;
  background: var(--input-bg); color: var(--text); transition: border-color .2s, box-shadow .2s;
}
input:focus { outline: none; border-color: rgba(99,102,241,.6); box-shadow: 0 0 0 3px rgba(99,102,241,.18); }
input::placeholder { color: var(--text-3); }
.hidden { display: none !important; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--placeholder); flex: none; display: block; }
.avatar.big { width: 96px; height: 96px; }

/* «Стекло»: полупрозрачная панель с размытием фона */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
}
.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.backdrop span { position: absolute; border-radius: 50%; filter: blur(70px); }
.backdrop span:nth-child(1) { width: 46vmax; height: 46vmax; left: -12vmax; top: -14vmax; background: var(--blob-1); }
.backdrop span:nth-child(2) { width: 40vmax; height: 40vmax; right: -10vmax; bottom: -12vmax; background: var(--blob-2); }
.backdrop span:nth-child(3) { width: 28vmax; height: 28vmax; left: 40%; top: 35%; background: var(--blob-3); }

.icon-btn {
  display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; padding: 0;
  border-radius: 50%; background: none; color: var(--text-2); cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; display: block; }
.icon-btn:hover { background: var(--hover); color: var(--accent); }

/* Переключатель темы в стиле iOS: солнце и луна */
.theme-toggle {
  position: relative; flex: none; width: 51px; height: 31px; padding: 0; border-radius: 16px;
  background: #e4e5f2; box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
  transition: background-color .25s;
}
.theme-toggle:active { transform: none; }
.theme-toggle .track-icon { position: absolute; top: 8px; width: 15px; height: 15px; transition: opacity .25s; }
.theme-toggle svg { display: block; width: 100%; height: 100%; }
.theme-toggle .track-sun { left: 7px; color: #ff9f0a; opacity: 0; }
.theme-toggle .track-moon { right: 7px; color: #8e8e93; }
.theme-toggle .knob {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.16);
  transition: transform .25s cubic-bezier(.3, 1.3, .5, 1), background-color .25s;
}
.theme-toggle .knob > span { position: absolute; inset: 5px; transition: opacity .25s, transform .25s; }
.theme-toggle .knob-sun { color: #ff9f0a; }
.theme-toggle .knob-moon { color: #fff; opacity: 0; transform: rotate(-90deg); }
:root[data-theme="dark"] .theme-toggle { background: rgba(255,255,255,.12); box-shadow: none; }
:root[data-theme="dark"] .theme-toggle .knob { transform: translateX(20px); background: var(--grad); }
:root[data-theme="dark"] .theme-toggle .knob-sun { opacity: 0; transform: rotate(90deg); }
:root[data-theme="dark"] .theme-toggle .knob-moon { opacity: 1; transform: none; }
:root[data-theme="dark"] .theme-toggle .track-sun { opacity: 1; }
:root[data-theme="dark"] .theme-toggle .track-moon { opacity: 0; }

/* ---------- Вход ---------- */
.login {
  height: 100%; display: grid; place-items: center; position: relative; overflow-y: auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.login > .theme-toggle { position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px; }
.login-card {
  width: min(380px, 100%); padding: 32px 28px; border-radius: 24px; text-align: center;
  border: 1px solid var(--glass-border); box-shadow: var(--shadow);
}
.logo { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 18px; background: var(--grad); display: grid; place-items: center; box-shadow: 0 10px 24px rgba(99,102,241,.35); }
.logo svg { width: 28px; height: 28px; color: #fff; }
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p { color: var(--text-2); margin: 0 0 4px; }
#google-btn { display: flex; justify-content: center; margin-top: 16px; min-height: 44px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 13px; margin: 18px 0 12px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.tabs { display: flex; gap: 2px; padding: 3px; border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 14px; }
.tab { flex: 1; padding: 7px 10px; border-radius: 9px; background: none; color: var(--text-2); font-size: 14px; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.auth-form .fl { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }
.auth-form .fl input { font-size: 15px; }
#login-error { text-align: left; }
.android-app { display: block; margin-top: 12px; font-size: 14px; color: var(--accent); text-decoration: none; }
.auth-form button[type="submit"] { margin-top: 6px; padding: 12px 14px; }
.auth-photo { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; color: var(--accent); font-size: 13px; margin-bottom: 4px; }
.auth-photo .avatar.big { width: 72px; height: 72px; }
.hint { color: var(--text-3); font-size: 12px; margin: 6px 0 0; }
.link-btn { background: none; color: var(--accent); padding: 8px 0 0; }
.password-fields { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* ---------- Раскладка ---------- */
.app {
  height: 100%; display: flex; gap: 12px; padding: 12px;
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
}
.sidebar, .chat { border-radius: 20px; border: 1px solid var(--glass-border); box-shadow: var(--shadow); overflow: hidden; }
.sidebar { width: 340px; flex: none; display: flex; flex-direction: column; min-height: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; background: var(--glass); -webkit-backdrop-filter: blur(22px) saturate(160%); backdrop-filter: blur(22px) saturate(160%); }

/* Боковая панель */
.side-top { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px 8px; }
.me { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; color: inherit; padding: 6px 8px; border-radius: var(--radius-sm); text-align: left; }
.me:hover { background: var(--hover); }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-text > span { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { color: var(--text-3); font-size: 12px; }
.new-chat { position: relative; padding: 4px 14px 12px; border-bottom: 1px solid var(--border); }
.new-chat input { padding-left: 38px; border-radius: 999px; }
.new-chat input::-webkit-search-cancel-button { cursor: pointer; }
.search-icon { position: absolute; left: 27px; top: 15px; width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
.lists { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
.list-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 10px 10px 4px; }
.chats-empty { color: var(--text-3); text-align: center; padding: 32px 16px; font-size: 14px; }
.chats, .search-results { list-style: none; margin: 0; padding: 0; }
.chats li, .search-results li {
  display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; cursor: pointer;
  transition: background-color .15s;
}
.chats li + li, .search-results li + li { margin-top: 2px; }
.chats li:hover, .search-results li:hover { background: var(--hover); }
.chats li.active { background: var(--active); }
.chats .info, .search-results .info { min-width: 0; flex: 1; }
.chats .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chats .name, .search-results .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chats .time { color: var(--text-3); font-size: 12px; flex: none; }
.chats li.unread .time { color: var(--accent); font-weight: 600; }
.chats .bottom { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.chats .last, .search-results .last { flex: 1; min-width: 0; color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chats .last.typing { color: var(--accent); font-style: italic; }
.search-results li.none { color: var(--text-3); cursor: default; justify-content: center; font-size: 14px; }
.search-results li.none:hover { background: none; }

/* Аватар с зелёной точкой «онлайн» */
.ava { position: relative; flex: none; }
.ava .avatar { width: 48px; height: 48px; }
.online-dot {
  position: absolute; right: 0; bottom: 1px; width: 13px; height: 13px; border-radius: 50%;
  background: var(--online); border: 2.5px solid var(--surface);
}
.peer-avatar { position: relative; flex: none; }
.peer-avatar .online-dot { width: 12px; height: 12px; right: -1px; bottom: -1px; }

/* Непрочитанные */
.badge {
  flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--grad); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
  box-shadow: 0 3px 8px rgba(99,102,241,.35);
}

/* Карточка «Приложение для Android» внизу списка чатов */
.app-card {
  display: flex; align-items: center; gap: 10px; flex: none;
  margin: 0 10px calc(10px + env(safe-area-inset-bottom)); padding: 8px 6px 8px 10px;
  border-radius: 14px; background: var(--grad-soft); border: 1px solid var(--border);
}
.app-card-icon { width: 34px; height: 34px; border-radius: 10px; flex: none; }
.app-card-info { flex: 1; min-width: 0; }
.app-card-title { font-size: 13px; font-weight: 600; line-height: 1.25; }
.app-card-version { font-size: 12px; color: var(--text-3); }
.app-card-btn {
  flex: none; padding: 7px 14px; border-radius: 10px; background: var(--grad); color: #fff;
  font-size: 13px; font-weight: 600; text-decoration: none; box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
.app-card-close { width: 30px; height: 30px; font-size: 13px; color: var(--text-3); }

/* ---------- Окно чата ---------- */
.chat-empty { margin: auto; color: var(--text-3); padding: 24px; text-align: center; max-width: 320px; }
.empty-icon { width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 24px; background: var(--grad-soft); display: grid; place-items: center; }
.empty-icon svg { width: 34px; height: 34px; color: var(--accent); }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; flex: none;
  border-bottom: 1px solid var(--border); background: var(--glass-strong); z-index: 2;
}
.peer-info { display: flex; flex-direction: column; min-width: 0; }
#peer-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-status { font-size: 12.5px; color: var(--text-3); min-height: 1.2em; }
.peer-status.online { color: var(--online); }
.peer-status.typing { color: var(--accent); }
.typing-dots { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite both; }
.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chat-head .spacer { flex: 1; }
.back { display: none; margin-left: -8px; color: var(--accent); }
.head-btn.gear { color: var(--text-3); }
.gear svg { width: 20px; height: 20px; display: block; }

.messages {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px clamp(12px, 3vw, 28px); display: flex; flex-direction: column; gap: 4px;
}
.msg {
  max-width: min(72%, 520px); padding: 8px 12px 6px; border-radius: 18px 18px 18px 6px;
  background: var(--bubble); color: var(--bubble-text); align-self: flex-start;
  box-shadow: var(--shadow-sm); animation: pop .18s ease-out;
}
.msg.mine {
  align-self: flex-end; background: var(--grad); color: #fff;
  border-radius: 18px 18px 6px 18px; box-shadow: 0 4px 14px rgba(99,102,241,.25);
}
.msg + .msg.mine, .msg.mine + .msg:not(.mine) { margin-top: 6px; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
/* Фото в сообщении: без лишних полей, время поверх картинки, если подписи нет */
.msg.has-image { padding: 4px; }
.msg.has-image .text { padding: 4px 8px 0; }
.msg.has-image .time { padding: 0 8px 4px; }
.msg.image-only { position: relative; padding: 4px; }
.msg.image-only .time {
  position: absolute; right: 10px; bottom: 10px; padding: 2px 8px; border-radius: 10px;
  background: rgba(0,0,0,.45); color: #fff; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.msg.image-only .ticks, .msg.image-only .ticks.read { color: #fff; }
.msg img { display: block; max-width: 100%; max-height: 340px; min-width: 120px; min-height: 80px; object-fit: cover; border-radius: 14px; cursor: zoom-in; background: var(--placeholder); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .time { font-size: 11px; color: var(--text-3); margin-top: 2px; display: flex; justify-content: flex-end; align-items: center; gap: 3px; }
.msg.mine .time { color: var(--bubble-mine-time); }
.day {
  align-self: center; position: sticky; top: 0; z-index: 1; font-size: 12px; font-weight: 600; color: var(--text-2);
  background: var(--day-bg); padding: 4px 12px; border-radius: 999px; margin: 10px 0;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: var(--shadow-sm);
}
.ticks { display: inline-flex; width: 16px; height: 11px; color: var(--text-3); }
.ticks svg { width: 100%; height: 100%; }
.ticks.read { color: var(--accent); }
.msg.mine .ticks { color: rgba(255,255,255,.7); }
.msg.mine .ticks.read { color: #fff; }

/* Панель ввода */
.composer {
  display: flex; align-items: flex-end; gap: 8px; flex: none; position: relative; z-index: 2;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--glass-strong);
}
.composer-main { flex: 1; min-width: 0; }
.input-wrap { position: relative; }
.input-wrap input { border-radius: 22px; padding: 10px 46px 10px 16px; min-height: 44px; }
.emoji-btn { position: absolute; right: 2px; top: 2px; }
.emoji-btn[aria-expanded="true"] { color: var(--accent); }
.attach { margin-bottom: 2px; }
.send { width: 44px; height: 44px; padding: 0; border-radius: 50%; display: grid; place-items: center; flex: none; }
.send svg { width: 20px; height: 20px; margin-left: -2px; }
.preview { position: relative; display: inline-block; margin-bottom: 8px; }
.preview img { max-height: 96px; border-radius: var(--radius-sm); display: block; cursor: zoom-in; box-shadow: var(--shadow-sm); }
.preview button { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; padding: 0; font-size: 12px; background: rgba(0,0,0,.6); color: #fff; border-radius: 50%; }

/* Эмодзи */
.emoji-panel {
  position: absolute; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 6;
  width: min(340px, calc(100% - 24px)); max-height: 260px; overflow-y: auto; padding: 8px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  border-radius: var(--radius); border: 1px solid var(--glass-border); box-shadow: var(--shadow);
  background: var(--glass-strong);
}
.emoji-panel button { background: none; padding: 0; height: 38px; font-size: 22px; border-radius: 10px; }
.emoji-panel button:hover { background: var(--hover); }

/* Перетаскивание фото */
.drop-hint {
  position: absolute; inset: 8px; z-index: 5; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: var(--radius); background: var(--drop-bg);
  color: var(--accent); font-weight: 600; pointer-events: none;
}

/* Просмотр фото */
.viewer {
  position: fixed; inset: 0; z-index: 100; background: rgba(5,5,12,.88); display: grid; place-items: center; cursor: zoom-out;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.viewer img {
  /* Картинка целиком в окне: без этого высокий скриншот вылезал за экран в приложении на Windows. */
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  width: auto; height: auto; object-fit: contain; border-radius: var(--radius-sm);
}
.viewer button { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; background: rgba(255,255,255,.15); color: #fff; font-size: 18px; border-radius: 50%; width: 40px; height: 40px; padding: 0; }

/* ---------- Звонки ---------- */
.call { position: fixed; inset: 0; z-index: 90; background: radial-gradient(circle at 30% 20%, #2a2360, #0d0d18 70%); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
/* Пока видео не пошло, вместо серой заглушки браузера — тёмный градиент (poster в index.html прозрачный). */
.call video, #devices-preview { background: radial-gradient(circle at 30% 20%, #1e1a45, #0a0a12 70%); }
#remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#local-video { position: absolute; right: 16px; top: calc(16px + env(safe-area-inset-top)); width: min(28vw, 220px); aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); z-index: 2; transform: scaleX(-1); box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.call.audio video, .call:not(.connected) #remote-video, .call.cam-off #local-video { visibility: hidden; }
.call-info { position: relative; z-index: 1; text-align: center; padding: 16px; }
.call-info .avatar.big { margin: 0 auto; width: 112px; height: 112px; box-shadow: 0 0 0 6px rgba(168,85,247,.25), 0 0 0 14px rgba(99,102,241,.12); }
.call.connected:not(.audio) .call-info { position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 16px; text-align: left; padding: 0; text-shadow: 0 1px 3px #000; }
.call.connected:not(.audio) .call-info img { display: none; }
.call-name { font-size: 24px; font-weight: 700; margin-top: 16px; }
.call-status { color: #c9cbe6; margin-top: 4px; font-variant-numeric: tabular-nums; }
.call-buttons { position: absolute; bottom: calc(32px + env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; justify-content: center; gap: 18px; z-index: 2; }
.round { width: 62px; height: 62px; border-radius: 50%; padding: 0; font-size: 24px; background: rgba(255,255,255,.16); color: #fff; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.round.off { background: #fff; color: #15161a; filter: grayscale(1); }
.round.green { background: #22c55e; }
.round.red { background: #ef4444; }
.round.gear { display: grid; place-items: center; }
.round.gear svg { width: 26px; height: 26px; color: #fff; }

/* Выбор устройств */
select {
  width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text);
}
/* Выпадающий список Chrome на Windows берёт фон у option, а не у select: задаём явно, иначе в тёмной теме светлый текст на белом. */
select option { background: var(--surface); color: var(--text); }
.devices { width: min(420px, calc(100% - 32px)); }
.devices .field { display: block; font-size: 13px; color: var(--text-2); margin-top: 14px; }
.devices video { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius-sm); background: #000; transform: scaleX(-1); }

/* ---------- Диалоги ---------- */
dialog {
  border: 1px solid var(--glass-border); border-radius: 22px; padding: 24px; width: min(380px, calc(100% - 32px));
  background: var(--glass-strong); color: var(--text); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(160%); backdrop-filter: blur(24px) saturate(160%);
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}
dialog::backdrop { background: rgba(10,10,25,.45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 16px; font-size: 20px; }
.profile-photo { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; color: var(--accent); margin-bottom: 16px; font-size: 14px; }
.profile-photo .avatar.big { margin: 0 auto; box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px rgba(129,140,248,.6); }
.row { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.row span { flex: 1; }
.link { background: none; color: var(--danger); padding: 8px 0; }

/* Предложение включить уведомления */
.push-banner {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 80;
  width: min(520px, calc(100% - 24px)); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  padding: 12px 14px; border-radius: var(--radius); color: var(--text); background: var(--glass-strong);
  border: 1px solid var(--glass-border); box-shadow: var(--shadow);
}
.push-bell { font-size: 20px; line-height: 1; }
.push-text { flex: 1; min-width: 180px; font-size: 14px; }
.push-actions { display: flex; gap: 8px; margin-left: auto; }

/* Окно «Уведомления» */
.push-setting { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.push-setting.first { margin-top: 0; padding-top: 0; border-top: 0; }
.setting-list { margin-top: 14px; border-top: 1px solid var(--border); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting-row > span { display: flex; flex-direction: column; min-width: 0; font-size: 14px; }
.setting-row small { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.setting-row .switch:disabled { opacity: .4; }
.side-top #notify-btn { margin-left: auto; }
.push-setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.switch {
  position: relative; flex: none; width: 51px; height: 31px; padding: 0; border-radius: 16px;
  background: #e4e5f2; transition: background-color .25s;
}
.switch:active { transform: none; }
:root[data-theme="dark"] .switch { background: rgba(255,255,255,.12); }
.switch[aria-checked="true"] { background: var(--grad); }
.switch .knob {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.16); transition: transform .25s;
}
.switch[aria-checked="true"] .knob { transform: translateX(20px); }

/* Без поддержки размытия делаем панели плотнее, чтобы текст читался. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass, .chat, dialog { background: var(--glass-strong); }
}

/* ---------- Телефон: показываем либо список, либо чат ---------- */
@media (max-width: 767px) {
  .app { padding: 0; gap: 0; }
  .sidebar, .chat { border-radius: 0; border: 0; box-shadow: none; }
  .sidebar { width: 100%; padding-top: env(safe-area-inset-top); }
  .chat-head { padding-top: calc(10px + env(safe-area-inset-top)); }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: inline-grid; }
  .msg { max-width: 84%; }
  .emoji-panel { left: 12px; right: 12px; width: auto; }
  .chat-head .head-btn { width: 38px; height: 38px; }
  #local-video { width: 30vw; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Беседы ---------- */
.new-chat { display: flex; align-items: center; gap: 6px; }
.new-chat input { flex: 1; min-width: 0; }
#new-group-btn { color: var(--accent); }
.group-icon { width: 15px; height: 15px; margin-right: 4px; vertical-align: -2px; color: var(--accent); }
.chat-head.group .peer-avatar, .chat-head.group .peer-info { cursor: pointer; }
.chat-head.group .peer-info:hover #peer-name { color: var(--accent); }
.msg .from { font-size: 12.5px; font-weight: 700; margin-bottom: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.has-image .from { padding: 4px 8px 2px; }
.msg.image-only.has-from .from { padding: 4px 8px 4px; }
.system-msg {
  align-self: center; max-width: 86%; margin: 6px 0; padding: 4px 12px; border-radius: 999px; text-align: center;
  font-size: 12.5px; color: var(--text-2); background: var(--day-bg);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}

.group-dialog { width: min(440px, calc(100% - 32px)); }
.group-dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 80px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
.group-fields { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.group-photo-pick { position: relative; flex: none; cursor: pointer; }
.group-photo-pick .avatar { width: 56px; height: 56px; }
.group-photo-plus {
  position: absolute; right: -2px; bottom: -2px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface); color: var(--accent);
  font-weight: 700; font-size: 16px; line-height: 1; box-shadow: var(--shadow-sm);
}
.group-fields input { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; max-height: 96px; overflow-y: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px;
  background: var(--active); color: var(--text); font-size: 13px;
}
.chip .avatar { width: 24px; height: 24px; }
.chip i { font-style: normal; font-size: 11px; color: var(--text-3); }
.chip:hover i { color: var(--danger); }
.picker-search { position: relative; }
.picker-search input { padding-left: 38px; border-radius: 999px; }
.picker-search .search-icon { left: 13px; top: 50%; transform: translateY(-50%); }
.people { list-style: none; margin: 8px -8px 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 120px; }
.people li { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; cursor: pointer; }
.people li:hover, .people li:focus-visible { background: var(--hover); outline: none; }
.people li.me-row { cursor: default; }
.people li.me-row:hover { background: none; }
.people li.none { color: var(--text-3); cursor: default; justify-content: center; font-size: 14px; padding: 20px 8px; }
.people li.none:hover { background: none; }
.people .ava .avatar { width: 40px; height: 40px; }
.people .online-dot { width: 11px; height: 11px; border-width: 2px; }
.people .info { flex: 1; min-width: 0; }
.people .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .last { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .last.online { color: var(--online); }
.people .check {
  flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--input-border);
  display: grid; place-items: center; transition: background-color .15s, border-color .15s;
}
.people li.picked .check { background: var(--grad); border-color: transparent; }
.people li.picked .check::after { content: ''; width: 10px; height: 6px; border: solid #fff; border-width: 0 0 2px 2px; transform: translate(0, -1px) rotate(-45deg); }
.people .remove { width: 32px; height: 32px; font-size: 13px; color: var(--text-3); }
.people .remove:hover { color: var(--danger); }
.group-count { font-size: 13px; color: var(--text-3); }
#ginfo .profile-photo { margin-bottom: 12px; }
#ginfo-title { text-align: center; font-weight: 600; }
.ginfo-members-head { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.ginfo-members-head .list-title { padding: 0; }
.ginfo-members-head .link-btn { padding: 4px 0; font-weight: 600; }

/* ---------- Свёрнутый звонок и уведомления ---------- */
.call-min { position: absolute; left: 16px; top: calc(16px + env(safe-area-inset-top)); z-index: 3; width: 44px; height: 44px; border-radius: 50%; padding: 0; display: grid; place-items: center; background: rgba(255,255,255,.16); color: #fff; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.call-min svg { width: 24px; height: 24px; }
.call.connected:not(.audio) .call-info { left: 72px; }
/* Видео остаются в документе, чтобы звук собеседника не прерывался. */
.call.minimized { visibility: hidden; pointer-events: none; }
.call.minimized * { visibility: hidden !important; }
.call-bar { position: fixed; top: 0; left: 0; right: 0; z-index: 80; display: flex; align-items: center; gap: 8px; padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); height: calc(44px + env(safe-area-inset-top)); background: linear-gradient(90deg, #16a34a, #22c55e); color: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.call-bar-open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; height: 100%; padding: 0 4px; background: none; color: inherit; text-align: left; }
.call-bar-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-bar-status { opacity: .9; font-variant-numeric: tabular-nums; white-space: nowrap; }
.call-bar-status::before { content: '· '; }
.call-bar-pulse { width: 10px; height: 10px; flex: none; border-radius: 50%; background: #fff; animation: call-pulse 1.4s ease-in-out infinite; }
@keyframes call-pulse { 50% { opacity: .35; transform: scale(.8); } }
.call-bar-btn { width: 34px; height: 34px; flex: none; border-radius: 50%; padding: 0; font-size: 15px; background: rgba(255,255,255,.22); color: #fff; }
.call-bar-btn.off { background: #fff; filter: grayscale(1); }
.call-bar-btn.red { background: #ef4444; }
body.call-bar-on .app { padding-top: calc(56px + env(safe-area-inset-top)); }
.toast { position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 120; max-width: min(92vw, 440px); padding: 10px 16px; border-radius: 14px; background: rgba(20,20,32,.92); color: #fff; font-size: 14px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
body.call-bar-on .toast { top: calc(56px + env(safe-area-inset-top)); }
@media (max-width: 767px) {
  body.call-bar-on .app { padding-top: calc(44px + env(safe-area-inset-top)); }
  body.call-bar-on .sidebar { padding-top: 0; }
  body.call-bar-on .chat-head { padding-top: 10px; }
}

/* Кнопка входа через Google в Android-приложении (открывает Chrome) */
.google-app-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 240px; height: 44px; padding: 0 20px; border-radius: 999px; background: #1a73e8; color: #fff; font-weight: 600; }

/* Камера собеседника выключена (кнопкой или он свернул приложение): вместо застывшего кадра — фото. */
.call.peer-cam-off #remote-video { visibility: hidden; }
.call.connected.peer-cam-off:not(.audio) .call-info { position: relative; top: auto; left: auto; text-align: center; padding: 16px; text-shadow: none; }
.call.connected.peer-cam-off:not(.audio) .call-info img { display: block; }
