/* Шёпот — оформление. Ночные чернила и свеча. */
@font-face {
  font-family: 'Lora Shepot';
  src: url('/fonts/lora-italic.woff') format('woff');
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --bg: #E6E9EF;
  --chat-bg: #E3E7EE;
  --panel: #FFFFFF;
  --panel-2: #F2F4F8;
  --sel: #E7EDF8;
  --text: #141B2D;
  --muted: #687089;
  --line: #DCE0E8;
  --ink: #1F3B73;
  --ink-2: #2A4A8C;
  --out: #1F3B73;
  --on-out: #FFFFFF;
  --out-muted: rgba(255, 255, 255, .66);
  --in: #FFFFFF;
  --candle: #E9A23B;
  --on-candle: #2E2006;
  --online: #2F9B71;
  --danger: #C8423A;
  --shadow: 0 1px 1px rgba(20, 27, 45, .06), 0 8px 24px rgba(20, 27, 45, .08);
  --bubble-shadow: 0 1px 1.5px rgba(20, 27, 45, .08);
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', 'Inter', Arial, sans-serif;
  --serif: 'Lora Shepot', 'Lora', Georgia, 'Times New Roman', serif;
  --r: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1120;
    --chat-bg: #0D1426;
    --panel: #121A2C;
    --panel-2: #19223A;
    --sel: #1C2946;
    --text: #E6EAF2;
    --muted: #8D96AE;
    --line: #222D45;
    --ink: #7FA2E8;
    --ink-2: #98B6F0;
    --out: #2B4C8E;
    --on-out: #F2F5FB;
    --out-muted: rgba(242, 245, 251, .62);
    --in: #1A2440;
    --candle: #F0B04D;
    --on-candle: #2A1C03;
    --online: #47B98A;
    --danger: #E5675F;
    --shadow: 0 1px 1px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    --bubble-shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B1120;
  --chat-bg: #0D1426;
  --panel: #121A2C;
  --panel-2: #19223A;
  --sel: #1C2946;
  --text: #E6EAF2;
  --muted: #8D96AE;
  --line: #222D45;
  --ink: #7FA2E8;
  --ink-2: #98B6F0;
  --out: #2B4C8E;
  --on-out: #F2F5FB;
  --out-muted: rgba(242, 245, 251, .62);
  --in: #1A2440;
  --candle: #F0B04D;
  --on-candle: #2A1C03;
  --online: #47B98A;
  --danger: #E5675F;
  --shadow: 0 1px 1px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  --bubble-shadow: none;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15.5px/1.42 var(--sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#app { height: 100dvh; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: .55; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 6px; }
.ic { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ic svg { display: block; }
.serif { font-family: var(--serif); font-style: italic; font-weight: 500; }
.muted { color: var(--muted); }
.root { height: 100%; }

/* ───── словесный знак ───── */
.wordmark {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 26px;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -.01em;
  white-space: nowrap;
}
.wordmark.big { font-size: clamp(56px, 14vw, 76px); letter-spacing: -.02em; }
.boot { height: 100%; display: grid; place-items: center; }
.boot .wordmark { opacity: .35; }

/* ───── кнопки ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 14px;
  font-weight: 600; font-size: 15.5px;
  transition: background .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primary { background: var(--ink); color: var(--panel); }
.btn.ghost { background: var(--panel-2); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.link { color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: inline-grid; place-items: center; flex: none;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.light { color: #fff; }

/* ───── вход ───── */
.auth {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 32px 16px calc(32px + env(safe-area-inset-bottom));
}
.auth-card { width: 100%; max-width: 400px; }
.auth-card .wordmark { margin: 0 0 14px -4px; min-height: 1em; }
.auth-lead { color: var(--muted); margin: 0 0 28px; font-size: 16px; max-width: 34ch; }
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--panel-2); border-radius: 12px; padding: 3px; gap: 3px;
}
.seg button { height: 38px; border-radius: 9px; font-weight: 600; font-size: 14.5px; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.auth .seg { margin-bottom: 20px; background: var(--panel); }
.auth .seg button.on { background: var(--panel-2); box-shadow: none; }
.auth-form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.field input, .rename input, .pw-form input {
  height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--panel); outline: none;
  transition: border-color .15s;
  width: 100%;
}
.field input:focus, .rename input:focus, .pw-form input:focus { border-color: var(--ink); }
.hint { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--muted); margin: 0; }
.hint .ic { margin-top: 1px; }
.hint.warn .ic { color: var(--candle); }
.hint.ok { color: var(--online); justify-content: center; margin-top: 12px; }
.form-error { color: var(--danger); font-size: 14px; margin: 0; }
.auth-form .btn { margin-top: 6px; height: 52px; }

/* ───── каркас ───── */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  background: var(--panel);
}
.side {
  display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding-top: env(safe-area-inset-top);
}
.pane {
  position: relative;
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--chat-bg);
}

/* ───── боковая панель ───── */
.side-head { display: flex; align-items: center; gap: 4px; padding: 14px 10px 8px 20px; }
.side-title { flex: 1; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.conn { font-size: 13px; color: var(--muted); }
.conn:not(.ok)::before {
  content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--candle); margin-right: 6px; vertical-align: 2px;
  animation: blink 1.2s infinite;
}
@keyframes blink { 50% { opacity: .25; } }
.side-search {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 14px 8px; padding: 0 12px; height: 40px;
  border-radius: 12px; background: var(--panel-2); color: var(--muted);
}
.side-search input { flex: 1; border: 0; outline: 0; background: none; min-width: 0; height: 100%; color: var(--text); }
.chat-list { flex: 1; overflow-y: auto; padding: 2px 8px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.chat-row {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left;
  padding: 9px 10px; border-radius: 14px;
  transition: background .12s;
}
.chat-row.active { background: var(--sel); }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-top, .row-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.row-kind { color: var(--muted); }
.row-time { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 3px; flex: none; }
.row-preview { flex: 1; min-width: 0; font-size: 14.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-preview.typing, .head-status.typing { color: var(--ink); }
.chat-row.unread .row-preview { color: var(--text); }
.badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--candle); color: var(--on-candle);
  font-size: 12.5px; font-weight: 700; display: inline-grid; place-items: center; flex: none;
}
.tick { color: var(--muted); }
.tick.read { color: var(--ink); }
.list-empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.list-empty .serif { font-size: 28px; color: var(--text); margin: 0 0 6px; }
.list-empty p { margin: 0 0 20px; }
.empty-small { color: var(--muted); text-align: center; padding: 20px; margin: 0; font-size: 14.5px; }

/* ───── аватары ───── */
.av {
  position: relative; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--av); color: #fff; font-weight: 600; letter-spacing: .02em;
  user-select: none;
}
.av-self { color: var(--panel); }
.av-icon { width: 42px; height: 42px; background: var(--sel); color: var(--ink); }
.av-dot {
  position: absolute; right: 0; bottom: 0; width: 28%; height: 28%; min-width: 10px; min-height: 10px;
  border-radius: 50%; background: var(--online); box-shadow: 0 0 0 2.5px var(--panel);
}
.av-gap { width: 30px; flex: none; }

/* ───── пустое окно ───── */
.pane-empty { display: grid; place-items: center; padding: 24px; }
.empty-art { text-align: center; max-width: 360px; color: var(--muted); }
.empty-art .big { font-size: 40px; color: var(--ink); margin: 0 0 10px; line-height: 1.1; }

/* ───── шапка чата ───── */
.chat-head {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 8px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
  z-index: 2;
}
.chat-head .back { display: none; }
.head-who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; padding: 2px 8px; border-radius: 12px; }
.head-text { min-width: 0; display: grid; }
.head-name { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.head-status { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-status.online { color: var(--online); }
.verified { color: var(--online); }
.key-warn {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 10px 12px 0; padding: 12px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--candle) 18%, var(--panel)); font-size: 14px;
}
.key-warn .ic { color: var(--candle); margin-top: 1px; }
.key-warn .link { flex: none; }

/* ───── лента сообщений ───── */
.msgs-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.msgs {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column-reverse;
  overscroll-behavior: contain;
}
.msgs-inner {
  display: flex; flex-direction: column;
  width: 100%; max-width: 860px; margin: 0 auto;
  padding: 12px 14px 10px;
}
.loading-more { text-align: center; color: var(--muted); font-size: 13.5px; min-height: 28px; padding: 6px; }
.day { text-align: center; margin: 14px 0 8px; position: sticky; top: 8px; z-index: 1; pointer-events: none; }
.day span {
  display: inline-block; padding: 4px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.sys { text-align: center; margin: 8px 0; }
.sys span { font-size: 13.5px; color: var(--muted); }

.row { display: flex; align-items: flex-end; gap: 8px; margin-top: 2px; }
.row.first { margin-top: 10px; }
.row.out { justify-content: flex-end; }
.row.out.failed { flex-direction: row; justify-content: flex-end; align-items: center; }

.bubble {
  position: relative;
  max-width: min(560px, 80%);
  padding: 7px 12px 7px;
  border-radius: var(--r);
  background: var(--in); color: var(--text);
  box-shadow: var(--bubble-shadow);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  --meta-w: 46px;
}
.out .bubble { background: var(--out); color: var(--on-out); --meta-w: 64px; }
.in.tail .bubble { border-bottom-left-radius: 6px; }
.out.tail .bubble { border-bottom-right-radius: 6px; }
.bubble a { text-decoration: underline; text-underline-offset: 2px; color: inherit; }
.in .bubble a { color: var(--ink); }
.txt::after { content: ''; display: inline-block; width: var(--meta-w); height: 1px; }
.meta {
  position: absolute; right: 10px; bottom: 5px;
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11.5px; line-height: 1; color: var(--muted);
  white-space: nowrap; pointer-events: none;
}
.out .meta { color: var(--out-muted); }
.out .tick, .out .tick.read { color: var(--out-muted); }
.out .tick.read { color: var(--candle); }
.sender { display: block; font-size: 13.5px; font-weight: 650; margin-bottom: 1px; }
.muted-text { color: var(--muted); font-style: italic; display: inline-flex; align-items: center; gap: 4px; padding-right: var(--meta-w); }
.out .muted-text { color: var(--out-muted); }

.bubble.bare { background: none; box-shadow: none; padding: 0 0 18px; }
.emoji-big { font-size: 44px; line-height: 1.15; }
.bubble.bare .meta { bottom: 0; color: var(--muted); }

@media (pointer: coarse) {
  .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}

.row.flash .bubble { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--candle); } 100% { box-shadow: var(--bubble-shadow); } }

.quote {
  display: grid; text-align: left; width: 100%;
  margin: 2px 0 5px; padding: 4px 10px;
  border-left: 3px solid var(--qc); border-radius: 4px 10px 10px 4px;
  background: color-mix(in srgb, var(--qc) 12%, transparent);
  font-size: 14px; line-height: 1.3; white-space: normal;
}
.quote b { color: var(--qc); font-size: 13px; }
.out .quote b { color: inherit; }
.quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }

/* медиа */
.bubble.has-media { padding: 3px; }
.bubble.has-media .quote { margin: 4px 6px 6px; width: auto; }
.bubble.has-media .sender { margin: 4px 9px 3px; }
.media {
  position: relative; overflow: hidden; cursor: zoom-in;
  width: min(330px, 66vw); max-height: 440px;
  border-radius: calc(var(--r) - 3px);
  background: var(--panel-2);
}
.out.tail .bubble.has-media:not(:has(.cap)) .media { border-bottom-right-radius: 4px; }
.in.tail .bubble.has-media:not(:has(.cap)) .media { border-bottom-left-radius: 4px; }
.media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb { filter: blur(14px); transform: scale(1.12); }
.media-full { opacity: 0; transition: opacity .25s; }
.media-full.ready { opacity: 1; }
.media.is-video { cursor: pointer; }
.play-badge, .media-progress {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(10, 16, 32, .5); color: #fff;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.play-badge .ic { margin-left: 3px; }
.media-tag {
  position: absolute; left: 8px; top: 8px;
  padding: 3px 8px; border-radius: 10px;
  background: rgba(10, 16, 32, .55); color: #fff; font-size: 12px;
}
.media-tag.err { top: auto; bottom: 8px; background: var(--danger); }
.bubble.has-media > .meta {
  right: 9px; bottom: 9px; padding: 4px 7px; border-radius: 10px;
  background: rgba(10, 16, 32, .5); color: #fff;
}
.bubble.has-media > .meta .tick, .bubble.has-media > .meta .tick.read { color: #fff; }
.bubble.has-media:has(.cap) > .meta { background: none; color: var(--muted); bottom: 7px; padding: 0; }
.out .bubble.has-media:has(.cap) > .meta { color: var(--out-muted); }
.out .bubble.has-media:has(.cap) > .meta .tick { color: var(--out-muted); }
.out .bubble.has-media:has(.cap) > .meta .tick.read { color: var(--candle); }
.cap { display: block; padding: 6px 9px 4px; }

/* голосовые */
.bubble.is-voice { padding: 8px 12px 8px 8px; min-width: 250px; }
.voice { display: flex; align-items: center; gap: 10px; }
.voice-btn {
  position: relative; width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--ink); color: var(--panel);
}
.out .voice-btn { background: var(--on-out); color: var(--out); }
.voice-btn > svg:first-child { margin-left: 2px; }
.voice-ring { position: absolute; inset: -4px; width: 52px; height: 52px; transform: rotate(-90deg); opacity: 0; color: var(--candle); pointer-events: none; }
.voice-ring.busy { opacity: 1; }
.voice-ring circle { transition: stroke-dashoffset .1s; }
.voice-col { flex: 1; min-width: 0; display: grid; gap: 5px; }
.voice-wave { display: flex; align-items: center; gap: 2px; height: 26px; cursor: pointer; }
.voice-wave span { flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px; background: currentColor; opacity: .3; transition: opacity .1s; }
.voice-wave span.on { opacity: 1; }
.in .voice-wave span.on { color: var(--ink); }
.voice-meta { display: flex; align-items: center; gap: 8px; font-size: 12.5px; opacity: .8; padding-right: var(--meta-w); }
.voice-speed {
  font-size: 11.5px; font-weight: 700; padding: 1px 6px; border-radius: 8px;
  background: color-mix(in srgb, currentColor 14%, transparent);
}

/* файлы */
.file-row { display: flex; align-items: center; gap: 12px; text-align: left; padding: 3px 0; padding-right: 8px; min-width: 210px; }
.file-ic {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: color-mix(in srgb, currentColor 12%, transparent);
}
.in .file-ic { color: var(--ink); }
.file-text { display: grid; min-width: 0; padding-bottom: 12px; }
.file-text b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.file-text small { opacity: .7; }

/* отправка */
.clock {
  width: 11px; height: 11px; border-radius: 50%;
  border: 1.5px solid currentColor; position: relative;
}
.clock::after {
  content: ''; position: absolute; left: 50%; top: 1.5px; width: 1.5px; height: 3.5px; margin-left: -.75px;
  background: currentColor; transform-origin: 50% 100%; animation: spin 1.2s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.pending .bubble { opacity: .92; }
.failed .bubble { background: color-mix(in srgb, var(--danger) 70%, var(--out)); }
.retry { margin-right: 8px; font-size: 13.5px; font-weight: 600; color: var(--danger); order: -1; }
.ring { display: block; }

.chat-empty {
  margin: auto; max-width: 340px; text-align: center; color: var(--muted);
  padding: 32px 22px; border-radius: 22px; background: color-mix(in srgb, var(--panel) 70%, transparent);
}
.chat-empty .seal {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; background: var(--candle); color: var(--on-candle);
}
.chat-empty p { margin: 0 0 12px; }
.msgs-inner:has(.chat-empty) { flex: 1; justify-content: center; }

.to-bottom {
  position: absolute; right: 16px; bottom: 14px; z-index: 3;
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel); color: var(--muted); box-shadow: var(--shadow);
}
.to-bottom .badge { position: absolute; top: -8px; left: 50%; transform: translateX(-50%); }

.drop-hint {
  position: absolute; inset: 10px; z-index: 5; border-radius: 22px;
  border: 2px dashed var(--ink); background: color-mix(in srgb, var(--panel) 80%, transparent);
  display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--ink); font-weight: 600;
  pointer-events: none;
}

/* ───── поле ввода ───── */
.composer-wrap, .composer.recording {
  background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; max-width: 900px; margin: 0 auto; width: 100%; }
.composer .attach { cursor: pointer; margin-bottom: 2px; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; outline: none;
  min-height: 46px; max-height: 168px;
  padding: 12px 16px; border-radius: 23px;
  border: 1.5px solid transparent; background: var(--panel-2);
  line-height: 1.35; font-size: 16px;
  transition: border-color .15s;
}
.composer textarea:focus { border-color: color-mix(in srgb, var(--ink) 45%, transparent); }
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--ink); color: var(--panel);
  transition: transform .12s, background .15s;
}
.send-btn:active:not(:disabled) { transform: scale(.92); }
.send-btn.mic { background: var(--panel-2); color: var(--ink); }
.composer.recording { display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.rec-info { flex: 1; display: flex; align-items: center; gap: 12px; padding-left: 6px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); transition: transform .08s; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 40px; }
.rec-hint { color: var(--muted); font-size: 14px; }

.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 0 16px; max-width: 900px; margin: 0 auto; color: var(--ink);
}
.reply-text { flex: 1; min-width: 0; display: grid; border-left: 2.5px solid var(--ink); padding-left: 10px; font-size: 14px; }
.reply-text b { font-size: 13.5px; }
.reply-text span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tray { display: flex; gap: 8px; padding: 10px 12px 0; overflow-x: auto; max-width: 900px; margin: 0 auto; }
.tray-item {
  position: relative; flex: none; width: 76px; height: 76px; border-radius: 14px; overflow: hidden;
  background: var(--panel-2);
}
.tray-item img, .tray-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tray-file { height: 100%; display: grid; place-content: center; justify-items: center; gap: 4px; padding: 6px; color: var(--ink); }
.tray-file span { font-size: 11px; color: var(--muted); max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-x {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(10, 16, 32, .65); color: #fff;
}
.tray-tag { position: absolute; left: 5px; bottom: 5px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6)); }

/* ───── меню сообщения ───── */
.menu-layer { position: fixed; inset: 0; z-index: 40; }
.menu {
  position: fixed; width: 230px; padding: 6px;
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow);
  border: 1px solid var(--line);
  animation: pop .14s ease-out;
}
.menu button { width: 100%; display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px; border-radius: 10px; text-align: left; font-size: 15px; }
.menu .ic { color: var(--muted); }
.menu .danger, .menu .danger .ic { color: var(--danger); }
@keyframes pop { from { opacity: 0; transform: scale(.94); } }

/* ───── модальные окна ───── */
.modal-layer {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(8, 12, 24, .45);
  display: grid; place-items: center; padding: 20px;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 440px; max-height: min(720px, calc(100dvh - 40px));
  display: flex; flex-direction: column;
  background: var(--panel); border-radius: 22px; box-shadow: var(--shadow);
  animation: rise .2s cubic-bezier(.2, .8, .2, 1);
}
.modal.small { max-width: 380px; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.modal-head { display: flex; align-items: center; padding: 14px 10px 6px 22px; }
.modal-head h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 650; }
.modal-body { padding: 6px 22px 22px; overflow-y: auto; display: grid; gap: 14px; align-content: start; }
.modal-body > p { margin: 0; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; }

.search-box {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 46px;
  border-radius: 12px; background: var(--panel-2); color: var(--muted);
}
.search-box input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--text); }
.results, .quick, .members { display: grid; gap: 2px; margin: 0 -10px; }
.user-row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px; text-align: left; }
.user-text { flex: 1; min-width: 0; display: grid; }
.user-text b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-text small { color: var(--muted); font-size: 13.5px; }
.check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; color: transparent; flex: none;
}
.check.on { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.role { color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px 0 12px;
  border-radius: 16px; background: var(--sel); color: var(--ink); font-weight: 600; font-size: 14px;
}

.profile { display: grid; justify-items: center; text-align: center; gap: 4px; padding: 4px 0 6px; }
.profile .av { margin-bottom: 8px; font-size: 32px; }
.profile h3 { margin: 0; font-size: 26px; display: flex; align-items: center; gap: 6px; }
.profile p { margin: 0; font-size: 14px; }
.rename { display: flex; gap: 8px; width: 100%; }
.rename .btn { flex: none; }
.list-actions { display: grid; margin: 0 -10px; }
.list-actions button { display: flex; align-items: center; gap: 14px; height: 48px; padding: 0 12px; border-radius: 12px; text-align: left; font-weight: 500; }
.list-actions .ic { color: var(--muted); }
.list-actions .danger, .list-actions .danger .ic { color: var(--danger); }

.set { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.set h4 { margin: 0; font-size: 14px; font-weight: 650; color: var(--muted); }
.set.about p { margin: 0; font-size: 14.5px; }
.pw-form { display: grid; gap: 8px; }
.toggle { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.toggle > span { flex: 1; display: grid; }
.toggle small { color: var(--muted); font-size: 13px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i {
  width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; flex: none;
  transition: background .18s;
}
.toggle i::after {
  content: ''; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .18s;
}
.toggle input:checked + i { background: var(--ink); }
.toggle input:checked + i::after { transform: translateX(18px); }
.toggle input:focus-visible + i { outline: 2px solid var(--ink); outline-offset: 2px; }

.code-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 8px;
  padding: 18px 12px; border-radius: 16px; background: var(--panel-2);
  font-size: 21px; font-weight: 600; text-align: center;
  font-variant-numeric: tabular-nums; letter-spacing: .06em;
}

/* ───── просмотр медиа ───── */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 7, 14, .94);
  display: flex; flex-direction: column;
  animation: fade .15s ease-out;
}
.lb-bar {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top));
  color: #fff;
}
.lb-cap { flex: 1; min-width: 0; padding-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.lb-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 8px calc(16px + env(safe-area-inset-bottom)); }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.lb-wait { color: #fff; display: grid; justify-items: center; gap: 10px; }

/* ───── уведомление внизу ───── */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; max-width: min(440px, calc(100vw - 32px));
  padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--panel); font-size: 14.5px; text-align: center;
  box-shadow: var(--shadow);
  animation: rise .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }

/* ───── наведение (только мышь) ───── */
@media (hover: hover) {
  .btn.primary:hover:not(:disabled) { background: var(--ink-2); }
  .btn.ghost:hover { background: var(--sel); }
  .icon-btn:hover { background: var(--panel-2); color: var(--text); }
  .icon-btn.light:hover { background: rgba(255, 255, 255, .14); }
  .chat-row:hover { background: var(--panel-2); }
  .send-btn:hover:not(:disabled) { background: var(--ink-2); }
  .menu button:hover { background: var(--panel-2); }
  .user-row:hover { background: var(--panel-2); }
  .list-actions button:hover { background: var(--panel-2); }
}

/* ───── телефоны ───── */
@media (max-width: 859px) {
  .app { grid-template-columns: 1fr; }
  .side { border-right: 0; }
  .pane { position: fixed; inset: 0; z-index: 10; transform: translateX(100%); visibility: hidden; transition: transform .26s cubic-bezier(.2, .8, .2, 1), visibility 0s .26s; }
  .chat-open .pane { transform: none; visibility: visible; transition: transform .26s cubic-bezier(.2, .8, .2, 1); }
  .pane-empty { display: none; }
  .chat-head .back { display: inline-grid; }
  .head-who { padding-left: 0; }
  .bubble { max-width: 84%; }
  .modal-layer { place-items: end stretch; padding: 0; }
  .modal {
    max-width: none; max-height: calc(100dvh - 40px); border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheet .24s cubic-bezier(.2, .8, .2, 1);
  }
  @keyframes sheet { from { transform: translateY(40%); opacity: .4; } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.apk { margin-top: 14px; text-decoration: none; }
.list-label { margin: 4px 10px 2px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.phone-row { display: flex; align-items: center; gap: 8px; }
.phone-row > span { flex: 1; font-variant-numeric: tabular-nums; }
.phone-row .btn { min-height: 38px; padding: 0 14px; font-size: 14.5px; }
