/* Дизайн-система: Minimalism & Swiss Style (ui-ux-pro-max) */
:root {
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --primary-soft: #EFF4FF;
  --on-primary: #FFFFFF;
  --page: #F1F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --muted: #F1F5F9;
  --fg: #0F172A;
  --fg-2: #475569;
  --fg-3: #64748B;
  --border: #E2E8F0;
  --online: #059669;
  --danger: #DC2626;
  --ring: #2563EB;
  --scrim: rgba(15, 23, 42, .5);

  /* тона аватаров: фон / текст */
  --t0-bg: #DBEAFE; --t0-fg: #1D4ED8;
  --t1-bg: #FFE4E6; --t1-fg: #BE123C;
  --t2-bg: #CCFBF1; --t2-fg: #0F766E;
  --t3-bg: #FEF3C7; --t3-fg: #B45309;
  --t4-bg: #DCFCE7; --t4-fg: #15803D;
  --t5-bg: #EDE9FE; --t5-fg: #6D28D9;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --dur: 180ms;
  --ease: cubic-bezier(.2, 0, 0, 1);
}
body.dark {
  color-scheme: dark;
  --primary: #3B82F6;
  --primary-hover: #60A5FA;
  --primary-soft: #172554;
  --page: #020617;
  --surface: #0F172A;
  --surface-2: #0B1222;
  --muted: #1E293B;
  --fg: #F1F5F9;
  --fg-2: #CBD5E1;
  --fg-3: #94A3B8;
  --border: #1E293B;
  --online: #34D399;
  --danger: #F87171;
  --ring: #60A5FA;
  --scrim: rgba(0, 0, 0, .65);

  --t0-bg: #1E3A8A; --t0-fg: #BFDBFE;
  --t1-bg: #881337; --t1-fg: #FECDD3;
  --t2-bg: #134E4A; --t2-fg: #99F6E4;
  --t3-bg: #78350F; --t3-fg: #FDE68A;
  --t4-bg: #14532D; --t4-fg: #BBF7D0;
  --t5-bg: #4C1D95; --t5-fg: #DDD6FE;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 16px; line-height: 1.5;
  background: var(--page); color: var(--fg);
  display: flex; justify-content: center; align-items: center;
  padding: 24px;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font: inherit; color: var(--fg); }
svg { display: block; flex-shrink: 0; }
a { color: var(--primary); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--r-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ===== Кнопки ===== */
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--r-md); display: grid; place-items: center;
  color: var(--fg-3); transition: background var(--dur) var(--ease), color var(--dur) var(--ease); flex-shrink: 0;
}
.icon-btn:hover { background: var(--muted); color: var(--fg); }
.icon-btn svg { width: 20px; height: 20px; }

.btn {
  width: 100%; height: 48px; border-radius: var(--r-md); font-weight: 600; font-size: 15px;
  background: var(--primary); color: var(--on-primary);
  transition: background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--primary-hover); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-secondary { background: var(--muted); color: var(--fg); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-link { background: none; color: var(--primary); height: 44px; font-weight: 500; }
.btn-link:hover:not(:disabled) { background: var(--primary-soft); }
.btn-link:disabled { color: var(--fg-3); opacity: 1; background: none; }

.mark {
  width: 48px; height: 48px; border-radius: var(--r-md); background: var(--primary);
  display: grid; place-items: center; color: var(--on-primary); margin-bottom: 24px;
}
.mark svg { width: 24px; height: 24px; }

/* ===== Карточка (онбординг + вход) ===== */
.card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 40px 32px 32px; position: relative;
}

/* Онбординг */
.onboarding { position: fixed; inset: 0; background: var(--page); display: flex; justify-content: center; align-items: center; z-index: 100; padding: 16px; }
.onboarding.hidden { display: none; }
.skip { position: absolute; top: 16px; right: 16px; height: 44px; padding: 0 12px; font-size: 14px; color: var(--fg-3); border-radius: var(--r-sm); }
.skip:hover { color: var(--fg); background: var(--muted); }
.slide { display: none; }
.slide.active { display: block; animation: fade 240ms var(--ease); }
.slide-icon {
  width: 56px; height: 56px; border-radius: var(--r-md); margin-bottom: 24px;
  display: grid; place-items: center; background: var(--primary-soft); color: var(--primary);
}
.slide-icon svg { width: 26px; height: 26px; }
.slide h2 { font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; margin-bottom: 8px; }
.slide p { color: var(--fg-2); margin-bottom: 32px; min-height: 72px; }
.onb-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.onb-foot .btn { width: auto; padding: 0 24px; }
.dots { display: flex; gap: 6px; }
.dot { width: 24px; height: 4px; border-radius: 2px; background: var(--border); transition: background var(--dur) var(--ease); position: relative; }
.dot::after { content: ''; position: absolute; inset: -20px -2px; }
.dot.active { background: var(--primary); }

/* Вход */
.auth { display: none; }
.auth.shown { display: block; animation: fade 240ms var(--ease); }
.auth h1 { font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; margin-bottom: 8px; }
.auth .sub { color: var(--fg-2); margin-bottom: 24px; }
.auth .sub b { color: var(--fg); font-weight: 600; }
.label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.field { position: relative; margin-bottom: 16px; }
.input-wrap { position: relative; }
.input-wrap .prefix { position: absolute; left: 14px; top: 0; height: 48px; display: flex; align-items: center; color: var(--fg-3); pointer-events: none; }
.input {
  width: 100%; height: 48px; padding: 0 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); font-size: 16px; outline: none; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder { color: var(--fg-3); }
.input.with-prefix { padding-left: 32px; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.invalid { border-color: var(--danger); }
.code-input { text-align: center; font-size: 24px; font-weight: 600; letter-spacing: .5em; padding-left: .5em; font-variant-numeric: tabular-nums; }
.helper { font-size: 13px; color: var(--fg-3); margin-top: 6px; }
.error { color: var(--danger); font-size: 13px; margin-top: 6px; display: none; }
.error.shown { display: block; }
.foot-hint { font-size: 14px; color: var(--fg-2); margin-top: 20px; text-align: center; }
.demo-note {
  margin-top: 16px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--muted);
  font-size: 13px; color: var(--fg-2); display: flex; gap: 8px; align-items: center;
}
.demo-note svg { width: 16px; height: 16px; color: var(--fg-3); }
.demo-note b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.step { display: none; }
.step.active { display: block; animation: fade 200ms var(--ease); }
.back-link { display: inline-flex; align-items: center; gap: 2px; height: 44px; padding-right: 8px; margin: -12px 0 12px -8px; color: var(--fg-2); font-size: 14px; border-radius: var(--r-sm); }
.back-link:hover { color: var(--fg); }
.back-link svg { width: 18px; height: 18px; }

/* ===== Мессенджер ===== */
.shell {
  display: none; width: 100%; max-width: 1200px; height: min(840px, calc(100vh - 48px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden;
}
.shell.shown { display: flex; animation: fade 240ms var(--ease); }

.sidebar { width: 340px; border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; background: var(--surface); }
.sidebar-head { height: 64px; padding: 0 12px 0 20px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; color: var(--on-primary); }
.brand-mark svg { width: 15px; height: 15px; }
.head-actions { display: flex; align-items: center; gap: 2px; }
.me-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }

.search { margin: 0 16px 12px; position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--fg-3); pointer-events: none; }
.search input {
  -webkit-appearance: none; appearance: none; color-scheme: inherit;
  width: 100%; height: 40px; padding: 0 12px 0 38px; background: var(--muted); border: 1px solid transparent;
  border-radius: var(--r-md); font-size: 14px; outline: none; transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.search input::placeholder { color: var(--fg-3); }
.search input:focus { border-color: var(--primary); background: var(--surface); }

.tabs { display: flex; gap: 4px; padding: 0 16px 8px; border-bottom: 1px solid var(--border); }
.tab {
  height: 36px; padding: 0 12px; font-size: 14px; font-weight: 500; color: var(--fg-3);
  border-radius: var(--r-sm); transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.tab:hover { color: var(--fg); background: var(--muted); }
.tab[aria-selected="true"] { color: var(--fg); background: var(--muted); }

.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md);
  cursor: pointer; transition: background var(--dur) var(--ease); width: 100%; text-align: left;
}
.chat-item:hover { background: var(--surface-2); }
body.dark .chat-item:hover { background: var(--muted); }
.chat-item.active { background: var(--primary-soft); }
.chat-info { flex: 1; min-width: 0; }
.chat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 12px; color: var(--fg-3); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.chat-item.unread .chat-time { color: var(--primary); font-weight: 600; }
.last { font-size: 14px; color: var(--fg-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.last .who { color: var(--fg-2); }
.last .typing { color: var(--primary); }
.badge {
  background: var(--primary); color: var(--on-primary); font-size: 12px; font-weight: 600; min-width: 20px; height: 20px;
  border-radius: 10px; display: grid; place-items: center; padding: 0 6px; flex-shrink: 0; align-self: center; font-variant-numeric: tabular-nums;
}
.empty-search { text-align: center; color: var(--fg-3); font-size: 14px; padding: 48px 16px; }

.avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 600; font-size: 17px; position: relative; flex-shrink: 0; background-size: cover; background-position: center;
}
.avatar svg { width: 20px; height: 20px; }
.avatar.sm { width: 40px; height: 40px; font-size: 15px; }
.avatar.xs { width: 32px; height: 32px; font-size: 13px; }
.avatar.lg { width: 88px; height: 88px; font-size: 32px; }
.avatar.lg svg { width: 36px; height: 36px; }
.avatar.online::after {
  content: ''; position: absolute; bottom: 0; right: 0; width: 12px; height: 12px;
  background: var(--online); border: 2px solid var(--surface); border-radius: 50%;
}
.chat-item.active .avatar.online::after { border-color: var(--primary-soft); }
.t0 { background: var(--t0-bg); color: var(--t0-fg); } .t1 { background: var(--t1-bg); color: var(--t1-fg); }
.t2 { background: var(--t2-bg); color: var(--t2-fg); } .t3 { background: var(--t3-bg); color: var(--t3-fg); }
.t4 { background: var(--t4-bg); color: var(--t4-fg); } .t5 { background: var(--t5-bg); color: var(--t5-fg); }
.tsaved { background: var(--primary); color: var(--on-primary); }
.c0 { color: var(--t0-fg); } .c1 { color: var(--t1-fg); } .c2 { color: var(--t2-fg); }
.c3 { color: var(--t3-fg); } .c4 { color: var(--t4-fg); } .c5 { color: var(--t5-fg); }

/* Чат */
.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface-2); }
.chat-view { display: flex; flex-direction: column; height: 100%; }
.chat-head {
  height: 64px; padding: 0 12px 0 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}
.back-mobile { display: none; }
.chat-head-info { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; text-align: left; padding: 4px; margin-left: -4px; border-radius: var(--r-sm); }
.chat-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { font-size: 13px; color: var(--fg-3); }
.chat-status.online { color: var(--online); }
.chat-status.typing { color: var(--primary); }
.chat-actions { display: flex; }

.messages { flex: 1; overflow-y: auto; padding: 16px 24px 8px; display: flex; flex-direction: column; gap: 2px; }
.day-sep { align-self: center; font-size: 12px; font-weight: 500; color: var(--fg-3); padding: 4px 10px; margin: 8px 0 12px; border-radius: 999px; background: var(--muted); }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: min(70%, 520px); }
.msg.new { animation: rise 200ms var(--ease); }
.msg.own { align-self: flex-end; flex-direction: row-reverse; }
.msg:not(.same) { margin-top: 10px; }
.msg-ava { width: 32px; flex-shrink: 0; }
.bubble {
  padding: 8px 12px 6px; border-radius: 16px; background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); font-size: 15px; line-height: 1.45; word-break: break-word; min-width: 72px;
}
.msg:not(.own).tail .bubble { border-bottom-left-radius: 4px; }
.msg.own .bubble { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.msg.own.tail .bubble { border-bottom-right-radius: 4px; }
.sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.meta { font-size: 11px; display: flex; align-items: center; justify-content: flex-end; gap: 3px; margin-top: 2px; color: var(--fg-3); font-variant-numeric: tabular-nums; }
.msg.own .meta { color: rgba(255,255,255,.85); }
.meta svg { width: 15px; height: 15px; }
.attach-img { max-width: 280px; width: 100%; border-radius: 10px; display: block; margin: 2px 0 6px; aspect-ratio: 13 / 9; object-fit: cover; }
.attach-file { display: flex; align-items: center; gap: 10px; padding: 2px 0 4px; }
.ficon { width: 40px; height: 40px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; flex-shrink: 0; }
.msg.own .ficon { background: rgba(255,255,255,.18); color: #fff; }
.ficon svg { width: 20px; height: 20px; }
.fname { font-weight: 500; font-size: 14px; }
.fsize { font-size: 12px; color: var(--fg-3); }
.msg.own .fsize { color: rgba(255,255,255,.85); }

.typing-bubble { display: flex; gap: 4px; padding: 14px 14px; min-width: 0; }
.typing-bubble span { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-3); animation: blink 1.2s infinite; }
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }

.empty-chat { margin: auto; text-align: center; max-width: 300px; display: flex; flex-direction: column; align-items: center; }
.empty-chat h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.empty-chat p { font-size: 14px; color: var(--fg-2); }

.composer { padding: 8px 16px 16px; flex-shrink: 0; }
.file-chip {
  display: none; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border);
  padding: 6px 4px 6px 6px; border-radius: var(--r-md); margin-bottom: 8px; font-size: 14px;
}
.file-chip.shown { display: flex; }
.file-chip img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.file-chip .chip-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-row {
  display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 4px; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.composer-row:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.composer-row input { flex: 1; border: none; outline: none; background: none; font-size: 15px; height: 44px; min-width: 0; padding: 0 4px; }
.composer-row input::placeholder { color: var(--fg-3); }
.send-btn {
  width: 44px; height: 44px; border-radius: var(--r-md); background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; flex-shrink: 0; transition: background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.send-btn:hover:not(:disabled) { background: var(--primary-hover); }
.send-btn:disabled { background: var(--muted); color: var(--fg-3); cursor: default; }
.send-btn svg { width: 20px; height: 20px; }
#fileInput, #avatarInput { display: none; }

/* Настройки */
.settings { display: none; flex-direction: column; height: 100%; background: var(--surface-2); }
.settings.shown { display: flex; }
.settings-body { flex: 1; overflow-y: auto; padding: 32px 24px; max-width: 560px; width: 100%; margin: 0 auto; }
.profile-top { display: flex; align-items: center; gap: 16px; margin-bottom: 32px; }
.ava-edit { position: relative; border-radius: 50%; }
.ava-edit .cam {
  position: absolute; right: -2px; bottom: -2px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface); color: var(--fg); display: grid; place-items: center; border: 1px solid var(--border);
}
.ava-edit .cam svg { width: 16px; height: 16px; }
.pname { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.puser { color: var(--fg-3); font-size: 14px; }
.group-title { font-size: 13px; font-weight: 600; color: var(--fg-3); margin: 0 0 8px 4px; }
.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: 24px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; min-height: 52px; }
.row + .row { border-top: 1px solid var(--border); }
.row label, .row .lbl { font-size: 15px; flex-shrink: 0; }
.row input { background: none; border: none; outline: none; text-align: right; font-size: 15px; color: var(--fg-2); flex: 1; min-width: 0; height: 44px; }
.row input:focus { color: var(--fg); }
.row input:disabled { color: var(--fg-3); }
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 13px; transition: background var(--dur) var(--ease); }
body.dark .slider { background: #334155; }
.slider::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform var(--dur) var(--ease); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--ring); outline-offset: 2px; }
.logout { width: 100%; height: 52px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); color: var(--danger); font-weight: 500; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 8px; transition: background var(--dur) var(--ease); }
.logout:hover { background: var(--muted); }
.logout svg { width: 18px; height: 18px; }

/* Модалка профиля */
.overlay { position: fixed; inset: 0; background: var(--scrim); display: none; justify-content: center; align-items: center; z-index: 200; padding: 16px; }
.overlay.shown { display: flex; animation: fade 150ms var(--ease); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 32px 24px 24px; text-align: center; width: 100%; max-width: 340px; animation: rise 200ms var(--ease); }
.modal .avatar { margin: 0 auto 16px; }
.modal .pstatus { font-size: 14px; color: var(--fg-3); margin: 4px 0 24px; }
.modal .pstatus.online { color: var(--online); }
.modal-actions { display: flex; gap: 8px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 8px); background: var(--fg); color: var(--surface);
  padding: 10px 16px; border-radius: var(--r-md); font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); z-index: 300; max-width: calc(100% - 32px); text-align: center;
}
.toast.shown { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

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

.chat-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }

/* ===== Адаптив ===== */
@media (max-width: 760px) {
  body { padding: 0; }
  .card { border: none; border-radius: 0; min-height: 100dvh; padding: 72px 20px 32px; max-width: none; }
  .onboarding { padding: 0; }
  .shell { height: 100dvh; max-width: none; border: none; border-radius: 0; }
  .sidebar { width: 100%; border-right: none; }
  .chat-area { display: none; }
  .shell.show-chat .sidebar { display: none; }
  .shell.show-chat .chat-area { display: flex; }
  .back-mobile { display: grid; margin-left: -8px; }
  .chat-head { padding: 0 8px; }
  .messages { padding: 12px 12px 4px; }
  .msg { max-width: 85%; }
  .composer { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
  .attach-img { max-width: 230px; }
}

/* ===== Дополнительно для рабочей версии ===== */
[hidden] { display: none !important; }
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--page); z-index: 400; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn.loading { color: transparent; position: relative; pointer-events: none; }
.btn.loading::after { content: ''; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; animation: spin .8s linear infinite; }

.conn-banner { padding: 6px 16px; font-size: 13px; text-align: center; background: var(--muted); color: var(--fg-2); flex-shrink: 0; }

.code-shown { margin-top: 16px; padding: 12px; border-radius: var(--r-md); background: var(--primary-soft); color: var(--fg); font-size: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.code-shown b { font-size: 20px; letter-spacing: .2em; font-variant-numeric: tabular-nums; color: var(--primary); }

.no-chat { margin: auto; text-align: center; color: var(--fg-2); display: flex; flex-direction: column; align-items: center; padding: 24px; }
.no-chat h3 { color: var(--fg); font-size: 17px; margin-bottom: 4px; }

.load-more { align-self: center; margin-bottom: 8px; height: 36px; padding: 0 14px; border-radius: 999px; font-size: 13px; color: var(--fg-2); background: var(--muted); }
.sys-msg { align-self: center; font-size: 13px; color: var(--fg-3); margin: 10px 0; text-align: center; max-width: 80%; }
.call-line { display: flex; align-items: center; gap: 8px; }
.call-line svg { width: 18px; height: 18px; }
.attach-img { cursor: zoom-in; background: var(--muted); }
.attach-file { color: inherit; text-decoration: none; }
.attach-file:hover { text-decoration: none; }
.msg.pending .bubble { opacity: .7; }

/* Модальные окна */
.modal.wide { max-width: 440px; text-align: left; padding: 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { font-size: 18px; font-weight: 600; }
.modal-head .icon-btn { margin-right: -8px; }
.seg { display: flex; background: var(--muted); border-radius: var(--r-md); padding: 3px; margin-bottom: 16px; }
.seg button { flex: 1; height: 36px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--fg-2); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(15,23,42,.08); }
.user-results { max-height: 300px; overflow-y: auto; margin: 8px -8px 0; }
.user-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; border-radius: var(--r-md); text-align: left; }
.user-row:hover { background: var(--surface-2); }
body.dark .user-row:hover { background: var(--muted); }
.user-row .u-name { font-weight: 500; font-size: 15px; }
.user-row .u-sub { font-size: 13px; color: var(--fg-3); }
.user-row .u-check { margin-left: auto; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; color: #fff; flex-shrink: 0; }
.user-row[aria-checked="true"] .u-check { background: var(--primary); border-color: var(--primary); }
.user-row .u-check svg { width: 14px; height: 14px; }
.hint-empty { color: var(--fg-3); font-size: 14px; text-align: center; padding: 24px 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.chip { height: 28px; padding: 0 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; }
.modal-foot { margin-top: 16px; }

/* Просмотр изображений */
.lightbox { position: fixed; inset: 0; background: rgba(2,6,23,.92); display: none; align-items: center; justify-content: center; z-index: 250; padding: 24px; }
.lightbox.shown { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lightbox .icon-btn { position: absolute; top: 12px; right: 12px; color: #fff; }
.lightbox .icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }

/* Экран звонка */
.call { position: fixed; inset: 0; z-index: 350; background: #0B1222; color: #F1F5F9; display: none; flex-direction: column; }
.call.shown { display: flex; animation: fade 200ms var(--ease); }
.call video { background: #000; }
.call .remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.call .local { position: absolute; right: 16px; top: 16px; width: 160px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 12px; border: 1px solid rgba(255,255,255,.15); z-index: 2; transform: scaleX(-1); }
.call-info { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; padding: 24px; }
.call.has-video .call-info { justify-content: flex-start; padding-top: 40px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.call.has-video .call-info .avatar { display: none; }
.call-info .avatar { margin-bottom: 12px; }
.call-name { font-size: 24px; font-weight: 600; }
.call-state { font-size: 15px; color: #94A3B8; font-variant-numeric: tabular-nums; }
.call.has-video .call-state { color: #E2E8F0; }
.call-controls { position: relative; z-index: 2; display: flex; justify-content: center; gap: 20px; padding: 24px 16px calc(32px + env(safe-area-inset-bottom)); }
.call-btn { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.12); color: #fff; transition: background var(--dur) var(--ease); }
.call-btn:hover { background: rgba(255,255,255,.2); }
.call-btn[aria-pressed="true"] { background: #F1F5F9; color: #0F172A; }
.call-btn.danger { background: #DC2626; }
.call-btn.danger:hover { background: #B91C1C; }
.call-btn.accept { background: #059669; }
.call-btn.accept:hover { background: #047857; }
.call-btn svg { width: 26px; height: 26px; }
.call-btn-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; color: #CBD5E1; }
@media (max-width: 760px) { .call .local { width: 104px; } }

/* ===================================================================
   v3 — функции как в Telegram + Minimalism/Swiss + micro-interactions
   (рекомендации ui-ux-pro-max для Chat & Messaging App)
   =================================================================== */
:root { --glass: rgba(255,255,255,.78); --press: cubic-bezier(.3,0,.2,1); --head-h: 64px; }
body.dark { --glass: rgba(15,23,42,.72); }

/* Нажатия: короткий отклик, без сдвига раскладки */
.icon-btn, .send-btn, .chat-item, .quick, .menu-item, .reaction, .mr, .vplay, .user-row { transition: transform 120ms var(--press), background var(--dur) var(--ease), color var(--dur) var(--ease); }
.icon-btn:active, .send-btn:active:not(:disabled), .vplay:active, .quick:active { transform: scale(.92); }
.chat-item:active, .user-row:active, .menu-item:active { transform: scale(.985); }
.btn:active:not(:disabled) { transform: scale(.98); }

/* Стеклянная шапка чата поверх ленты */
.chat-view { position: relative; }
.chat-view > .chat-head {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3; border-bottom-color: transparent;
  background: var(--glass); -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
  box-shadow: 0 1px 0 var(--border);
}
.chat-view > .messages { padding-top: calc(var(--head-h) + 12px); }
.chat-head-info:hover:not(:disabled) .chat-title { color: var(--primary); }

/* Даты закреплены при прокрутке */
.day-sep { position: sticky; top: calc(var(--head-h) + 8px); z-index: 2; background: none; padding: 0; margin: 10px 0; }
.day-sep span { display: inline-block; font-size: 12px; font-weight: 500; color: var(--fg-2); padding: 4px 12px; border-radius: 999px; background: var(--glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: 0 0 0 1px var(--border); }
.sys-msg { margin: 8px 0; }
.sys-msg span { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--muted); font-size: 13px; color: var(--fg-2); }

/* Пузыри */
.msg { max-width: min(72%, 560px); }
.bubble-wrap { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; gap: 4px; }
.msg.own .bubble-wrap { align-items: flex-end; }
.bubble { box-shadow: 0 1px 1px rgba(15,23,42,.04); transition: box-shadow var(--dur) var(--ease), transform 120ms var(--press); -webkit-touch-callout: none; }
.msg.own .bubble { box-shadow: none; }
.msg.menu-target .bubble { box-shadow: 0 0 0 2px var(--primary); }
.msg.own.menu-target .bubble { box-shadow: 0 0 0 2px var(--primary-soft), 0 0 0 4px var(--primary); }
.msg.flash .bubble { animation: flash 1.2s var(--ease); }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--primary); } 100% { box-shadow: 0 0 0 0 transparent; } }
.mtext { white-space: pre-wrap; }
.mtext a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.meta .edited { margin-right: 4px; font-style: italic; }
.msg.new .bubble { animation: bubble-in 220ms var(--press); }
.msg.own.new .bubble { transform-origin: bottom right; }
.msg:not(.own).new .bubble { transform-origin: bottom left; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }
.msg.new { animation: none; }

/* Цитата ответа */
.reply-quote {
  display: flex; flex-direction: column; width: 100%; text-align: left; margin: 2px 0 6px; padding: 4px 10px;
  border-left: 3px solid currentColor; border-radius: 6px; background: color-mix(in srgb, currentColor 10%, transparent); cursor: pointer; min-width: 0;
}
.reply-quote:hover { background: color-mix(in srgb, currentColor 16%, transparent); }
.rq-name { font-size: 13px; font-weight: 600; }
.rq-text { font-size: 13px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.msg.own .reply-quote { color: #fff; }
.msg.own .rq-text { color: rgba(255,255,255,.85); }

/* Реакции */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; }
.reaction {
  height: 28px; padding: 0 8px; border-radius: 999px; display: inline-flex; align-items: center; gap: 4px; font-size: 15px;
  background: var(--surface); border: 1px solid var(--border); color: var(--fg-2);
}
.reaction b { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.reaction:hover { border-color: var(--primary); }
.reaction.mine { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.msg.new .reaction, .reaction.mine { animation: pop 260ms var(--press); }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* Голосовые */
.msg.voice .bubble { min-width: 240px; }
.voice-player { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.vplay { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); flex-shrink: 0; }
.vplay svg { width: 18px; height: 18px; }
.msg.own .vplay { background: #fff; color: var(--primary); }
.vbody { flex: 1; min-width: 0; }
.vw { display: flex; align-items: center; gap: 2px; height: 28px; cursor: pointer; }
.vw i { flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px; background: var(--fg-3); opacity: .45; transition: opacity 80ms linear, background 80ms linear; }
.vw i.on { opacity: 1; background: var(--primary); }
.msg.own .vw i { background: #fff; opacity: .45; }
.msg.own .vw i.on { opacity: 1; }
.vtime { font-size: 12px; color: var(--fg-3); font-variant-numeric: tabular-nums; margin-top: 2px; }
.msg.own .vtime { color: rgba(255,255,255,.85); }

/* Кнопка «вниз» */
.to-bottom {
  position: absolute; right: 20px; bottom: 92px; z-index: 3; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface); color: var(--fg-2); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(15,23,42,.12); animation: rise 180ms var(--press);
}
.to-bottom svg { width: 22px; height: 22px; }
.to-bottom:hover { color: var(--primary); }
.to-bottom .badge { position: absolute; top: -6px; right: -4px; }

/* Перетаскивание файла */
.drop-zone { position: absolute; inset: 8px; z-index: 5; border-radius: var(--r-lg); border: 2px dashed var(--primary); background: color-mix(in srgb, var(--primary-soft) 92%, transparent); display: grid; place-items: center; pointer-events: none; animation: fade 120ms var(--ease); }
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--primary); font-weight: 600; }
.drop-inner svg { width: 32px; height: 32px; }

/* Ответ / редактирование над полем ввода */
.compose-ctx { display: flex; align-items: center; gap: 10px; padding: 6px 4px 6px 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); animation: rise 160ms var(--press); }
.ctx-icon { color: var(--primary); display: grid; }
.ctx-icon svg { width: 20px; height: 20px; }
.ctx-body { flex: 1; min-width: 0; border-left: 2px solid var(--primary); padding-left: 10px; }
.ctx-title { font-size: 13px; font-weight: 600; color: var(--primary); }
.ctx-text { font-size: 13px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Микрофон ↔ отправить */
.send-btn:not([hidden]) { animation: pop 200ms var(--press); }
.send-btn.mic { background: var(--muted); color: var(--fg-2); }
.send-btn.mic:hover { background: var(--primary); color: var(--on-primary); }

/* Запись голоса */
.rec-bar { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--primary); border-radius: var(--r-lg); padding: 4px; box-shadow: 0 0 0 3px var(--primary-soft); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; flex-shrink: 0; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 40px; }
.rec-wave { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 2px; height: 28px; overflow: hidden; }
.rec-wave i { width: 3px; border-radius: 2px; background: var(--primary); flex-shrink: 0; }
#recCancel:hover { color: var(--danger); }

/* Контекстное меню */
.ctx-menu {
  position: fixed; z-index: 400; min-width: 220px; padding: 6px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 12px 40px rgba(15,23,42,.18); animation: menu-in 140ms var(--press); transform-origin: top left;
}
body.dark .ctx-menu { box-shadow: 0 12px 40px rgba(0,0,0,.55); }
@keyframes menu-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.menu-reactions { display: flex; gap: 2px; padding: 2px 2px 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.mr { width: 36px; height: 36px; border-radius: 50%; font-size: 20px; display: grid; place-items: center; }
.mr:hover { transform: scale(1.22); background: var(--muted); }
.mr.mine { background: var(--primary-soft); }
.menu-item { width: 100%; height: 40px; display: flex; align-items: center; gap: 12px; padding: 0 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.menu-item svg { width: 18px; height: 18px; color: var(--fg-3); }
.menu-item:hover, .menu-item:focus-visible { background: var(--muted); outline: none; }
.menu-item.danger, .menu-item.danger svg { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* Диалоги */
.modal.dialog { text-align: left; max-width: 360px; padding: 24px; }
.dialog h2 { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.dialog p { color: var(--fg-2); font-size: 15px; margin-bottom: 20px; }
.dialog .input { margin: 8px 0 20px; }
.btn-danger { background: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #B91C1C; }

/* Профиль */
.modal.profile-modal { position: relative; max-width: 380px; padding: 28px 20px 16px; max-height: calc(100dvh - 32px); overflow-y: auto; }
.modal-x { position: absolute; top: 8px; right: 8px; }
.profile-modal .pname { font-size: 20px; }
.profile-modal .pstatus { margin: 2px 0 20px; }
.quick-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.quick { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: var(--r-md); background: var(--muted); font-size: 12px; font-weight: 500; color: var(--primary); }
.quick svg { width: 22px; height: 22px; }
.quick:hover { background: var(--primary-soft); }
.info-list { text-align: left; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: 16px; }
body.dark .info-list { background: var(--muted); }
.info-row { padding: 10px 14px; }
.info-row + .info-row { border-top: 1px solid var(--border); }
.info-value { font-size: 15px; word-break: break-word; }
.info-label { font-size: 12px; color: var(--fg-3); }
.members-block { text-align: left; margin-bottom: 8px; }
.members-head { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 6px; font-size: 13px; font-weight: 600; color: var(--fg-3); }
.btn-text { color: var(--primary); font-weight: 600; font-size: 14px; height: 36px; padding: 0 8px; border-radius: 8px; }
.btn-text:hover { background: var(--primary-soft); }
.members-list { max-height: 260px; overflow-y: auto; }
.member-row { display: flex; align-items: center; gap: 12px; padding: 6px 4px; border-radius: var(--r-md); }
.member-info { flex: 1; min-width: 0; }
.member-info .u-name { font-size: 15px; font-weight: 500; }
.member-info .u-sub { font-size: 13px; color: var(--fg-3); }
.member-info .u-sub.online { color: var(--online); }
.role { font-size: 11px; font-weight: 600; color: var(--primary); background: var(--primary-soft); padding: 1px 6px; border-radius: 999px; margin-left: 4px; vertical-align: 1px; }
.danger-row { width: 100%; height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--danger); font-weight: 500; border-radius: var(--r-md); margin-top: 4px; }
.danger-row svg { width: 18px; height: 18px; }
.danger-row:hover { background: var(--muted); }

/* Список чатов: закреп, без звука, галочки */
.chat-name-wrap { display: flex; align-items: center; gap: 4px; min-width: 0; }
.muted-ic svg { width: 14px; height: 14px; color: var(--fg-3); }
.pin-ic { color: var(--fg-3); display: grid; align-self: center; }
.pin-ic svg { width: 16px; height: 16px; transform: rotate(45deg); }
.badge.muted { background: var(--fg-3); }
.chat-time { display: inline-flex; align-items: center; gap: 2px; }
.list-tick svg { width: 16px; height: 16px; color: var(--fg-3); }
.list-tick.read svg { color: var(--primary); }

/* Скелетон загрузки */
.skeleton { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.sk-msg { height: 40px; border-radius: 16px; background: linear-gradient(90deg, var(--muted) 0%, var(--border) 50%, var(--muted) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.sk-msg.own { align-self: flex-end; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (max-width: 760px) {
  :root { --head-h: 56px; }
  .chat-view > .chat-head { height: 56px; }
  .to-bottom { right: 12px; bottom: 80px; }
  .msg { max-width: 86%; }
  .msg.voice .bubble { min-width: 220px; }
  .rq-text { max-width: 220px; }
  .quick { font-size: 11px; }
}

/* ===== PWA: установка и уведомления ===== */
.install-card { display: flex; align-items: center; gap: 10px; margin: 0 12px 8px; padding: 10px 6px 10px 10px; border-radius: var(--r-md); background: var(--primary-soft); animation: rise 200ms var(--press); }
.install-card img { border-radius: 10px; flex-shrink: 0; }
.install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; color: var(--fg-2); line-height: 1.35; }
.install-text b { color: var(--fg); font-size: 14px; }
.install-btn { width: auto; height: 36px; padding: 0 12px; font-size: 13px; flex-shrink: 0; }
.install-card .icon-btn { width: 36px; height: 36px; }
.push-hint { font-size: 13px; color: var(--fg-3); margin: -12px 4px 24px; }
@media (display-mode: standalone) { body { padding: 0; } .shell { height: 100dvh; max-width: none; border: none; border-radius: 0; } }
