/* ============================================================
   Glassgram — Telegram-стиль + Liquid Glass
   Оптимизировано под iPhone: лёгкое размытие, тёмная тема,
   безопасные зоны, клавиатура
   ============================================================ */
:root {
  color-scheme: light;
  --bg: #e6ecfb;
  --text: #10182b;
  --muted: #6b7590;
  --accent: #2f8cf5;
  --accent-2: #6d5cf6;
  --danger: #ea4d5e;
  --online: #34c759;

  --glass: rgba(255,255,255,.45);
  --glass-strong: rgba(255,255,255,.66);
  --glass-weak: rgba(255,255,255,.26);
  --edge: rgba(255,255,255,.75);
  --edge-soft: rgba(255,255,255,.4);
  --field: rgba(255,255,255,.55);
  --field-focus: rgba(255,255,255,.8);
  --hover: rgba(255,255,255,.5);
  --chip: rgba(255,255,255,.55);
  --bubble-in: rgba(255,255,255,.86);
  --bubble-in-text: #10182b;
  --shadow: 0 8px 30px rgba(40,50,100,.12), 0 1px 4px rgba(40,50,100,.05);
  --shadow-lg: 0 24px 70px rgba(30,40,90,.26);
  --inner: inset 0 1px 0 var(--edge);
  --blur: 22px;
  --scrim: rgba(12,16,36,.3);
  --separator: rgba(60,70,110,.14);
  --ease: cubic-bezier(.25,.1,.25,1);   /* близко к системной анимации iOS */
  --ease-out: cubic-bezier(.2,.8,.2,1);

  --blob-1: rgba(90,150,255,.8);
  --blob-2: rgba(200,130,255,.65);
  --blob-3: rgba(110,225,215,.6);
  --blob-4: rgba(255,190,140,.55);
  --base-a: #eef2fc; --base-b: #e1e8fb; --base-c: #f1e9fb;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --app-h: 100dvh;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1424;
    --text: #eef1f8;
    --muted: #98a2bb;
    --accent: #4da3ff;
    --glass: rgba(30,36,58,.55);
    --glass-strong: rgba(34,40,66,.78);
    --glass-weak: rgba(30,36,58,.35);
    --edge: rgba(255,255,255,.16);
    --edge-soft: rgba(255,255,255,.09);
    --field: rgba(255,255,255,.08);
    --field-focus: rgba(255,255,255,.13);
    --hover: rgba(255,255,255,.07);
    --chip: rgba(30,36,58,.7);
    --bubble-in: rgba(46,52,80,.92);
    --bubble-in-text: #eef1f8;
    --shadow: 0 8px 30px rgba(0,0,0,.35);
    --shadow-lg: 0 24px 70px rgba(0,0,0,.55);
    --scrim: rgba(0,0,0,.55);
    --separator: rgba(255,255,255,.09);
    --blob-1: rgba(60,100,230,.5);
    --blob-2: rgba(150,80,230,.4);
    --blob-3: rgba(40,170,170,.35);
    --blob-4: rgba(230,120,90,.3);
    --base-a: #131a33; --base-b: #0f1424; --base-c: #181334;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Интерфейс не выделяется и не зумится двойным тапом; текст сообщений и поля — можно */
body { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
input, textarea, .bubble, .setup, .messages-empty { -webkit-user-select: text; user-select: text; }
@media (pointer: coarse) { .bubble { -webkit-user-select: none; user-select: none; } }
html, body { margin: 0; padding: 0; height: 100%; }
html { overflow: hidden; background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", system-ui, Roboto, sans-serif;
  color: var(--text); font-size: 15px; line-height: 1.45;
  background: var(--bg); overflow: hidden; overscroll-behavior: none;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
#app { height: var(--app-h); width: 100%; position: relative; overflow: hidden; }
/* При открытой клавиатуре нижняя безопасная зона не нужна — она под клавиатурой */
body.kbd .composer { padding-bottom: 6px; }
body.kbd .list { padding-bottom: 8px; }
body.kbd .sheet { padding-bottom: 16px; }

/* ---- Жидкий фон ---- */
body::before {
  content: ""; position: fixed; inset: -15%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(38% 45% at 15% 20%, var(--blob-1), transparent 70%),
    radial-gradient(35% 40% at 85% 15%, var(--blob-2), transparent 70%),
    radial-gradient(40% 45% at 78% 82%, var(--blob-3), transparent 70%),
    radial-gradient(35% 40% at 18% 85%, var(--blob-4), transparent 70%),
    linear-gradient(160deg, var(--base-a), var(--base-b) 50%, var(--base-c));
  filter: blur(40px) saturate(125%);
  animation: drift 28s ease-in-out infinite alternate;
  transform: translateZ(0);
}
@keyframes drift {
  0% { transform: translate3d(0,0,0) scale(1); }
  50% { transform: translate3d(-2.5%,2%,0) scale(1.04); }
  100% { transform: translate3d(2%,-2%,0) scale(1.02); }
}
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } }

a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; color: inherit; border: 0; background: none; padding: 0; }
input, textarea { font: inherit; color: inherit; }
input, textarea, select { font-size: 16px; } /* iOS не зумит при фокусе */
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.danger-text { color: var(--danger) !important; }

/* ---- Стекло ---- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(170%); backdrop-filter: blur(var(--blur)) saturate(170%);
  border: 1px solid var(--edge-soft);
  box-shadow: var(--shadow), var(--inner);
}

/* ---- Кнопки ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; position: relative; overflow: hidden;
  padding: 13px 18px; border-radius: 999px; font-weight: 600; color: var(--text); min-height: 46px;
  background: var(--field); border: 1px solid var(--edge-soft);
  box-shadow: var(--inner);
  transition: transform .15s var(--ease), filter .15s, background .15s;
}
.btn:active { transform: scale(.97); filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; margin-top: 8px; }
.btn.primary {
  color: #fff; border-color: transparent;
  background: linear-gradient(135deg, #3f9cff, #2f7ff5 55%, #6d5cf6);
  box-shadow: 0 8px 22px rgba(47,127,245,.35), inset 0 1px 0 rgba(255,255,255,.5);
}
.btn.primary::before {
  content: ""; position: absolute; inset: 1px; border-radius: inherit; pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.38), rgba(255,255,255,.04) 45%, transparent 60%);
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--accent); flex-shrink: 0;
  transition: background .15s;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--hover); }

/* ---- Поля ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); padding-left: 8px; }
.field input, .nick-wrap {
  width: 100%; padding: 13px 16px; border-radius: 999px; outline: none; border: 1px solid var(--edge-soft);
  background: var(--field); box-shadow: var(--inner);
  transition: box-shadow .15s, background .15s; -webkit-appearance: none; appearance: none;
}
.field input:focus, .nick-wrap:focus-within { background: var(--field-focus); box-shadow: var(--inner), 0 0 0 4px rgba(47,140,245,.22); }
.nick-wrap { display: flex; align-items: center; gap: 4px; padding-left: 14px; }
.nick-wrap i { font-style: normal; color: var(--muted); font-weight: 600; }
.nick-wrap input { flex: 1; border: 0; background: none; box-shadow: none; padding: 0; outline: none; min-width: 0; }
.field small { padding-left: 8px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: -4px 0 8px; padding-left: 8px; }

/* ---- Экраны ---- */
.screen { position: absolute; inset: 0; }
.screen.center { display: flex; flex-direction: column; align-items: center; padding: calc(16px + var(--sat)) 16px calc(16px + var(--sab)); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.screen.center .card { margin: auto 0; flex-shrink: 0; }
.card { width: 100%; max-width: 420px; border-radius: 26px; padding: 28px; box-shadow: var(--shadow-lg), var(--inner); }
.card h1 { font-size: 24px; margin: 22px 0 4px; letter-spacing: -.02em; }
.card p { margin: 0 0 18px; }
.setup ol { padding-left: 20px; margin: 0 0 14px; line-height: 1.7; }
.setup code { background: var(--field); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.01em; }
.logo {
  width: 38px; height: 38px; border-radius: 12px; display: block;
  background: url('/icons/icon-192.png') center/cover; box-shadow: 0 6px 16px rgba(47,127,245,.4), inset 0 1px 0 rgba(255,255,255,.6);
}
.switch { text-align: center; color: var(--muted); margin: 12px 0 0 !important; font-size: 15px; }
.switch a { display: inline-block; padding: 8px 6px; font-weight: 600; }

/* Режим «завершите профиль»: email и пароль не нужны */
#registerForm.complete .field:nth-of-type(3), #registerForm.complete .field:nth-of-type(4), #registerForm.complete .switch { display: none; }

/* ---- Аватар ---- */
.avatar {
  display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 700; flex-shrink: 0; position: relative;
  width: 50px; height: 50px; font-size: 18px; text-transform: uppercase; letter-spacing: -.02em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 3px 10px rgba(40,50,100,.2);
}
.avatar.sm { width: 36px; height: 36px; font-size: 14px; }
.avatar.lg { width: 72px; height: 72px; font-size: 28px; }
.avatar.c0 { background: linear-gradient(135deg, #ff8a65, #ff5252); }
.avatar.c1 { background: linear-gradient(135deg, #4facfe, #2f7ff5); }
.avatar.c2 { background: linear-gradient(135deg, #a18cd1, #7b5cf6); }
.avatar.c3 { background: linear-gradient(135deg, #43e97b, #2bb673); }
.avatar.c4 { background: linear-gradient(135deg, #f6d365, #fda085); }
.avatar.c5 { background: linear-gradient(135deg, #f093fb, #f5576c); }
.avatar.c6 { background: linear-gradient(135deg, #5ee7df, #2fa8c5); }
.avatar.c7 { background: linear-gradient(135deg, #ffd452, #f7971e); }
.avatar .dot {
  position: absolute; right: 0; bottom: 0; width: 13px; height: 13px; border-radius: 50%; background: var(--online);
  border: 2.5px solid var(--bg); display: none;
}
.avatar.online .dot { display: block; }

/* ---- Основной экран ---- */
.main { display: flex; padding: calc(10px + var(--sat)) calc(12px + var(--sar)) calc(10px + var(--sab)) calc(12px + var(--sal)); gap: 12px; }
.pane { position: relative; min-width: 0; height: 100%; }
.pane-list { width: 360px; flex-shrink: 0; border-radius: 26px; display: flex; flex-direction: column; overflow: hidden; }
.pane-chat { flex: 1; display: flex; flex-direction: column; }

.pane-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 4px; }
.pane-title { flex: 1; text-align: center; font-weight: 700; font-size: 17px; }
.search-wrap {
  position: relative; margin: 6px 12px 8px; display: flex; align-items: center;
  background: var(--field); border: 1px solid var(--edge-soft); border-radius: 999px; padding: 0 12px; box-shadow: var(--inner);
}
.search-wrap svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.search-wrap input { flex: 1; border: 0; background: none; outline: none; padding: 10px 8px; min-width: 0; -webkit-appearance: none; }
.search-wrap input::-webkit-search-cancel-button, .search-wrap input::-webkit-search-decoration { display: none; -webkit-appearance: none; }
.search-wrap .clear { width: 32px; height: 32px; margin-right: -6px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 15px; line-height: 1; }
.search-wrap .clear::before { content: "\00d7"; width: 20px; height: 20px; border-radius: 50%; background: rgba(120,130,160,.55); display: grid; place-items: center; }
.list { flex: 1; overflow-y: auto; padding: 0 8px 8px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.list-empty { flex: 1; display: grid; place-content: center; text-align: center; gap: 4px; color: var(--muted); padding: 20px; }
.list-empty .big { font-size: 44px; }
.list-section { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 12px 6px; }

.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 10px; border-radius: 16px; cursor: pointer; width: 100%; text-align: left;
  transition: background .15s; min-height: 68px;
}
.chat-item:active { background: var(--hover); transition: none; }
@media (hover: hover) { .chat-item:hover { background: var(--hover); } }
.chat-item.active { background: linear-gradient(135deg, #3f9cff, #2f7ff5); color: #fff; box-shadow: 0 8px 22px rgba(47,127,245,.3), inset 0 1px 0 rgba(255,255,255,.4); }
.chat-item.active .muted, .chat-item.active .time, .chat-item.active .last { color: rgba(255,255,255,.85); }
.chat-item .body { flex: 1; min-width: 0; }
.chat-item .row { display: flex; align-items: baseline; gap: 8px; }
.chat-item .name { font-weight: 600; font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { font-size: 13px; color: var(--muted); flex-shrink: 0; }
.chat-item .last { font-size: 15px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-item .last b { font-weight: 500; color: var(--text); }
.chat-item.active .last b { color: #fff; }
.chat-item .badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  color: #fff; background: var(--accent); box-shadow: inset 0 1px 0 rgba(255,255,255,.4); margin-left: 6px; flex-shrink: 0;
}
.chat-item.active .badge { background: #fff; color: var(--accent); }

/* ---- Чат ---- */
.chat-empty { flex: 1; display: grid; place-items: center; }
.pill { padding: 10px 18px; border-radius: 999px; color: var(--muted); font-weight: 500; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 999px; background: var(--glass-strong); z-index: 2; }
.chat-head .back { display: none; margin-left: -8px; }
.chat-title { flex: 1; min-width: 0; line-height: 1.2; }
.chat-title .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title .status { font-size: 13px; color: var(--muted); }
.chat-title .status.online, .chat-title .status.typing { color: var(--accent); }

.messages {
  flex: 1; overflow-y: auto; padding: 14px 8px 8px; display: flex; flex-direction: column; gap: 3px; position: relative;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.messages-empty { margin: auto; text-align: center; color: var(--muted); font-size: 14px; padding: 12px 18px; border-radius: 16px; background: var(--chip); }
.day { align-self: center; margin: 10px 0 6px; font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--chip); padding: 4px 12px; border-radius: 999px; }
.msg { max-width: min(78%, 560px); display: flex; flex-direction: column; position: relative; -webkit-touch-callout: none; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; }
.bubble {
  padding: 8px 12px 6px; border-radius: 18px; font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; white-space: pre-wrap; position: relative;
}
.msg.in .bubble { background: var(--bubble-in); color: var(--bubble-in-text); box-shadow: 0 2px 8px rgba(40,50,100,.08), var(--inner); border-bottom-left-radius: 6px; }
.msg.out .bubble { color: #fff; background: linear-gradient(135deg, #3f9cff, #2f7ff5 60%, #6d5cf6); box-shadow: 0 4px 14px rgba(47,127,245,.28), inset 0 1px 0 rgba(255,255,255,.4); border-bottom-right-radius: 6px; }
.msg.in + .msg.in .bubble { border-top-left-radius: 8px; }
.msg.out + .msg.out .bubble { border-top-right-radius: 8px; }
.meta { float: right; margin: 6px -4px -2px 8px; font-size: 11px; opacity: .65; display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.meta .ticks { font-size: 12px; letter-spacing: -3px; }
.meta .ticks.read { color: #dff5ff; opacity: 1; }
.msg.out .meta { opacity: .85; }
.msg.pending .bubble { opacity: .7; }
.msg .bubble a { color: inherit; text-decoration: underline; }
.msg .bubble:active { filter: brightness(.94); }

.scroll-down {
  position: absolute; right: 12px; bottom: 78px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; z-index: 3;
  background: var(--glass-strong); border: 1px solid var(--edge-soft); box-shadow: var(--shadow), var(--inner); color: var(--accent);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.scroll-down.show { opacity: 1; transform: none; pointer-events: auto; }
.scroll-down svg { width: 20px; height: 20px; }

.composer { padding: 8px 0 0; }
.composer-inner {
  display: flex; align-items: flex-end; gap: 8px; padding: 5px 5px 5px 16px; border-radius: 26px; background: var(--glass-strong);
}
.composer textarea {
  flex: 1; resize: none; border: 0; background: none; outline: none; padding: 11px 0; max-height: 140px; line-height: 1.35;
  font-size: 16px; -webkit-appearance: none;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex-shrink: 0;
  background: linear-gradient(135deg, #3f9cff, #2f7ff5 60%, #6d5cf6);
  box-shadow: 0 6px 16px rgba(47,127,245,.4), inset 0 1px 0 rgba(255,255,255,.5); transition: transform .15s, opacity .15s;
}
.send svg { width: 20px; height: 20px; margin-left: 2px; }
.send:active { transform: scale(.92); }
.send:disabled { opacity: .4; transform: none; }

/* ---- Профиль (шторка) ---- */
.sheet-backdrop, .ctx-backdrop { position: absolute; inset: 0; z-index: 30; background: var(--scrim); display: grid; place-items: end center; }
.ctx-backdrop { place-items: center; }
.sheet {
  width: 100%; max-width: 480px; border-radius: 28px 28px 0 0; padding: 10px 20px calc(16px + var(--sab));
  background: var(--glass-strong); box-shadow: var(--shadow-lg), var(--inner); animation: up .3s var(--ease-out);
  max-height: calc(var(--app-h) - 40px); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes down { from { transform: none; } to { transform: translateY(100%); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
.sheet-backdrop, .ctx-backdrop { animation: fadeIn .2s var(--ease); }
.sheet-backdrop.closing, .ctx-backdrop.closing { animation: fadeOut .2s var(--ease) forwards; pointer-events: none; }
.sheet-backdrop.closing .sheet { animation: down .22s var(--ease) forwards; }
.ctx-backdrop.closing .ctx { animation: fadeOut .15s var(--ease) forwards; }
.sheet-grip { width: 40px; height: 5px; border-radius: 999px; background: rgba(128,136,160,.4); margin: 0 auto 14px; }
.profile-top { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile-name { font-weight: 700; font-size: 18px; }
.install-box { margin-top: 14px; padding: 12px 14px; border-radius: 16px; background: var(--field); border: 1px solid var(--edge-soft); }
.install-box p { margin: 4px 0 8px; }
.ctx { width: 240px; border-radius: 20px; padding: 6px; background: var(--glass-strong); box-shadow: var(--shadow-lg), var(--inner); display: flex; flex-direction: column; animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.ctx button { padding: 14px; border-radius: 14px; font-weight: 500; min-height: 48px; }
.ctx button:active { background: var(--hover); }

/* ---- Тост, лоадер ---- */
.toast {
  position: absolute; top: calc(66px + var(--sat)); left: 50%; transform: translateX(-50%) translateY(-20px); opacity: 0; z-index: 60; pointer-events: none;
  color: #fff; padding: 10px 18px; border-radius: 999px; transition: opacity .25s var(--ease), transform .25s var(--ease); font-size: 14px; max-width: calc(100vw - 32px); text-align: center;
  background: rgba(20,24,43,.85); border: 1px solid rgba(255,255,255,.2); box-shadow: 0 10px 30px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: rgba(234,77,94,.9); }
.loader { position: absolute; inset: 0; z-index: 100; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--edge-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Скроллбар (десктоп) ---- */
@media (hover: hover) {
  ::-webkit-scrollbar { width: 8px; }
  ::-webkit-scrollbar-thumb { background: rgba(120,130,160,.35); border-radius: 999px; }
}

/* Любые тач-устройства (включая iPhone в ландшафте): фон без blur-фильтра и анимации */
@media (pointer: coarse) {
  body::before { filter: none; animation: none; inset: 0; transform: none; }
  :root { --blur: 16px; }
}

/* ---- Уменьшенная анимация ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   Телефоны
   ============================================================ */
@media (max-width: 760px) {
  :root { --blur: 14px; }
  /* Фон без тяжёлого blur-фильтра и анимации — экономим батарею и GPU */
  body::before {
    filter: none; animation: none; inset: 0; transform: none;
    background:
      radial-gradient(70% 55% at 10% 15%, var(--blob-1), transparent 70%),
      radial-gradient(65% 50% at 95% 10%, var(--blob-2), transparent 70%),
      radial-gradient(70% 55% at 85% 90%, var(--blob-3), transparent 70%),
      radial-gradient(65% 50% at 10% 95%, var(--blob-4), transparent 70%),
      linear-gradient(160deg, var(--base-a), var(--base-b) 50%, var(--base-c));
  }

  .main { padding: 0 var(--sar) 0 var(--sal); gap: 0; }
  .pane-list, .pane-chat {
    position: absolute; inset: 0; width: 100%;
    transition: transform .32s var(--ease-out), opacity .32s var(--ease-out);
  }
  .pane-list {
    border-radius: 0; border: 0; box-shadow: none; background: transparent;
    -webkit-backdrop-filter: none; backdrop-filter: none;
    padding-top: var(--sat);
  }
  .pane-head { padding: 4px 6px 0; }
  .search-wrap { margin: 4px 10px 6px; }
  .pane-title { font-size: 18px; }
  .pane-chat { transform: translateX(100%); }
  .main.show-chat .pane-list { transform: translateX(-25%); opacity: 0; pointer-events: none; }
  .main.show-chat .pane-chat { transform: none; }

  .chat-item.active { background: transparent; color: inherit; box-shadow: none; }
  .chat-item.active .muted, .chat-item.active .time, .chat-item.active .last { color: var(--muted); }
  .chat-item.active .last b { color: var(--text); }
  .chat-item.active .badge { background: var(--accent); color: #fff; }

  .chat-head {
    /* Шапка начинается под строкой состояния, чтобы размытие не попадало на часы и батарею */
    border-radius: 0; border-left: 0; border-right: 0; border-top: 0; padding: 4px 8px 6px; margin-top: var(--sat);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(170%); backdrop-filter: blur(var(--blur)) saturate(170%);
  }
  .chat-head .back { display: grid; order: 0; margin-left: -4px; }
  .chat-head .chat-title { order: 1; text-align: center; }
  .chat-head #chatAvatar { order: 2; width: 38px; height: 38px; font-size: 15px; }
  .chat-item { min-height: 72px; border-radius: 0; padding: 10px 12px; position: relative; }
  .chat-item::after { content: ""; position: absolute; left: 76px; right: 0; bottom: 0; height: 1px; background: var(--separator); transform: scaleY(.5); }
  .chat-item:last-child::after { display: none; }
  .chat-item .avatar { width: 52px; height: 52px; font-size: 19px; }
  .list { padding: 0 0 8px; }
  .list-section { padding: 10px 16px 6px; }
  .chat-empty { display: none; }
  .messages { padding: 8px 8px 4px; }
  .msg { max-width: 84%; }
  .bubble { font-size: 17px; padding: 8px 13px 6px; }
  .composer { padding: 6px 8px calc(6px + var(--sab)); }
  .composer-inner { border-radius: 24px; }
  .scroll-down { bottom: calc(70px + var(--sab)); }
  .list { padding-bottom: calc(8px + var(--sab)); }
  .sheet { max-width: none; }
  .card { padding: 24px 20px; }
}

/* Установлено на экран «Домой» (standalone): контент под статус-баром */
@media (display-mode: standalone) and (max-width: 760px) {
  .pane-list { padding-top: var(--sat); }
}

/* ---- Фото, ответы, закреп ---- */
.attach {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex-shrink: 0; margin-left: -8px;
}
.attach svg { width: 24px; height: 24px; }
.attach:active { color: var(--accent); }
.composer-inner { padding-left: 8px; }

.reply-bar {
  display: flex; align-items: center; gap: 10px; margin: 0 0 6px; padding: 8px 6px 8px 12px; border-radius: 18px; background: var(--glass-strong);
  animation: fadeIn .18s var(--ease);
}
.reply-line { width: 3px; align-self: stretch; border-radius: 2px; background: var(--accent); flex-shrink: 0; }
.reply-body { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; line-height: 1.3; }
.reply-body b { color: var(--accent); font-weight: 600; }
.reply-body span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-cancel { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; color: var(--muted); }
.reply-cancel:active { background: var(--hover); }

.pinned-bar {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 8px 8px 14px; margin: 6px 0 0; border-radius: 16px;
  background: var(--glass-strong); border: 1px solid var(--edge-soft); box-shadow: var(--shadow), var(--inner); z-index: 2;
}
.pin-ico { color: var(--accent); display: grid; place-items: center; }
.pin-ico svg { width: 18px; height: 18px; }
.pin-body { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; line-height: 1.3; }
.pin-body b { color: var(--accent); font-weight: 600; font-size: 13px; }
.pin-body span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-x { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; color: var(--muted); }
.pin-x:active { background: var(--hover); }

.quote {
  display: flex; flex-direction: column; gap: 1px; padding: 4px 10px; margin: 0 0 6px; border-radius: 10px; font-size: 14px; line-height: 1.3; cursor: pointer;
  border-left: 3px solid var(--accent); background: rgba(47,140,245,.1);
}
.msg.out .quote { border-left-color: rgba(255,255,255,.85); background: rgba(255,255,255,.18); }
.quote b { font-weight: 600; color: var(--accent); }
.msg.out .quote b { color: #fff; }
.quote span { opacity: .8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }

.bubble.img { padding: 4px; overflow: hidden; border-radius: 18px; }
.bubble.img .quote { margin: 4px 4px 6px; }
.bubble.img img { display: block; width: min(70vw, 300px); max-width: 100%; height: auto; border-radius: 14px; background: rgba(0,0,0,.08); object-fit: cover; }
.bubble.img .caption { padding: 6px 8px 2px; }
.bubble.img .meta { position: absolute; right: 10px; bottom: 8px; margin: 0; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.45); color: #fff; opacity: 1; }
.bubble.img .caption ~ .meta { position: static; background: none; color: inherit; float: right; margin: 6px -4px -2px 8px; padding: 0; opacity: .85; }
.msg.uploading .bubble.img img { opacity: .6; }
.msg.uploading .bubble.img::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 32px; height: 32px; margin: -16px 0 0 -16px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.5); border-top-color: #fff; animation: spin .8s linear infinite;
}
.msg.highlight .bubble { animation: flash 1.2s var(--ease); }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 4px rgba(47,140,245,.45); } 100% { box-shadow: 0 0 0 0 rgba(47,140,245,0); } }

.viewer {
  position: absolute; inset: 0; z-index: 80; background: rgba(0,0,0,.92); display: grid; place-items: center; animation: fadeIn .2s var(--ease);
}
.viewer img { max-width: 100vw; max-height: 100%; object-fit: contain; }
.viewer-close {
  position: absolute; top: calc(8px + var(--sat)); right: 12px; width: 44px; height: 44px; border-radius: 50%; color: #fff; font-size: 30px; line-height: 1;
  background: rgba(255,255,255,.15); display: grid; place-items: center;
}
@media (max-width: 760px) {
  .pinned-bar { border-radius: 0; border-left: 0; border-right: 0; margin: 0; box-shadow: none; }
  .reply-bar { border-radius: 16px; }
}
