:root,
html[data-theme="dark"] {
  --bg: #0e1621;
  --bg-sidebar: #17212b;
  --bg-chat: #0e1621;
  --bg-header: #17212b;
  --bg-composer: #17212b;
  --bg-bubble: #182533;
  --bg-bubble-mine: #2b5278;
  --bg-hover: rgba(255,255,255,0.04);
  --bg-active: #202b36;
  --ink: #f5f7fa;
  --muted: #7f8b99;
  --line: rgba(255,255,255,0.06);
  --accent: #5288c1;
  --accent-2: #6ab3f3;
  --ok: #4fae4e;
  --danger: #e53935;
  --alert-bg: #3d2e14;
  --alert-border: #e2a100;
  --alert-ink: #ffd666;
  --shadow: 0 12px 40px rgba(0,0,0,0.45);
  --radius: 14px;
  --font: "Manrope", system-ui, sans-serif;
  --sidebar-w: 340px;
  --sb-size: 6px;
  --sb-track: transparent;
  --sb-thumb: rgba(255,255,255,0.18);
  --sb-thumb-hover: rgba(255,255,255,0.32);
  --menu-bg: rgba(33, 43, 54, 0.98);
  --menu-border: rgba(255,255,255,0.08);
  --emoji-popup-bg: rgba(28, 39, 51, 0.78);
  --theme-ease: background-color .28s ease, color .28s ease, border-color .28s ease, box-shadow .28s ease;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  height: 100svh;
  height: 100dvh;
}
#app {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Desktop Electron chrome */
html.is-desktop .desktop-titlebar {
  flex-shrink: 0;
  height: 40px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg-sidebar) 92%, #fff 8%), var(--bg-sidebar));
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: stretch;
  z-index: 50;
  user-select: none;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset;
}
html.is-desktop .desktop-titlebar-drag {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  -webkit-app-region: drag;
  app-region: drag;
  padding: 0 10px 0 78px; /* room for macOS traffic lights */
}
html.is-desktop[data-desktop-platform="win32"] .desktop-titlebar-drag,
html.is-desktop[data-desktop-platform="linux"] .desktop-titlebar-drag {
  padding-left: 14px;
  padding-right: 12px;
}
html.is-desktop .desktop-titlebar-brand {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: -0.03em;
  color: var(--ink);
}
html.is-desktop .desktop-titlebar-sep {
  width: 1px;
  height: 14px;
  background: var(--line);
  flex-shrink: 0;
}
html.is-desktop .desktop-titlebar-sub {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
html.is-desktop .desktop-titlebar-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(82,136,193,0.16);
  color: var(--accent-2);
  border: 1px solid rgba(82,136,193,0.28);
}
html.is-desktop .desktop-titlebar-pill.is-dnd {
  background: rgba(229,57,53,0.14);
  color: #ff8a80;
  border-color: rgba(229,57,53,0.28);
}
html.is-desktop .desktop-titlebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 10px;
  -webkit-app-region: no-drag;
  app-region: no-drag;
}
html.is-desktop[data-desktop-platform="win32"] .desktop-titlebar-actions {
  padding-right: 148px;
}
html.is-desktop .desktop-titlebar-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
html.is-desktop .desktop-titlebar-btn:hover {
  background: var(--bg-hover);
  color: var(--ink);
  border-color: var(--line);
}
html.is-desktop .desktop-titlebar-btn.is-on {
  color: #ff8a80;
  background: rgba(229,57,53,0.12);
}
html.is-desktop .shell {
  flex: 1;
  min-height: 0;
  height: auto !important;
  max-height: none;
}
html.is-desktop .login-wrap {
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(900px 420px at 12% -10%, rgba(82,136,193,0.18), transparent 55%),
    var(--bg);
}
html.is-desktop .login-card {
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  border: 1px solid var(--line);
}
html.is-desktop .side-head h1 {
  visibility: hidden;
  height: 0;
  margin: 0;
  overflow: hidden;
}
html.is-desktop .side-head {
  padding-top: 8px;
  padding-bottom: 4px;
  min-height: 0;
}
html.is-desktop .sidebar {
  box-shadow: 1px 0 0 var(--line);
}
html.is-desktop {
  --theme-ease: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}
html.is-desktop body {
  font-family: inherit;
}
html.is-desktop .msg.msg-enter { animation: none; }
html.is-desktop .typing-pulse,
html.is-desktop .typing-dots i,
html.is-desktop .alert-attention {
  animation: none !important;
}
html.is-desktop .pin-bar,
html.is-desktop .emoji-popup,
html.is-desktop .attach-sheet,
html.is-desktop .modal-backdrop {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
html.is-desktop .shell,
html.is-desktop .sidebar,
html.is-desktop .main,
html.is-desktop .composer,
html.is-desktop .chat-top,
html.is-desktop .modal {
  transition: none !important;
}
html.is-desktop .bottom-nav {
  backdrop-filter: none;
  background: var(--bg-sidebar);
}
html.is-desktop .chat-top {
  backdrop-filter: none;
  background: var(--bg-header);
}
.settings-hub-list {
  display: grid;
  gap: 2px;
}
.settings-hub-item .profile-row-lead > span {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.settings-hub-title {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
}
.settings-hub-desc {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}
.profile-panel.is-hub .profile-layout {
  gap: 8px;
}
.profile-panel.is-section .profile-layout {
  gap: 12px;
}

/* Settings home — Telegram-like grouped list (no tiles) */
.settings-home {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding-top: 4px;
}
.profile-panel.is-hub .profile-panel-body {
  padding-top: 12px;
  max-width: 520px;
}
.profile-panel.is-hub .profile-layout {
  gap: 0;
}
.settings-identity {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 4px 18px;
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
  border-bottom: 1px solid var(--line);
}
.settings-identity:hover .settings-identity-name {
  color: var(--accent-2, var(--accent));
}
.settings-identity-avatar {
  flex-shrink: 0;
  line-height: 0;
}
.settings-identity-avatar .avatar,
.settings-identity-avatar .avatar.profile-lg {
  width: 64px;
  height: 64px;
  font-size: 1.35rem;
  border-radius: 50%;
}
.settings-identity-text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}
.settings-identity-name {
  font-size: 1.2rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.25;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.settings-identity-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}
.settings-identity-dot { opacity: 0.55; }
.settings-group {
  display: grid;
  gap: 8px;
}
.settings-group-label {
  margin: 0 4px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.settings-group-body {
  border-radius: 14px;
  background: var(--bg-sidebar);
  border: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
  overflow: hidden;
}
.settings-group-empty {
  padding: 16px 14px;
}
.settings-group-empty .muted {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}
.settings-nav-row {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin: 0;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.settings-group-body > .settings-nav-row:last-child {
  border-bottom: 0;
}
.settings-nav-row:hover {
  background: var(--bg-hover);
}
.settings-nav-row:active {
  background: var(--bg-active);
}
.settings-nav-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--accent-2, var(--accent));
  background: color-mix(in srgb, var(--accent, #5288c1) 16%, transparent);
}
.settings-nav-ico .ui-ico {
  width: 18px;
  height: 18px;
}
.settings-nav-copy {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
}
.settings-nav-title {
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.settings-nav-desc {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.3;
}
.settings-nav-chevron {
  color: color-mix(in srgb, var(--muted) 80%, transparent);
  font-size: 1.35rem;
  font-weight: 300;
  line-height: 1;
  flex-shrink: 0;
  transform: translateY(-1px);
}
.settings-nav-row.is-danger {
  color: var(--danger, #e05a5a);
}
.settings-nav-row.is-danger .settings-nav-ico {
  color: var(--danger, #e05a5a);
  background: color-mix(in srgb, var(--danger, #e05a5a) 14%, transparent);
}
.settings-nav-row.is-danger .settings-nav-title {
  font-weight: 700;
}
html[data-theme="light"] .settings-group-body {
  background: color-mix(in srgb, #fff 92%, var(--bg-header));
  border-color: color-mix(in srgb, var(--line) 70%, #fff);
}
html[data-theme="light"] .settings-nav-row:hover {
  background: rgba(0, 0, 0, 0.035);
}
html.is-desktop .settings-nav-row,
html.is-desktop .settings-identity {
  transition: none;
}
@media (max-width: 720px) {
  .profile-panel.is-hub .profile-panel-body {
    padding-left: 14px;
    padding-right: 14px;
  }
  .settings-identity {
    padding-left: 2px;
    padding-right: 2px;
  }
  .settings-identity-avatar .avatar {
    width: 58px;
    height: 58px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
html.is-hidden-tab .typing-dots,
html.is-hidden-tab .typing-pulse {
  animation: none !important;
}

html.is-desktop .msg {
  -webkit-user-select: text;
}
html.is-desktop .msg-bubble {
  cursor: context-menu;
}
html.is-desktop.desktop-compact {
  --sidebar-w: 300px;
}
html.is-desktop.desktop-compact .chat-item {
  padding: 8px;
  gap: 8px;
}
html.is-desktop.desktop-compact .msg-bubble {
  font-size: 0.92rem;
}
html.is-desktop.desktop-compact .bottom-nav .bnav-btn {
  min-height: 42px;
}
html.is-desktop .desktop-shortcuts-modal {
  width: min(440px, 92vw);
}
html.is-desktop .desktop-shortcuts-grid {
  display: grid;
  gap: 10px;
  margin: 8px 0 14px;
}
html.is-desktop .desktop-shortcuts-grid > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--line);
  font-size: 0.88rem;
}
html.is-desktop .desktop-shortcuts-grid kbd {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--line);
  white-space: nowrap;
}
html.is-desktop .desktop-shortcuts-note {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.4;
}
html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  touch-action: manipulation;
  transition: var(--theme-ease);
  margin: 0;
  max-height: 100svh;
  max-height: 100dvh;
}
#app, .shell, .sidebar, .composer, .chat-top, .modal {
  transition: var(--theme-ease);
}
.main {
  /* transform must never inherit theme transition — breaks finger-tracking swipe */
  transition: background-color .28s ease, color .28s ease, border-color .28s ease, box-shadow .28s ease;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-2); }
#app {
  height: 100%;
  max-height: 100%;
  min-height: 0;
}

/* Boot preloader */
.site-preloader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background:
    radial-gradient(700px 380px at 18% 12%, rgba(82,136,193,0.16), transparent 58%),
    radial-gradient(560px 320px at 88% 88%, rgba(42,90,140,0.14), transparent 55%),
    var(--bg);
  transition: opacity .38s ease, visibility .38s ease;
}
.site-preloader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.boot-error {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 10000;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(185, 28, 28, 0.92);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  pointer-events: none;
}
.site-preloader-inner {
  display: grid;
  justify-items: center;
  gap: 14px;
  text-align: center;
  animation: preloader-rise .45s ease both;
}
.site-preloader-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 600;
  font-size: 1.45rem;
  letter-spacing: -0.04em;
  color: #fff;
  background: linear-gradient(145deg, #5288c1 0%, #2b5278 100%);
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
}
.site-preloader-brand {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.04em;
}
.site-preloader-brand span { color: var(--accent-2); }
.site-preloader-bar {
  width: 120px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  margin-top: 4px;
}
.site-preloader-bar i {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--accent-2), transparent);
  animation: preloader-slide 1.05s ease-in-out infinite;
}
@keyframes preloader-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes preloader-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

.ui-ico {
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}
.icon-btn .ui-ico,
.send-btn .ui-ico {
  display: block;
}
.btn .ui-ico,
.chip .ui-ico {
  display: inline-block;
  vertical-align: -3px;
  margin-right: 4px;
}
.chip .ui-ico { width: 12px; height: 12px; margin-right: 3px; vertical-align: -2px; }
.btn.inline-ico {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn.inline-ico .ui-ico { margin-right: 0; }
.avatar.avatar-ico {
  color: #fff;
  font-size: 0;
}
.avatar.avatar-ico .ui-ico {
  width: 20px;
  height: 20px;
}
.type-tag .ui-ico {
  width: 11px;
  height: 11px;
  display: inline-block;
  vertical-align: -1px;
}
.banner .ui-ico { color: var(--alert-ink); flex-shrink: 0; }
.file-card .ico {
  display: grid;
  place-items: center;
  color: var(--accent-2);
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  font-size: 0;
}
.file-card .ico .ui-ico { width: 18px; height: 18px; }
.pin-ico {
  display: grid;
  place-items: center;
  color: var(--accent-2);
  flex-shrink: 0;
}
.pin-ico .ui-ico { width: 16px; height: 16px; }
.chat-pin-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-2);
  width: 14px;
  height: 14px;
  margin-right: 4px;
  opacity: 0.85;
  flex-shrink: 0;
  vertical-align: middle;
}
.chat-pin-mark.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.chat-pin-mark .ui-ico { width: 12px; height: 12px; }

/* Login */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(800px 400px at 20% 0%, rgba(82,136,193,0.18), transparent 60%),
    radial-gradient(700px 400px at 100% 100%, rgba(42,90,140,0.15), transparent 55%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  padding: 36px 28px 28px;
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  animation: rise .35s ease both;
}
.brand {
  margin: 0 0 6px;
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.04em;
}
.brand span { color: var(--accent-2); }
.login-card > p { margin: 0 0 22px; color: var(--muted); font-size: .92rem; }
.login-user {
  margin: -8px 0 10px !important;
  font-weight: 700;
  color: var(--text) !important;
}
.login-methods {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}
.login-methods .btn { margin: 0; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--bg);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}
.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
}
.btn:hover { background: var(--accent-2); color: #0e1621; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--ink); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 7px 11px; font-size: .82rem; border-radius: 10px; }
.btn.block { width: 100%; }
.error { color: #ff8a80; font-size: .88rem; min-height: 1.2em; margin: 0 0 10px; }

/* Shell — Telegram layout */
.shell {
  height: 100%;
  max-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  overflow: hidden;
}
.shell.no-banner {
  grid-template-rows: 1fr;
}
.banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(90deg, #2b5278, #1e3a5f);
  color: #fff;
  padding: 10px 16px;
  text-align: center;
  font-weight: 600;
  font-size: .92rem;
}
.shell.mobile-chat-open .banner {
  display: none;
}
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head {
  padding: 14px 14px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.side-head h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.side-head h1 span { color: var(--accent-2); }
.me {
  padding: 4px 14px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 0;
}
.me:hover { background: var(--bg-hover); }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
  font-size: .85rem;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.avatar.sm { width: 36px; height: 36px; font-size: .75rem; }
.me .name { font-weight: 700; font-size: .95rem; }
.me .role { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 10px 10px;
  flex-shrink: 0;
}
.tab {
  flex: 1;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 4px;
  font-weight: 600;
  font-size: .78rem;
  line-height: 1.15;
  min-width: 0;
}
.tab .ui-ico {
  flex-shrink: 0;
  opacity: 0.9;
}
.tab span {
  display: block;
  width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tab.active { background: var(--bg-active); color: var(--ink); }
.tab.active .ui-ico { opacity: 1; }
.side-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0 6px 12px;
  /* Keep gutter reserved so pin/sort never flashes scrollbar width */
  scrollbar-gutter: stable;
}
.side-actions {
  padding: 10px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
  flex-shrink: 0;
}

/* Bottom nav — Telegram-style */
.bottom-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
  gap: 0;
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--bg-sidebar);
  padding: 4px 8px max(6px, env(safe-area-inset-bottom, 0px));
  position: relative;
  z-index: 5;
}
.bnav-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 12px;
  cursor: pointer;
  padding: 6px;
}
.bnav-btn:hover { color: var(--ink); background: var(--bg-hover); }
.bnav-btn.active { color: var(--accent); }
.bnav-btn .ui-ico { width: 22px; height: 22px; }
.bnav-letter {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  line-height: 1;
}
.bnav-mid {
  position: relative;
  display: grid;
  place-items: center;
}
.bnav-empty {
  display: block;
  width: 100%;
  min-height: 48px;
}
.staff-menu {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  min-width: 200px;
  background: var(--bg-elevated, var(--bg-header));
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  padding: 6px;
  display: grid;
  gap: 2px;
  z-index: 20;
}
.staff-menu-item {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}
.staff-menu-item:hover { background: var(--bg-hover); }
.staff-menu-item .ui-ico { opacity: 0.9; flex-shrink: 0; }

.global-search-pull {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.22s ease, opacity 0.18s ease, margin 0.22s ease;
  margin: 0 6px;
  flex-shrink: 0;
}
.global-search-pull.is-open {
  max-height: 56px;
  opacity: 1;
  margin: 0 6px 8px;
}
.global-search-pull-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 8px 0 12px;
  background: var(--bg);
  min-height: 42px;
}
.global-search-ico {
  color: var(--muted);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.global-search-pull .global-search-input {
  border: none;
  background: transparent;
  padding: 10px 4px;
  flex: 1;
  min-width: 0;
  outline: none;
}
.global-search-clear {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.profile-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 4px 0 8px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
}
.profile-toc-link {
  appearance: none;
  text-decoration: none;
  color: var(--muted);
  background: var(--bg-hover);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 650;
}
.profile-toc-link:hover {
  color: var(--ink);
  border-color: rgba(82, 136, 193, 0.45);
}
.profile-card-label .ui-ico {
  opacity: 0.85;
}

.chat-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 12px;
  padding: 10px;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  color: var(--ink);
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item.has-unread {
  background: rgba(82, 136, 193, 0.14);
}
.chat-item.has-unread:hover {
  background: rgba(82, 136, 193, 0.2);
}
.chat-item.has-unread.active {
  background: var(--bg-active);
}
.chat-item.pinned-chat .title { color: var(--ink); }
.chat-item .title {
  font-weight: 500;
  font-size: .92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 2px;
}
.chat-item.has-unread .title {
  font-weight: 800;
}
.chat-item.has-unread .preview {
  color: rgba(245, 247, 250, 0.82);
  font-weight: 500;
}
.chat-item .preview { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  font-size: .7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0 6px;
  box-shadow: 0 0 0 2px rgba(14, 22, 33, 0.35);
}
.type-tag { font-size: .65rem; color: var(--accent-2); text-transform: uppercase; letter-spacing: .03em; }

/* Main chat column — composer pinned bottom */
.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(43,82,120,0.12), transparent 50%),
    var(--bg-chat);
}
.chat-top {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  min-height: 56px;
}
.chat-top-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}
.chat-top-actions .icon-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
}
.chat-top-actions .icon-btn:hover {
  background: var(--bg-hover);
  color: var(--ink);
}
.pin-chat-btn.active {
  color: var(--accent-2);
  background: rgba(82, 136, 193, 0.22);
  border-color: rgba(106, 179, 243, 0.4);
}
.pin-chat-btn.is-locked,
.pin-chat-btn:disabled {
  opacity: 0.85;
  cursor: default;
  pointer-events: none;
}
.alert-mode-btn.active {
  color: #f0c14a;
  background: rgba(230, 126, 34, 0.22);
  border-color: rgba(230, 126, 34, 0.55);
}
.chat-top-main {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.chat-top-text {
  min-width: 0;
}
.chat-top-hit {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 2px 6px 2px 2px;
  margin: -2px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .14s ease;
}
.chat-top-hit:hover { background: var(--bg-hover); }
.chat-top-hit .avatar {
  width: 40px;
  height: 40px;
  font-size: .85rem;
  flex-shrink: 0;
}
.chat-top-text h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-top h2 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.chat-top .sub { color: var(--muted); font-size: .78rem; }
.chat-top .sub.is-typing {
  color: var(--accent-2);
  font-weight: 600;
}
.typing-pulse {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  animation: typing-pulse 1.35s ease-in-out infinite;
}
.typing-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 4px;
  align-items: center;
}
.typing-dots i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: typing-dot 1.2s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
@keyframes typing-dot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-1px); }
}

.pin-bar {
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  background: rgba(23, 33, 43, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.pin-bar-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 8px 14px;
  min-width: 0;
}
.pin-bar-main:hover { background: var(--bg-hover); }
.pin-bar-unpin {
  flex-shrink: 0;
  border: none;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--accent-2);
  font-weight: 700;
  font-size: .78rem;
  padding: 0 14px;
  white-space: nowrap;
}
.pin-bar-unpin:hover { background: rgba(229,57,53,0.12); color: #ff8a80; }
.pin-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  font-size: .78rem;
}
.pin-text strong { color: var(--accent-2); font-size: .72rem; letter-spacing: .02em; }
.pin-preview {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages {
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
  padding: 12px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overscroll-behavior: contain;
  overflow-anchor: none;
  -webkit-overflow-scrolling: touch;
}
.messages-spacer {
  flex: 1 1 auto;
  min-height: 0;
  pointer-events: none;
}

.day-sep {
  align-self: center;
  margin: 10px 0 4px;
  flex-shrink: 0;
  z-index: 1;
}
.day-sep span {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.85);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .01em;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  user-select: none;
}
.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(540px, 92%);
  width: fit-content;
  flex-shrink: 0;
}
.msg.msg-enter { animation: rise .18s ease both; }
.msg.mine { align-self: flex-end; flex-direction: row; }
.msg:not(.mine) { align-self: flex-start; }
.msg.msg-cont { margin-top: 2px; }
.msg.msg-first { margin-top: 8px; }
.msg-avatar-col {
  width: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  align-self: flex-end;
}
.avatar.msg-av {
  width: 36px;
  height: 36px;
  font-size: .7rem;
}
.avatar.msg-av[data-user-profile],
.msg-author[data-user-profile] {
  cursor: pointer;
}
.msg-author[data-user-profile]:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.avatar.msg-av[data-user-profile]:hover {
  filter: brightness(1.08);
}
.msg-av-spacer {
  width: 36px;
  height: 36px;
}
.msg.flash .msg-bubble {
  box-shadow: 0 0 0 2px var(--accent-2);
}
.msg.pinned .msg-bubble {
  box-shadow: inset 0 0 0 1px rgba(106, 179, 243, 0.35);
}
.msg-bubble {
  background: var(--bg-bubble);
  border-radius: 14px 14px 14px 4px;
  padding: 5px 10px 3px;
  position: relative;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  flex: 0 1 auto;
  box-sizing: border-box;
  overflow: visible;
}
.msg.mine .msg-bubble {
  background: var(--bg-bubble-mine);
  border-radius: 14px 14px 4px 14px;
}
.msg.alert .msg-bubble {
  background: var(--alert-bg);
  border: 2px solid var(--alert-border);
  color: var(--alert-ink);
}
.msg.alert .msg-text {
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1.35;
}
.alert-attention {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--alert-border);
  background: rgba(255, 200, 0, 0.22);
  color: var(--alert-ink);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  line-height: 1.2;
  animation: alert-attention-blink 1s ease-in-out infinite;
}
.alert-attention-icon {
  flex: 0 0 auto;
  display: block;
}
.alert-attention-text {
  display: inline-block;
}
@keyframes alert-attention-blink {
  0%, 100% { opacity: 1; filter: brightness(1); }
  50% { opacity: 0.35; filter: brightness(1.35); }
}
@media (prefers-reduced-motion: reduce) {
  .alert-attention { animation: none; }
}
.msg.probiv-report {
  max-width: min(640px, 96%);
}
.msg.probiv-report .msg-bubble {
  max-width: 100%;
  min-width: min(280px, 70vw);
}
.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
  font-size: .95rem;
  width: fit-content;
  max-width: 100%;
}
.probiv-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.pager-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  color: var(--ink);
  font-size: 1.2rem;
  display: grid;
  place-items: center;
}
.pager-btn:hover { background: var(--accent); border-color: transparent; }
.pager-info {
  font-size: .82rem;
  color: var(--muted);
  min-width: 64px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.msg-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 2px;
}
.msg-author { font-weight: 700; font-size: .78rem; color: var(--accent-2); }
.nick-mentor, .chat-title-nick.nick-mentor, .me-nick.nick-mentor, .user-nick.nick-mentor, .chat-top-nick.nick-mentor {
  color: #ff5c7a !important;
  background: linear-gradient(90deg, #ff5c7a, #ff8fab);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}
.nick-admin, .chat-title-nick.nick-admin, .me-nick.nick-admin, .user-nick.nick-admin, .chat-top-nick.nick-admin {
  color: #6ab3f3;
  font-weight: 800;
}
.role-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  line-height: 1;
  vertical-align: middle;
  -webkit-text-fill-color: initial;
  flex-shrink: 0;
}
.role-icon svg {
  display: block;
}
.role-icon-admin {
  color: #6ab3f3;
}
.role-icon-mentor {
  color: #ff5c7a;
  filter: drop-shadow(0 0 5px rgba(255, 92, 122, 0.4));
}
.chat-title-nick, .chat-top-nick, .me-nick, .user-nick, .inline-nick {
  font-weight: inherit;
}
.chat-top h2 { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.chat-top h2 .chat-top-nick { font-size: inherit; }
.title { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; }
.title .chat-title-nick { font-weight: inherit; font-size: .92rem; }
.chat-item.has-unread .title .chat-title-nick { font-weight: 800; }
.msg.search-hit-msg .msg-bubble {
  box-shadow: 0 0 0 2px rgba(255, 214, 102, 0.55);
}
.msg.search-hit-focus .msg-bubble {
  box-shadow: 0 0 0 2px rgba(255, 196, 60, 0.95);
}
mark.search-mark {
  background: rgba(255, 214, 102, 0.55);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.msg.search-hit-focus mark.search-mark {
  background: rgba(255, 196, 60, 0.85);
}

.global-search-wrap {
  padding: 0 10px 10px;
  flex-shrink: 0;
}
.global-search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--bg);
  outline: none;
}
.global-search-input:focus { border-color: rgba(82,136,193,0.55); }
.side-scroll {
  overscroll-behavior-y: contain;
}
.sheet-back-wrap {
  padding: 0 10px 10px;
}
.sheet-back-btn {
  width: 100%;
  justify-content: center;
  gap: 6px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--bg);
  font-weight: 600;
}
.sheet-back-btn:hover {
  border-color: rgba(82,136,193,0.55);
  background: var(--bg-active);
}
.side-scroll.sheet-side-scroll {
  padding: 0 10px 12px;
}
.sheet-side-form,
.sheet-side-hint,
.sheet-side-tools {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--line);
}
.sheet-side-form h2,
.sheet-gos-tools-head h2 {
  margin: 0 0 12px;
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sheet-gos-tools-side .sheet-gos-tools-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sheet-gos-tools-top {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-header);
  flex-shrink: 0;
}
.sheet-gos-tools-top .sheet-gos-tools-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}
.sheet-gos-tools-top .sheet-gos-tools-head h2 {
  margin: 0;
}
.sheet-gos-tools-hint {
  font-size: 0.8rem;
}
.sheet-gos-tools-top .sheet-gos-tools-body {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: flex-end;
}
.sheet-gos-tool-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.sheet-gos-tool-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.sheet-gos-color-row,
.sheet-gos-fontsize-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.sheet-gos-presets {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.sheet-gos-color-row input[type="color"] {
  width: 34px;
  height: 28px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}
.sheet-gos-color-row input[type="color"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.sheet-gos-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.28);
  padding: 0;
  cursor: pointer;
}
.sheet-gos-swatch:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.sheet-gos-swatch[data-sheet-bg="#f8fafc"] {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35);
}
.sheet-gos-swatch.is-default {
  background: #0e1621;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
  position: relative;
}
.sheet-gos-swatch.is-default::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 50%;
  height: 1px;
  background: rgba(248, 113, 113, 0.85);
  transform: rotate(-45deg);
}
.sheet-gos-fontsize-row input[type="number"] {
  width: 56px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 4px 6px;
  text-align: center;
}
.sheet-fontsize-btn {
  min-width: 28px;
  padding: 2px 8px !important;
}

/* Fullscreen sheet popup (/sheet.html) */
body.sheet-popup-page {
  overflow: hidden;
}
.sheet-popup-shell {
  display: grid;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  background: var(--bg);
}
.sheet-popup-shell.is-entries {
  grid-template-columns: minmax(260px, 320px) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "bar bar"
    "side main";
}
.sheet-popup-shell.is-gos {
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1fr;
  grid-template-areas:
    "bar"
    "tools"
    "main";
}
.sheet-popup-bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-sidebar);
  flex-shrink: 0;
}
.sheet-popup-brand {
  font-weight: 800;
  letter-spacing: 0.02em;
}
.sheet-popup-brand span {
  color: var(--accent-2);
}
.sheet-popup-side {
  grid-area: side;
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: var(--bg-sidebar);
  min-height: 0;
}
.sheet-popup-tools {
  grid-area: tools;
  min-height: 0;
}
.sheet-popup-main {
  grid-area: main;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet-popup-main .sheet-view {
  height: 100%;
}
.sheet-popup-main .sheet-top {
  padding: 10px 14px;
}
@media (max-width: 860px) {
  .sheet-popup-shell.is-entries {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "bar"
      "side"
      "main";
  }
  .sheet-popup-side {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 38vh;
  }
  .sheet-popup-tools .sheet-gos-tools-body {
    gap: 10px 12px;
  }
  .sheet-popup-shell.is-gos .sheet-popup-tools {
    max-height: 34vh;
    overflow: auto;
  }
}
.search-section-label {
  padding: 10px 12px 4px;
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.search-empty {
  padding: 24px 14px;
  color: var(--muted);
  text-align: center;
  font-size: .9rem;
}
.search-hit {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 12px;
  display: grid;
  gap: 2px;
}
.search-hit:hover { background: var(--bg-hover); }
.search-hit-title { font-weight: 700; font-size: .9rem; display: flex; align-items: center; flex-wrap: wrap; gap: 2px; }
.search-hit-body {
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-hit-meta { color: var(--muted); font-size: .7rem; }

.chat-search-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--line);
}
.chat-search-bar input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--bg);
  outline: none;
}

.timer-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px 20px 40px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 55% at 50% 42%, rgba(82, 136, 193, 0.18), transparent 70%),
    radial-gradient(ellipse 50% 40% at 50% 80%, rgba(14, 22, 33, 0.9), transparent 70%),
    var(--bg-chat);
}
.timer-glow {
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(106, 179, 243, 0.22), transparent 68%);
  filter: blur(8px);
  pointer-events: none;
  animation: timer-breathe 3.2s ease-in-out infinite;
  opacity: 0.55;
}
.timer-stage.is-running .timer-glow {
  opacity: 0.9;
  animation-duration: 1.8s;
}
.timer-stage.timer-urgent .timer-glow {
  background: radial-gradient(circle, rgba(229, 57, 53, 0.28), transparent 68%);
  animation-duration: 0.7s;
}
.timer-stage.is-done .timer-glow {
  background: radial-gradient(circle, rgba(79, 174, 78, 0.35), transparent 68%);
  animation: timer-done-flash 0.6s ease-out both;
}
@keyframes timer-breathe {
  0%, 100% { transform: scale(0.92); opacity: 0.45; }
  50% { transform: scale(1.08); opacity: 0.85; }
}
@keyframes timer-done-flash {
  0% { transform: scale(0.7); opacity: 0.2; }
  40% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1.05); opacity: 0.7; }
}
.timer-ring-wrap {
  position: relative;
  width: min(280px, 72vw);
  height: min(280px, 72vw);
  display: grid;
  place-items: center;
  z-index: 1;
}
.timer-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.timer-ring-bg {
  stroke: rgba(255, 255, 255, 0.08);
}
.timer-ring-fg {
  stroke: var(--accent-2);
  stroke-linecap: round;
  transition: stroke 0.25s ease;
  filter: drop-shadow(0 0 8px rgba(106, 179, 243, 0.45));
}
.timer-stage.timer-urgent .timer-ring-fg {
  stroke: #ff6b6b;
  filter: drop-shadow(0 0 10px rgba(229, 57, 53, 0.55));
  animation: timer-ring-pulse 0.55s ease-in-out infinite;
}
.timer-stage.is-done .timer-ring-fg {
  stroke: #4fae4e;
  filter: drop-shadow(0 0 12px rgba(79, 174, 78, 0.55));
  stroke-dashoffset: 0 !important;
}
@keyframes timer-ring-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.timer-core {
  position: relative;
  z-index: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.timer-countdown {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: clamp(2.4rem, 9vw, 3.6rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  min-width: 7ch;
}
.timer-ms {
  font-size: 0.52em;
  opacity: 0.55;
  font-weight: 500;
  letter-spacing: 0;
}
.timer-idle-mark { opacity: 0.35; }
.timer-countdown.timer-tick {
  animation: timer-digit-pop 0.28s ease;
}
@keyframes timer-digit-pop {
  0% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.timer-stage.is-done .timer-countdown {
  animation: timer-finish-pop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes timer-finish-pop {
  0% { transform: scale(0.85); opacity: 0.5; }
  55% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}
.timer-caption {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.timer-stage.is-done .timer-caption {
  color: #7dcc7c;
}
.timer-presets {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 420px;
  z-index: 1;
}
.timer-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 72px;
  min-height: 72px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  background: rgba(23, 33, 43, 0.85);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.timer-preset:hover {
  transform: translateY(-2px);
  border-color: var(--accent-2);
  background: rgba(82, 136, 193, 0.22);
}
.timer-preset:active { transform: scale(0.96); }
.timer-preset-num {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1;
}
.timer-preset-unit {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.timer-cancel {
  z-index: 1;
  min-width: 140px;
}
.timer-done-hint {
  z-index: 1;
  color: #7dcc7c;
  font-weight: 700;
  font-size: 0.95rem;
  animation: rise 0.35s ease both;
}
.timer-melody-row {
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.timer-melody-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.timer-melody-row:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}
.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 1px;
  line-height: 1.2;
  min-height: 0;
}
.msg-time { color: rgba(255,255,255,0.45); font-size: .68rem; line-height: 1.2; }
.msg.mine .msg-time { color: rgba(255,255,255,0.55); }

/* Избранное — заметки */
.messages.notes-feed {
  gap: 12px;
  padding: 16px 18px 14px;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(201, 162, 39, 0.07), transparent 55%),
    transparent;
}
.msg.note {
  max-width: min(560px, 96%);
  width: 100%;
  align-self: center;
  margin-top: 0;
}
.msg.note.msg-first { margin-top: 4px; }
.msg.note .msg-bubble {
  width: 100%;
  max-width: 100%;
  background:
    linear-gradient(165deg, rgba(36, 44, 56, 0.98) 0%, rgba(24, 32, 42, 0.98) 100%);
  border: 1px solid rgba(201, 162, 39, 0.22);
  border-left: 3px solid #c9a227;
  border-radius: 12px 14px 14px 12px;
  padding: 12px 14px 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  overflow: visible;
}
.msg.note .note-date {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: rgba(201, 162, 39, 0.85);
  margin-bottom: 8px;
}
.msg.note .msg-text {
  font-size: 0.98rem;
  line-height: 1.55;
  width: 100%;
  color: rgba(245, 247, 250, 0.95);
}
.msg.note .msg-files { margin-top: 10px; }
.msg.note.pinned .msg-bubble {
  box-shadow:
    inset 0 0 0 1px rgba(106, 179, 243, 0.35),
    0 8px 24px rgba(0, 0, 0, 0.18);
}

.read-status {
  font-size: .78rem;
  font-weight: 600;
  color: rgba(255,255,255,0.42);
  cursor: pointer;
  letter-spacing: -0.02em;
}
.read-status.read { color: #5eb3f5; }
html[data-theme="light"] .read-status { color: rgba(0,0,0,0.35); }
html[data-theme="light"] .read-status.read { color: #2aabee; }
.msg-reply, .msg-forward {
  font-size: .78rem;
  color: var(--muted);
  border-left: 3px solid var(--accent-2);
  padding: 3px 8px;
  margin-bottom: 5px;
  background: rgba(0,0,0,0.15);
  border-radius: 0 8px 8px 0;
}
.msg-files { display: grid; gap: 6px; margin-top: 6px; }
.msg-files img.thumb {
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  display: block;
  cursor: zoom-in;
  object-fit: cover;
}
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.2);
  text-decoration: none;
  color: inherit;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
}
.msg-actions.tg-msg-menu {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  z-index: 8;
  margin: 0;
  padding: 0;
  border-radius: 14px;
  background: var(--menu-bg);
  border: 1px solid var(--menu-border);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.92) translateY(4px);
  transform-origin: bottom left;
  transition: opacity .14s ease, visibility .14s ease, transform .14s ease;
  width: max-content;
  min-width: 196px;
  max-width: min(280px, 88vw);
  overflow: hidden;
}
.msg.mine .msg-actions.tg-msg-menu {
  left: auto;
  right: 0;
  transform-origin: bottom right;
}
.msg.is-actions-open .msg-actions.tg-msg-menu,
.msg-actions.tg-msg-menu.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1) translateY(0);
  animation: tg-menu-in .16s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.msg-actions.tg-msg-menu.is-fixed-pos {
  position: fixed;
  bottom: auto;
  right: auto;
  z-index: 1200;
}
body > .msg-actions.tg-msg-menu {
  /* Portaled out of .messages overflow / containment */
  margin: 0;
}
.msg-actions.tg-msg-menu.opens-down {
  transform-origin: top left;
  animation-name: tg-menu-in-down;
}
.msg.mine .msg-actions.tg-msg-menu.opens-down,
.msg.note .msg-actions.tg-msg-menu.opens-down {
  transform-origin: top right;
}
.msg-actions.tg-msg-menu.opens-up {
  transform-origin: bottom left;
}
.msg.mine .msg-actions.tg-msg-menu.opens-up,
.msg.note .msg-actions.tg-msg-menu.opens-up {
  transform-origin: bottom right;
}
.msg.note .msg-actions.tg-msg-menu {
  left: auto;
  right: 0;
  transform-origin: bottom right;
}
.tg-react-strip {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 7px 6px 5px;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
  -ms-overflow-style: none;
  background: color-mix(in srgb, var(--menu-bg) 92%, transparent);
}
.tg-react-strip::-webkit-scrollbar { display: none; }
.tg-react-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1.28rem;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  transition: background .12s ease, transform .14s cubic-bezier(0.2, 0.9, 0.35, 1.4);
  -webkit-tap-highlight-color: transparent;
}
.tg-react-btn:hover {
  background: var(--bg-hover);
  transform: scale(1.18);
}
.tg-react-btn:active {
  transform: scale(0.92);
}
.tg-react-btn.is-active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}
.tg-action-list {
  display: flex;
  flex-direction: column;
  padding: 4px;
}
.tg-act {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
}
.tg-act span:first-child {
  display: inline-flex;
  color: var(--muted);
  width: 18px;
  justify-content: center;
}
.tg-act:hover { background: var(--bg-hover); }
.tg-act.danger { color: var(--danger); }
.tg-act.danger span:first-child { color: var(--danger); }
.tg-act.danger:hover { background: rgba(229, 57, 53, 0.12); }
@keyframes tg-menu-in {
  from { opacity: 0; transform: scale(0.92) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes tg-menu-in-down {
  from { opacity: 0; transform: scale(0.92) translateY(-6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.chip {
  border: none;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 3px 7px;
  font-size: .72rem;
  color: var(--muted);
}
.chip.danger { color: #ff8a8a; }
.chip.danger:hover { background: rgba(229,57,53,0.18); color: #ffb4b4; }
.chip:hover { background: rgba(255,255,255,0.12); color: var(--ink); }

/* Telegram-style reaction chips */
.reactions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 5px 0 2px;
  max-width: 100%;
  position: relative;
  z-index: 1;
  pointer-events: none; /* empty row doesn't steal bubble clicks */
}
.reaction {
  pointer-events: auto;
  border: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
  background: color-mix(in srgb, var(--bg-elevated, var(--bg-bubble)) 55%, rgba(0, 0, 0, 0.35));
  border-radius: 999px;
  min-height: 28px;
  height: 28px;
  padding: 0 8px 0 6px;
  font-size: .78rem;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  color: var(--ink);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background .14s ease,
    border-color .14s ease,
    color .14s ease,
    box-shadow .14s ease,
    transform .12s cubic-bezier(0.2, 0.9, 0.35, 1.35);
}
.reaction .reaction-emoji {
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  transform: translateY(0.5px);
}
.reaction .reaction-count {
  font-size: .76rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: 0.92;
  min-width: 0.6em;
}
.reaction:hover {
  transform: scale(1.06);
  border-color: color-mix(in srgb, var(--ink) 18%, transparent);
}
.reaction:active {
  transform: scale(0.94);
}
.reaction.me {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--ink);
  box-shadow: inset 0 0 0 0.5px color-mix(in srgb, var(--accent) 35%, transparent);
}
.reaction.me .reaction-count {
  color: color-mix(in srgb, var(--accent) 70%, var(--ink));
}
.reaction.reaction-pop {
  animation: reaction-bounce .28s cubic-bezier(0.2, 0.85, 0.3, 1.35) both;
}
.reaction.reaction-pop-soft {
  animation: reaction-nudge .2s cubic-bezier(0.2, 0.9, 0.35, 1.2) both;
}
@keyframes reaction-bounce {
  0% { opacity: 0.35; transform: scale(0.42); }
  55% { opacity: 1; transform: scale(1.16); }
  78% { transform: scale(0.96); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes reaction-nudge {
  0% { transform: scale(1); }
  45% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Who-reacted popover */
.reactors-pop {
  position: fixed;
  z-index: 80;
  min-width: 168px;
  max-width: min(240px, 86vw);
  max-height: min(260px, 50vh);
  overflow: auto;
  padding: 6px;
  border-radius: 12px;
  background: var(--menu-bg);
  border: 1px solid var(--menu-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(14px);
  animation: tg-menu-in .14s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.reactors-pop-title {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  padding: 4px 8px 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.reactors-pop-title .reaction-emoji { font-size: 1rem; }
.reactors-pop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  color: var(--ink);
  cursor: default;
}
.reactors-pop-row .av,
.reactors-pop-row .msg-av,
.reactors-pop-row .avatar {
  width: 28px;
  height: 28px;
  font-size: .7rem;
  flex: 0 0 auto;
}
.reactors-pop-name {
  font-size: .86rem;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html[data-theme="light"] .reaction {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
html[data-theme="light"] .reaction:hover {
  border-color: rgba(0, 0, 0, 0.14);
  background: #fff;
}
html[data-theme="light"] .reaction.me {
  background: color-mix(in srgb, var(--accent, #3390ec) 16%, #fff);
  border-color: color-mix(in srgb, var(--accent, #3390ec) 48%, transparent);
  box-shadow: none;
}
html[data-theme="light"] .reaction.me .reaction-count {
  color: var(--accent, #3390ec);
}
html[data-theme="light"] .reactors-pop {
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
}

/* Composer — Telegram style */
.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--bg-composer);
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: box-shadow .15s, background .15s;
}
.composer.is-drop-target {
  background: rgba(82, 136, 193, 0.18);
  box-shadow: inset 0 0 0 1px rgba(106, 179, 243, 0.45);
}
.composer-attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 2px 4px;
  max-height: 140px;
  overflow-y: auto;
}
.attach-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 180px;
  padding: 6px 28px 6px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 0.78rem;
}
.attach-chip.is-image {
  padding: 0;
  width: 72px;
  height: 72px;
  max-width: none;
  overflow: hidden;
  border-radius: 12px;
}
.attach-chip.is-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attach-chip-ico {
  display: inline-flex;
  opacity: 0.75;
  flex-shrink: 0;
}
.attach-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-chip-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.attach-chip:not(.is-image) .attach-chip-remove {
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  color: var(--muted);
  font-size: 16px;
}
.attach-chip-remove:hover {
  background: rgba(220, 60, 60, 0.9);
  color: #fff;
}
.composer-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.composer-input-wrap {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border-radius: 22px;
  display: flex;
  align-items: flex-end;
  padding: 0 4px 0 14px;
  border: 1px solid transparent;
  position: relative;
}
.composer-input-wrap:focus-within {
  border-color: rgba(82,136,193,0.45);
}
.mention-suggest {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 45;
  max-height: min(240px, 40vh);
  overflow: auto;
  display: grid;
  gap: 2px;
  padding: 6px;
  border-radius: 14px;
  background: var(--menu-bg, var(--bg-sidebar));
  border: 1px solid var(--menu-border, var(--line));
  box-shadow: 0 12px 28px rgba(0,0,0,0.35);
  animation: emoji-pop .14s ease both;
}
.mention-suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.mention-suggest-item:hover,
.mention-suggest-item.is-active {
  background: var(--bg-hover);
}
.mention-suggest-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}
.mention-suggest-text strong {
  font-size: .9rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mention-suggest-text .muted {
  font-size: .75rem;
}
.composer textarea {
  flex: 1;
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  border: none;
  border-radius: 0;
  padding: 12px 4px 12px 0;
  outline: none;
  background: transparent;
  line-height: 1.35;
  color: var(--ink);
}
.composer-side {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding-bottom: 0;
  align-self: center;
}
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.icon-btn:hover, .icon-btn.active { color: var(--accent-2); background: var(--bg-hover); }
.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  align-self: center;
  margin: 0;
  padding: 0;
  line-height: 0;
}
.send-btn .ui-ico {
  display: block;
  transform: translateX(1px);
}
.send-btn:hover { background: var(--accent-2); color: #0e1621; }
.composer { position: relative; }
.emoji-popup {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: calc(100% + 6px);
  z-index: 30;
  max-height: min(300px, 44vh);
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--emoji-popup-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.38);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  overflow: hidden;
  animation: emoji-pop .18s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.emoji-popup-head {
  padding: 6px 10px 4px;
  font-size: .7rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .02em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}
.emoji-popup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 16px);
  gap: 4px;
  padding: 6px;
  width: 100%;
  box-sizing: border-box;
  overflow-y: auto;
  overscroll-behavior: contain;
  justify-content: start;
}
.emoji-popup-grid button {
  border: none;
  background: transparent;
  font-size: 14px;
  padding: 0;
  margin: 0;
  border-radius: 3px;
  line-height: 16px;
  cursor: pointer;
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  max-width: 16px;
  max-height: 16px;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: background .12s;
}
.emoji-popup-grid button:hover {
  background: var(--bg-hover);
  transform: none;
}
@keyframes emoji-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@media (max-width: 720px) {
  .emoji-popup-grid { grid-template-columns: repeat(auto-fill, 16px); }
  .emoji-popup { left: 4px; right: 4px; max-height: min(260px, 40vh); }
}
.composer-extra {
  display: flex;
  gap: 6px;
  padding-left: 4px;
}
.reply-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: rgba(82,136,193,0.12);
  border-radius: 10px;
  font-size: .82rem;
  border-left: none;
  overflow: hidden;
  min-height: 44px;
}
.reply-bar-accent {
  width: 3px;
  flex-shrink: 0;
  background: var(--accent-2);
}
.reply-bar.is-edit .reply-bar-accent { background: #e8a838; }
.reply-bar-body {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}
.reply-bar-name {
  color: var(--accent-2);
  font-weight: 700;
  font-size: .72rem;
  letter-spacing: .02em;
}
.reply-bar.is-edit .reply-bar-name { color: #e8a838; }
.reply-bar-text {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .8rem;
}
.reply-bar .icon-btn {
  width: 36px;
  height: auto;
  flex-shrink: 0;
  border-radius: 0;
  color: var(--muted);
}
.reply-bar .icon-btn:hover { color: var(--ink); background: rgba(255,255,255,0.04); }

.unread-sep {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
  flex-shrink: 0;
}
.unread-sep::before,
.unread-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(82, 136, 193, 0.45);
}
.unread-sep span {
  flex-shrink: 0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.messages-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.messages-wrap > .messages {
  flex: 1 1 auto;
  min-height: 0;
}
.scroll-fab {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-header);
  color: var(--ink);
  display: none;
  place-items: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  cursor: pointer;
  transition: opacity .15s, transform .15s;
}
.scroll-fab.is-visible { display: grid; }
.scroll-fab:hover { background: var(--bg-hover); }
.scroll-fab.has-new { bottom: 56px; }
.new-msg-pill {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 5;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(82,136,193,0.35);
  background: rgba(23, 33, 43, 0.96);
  color: var(--accent-2);
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  white-space: nowrap;
}
.new-msg-pill.is-visible { display: inline-flex; }
.new-msg-pill:hover { background: var(--bg-hover); }

.msg-text a.msg-link {
  color: #6ab3f3;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
}
.msg-edited {
  font-size: .68rem;
  color: var(--muted);
  font-style: italic;
  margin-right: 4px;
}

.forward-modal .forward-list {
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 8px 0 12px;
}
.forward-modal .chat-item.forward-pick {
  width: 100%;
  text-align: left;
}
.forward-modal .chat-item.forward-pick.is-selected {
  background: rgba(82,136,193,0.18);
}
.fwd-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: .72rem;
  color: #fff;
  margin-left: auto;
}
.forward-modal .chat-item.is-selected .fwd-check {
  background: var(--accent-2);
  border-color: var(--accent-2);
}
.chat-item.is-muted .title { opacity: 0.85; }
.chat-mute-mark {
  display: inline-flex;
  margin-left: 4px;
  color: var(--muted);
  vertical-align: middle;
}
.icon-btn.mute-chat-btn.active { color: var(--muted); }

.empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 40px;
}
.empty h3 { margin: 0 0 8px; color: var(--ink); }

/* Panels */
.panel { padding: 16px; }
.panel h2 { margin: 0 0 4px; font-size: 1.15rem; }
.panel .lead { color: var(--muted); margin: 0 0 16px; font-size: .9rem; }
.section { margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.user-row, .audit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.user-row .actions { display: flex; gap: 5px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.blocked { opacity: .5; }

/* People tab */
.people-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 16px 18px 28px;
}
.people-side { padding: 12px 4px; }
.people-side-lead { margin-bottom: 6px !important; }
.people-side-stats { font-size: .82rem; }
.people-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.people-head > div:first-child {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 6px 8px;
}
.people-head h2 { margin: 0; }
.people-head .lead { margin-bottom: 0; }
.people-create {
  margin-top: 8px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.people-create h3 { margin: 0 0 10px; font-size: .95rem; }
.people-create-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px 12px;
  align-items: end;
}
.people-create-form .field { margin-bottom: 0; }
.people-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 10px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-chat);
  padding-bottom: 4px;
}
.people-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  background: var(--bg-sidebar);
  outline: none;
}
.people-search:focus { border-color: var(--accent); }
.people-filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  justify-content: space-between;
}
.people-role-filters,
.people-extra-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.people-sort {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-sidebar);
  color: var(--ink);
  padding: 6px 12px;
  font-size: .78rem;
  font-weight: 600;
  outline: none;
}
.people-sort:focus { border-color: var(--accent); }
.people-filter {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: .78rem;
  font-weight: 600;
}
.people-filter:hover { background: var(--bg-hover); color: var(--ink); }
.people-filter.active {
  background: rgba(82,136,193,0.22);
  border-color: rgba(82,136,193,0.45);
  color: var(--accent-2);
}
.people-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 24px;
}
.people-empty {
  padding: 28px 12px;
  text-align: center;
}
.people-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  transition: background .12s ease, border-color .12s ease;
}
.people-row:hover {
  background: var(--bg-hover);
  border-color: var(--line);
}
.people-row.is-blocked { opacity: .62; }
.people-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  background: transparent;
  padding: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
}
.people-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #5a6672;
  border: 2px solid var(--bg-chat);
}
.presence-dot.on { background: var(--ok); }
.people-meta { min-width: 0; }
.people-name-line {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: .95rem;
}
.people-you, .people-blocked-tag {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.people-blocked-tag {
  background: rgba(229,57,53,0.18);
  color: #ff8a80;
}
.people-sub {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 3px;
  font-size: .78rem;
  color: var(--muted);
}
.people-login { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: .74rem; }
.people-presence.on { color: var(--ok); }
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .02em;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.role-badge-admin { background: rgba(106,179,243,0.18); color: #6ab3f3; }
.role-badge-mentor { background: rgba(255,92,122,0.16); color: #ff8fab; }
.role-badge-gos { background: rgba(79,174,78,0.16); color: #7dcf7c; }
.role-badge-user { background: rgba(255,255,255,0.05); color: #9aa6b2; }
.people-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.people-role-select {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  padding: 6px 8px;
  font-size: .78rem;
  max-width: 120px;
}
@media (max-width: 720px) {
  .people-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .people-actions { justify-content: flex-start; }
  .people-role-select { max-width: none; flex: 1; }
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
  animation: fade .15s ease both;
}
.modal {
  width: min(480px, 100%);
  max-height: min(85vh, 720px);
  overflow: auto;
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: rise .2s ease both;
}
.modal.wide { width: min(560px, 100%); }
.modal h3 { margin: 0 0 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.modal.user-card-modal {
  width: min(340px, 100%);
  padding: 22px 20px 16px;
}
.user-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 4px 0 8px;
}
.avatar.profile-lg {
  width: 96px;
  height: 96px;
  font-size: 2rem;
  margin-bottom: 10px;
}
.avatar.avatar-previewable {
  cursor: zoom-in;
}
.avatar.avatar-previewable:hover {
  outline: 2px solid rgba(106, 179, 243, 0.55);
  outline-offset: 2px;
}
.user-card-name {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
}
.user-card-login {
  color: var(--muted);
  font-size: .9rem;
}
.user-card-role {
  margin-top: 6px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent-2);
  font-weight: 600;
}
.user-card-note {
  margin-top: 8px;
  font-size: .8rem;
}
.user-card-actions {
  justify-content: center;
  margin-top: 16px;
}
.user-card-actions .btn {
  min-width: 110px;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 12px;
}
.lightbox img, .lightbox video {
  max-width: min(96vw, 1100px);
  max-height: 80vh;
  border-radius: 8px;
  object-fit: contain;
}
.lightbox audio { width: min(480px, 90vw); }
.lightbox .lb-name { color: var(--muted); font-size: .9rem; }
.lightbox .lb-close {
  position: absolute;
  top: 16px;
  right: 16px;
}
.lightbox .lb-avatar {
  width: min(72vw, 320px);
  height: min(72vw, 320px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(2.5rem, 12vw, 5rem);
  font-weight: 800;
  color: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.readers-modal { width: min(400px, 100%); }
.readers-section { margin-bottom: 14px; }
.readers-section-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 8px;
}
.readers-list { display: grid; gap: 8px; max-height: 28vh; overflow: auto; }
.readers-list .row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-2);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: rise .2s ease both;
}
.toast strong { display: block; margin-bottom: 4px; }
.toast div { color: var(--muted); font-size: .85rem; }
.toast div:empty { display: none; }
.profile-success {
  color: #15803d;
  font-weight: 600;
  font-size: .9rem;
  margin: 0 0 12px;
}

.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.profile-hint {
  font-size: .75rem;
  margin-top: 4px;
}
.profile-security {
  margin: 6px 0 4px;
  padding: 14px 0 2px;
  border-top: 1px solid var(--line);
}
.profile-security-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 10px;
}
.profile-premium {
  margin: 4px 0 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}
.profile-premium.is-active {
  border-color: rgba(212, 175, 55, 0.45);
  background: rgba(212, 175, 55, 0.1);
}
.profile-premium-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.profile-premium-badge {
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #c9a227;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.profile-premium.is-active .profile-premium-badge {
  color: #e8c547;
}
.profile-premium-status {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
}
.profile-premium.is-active .profile-premium-status {
  color: #d4b84a;
}
.profile-premium-desc {
  font-size: .82rem;
  line-height: 1.35;
  color: var(--muted);
}
.password-modal-lead {
  margin: 0 0 14px;
  font-size: .9rem;
  line-height: 1.4;
}
.password-feedback {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: .88rem;
  font-weight: 600;
  margin: 0 0 14px;
  line-height: 1.35;
}
.password-feedback.error {
  background: rgba(239, 68, 68, 0.14);
  color: #ff8a80;
  border: 1px solid rgba(239, 68, 68, 0.28);
}
.password-feedback.success {
  background: rgba(34, 197, 94, 0.14);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.28);
}
.totp-block {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
html[data-theme="light"] .totp-block {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}
.totp-qr-wrap {
  display: flex;
  justify-content: center;
  margin: 10px 0 12px;
}
.totp-qr {
  width: 180px;
  height: 180px;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
}
.totp-secret {
  user-select: all;
  word-break: break-all;
  font-size: 0.85em;
}
.totp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pw-input {
  position: relative;
  display: flex;
  align-items: center;
}
.pw-input input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 44px 12px 14px;
  background: var(--bg);
  outline: none;
  color: var(--ink);
}
.pw-input input:focus {
  border-color: var(--accent);
}
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.pw-toggle:hover {
  background: var(--bg-hover);
  color: var(--ink);
}
.password-actions {
  margin-top: 18px;
  align-items: stretch;
}
.password-actions .btn.block-sm {
  flex: 1;
}
.password-modal .field {
  margin-bottom: 14px;
}
.password-modal .field label {
  margin-bottom: 2px;
}

.bg-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-row { display: flex; flex-wrap: wrap; gap: 8px; }
.color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-dot.selected { border-color: #fff; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(240px, 42vw) 1fr; }
  .sidebar { display: flex; min-width: 0; }
}
.mobile-only { display: none !important; }

/* Telegram-like single-column phones */
@media (max-width: 720px) {
  .mobile-only { display: grid !important; }
  html, body, #app, .shell {
    height: 100svh;
    height: 100dvh;
    max-height: 100svh;
    max-height: 100dvh;
  }
  .shell.mobile-chat-open {
    height: 100dvh;
    max-height: 100dvh;
  }
  .layout {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100vw;
    height: 100%;
    min-height: 0;
  }
  .layout:not(.show-chat) .main {
    display: none;
  }
  .layout.show-chat:not(.show-sheet) {
    position: relative;
    display: block;
  }
  /* Keep chat list under the open chat always — no display:none↔flex reflow mid-swipe */
  .layout.show-chat:not(.show-sheet) .sidebar {
    display: flex !important;
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    max-width: none;
    visibility: hidden;
    pointer-events: none;
    transform: none !important;
  }
  .layout.show-chat:not(.show-sheet).is-edge-ready .sidebar,
  .layout.show-chat:not(.show-sheet).is-edge-swiping .sidebar {
    visibility: visible;
  }
  .layout.show-chat:not(.show-sheet) .main {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    min-height: 0;
    background-color: var(--bg-chat);
  }

  /* Telegram-like edge-swipe: only .main moves; no transform transition while dragging */
  .layout.is-edge-swiping {
    --swipe-p: 0;
  }
  .layout.is-edge-swiping.show-chat:not(.show-sheet) .sidebar::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.45);
    opacity: calc(1 - var(--swipe-p, 0));
  }
  .layout.is-edge-swiping .main,
  .layout.is-edge-ready .main {
    transition: none !important;
    animation: none !important;
    touch-action: none;
    border-radius: 12px 0 0 12px;
    box-shadow: -10px 0 32px rgba(0, 0, 0, 0.45);
    will-change: transform;
  }
  .layout.is-edge-swiping .messages,
  .layout.is-edge-swiping .side-scroll {
    overflow: hidden !important;
    touch-action: none;
  }
  .layout.is-edge-swiping.show-sheet .main {
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.35);
  }

  .layout.show-chat.show-sheet {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(160px, 38vh) minmax(0, 1fr);
    display: grid;
  }
  .layout.show-chat.show-sheet .sidebar {
    display: flex !important;
    position: relative;
    inset: auto;
    z-index: auto;
    visibility: visible;
    pointer-events: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 38vh;
    min-height: 0;
    overflow: hidden;
    width: auto;
  }
  .layout.show-chat.show-sheet .side-head,
  .layout.show-chat.show-sheet .me,
  .layout.show-chat.show-sheet .tabs,
  .layout.show-chat.show-sheet .side-actions {
    display: none;
  }
  .layout.show-chat.show-sheet .sheet-back-wrap {
    padding-top: 8px;
  }
  .layout.show-chat.show-sheet .main {
    position: relative;
    z-index: auto;
    height: auto;
    min-height: 0;
  }

  .chat-item,
  .people-main,
  .tab,
  .icon-btn,
  .send-btn {
    min-height: 44px;
  }
  .chat-item {
    padding: 13px 12px;
    gap: 12px;
    border-radius: 0;
    grid-template-columns: 48px 1fr auto;
  }
  .chat-item .avatar {
    width: 48px;
    height: 48px;
    font-size: .9rem;
  }
  .chat-item .title {
    font-size: .98rem;
    font-weight: 600;
  }
  .chat-item.has-unread .title { font-weight: 750; }
  .chat-item .preview {
    font-size: .82rem;
    margin-top: 2px;
  }
  .chat-item .badge {
    min-width: 22px;
    height: 22px;
    font-size: .72rem;
  }
  .side-scroll {
    /* Bottom inset is owned by .bottom-nav — avoid a second home-indicator gap. */
    padding: 4px 0 8px;
  }
  .side-head {
    padding: 10px 14px 6px;
  }
  .side-head h1 { font-size: 1.12rem; }
  .me {
    padding: 8px 14px 12px;
    gap: 12px;
  }
  .tabs {
    padding: 0 10px 12px;
    gap: 6px;
  }
  .tab {
    min-height: 48px;
    padding: 10px 4px;
    font-size: .8rem;
    border-radius: 12px;
  }
  .sheet-chat-item { display: none !important; }
  .msg {
    max-width: min(100%, 92%);
  }
  .messages {
    padding: 10px 10px 12px;
    gap: 5px;
  }
  .msg-bubble {
    font-size: 0.97rem;
    line-height: 1.42;
    padding: 8px 12px 5px;
    border-radius: 16px 16px 16px 5px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
  }
  .msg.mine .msg-bubble {
    border-radius: 16px 16px 5px 16px;
  }
  .day-sep { margin: 12px 0 6px; }
  .day-sep span {
    padding: 5px 12px;
    font-size: .72rem;
    border-radius: 10px;
  }
  .composer {
    /* Floating Telegram-style bar — no full-width strip */
    border-top: none;
    background: transparent;
    padding: 2px 8px 2px;
    gap: 6px;
  }
  .composer-row { gap: 6px; align-items: flex-end; }
  .composer-input-wrap {
    border-radius: 18px;
    padding: 0 2px 0 10px;
    min-height: 36px;
    background: var(--bg-composer);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
  }
  .composer textarea {
    min-height: 36px;
    max-height: 120px;
    font-size: 0.95rem;
    padding: 8px 2px;
    line-height: 1.3;
  }
  .composer .icon-btn,
  .composer .send-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
  }
  .composer .send-btn {
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.28);
  }
  .reply-bar {
    min-height: 36px;
    border-radius: 14px;
    margin: 0 2px;
    background: var(--bg-composer);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  }
  .messages {
    padding-bottom: 6px;
  }
  .sidebar:has(.side-actions) .side-scroll {
    padding-bottom: 12px;
  }
  .side-actions {
    /* Nav already pads for safe-area; keep actions tight above it. */
    padding-bottom: 8px;
  }
  .chat-top {
    padding: 8px 8px 8px 4px;
    gap: 4px;
    min-height: 56px;
  }
  .chat-top-main { gap: 2px; min-width: 0; }
  .chat-top .icon-btn.mobile-only {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }
  .chat-top-actions .icon-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }
  .chat-top .btn.inline-ico { display: none; }
  .chat-top .title { font-size: 1.02rem; font-weight: 700; }
  .people-panel { padding: 12px 12px 24px; }
  .admin-panel { padding: 12px 12px 24px; }
  .admin-panel-head {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 8px;
  }
  .admin-panel-head h2 { margin: 0; }
  .modal {
    width: min(100%, 100%);
    max-height: min(92dvh, 720px);
    border-radius: 14px;
    padding: 14px;
  }
  .sheet-top { padding: 10px 12px; }
  .sheet-toolbar { width: 100%; }
  .sheet-search { min-width: 0; flex: 1; }
  .empty { padding: 32px 18px; }
  .scroll-fab {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    width: 44px;
    height: 44px;
  }
  .profile-panel-top,
  .sip-top,
  .rec-top {
    min-height: 56px;
    padding-left: 8px;
    padding-right: 12px;
  }
  .profile-panel-top .icon-btn,
  .sip-top .icon-btn,
  .rec-top .icon-btn {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }
  #toast-host {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    max-width: none;
  }
}

.test-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(230, 126, 34, 0.2);
  color: #f0b27a;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: middle;
}
.test-badge.sm { margin-left: 4px; padding: 1px 5px; font-size: .58rem; }

.admin-panel { padding: 16px 18px 28px; overflow: auto; height: 100%; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.admin-card {
  background: rgba(23, 33, 43, 0.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-card h3 {
  margin: 0;
  font-size: .95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.admin-card-wide { grid-column: 1 / -1; }
.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.admin-stats div {
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.admin-stats strong { font-size: 1.15rem; }
.admin-stats span { color: var(--muted); font-size: .72rem; }
.admin-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--muted);
}
.admin-user-quick { display: grid; gap: 6px; max-height: 260px; overflow: auto; }
.admin-user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(0,0,0,0.15);
  font-size: .85rem;
}
.admin-audit { max-height: 320px; overflow: auto; }

.sheet-side-hint .lead,
.sheet-side-form .lead { margin-top: 6px; }
.sheet-entry-form .field { margin-bottom: 10px; }
.sheet-entry-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
  font: inherit;
}
.sheet-kind-switch {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.sheet-kind-switch .chip.active {
  border-color: var(--accent-2);
  background: rgba(82,136,193,0.28);
  color: var(--ink);
}
.sheet-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--bg-chat);
}
.sheet-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-header);
  flex-wrap: wrap;
}
.sheet-top h2 { margin: 0; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.sheet-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.sheet-search {
  min-width: 180px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  color: var(--ink);
}
.sheet-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--muted);
}
.sheet-tool input[type="number"] {
  width: 56px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 4px 6px;
}
.sheet-tool input[type="color"] {
  width: 34px;
  height: 28px;
  border: none;
  background: transparent;
  padding: 0;
}
.sheet-days {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.15);
}
.sheet-day {
  border: 1px solid var(--line);
  background: rgba(23,33,43,0.9);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: .78rem;
  white-space: nowrap;
}
.sheet-day.active {
  color: var(--ink);
  border-color: var(--accent-2);
  background: rgba(82,136,193,0.25);
}
.sheet-search-hits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.sheet-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px;
}
.sheet-zoom {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.sheet-zoom-label {
  min-width: 3.2em;
  text-align: center;
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sheet-zoom-btn {
  min-width: 28px;
  padding: 2px 8px !important;
}
.sheet-zoom-inner {
  zoom: var(--sheet-zoom, 1);
  transform-origin: top left;
}
.sheet-entries-wrap {
  min-width: 100%;
  overflow: auto;
}
.sheet-entries {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .88rem;
}
.sheet-entries col.sheet-col-num { width: 36px; }
.sheet-entries col.sheet-col-user { width: 110px; }
.sheet-entries col.sheet-col-fio { width: 160px; }
.sheet-entries col.sheet-col-phone { width: 100px; }
.sheet-entries col.sheet-col-email { width: 140px; }
.sheet-entries col.sheet-col-extra { width: auto; }
.sheet-entries col.sheet-col-actions { width: 72px; }
.sheet-entries th,
.sheet-entries td {
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.sheet-entries th {
  position: sticky;
  top: 0;
  background: #17212b;
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  z-index: 1;
}
.sheet-entries td {
  background: #0e1621;
  color: var(--ink);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}
.sheet-entries td.sheet-col-user,
.sheet-entries th.sheet-col-user,
.sheet-entry-user {
  width: 110px;
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .88rem;
  color: var(--accent-2);
}
.sheet-entries td.sheet-col-phone,
.sheet-entries th.sheet-col-phone {
  width: 100px;
  max-width: 100px;
}
.sheet-entry-num {
  width: 1%;
  white-space: nowrap;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .82rem;
}
.sheet-entry-cell {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 2px 4px;
  border-radius: 6px;
}
.sheet-entry-cell:focus {
  outline: none;
  border-color: var(--accent-2);
  background: rgba(0,0,0,0.25);
}
textarea.sheet-extra-input {
  resize: vertical;
  min-height: 2.6em;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: visible;
}
.sheet-extra-cell {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.sheet-extra-cell .sheet-entry-cell,
.sheet-extra-cell .sheet-extra-text,
.sheet-extra-cell > span {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.sheet-entry-extra {
  transition: background .15s ease;
  min-width: 180px;
}
.sheet-extra-palette {
  display: inline-flex;
  gap: 4px;
  flex: 0 0 auto;
  padding-top: 2px;
}
.sheet-bg-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 0;
  cursor: pointer;
  background: #0e1621;
}
.sheet-bg-swatch.is-purple { background: #6d28d9; }
.sheet-bg-swatch.is-orange { background: #ea580c; }
.sheet-bg-swatch.is-default {
  background: linear-gradient(135deg, #0e1621 50%, #243044 50%);
}
.sheet-bg-swatch.is-active {
  outline: 2px solid #fff;
  outline-offset: 1px;
}
.sheet-entry-actions {
  white-space: nowrap;
  width: 1%;
  vertical-align: middle;
}
.sheet-entry-row.is-transferred > td:not(.sheet-entry-extra) {
  background: #efd6d6 !important;
  color: #1f2937;
}
/* Extra cell: pink by default; inline extra_bg (purple/orange) still wins. */
.sheet-entry-row.is-transferred > td.sheet-entry-extra {
  background: #efd6d6;
  color: #1f2937;
}
.sheet-entry-row.is-transferred .sheet-entry-user,
.sheet-entry-row.is-transferred .sheet-entry-num {
  color: #374151;
}
.sheet-entry-row.is-transferred .sheet-entry-cell:focus {
  background: rgba(255, 255, 255, 0.45);
  border-color: #9a6b6b;
}
.sheet-transferred {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #16a34a;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
}
.sheet-entry-row.is-blurred td > *:not(.sheet-extra-palette),
.sheet-entry-row.is-blurred td:not(.sheet-entry-extra) {
  filter: blur(5px);
  user-select: none;
  pointer-events: none;
  opacity: 0.75;
}
.sheet-entry-row.is-blurred .sheet-entry-extra {
  /* keep colored background visible; blur only text */
}
.sheet-entry-row.is-blurred .sheet-entry-extra .sheet-extra-text,
.sheet-entry-row.is-blurred .sheet-entry-extra > span {
  filter: blur(5px);
  user-select: none;
  pointer-events: none;
  opacity: 0.75;
}
.sheet-entry-row.sheet-hit-row td,
.sheet-hit-row td,
.sheet-entry-row.sheet-focus-row td {
  box-shadow: inset 0 0 0 2px rgba(230, 126, 34, 0.85);
  background: rgba(230, 126, 34, 0.16) !important;
  animation: sheet-hit-flash 1.2s ease;
}
@keyframes sheet-hit-flash {
  0% { background: rgba(241, 196, 15, 0.45) !important; }
  100% { background: rgba(230, 126, 34, 0.16) !important; }
}
.sheet-entry-empty td {
  text-align: center;
  padding: 28px 12px;
}
.sheet-grid {
  display: grid;
  grid-template-columns: 44px var(--sheet-col-template, repeat(var(--sheet-cols, 12), minmax(0, 1fr)));
  gap: 1px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  width: max-content;
  min-width: 100%;
  user-select: none;
}
.sheet-grid.is-stretch {
  width: 100%;
  max-width: 100%;
}
.sheet-colhead {
  position: relative;
  padding-right: 8px;
}
.sheet-col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
}
.sheet-col-resizer:hover,
.sheet-col-resizer:active {
  background: rgba(106, 179, 243, 0.35);
}
.sheet-cell.is-bold {
  font-weight: 700;
}
.sheet-bold-btn.active {
  background: rgba(82, 136, 193, 0.35);
  color: var(--ink);
  border-color: rgba(106, 179, 243, 0.55);
}
body.sheet-popup-page .sheet-scroll,
body.sheet-popup-page .sheet-zoom-inner {
  width: 100%;
  max-width: 100%;
}
body.sheet-popup-page .sheet-grid.is-stretch {
  width: 100%;
  min-width: 100%;
}
.admin-panel-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}
.admin-panel-head h2 { margin: 0 0 4px; }
.admin-panel-head .lead { margin: 0; }
.sheet-corner, .sheet-colhead, .sheet-rowhead {
  background: #17212b;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  min-height: 32px;
  position: sticky;
  z-index: 2;
}
.sheet-colhead { top: 0; }
.sheet-rowhead {
  left: 0;
  cursor: pointer;
}
.sheet-rowhead:hover,
.sheet-rowhead:focus {
  background: #243044;
  color: var(--ink);
  outline: none;
}
.sheet-corner { top: 0; left: 0; z-index: 3; }
.sheet-cell {
  border: 0;
  background: #0e1621;
  color: var(--ink);
  padding: 4px 6px;
  min-height: 32px;
  width: 100%;
  box-sizing: border-box;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 14px;
}
.sheet-cell.is-in-selection {
  outline: 1px solid rgba(82, 136, 193, 0.55);
  outline-offset: -1px;
  background-image: linear-gradient(rgba(82, 136, 193, 0.28), rgba(82, 136, 193, 0.28));
  z-index: 1;
  position: relative;
}
.sheet-cell:focus, .sheet-cell.is-selected {
  outline: 2px solid var(--accent-2);
  outline-offset: -2px;
  z-index: 2;
  position: relative;
}
.sheet-cell.sheet-hit,
.sheet-cell.sheet-focus-row,
.sheet-cell.sheet-focus-cell {
  box-shadow: inset 0 0 0 2px rgba(230, 126, 34, 0.85);
  animation: sheet-hit-flash 1.2s ease;
}
.tabs { flex-wrap: wrap; }
.tabs .tab {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.chat-item.sheet-chat-item .test-badge {
  margin-left: 4px;
}


/* ===== Telegram UI pack: themes, scrollbars, motion, settings ===== */

html[data-theme="light"] {
  --bg: #e8eef3;
  --bg-sidebar: #ffffff;
  --bg-chat: #91a7ba;
  --bg-header: #ffffff;
  --bg-composer: #ffffff;
  --bg-bubble: #ffffff;
  --bg-bubble-mine: #effdde;
  --bg-hover: rgba(0,0,0,0.045);
  --bg-active: #e3f0fa;
  --ink: #1a1a1a;
  --muted: #6d7882;
  --line: rgba(0,0,0,0.08);
  --accent: #3390ec;
  --accent-2: #2a7dc7;
  --ok: #3ea33e;
  --danger: #d32f2f;
  --alert-bg: #fff6e0;
  --alert-border: #e2a100;
  --alert-ink: #9a6b00;
  --shadow: 0 12px 36px rgba(0,0,0,0.14);
  --sb-track: transparent;
  --sb-thumb: rgba(0,0,0,0.22);
  --sb-thumb-hover: rgba(0,0,0,0.38);
  --menu-bg: rgba(255,255,255,0.98);
  --menu-border: rgba(0,0,0,0.08);
  --emoji-popup-bg: rgba(255, 255, 255, 0.86);
}
html[data-theme="light"] .main {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.22), transparent 50%),
    var(--bg-chat);
}
html[data-theme="light"] .msg.mine .msg-bubble {
  color: #1a1a1a;
}
html[data-theme="light"] .msg.mine .msg-time {
  color: rgba(0,0,0,0.45);
}
html[data-theme="light"] .msg-time {
  color: rgba(0,0,0,0.4);
}
html[data-theme="light"] .msg-text a.msg-link { color: #1b6fb5; }
html[data-theme="light"] .site-preloader {
  background:
    radial-gradient(700px 380px at 18% 12%, rgba(51,144,236,0.12), transparent 58%),
    var(--bg);
}
html[data-theme="light"] .chat-item.has-unread .preview {
  color: rgba(26, 26, 26, 0.72);
}
html[data-theme="light"] .pin-bar {
  background: rgba(255,255,255,0.96);
}
html[data-theme="light"] .new-msg-pill,
html[data-theme="light"] .scroll-fab {
  background: rgba(255,255,255,0.96);
  color: var(--ink);
}
html[data-theme="light"] .attach-chip {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.08);
  color: var(--ink);
}
html[data-theme="light"] .composer-input-wrap {
  background: #f1f3f5;
}
html[data-theme="light"] .send-btn:hover {
  color: #fff;
}

/* Chat design variants */
html[data-chat-design="bubbles"] .msg-bubble {
  border-radius: 18px;
  padding: 8px 12px 6px;
}
html[data-chat-design="bubbles"] .messages:not([style*="background-image"]) {
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.035) 0 1px, transparent 1.5px),
    radial-gradient(circle at 72% 44%, rgba(255,255,255,0.03) 0 1px, transparent 1.5px),
    radial-gradient(circle at 40% 78%, rgba(255,255,255,0.028) 0 1px, transparent 1.5px);
  background-size: 48px 48px, 56px 56px, 40px 40px;
}
html[data-theme="light"][data-chat-design="bubbles"] .messages:not([style*="background-image"]) {
  background-image:
    radial-gradient(circle at 12% 18%, rgba(0,0,0,0.04) 0 1px, transparent 1.5px),
    radial-gradient(circle at 72% 44%, rgba(0,0,0,0.035) 0 1px, transparent 1.5px),
    radial-gradient(circle at 40% 78%, rgba(0,0,0,0.03) 0 1px, transparent 1.5px);
}
html[data-chat-design="compact"] .msg.msg-first { margin-top: 4px; }
html[data-chat-design="compact"] .msg.msg-cont { margin-top: 1px; }
html[data-chat-design="compact"] .msg-bubble { padding: 5px 9px 4px; border-radius: 12px; }
html[data-chat-design="compact"] .chat-item { padding: 7px 10px; border-radius: 10px; gap: 8px; }
html[data-chat-design="compact"] .chat-item .preview { font-size: .74rem; }
html[data-chat-design="compact"] .composer textarea { min-height: 40px; padding-top: 10px; padding-bottom: 10px; }

/* Telegram-like scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--sb-thumb) var(--sb-track);
}
*::-webkit-scrollbar {
  width: var(--sb-size);
  height: var(--sb-size);
}
*::-webkit-scrollbar-track {
  background: var(--sb-track);
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb {
  background: var(--sb-thumb);
  border-radius: 999px;
  border: 1px solid transparent;
  background-clip: padding-box;
  min-height: 28px;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--sb-thumb-hover);
  background-clip: padding-box;
}
*::-webkit-scrollbar-corner { background: transparent; }

.side-scroll,
.messages,
.emoji-popup-grid,
.modal,
.forward-list,
.people-list,
.sheet-table-wrap,
.sheet-scroll,
.tg-react-strip {
  scrollbar-gutter: stable;
}

/* Soft-hide thumbs until hover/scroll (WebKit) */
.side-scroll::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.emoji-popup-grid::-webkit-scrollbar-thumb,
.modal::-webkit-scrollbar-thumb,
.forward-list::-webkit-scrollbar-thumb,
.sheet-table-wrap::-webkit-scrollbar-thumb,
.sheet-scroll::-webkit-scrollbar-thumb {
  background: transparent;
  background-clip: padding-box;
}
.side-scroll:hover::-webkit-scrollbar-thumb,
.messages:hover::-webkit-scrollbar-thumb,
.emoji-popup-grid:hover::-webkit-scrollbar-thumb,
.modal:hover::-webkit-scrollbar-thumb,
.forward-list:hover::-webkit-scrollbar-thumb,
.sheet-table-wrap:hover::-webkit-scrollbar-thumb,
.sheet-scroll:hover::-webkit-scrollbar-thumb,
.side-scroll:focus-within::-webkit-scrollbar-thumb,
.messages:focus-within::-webkit-scrollbar-thumb {
  background: var(--sb-thumb);
  background-clip: padding-box;
}
.side-scroll:hover::-webkit-scrollbar-thumb:hover,
.messages:hover::-webkit-scrollbar-thumb:hover,
.emoji-popup-grid:hover::-webkit-scrollbar-thumb:hover,
.modal:hover::-webkit-scrollbar-thumb:hover {
  background: var(--sb-thumb-hover);
  background-clip: padding-box;
}

/* Motion */
.chat-pane-enter {
  animation: chat-open .2s ease both;
}
@keyframes chat-open {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg.msg-enter {
  animation: msg-slide .18s ease both;
}
@keyframes msg-slide {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.scroll-fab {
  transition: opacity .18s ease, transform .18s ease, background .18s ease, bottom .18s ease;
}
.scroll-fab.is-visible {
  animation: fab-pop .2s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.new-msg-pill {
  transition: opacity .18s ease, transform .18s ease, background .18s ease;
}
.new-msg-pill.is-visible {
  animation: pill-pop .2s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes fab-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.92); }
  to { opacity: 1; transform: none; }
}
@keyframes pill-pop {
  from { opacity: 0; transform: translate(-50%, 8px) scale(0.92); }
  to { opacity: 1; transform: translateX(-50%); }
}
.chat-item {
  transition: background .14s ease, transform .1s ease, opacity .18s ease;
}
.chat-item:active {
  transform: scale(0.985);
  background: var(--bg-active);
}
.modal-backdrop {
  animation: fade .18s ease both;
}
.modal {
  animation: rise .2s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes menu-drop {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.toast {
  animation: toast-in .2s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* Empty home */
.empty-home {
  gap: 10px;
}
.empty-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin: 0 auto 4px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 600;
  font-size: 1.4rem;
  color: #fff;
  background: linear-gradient(145deg, var(--accent) 0%, #2b5278 100%);
  box-shadow: 0 10px 24px rgba(0,0,0,0.25);
  opacity: 0.9;
}
.empty-home h3 { font-weight: 700; }
.empty-home p { margin: 0; max-width: 280px; }

/* Settings modal */
.settings-modal { width: min(440px, 100%); max-height: min(86vh, 720px); overflow: auto; }

/* Profile / settings main panels (Telegram-like) */
.profile-panel,
.settings-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--bg-chat);
}
.profile-panel-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-header);
  flex-shrink: 0;
}
.profile-panel-top-text { flex: 1; min-width: 0; }
.profile-panel-top h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}
.profile-panel-body,
.settings-panel-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px 20px 48px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
  scroll-behavior: smooth;
}
.settings-panel-body {
  padding: 20px 20px 36px;
  max-width: 640px;
}

/* Own profile hero */
.profile-own-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: 20px 12px 8px;
  margin: 0 0 8px;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.profile-own-hero-avatar {
  flex-shrink: 0;
  line-height: 0;
}
.profile-own-hero-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
  width: 100%;
}
.profile-own-name {
  font-size: 1.55rem;
  font-weight: 780;
  letter-spacing: -0.02em;
  line-height: 1.25;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--ink);
}
.profile-own-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.profile-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-panel, var(--bg-header)) 80%, transparent);
  color: var(--muted);
}
.profile-badge-role {
  color: var(--accent-2, var(--accent));
  border-color: color-mix(in srgb, var(--accent-2, var(--accent)) 35%, var(--line));
  background: color-mix(in srgb, var(--accent-2, var(--accent)) 12%, transparent);
}
.profile-badge-premium {
  color: #b8952a;
  border-color: rgba(212, 175, 55, 0.35);
  background: rgba(212, 175, 55, 0.08);
}
.profile-badge-premium.is-active {
  color: #e8c547;
  border-color: rgba(232, 197, 71, 0.5);
  background: rgba(212, 175, 55, 0.16);
}
.profile-own-login {
  color: var(--muted);
  font-size: .98rem;
  font-weight: 500;
}
.profile-avatar-actions {
  margin-top: 4px;
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
}
.profile-hint { font-size: .78rem; max-width: 280px; line-height: 1.35; }

.profile-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 0;
}
.profile-panel-form {
  display: contents;
}
.profile-card {
  padding: 16px 16px 14px;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 14px;
  background: var(--bg-sidebar);
  box-shadow: none;
  scroll-margin-top: 12px;
}
.profile-card-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.profile-card-lead {
  margin: -4px 0 12px;
  font-size: .88rem;
  line-height: 1.4;
}
.profile-card-block {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
}
.profile-card-block-last {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.profile-card-block .settings-label {
  margin-bottom: 8px;
}
.profile-panel-form .field { margin-bottom: 12px; }
.profile-panel-form .field:last-of-type { margin-bottom: 0; }
.profile-security-form .field { margin-bottom: 12px; }
.profile-color-field { margin-top: 4px; }
.profile-panel-save {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}
.profile-panel-save .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.profile-card-premium .profile-premium {
  margin: 0;
}
.profile-card-notifs.settings-section {
  margin-bottom: 0;
  padding: 16px 16px 14px;
  border-radius: 16px;
}
.profile-panel-rows .profile-row-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-chat) 55%, var(--bg-panel, var(--bg-header)));
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background .14s, border-color .14s, transform .12s;
}
.profile-panel-rows .profile-row-btn:last-child { margin-bottom: 0; }
.profile-panel-rows .profile-row-btn.is-busy {
  opacity: 0.65;
  cursor: wait;
  pointer-events: none;
}
.profile-panel-rows .profile-row-btn:hover {
  background: var(--bg-hover);
  border-color: color-mix(in srgb, var(--accent, #5288c1) 35%, var(--line));
}
.profile-panel-rows .profile-row-btn:active { transform: scale(0.995); }
.profile-row-lead {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.profile-row-lead .ui-ico {
  flex-shrink: 0;
  opacity: .88;
  color: var(--accent, #5288c1);
}
.profile-row-chevron {
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 400;
  line-height: 1;
  flex-shrink: 0;
}
.profile-row-danger {
  color: var(--danger, #e05a5a);
}
.profile-row-danger .profile-row-lead .ui-ico {
  color: var(--danger, #e05a5a);
}
.profile-row-danger:hover {
  border-color: color-mix(in srgb, var(--danger, #e05a5a) 40%, var(--line)) !important;
  background: color-mix(in srgb, var(--danger, #e05a5a) 10%, var(--bg-hover)) !important;
}
.password-panel .password-modal-lead { margin-top: 0; }
.layout.show-profile .main { background: var(--bg-chat); }
html[data-theme="light"] .profile-card {
  background: color-mix(in srgb, #fff 92%, var(--bg-header));
  box-shadow: none;
}
html[data-theme="light"] .profile-own-hero {
  background: transparent;
  box-shadow: none;
}
html[data-theme="light"] .profile-panel-rows .profile-row-btn {
  background: color-mix(in srgb, #fff 88%, var(--bg-header));
}
html[data-theme="light"] .profile-badge {
  background: color-mix(in srgb, #fff 75%, var(--bg-header));
}

@media (min-width: 780px) {
  .profile-own-hero {
    flex-direction: row;
    align-items: center;
    text-align: left;
    gap: 24px;
    padding: 28px 24px;
  }
  .profile-own-hero-meta {
    align-items: flex-start;
    text-align: left;
    flex: 1;
  }
  .profile-own-name { justify-content: flex-start; }
  .profile-own-badges { justify-content: flex-start; }
  .profile-avatar-actions {
    justify-items: start;
    text-align: left;
  }
}

@media (max-width: 720px) {
  .profile-panel-body {
    padding: 10px 12px max(20px, env(safe-area-inset-bottom, 0px));
  }
  .profile-own-hero {
    padding: 18px 12px 16px;
    border-radius: 14px;
    gap: 12px;
    margin-bottom: 10px;
  }
  .profile-own-name { font-size: 1.28rem; }
  .profile-own-badges { gap: 5px; }
  .profile-card {
    padding: 12px 12px 10px;
    border-radius: 14px;
  }
  .profile-card-label {
    margin-bottom: 8px;
    font-size: .68rem;
  }
  .profile-card-lead {
    margin: -2px 0 8px;
    font-size: .84rem;
  }
  .profile-card-block {
    margin-bottom: 12px;
    padding-bottom: 10px;
  }
  .profile-panel-form .field { margin-bottom: 10px; }
  .profile-panel-save { margin-top: 10px; }
  .profile-card-notifs.settings-section {
    padding: 12px 12px 10px;
    border-radius: 14px;
  }
  .settings-row {
    padding: 11px 0;
    min-height: 44px;
  }
  .settings-seg-btn { padding: 12px 10px; min-height: 44px; }
  .settings-design { padding: 11px 12px; }
  .profile-layout { gap: 10px; }
}
.settings-section { margin-bottom: 16px; padding: 14px 14px 12px; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in srgb, var(--bg-panel, var(--bg-header)) 72%, transparent); }
html[data-theme="light"] .settings-section {
  background: color-mix(in srgb, #fff 82%, var(--bg-header));
}
.settings-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 8px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: .92rem;
  font-weight: 500;
  cursor: pointer;
}
.settings-row:last-of-type { border-bottom: none; }
.settings-row-static {
  cursor: default;
  align-items: flex-start;
}
.settings-row-static .btn { flex-shrink: 0; margin-top: 2px; }
.settings-row-meta {
  font-size: .78rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}
.settings-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.settings-row.is-disabled,
.settings-sub.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}
.settings-sub {
  padding: 8px 0 4px;
  margin-bottom: 4px;
}
.settings-hint {
  margin: 10px 0 0;
  font-size: .78rem;
  line-height: 1.4;
  color: var(--muted);
}
.settings-hint-warn {
  color: #d97706;
  background: rgba(217, 119, 6, 0.1);
  border: 1px solid rgba(217, 119, 6, 0.28);
  border-radius: 10px;
  padding: 8px 10px;
}
html[data-theme="light"] .settings-hint-warn {
  color: #b45309;
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(180, 83, 9, 0.22);
}
.settings-seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--bg-hover);
  border: 1px solid var(--line);
}
.settings-seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: background .14s, color .14s, transform .12s;
}
.settings-seg-btn:active { transform: scale(0.98); }
.settings-seg-btn.active {
  background: var(--bg-bubble);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
html[data-theme="light"] .settings-seg-btn.active {
  background: #fff;
}
.settings-designs {
  display: grid;
  gap: 8px;
}
.settings-design {
  display: grid;
  gap: 2px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg-hover);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .14s, background .14s, transform .1s;
}
.settings-design strong { font-size: .92rem; }
.settings-design span { font-size: .78rem; color: var(--muted); }
.settings-design:hover { background: var(--bg-active); }
.settings-design.active {
  border-color: var(--accent);
  background: rgba(82,136,193,0.14);
}
html[data-theme="light"] .settings-design.active {
  background: rgba(51,144,236,0.1);
}
.settings-preview {
  margin-top: 4px;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--bg-chat);
  min-height: 148px;
  position: relative;
  transition: background .2s ease;
}
.settings-preview-wall {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
}
html[data-chat-design="bubbles"] .settings-preview-wall {
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.07) 0 1px, transparent 1.5px),
    radial-gradient(circle at 72% 44%, rgba(255,255,255,0.05) 0 1px, transparent 1.5px),
    radial-gradient(circle at 40% 78%, rgba(255,255,255,0.045) 0 1px, transparent 1.5px);
  background-size: 48px 48px, 56px 56px, 40px 40px;
}
html[data-theme="light"][data-chat-design="bubbles"] .settings-preview-wall {
  background-image:
    radial-gradient(circle at 12% 18%, rgba(0,0,0,0.05) 0 1px, transparent 1.5px),
    radial-gradient(circle at 72% 44%, rgba(0,0,0,0.04) 0 1px, transparent 1.5px),
    radial-gradient(circle at 40% 78%, rgba(0,0,0,0.035) 0 1px, transparent 1.5px);
}
.settings-preview-feed {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px;
}
.settings-preview-row {
  display: flex;
  max-width: 78%;
}
.settings-preview-row.mine { align-self: flex-end; }
.settings-preview-bubble {
  background: var(--bg-bubble);
  color: var(--ink);
  border-radius: 14px;
  padding: 8px 11px 6px;
  font-size: .82rem;
  line-height: 1.35;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  transition: border-radius .18s ease, padding .18s ease, background .18s ease;
}
.settings-preview-row.mine .settings-preview-bubble {
  background: var(--bg-bubble-mine);
}
html[data-chat-design="bubbles"] .settings-preview-bubble {
  border-radius: 18px;
  padding: 9px 12px 7px;
}
html[data-chat-design="compact"] .settings-preview-feed { gap: 4px; }
html[data-chat-design="compact"] .settings-preview-bubble {
  border-radius: 12px;
  padding: 5px 9px 4px;
  font-size: .78rem;
}
.settings-preview-meta {
  display: block;
  margin-top: 3px;
  font-size: .65rem;
  color: var(--muted);
  text-align: right;
}
.settings-preview-row.mine .settings-preview-meta {
  color: rgba(245,247,250,0.55);
}
html[data-theme="light"] .settings-preview-row.mine .settings-preview-meta {
  color: rgba(0,0,0,0.4);
}

/* Chat info panel (Telegram-style) */
.chat-info-backdrop {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,0.45);
  border: none;
  padding: 0;
  cursor: pointer;
  animation: fade .18s ease both;
}
.chat-info-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  width: min(380px, 100%);
  background: var(--bg-sidebar);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(0,0,0,0.28);
  display: flex;
  flex-direction: column;
  min-height: 0;
  animation: chat-info-in .22s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes chat-info-in {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: none; }
}
.chat-info-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  min-height: 54px;
}
.chat-info-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
}
.chat-info-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 16px 16px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.chat-info-hero .avatar {
  width: 84px;
  height: 84px;
  font-size: 1.6rem;
  border-radius: 50%;
}
.chat-info-hero-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
}
.chat-info-hero-sub {
  margin: 0;
  color: var(--muted);
  font-size: .82rem;
}
.chat-info-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.chat-info-tabs.chat-info-tabs-dm {
  grid-template-columns: repeat(3, 1fr);
}
.chat-info-peer-btn {
  margin-top: 8px;
}
.chat-info-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 4px;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .14s, border-color .14s;
}
.chat-info-tab.active {
  color: var(--accent-2);
  border-bottom-color: var(--accent-2);
}
.chat-info-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  scrollbar-gutter: stable;
}
.chat-info-member {
  width: 100%;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  border: none;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .14s;
}
.chat-info-member:hover { background: var(--bg-hover); }
.chat-info-member .name { font-weight: 600; font-size: .92rem; }
.chat-info-member .meta { color: var(--muted); font-size: .74rem; }
.chat-info-media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
.chat-info-media-grid button {
  border: none;
  padding: 0;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--bg-active);
  cursor: pointer;
}
.chat-info-media-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .18s ease;
}
.chat-info-media-grid button:hover img { transform: scale(1.04); }
.chat-info-link,
.chat-info-file {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: background .14s;
}
.chat-info-link:hover,
.chat-info-file:hover { background: var(--bg-hover); }
.chat-info-link .url {
  color: var(--accent-2);
  font-size: .86rem;
  word-break: break-all;
}
.chat-info-link .from,
.chat-info-file .from {
  color: var(--muted);
  font-size: .72rem;
  margin-top: 2px;
}
.chat-info-file .ico {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(82,136,193,0.18);
  color: var(--accent-2);
  flex-shrink: 0;
}
.chat-info-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
}
.chat-info-more {
  margin: 10px auto 4px;
  display: block;
}
.chat-info-opening {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
  background: rgba(14, 22, 33, 0.2);
}
html[data-theme="light"] .chat-info-opening {
  background: rgba(255,255,255,0.18);
}

@media (max-width: 720px) {
  .chat-info-panel {
    width: 100%;
    border-left: none;
    animation: chat-info-mobile-in .22s cubic-bezier(0.2, 0.9, 0.3, 1) both;
  }
  @keyframes chat-info-mobile-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
  }
  .chat-info-tabs { grid-template-columns: repeat(4, 1fr); }
  .chat-info-tab { font-size: .72rem; padding: 10px 2px; }
}

/* Polish */
.side-head { padding: 12px 12px 6px; }
.me { padding: 6px 12px 10px; border-radius: 12px; margin: 0 4px; }
.chat-item { padding: 9px 10px; }
.chat-top { padding: 8px 14px; min-height: 54px; }
@media (min-width: 721px) {
  .composer { padding: 8px 10px 10px; }
  .composer-input-wrap { border-radius: 24px; }
}
.profile-security-label { margin-bottom: 6px; }
.profile-security .btn.block { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }

/* PWA / iOS safe areas (viewport-fit=cover + black-translucent).
   Banner consumes the top inset when present; otherwise top chrome does.
   Bottom: use max(base, inset) — never base+inset (double gap on iPhone).
   env() is 0 on desktop — no layout change beyond the small base padding. */
.banner {
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.shell.no-banner .side-head {
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}
.shell.no-banner .chat-top {
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
}
.shell.no-banner .profile-panel-top,
.shell.no-banner .sheet-top,
.shell.no-banner .sip-top,
.shell.no-banner .rec-top {
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}
.shell.no-banner .people-panel,
.shell.no-banner .admin-panel {
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
}
.login-wrap {
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
}

/* ——— iOS / standalone PWA polish ——— */
html.is-ios,
html.is-ios body {
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
html.is-ios body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  margin: 0;
  background: var(--bg);
}
html.is-ios #app {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--vv-height, 100%);
  max-height: var(--vv-height, 100%);
  overflow: hidden;
}
html.is-ios .shell {
  height: 100%;
  max-height: 100%;
  padding-bottom: 0;
  overflow: hidden;
}
html.is-ios .layout,
html.is-ios .main {
  min-height: 0;
  height: 100%;
  max-height: 100%;
}
/* Keyboard: grow bottom padding smoothly — header stays pinned. */
html.is-ios .shell.mobile-chat-open .main {
  padding-bottom: 0;
  transition: none;
  box-sizing: border-box;
}
html.is-ios.ios-keyboard-open .shell.mobile-chat-open .main {
  padding-bottom: var(--kb-inset, 0px);
  transition: padding-bottom 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
html.is-ios .shell.mobile-chat-open .chat-top,
html.is-ios .shell.mobile-chat-open .pin-bar,
html.is-ios .shell.mobile-chat-open .sip-top,
html.is-ios .shell.mobile-chat-open .rec-top,
html.is-ios .shell.mobile-chat-open .profile-panel-top {
  position: relative;
  z-index: 30;
  flex-shrink: 0;
  transform: translateZ(0);
  background: var(--bg-header);
}
html.is-ios .bottom-nav {
  padding-bottom: max(4px, env(safe-area-inset-bottom, 0px));
}
html.is-ios .shell.mobile-chat-open .composer {
  flex-shrink: 0;
  border-top: none;
  background: transparent;
  padding: 0 8px 2px;
  margin-bottom: 0;
  transition: none;
}
html.is-ios.ios-keyboard-open .shell.mobile-chat-open .composer {
  padding-bottom: 2px;
}
html.is-ios .shell.mobile-chat-open .composer-input-wrap {
  min-height: 34px;
  border-radius: 17px;
  background: color-mix(in srgb, var(--bg-composer) 92%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
}
html.is-ios .shell.mobile-chat-open .composer textarea {
  min-height: 34px;
  font-size: 16px; /* keep 16 to avoid iOS focus zoom */
  padding: 7px 2px;
}
html.is-ios .shell.mobile-chat-open .composer .icon-btn,
html.is-ios .shell.mobile-chat-open .composer .send-btn {
  width: 34px;
  height: 34px;
  min-height: 34px;
}
html[data-theme="light"] .composer-input-wrap {
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
html.is-ios.ios-keyboard-open .shell.mobile-chat-open .messages-wrap,
html.is-ios.ios-keyboard-open .shell.mobile-chat-open .messages {
  min-height: 0;
}
html.is-ios .msg {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
html.is-ios .msg .msg-text,
html.is-ios .msg .msg-actions {
  -webkit-user-select: text;
  user-select: text;
}
html.is-ios .msg.is-pressing .msg-bubble {
  transform: scale(0.97);
  transition: transform 0.12s ease;
  filter: brightness(1.06);
}
html.is-ios .msg-bubble {
  transition: transform 0.12s ease, filter 0.12s ease;
}
html.is-standalone .bnav-btn:active,
html.is-ios .bnav-btn:active,
html.is-ios .chat-item:active,
html.is-ios .sip-row:active,
html.is-ios .sip-m-card:active,
html.is-ios .icon-btn:active,
html.is-ios .send-btn:active {
  opacity: 0.72;
}
html.is-ios .messages,
html.is-ios .side-scroll,
html.is-ios .sip-list,
html.is-ios .profile-panel-body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
html.is-ios input,
html.is-ios textarea,
html.is-ios select {
  font-size: 16px; /* prevent iOS focus zoom */
}
@media (max-width: 720px) {
  html.is-ios .shell.mobile-chat-open .bottom-nav {
    display: none;
  }
  html.is-ios .profile-panel-body {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
  html.is-ios .shell.mobile-chat-open .chat-top {
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }
  html.is-ios.ios-keyboard-open .shell.mobile-chat-open .chat-top {
    /* Keep notch/status padding stable — header must not jump under the status bar. */
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }
}

/* App-like: reduce double-tap zoom on controls (desktop unaffected) */
button,
.icon-btn,
.btn,
.tab,
.chat-item,
.chip,
.reaction,
.tg-react-btn {
  touch-action: manipulation;
}

@media (prefers-reduced-motion: reduce) {
  .chat-pane-enter, .msg.msg-enter, .emoji-popup, .msg-actions.tg-msg-menu.is-open,
  .scroll-fab.is-visible, .new-msg-pill.is-visible, .typing-pulse, .typing-dots i,
  .reaction.reaction-pop, .reaction.reaction-pop-soft, .reactors-pop, .chat-info-panel, .chat-info-backdrop, .modal-backdrop, .modal,
  .settings-preview-bubble, .toast {
    animation: none !important;
  }
  .typing-pulse { opacity: 1; }
  /* Keep interactive edge-swipe able to animate on commit (Reduce Motion users still get a short fling). */
  .layout.is-edge-swiping:not(.is-edge-swipe-animating) .main,
  .layout.is-edge-swiping:not(.is-edge-swipe-animating) .sidebar {
    transition: none !important;
  }
}


/* Infinite history loader */
.history-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
}
.history-loader-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent-2);
  animation: history-spin .7s linear infinite;
}
@keyframes history-spin {
  to { transform: rotate(360deg); }
}

/* Attach sheet (Telegram +) */
.attach-wrap { position: relative; flex-shrink: 0; }
.attach-sheet {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 40;
  min-width: 220px;
  padding: 6px;
  border-radius: 14px;
  background: var(--menu-bg);
  border: 1px solid var(--menu-border);
  box-shadow: 0 12px 28px rgba(0,0,0,0.35);
  display: grid;
  gap: 2px;
  animation: emoji-pop .16s ease both;
}
.attach-sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 11px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  text-align: left;
}
.attach-sheet-item:hover { background: var(--bg-hover); }
.attach-sheet-item.is-on { color: var(--alert-ink); background: rgba(226,161,0,0.12); }
.icon-btn.alert-on { color: var(--alert-ink); }

/* Mentions */
.msg-mention {
  color: var(--accent-2);
  font-weight: 700;
  cursor: pointer;
}
.msg-mention:hover { text-decoration: underline; }
.chat-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.badge.mention-badge {
  background: var(--accent);
  color: #fff;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  display: inline-grid;
  place-items: center;
  border-radius: 11px;
}
.chat-item.has-mention .preview { color: var(--accent-2); }

/* Polls */
.msg-poll { display: grid; gap: 6px; margin: 4px 0 2px; min-width: 200px; }
.msg-poll-q { font-weight: 700; margin-bottom: 2px; }
.msg-poll-opt {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.12);
  color: inherit;
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  text-align: left;
}
.msg-poll-opt i {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: rgba(82,136,193,0.22);
  z-index: 0;
}
.msg-poll-opt-text, .msg-poll-opt-meta { position: relative; z-index: 1; }
.msg-poll-opt.me { border-color: var(--accent); }
.poll-opt-input { display: block; width: 100%; margin-top: 6px; }

/* Settings accents / walls */
.settings-accents { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-accent {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid transparent;
  background: var(--swatch, var(--accent));
  cursor: pointer;
}
.settings-accent.active { border-color: var(--ink); box-shadow: 0 0 0 2px var(--bg); }
.settings-walls { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.settings-wall {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 8px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
  background: #17212b;
  cursor: pointer;
  font-size: .75rem;
  font-weight: 700;
}
.settings-wall.active { outline: 2px solid var(--accent); }
.settings-wall-custom { display: flex; gap: 8px; align-items: center; margin-top: 8px; }

/* Global wallpaper fallback */
html[data-wallpaper] .messages:not([style*="background"]) {
  background: var(--chat-wallpaper) !important;
}

/* Profile card */
.avatar.profile-xl { width: 112px; height: 112px; font-size: 2.2rem; border-radius: 50%; }
.avatar.profile-xxl {
  width: 132px;
  height: 132px;
  font-size: 2.55rem;
  border-radius: 50%;
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--bg-chat) 70%, transparent),
    0 10px 28px rgba(0, 0, 0, 0.22);
}
.tg-profile-card { width: min(400px, 100%); padding: 0; overflow: hidden; }
.tg-profile-hero {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 28px 20px 16px;
  background: linear-gradient(180deg, rgba(82,136,193,0.18), transparent 70%);
}
.tg-profile-actions { padding: 0 16px 12px; display: grid; gap: 8px; }
.tg-profile-section { padding: 10px 16px 14px; border-top: 1px solid var(--line); }
.tg-profile-section-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); margin-bottom: 8px;
}
.tg-profile-row { padding: 6px 0; font-size: .9rem; display: flex; justify-content: space-between; gap: 8px; }
.tg-profile-media {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px;
}
.tg-profile-media button {
  border: none; padding: 0; aspect-ratio: 1; overflow: hidden; cursor: pointer; background: var(--bg-hover);
}
.tg-profile-media img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Chat info group edit */
.chat-info-title-input {
  width: min(280px, 90%);
  text-align: center;
  font-size: 1.15rem;
  font-weight: 800;
  border: 1px solid var(--line);
  background: var(--bg-hover);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
}
.chat-info-avatar-edit {
  position: relative; border: none; padding: 0; background: transparent; cursor: pointer; border-radius: 50%;
}
.chat-info-avatar-edit-badge {
  position: absolute; right: 0; bottom: 0;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border: 2px solid var(--bg-sidebar);
}

/* SIP panel */
.sip-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--bg-chat);
}
.sip-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-header);
  flex-shrink: 0;
}
.sip-top-text { flex: 1; min-width: 0; }
.sip-top h2 { margin: 0; font-size: 1.1rem; }
.sip-top .muted { margin: 2px 0 0; font-size: .8rem; }
.sip-summary {
  margin: 4px 0 0;
  font-size: .78rem;
  font-weight: 650;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  line-height: 1.35;
}
.sip-sum-sep { color: var(--muted); font-weight: 500; opacity: .7; }
.sip-sum.sip-tone-ok { color: #7dcf7c; }
.sip-sum.sip-tone-warn { color: #ffd54f; }
.sip-sum.sip-tone-bad { color: #ff8a80; }
html[data-theme="light"] .sip-sum.sip-tone-ok { color: #2e7d32; }
html[data-theme="light"] .sip-sum.sip-tone-warn { color: #f9a825; }
html[data-theme="light"] .sip-sum.sip-tone-bad { color: #c62828; }

.sip-admin {
  border-bottom: 1px solid var(--line);
  background: var(--bg-sidebar);
  flex-shrink: 0;
}
.sip-admin-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: .9rem;
}
.sip-admin-toggle:hover { background: var(--bg-hover); }
.sip-admin-body {
  display: grid;
  gap: 10px;
  padding: 0 12px 10px;
}
.sip-admin-body[hidden] {
  display: none !important;
}
.sip-admin-block h4 {
  margin: 0 0 6px;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.sip-card-create,
.sip-target-form,
.sip-target-edit-form { display: grid; gap: 6px; }
.sip-card-create .field,
.sip-target-form .field,
.sip-target-edit-form .field { margin: 0; }
.sip-card-create .field label,
.sip-target-form .field label,
.sip-target-edit-form .field label {
  font-size: .72rem;
  margin-bottom: 2px;
}
.sip-card-create input,
.sip-target-form input,
.sip-target-edit-form input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-hover);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: .85rem;
}
.sip-req { color: #ff8a80; }
.sip-field-hint {
  margin: 4px 0 0;
  font-size: .72rem;
  line-height: 1.35;
}
.sip-target-form-row {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}
.sip-target-checks { display: grid; gap: 4px; }
.sip-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-hover);
  cursor: pointer;
}
.sip-check:hover { border-color: rgba(82,136,193,0.45); }
.sip-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.sip-check-box {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 5px;
  border: 1.5px solid rgba(255,255,255,0.28);
  background: rgba(0,0,0,0.18);
  flex-shrink: 0;
  position: relative;
}
.sip-check input:checked + .sip-check-box {
  border-color: #4fae4e;
  background: rgba(79,174,78,0.25);
}
.sip-check input:checked + .sip-check-box::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid #7dcf7c;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.sip-check input:checked ~ .sip-check-text strong { color: #9be29a; }
.sip-check-text { display: grid; gap: 2px; min-width: 0; }
.sip-check-text strong { font-size: .82rem; }
.sip-check-text small { color: var(--muted); font-family: "IBM Plex Mono", monospace; font-size: .72rem; }
.sip-check-empty { margin: 0; padding: 4px 0; }

.sip-targets-grid {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}
.sip-target-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-hover);
}
.sip-target-card.is-editing {
  display: block;
  padding: 8px;
}
.sip-target-card-ico {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(15,118,110,0.22);
  color: #5eead4;
  flex-shrink: 0;
}
.sip-target-card-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.sip-target-card-body strong { font-size: .9rem; }
.sip-target-card-body code {
  font-family: "IBM Plex Mono", monospace;
  font-size: .72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}
.sip-target-card-actions { display: flex; gap: 2px; flex-shrink: 0; }
.sip-target-edit-fields {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}
.sip-target-edit-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.sip-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.sip-list > .empty {
  margin: 24px 16px;
}
.sip-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  transition: background .12s ease;
  min-height: 64px;
  min-width: 0;
}
.sip-row:hover {
  background: var(--bg-hover);
}
.sip-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.sip-row-main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "name chip"
    "meta meta";
  gap: 3px 8px;
  align-items: center;
}
.sip-row-name {
  grid-area: name;
  margin: 0;
  font-size: .95rem;
  font-weight: 650;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.sip-row-main > .sip-chip {
  grid-area: chip;
  justify-self: end;
}
.sip-row-meta {
  grid-area: meta;
  font-size: .75rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
  min-width: 0;
}
/* legacy title wrapper (if any soft-render leftovers) */
.sip-row-title {
  display: contents;
}
.sip-row-title h3 {
  margin: 0;
  font-size: .95rem;
  font-weight: 650;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.sip-row.sip-status-broken,
.sip-row.sip-tone-bad {
  background: rgba(229, 57, 53, 0.06);
  box-shadow: inset 3px 0 0 #e53935;
}
.sip-row.sip-status-done,
.sip-row.sip-tone-ok {
  background: rgba(79, 174, 78, 0.06);
  box-shadow: inset 3px 0 0 #4fae4e;
}
.sip-row.is-unclaimed {
  opacity: 0.48;
  filter: grayscale(0.45) saturate(0.55);
  color: color-mix(in srgb, var(--text) 72%, var(--muted));
}
.sip-row.is-unclaimed .sip-row-name,
.sip-row.is-unclaimed .sip-row-title h3,
.sip-row.is-unclaimed .sip-chip,
.sip-row.is-unclaimed .sip-row-meta,
.sip-row.is-unclaimed .sip-status-ico {
  opacity: 0.9;
}
.sip-row.is-unclaimed:hover {
  opacity: 0.72;
  filter: grayscale(0.2) saturate(0.8);
}
.sip-row.sip-status-in_progress,
.sip-row.sip-tone-warn {
  background: rgba(255, 193, 7, 0.08);
  box-shadow: inset 3px 0 0 #f9a825;
}
.sip-status-ico {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: rgba(255,255,255,0.06);
  position: relative;
}
.sip-tone-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.25);
}
.sip-status-ico.sip-tone-ok .sip-tone-dot { background: #4caf50; }
.sip-status-ico.sip-tone-warn .sip-tone-dot { background: #ffc107; }
.sip-status-ico.sip-tone-bad .sip-tone-dot { background: #e53935; }
.sip-status-ico.is-lg {
  width: 52px;
  height: 52px;
  border-radius: 14px;
}
.sip-status-ico.sip-status-free,
.sip-status-ico.sip-status-taken,
.sip-status-ico.sip-status-done,
.sip-status-ico.sip-tone-ok { color: #7dcf7c; background: rgba(79,174,78,0.16); }
.sip-status-ico.sip-status-broken,
.sip-status-ico.sip-tone-bad { color: #ff8a80; background: rgba(229,57,53,0.18); }
.sip-status-ico.sip-status-in_progress,
.sip-status-ico.sip-tone-warn { color: #ffd54f; background: rgba(255,193,7,0.18); }

.sip-chip {
  box-sizing: border-box;
  min-width: 0;
  max-width: 110px;
  text-align: center;
  font-size: .62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .02em;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.sip-reason { color: var(--alert-ink); }

.sip-card-actions {
  display: grid;
  gap: 6px;
  flex-shrink: 0;
}
.sip-card-actions.is-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 0;
  max-width: none;
  min-width: 0;
}
.sip-card-actions.is-row .sip-broken-btn {
  width: auto;
  min-width: 0;
  height: 30px;
  min-height: 30px;
  padding: 0 10px;
  font-size: .72rem;
  border-radius: 8px;
  box-shadow: none;
}
.sip-card-actions.is-row .sip-act-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  min-height: 0;
  max-width: 100%;
}
.sip-broken-btn,
.sip-broken-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 40px;
  min-height: 40px;
  border: 0;
  border-radius: 11px;
  box-sizing: border-box;
}
.sip-broken-slot {
  display: none;
}
.sip-broken-btn {
  background: linear-gradient(180deg, #e85a52, #c62828);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: .88rem;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(198,40,40,0.28);
}
.sip-broken-btn:hover { filter: brightness(1.06); }
.sip-broken-btn.is-detail {
  height: 48px;
  min-height: 48px;
  font-size: 1rem;
  border-radius: 12px;
}
.sip-act-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
  align-items: center;
  overflow: visible;
}
.sip-act-spacer {
  display: none;
}
.sip-act {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  border-radius: 9px;
  padding: 5px 7px;
  font: inherit;
  font-size: .72rem;
  cursor: pointer;
  flex-shrink: 0;
  max-width: 100%;
}
.sip-act span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sip-act:hover { background: var(--bg-hover); }
.sip-act.sip-act-sm { padding: 4px 6px; font-size: .7rem; }
.sip-act.sip-act-danger { color: #ff8a80; }

.sip-status-free .sip-chip,
.sip-status-taken .sip-chip,
.sip-status-done .sip-chip,
.sip-chip.sip-tone-ok { background: rgba(79,174,78,0.2); color: #7dcf7c; }
.sip-status-broken .sip-chip,
.sip-chip.sip-tone-bad { background: rgba(229,57,53,0.2); color: #ff8a80; }
.sip-status-in_progress .sip-chip,
.sip-chip.sip-tone-warn { background: rgba(255,193,7,0.22); color: #ffd54f; }

.sip-detail {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 28px;
  display: grid;
  gap: 14px;
  align-content: start;
}
.sip-detail-bar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.sip-workspace-hint {
  font-size: .78rem;
  flex: 1;
  min-width: 0;
}
.sip-status-banner {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-bubble);
}
.sip-status-banner.is-loud {
  padding: 18px 18px;
  border-width: 2px;
  border-radius: 16px;
}
.sip-status-banner-text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}
.sip-status-banner-label {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: .01em;
  line-height: 1.2;
  text-transform: uppercase;
}
.sip-status-banner.is-loud .sip-status-banner-label {
  font-size: 1.45rem;
}
.sip-status-banner-hint {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.35;
  word-break: break-word;
}
.sip-status-banner.is-loud .sip-status-banner-hint {
  font-size: .92rem;
  font-weight: 550;
}

/* Loud / clear status colors */
.sip-status-banner.sip-status-broken {
  background: linear-gradient(135deg, rgba(198,40,40,0.28), rgba(229,57,53,0.12));
  border-color: rgba(229,57,53,0.65);
  box-shadow: 0 0 0 1px rgba(229,57,53,0.25), 0 10px 28px rgba(198,40,40,0.22);
}
.sip-status-banner.sip-status-broken .sip-status-banner-label { color: #ff8a80; }
.sip-status-banner.sip-status-broken .sip-status-banner-hint { color: #ffc1bc; }
.sip-status-banner.sip-status-broken .sip-status-ico {
  color: #fff;
  background: #c62828;
  box-shadow: 0 4px 14px rgba(198,40,40,0.45);
}

.sip-status-banner.sip-status-done,
.sip-status-banner.sip-status-working,
.sip-status-banner.sip-status-free {
  background: linear-gradient(135deg, rgba(46,125,50,0.3), rgba(79,174,78,0.12));
  border-color: rgba(79,174,78,0.6);
  box-shadow: 0 0 0 1px rgba(79,174,78,0.22), 0 10px 28px rgba(46,125,50,0.2);
}
.sip-status-banner.sip-status-done .sip-status-banner-label,
.sip-status-banner.sip-status-working .sip-status-banner-label,
.sip-status-banner.sip-status-free .sip-status-banner-label { color: #9be29a; }
.sip-status-banner.sip-status-done .sip-status-banner-hint,
.sip-status-banner.sip-status-working .sip-status-banner-hint,
.sip-status-banner.sip-status-free .sip-status-banner-hint { color: #c8f0c7; }
.sip-status-banner.sip-status-done .sip-status-ico,
.sip-status-banner.sip-status-working .sip-status-ico,
.sip-status-banner.sip-status-free .sip-status-ico {
  color: #fff;
  background: #2e7d32;
  box-shadow: 0 4px 14px rgba(46,125,50,0.4);
}

.sip-status-banner.sip-status-in_progress,
.sip-status-banner.sip-status-repair {
  background: linear-gradient(135deg, rgba(249,168,37,0.28), rgba(255,193,7,0.1));
  border-color: rgba(255,193,7,0.55);
  box-shadow: 0 0 0 1px rgba(255,193,7,0.22), 0 10px 28px rgba(249,168,37,0.18);
}
.sip-status-banner.sip-status-in_progress .sip-status-banner-label,
.sip-status-banner.sip-status-repair .sip-status-banner-label { color: #ffd54f; }
.sip-status-banner.sip-status-in_progress .sip-status-banner-hint,
.sip-status-banner.sip-status-repair .sip-status-banner-hint { color: #ffe082; }
.sip-status-banner.sip-status-in_progress .sip-status-ico,
.sip-status-banner.sip-status-repair .sip-status-ico {
  color: #1a1a1a;
  background: #ffc107;
  box-shadow: 0 4px 14px rgba(255,193,7,0.4);
}

.sip-status-banner.sip-status-taken {
  background: rgba(79,174,78,0.12);
  border-color: rgba(79,174,78,0.4);
}
.sip-status-banner.sip-status-taken .sip-status-banner-label { color: #7dcf7c; }

.sip-detail-hero {
  padding: 0 2px;
}
.sip-detail-hero h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}
.sip-detail-meta {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.sip-detail-meta > div,
.sip-detail-reason {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
}
.sip-detail-meta strong,
.sip-detail-reason strong { font-size: .92rem; font-weight: 650; }
.sip-detail-reason { grid-column: 1 / -1; }
.sip-history h3 {
  margin: 0 0 10px;
  font-size: .9rem;
}
.sip-history-empty { padding: 8px 0; }
.sip-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0;
}
.sip-tl-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  position: relative;
  padding: 0 0 14px;
}
.sip-tl-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 26px;
  bottom: 0;
  width: 1px;
  background: var(--line);
}
.sip-tl-ico {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.sip-tl-broken .sip-tl-ico { color: #ff8a80; background: rgba(229,57,53,0.16); }
.sip-tl-claimed .sip-tl-ico,
.sip-tl-in_progress .sip-tl-ico { color: #8ec0ef; background: rgba(51,144,236,0.16); }
.sip-tl-done .sip-tl-ico,
.sip-tl-created .sip-tl-ico { color: #7dcf7c; background: rgba(79,174,78,0.14); }
.sip-tl-title { font-weight: 700; font-size: .88rem; }
.sip-tl-text { font-size: .82rem; color: var(--alert-ink); margin-top: 2px; }
.sip-tl-meta { font-size: .72rem; color: var(--muted); margin-top: 3px; }

.layout.show-sip .main { background: var(--bg-chat); }

/* Light theme SIP polish */
html[data-theme="light"] .sip-row.sip-status-broken,
html[data-theme="light"] .sip-row.sip-tone-bad {
  background: rgba(229, 57, 53, 0.07);
}
html[data-theme="light"] .sip-row.sip-status-done,
html[data-theme="light"] .sip-row.sip-tone-ok {
  background: rgba(62, 163, 62, 0.08);
}
html[data-theme="light"] .sip-row.is-unclaimed {
  opacity: 0.5;
  filter: grayscale(0.4) saturate(0.5);
}
html[data-theme="light"] .sip-row.sip-status-in_progress,
html[data-theme="light"] .sip-row.sip-tone-warn {
  background: rgba(255, 193, 7, 0.12);
}
html[data-theme="light"] .sip-status-ico.sip-status-free,
html[data-theme="light"] .sip-status-ico.sip-status-taken,
html[data-theme="light"] .sip-status-ico.sip-status-done,
html[data-theme="light"] .sip-status-ico.sip-tone-ok { color: #2e7d32; background: rgba(46,125,50,0.12); }
html[data-theme="light"] .sip-status-ico.sip-status-broken,
html[data-theme="light"] .sip-status-ico.sip-tone-bad { color: #c62828; background: rgba(198,40,40,0.12); }
html[data-theme="light"] .sip-status-ico.sip-status-in_progress,
html[data-theme="light"] .sip-status-ico.sip-tone-warn { color: #f57f17; background: rgba(249,168,37,0.16); }
html[data-theme="light"] .sip-status-free .sip-chip,
html[data-theme="light"] .sip-status-taken .sip-chip,
html[data-theme="light"] .sip-status-done .sip-chip,
html[data-theme="light"] .sip-chip.sip-tone-ok { background: rgba(46,125,50,0.12); color: #2e7d32; }
html[data-theme="light"] .sip-status-broken .sip-chip,
html[data-theme="light"] .sip-chip.sip-tone-bad { background: rgba(198,40,40,0.12); color: #c62828; }
html[data-theme="light"] .sip-status-in_progress .sip-chip,
html[data-theme="light"] .sip-chip.sip-tone-warn { background: rgba(249,168,37,0.18); color: #f57f17; }
html[data-theme="light"] .sip-act {
  background: rgba(0,0,0,0.03);
}
html[data-theme="light"] .sip-act.sip-act-danger { color: #c62828; }

html[data-theme="light"] .sip-status-banner.sip-status-broken {
  background: linear-gradient(135deg, #ffebee, #fff5f5);
  border-color: #e53935;
  box-shadow: 0 8px 24px rgba(198,40,40,0.16);
}
html[data-theme="light"] .sip-status-banner.sip-status-broken .sip-status-banner-label { color: #b71c1c; }
html[data-theme="light"] .sip-status-banner.sip-status-broken .sip-status-banner-hint { color: #c62828; }

html[data-theme="light"] .sip-status-banner.sip-status-done {
  background: linear-gradient(135deg, #e8f5e9, #f1f8f2);
  border-color: #43a047;
  box-shadow: 0 8px 24px rgba(46,125,50,0.14);
}
html[data-theme="light"] .sip-status-banner.sip-status-done .sip-status-banner-label { color: #1b5e20; }
html[data-theme="light"] .sip-status-banner.sip-status-done .sip-status-banner-hint { color: #2e7d32; }

html[data-theme="light"] .sip-status-banner.sip-status-in_progress {
  background: linear-gradient(135deg, #e3f2fd, #f3f9ff);
  border-color: #1e88e5;
  box-shadow: 0 8px 24px rgba(25,118,210,0.14);
}
html[data-theme="light"] .sip-status-banner.sip-status-in_progress .sip-status-banner-label { color: #0d47a1; }
html[data-theme="light"] .sip-status-banner.sip-status-in_progress .sip-status-banner-hint { color: #1565c0; }

html[data-theme="light"] .sip-status-banner.sip-status-free {
  background: #f1f8f2;
  border-color: rgba(46,125,50,0.35);
}
html[data-theme="light"] .sip-status-banner.sip-status-free .sip-status-banner-label { color: #2e7d32; }
html[data-theme="light"] .sip-status-banner.sip-status-taken {
  background: #eef5fc;
  border-color: rgba(21,101,192,0.35);
}
html[data-theme="light"] .sip-status-banner.sip-status-taken .sip-status-banner-label { color: #1565c0; }
html[data-theme="light"] .sip-status-banner .sip-status-banner-hint { color: var(--muted); }

@media (max-width: 720px) {
  .sip-target-form-row,
  .sip-target-edit-fields {
    grid-template-columns: 1fr;
  }

  .sip-top {
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
  .sip-top h2 { font-size: 1.12rem; font-weight: 700; }
  .sip-top .muted,
  .sip-summary { font-size: .72rem; }
  .sip-summary {
    margin-top: 2px;
    gap: 4px 8px;
  }
  .sip-top #sip-refresh {
    flex-shrink: 0;
  }
  .sip-admin-body { padding: 0 12px 12px; }

  /* ——— Mobile SIP cards (full redraw) ——— */
  .sip-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* bottom-nav already owns home-indicator inset */
    padding: 10px 12px 12px;
    -webkit-overflow-scrolling: touch;
  }
  .sip-m-card {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 0;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--bg-elevated, var(--bg-header));
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
  }
  .sip-m-card.sip-tone-ok { border-color: rgba(76, 175, 80, 0.28); }
  .sip-m-card.sip-tone-warn { border-color: rgba(255, 167, 38, 0.35); }
  .sip-m-card.sip-tone-bad { border-color: rgba(239, 83, 80, 0.4); }
  .sip-m-card.is-unclaimed {
    background: rgba(255, 193, 7, 0.08);
    border-color: rgba(255, 193, 7, 0.45);
  }
  .sip-m-card-top {
    display: flex;
    align-items: stretch;
    gap: 0;
    min-width: 0;
  }
  .sip-m-rail {
    width: 5px;
    flex-shrink: 0;
    background: #66bb6a;
  }
  .sip-m-card.sip-tone-warn .sip-m-rail { background: #ffb74d; }
  .sip-m-card.sip-tone-bad .sip-m-rail { background: #ef5350; }
  .sip-m-card.is-unclaimed .sip-m-rail { background: #ffc107; }
  .sip-m-card-body {
    flex: 1;
    min-width: 0;
    padding: 12px 4px 12px 12px;
  }
  .sip-m-card-line1 {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }
  .sip-m-name {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 1.02rem;
    font-weight: 650;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sip-m-badge {
    flex-shrink: 0;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 4px 8px;
    border-radius: 999px;
    line-height: 1;
    background: rgba(76, 175, 80, 0.18);
    color: #a5d6a7;
  }
  .sip-m-badge.sip-tone-warn {
    background: rgba(255, 167, 38, 0.2);
    color: #ffcc80;
  }
  .sip-m-badge.sip-tone-bad {
    background: rgba(239, 83, 80, 0.22);
    color: #ef9a9a;
  }
  .sip-m-meta {
    margin: 6px 0 0;
    font-size: .78rem;
    color: var(--muted);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .sip-m-chev {
    display: flex;
    align-items: center;
    padding: 0 10px 0 4px;
    color: var(--muted);
    opacity: 0.55;
    flex-shrink: 0;
  }
  .sip-m-card-acts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 12px 12px;
    border-top: none;
  }
  .sip-m-card-acts:not(:empty) {
    padding-top: 0;
  }
  .sip-m-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: .82rem;
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
  }
  .sip-m-btn svg { flex-shrink: 0; }
  .sip-m-btn.is-danger {
    color: #ef9a9a;
    border-color: rgba(239, 83, 80, 0.35);
  }
  .sip-m-btn:active { opacity: 0.75; }

  /* Mobile SIP detail */
  .sip-m-detail {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }
  .sip-m-detail-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    border-bottom: 1px solid var(--border);
    background: var(--bg-header);
  }
  .sip-m-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 0;
    background: transparent;
    color: var(--accent, #64b5f6);
    font-size: .95rem;
    font-weight: 600;
    padding: 6px 4px;
    -webkit-tap-highlight-color: transparent;
  }
  .sip-m-detail-lock {
    font-size: .82rem;
    padding: 6px 4px;
  }
  .sip-m-detail-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 14px max(20px, env(safe-area-inset-bottom, 0px));
  }
  .sip-m-hero {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--bg-elevated, var(--bg-header));
  }
  .sip-m-hero.sip-tone-ok { border-color: rgba(76, 175, 80, 0.35); background: rgba(76, 175, 80, 0.08); }
  .sip-m-hero.sip-tone-warn { border-color: rgba(255, 167, 38, 0.4); background: rgba(255, 167, 38, 0.1); }
  .sip-m-hero.sip-tone-bad,
  .sip-m-hero.is-loud.sip-tone-bad { border-color: rgba(239, 83, 80, 0.45); background: rgba(239, 83, 80, 0.12); }
  .sip-m-hero-ico {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.06);
  }
  .sip-m-hero-status {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.25;
  }
  .sip-m-hero-hint {
    margin-top: 4px;
    font-size: .8rem;
    color: var(--muted);
    line-height: 1.35;
  }
  .sip-m-detail-title {
    margin: 16px 0 10px;
    font-size: 1.35rem;
    font-weight: 750;
    line-height: 1.25;
    word-break: break-word;
  }
  .sip-m-kv {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-radius: 14px;
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--bg-elevated, var(--bg-header));
  }
  .sip-m-kv-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: .88rem;
  }
  .sip-m-kv-row:last-child { border-bottom: 0; }
  .sip-m-kv-row span { color: var(--muted); flex-shrink: 0; }
  .sip-m-kv-row strong {
    text-align: right;
    font-weight: 650;
    word-break: break-word;
  }
  .sip-m-kv-row.is-block {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .sip-m-kv-row.is-block strong { text-align: left; }
  .sip-m-detail-acts {
    margin-top: 14px;
  }
  .sip-m-detail-acts .sip-card-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .sip-m-detail-acts .sip-broken-btn.is-detail {
    width: 100%;
    min-height: 48px;
    border-radius: 12px;
    justify-content: center;
  }
  .sip-m-detail-acts .sip-act-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .sip-m-detail-acts .sip-act {
    min-height: 44px;
    justify-content: center;
    border-radius: 12px;
    font-size: .85rem;
  }
  .sip-m-history {
    margin-top: 18px;
  }
  .sip-m-history h3 {
    font-size: .95rem;
    margin: 0 0 10px;
  }
}

html.is-ios .sip-panel {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
html.is-ios .sip-list,
html.is-ios .sip-detail,
html.is-ios .sip-m-detail-scroll {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
html[data-theme="light"] .sip-m-badge {
  color: #2e7d32;
  background: rgba(76, 175, 80, 0.16);
}
html[data-theme="light"] .sip-m-badge.sip-tone-warn {
  color: #ef6c00;
  background: rgba(255, 167, 38, 0.18);
}
html[data-theme="light"] .sip-m-badge.sip-tone-bad {
  color: #c62828;
  background: rgba(239, 83, 80, 0.14);
}
html[data-theme="light"] .sip-m-card.is-unclaimed {
  background: rgba(255, 193, 7, 0.12);
}
html.is-ios .shell.mobile-chat-open .sip-top {
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}


/* Recordings panel */
.rec-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background:
    radial-gradient(900px 420px at 12% -10%, rgba(82,136,193,0.14), transparent 55%),
    radial-gradient(700px 360px at 100% 0%, rgba(180,83,9,0.08), transparent 50%),
    var(--bg-chat);
}
.rec-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-header) 92%, transparent);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.rec-top-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(180,83,9,0.28), rgba(245,158,11,0.12));
  color: #f0b429;
  flex-shrink: 0;
}
.rec-top-text { flex: 1; min-width: 0; }
.rec-top h2 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}
.rec-top .muted { margin: 2px 0 0; font-size: .78rem; }
.rec-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: grid;
  gap: 16px;
  align-content: start;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}
.rec-card {
  border: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
  border-radius: 18px;
  background: color-mix(in srgb, var(--bg-panel, var(--bg-header)) 88%, transparent);
  box-shadow: 0 10px 28px rgba(0,0,0,0.12);
  padding: 14px;
  display: grid;
  gap: 14px;
}
.rec-dropzone {
  border: 1.5px dashed rgba(82,136,193,0.4);
  border-radius: 16px;
  padding: 28px 18px 24px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(82,136,193,0.1), rgba(82,136,193,0.03));
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s, box-shadow .18s;
  display: grid;
  gap: 8px;
  justify-items: center;
}
.rec-dropzone:hover,
.rec-dropzone.is-drop-target {
  border-color: var(--accent, #5288c1);
  background: linear-gradient(180deg, rgba(82,136,193,0.16), rgba(82,136,193,0.06));
  box-shadow: 0 0 0 4px rgba(82,136,193,0.12);
}
.rec-dropzone.is-drop-target { transform: translateY(-1px); }
.rec-drop-ring {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: rgba(82,136,193,0.14);
  border: 1px solid rgba(82,136,193,0.28);
  margin-bottom: 2px;
}
.rec-drop-ico { color: var(--accent, #5288c1); opacity: .95; }
.rec-drop-title { font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; }
.rec-drop-sub { color: var(--muted); font-size: .8rem; max-width: 26rem; line-height: 1.35; }
.rec-pick-btn { margin-top: 6px; min-width: 9.5rem; }
.rec-queue { display: grid; gap: 10px; }
.rec-queue-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.rec-queue-title { font-weight: 700; font-size: .88rem; }
.rec-queue-count { font-size: .75rem; color: var(--muted); font-weight: 600; }
.rec-file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.rec-file-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-chat) 55%, var(--bg-panel, var(--bg-header)));
}
.rec-file-ico {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(180,83,9,0.18);
  color: #f0b429;
  flex-shrink: 0;
}
.rec-file-body { flex: 1; min-width: 0; display: grid; gap: 5px; }
.rec-file-name {
  font-weight: 650;
  font-size: .88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rec-file-meta { font-size: .75rem; color: var(--muted); }
.rec-err { color: #ff8a80; }
.rec-progress {
  height: 6px;
  border-radius: 99px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
html[data-theme="light"] .rec-progress { background: rgba(0,0,0,0.08); }
.rec-progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #b45309, #f59e0b);
  border-radius: inherit;
  transition: width .12s linear;
}
.rec-progress.is-overall { height: 8px; }
.rec-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding-top: 2px;
}
.rec-send-btn {
  min-height: 42px;
  padding-inline: 18px;
  font-weight: 700;
  border-radius: 12px;
  flex: 1 1 auto;
}
.rec-empty {
  text-align: center;
  padding: 4px 4px 0;
  font-size: .84rem;
}
.rec-banner {
  padding: 11px 13px;
  border-radius: 12px;
  font-size: .85rem;
  font-weight: 650;
}
.rec-banner-ok { background: rgba(79,174,78,0.16); color: #9be29a; }
.rec-banner-warn { background: rgba(255,193,7,0.16); color: #ffd54f; }
.rec-banner-bad { background: rgba(229,57,53,0.16); color: #ff8a80; }
html[data-theme="light"] .rec-banner-ok { color: #2e7d32; }
html[data-theme="light"] .rec-banner-warn { color: #f57f17; }
html[data-theme="light"] .rec-banner-bad { color: #c62828; }
.rec-status-error .rec-progress-bar { background: #e53935; }
.rec-status-ready .rec-progress-bar { background: #4caf50; }
.rec-history-card { gap: 10px; }
.rec-history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.rec-history-head h3 {
  margin: 0;
  font-size: .95rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}
.rec-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.rec-history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-chat) 50%, transparent);
}
.rec-history-main { min-width: 0; display: grid; gap: 3px; }
.rec-history-when {
  font-weight: 650;
  font-size: .86rem;
  font-variant-numeric: tabular-nums;
}
.rec-history-meta {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rec-history-badge {
  flex-shrink: 0;
  font-size: .72rem;
  font-weight: 750;
  padding: 5px 9px;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.rec-history-badge-ok {
  background: rgba(79,174,78,0.18);
  color: #9be29a;
}
.rec-history-badge-partial {
  background: rgba(255,193,7,0.16);
  color: #ffd54f;
}
.rec-history-badge-fail {
  background: rgba(229,57,53,0.16);
  color: #ff8a80;
}
html[data-theme="light"] .rec-history-badge-ok { color: #2e7d32; }
html[data-theme="light"] .rec-history-badge-partial { color: #f57f17; }
html[data-theme="light"] .rec-history-badge-fail { color: #c62828; }
.rec-history-empty {
  text-align: center;
  padding: 10px 4px 4px;
  font-size: .84rem;
}
.layout.show-recordings .main { background: var(--bg-chat); }

@media (max-width: 720px) {
  .rec-body { padding: 12px; gap: 12px; }
  .rec-card { padding: 12px; border-radius: 16px; }
  .rec-dropzone { padding: 22px 14px 18px; }
  .rec-send-btn { width: 100%; }
}

/* Test environment badge (test.spilka.icu) */
html.is-test body::before {
  content: "TEST";
  position: fixed;
  top: max(8px, env(safe-area-inset-top, 0px));
  right: max(8px, env(safe-area-inset-right, 0px));
  z-index: 99999;
  pointer-events: none;
  font: 700 11px/1 var(--font, system-ui, sans-serif);
  letter-spacing: 0.08em;
  color: #1a1200;
  background: #ffc107;
  padding: 6px 10px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  opacity: 0.92;
}
