
/* ═══════════════════════════════════════════════════
   NitChat V9 · Liquid Glass · премиум
   ═══════════════════════════════════════════════════ */

:root, html[data-theme="light"] {
  --bg-app: #f5f7fa;
  --bg-sidebar: rgba(255,255,255,0.72);
  --bg-header: rgba(255,255,255,0.72);
  --bg-hover: rgba(82,136,193,0.08);
  --bg-active: rgba(82,136,193,0.15);
  --bg-chat: #eef2f8;
  --bg-bubble-in: rgba(255,255,255,0.95);
  --bg-bubble-out: linear-gradient(135deg, #5a9bd5 0%, #4a89c9 100%);
  --bg-composer: rgba(255,255,255,0.72);
  --bg-input: rgba(255,255,255,0.6);
  --border: rgba(120,140,170,0.15);
  --text: #0e1418;
  --text-dim: #6b7580;
  --text-muted: #a5adb5;
  --accent: #5288c1;
  --accent-2: #3f74ad;
  --accent-soft: rgba(82,136,193,0.14);
  --ok: #3fc255;
  --danger: #e5504a;
  --danger-soft: rgba(229,80,74,0.1);
  --shadow-sm: 0 1px 3px rgba(16,20,24,0.06);
  --shadow-lg: 0 20px 50px rgba(16,20,24,0.14);
  --glass-bg: rgba(255,255,255,0.65);
  --glass-brd: rgba(255,255,255,0.9);
  --glass-inner: inset 0 1px 0 rgba(255,255,255,0.95), inset 0 -1px 0 rgba(0,0,0,0.03);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg-app: #0a1018;
  --bg-sidebar: rgba(20,28,40,0.72);
  --bg-header: rgba(20,28,40,0.72);
  --bg-hover: rgba(90,155,213,0.1);
  --bg-active: rgba(90,155,213,0.2);
  --bg-chat: #0a1018;
  --bg-bubble-in: rgba(30,42,58,0.9);
  --bg-bubble-out: linear-gradient(135deg, #2b5278 0%, #234467 100%);
  --bg-composer: rgba(20,28,40,0.72);
  --bg-input: rgba(30,42,58,0.6);
  --border: rgba(90,155,213,0.15);
  --text: #f4f7fa;
  --text-dim: #7b8ea8;
  --text-muted: #5a6c81;
  --accent: #5a9bd5;
  --accent-2: #4a89c9;
  --accent-soft: rgba(90,155,213,0.15);
  --danger: #ff7a7a;
  --danger-soft: rgba(255,122,122,0.1);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.35);
  --shadow-lg: 0 20px 50px rgba(0,0,0,0.6);
  --glass-bg: rgba(20,28,40,0.6);
  --glass-brd: rgba(90,155,213,0.2);
  --glass-inner: inset 0 1px 0 rgba(255,255,255,0.08), inset 0 -1px 0 rgba(0,0,0,0.2);
  color-scheme: dark;
}

/* ═══ ФОНЫ ═══ */
html[data-bg="ocean"] #messages, html[data-bg="ocean"] .placeholder {
  background:
    radial-gradient(ellipse at 15% 10%, rgba(200,224,245,0.9) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(168,200,234,0.85) 0%, transparent 55%),
    linear-gradient(180deg, #eaf2fb 0%, #d8e6f3 100%);
}
html[data-theme="dark"][data-bg="ocean"] #messages,
html[data-theme="dark"][data-bg="ocean"] .placeholder {
  background:
    radial-gradient(ellipse at 15% 10%, rgba(26,58,92,0.9) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(15,42,68,0.85) 0%, transparent 55%),
    linear-gradient(180deg, #0a1018 0%, #0a1a2a 100%);
}
html[data-bg="sunset"] #messages, html[data-bg="sunset"] .placeholder {
  background:
    radial-gradient(ellipse at 30% 0%, rgba(255,214,186,0.95) 0%, transparent 55%),
    radial-gradient(ellipse at 70% 100%, rgba(255,192,203,0.9) 0%, transparent 55%),
    linear-gradient(180deg, #fff0e6 0%, #ffe0d6 100%);
}
html[data-theme="dark"][data-bg="sunset"] #messages,
html[data-theme="dark"][data-bg="sunset"] .placeholder {
  background:
    radial-gradient(ellipse at 30% 0%, rgba(92,36,24,0.95) 0%, transparent 55%),
    radial-gradient(ellipse at 70% 100%, rgba(74,26,44,0.9) 0%, transparent 55%),
    linear-gradient(180deg, #1a0e0a 0%, #2a1418 100%);
}
html[data-bg="night"] #messages, html[data-bg="night"] .placeholder {
  background: linear-gradient(180deg, #1a2540 0%, #2a3a5e 50%, #3a4a70 100%);
  position: relative;
}
html[data-bg="night"] #messages::before, html[data-bg="night"] .placeholder::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 22%, #fff 50%, transparent),
    radial-gradient(1px 1px at 45% 60%, #fff 50%, transparent),
    radial-gradient(1.5px 1.5px at 78% 18%, #fff 50%, transparent),
    radial-gradient(1px 1px at 88% 72%, #fff 50%, transparent),
    radial-gradient(1px 1px at 25% 88%, #fff 50%, transparent),
    radial-gradient(1.5px 1.5px at 62% 42%, #fff 50%, transparent),
    radial-gradient(1px 1px at 92% 32%, #fff 50%, transparent);
  opacity: 0.6; animation: twinkle 5s ease-in-out infinite alternate;
}
@keyframes twinkle { 0% { opacity: 0.3; } 100% { opacity: 0.85; } }
html[data-bg="neon"] #messages, html[data-bg="neon"] .placeholder {
  background:
    radial-gradient(ellipse at 12% 12%, rgba(168,85,247,0.5) 0%, transparent 45%),
    radial-gradient(ellipse at 88% 88%, rgba(236,72,153,0.5) 0%, transparent 45%),
    linear-gradient(180deg, #1a0f2e 0%, #0f1a2e 100%);
}
html[data-bg="forest"] #messages, html[data-bg="forest"] .placeholder {
  background:
    radial-gradient(ellipse at 20% 20%, rgba(167,243,208,0.85) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(134,239,172,0.75) 0%, transparent 55%),
    linear-gradient(180deg, #ecfdf5 0%, #d1fae5 100%);
}
html[data-theme="dark"][data-bg="forest"] #messages,
html[data-theme="dark"][data-bg="forest"] .placeholder {
  background:
    radial-gradient(ellipse at 20% 20%, rgba(6,78,59,0.9) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(20,83,45,0.85) 0%, transparent 55%),
    linear-gradient(180deg, #0a1f1a 0%, #0d1f18 100%);
}
html[data-bg="minimal"] #messages, html[data-bg="minimal"] .placeholder {
  background: var(--bg-chat);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; background: var(--bg-app); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.4; overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
input, button { font-family: inherit; }
input { -webkit-appearance: none; }
.hidden { display: none !important; }
.screen { height: 100vh; height: 100dvh; }

/* ═══ Кнопки: iOS-safe ═══ */
button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* hover только для мышки — на тач не мешает */
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: var(--bg-hover); color: var(--text); }
  .row:hover { background: var(--bg-hover); }
  .row:hover .avatar { transform: scale(1.06); }
}

/* ═══ GLASS ═══ */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-brd);
  box-shadow: var(--shadow-lg), var(--glass-inner);
}
.glass-panel {
  background: var(--bg-sidebar);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
}

/* ═══ AUTH ═══ */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-top: calc(24px + var(--safe-top));
  position: relative; overflow: hidden;
  background: var(--bg-app);
}
.mesh-canvas { position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: 0.9; }
html[data-theme="dark"] .mesh-canvas { opacity: 0.4; }

.auth-wrap {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px; text-align: center;
  padding: 40px 28px 28px;
  border-radius: 28px;
  animation: card-in .6s cubic-bezier(0.2,0.9,0.3,1.2);
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.logo-wrap { position: relative; display: inline-block; margin-bottom: 12px; }
.logo-glow {
  position: absolute; inset: -20px; border-radius: 50%;
  background: radial-gradient(circle, rgba(90,155,213,0.45) 0%, transparent 70%);
  filter: blur(20px); animation: glow-pulse 3.5s ease-in-out infinite;
}
@keyframes glow-pulse { 0%,100% { opacity: 0.6; transform: scale(1); } 50% { opacity: 1; transform: scale(1.1); } }
.tg-logo { position: relative; font-size: 76px; line-height: 1;
  filter: drop-shadow(0 10px 30px rgba(82,136,193,0.45));
  animation: floaty 3.5s ease-in-out infinite; }
@keyframes floaty { 0%,100% { transform: translateY(0) rotate(-2deg);} 50% { transform: translateY(-8px) rotate(2deg);} }
.brand-title {
  font-size: 40px; font-weight: 800; letter-spacing: -0.035em;
  background: linear-gradient(135deg, #74b6ee 0%, #5288c1 50%, #4a89c9 100%);
  background-size: 200% auto;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 4px; animation: shine 4s linear infinite;
}
@keyframes shine { to { background-position: 200% center; } }
.brand-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 28px; }

.auth-tabs {
  position: relative; display: flex;
  background: var(--bg-input); border-radius: 14px;
  padding: 5px; margin-bottom: 22px;
  border: 1px solid var(--border);
}
.tab-indicator {
  position: absolute; top: 5px; left: 5px; bottom: 5px;
  width: calc(50% - 5px); border-radius: 10px;
  background: linear-gradient(135deg, #5a9bd5, #4a89c9);
  box-shadow: 0 6px 16px -4px rgba(82,136,193,0.55);
  transition: transform .35s cubic-bezier(0.2,0.9,0.3,1.2); z-index: 0;
}
.auth-tabs[data-active="register"] .tab-indicator { transform: translateX(100%); }
.auth-tab {
  position: relative; z-index: 1; flex: 1; padding: 12px;
  background: transparent; border: none;
  color: var(--text-dim); font-size: 14px; font-weight: 600;
  transition: color .3s;
}
.auth-tab.active { color: #fff; }

#auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.tg-field {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-input); border-radius: 14px;
  padding: 0 18px; border: 1.5px solid transparent;
  transition: border .25s, background .25s, box-shadow .25s;
}
.tg-field:focus-within {
  border-color: var(--accent); background: var(--bg-app);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.field-group.has-error .tg-field { border-color: var(--danger); background: var(--danger-soft); }
.field-group.has-success .tg-field { border-color: var(--ok); }
.tg-field .prefix { color: var(--text-dim); font-size: 16px; font-weight: 600; padding-right: 2px; }
.tg-field:focus-within .prefix { color: var(--accent); }
.field-group.has-error .tg-field .prefix { color: var(--danger); }
.tg-field input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 16px; padding: 16px 0;
}
.tg-field input::placeholder { color: var(--text-muted); }
.field-status { display: none; font-size: 16px; flex-shrink: 0; }
.field-group.has-success .field-status { display: block; color: var(--ok); }
.field-group.has-success .field-status::after { content: '✓'; font-weight: 700; }
.field-group.has-error .field-status { display: block; color: var(--danger); }
.field-group.has-error .field-status::after { content: '!'; font-weight: 800; }
.eye-btn {
  background: transparent; border: none; padding: 8px;
  color: var(--text-muted); display: flex; align-items: center; justify-content: center;
  border-radius: 50%; transition: color .15s; flex-shrink: 0;
  touch-action: manipulation;
}
.eye-btn.showing { color: var(--accent); }
.field-hint {
  font-size: 12px; color: var(--text-muted); padding: 0 4px;
  transition: opacity .25s, max-height .25s; max-height: 30px;
}
.field-group.has-error .field-hint { opacity: 0; max-height: 0; overflow: hidden; }
.field-error {
  font-size: 12.5px; color: var(--danger); padding: 0 4px; font-weight: 500;
  max-height: 0; overflow: hidden; opacity: 0;
  transition: max-height .3s ease, opacity .2s ease;
}
.field-group.has-error .field-error { max-height: 60px; opacity: 1; }
.field-error::before { content: '⚠ '; }
.tg-btn-primary {
  position: relative; margin-top: 8px; padding: 16px;
  border: none; border-radius: 14px; overflow: hidden;
  background: linear-gradient(135deg, #5a9bd5, #4a89c9);
  color: #fff; font-size: 15.5px; font-weight: 700;
  transition: filter .2s, transform .1s;
  box-shadow: 0 10px 24px -10px rgba(82,136,193,0.6);
}
.tg-btn-primary:active { transform: scale(0.985); }
.tg-btn-primary:disabled { opacity: 0.75; cursor: not-allowed; }
.btn-spinner {
  display: none; position: absolute; top: 50%; left: 50%;
  width: 20px; height: 20px; margin: -10px 0 0 -10px;
  border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tg-btn-primary.loading .btn-text { opacity: 0; }
.tg-btn-primary.loading .btn-spinner { display: block; }
.auth-footer { color: var(--text-muted); font-size: 11px; margin-top: 20px; opacity: 0.6; }

/* ═══ MODAL ═══ */
.modal { position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: fade-in .25s; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  position: relative; z-index: 1; border-radius: 22px;
  padding: 32px 40px; text-align: center;
  animation: modal-pop .4s cubic-bezier(0.2,0.9,0.3,1.4);
}
@keyframes modal-pop { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
.success-check { width: 72px; height: 72px; margin-bottom: 14px; }
.success-check circle { stroke-dasharray: 160; stroke-dashoffset: 160; animation: draw-circle .6s ease forwards; }
.success-check path { stroke-dasharray: 60; stroke-dashoffset: 60; animation: draw-check .4s .5s ease forwards; }
@keyframes draw-circle { to { stroke-dashoffset: 0; } }
@keyframes draw-check { to { stroke-dashoffset: 0; } }
.modal-card h3 { font-size: 20px; margin-bottom: 6px; }
.modal-card p { color: var(--text-dim); font-size: 14px; }

/* ═══ LAYOUT ═══ */
#chat-screen { display: flex; background: var(--bg-app); }
#sidebar {
  width: 360px; display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  padding-top: var(--safe-top);
  position: relative; z-index: 2;
}
.side-top { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.side-search {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: var(--bg-input); border-radius: 22px;
  padding: 0 16px; height: 42px;
  border: 1.5px solid var(--border);
  transition: border .2s, box-shadow .2s;
}
.side-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.side-search .ico { color: var(--text-muted); display: flex; }
.side-search input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-size: 14.5px; }
.side-search input::placeholder { color: var(--text-muted); }
.side-search .clear-btn {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 14px; padding: 4px 6px; border-radius: 50%;
}

.side-tabs { display: flex; gap: 6px; padding: 0 14px 12px; }
.side-tab {
  flex: 1; padding: 9px; border: none; background: transparent;
  color: var(--text-dim); font-size: 13.5px; font-weight: 600;
  border-radius: 10px; transition: background .18s, color .18s;
}
.side-tab.active { background: var(--accent-soft); color: var(--accent); }

.panel { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

#contact-list, #search-list { list-style: none; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 14px; cursor: pointer;
  transition: background .18s, transform .15s;
  position: relative; touch-action: manipulation;
}
.row:active { transform: scale(0.99); background: var(--bg-hover); }
.row.active { background: var(--bg-active); }

.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; color: #fff;
  background: linear-gradient(135deg, #74b6ee, #4a89c9);
  position: relative;
  box-shadow: 0 3px 10px -3px rgba(82,136,193,0.5);
  transition: transform .25s cubic-bezier(0.2,0.9,0.3,1.4);
}
.avatar.online::after {
  content: ""; position: absolute; bottom: 1px; right: 1px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--ok);
  border: 2.5px solid var(--bg-sidebar);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%,100% { box-shadow: 0 0 0 0 rgba(63,194,85,0.5); }
  50%     { box-shadow: 0 0 0 8px rgba(63,194,85,0); }
}

.row-body { flex: 1; min-width: 0; }
.row-line1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row-username { font-weight: 600; font-size: 14.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { font-size: 12px; color: var(--text-muted); flex-shrink: 0; font-feature-settings: "tnum"; }
.row-line2 { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-top: 2px; }
.row-sub { font-size: 13.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-badge {
  background: linear-gradient(135deg, #5a9bd5, #4a89c9); color: #fff;
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 10px;
  min-width: 22px; text-align: center;
}
.row-add-btn {
  background: linear-gradient(135deg, #5a9bd5, #4a89c9);
  border: none; color: #fff; font-size: 12.5px; font-weight: 600;
  padding: 7px 14px; border-radius: 10px;
  transition: filter .15s, transform .1s;
  touch-action: manipulation;
}
.row-add-btn:active { transform: scale(0.97); }
.row-add-btn.added { background: var(--bg-input); color: var(--text-dim); cursor: default; }

.empty-list { text-align: center; padding: 48px 24px; color: var(--text-dim); font-size: 14px; }
.empty-list .big { font-size: 52px; margin-bottom: 14px; opacity: 0.5; }
.empty-list .dim { color: var(--text-muted); font-size: 12.5px; margin-top: 10px; line-height: 1.5; }
.search-hint { padding: 12px 14px 8px; color: var(--text-muted); font-size: 12.5px; }

.side-bottom {
  border-top: 1px solid var(--border);
  padding: 10px 14px; padding-bottom: calc(10px + var(--safe-bottom));
}
.me-row { display: flex; align-items: center; gap: 4px; }
.me-info { flex: 1; min-width: 0; padding-left: 8px; }
.me-username { font-weight: 600; font-size: 14px; }
.me-status { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.me-status .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted);
  transition: background .3s;
}
.me-status.online .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(63,194,85,0.2); }
.icon-btn {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 18px; padding: 8px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  min-width: 36px; min-height: 36px;
  transition: background .15s, color .15s, transform .12s;
  touch-action: manipulation;
}
.icon-btn:active { transform: scale(0.9); background: var(--bg-hover); }

/* ═══ MAIN ═══ */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-chat); position: relative; }
.placeholder { flex: 1; display: flex; align-items: center; justify-content: center; }
.ph-inner { text-align: center; color: var(--text-dim); padding: 20px; }
.ph-big { font-size: 92px; margin-bottom: 16px; opacity: 0.55; }
.ph-inner h2 { font-size: 24px; color: var(--text); font-weight: 700; margin-bottom: 8px; }
.ph-inner p { font-size: 14px; }

.chat-view { flex: 1; display: flex; flex-direction: column; position: relative; min-height: 0; }
.chat-top {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 18px; padding-top: calc(8px + var(--safe-top));
  height: calc(60px + var(--safe-top));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 3;
}
.back-btn {
  display: none; background: transparent; border: none;
  color: var(--text); font-size: 24px; padding: 6px 10px; border-radius: 50%;
  touch-action: manipulation;
}
.back-btn:active { background: var(--bg-hover); }
.chat-info { flex: 1; min-width: 0; }
.peer-username { font-weight: 700; font-size: 15px; }
.peer-status { font-size: 12.5px; color: var(--text-dim); }
.peer-status.online { color: var(--accent); font-weight: 500; }

#messages {
  flex: 1; overflow-y: auto; padding: 20px 4% 16px;
  display: flex; flex-direction: column; gap: 2px;
  position: relative; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb { background: rgba(120,140,170,0.3); border-radius: 4px; }

.bubble {
  max-width: min(72%, 520px); padding: 9px 14px 7px;
  border-radius: 18px; font-size: 14.5px; line-height: 1.4;
  word-wrap: break-word; position: relative; margin-bottom: 3px;
  animation: bubble-in .25s cubic-bezier(0.2,0.9,0.3,1.3);
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.bubble.out {
  align-self: flex-end; background: var(--bg-bubble-out);
  border-bottom-right-radius: 6px; color: #fff;
  box-shadow: 0 3px 12px -3px rgba(82,136,193,0.5);
}
.bubble.in {
  align-self: flex-start; background: var(--bg-bubble-in);
  border-bottom-left-radius: 6px; color: var(--text);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
}
html[data-theme="dark"] .bubble.in { border: 1px solid rgba(90,155,213,0.12); }

.bubble .btime {
  font-size: 11px; opacity: 0.75;
  float: right; margin: 4px 0 -2px 10px;
  font-feature-settings: "tnum";
  display: inline-flex; align-items: center; gap: 2px;
}
.bubble.out .btime { color: rgba(255,255,255,0.85); }
.bubble.in .btime { color: var(--text-muted); }
/* Галочки: одна белая = отправлено, две синие = прочитано */
.checks {
  display: inline-flex; margin-left: 3px; padding-right: 2px;
  font-weight: 700; font-size: 12px; line-height: 1;
  transition: color .2s;
}
.checks.sent::after {
  content: '✓';
  color: #ffffff;
  opacity: 0.92;
  letter-spacing: 0;
}
.checks.read::after {
  content: '✓✓';
  color: #7dd3fc;
  opacity: 1;
  letter-spacing: -2px;
  padding-right: 2px;
}
/* Тёмная тема — чуть ярче */
html[data-theme="dark"] .checks.read::after { color: #8fe3ff; }

.scroll-bottom {
  position: absolute; right: 18px; bottom: 90px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--glass-bg); border: 1px solid var(--glass-brd);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  color: var(--text-dim); z-index: 4;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
  animation: fade-in .2s;
  transition: transform .15s;
  touch-action: manipulation;
}
.scroll-bottom:active { transform: scale(1.1); }

.day-sep {
  align-self: center; margin: 12px 0;
  background: rgba(82,136,193,0.18);
  color: var(--accent);
  font-size: 12px; font-weight: 600;
  padding: 5px 14px; border-radius: 12px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}

.composer {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; padding-bottom: calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#msg-input {
  flex: 1; background: var(--bg-input); border: 1px solid var(--border); outline: none;
  color: var(--text); font-size: 15px; padding: 13px 18px; border-radius: 22px;
  transition: box-shadow .2s, border .2s;
  font-family: inherit;
}
#msg-input:focus { box-shadow: 0 0 0 3px var(--accent-soft); border-color: var(--accent); }
#msg-input::placeholder { color: var(--text-muted); }
#msg-input:disabled { opacity: 0.5; }
#send-btn {
  width: 46px; height: 46px; border: none; border-radius: 50%;
  background: linear-gradient(135deg, #5a9bd5, #4a89c9);
  color: #fff; display: flex; align-items: center; justify-content: center;
  transition: filter .15s, transform .15s;
  box-shadow: 0 6px 18px -6px rgba(82,136,193,0.6);
  touch-action: manipulation;
}
#send-btn:active:not(:disabled) { transform: scale(0.92); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ═══ TOASTS · Liquid Glass ═══ */
#toast-host {
  position: fixed; top: calc(14px + var(--safe-top)); right: 14px;
  z-index: 9999; display: flex; flex-direction: column; gap: 10px;
  pointer-events: none; max-width: min(400px, calc(100vw - 28px));
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.85);
  border-radius: 20px; padding: 12px 14px;
  box-shadow:
    0 12px 40px rgba(16,20,24,0.15),
    0 2px 8px rgba(16,20,24,0.06),
    inset 0 1px 0 rgba(255,255,255,0.95);
  cursor: pointer;
  animation: toast-in .38s cubic-bezier(0.2,0.9,0.3,1.4);
  min-width: 260px; position: relative; overflow: hidden;
  transition: transform .2s, opacity .25s;
}
html[data-theme="dark"] .toast {
  background: rgba(20,28,40,0.75);
  border-color: rgba(90,155,213,0.25);
  box-shadow:
    0 12px 40px rgba(0,0,0,0.6),
    0 2px 8px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.08);
}
.toast::after {
  content: ''; position: absolute; inset: 0; border-radius: 20px;
  padding: 1px; pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,0.9), transparent 40%, transparent 60%, rgba(116,182,238,0.4));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: 0.8;
}
.toast.success::before,
.toast.error::before {
  content: ''; position: absolute; top: 0; left: 0; bottom: 0;
  width: 4px;
}
.toast.success::before { background: linear-gradient(180deg, #6ee584, #3fc255); }
.toast.error::before   { background: linear-gradient(180deg, #ff7a7a, #e5504a); }
.toast.hide { opacity: 0; transform: translateY(-14px); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-16px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.toast .t-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #74b6ee, #4a89c9);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px;
  box-shadow:
    0 4px 12px -4px rgba(82,136,193,0.7),
    inset 0 1px 0 rgba(255,255,255,0.4);
}
.toast .t-body { flex: 1; min-width: 0; }
.toast .t-title { font-weight: 700; font-size: 14px; color: var(--text); margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast .t-msg { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast .t-close { background: transparent; border: none; color: var(--text-muted); font-size: 14px; padding: 4px 6px; flex-shrink: 0; border-radius: 50%; }
.toast.success .t-avatar { background: linear-gradient(135deg, #6ee584, #3fc255); }
.toast.error   .t-avatar { background: linear-gradient(135deg, #ff7a7a, #e5504a); }

/* ═══ BG PICKER ═══ */
.bg-picker { position: fixed; inset: 0; z-index: 10001; display: flex; align-items: flex-end; justify-content: center; }
.bg-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.35);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: fade-in .25s;
}
.bg-sheet {
  position: relative; z-index: 1;
  border-radius: 24px 24px 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  width: 100%; max-width: 520px;
  animation: slide-up .35s cubic-bezier(0.2,0.9,0.3,1.2);
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.bg-sheet h4 { font-size: 16px; margin-bottom: 16px; text-align: center; font-weight: 700; }
.bg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.bg-item {
  aspect-ratio: 1; border-radius: 18px; cursor: pointer;
  border: 2.5px solid transparent;
  transition: transform .18s, border-color .18s, box-shadow .18s;
  overflow: hidden; position: relative;
  touch-action: manipulation;
  box-shadow: 0 4px 16px -6px rgba(16,20,24,0.2);
}
.bg-item:active { transform: scale(0.96); }
.bg-item.active { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), 0 4px 16px -6px rgba(16,20,24,0.2); }
.bg-item[data-bg="ocean"]   { background: linear-gradient(180deg, #c8e0f5, #a8c8ea); }
.bg-item[data-bg="sunset"]  { background: linear-gradient(180deg, #ffd6ba, #ffb0c8); }
.bg-item[data-bg="night"]   { background: linear-gradient(180deg, #1a2540, #3a4a70); }
.bg-item[data-bg="neon"]    { background: linear-gradient(135deg, #a855f7, #ec4899); }
.bg-item[data-bg="forest"]  { background: linear-gradient(180deg, #a7f3d0, #86efac); }
.bg-item[data-bg="minimal"] { background: #eef2f8; }
.bg-item .label {
  position: absolute; bottom: 8px; left: 8px; right: 8px;
  font-size: 11px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  text-align: center; font-weight: 600;
}
.bg-item[data-bg="minimal"] .label { color: var(--text-dim); text-shadow: none; }
.bg-close {
  width: 100%; padding: 14px; border-radius: 14px;
  background: linear-gradient(135deg, #5a9bd5, #4a89c9);
  color: #fff; font-weight: 700; font-size: 15px; border: none;
  touch-action: manipulation;
}
.bg-close:active { transform: scale(0.99); }

/* ═══ MOBILE ═══ */
@media (max-width: 760px) {
  #sidebar {
    position: absolute; inset: 0; width: 100%; z-index: 10;
    transition: transform .35s cubic-bezier(0.2,0.9,0.3,1);
  }
  #main { width: 100%; }
  #chat-screen.chat-open #sidebar { transform: translateX(-100%); }
  .back-btn { display: flex; align-items: center; }
  .placeholder { display: none; }
  .bubble { max-width: 86%; }
  #toast-host { left: 14px; right: 14px; max-width: none; }
  .brand-title { font-size: 34px; }
  .tg-logo { font-size: 68px; }
}
