/* ===== Темы ===== */
:root {
  --accent: #3390ec;
  --msg-size: 15px;
  --danger: #e53935;
  --online: #4fcf5c;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root, [data-theme="light"] {
  --bg: #ffffff;
  --bg-2: #f4f4f5;
  --chat-bg: #e9edf1;
  --text: #0f1419;
  --text-2: #707579;
  --border: #e6e8ea;
  --hover: #f1f2f4;
  --input-bg: #f1f2f4;
  --bubble-in: #ffffff;
  --bubble-out: color-mix(in srgb, var(--accent) 17%, #ffffff);
  --meta: #8b9298;
  --meta-out: color-mix(in srgb, var(--accent) 55%, #4a5560);
  --tick: var(--accent);
  --pill-bg: rgba(0, 0, 0, .18);
  --pill-text: #fff;
  --menu-bg: rgba(255, 255, 255, .94);
  --shadow: 0 6px 24px rgba(0, 0, 0, .14);
  --bubble-shadow: 0 1px 1px rgba(0, 0, 0, .07);
  --muted-badge: #c3c8cc;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #212121;
  --bg-2: #181818;
  --chat-bg: #0f0f0f;
  --text: #f5f5f5;
  --text-2: #9e9e9e;
  --border: #2c2c2c;
  --hover: #2b2b2b;
  --input-bg: #2b2b2b;
  --bubble-in: #232323;
  --bubble-out: color-mix(in srgb, var(--accent) 52%, #1c1c1c);
  --meta: #8a8a8a;
  --meta-out: rgba(255, 255, 255, .62);
  --tick: #fff;
  --pill-bg: rgba(255, 255, 255, .1);
  --menu-bg: rgba(40, 40, 40, .94);
  --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  --bubble-shadow: none;
  --muted-badge: #4b4b4b;
  color-scheme: dark;
}
[data-theme="night"] {
  --bg: #17212b;
  --bg-2: #0e1621;
  --chat-bg: #0e1621;
  --text: #f5f6f7;
  --text-2: #7f91a4;
  --border: #0f1923;
  --hover: #202b36;
  --input-bg: #242f3d;
  --bubble-in: #182533;
  --bubble-out: color-mix(in srgb, var(--accent) 45%, #17212b);
  --meta: #6d7f8f;
  --meta-out: rgba(255, 255, 255, .58);
  --tick: #fff;
  --pill-bg: rgba(255, 255, 255, .08);
  --menu-bg: rgba(30, 42, 54, .95);
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --bubble-shadow: none;
  --muted-badge: #3e546a;
  color-scheme: dark;
}
[data-theme="black"] {
  --bg: #000000;
  --bg-2: #0a0a0a;
  --chat-bg: #000000;
  --text: #f2f2f2;
  --text-2: #8a8a8a;
  --border: #1c1c1c;
  --hover: #141414;
  --input-bg: #161616;
  --bubble-in: #1b1b1b;
  --bubble-out: color-mix(in srgb, var(--accent) 50%, #000000);
  --meta: #7a7a7a;
  --meta-out: rgba(255, 255, 255, .6);
  --tick: #fff;
  --pill-bg: rgba(255, 255, 255, .1);
  --menu-bg: rgba(24, 24, 24, .96);
  --shadow: 0 6px 24px rgba(0, 0, 0, .7);
  --bubble-shadow: none;
  --muted-badge: #3a3a3a;
  color-scheme: dark;
}

/* ===== База ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: var(--app-h, 100dvh); overflow: hidden;
  background: var(--bg); color: var(--text); font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
#app { height: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.accent { color: var(--accent) !important; }
.dim { opacity: .55; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; }
.pad { padding: 12px 16px; }
p { margin: 0 0 8px; }

.ic { width: 22px; height: 22px; flex-shrink: 0; display: block; }
.ic.tiny { width: 15px; height: 15px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  color: var(--text-2); background: none; border: 0; padding: 0; transition: background .15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { background: var(--border); }

.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px;
  font-weight: 600; font-size: 15px; transition: filter .15s, transform .1s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.98); }
.btn.wide { width: 100%; padding: 13px; }
.btn.small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-flat {
  background: none; border: 0; color: var(--accent); padding: 8px 12px; border-radius: 8px;
  font-weight: 600; font-size: 14.5px; white-space: nowrap;
}
.btn-flat:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.btn-flat.small { padding: 4px 8px; font-size: 13px; }
.danger, .btn-flat.danger, .info-row.danger, .ctx-item.danger { color: var(--danger) !important; }
.info-row.danger .ic { color: var(--danger) !important; }
.btn-flat.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.input {
  width: 100%; background: var(--input-bg); border: 1.5px solid transparent; border-radius: 10px;
  padding: 11px 13px; font-size: 16px; color: var(--text); outline: none; transition: border-color .15s;
  resize: none;
}
.input:focus { border-color: var(--accent); background: var(--bg); }
.input::placeholder { color: var(--text-2); }
.input.big { font-size: 22px; letter-spacing: .2em; }
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }
.range { width: 100%; accent-color: var(--accent); }

/* Переключатель */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--muted-badge); border-radius: 11px; transition: background .2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.check-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; cursor: pointer; font-size: 14.5px; }

/* Аватары */
.avatar {
  border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600;
  flex-shrink: 0; overflow: hidden; user-select: none; position: relative;
  background: linear-gradient(135deg, rgba(255,255,255,.18), rgba(0,0,0,.06));
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar .ic { width: 50%; height: 50%; }
.av-wrap { position: relative; flex-shrink: 0; }
.online-dot { position: absolute; right: 1px; bottom: 1px; width: 14px; height: 14px; border-radius: 50%; background: var(--online); border: 2.5px solid var(--bg); }

.loader { width: 34px; height: 34px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.splash { height: 100%; display: grid; place-items: center; }

/* ===== Раскладка ===== */
.app { display: flex; height: 100%; overflow: hidden; }
.sidebar {
  width: 380px; min-width: 300px; flex-shrink: 0; position: relative; display: flex; flex-direction: column;
  background: var(--bg); border-right: 1px solid var(--border); overflow: hidden;
}
.main { flex: 1; position: relative; display: flex; min-width: 0; background: var(--chat-bg); overflow: hidden; }

.side-head { height: 56px; display: flex; align-items: center; gap: 8px; padding: 0 10px; flex-shrink: 0; position: relative; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; height: 40px; border-radius: 22px;
  background: var(--input-bg); padding: 0 14px; color: var(--text-2); border: 1.5px solid transparent; transition: border-color .15s;
}
.search:focus-within { border-color: var(--accent); background: var(--bg); }
.search .ic { width: 19px; height: 19px; }
.search-input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; color: var(--text); }
.search-input::-webkit-search-cancel-button { display: none; }
.app.offline .side-head::after {
  content: 'Соединение…'; position: absolute; left: 0; right: 0; top: 100%; z-index: 3;
  background: var(--accent); color: #fff; font-size: 12.5px; text-align: center; padding: 2px;
}

.chat-list { flex: 1; overflow-y: auto; padding: 2px 0 90px; overscroll-behavior: contain; }
.chat-item {
  display: flex; gap: 11px; align-items: center; width: calc(100% - 12px); margin: 0 6px; padding: 7px 9px;
  border-radius: 12px; background: none; border: 0; text-align: left; transition: background .12s;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--accent); color: #fff; }
.chat-item.active .chat-item-text, .chat-item.active .chat-item-time, .chat-item.active .ic { color: rgba(255, 255, 255, .85) !important; }
.chat-item.active .unread { background: #fff; color: var(--accent); }
.chat-item.active .online-dot { border-color: var(--accent); }
.chat-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-item-top, .chat-item-bottom { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-item-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; font-weight: 600; font-size: 15.5px; }
.chat-item-time { display: flex; align-items: center; gap: 3px; font-size: 12.5px; color: var(--text-2); flex-shrink: 0; }
.chat-item-text { flex: 1; font-size: 14.5px; color: var(--text-2); }
.chat-item-right { flex-shrink: 0; }
.unread {
  display: inline-block; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 600; line-height: 22px; text-align: center;
}
.unread.muted-badge { background: var(--muted-badge); }
.find-av { width: 54px; height: 54px; background: var(--input-bg); color: var(--accent); }
.list-empty { text-align: center; padding: 48px 28px; color: var(--text-2); }
.list-empty .ic { width: 44px; height: 44px; margin: 0 auto 12px; color: var(--accent); }
.list-empty b { display: block; color: var(--text); margin-bottom: 6px; font-size: 16px; }
.list-banners { flex-shrink: 0; }
.list-banner {
  display: flex; align-items: center; gap: 10px; margin: 4px 10px 6px; padding: 9px 6px 9px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, var(--bg)); font-size: 13.5px;
}
.list-banner > .ic { color: var(--accent); }
.list-banner.warn { background: color-mix(in srgb, #f5a623 22%, var(--bg)); }
.list-banner.warn > .ic { color: #e69100; }
.list-banner span { flex: 1; }
.fab {
  position: absolute; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; border: 0; display: grid; place-items: center; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .15s; z-index: 2;
}
.fab:hover { transform: scale(1.05); }

/* ===== Чат ===== */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; transition: margin .2s; }
.chat-empty { flex: 1; display: grid; place-items: center; }
.chat-empty-pill { display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 16px; background: var(--pill-bg); color: var(--pill-text); font-size: 14px; max-width: 80%; }
.chat-empty-pill .ic { width: 16px; height: 16px; }

.chat-head {
  height: 56px; display: flex; align-items: center; gap: 6px; padding: 0 8px 0 12px; flex-shrink: 0;
  background: var(--bg); border-bottom: 1px solid var(--border); z-index: 3;
}
.back-btn { display: none; }
.chat-head-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 11px; cursor: pointer; padding: 4px 0; }
.chat-head-text { min-width: 0; flex: 1; }
.chat-title { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 16px; min-width: 0; }
.chat-title .ic { width: 16px; height: 16px; }
.chat-sub { font-size: 13.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ttl-pill { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 500; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); padding: 1px 7px 1px 5px; border-radius: 10px; flex-shrink: 0; }
.ttl-pill .ic { width: 13px; height: 13px; }
.chat-actions { display: flex; align-items: center; }
.chat-banner:empty { display: none; }
.banner { display: flex; align-items: center; gap: 10px; padding: 9px 14px; font-size: 13.5px; cursor: default; }
.banner span { flex: 1; }
.banner.warn { background: color-mix(in srgb, #f5a623 20%, var(--bg)); }
.banner.warn > .ic { color: #e69100; }
.banner.info { background: color-mix(in srgb, var(--accent) 12%, var(--bg)); border-radius: 12px; margin: 10px 12px; }
.banner.info > .ic { color: var(--accent); }

.chat-body { flex: 1; position: relative; min-height: 0; }
.chat-scroll { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
.msgs-wrap { max-width: 780px; margin: 0 auto; padding: 8px 14px 6px; min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.msgs.pending:empty { display: none; }

.day-sep { position: sticky; top: 8px; z-index: 2; display: flex; justify-content: center; margin: 10px 0 6px; pointer-events: none; }
.day-sep span, .sys-msg span {
  background: var(--pill-bg); color: var(--pill-text); font-size: 13px; font-weight: 500; padding: 3px 11px; border-radius: 13px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.sys-msg { display: flex; justify-content: center; margin: 8px 0; text-align: center; }
.sys-msg span { max-width: 85%; }
.unread-sep { text-align: center; font-size: 13px; color: var(--text-2); background: color-mix(in srgb, var(--bg) 70%, transparent); margin: 8px -14px; padding: 4px; }

.row { display: flex; align-items: flex-end; gap: 7px; margin-top: 2px; }
.row.first { margin-top: 7px; }
.row.out { justify-content: flex-end; }
.row-av { width: 34px; flex-shrink: 0; cursor: pointer; }
.row.flash .bubble { animation: flash 1.4s; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); } }
.row.pending { opacity: .85; }

.bubble {
  position: relative; max-width: min(540px, 78%); min-width: 0; background: var(--bubble-in); color: var(--text);
  border-radius: var(--radius); padding: 6px 10px 7px; box-shadow: var(--bubble-shadow);
  font-size: var(--msg-size); line-height: 1.38; overflow-wrap: anywhere; word-break: break-word;
  user-select: text; -webkit-user-select: text; -webkit-touch-callout: none;
}
.row.out .bubble { background: var(--bubble-out); }
.row.in.last .bubble { border-bottom-left-radius: 5px; }
.row.out.last .bubble { border-bottom-right-radius: 5px; }
.text { white-space: pre-wrap; }
.text.locked { color: var(--text-2); font-style: italic; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.text.locked .ic { width: 16px; height: 16px; }
.meta {
  position: absolute; right: 9px; bottom: 5px; display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; line-height: 1; color: var(--meta); white-space: nowrap; user-select: none; pointer-events: auto;
}
.meta-pad { display: inline-flex; gap: 3px; font-size: 12px; line-height: 1; visibility: hidden; margin-left: 10px; white-space: nowrap; vertical-align: baseline; pointer-events: none; }
.meta .ic, .meta-pad .ic { width: 15px; height: 15px; }
.meta .meta-ic .ic, .meta-pad .meta-ic .ic, .meta .warn-ic .ic, .meta-pad .warn-ic .ic { width: 12px; height: 12px; }
.meta .warn-ic { color: #e69100; }
.row.out .meta { color: var(--meta-out); }
.ticks { display: inline-flex; }
.ticks.read { color: var(--tick); }
.row.out .ticks .ic { width: 16px; height: 16px; }
.sender { font-weight: 600; font-size: 13.5px; margin-bottom: 1px; }
.fwd { font-size: 13px; color: var(--accent); margin-bottom: 2px; font-weight: 500; }
.quote {
  border-left: 3px solid var(--accent); padding: 3px 8px; margin: 2px 0 5px; border-radius: 5px; cursor: pointer;
  background: color-mix(in srgb, var(--accent) 9%, transparent); min-width: 0;
}
.quote-name { font-weight: 600; font-size: 13px; }
.quote-text { font-size: 13.5px; color: var(--text-2); }
.row.out .quote { background: rgba(0, 0, 0, .05); }
[data-theme="dark"] .row.out .quote, [data-theme="night"] .row.out .quote, [data-theme="black"] .row.out .quote { background: rgba(255, 255, 255, .08); }
[data-theme="dark"] .row.out .quote-text, [data-theme="night"] .row.out .quote-text, [data-theme="black"] .row.out .quote-text { color: rgba(255,255,255,.7); }

/* Эмодзи без пузыря */
.bubble.emoji { background: none !important; box-shadow: none; padding: 0; }
.emoji-big { font-size: 46px; line-height: 1.15; padding-bottom: 20px; }
.bubble.emoji .meta { background: var(--pill-bg); color: var(--pill-text); padding: 3px 7px; border-radius: 10px; right: 0; bottom: 0; }

/* Медиа */
.bubble.media { padding: 0; overflow: hidden; }
.bubble.media > .sender, .bubble.media > .fwd, .bubble.media > .quote { margin: 6px 10px 5px; }
.bubble:not(.media) .media-box { margin: 0 -10px -7px; }
.bubble:not(.media) .media-box .thumb { border-radius: 0; }
.media-box .text { padding: 6px 10px 7px; position: relative; }
.thumb { position: relative; overflow: hidden; background: var(--hover); cursor: pointer; max-width: 100%; }
.bubble.media .thumb { border-radius: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb img.blur { filter: blur(10px); transform: scale(1.12); }
.media-only .meta, .media-only > .meta { background: rgba(0, 0, 0, .45); color: #fff !important; padding: 3px 7px; border-radius: 10px; right: 7px; bottom: 7px; }
.media-only .meta .ticks.read { color: #fff; }
.play-ov { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(0, 0, 0, .45); color: #fff; display: grid; place-items: center; }
.play-ov .ic { width: 26px; height: 26px; margin-left: 3px; }
.thumb-badge { position: absolute; left: 7px; top: 7px; background: rgba(0, 0, 0, .5); color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 9px; }
.thumb-progress { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--accent); transition: width .2s; }

/* Голосовые */
.voice-box { padding-bottom: 12px; }
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.voice-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; border: 0; display: grid; place-items: center; flex-shrink: 0; }
.voice-btn .ic { width: 20px; height: 20px; }
.voice-btn.loading { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.voice-body { flex: 1; min-width: 0; }
.voice-wave { display: flex; align-items: center; gap: 2px; height: 26px; cursor: pointer; }
.voice-wave span { flex: 1; max-width: 3px; min-height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--accent) 35%, transparent); }
.voice-wave span.on { background: var(--accent); }
.voice-time { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.row.out .voice-time { color: var(--meta-out); }

/* Файлы и звонки */
.file-box { padding-bottom: 2px; }
.file-row { display: flex; gap: 11px; align-items: center; cursor: pointer; min-width: 210px; padding: 2px 0 12px; }
.file-ic, .call-ic { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; border: 0; display: grid; place-items: center; flex-shrink: 0; }
.file-ic .ic, .call-ic .ic { width: 20px; height: 20px; }
.file-text { min-width: 0; flex: 1; }
.file-name { font-weight: 500; }
.file-sub { font-size: 13px; color: var(--text-2); }
.row.out .file-sub { color: var(--meta-out); }
.file-box .text { margin-top: -6px; }
.call-box { display: flex; align-items: center; gap: 11px; min-width: 200px; padding: 2px 0 12px; cursor: pointer; }
.call-ic.missed { background: var(--danger); }
.call-label { font-weight: 500; }
.call-sub { font-size: 13px; color: var(--text-2); }
.row.out .call-sub { color: var(--meta-out); }

.up-progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding: 0 10px 6px; }
.bubble:not(.media) .up-progress { padding: 0; }
.up-track { flex: 1; height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--accent) 25%, transparent); overflow: hidden; }
.up-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-cancel { background: none; border: 0; color: var(--accent); font-size: 13px; font-weight: 600; padding: 2px 4px; }
.err-text { color: var(--danger); font-size: 13px; flex: 1; }

.empty-hint { flex: 1; display: grid; place-items: center; padding: 20px 0; }
.empty-hint-box { max-width: 300px; text-align: center; background: var(--pill-bg); color: var(--pill-text); padding: 16px 18px; border-radius: 16px; backdrop-filter: blur(6px); }
.empty-hint-box .ic { width: 34px; height: 34px; margin: 0 auto 8px; }
.empty-hint-box b { display: block; margin-bottom: 4px; }
.empty-hint-box p { margin: 0; font-size: 13.5px; opacity: .9; }

.to-bottom {
  position: absolute; right: 18px; bottom: 14px; width: 46px; height: 46px; border-radius: 50%;
  background: var(--bg); color: var(--text-2); border: 0; display: grid; place-items: center; box-shadow: var(--shadow); z-index: 4;
}
.to-bottom .badge { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; min-width: 20px; height: 20px; line-height: 20px; border-radius: 10px; padding: 0 6px; }

/* Поле ввода */
.composer { background: var(--bg); padding: 7px 10px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); flex-shrink: 0; }
.composer > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.composer.disabled { opacity: .6; pointer-events: none; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.input-wrap { flex: 1; min-width: 0; background: var(--input-bg); border-radius: 21px; display: flex; }
.composer-input {
  flex: 1; border: 0; outline: 0; background: none; resize: none; padding: 10px 15px; font-size: 16px; line-height: 1.35;
  max-height: 180px; min-height: 42px; color: var(--text); display: block;
}
.composer-input::placeholder { color: var(--text-2); }
.attach-btn { width: 42px; height: 42px; }
.send-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; border: 0; display: grid; place-items: center; flex-shrink: 0; transition: transform .1s, background .15s; }
.send-btn:active { transform: scale(.94); }
.send-btn .ic { width: 20px; height: 20px; }
.send-btn.mic { background: none; color: var(--text-2); }
.send-btn.mic:hover { background: var(--hover); }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 2px 0 7px 4px; }
.reply-bar-text { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 9px; font-size: 13.5px; }
.reply-bar-title { color: var(--accent); font-weight: 600; }
.rec-row { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.rec-info { flex: 1; display: flex; align-items: center; gap: 10px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; min-width: 42px; }
.rec-level { flex: 1; height: 4px; border-radius: 2px; background: var(--accent); transform-origin: left; transform: scaleX(.02); transition: transform .08s; opacity: .7; }
.drop-zone { position: absolute; inset: 8px; z-index: 20; border: 2.5px dashed var(--accent); border-radius: 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); display: grid; place-items: center; color: var(--accent); font-weight: 600; pointer-events: none; }
.drop-zone > div { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.drop-zone .ic { width: 40px; height: 40px; }

/* ===== Боковые панели ===== */
.side-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 380px; max-width: 100%; z-index: 10;
  background: var(--bg); border-left: 1px solid var(--border); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s ease; box-shadow: var(--shadow);
}
.side-panel.in { transform: none; }
@media (min-width: 1240px) {
  .main.info-open .chat { margin-right: 380px; }
  .side-panel { box-shadow: none; }
}
.settings-page {
  position: absolute; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform .22s ease;
}
.settings-page.in { transform: none; }
.panel-head { height: 56px; display: flex; align-items: center; gap: 8px; padding: 0 8px; flex-shrink: 0; border-bottom: 1px solid var(--border); }
.panel-title { font-size: 18px; font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.info-section { padding: 6px; }
.info-section + .info-section, .section-title + .info-section { border-top: 1px solid var(--border); }
.section-title.pad + .info-section { border-top: 0; }
.section-title { font-size: 14px; font-weight: 600; color: var(--accent); padding: 12px 14px 4px; }
.pad .section-title { padding: 16px 0 8px; }
.info-row {
  display: flex; gap: 18px; align-items: center; width: 100%; padding: 11px 12px; border-radius: 10px;
  background: none; border: 0; color: var(--text); text-align: left; font-size: 15px; cursor: pointer;
}
button.info-row:hover, label.info-row:hover { background: var(--hover); }
.info-row.static { cursor: default; }
.info-row.static:hover { background: none; }
.info-row > .ic { color: var(--text-2); }
.info-row-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.info-row-text small { display: block; color: var(--text-2); font-size: 13px; margin-top: 1px; line-height: 1.3; }
.info-row.dimmed { opacity: .5; }
.profile-head { display: flex; flex-direction: column; align-items: center; padding: 22px 16px 14px; text-align: center; }
.profile-head .avatar { margin-bottom: 12px; font-size: 40px; }
.profile-name { font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.profile-sub { color: var(--text-2); font-size: 14px; margin-top: 2px; }
.quick-actions { display: flex; justify-content: center; gap: 10px; padding: 0 12px 14px; flex-wrap: wrap; }
.qa {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 6px 8px; min-width: 88px;
  border-radius: 12px; background: var(--input-bg); border: 0; color: var(--accent); font-size: 13px; font-weight: 500;
}
.qa:hover { filter: brightness(.97); }
.member { display: flex; align-items: center; gap: 12px; width: 100%; padding: 7px 12px; border-radius: 10px; background: none; border: 0; text-align: left; }
.member:hover { background: var(--hover); }
.member-text { flex: 1; min-width: 0; }
.member-text small { display: block; color: var(--text-2); font-size: 13px; }
.role-badge { font-size: 12px; color: var(--accent); font-weight: 500; }
.me-card { display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px; background: none; border: 0; text-align: left; border-bottom: 1px solid var(--border); }
.me-card:hover { background: var(--hover); }
.me-card-text { flex: 1; min-width: 0; }
.me-name { font-size: 18px; font-weight: 600; }

.theme-preview { background: var(--chat-bg); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.theme-preview .row.out + .row.in, .theme-preview .row.in + .row.out { margin-top: 6px; }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 0; color: #fff; display: grid; place-items: center; transition: transform .12s; }
.swatch.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text-2); }
.swatch:hover { transform: scale(1.08); }
.radio-list { display: flex; flex-direction: column; }
.radio-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 8px; border-radius: 8px; background: none; border: 0; text-align: left; font-size: 15px; }
.radio-item:hover { background: var(--hover); }
.radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--text-2); flex-shrink: 0; transition: all .15s; }
.radio-item.on .radio { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 4px var(--bg); }
.prose ul { padding-left: 20px; margin: 8px 0 12px; }
.prose li { margin-bottom: 8px; line-height: 1.45; }
.about-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0 16px; font-size: 18px; }
.about-hero .ic { width: 48px; height: 48px; color: var(--accent); }
.fingerprint { background: var(--input-bg); border-radius: 12px; padding: 12px; text-align: center; }
.fingerprint code { font-size: 12.5px; color: var(--text-2); word-break: break-all; display: block; margin-top: 6px; line-height: 1.6; }
.invite-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 22px; text-align: center; padding: 14px; background: var(--input-bg); border-radius: 12px; letter-spacing: .06em; user-select: all; }

.safety { text-align: center; }
.safety-emoji { font-size: 30px; letter-spacing: 6px; margin: 4px 0 12px; }
.safety-digits { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 16px; margin-bottom: 14px; }
.safety .banner { border-radius: 10px; margin-bottom: 12px; text-align: left; }

.avatar-pick { width: 96px; height: 96px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; overflow: hidden; flex-shrink: 0; margin: 0 auto; }
.avatar-pick img { width: 100%; height: 100%; object-fit: cover; }
.avatar-pick .ic { width: 34px; height: 34px; }
.group-head { display: flex; align-items: center; gap: 14px; }
.group-head .avatar-pick { width: 72px; height: 72px; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--input-bg); border-radius: 16px; padding: 2px 4px 2px 2px; font-size: 14px; }
.chip button { background: none; border: 0; padding: 2px; display: grid; color: var(--text-2); }
.chip button .ic { width: 16px; height: 16px; }
.lookup-row { display: flex; gap: 8px; }
.lookup-result { margin-top: 6px; }
.pick-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; border-radius: 10px; background: none; border: 0; text-align: left; font-size: 15px; }
.pick-item:hover { background: var(--hover); }
.pick-item > .ic { color: var(--text-2); }
.pick-list { max-height: 50vh; overflow-y: auto; margin-top: 8px; }
.send-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; margin-bottom: 10px; max-height: 40vh; overflow-y: auto; }
.send-previews img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.send-file { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--input-bg); border-radius: 10px; }
.send-file span { flex: 1; }
.send-file small { color: var(--text-2); }

/* ===== Модальные окна, меню, тосты ===== */
.modal-back {
  position: fixed; inset: 0; z-index: 350; background: rgba(0, 0, 0, .42); display: grid; place-items: center; padding: 16px;
  animation: fade .16s ease;
}
.modal-back.out { opacity: 0; transition: opacity .16s; }
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--bg); border-radius: 16px; width: min(420px, 100%); max-height: calc(var(--app-h, 100dvh) - 32px); overflow-y: auto;
  padding: 18px 18px 10px; box-shadow: var(--shadow); animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.95); opacity: 0; } }
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 12px; }
.modal-body { font-size: 15px; }
.modal-body p { line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; gap: 4px; margin-top: 12px; flex-wrap: wrap; }
.ctx-back { position: fixed; inset: 0; z-index: 359; }
.ctx-menu {
  position: fixed; z-index: 360; min-width: 210px; max-width: 280px; padding: 5px; border-radius: 12px;
  background: var(--menu-bg); box-shadow: var(--shadow); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  opacity: 0; transform: scale(.96); transform-origin: top left; transition: opacity .12s, transform .12s;
}
.ctx-menu.in { opacity: 1; transform: none; }
.ctx-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 9px 12px; border-radius: 8px; background: none; border: 0; text-align: left; font-size: 14.5px; font-weight: 500; }
.ctx-item:hover { background: var(--hover); }
.ctx-item .ic { width: 20px; height: 20px; color: var(--text-2); }
.ctx-item.danger .ic { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.toasts { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: rgba(30, 30, 30, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); animation: pop .18s ease; transition: opacity .3s; text-align: center; }
.toast.err { background: rgba(200, 40, 40, .95); }
.toast.out { opacity: 0; }

/* ===== Просмотр медиа ===== */
.viewer { position: fixed; inset: 0; z-index: 250; background: rgba(0, 0, 0, .94); display: flex; flex-direction: column; animation: fade .15s; }
.viewer-top { display: flex; align-items: center; gap: 4px; padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px; color: #fff; }
.viewer-top .icon-btn { color: #fff; }
.viewer-top .icon-btn:hover { background: rgba(255, 255, 255, .12); }
.viewer-info { flex: 1; font-size: 14px; opacity: .85; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-stage { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 8px calc(8px + env(safe-area-inset-bottom)); position: relative; }
.viewer-media { max-width: 100%; max-height: calc(var(--app-h, 100dvh) - 80px); object-fit: contain; border-radius: 4px; grid-area: 1 / 1; }
.viewer-media.blur { filter: blur(14px); width: min(90vw, 600px); }
.viewer-progress { color: #fff; grid-area: 1 / 1; background: rgba(0, 0, 0, .5); padding: 6px 12px; border-radius: 12px; font-size: 14px; z-index: 1; }

/* ===== Звонок ===== */
.call {
  position: fixed; inset: 0; z-index: 300; background: #0d1117; color: #fff; display: flex; flex-direction: column; align-items: center;
  overflow: hidden; transition: opacity .6s; animation: fade .2s;
}
.call.ending { opacity: .4; pointer-events: none; }
.call-bg { position: absolute; inset: 0; background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--accent) 45%, #0d1117), #0d1117 70%); }
.call-bg img { width: 100%; height: 100%; object-fit: cover; filter: blur(48px) brightness(.55); transform: scale(1.2); }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; background: #000; transition: opacity .3s; pointer-events: none; }
.call.has-video .call-remote { opacity: 1; }
.call.has-video .call-center .avatar { display: none; }
.call.has-video .call-center { margin-top: 8px; text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.call-top { position: relative; z-index: 2; padding-top: calc(14px + env(safe-area-inset-top)); }
.call-key { display: flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, .14); padding: 5px 12px; border-radius: 16px; font-size: 14px; backdrop-filter: blur(8px); }
.call-key .ic { width: 15px; height: 15px; }
.call-center { position: relative; z-index: 2; margin-top: 11vh; text-align: center; display: flex; flex-direction: column; align-items: center; }
.call-center .avatar { margin-bottom: 18px; font-size: 46px; box-shadow: 0 0 0 10px rgba(255,255,255,.06), 0 0 0 22px rgba(255,255,255,.03); }
.call-name { font-size: 26px; font-weight: 600; padding: 0 20px; }
.call-status { opacity: .8; margin-top: 4px; font-size: 16px; font-variant-numeric: tabular-nums; }
.call-local { position: absolute; z-index: 3; right: 14px; top: calc(64px + env(safe-area-inset-top)); width: 112px; height: 160px; object-fit: cover; border-radius: 14px; background: #000; box-shadow: 0 4px 16px rgba(0, 0, 0, .5); }
@media (min-width: 761px) { .call-local { width: 220px; height: 140px; } }
.call-local.mirror { transform: scaleX(-1); }
.call-btns { position: absolute; z-index: 3; bottom: calc(34px + env(safe-area-inset-bottom)); display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; padding: 0 12px; }
.cbtn-wrap { display: flex; flex-direction: column; align-items: center; gap: 7px; font-size: 12.5px; opacity: .95; width: 72px; text-align: center; }
.cbtn { width: 62px; height: 62px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .18); color: #fff; display: grid; place-items: center; backdrop-filter: blur(10px); transition: transform .1s, background .15s; }
.cbtn:active { transform: scale(.93); }
.cbtn .ic { width: 26px; height: 26px; }
.cbtn.on { background: #fff; color: #111; }
.cbtn.red { background: #e53935; }
.cbtn.green { background: #2fb84d; }
.cbtn.rot .ic { transform: rotate(135deg); }
.cbtn.rec { color: #e53935; }
.call-top { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.call-rec { background: rgba(229, 57, 53, .9); color: #fff; padding: 4px 12px; border-radius: 14px; font-size: 13.5px; font-weight: 500; font-variant-numeric: tabular-nums; }

/* ===== Вход ===== */
.auth { height: 100%; overflow-y: auto; display: flex; align-items: center; justify-content: center; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); background: var(--bg-2); }
.auth-card { width: min(400px, 100%); background: var(--bg); border-radius: 20px; padding: 28px 22px 20px; box-shadow: 0 2px 24px rgba(0, 0, 0, .06); }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand h1 { margin: 12px 0 4px; font-size: 26px; }
.auth-logo { width: 72px; height: 72px; border-radius: 22px; background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 70%, #fff), var(--accent)); color: #fff; display: grid; place-items: center; margin: 0 auto; }
.auth-logo .ic { width: 34px; height: 34px; }
.tabs { display: flex; background: var(--input-bg); border-radius: 11px; padding: 3px; margin-bottom: 14px; }
.tab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--text-2); font-size: 14.5px; }
.tab.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.auth-status { font-size: 14px; color: var(--text-2); text-align: center; min-height: 0; }
.auth-status:empty, .auth-error:empty { display: none; }
.auth-error { font-size: 14px; color: var(--danger); text-align: center; }
.agree { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; color: var(--text-2); cursor: pointer; line-height: 1.4; }
.agree input { margin-top: 2px; accent-color: var(--accent); width: 17px; height: 17px; flex-shrink: 0; }
.pw-meter { height: 4px; border-radius: 2px; background: var(--input-bg); overflow: hidden; margin-top: -4px; }
.pw-meter span { display: block; height: 100%; width: 0; background: var(--danger); transition: width .2s, background .2s; }
.pw-meter[data-level="2"] span { background: #f0a020; }
.pw-meter[data-level="3"] span { background: #2fb84d; }

/* ===== Мобильная раскладка ===== */
@media (max-width: 760px) {
  .sidebar { width: 100%; min-width: 0; border-right: 0; transition: transform .25s ease; }
  .main { position: fixed; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .25s ease; box-shadow: var(--shadow); height: var(--app-h, 100dvh); }
  .app.chat-open .main { transform: none; }
  .app.chat-open .sidebar { transform: translateX(-22%); }
  .back-btn { display: grid; }
  .chat-head { padding-left: 2px; }
  .bubble { max-width: 84%; }
  .msgs-wrap { padding: 6px 8px 4px; }
  .side-panel { width: 100%; border-left: 0; }
  .chat-empty { display: none; }
  .unread-sep { margin: 8px -8px; }
  .modal-back { align-items: end; padding: 0; }
  .modal { width: 100%; border-radius: 18px 18px 0 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); animation: up .22s ease; }
  @keyframes up { from { transform: translateY(40px); opacity: 0; } }
  .ctx-item { padding: 11px 12px; font-size: 15.5px; }
}
@media (hover: none) {
  .chat-item:hover, .info-row:hover, .member:hover, .icon-btn:hover { background: none; }
  .chat-item.active { background: var(--accent); }
  .chat-item:active { background: var(--hover); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
