/* ═══════════════════════════════════════════════════════════
   Krugolet Chat — Design System (mockup tokens)
   Light · #2f7cf6 accent · SF Pro stack
   ═══════════════════════════════════════════════════════════ */

:root {
  /* Design tokens (mockup) */
  --bg-page: #f6f7f9;
  --bg-sidebar: #fbfcfd;
  --bg-card: #ffffff;
  --bg-input: #f1f3f6;
  --bg-hover: #eef1f5;
  --bg-chip: #e9edf2;
  --bg-bubble-in: #ffffff;
  --text-main: #14181f;
  --text-dim: #5d6672;
  --text-faint: #9aa4b2;
  --border-soft: #e5e8ed;
  --accent: #2f7cf6;
  --accent-hover: #1f66d6;
  --accent-soft: rgba(47, 124, 246, 0.12);
  --accent-glow: rgba(47, 124, 246, 0.25);
  --gradient-brand: linear-gradient(135deg, #2f7cf6, #6aa6ff);
  /* Shared placeholder avatar (no photo) — list, header, members, messages */
  --avatar-initial-bg: var(--accent-soft);
  --avatar-initial-fg: var(--accent);
  --avatar-initial-weight: 600;
  --online: #31b567;
  --bubble-shadow: 0 3px 12px rgba(20, 30, 50, 0.06);
  --card-shadow: 0 6px 24px rgba(20, 30, 50, 0.06);

  /* Aliases (existing class names) */
  --bg: var(--bg-page);
  --bg-elevated: var(--bg-card);
  --bg-soft: var(--bg-input);
  --bg-muted: var(--bg-chip);
  --border: var(--border-soft);
  --border-strong: #d8dde5;
  --text: var(--text-main);
  --text-secondary: var(--text-dim);
  --text-tertiary: var(--text-faint);
  --success: var(--online);
  --success-soft: rgba(49, 181, 103, 0.12);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.08);
  --ai-badge: var(--accent-soft);
  --ai-border: rgba(47, 124, 246, 0.2);

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14.5px;
  --text-lg: 15px;
  --text-xl: 18px;
  --text-2xl: 28px;
  --text-3xl: 34px;
  --leading-tight: 1.2;
  --leading-normal: 1.45;
  --tracking-tight: -0.01em;
  --tracking-heading: -0.025em;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radii */
  --radius-sm: 12px;
  --radius: 14px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 980px;
  --radius-bubble: 18px;
  --radius-bubble-tail: 6px;

  /* Shadows */
  --shadow-xs: 0 1px 3px rgba(20, 30, 50, 0.04);
  --shadow-sm: 0 2px 10px rgba(20, 30, 50, 0.05);
  --shadow: var(--card-shadow);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.18);
  --shadow-modal: 0 28px 80px rgba(0, 0, 0, 0.3);

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 0.15s;
  --duration: 0.25s;
  --duration-slow: 0.4s;

  /* Layout */
  --sidebar-w: 320px;
  --tap-min: 44px;
  --blur-modal: 8px;
  --blur-glass: 0px;
  /* visualViewport (iOS Safari IME) — synced from login keyboard assist */
  --vv-height: 100%;
  --vv-offset-top: 0px;
}


@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(128, 140, 160, 0.25); border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }

.is-hidden, [hidden] { display: none !important; }

/* Native Capacitor shell: never offer install / APK CTAs */
html.is-native-app #android-install-sheet,
html.is-native-app #btn-install-pwa,
html.is-native-app .auth-apps {
  display: none !important;
}

/*
 * Height chain: prefer % of the (resized) WebView over locked 100dvh.
 * Android adjustResize + Keyboard.resizeOnFullScreen shrink the WebView with the IME;
 * 100dvh often stays at the large viewport and pushes the composer under the keyboard.
 */
html, body {
  height: 100%;
  max-height: 100%;
}

/*
 * OKChat height chain: html/body/% WebView → #chat-app → shell → panel.
 * Without an explicit height on #chat-app, % heights on .chat-shell collapse to
 * content size → composer sits mid-screen with a huge empty body below.
 */
body.page-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: 100%;
  min-height: 0;
}

#chat-app {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}
/*
 * Drop bottom safe-area / leftover pad while IME is open.
 * Android adjustResize (+ Keyboard.resizeOnFullScreen) already shrinks the WebView;
 * keeping env(safe-area-inset-bottom) double-counts and leaves a gap above the keyboard.
 */
html.keyboard-open,
html.keyboard-open body,
html.keyboard-open .page-auth,
html.keyboard-open .auth-shell {
  padding-bottom: 0 !important;
}

/* ── Auth ─────────────────────────────────────────────────── */

.page-auth {
  position: relative;
  min-height: 100%;
  height: 100%;
  width: 100%;
  max-width: 100%;
  background: var(--bg-page);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: none;
  touch-action: pan-y;
}

.auth-shell {
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 24px;
  padding-top: max(72px, calc(env(safe-area-inset-top, 0px) + 56px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  overscroll-behavior-x: none;
}
/*
 * IME open (phone / code): keep field + primary button inside the visible viewport.
 * Hide brand / legal / app CTAs so they don't steal height or leave a white abyss
 * (same adjustResize + keyboard-open contract as .composer).
 *
 * Mobile Safari web: NEVER flex-end — that docks the card onto the IME / autofill
 * accessory bar. Center the card in the visualViewport with bottom clearance.
 * Native Cap (adjustResize): flex-end flush above the resized WebView is fine.
 */
html.keyboard-open .page-auth {
  overflow: hidden;
}
html.keyboard-open .auth-shell {
  justify-content: center;
  align-items: center;
  min-height: 100%;
  height: 100%;
  padding-top: max(8px, env(safe-area-inset-top, 0px));
  padding-bottom: 0 !important;
  overflow: hidden;
}
html.keyboard-open .auth-topbar,
html.keyboard-open .auth-brand,
html.keyboard-open .auth-legal,
html.keyboard-open .auth-apps {
  display: none !important;
}
html.keyboard-open .auth-card {
  width: min(460px, 100%);
  margin: 0;
  animation: none;
  flex: 0 0 auto;
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
html.keyboard-open .auth-panel {
  padding: 16px;
  gap: 12px;
}
html.keyboard-open .auth-form {
  gap: 12px;
}
html.keyboard-open .auth-alert:not(.is-hidden) {
  margin-bottom: 8px;
}
html.is-native-app.keyboard-open .page-auth,
html.is-native-app.keyboard-open .auth-shell {
  padding-bottom: 0 !important;
}
html.is-native-app.keyboard-open .auth-shell {
  justify-content: flex-end;
}

/*
 * Mobile Safari: layout viewport stays full height when IME opens — pin auth shell
 * to visualViewport (Capacitor adjustResize already shrinks the WebView).
 * Bottom pad clears the iOS autofill / QuickType accessory bar above the keys.
 */
html.keyboard-open:not(.is-native-app):has(body.page-auth) {
  overflow: hidden !important;
  overscroll-behavior: none;
}
html.keyboard-open:not(.is-native-app) body.page-auth {
  position: fixed;
  top: var(--vv-offset-top, 0px);
  left: 0;
  right: 0;
  width: 100%;
  height: var(--vv-height, 100%);
  max-height: var(--vv-height, 100%);
  overflow: hidden !important;
  overscroll-behavior: none;
  touch-action: none;
}
html.keyboard-open:not(.is-native-app) .auth-shell {
  justify-content: center;
  /* More specific than the shared keyboard-open padding-bottom:0 rule */
  padding-bottom: 52px !important;
  padding-top: max(12px, env(safe-area-inset-top, 0px));
}
html.keyboard-open .page-auth {
  min-height: 0;
}
html.keyboard-open .auth-shell {
  min-height: 0;
}

.auth-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  padding-top: max(20px, env(safe-area-inset-top, 0px));
}

.auth-topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: inherit;
}

.auth-card {
  width: min(460px, 100%);
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  animation: rise var(--duration-slow) var(--ease) both;
  text-align: center;
}

.auth-brand { text-align: center; margin-bottom: 30px; }

.auth-logo {
  width: 76px;
  height: 76px;
  margin: 0 auto 26px;
  border-radius: 22px;
  background: transparent;
  box-shadow: 0 12px 32px rgba(47, 124, 246, 0.22);
  overflow: hidden;
  display: block;
  flex: none;
}

.auth-logo img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.auth-title {
  margin: 0 0 12px;
  font-size: 34px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: var(--tracking-heading);
  text-wrap: balance;
}

.auth-subtitle {
  margin: 0 0 30px;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1.55;
}

.auth-subtitle-phone {
  display: inline-block;
  margin-top: 4px;
  white-space: nowrap;
  word-break: keep-all;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
  font-weight: 600;
}

.auth-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: 26px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: left;
}

.auth-phone-row {
  display: flex;
  gap: 10px;
}

.auth-phone-prefix {
  border: 1.5px solid var(--border-soft);
  background: var(--bg-input);
  color: var(--text-main);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 15px;
  font-weight: 500;
  flex: none;
  display: grid;
  place-items: center;
}

.auth-flashcall-number {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
  text-align: center;
  margin: 4px 0 8px;
  white-space: nowrap;
  word-break: keep-all;
}

.auth-flashcall-number a {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.auth-flashcall-number a:hover { color: var(--accent); }

.auth-legal {
  margin-top: 18px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-faint);
}

.auth-legal a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.legal-card {
  width: min(720px, 100%);
  text-align: left;
}

.legal-body {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-main);
}

.legal-body > *:first-child {
  margin-top: 0;
}

.legal-body > *:last-child {
  margin-bottom: 0;
}

.legal-body h1,
.legal-body h2,
.legal-body h3 {
  margin: 1.1em 0 0.45em;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-main);
}

.legal-body h1 { font-size: 1.35em; }
.legal-body h2 { font-size: 1.2em; }
.legal-body h3 { font-size: 1.05em; }

.legal-body p,
.legal-body ul,
.legal-body ol {
  margin: 0 0 0.85em;
}

.legal-body ul,
.legal-body ol {
  padding-left: 1.25em;
}

.legal-body a {
  color: var(--accent);
}

.legal-body code {
  font-size: 0.92em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--bg-hover);
}

.legal-empty {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-faint);
}

.auth-step-code .auth-title {
  font-size: 28px;
  margin-bottom: 8px;
}

.auth-form { display: grid; gap: var(--space-3); }
.auth-step { display: block; }

.auth-step-indicator {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}

.auth-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg-muted);
  transition: background var(--duration) var(--ease), transform var(--duration) var(--ease-spring);
}

.auth-step-dot.is-active {
  background: var(--accent);
  transform: scale(1.25);
}

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 7px;
  display: block;
}

.field-req {
  color: #c62828;
  font-weight: 700;
}

.field-hint {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-tertiary, var(--text-dim));
}

.field-error {
  margin: 6px 0 0;
  font-size: 12.5px;
  line-height: 1.35;
  color: #c62828;
}

.field-input.is-invalid,
.field-textarea.is-invalid {
  border-color: #c62828;
  box-shadow: 0 0 0 4px rgba(198, 40, 40, 0.12);
}

.field-input, .field-textarea {
  width: 100%;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-input);
  border-radius: 12px;
  padding: 13px 16px;
  min-height: var(--tap-min);
  outline: none;
  font-size: 15px;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease), background var(--duration) var(--ease);
}

.field-input:focus, .field-textarea:focus {
  background: var(--bg-card);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 124, 246, 0.12);
}

.field-input-code {
  letter-spacing: 0.4em;
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 600;
}

.field-textarea { resize: vertical; min-height: 96px; }

/* Keep file pickers in the accessibility tree without display:none — mobile WebViews
 * often ignore programmatic .click() on display:none / [hidden] inputs. */
input[type="file"].is-hidden,
input[type="file"][hidden] {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
  opacity: 0 !important;
  display: block !important;
  visibility: visible !important;
  pointer-events: none !important;
}

.auth-hint {
  margin: 0 0 var(--space-2);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
}

/* In-flow under topbar — never overlays title/subtitle (fixed toast covered dial instructions). */
.auth-alert {
  position: relative;
  width: 100%;
  z-index: 1;
  margin: 0 0 16px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  animation: fade-in var(--duration) var(--ease) both;
  text-align: left;
}

.auth-alert.is-error { background: var(--danger-soft); color: #c62828; }
.auth-alert.is-ok { background: var(--success-soft); color: #1b7a3a; }

/* KrugoletUI toasts — sit below brand / safe-area, never over login header */
.kr-toast-host {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
  z-index: 12000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.kr-toast {
  pointer-events: auto;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 560;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  background: #1f2937;
  color: #fff;
}
.kr-toast.is-in { opacity: 1; transform: translateY(0); }
.kr-toast.is-out { opacity: 0; transform: translateY(-6px); }
.kr-toast--error { background: #c62828; color: #fff; }
.kr-toast--success { background: #1b7a3a; color: #fff; }
.kr-toast--info { background: #1f2937; color: #fff; }

body.page-auth .kr-toast-host {
  top: calc(env(safe-area-inset-top, 0px) + 56px);
}

/* KrugoletUI confirm / prompt / choose — aligned column, clear hierarchy */
.kr-dialog-overlay .kr-dialog-card {
  width: min(400px, calc(100vw - 32px));
  padding: 0;
  overflow: hidden;
}
.kr-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 0;
}
.kr-dialog-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.3;
}
.kr-dialog-close {
  width: 48px;
  height: 48px;
  margin: -8px -8px 0 0;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary, #5b6575);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.kr-dialog-close svg {
  width: 24px;
  height: 24px;
}
.kr-dialog-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.kr-dialog-close:focus-visible {
  outline: 2px solid #2f7cf6;
  outline-offset: 2px;
}
.kr-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px 18px 18px;
}
.kr-dialog-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-secondary, #5b6575);
}
.kr-dialog-field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  margin: 0;
}
.kr-dialog-label {
  display: block;
  margin: 0;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text, #1a1d24);
  line-height: 1.3;
}
.kr-dialog-control {
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  border: 1.5px solid var(--border-soft, #e3e7ee);
  background: var(--bg-input, #f4f6f9);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
select.kr-dialog-control {
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-dim, #8b95a5) 50%),
    linear-gradient(135deg, var(--text-dim, #8b95a5) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.kr-dialog-control:hover {
  border-color: #c8d0dc;
}
.kr-dialog-control:focus,
.kr-dialog-control:focus-visible {
  background-color: var(--bg-card, #fff);
  border-color: #2f7cf6;
  /* Single subtle ring — no double border/glow stack */
  box-shadow: 0 0 0 3px rgba(47, 124, 246, 0.16);
  outline: none;
}
.kr-dialog-remember {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 2px 0;
  font-size: 14px;
  line-height: 1.35;
  color: var(--text-secondary, #5b6575);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.kr-dialog-remember-input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  accent-color: #2f7cf6;
  cursor: pointer;
}
.kr-dialog-remember-text {
  flex: 1;
  min-width: 0;
}
.kr-dialog-actions {
  display: flex;
  justify-content: flex-end;
  align-items: stretch;
  gap: 10px;
  margin: 4px 0 0;
  width: 100%;
}
.kr-dialog-btn {
  min-height: 44px;
  min-width: 96px;
  padding: 11px 18px;
  font-weight: 600;
}
.kr-dialog-actions .btn-ghost {
  color: var(--text-secondary, #5b6575);
  background: var(--bg-hover, rgba(26, 29, 36, 0.06));
  border: 1px solid transparent;
}
.kr-dialog-actions .btn-ghost:hover {
  color: var(--text);
  background: var(--bg-muted, rgba(26, 29, 36, 0.1));
}
.kr-dialog-actions .btn-ghost:focus-visible,
.kr-dialog-actions .btn-primary:focus-visible,
.kr-dialog-actions .btn-danger-soft:focus-visible {
  outline: 2px solid #2f7cf6;
  outline-offset: 2px;
  box-shadow: none;
}
.kr-dialog-actions .btn-primary {
  background: #2f7cf6;
}
.kr-dialog-actions .btn-primary:hover:not(:disabled) {
  background: #2569d4;
}

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: none;
  border-radius: 13px;
  padding: 14px 22px;
  min-height: var(--tap-min);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease), background var(--duration) var(--ease), opacity var(--duration) var(--ease), filter var(--duration) var(--ease);
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
a.btn-primary,
a.btn-primary:link,
a.btn-primary:visited,
a.btn-primary:active,
a.btn-primary:hover {
  color: #fff;
  text-decoration: none;
}
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-soft); color: var(--text); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  padding: 0;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
  box-shadow: none;
}

.btn-send:hover:not(:disabled) { background: var(--accent-hover); }

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease), transform var(--duration-fast) var(--ease);
}

.icon-btn:hover { background: var(--bg-hover); color: var(--accent); }
.icon-btn:active { transform: scale(0.94); }

/* ── Avatar picker ──────────────────────────────────────── */

.welcome-hero {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.welcome-hero-compact { margin-bottom: var(--space-2); }

.avatar-picker {
  position: relative;
  width: 96px;
  height: 96px;
  border: none;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  transition: transform var(--duration) var(--ease-spring);
}

.avatar-picker:hover { transform: scale(1.04); }
.avatar-picker:active { transform: scale(0.97); }
.avatar-picker-md { width: 84px; height: 84px; }

.avatar-picker-preview {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.5), transparent 40%),
    linear-gradient(145deg, #e8e8ed, #c7c7cc);
  color: #fff;
  font-size: 32px;
  font-weight: 650;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.55), var(--shadow-sm);
  transition: box-shadow var(--duration) var(--ease);
}

.avatar-picker:hover .avatar-picker-preview {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.55), 0 10px 28px var(--accent-glow);
}

.avatar-picker-preview.has-image { background-color: var(--bg-muted); }

.avatar-picker-badge {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow), 0 0 0 3px var(--bg-elevated);
  transition: background var(--duration) var(--ease), transform var(--duration) var(--ease-spring);
}

.avatar-picker-badge svg {
  width: 17px;
  height: 17px;
  display: block;
}

.avatar-picker:hover .avatar-picker-badge {
  background: var(--accent-hover);
  transform: scale(1.08);
}

.avatar-picker-hint {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ── Chat shell ─────────────────────────────────────────── */

.page-chat {
  height: 100%;
  max-height: 100%;
  width: 100%;
  max-width: none;
  overflow: hidden;
  box-sizing: border-box;
  /*
   * OKChat shell: pad top only here. Bottom inset belongs on the composer once;
   * left/right stay 0 so Cap force-margins (or browser chrome) are not double-counted
   * into a narrow center column.
   */
  padding: env(safe-area-inset-top, 0px) 0 0 0;
}

.chat-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: minmax(0, 1fr);
  flex: 1 1 auto;
  height: 100%;
  max-height: 100%;
  width: 100%;
  max-width: none;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  align-content: stretch;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: none;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: transparent;
  overflow: hidden;
  flex: none;
  display: block;
}

.brand-logo img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.brand-mark {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.brand-sub {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-faint);
  margin-top: 1px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-actions { display: flex; gap: 2px; }

.group-list {
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 10px 12px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
}

.sidebar-search {
  /* Pattern A: keep rounded pill, breathing room under header (OKChat-like) */
  padding: 12px 16px 10px;
}
.sidebar-search .field-input {
  border-radius: 12px;
  border: 1.5px solid transparent;
  background: var(--bg-input);
  padding: 11px 14px;
  font-size: 13.5px;
  min-height: 0;
}
.sidebar-search .field-input:focus {
  border-color: var(--accent);
  background: var(--bg-card);
  box-shadow: 0 0 0 4px rgba(47, 124, 246, 0.1);
}
/* Dark: --bg-input is darker than sidebar — lift surface + subtle border */
html[data-theme="dark"] .sidebar-search .field-input {
  background: var(--bg-elevated);
  border-color: var(--border-soft);
}
html[data-theme="dark"] .sidebar-search .field-input:focus {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.dir-tabs {
  display: flex;
  gap: 3px;
  padding: 0 10px 8px;
  flex-shrink: 0;
}
.dir-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-muted, #6b7280);
  font: 600 11.5px/1.2 inherit;
  padding: 8px 4px;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  white-space: nowrap;
}
.dir-tab.is-active {
  background: rgba(47, 124, 246, 0.1);
  color: var(--accent, #2f7cf6);
}
.dir-skeleton {
  padding: 4px 0 12px;
}
.dir-skel-row {
  height: 56px;
  margin: 6px 12px;
  border-radius: 12px;
  background: linear-gradient(
    90deg,
    var(--bg-hover, #f3f4f6) 0%,
    var(--bg-input, #e8eaed) 45%,
    var(--bg-hover, #f3f4f6) 90%
  );
  background-size: 200% 100%;
  animation: dir-skel-shimmer 1.1s ease-in-out infinite;
}
@keyframes dir-skel-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
html[data-theme="dark"] .dir-skel-row {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.09) 45%,
    rgba(255, 255, 255, 0.04) 90%
  );
  background-size: 200% 100%;
}
.dir-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 8px;
  flex-shrink: 0;
}
.dir-nav.is-hidden { display: none; }
.dir-nav-back {
  border: 0;
  background: var(--bg-input);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--text);
}
.dir-nav-title {
  font: 600 13px/1.2 inherit;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dir-section { padding: 4px 0 10px; }
.dir-section-title {
  font: 700 11px/1.2 inherit;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #6b7280);
  padding: 8px 16px 6px;
}
.dir-empty { padding: 16px; }
.dir-hint { display: flex; flex-direction: column; gap: 10px; }
.dir-hint .modal-text { margin: 0; line-height: 1.45; }
.dir-mine-create { margin: 4px 16px 10px 22px; width: calc(100% - 38px); }
.dir-mode-row { padding: 8px 16px 16px; }
.dir-mine-book { padding-bottom: 6px; }
.group-item.dir-mine-book-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px;
  align-items: center;
  opacity: 0.96;
  border-bottom: 1px solid var(--border-soft, rgba(0,0,0,.06));
  padding: 4px 4px 4px 0;
  cursor: default;
}
.dir-mine-book.is-collapsed .dir-mine-book-head {
  border-bottom-color: transparent;
}
.dir-mine-book-hit {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 10px 8px;
  align-items: center;
  min-width: 0;
  min-height: 44px;
  border: 0;
  background: transparent;
  padding: 8px 2px 8px 12px;
  margin: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dir-mine-book-hit:active { background: var(--bg-hover); }
.dir-mine-book-head .group-item-name { font-weight: 700; }
.dir-mine-book-trail {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-width: 0;
}
.dir-mine-book-tools {
  display: flex;
  align-items: center;
  flex: none;
}
.dir-mine-book-tools .icon-btn {
  width: 44px;
  height: 44px;
}
.dir-mine-pin.is-on { color: #e8872a; }
.dir-mine-chevron {
  display: inline-flex;
  color: var(--text-tertiary);
  flex: none;
}
.dir-mine-book .group-item:not(.dir-mine-book-head) {
  padding-left: 22px;
}
.modal-subtitle {
  margin: 14px 0 6px;
  font: 700 12px/1.3 inherit;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted, #6b7280);
}
/* Must beat .group-item (2-col) — otherwise action slips under avatar/text */
.group-item.dir-book-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px 12px;
  width: 100%;
  text-align: left;
}
.group-item.dir-book-row--join {
  grid-template-columns: minmax(0, 1fr) auto;
  cursor: default;
  gap: 8px;
}
.dir-book-row .dir-book-hit {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
  width: 100%;
}
.dir-row-action {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 2px;
  min-width: 0;
}
.dir-row-action-btn {
  white-space: nowrap;
  width: auto !important;
  flex: 0 0 auto;
  padding: 5px 10px;
  line-height: 1.2;
  max-width: 100%;
}
.dir-row-chevron {
  color: var(--text-faint, #9aa3b2);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  opacity: 0.65;
  padding-right: 2px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 11px;
  flex-shrink: 0;
}

.sidebar-user-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  padding: 0;
  background: var(--gradient-brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  overflow: hidden;
  flex: none;
  background-size: cover;
  background-position: center;
  transition: transform 0.2s;
}
.sidebar-user-btn:hover { transform: scale(1.08); }

.sidebar-user-meta {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-user-meta:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Above drawers/panels; body-mounted so #chat-app overflow cannot clip it */
#modal-settings {
  z-index: 120;
}

.sidebar-user-name-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-badge {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 6px;
  text-transform: uppercase;
  flex: none;
}

.sidebar-user-status {
  font-size: 11px;
  color: var(--online);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

.sidebar-user-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 99px;
  background: var(--online);
  display: inline-block;
}

.group-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  width: 100%;
  max-width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 14px;
  padding: 11px 12px;
  min-height: 0;
  min-width: 0;
  cursor: pointer;
  transition: background 0.2s;
}

.group-item--catalog {
  grid-template-columns: minmax(0, 1fr) auto;
  cursor: default;
  gap: 4px;
}
.group-item--catalog .group-item-hit {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.group-item--catalog .group-item-dm {
  flex: 0 0 auto;
  margin-right: 2px;
}
.dir-book-expert {
  grid-template-columns: 44px minmax(0, 1fr) auto;
  cursor: default;
}
.member-name-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  max-width: 100%;
}
.member-name-btn:hover,
.member-name-btn:focus-visible {
  text-decoration: underline;
  outline: none;
}

.group-item:hover { background: var(--bg-hover); }
.group-item:active { transform: none; }
.group-item.is-active { background: rgba(47, 124, 246, 0.09); }
.group-item.is-active:hover { background: rgba(47, 124, 246, 0.13); }
.group-item.is-muted { opacity: 0.78; }

.group-item-avatar {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: var(--avatar-initial-weight, 600);
  font-size: 17px;
  line-height: 1;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
  text-transform: uppercase;
  user-select: none;
}
/* Groups only — peers use .avatar-initial (soft bg + accent letter). */
.group-item-avatar:not(.has-image):not(.avatar-initial) {
  background: var(--gradient-brand);
}

/* Shared peer/user initial (no photo) — keep list + header + members + forward in sync.
   Must clear background-image: .group-item-avatar / .chat-header-avatar set brand
   gradient via `background` shorthand; background-color alone left blue-on-blue. */
.avatar-initial:not(.has-image),
.group-item.is-dm .group-item-avatar:not(.has-image),
.forward-group-list .group-item.is-dm .group-item-avatar:not(.has-image),
.chat-header-avatar.is-peer:not(.has-image),
.member-row .avatar:not(.has-image),
.member-avatar:not(.has-image),
.msg .avatar:not(.has-image) {
  color: var(--avatar-initial-fg);
  background-color: var(--avatar-initial-bg);
  background-image: none;
  font-weight: var(--avatar-initial-weight, 600);
  border-radius: 999px;
}

.avatar-initial.has-image,
.group-item-avatar.has-image,
.chat-header-avatar.has-image,
.avatar.has-image,
.member-avatar.has-image,
.member-row .avatar.has-image,
.msg .avatar.has-image {
  color: transparent;
  font-size: 0 !important;
  background: none;
  background-color: var(--bg-muted, var(--bg-chip));
}
.avatar-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
  pointer-events: none;
}
.group-item-main { min-width: 0; overflow: hidden; display: grid; gap: 4px; }
.group-item-top, .group-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.group-item-name {
  font-weight: 600;
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}
/* ExpertBook titles: show more of name+profession; full text via title / long-press / ⋯ */
.group-item-name--book {
  white-space: normal;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  line-height: 1.25;
  max-height: calc(1.25em * 2);
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}
.group-item-top time {
  flex-shrink: 0;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
.group-item-bottom small {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.unread-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
  flex: none;
  flex-shrink: 0;
  line-height: 1;
  box-sizing: border-box;
  /* Reset UA <mark> if any leftover markup still uses it */
  -webkit-text-fill-color: #fff;
}
.unread-badge--book {
  background: #e8872a;
  color: #fff;
  min-width: 20px;
  height: 20px;
  box-shadow: 0 0 0 1px rgba(232, 135, 42, 0.35);
}
html[data-theme="dark"] .unread-badge--book {
  background: #f0a04a;
  color: #1a1208;
  box-shadow: 0 0 0 1px rgba(240, 160, 74, 0.45);
}
.book-title-info {
  display: grid;
  gap: 10px;
  margin: 0 0 4px;
}
.book-title-info-row {
  display: grid;
  gap: 2px;
}
.book-title-info-k {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #6b7280);
}
.book-title-info-v {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  white-space: normal;
  word-break: break-word;
}
.mute-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
}
.mute-dot svg,
.mute-icon {
  display: block;
  flex-shrink: 0;
}
.mute-icon--on {
  color: var(--online, #31b567);
}
.mute-icon--off {
  color: var(--text-faint, #8a93a3);
}
.menu-mute-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  line-height: 0;
}
.menu-mute-state.is-muted {
  color: var(--text-faint, #8a93a3);
}
.btn-send svg {
  display: block;
}
.attach-menu-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}
.dir-nav-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.android-install-close,
.profile-modal-close,
.tips-banner-dismiss,
.lightbox-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.lightbox-nav svg {
  display: block;
}

.group-name {
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-tight);
}

.group-preview {
  grid-column: 1 / -1;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
}

/* ── Chat panel ─────────────────────────────────────────── */

.chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--bg-page);
}

.chat-panel.is-drop-target::after {
  content: "Отпустите изображение";
  position: absolute;
  inset: var(--space-3);
  z-index: 20;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.88);
  color: var(--accent);
  font-weight: 600;
  font-size: var(--text-base);
  letter-spacing: var(--tracking-tight);
  pointer-events: none;
  backdrop-filter: blur(10px);
  animation: fade-in var(--duration-fast) var(--ease) both;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  min-height: 68px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-soft);
  position: relative;
  z-index: 30;
}

/* Desktop / fine pointer: back control is hidden — collapse its slot so title sits left */
.chat-header > #btn-toggle-sidebar.mobile-only {
  display: none !important;
  width: 0 !important;
  min-width: 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
  flex: 0 0 0 !important;
}
@media (min-width: 841px) and (hover: hover) and (pointer: fine) {
  html:not(.is-native-app) .chat-header {
    padding-left: 16px;
    gap: 8px;
  }
}

.chat-header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  position: relative;
  z-index: 2; /* above title plaque (z-index:1) so search/⋮ stay visible */
}

/* Header + message-search: larger tap targets, stronger contrast */
.chat-header > .icon-btn,
.chat-header-actions .icon-btn,
.msg-search-bar .icon-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  color: var(--text-main, var(--text));
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  flex-shrink: 0;
  opacity: 1;
  visibility: visible;
}

.chat-header > .icon-btn:hover,
.chat-header-actions .icon-btn:hover,
.msg-search-bar .icon-btn:hover {
  color: var(--accent);
  background: var(--bg-hover);
}

.chat-header > .icon-btn:focus-visible,
.chat-header-actions .icon-btn:focus-visible,
.msg-search-bar .icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-header > .icon-btn svg,
.chat-header-actions .icon-btn svg,
.msg-search-bar .icon-btn svg,
.tips-banner-dismiss svg,
.pinned-bar .icon-btn svg {
  width: 22px;
  height: 22px;
  display: block;
  flex-shrink: 0;
  overflow: visible;
  pointer-events: none;
}

.chat-header-actions .icon-btn svg,
.chat-header > .icon-btn svg {
  width: 24px;
  height: 24px;
}

.chat-header > .icon-btn svg path,
.chat-header-actions .icon-btn svg path,
.msg-search-bar .icon-btn svg path,
.tips-banner-dismiss svg path,
.pinned-bar .icon-btn svg path {
  stroke: currentColor;
  stroke-width: 2.4px;
  fill: none;
}

.chat-header > .icon-btn svg circle[fill],
.chat-header-actions .icon-btn svg circle[fill],
.msg-search-bar .icon-btn svg circle[fill] {
  fill: currentColor;
  stroke: none;
}

.chat-header > .icon-btn svg circle[stroke],
.chat-header-actions .icon-btn svg circle[stroke],
.msg-search-bar .icon-btn svg circle[stroke] {
  stroke: currentColor;
  fill: none;
}

.chat-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.chat-desc {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.chat-header-text {
  border-radius: 12px;
  padding: 4px 8px;
  margin: -4px 0; /* no negative right margin — was overlapping header action icons */
  margin-left: 0; /* do not overlap #btn-toggle-sidebar hit target */
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  z-index: 0;
  min-width: 0;
}
.chat-header-text:hover { background: var(--bg-hover); }

/* Tips banner */
.tips-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 9px 24px;
  flex-shrink: 0;
  background: rgba(47, 124, 246, 0.07);
  border: none;
  border-bottom: 1px solid var(--border-soft);
  border-radius: 0;
  font-size: 12.5px;
  color: var(--text-dim);
  animation: fadeUp 0.25s ease both;
}

.tips-banner-text { flex: 1; line-height: var(--leading-normal); min-width: 0; }
.tips-banner-label { font-weight: 600; color: var(--text-main); }
.tips-banner-text strong { color: var(--text); font-weight: 600; }

.tips-banner-dismiss {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 13px;
  line-height: 1;
  transition: color 0.15s ease, background 0.15s ease;
}

.tips-banner-dismiss:hover { color: var(--text-main); background: transparent; }

/* Messages area */
.messages-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  /* Telegram-style soft blue chat wallpaper */
  background: linear-gradient(165deg, #eaf5fc 0%, #d8eef8 48%, #cce6f4 100%);
  isolation: isolate;
}

/* Repeating doodle tile (low contrast so bubbles stay readable) */
.messages-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url("../images/chat-wallpaper-doodles-blue.png?v=173");
  background-repeat: repeat;
  background-position: center top;
  background-size: 420px 420px;
  opacity: 0.38;
  mix-blend-mode: multiply;
}

.messages-wrap > * {
  position: relative;
  z-index: 1;
}

.messages-date-sticky {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: rgba(29, 29, 31, 0.72);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.15s ease;
}

.messages-date-sticky.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.messages-top-loader {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 11;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

.messages-top-loader.is-hidden { display: none; }

.msg-day-sep {
  align-self: center;
  display: flex;
  justify-content: center;
  width: 100%;
  margin: var(--space-3) 0 var(--space-2);
  pointer-events: none;
}

.msg-day-sep span {
  display: inline-flex;
  padding: 5px 13px;
  border-radius: 999px;
  background: var(--bg-chip);
  color: var(--text-faint);
  font-size: 11.5px;
  font-weight: 600;
}

.messages {
  flex: 1 1 auto;
  min-height: 0; /* critical: allow flex child to scroll instead of growing */
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0;
  display: block;
  scroll-behavior: auto; /* smooth breaks scroll-anchor restore on prepend */
  -webkit-overflow-scrolling: touch;
  overflow-anchor: none;
  scrollbar-gutter: stable;
}

/* OKChat messages-container: short threads sit on the tip (flex-end). */
.messages-inner {
  width: 100%;
  min-height: 100%;
  box-sizing: border-box;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
  overflow-anchor: none;
}

/* Brief freeze after prepend/trim pin — keep scrollbar; JS restores scrollTop. */
.messages--pin-freeze {
  overflow-y: scroll;
  overflow-anchor: none;
  overscroll-behavior: none;
}

/* Bulk tip/open paint: suppress enter animations that look like a vanish. */
.messages.messages--static .msg.is-new,
.messages.messages--static .time-separator {
  animation: none !important;
}

.messages-trim-spacer {
  flex-shrink: 0;
  width: 100%;
  pointer-events: none;
}

.messages-scroll-sentinel {
  flex: 0 0 1px;
  height: 1px;
  width: 100%;
  pointer-events: none;
  visibility: hidden;
}

.new-messages-btn {
  position: absolute;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 18px;
  min-height: 36px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  /* Opaque elevated surface — readable over blue outgoing bubbles and light chat bg */
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  animation: rise var(--duration) var(--ease-spring) both;
  transition: background var(--duration) var(--ease), transform var(--duration-fast) var(--ease-spring), border-color var(--duration) var(--ease);
}

.new-messages-btn .new-messages-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.new-messages-btn .new-messages-count.is-hidden {
  display: none;
}

.new-messages-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.new-messages-btn:active { transform: translateX(-50%) scale(0.96); }

/* Empty states */
.empty-state {
  margin: auto;
  text-align: center;
  padding: var(--space-10) var(--space-6);
  max-width: 320px;
}

.empty-state-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius);
  background: transparent;
  display: block;
  overflow: hidden;
  color: var(--text-tertiary);
}

.empty-state-icon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.empty-state-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-lg);
  font-weight: 650;
  letter-spacing: var(--tracking-tight);
  color: var(--text);
}

.empty-state-text {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  line-height: var(--leading-normal);
}

/* Time separators */
.time-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: var(--space-4) 0;
  animation: fade-in var(--duration) var(--ease) both;
}

.time-separator span {
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.05);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

/* Messages — hug bubble content (actions open via long-press / right-click). */
.msg {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(0, auto);
  grid-template-areas: "avatar bubble";
  align-items: start;
  gap: var(--space-2) 6px;
  width: fit-content;
  max-width: min(680px, 88%);
  min-width: 0;
  align-self: flex-start;
}

.msg > .avatar { grid-area: avatar; }
.msg > .msg-bubble { grid-area: bubble; }

.msg.is-new {
  animation: msg-in var(--duration) var(--ease) both;
}

@media (prefers-reduced-motion: reduce) {
  .msg.is-new { animation: none; }
  .poll-bar { transition: none !important; }
  .messages { scroll-behavior: auto; }
}

.msg.is-mine {
  /* margin-inline-start wins even if a media query stretches row width */
  align-self: flex-end;
  margin-inline-start: auto;
  grid-template-columns: minmax(0, auto);
  grid-template-areas: "bubble";
}

/* Personal chats: no left avatar column */
.msg.is-dm:not(.is-mine) {
  grid-template-columns: minmax(0, auto);
  grid-template-areas: "bubble";
}

/* Panel-level DM: hide peer avatars on first paint (boot cache before .msg.is-dm). */
.chat-panel.is-dm .msg:not(.is-mine),
html.chat-boot-dm .chat-panel .msg:not(.is-mine) {
  grid-template-columns: minmax(0, auto);
  grid-template-areas: "bubble";
}
.chat-panel.is-dm .msg > .avatar,
.chat-panel.is-dm .msg .msg-author,
html.chat-boot-dm .chat-panel .msg > .avatar,
html.chat-boot-dm .chat-panel .msg .msg-author {
  display: none !important;
}

.msg.is-grouped {
  margin-top: calc(var(--space-1) * -1);
}

.msg.is-grouped .avatar { visibility: hidden; }
.msg.is-grouped .msg-author { display: none; }

.msg.is-mine .msg-bubble {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 4px 14px rgba(47, 124, 246, 0.25);
  justify-self: end;
}

.msg.is-mine.is-grouped .msg-bubble {
  border-radius: 18px 18px 6px 18px;
}

.msg.is-mine .msg-meta { color: rgba(255, 255, 255, 0.65); justify-content: flex-end; }

.msg.is-ai .msg-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--ai-border);
}

.msg.is-ai.is-mine .msg-bubble {
  background: var(--accent);
  border: none;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background-color: var(--avatar-initial-bg);
  color: var(--avatar-initial-fg);
  font-size: 12.5px;
  font-weight: var(--avatar-initial-weight, 600);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  align-self: end;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}
.avatar.has-image {
  color: transparent;
  font-size: 0 !important;
  background-color: var(--bg-muted, var(--bg-chip));
}

button.avatar.msg-user-hit {
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
button.avatar.msg-user-hit:hover,
button.avatar.msg-user-hit:focus-visible {
  outline: 2px solid var(--accent, #3b82f6);
  outline-offset: 2px;
}

.msg-bubble {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  width: fit-content;
  max-width: min(420px, 100%);
  min-width: 0;
  overflow: hidden;
  box-sizing: border-box;
  background: var(--bg-bubble-in);
  border: 1px solid var(--border-soft);
  border-radius: 18px 18px 18px 6px;
  padding: 12px 14px;
  box-shadow: var(--bubble-shadow);
  justify-self: start;
}

.msg.is-grouped:not(.is-mine) .msg-bubble {
  border-bottom-left-radius: var(--radius-bubble);
}

.msg-author {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

.msg-author-btn {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.msg-author-btn:hover,
.msg-author-btn:focus-visible {
  text-decoration: underline;
  outline: none;
}

.msg.is-mine .msg-author { display: none; }

.ai-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.msg.is-mine .ai-badge {
  background: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.9);
}

/* Caption / body — always in normal flow BELOW media (never absolute/float overlay). */
.msg-body,
.msg-text {
  position: static;
  float: none;
  clear: both;
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Media block sits above caption; clips any oversized media so text cannot run onto it. */
.msg-media {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  flex: 0 0 auto;
  overflow: hidden;
  float: none;
  clear: both;
}

.msg-image,
.msg-media-pending.msg-image-slot {
  display: block;
  width: 100%;
  max-width: min(72vw, 320px);
  /* Reserve space before decode so reopen does not jump when imgs paint. */
  aspect-ratio: 4 / 3;
  min-height: 180px;
  max-height: 360px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.04);
  cursor: zoom-in;
  overflow: hidden;
  float: none;
  position: relative;
}

.msg-media-pending.msg-image-slot {
  cursor: default;
  display: grid;
  place-items: center;
}

.msg-image img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: inherit;
  vertical-align: top;
  position: absolute;
  inset: 0;
}

.msg-bubble:has(.msg-media) {
  max-width: min(72vw, 320px);
  padding: 4px;
}

.msg-bubble:has(.msg-media) .msg-author,
.msg-bubble:has(.msg-media) .msg-forwarded,
.msg-bubble:has(.msg-media) .msg-reply,
.msg-bubble:has(.msg-media) .msg-body,
.msg-bubble:has(.msg-media) .msg-text,
.msg-bubble:has(.msg-media) .msg-meta {
  padding-left: 10px;
  padding-right: 10px;
}

.msg-bubble:has(.msg-media) .msg-author,
.msg-bubble:has(.msg-media) .msg-forwarded,
.msg-bubble:has(.msg-media) .msg-reply {
  padding-top: 6px;
}

.msg-bubble:has(.msg-media) .msg-body,
.msg-bubble:has(.msg-media) .msg-text {
  position: relative;
  z-index: 1;
  padding-top: 8px;
  padding-bottom: 2px;
}

.msg-bubble:has(.msg-media) .msg-meta {
  padding-bottom: 6px;
  margin-top: 4px;
}

.msg-bubble.has-image-only,
.msg.is-mine .msg-bubble.has-image-only {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.msg-bubble.has-image-only .msg-media,
.msg-bubble.has-image-only .msg-image {
  margin: 0;
}

.msg-bubble.has-image-only .msg-meta {
  margin-top: 4px;
  padding: 0 4px;
  color: var(--text-tertiary);
}

.msg.is-mine .msg-bubble.has-image-only .msg-meta {
  color: var(--text-tertiary);
}

.msg-media-pending {
  display: grid;
  place-items: center;
  min-width: 120px;
  min-height: 88px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
}
.msg.is-mine .msg-media-pending {
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.92);
}

/* OKChat-style multi-photo album */
.attachments.attachments-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: min(72vw, 320px);
  max-width: 100%;
  border-radius: 14px;
  overflow: hidden;
  float: none;
  position: relative;
}
.attachments-grid-row {
  display: grid;
  gap: 2px;
  min-height: 0;
}
.attachments.attachments-grid .attachment-cell-wrap {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.06);
  overflow: hidden;
  cursor: pointer;
}
.attachments.attachments-grid .attachment-grid-img,
.attachments.attachments-grid .attachment-grid-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.peer-profile-sheet .peer-profile-body {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 10px;
  padding-top: 8px;
}
.peer-profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 999px;
  font-size: 36px;
  overflow: hidden;
}
.peer-profile-avatar--photo {
  cursor: pointer;
}
.peer-profile-avatar--photo:focus-visible {
  outline: 2px solid var(--accent, #2a6df4);
  outline-offset: 3px;
}
.peer-profile-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.peer-profile-meta {
  margin: 0;
  color: var(--text-dim);
}
.peer-media-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--surface-2, rgba(127, 127, 127, 0.12));
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.peer-media-row:hover {
  background: var(--surface-3, rgba(127, 127, 127, 0.18));
}
.peer-media-row-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(127, 127, 127, 0.14);
  color: var(--text-dim);
  flex-shrink: 0;
}
.peer-media-row-text {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.peer-media-row-title {
  font-weight: 600;
  font-size: 15px;
}
.peer-media-row-meta {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.peer-media-row-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  flex-shrink: 0;
}
.peer-media-row-chevron {
  color: var(--text-dim);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.photo-grid-btn {
  position: relative;
}
.photo-grid-btn.is-video::after,
.photo-grid-btn.is-circle::after {
  content: '';
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55) center / 12px no-repeat;
  pointer-events: none;
}
.photo-grid-btn.is-video::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E");
}
.photo-grid-btn.is-circle::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='7'/%3E%3Ccircle cx='12' cy='12' r='2.5' fill='white' stroke='none'/%3E%3C/svg%3E");
}
.lightbox-video {
  max-width: 100%;
  max-height: min(78vh, 100%);
  background: #000;
}

.msg-bubble.has-poll {
  max-width: min(340px, 92%);
  padding: 12px 14px;
  width: min(340px, 92vw);
}

.msg-meta {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  align-items: baseline;
}

.msg-edited {
  font-size: 10px;
  opacity: 0.85;
  font-style: italic;
}

.reply-bar.is-edit::before {
  background: #e8a317;
}

.msg-forwarded {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.msg.is-mine .msg-forwarded { color: rgba(255, 255, 255, 0.75); }

.msg-reply {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 4px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.05);
  cursor: pointer;
  border: none;
  border-left: 3px solid var(--accent);
  text-align: left;
  font: inherit;
  color: inherit;
  box-sizing: border-box;
  overflow: hidden;
}

.msg.is-mine .msg-reply {
  background: rgba(255, 255, 255, 0.16);
  border-left-color: rgba(255, 255, 255, 0.85);
}

.msg-reply-author {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  font-size: var(--text-xs);
  font-weight: 650;
  line-height: 1.3;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-reply-text {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  font-size: var(--text-xs);
  opacity: 0.85;
  line-height: 1.35;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-reply-thumb {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

/* Message action sheet — opened via long-press (mobile) or right-click (desktop). */
.msg-action-sheet {
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  display: none;
  flex-direction: column;
  min-width: 160px;
  padding: 6px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 120;
  max-height: min(70vh, calc(100dvh - 120px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.msg.is-actions-open .msg-action-sheet,
.msg-action-sheet.is-open { display: flex; }
.msg:not(.is-mine) .msg-action-sheet { left: 0; right: auto; }

.msg-action-sheet button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text);
}

.msg-action-sheet button:hover { background: var(--bg-soft); }

.msg-action-sheet button.msg-action-danger {
  color: var(--danger);
}

.msg-action-sheet button.msg-action-danger:hover {
  background: var(--danger-soft);
}

/* Composer — OKChat: pinned to bottom of flex column, never shrink under IME. */
.composer {
  flex: 0 0 auto;
  flex-shrink: 0;
  flex-grow: 0;
  margin-top: auto;
  align-self: stretch;
  position: relative;
  z-index: 5;
  min-height: 44px;
  padding: 0 !important;
  background: var(--bg-card);
  border-top: 1px solid var(--border-soft);
}

/* Desktop keyboard hint only — hide by default (touch / Capacitor / narrow). */
.composer-hint-desktop {
  display: none;
  font-size: 11px;
  color: var(--text-faint);
  margin: 0;
}
@media (hover: hover) and (pointer: fine) and (min-width: 841px) {
  .composer-hint-desktop { display: block; }
}

.composer-hint {
  display: none;
  font-size: 11px;
  color: var(--text-faint);
  margin: 0;
}
@media (hover: hover) and (pointer: fine) and (min-width: 841px) {
  .composer-hint { display: block; }
}

.reply-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  padding: 10px 12px 10px 14px;
  border-radius: 12px;
  background: var(--bg-chip);
  border: 1px solid var(--border-strong);
  position: relative;
  box-sizing: border-box;
}
.reply-bar::before {
  content: "";
  width: 3px;
  align-self: stretch;
  min-height: 28px;
  border-radius: 3px;
  background: var(--accent);
  flex: none;
}

.reply-bar-content { flex: 1; min-width: 0; }
.reply-bar-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--accent);
  margin-bottom: 2px;
}
.reply-bar-author {
  font-size: var(--text-sm);
  font-weight: 650;
  color: var(--text);
}
.reply-bar-text {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-bar-thumb {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.composer-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 16px;
  padding: 6px 6px 6px 8px;
  min-width: 0;
  width: 100%;
  overflow: visible;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease), background var(--duration) var(--ease);
}

.composer-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 124, 246, 0.1);
  background: var(--bg-card);
}

/*
 * Textarea must absorb leftover width only. Do NOT use field-sizing:content —
 * it gives the control a content-based min-width; on narrow viewports that
 * squeezes / clips #btn-circle as soon as the user types a character.
 * Vertical growth is handled by autosizeComposer() in JS.
 */
.composer-input {
  flex: 1 1 0%;
  min-width: 0;
  width: 0;
  max-width: 100%;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  max-height: 150px;
  padding: 9px 2px;
  line-height: 1.45;
  font-size: 14.5px;
  min-height: 38px;
  height: 38px;
  overflow-x: hidden;
  overflow-y: hidden;
  field-sizing: fixed;
}

/* Circle beside paperclip when compose is empty; JS hides while #compose-body has text. */
.circle-btn,
#btn-circle {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 38px;
  width: auto;
  height: 38px;
  padding: 0 8px;
  border-radius: 11px;
  flex: 0 0 auto;
  flex-shrink: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 650;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease), opacity var(--duration) var(--ease);
  opacity: 0.95;
}
/* Respect [hidden] / .is-hidden — do not force-show while typing. */
#composer:not([hidden]) #btn-circle:not([hidden]):not(.is-hidden) {
  display: inline-flex;
  visibility: visible;
  opacity: 0.95;
}
.circle-btn:hover,
#btn-circle:hover {
  background: var(--bg-hover);
  color: var(--accent);
  opacity: 1;
}
.circle-btn-icon {
  display: block;
  flex: none;
}
.circle-btn-label {
  line-height: 1;
  letter-spacing: 0.01em;
}
@media (max-width: 380px) {
  .circle-btn,
  #btn-circle {
    padding: 0;
    width: 38px;
  }
  .circle-btn-label { display: none; }
}

.attach-btn {
  color: var(--accent);
  cursor: pointer;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  flex-shrink: 0;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease), opacity var(--duration) var(--ease);
  opacity: 0.92;
}
.attach-btn:hover { background: var(--bg-hover); color: var(--accent); opacity: 1; }

.attach-btn-icon {
  display: block;
  width: 24px;
  height: 24px;
}

.composer-preview {
  position: relative;
  margin-bottom: var(--space-2);
  width: fit-content;
  max-width: 100%;
}

.composer-preview-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}

.composer-preview-thumb {
  position: relative;
  width: fit-content;
  max-width: min(160px, 42vw);
  border-radius: var(--radius-sm);
  overflow: visible;
}

.composer-preview-thumb img,
.composer-preview-thumb .composer-preview-video {
  display: block;
  max-height: 96px;
  max-width: 100%;
  width: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: cover;
  background: var(--bg-muted);
}

.composer-preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 3;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 21, 0.78);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28), 0 0 0 1.5px rgba(255, 255, 255, 0.35);
  transition: background var(--duration) var(--ease), transform var(--duration-fast) var(--ease), opacity var(--duration) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.composer-preview-remove svg {
  display: block;
  width: 14px;
  height: 14px;
  pointer-events: none;
}

.composer-preview-remove:hover {
  background: rgba(20, 22, 28, 0.92);
  color: #fff;
}

.composer-preview-remove:active {
  transform: scale(0.92);
}

.composer-preview-remove:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.composer-preview-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: rgba(10, 14, 20, 0.48);
  pointer-events: none;
}

.composer-preview-loading[hidden] {
  display: none !important;
}

.composer-preview-spinner {
  width: 28px;
  height: 28px;
  box-sizing: border-box;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: composerPreviewSpin 0.7s linear infinite;
}

@keyframes composerPreviewSpin {
  to { transform: rotate(360deg); }
}

.composer-preview.is-uploading .composer-preview-remove {
  opacity: 0.35;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .composer-preview-spinner {
    animation: none;
    border-top-color: rgba(255, 255, 255, 0.85);
  }
}

/* ── Modals ─────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(10, 14, 20, 0.4);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  animation: fadeIn 0.2s ease both;
}

/* Above .lightbox-overlay (90) so «Переслать» from media viewer stays on top */
#modal-forward {
  z-index: 100;
}

.modal-card {
  position: relative;
  width: min(440px, 100%);
  max-width: calc(100vw - 48px);
  max-height: 86vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 22px;
  padding: 0 0 24px;
  box-shadow: var(--shadow-modal);
  animation: popIn 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.modal-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px 0;
}

.modal-card-head .modal-title {
  margin: 0;
  padding: 0;
}

.modal-card > .auth-form,
.modal-card > .modal-text,
.modal-card > .help-list,
.modal-card > .forward-group-list,
.modal-card > .modal-actions,
.modal-card > .btn {
  margin-left: 24px;
  margin-right: 24px;
}

.modal-card > .auth-form { margin-top: 18px; }
.modal-card > .modal-text { margin-top: 12px; }

.modal-form-gap { gap: 14px; }

.modal-close,
.modal-close-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  flex: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
}

.modal-close:hover,
.modal-close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.modal-card > .modal-title {
  padding: 20px 48px 0 24px;
}

.modal-card-welcome { text-align: center; }
.modal-card-welcome .auth-form { text-align: left; }
.modal-card-welcome > .modal-title { padding-right: 0; }

.modal-title {
  margin: 0 0 var(--space-2);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-text {
  margin: 0 0 var(--space-6);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.check-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  min-height: var(--tap-min);
  cursor: pointer;
}

.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }

.logout-wrap {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

/* Help modal bullets */
.help-list {
  margin: 0 0 var(--space-6);
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--space-4);
}

.help-list li {
  display: flex;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}

.help-list-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 14px;
}

/* Help modal footer — balanced spacing around full-width «Понятно» */
.modal-card-help {
  padding-bottom: 20px;
}

.modal-card-help > .modal-text {
  margin-bottom: 12px;
}

.modal-card-help > .help-list {
  margin-bottom: 12px;
}

.modal-actions-stack {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 4px;
}

.modal-actions-stack .btn {
  width: 100%;
  box-sizing: border-box;
  min-height: var(--tap-min);
  padding: 14px 22px;
}

.mobile-only { display: none; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  animation: fade-in var(--duration) var(--ease) both;
}

/* ── Animations ─────────────────────────────────────────── */

@keyframes rise {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ── Polls / forward ────────────────────────────────────── */

.modal-card-forward {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  padding-bottom: 16px;
}

.modal-card-forward > .modal-text {
  margin-bottom: 4px;
}

.forward-group-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(52vh, 380px);
  overflow: auto;
  margin: 4px 0 8px;
  padding: 2px 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.forward-group-list .forward-group-btn,
.forward-group-list .forward-group-item,
.forward-group-list .group-item {
  width: 100%;
  max-width: 100%;
  margin: 0;
  font: inherit;
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
}

.forward-group-list .group-item:hover {
  background: var(--bg-hover);
}

.forward-group-list .group-item:active,
.forward-group-list .group-item:focus-visible {
  background: rgba(47, 124, 246, 0.09);
  outline: none;
}

/* DM initials: shared via .avatar-initial / .group-item.is-dm rules above */

.forward-group-empty {
  margin: 12px 0 8px;
  padding: 20px 12px;
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.modal-card-forward .modal-actions {
  margin-top: 4px;
  padding-top: 4px;
}

.modal-card-poll { width: min(440px, 100%); }

.poll-options-edit { display: grid; gap: 8px; margin-bottom: 8px; }

.poll-option-edit {
  display: flex;
  gap: 8px;
  align-items: center;
}

.poll-option-edit input {
  flex: 1;
  border: 1px solid var(--border-strong);
  background: #fafafa;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-height: var(--tap-min);
}

.poll-option-edit .icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elevated);
}

.poll-bubble {
  display: grid;
  gap: 10px;
}

.poll-question {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 650;
  letter-spacing: var(--tracking-tight);
}

.poll-type {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.msg.is-mine .poll-type { color: rgba(255,255,255,0.7); }

.poll-options { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.poll-option {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-input);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.25s;
}
.poll-option:hover { border-color: var(--accent); }

.msg.is-mine .poll-option {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.18);
}

.poll-option.chosen { border-color: var(--accent); }
.msg.is-mine .poll-option.chosen { border-color: rgba(255,255,255,0.7); }

.poll-option.is-disabled { cursor: default; }

.poll-bar {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent-soft);
  pointer-events: none;
  z-index: 0;
  transition: width 0.22s ease;
}

.msg.is-mine .poll-bar { background: rgba(255,255,255,0.18); }

.poll-option > * { position: relative; z-index: 1; }

.poll-option-text { font-size: var(--text-sm); font-weight: 500; }
.poll-option-pct { font-size: var(--text-xs); font-weight: 700; color: var(--text-tertiary); }
.msg.is-mine .poll-option-pct { color: rgba(255,255,255,0.75); }

.poll-radio, .poll-box {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--accent);
}

.msg.is-mine .poll-radio,
.msg.is-mine .poll-box { color: #fff; }

.poll-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.msg.is-mine .poll-footer { color: rgba(255,255,255,0.7); }

.poll-footer button {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.msg.is-mine .poll-footer button { color: rgba(255,255,255,0.9); }

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* Link previews */
.link-preview {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 10px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0,0,0,0.04);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
}
.msg.is-mine .link-preview { background: rgba(255,255,255,0.16); color: #fff; }
.link-preview > i {
  display: block;
  width: 4px;
  border-radius: 4px;
  background: var(--accent);
  grid-row: 1 / span 2;
}
.link-preview span { display: grid; gap: 2px; min-width: 0; }
.link-preview small { font-size: 11px; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.msg.is-mine .link-preview small { color: rgba(255,255,255,0.85); }
.link-preview b { font-size: 14px; line-height: 1.25; }
.link-preview em {
  font-style: normal;
  font-size: 12px;
  opacity: 0.8;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
}

/* Group info / photos panels (legacy; overridden by drawer rules below) */
.panel-overlay,
#panel-group-info, #panel-photos, #panel-add-member {
  /* layout owned by Product2 drawer block */
}
.group-info-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.group-info-hero {
  text-align: center;
  margin-bottom: 16px;
}
.group-avatar-lg {
  width: 72px;
  height: 72px;
  margin: 0 auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  background: var(--gradient-brand);
}
.group-info-actions {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}
.group-info-section {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  margin: 12px 0 8px;
}
.member-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(40vh, 360px);
  overflow: auto;
  min-height: 0;
}
.member-results { display: grid; gap: 6px; }
.load-more-btn {
  width: 100%;
  margin-top: 8px;
}
.photo-grid-wrap {
  min-height: 0;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  min-height: 48px;
  border-radius: 10px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  box-sizing: border-box;
  transition: background var(--duration, 0.15s) var(--ease, ease);
}
.member-row:hover { background: var(--bg-hover); }
.member-row .avatar,
.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  /* Layout only — color/bg for initials come from shared :not(.has-image) rules above.
     Do not use `background` shorthand here: it resets background-image and hides photos. */
  font-weight: var(--avatar-initial-weight, 600);
  font-size: 13px;
  line-height: 1;
  flex: none;
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  user-select: none;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.member-row .avatar:not(.has-image),
.member-avatar:not(.has-image) {
  background-color: var(--avatar-initial-bg);
  color: var(--avatar-initial-fg);
}
.member-row .avatar.has-image,
.member-avatar.has-image {
  color: transparent;
  font-size: 0 !important;
  background-color: var(--bg-muted, var(--bg-chip));
}
.msg .avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: var(--avatar-initial-weight, 600);
  font-size: 14px;
  line-height: 1;
  flex: none;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.msg .avatar:not(.has-image) {
  background-color: var(--avatar-initial-bg);
  color: var(--avatar-initial-fg);
}
.msg .avatar.has-image {
  color: transparent;
  font-size: 0 !important;
  background-color: var(--bg-muted, var(--bg-chip));
}
.member-row.is-online .member-avatar::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--online);
  box-shadow: 0 0 0 2px var(--bg-card);
}
.member-meta {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}
.member-name-line {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.member-name {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.member-meta .role-badge,
.member-name-line .verified-badge,
.member-name-badge {
  flex: 0 0 auto;
  flex-shrink: 0;
  font-size: 9px;
  padding: 2px 5px;
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.member-name-line .verified-badge {
  margin-left: 0;
  padding: 1px 5px;
  font-size: 10px;
}
.role-badge--mod {
  color: var(--text-dim);
  background: var(--bg-chip);
}
.role-badge--verified {
  color: #0b6b3a;
  background: var(--success-soft);
}
.member-sub,
.member-status {
  display: block;
  font-size: 12px;
  line-height: 1.2;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
}
.member-status.is-online { color: var(--online); }
.member-status.is-banned { color: var(--danger); }
.member-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  flex: 0 0 auto;
  flex-shrink: 0;
  margin-left: 8px;
  min-width: 0;
}
.member-actions .member-action,
.member-row .member-action,
.member-row > .icon-btn {
  flex: 0 0 auto;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
  opacity: 0.7;
}
.member-actions .member-action svg,
.member-row .member-action svg,
.icon-role,
.icon-dm {
  width: 18px;
  height: 18px;
  display: block;
  flex-shrink: 0;
}
.member-row:hover .member-action,
.member-row:hover > .icon-btn,
.member-actions:focus-within .member-action {
  opacity: 1;
}
.member-action--danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
}
.poll { margin-top: 8px; display: grid; gap: 6px; }
.poll-question { font-weight: 600; margin-bottom: 4px; }
.poll-option {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.5);
  overflow: hidden;
  text-align: left;
  cursor: pointer;
}
.poll-option.is-chosen { border-color: var(--accent); }
.poll-bar {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent-soft);
  pointer-events: none;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.poll-option-text { position: relative; z-index: 1; }
.poll-meta { font-size: 12px; opacity: 0.7; }
.photo-month {
  grid-column: 1 / -1;
  margin: 8px 0 4px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: capitalize;
}
#message-search-bar.msg-search-bar {
  inset: auto;
  top: auto;
  height: auto;
  position: relative;
  display: flex;
  gap: 10px;
  border-bottom: 1px solid var(--border-soft);
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.is-search-hit .msg-bubble,
article.message.is-search-hit .bubble {
  outline: 2px solid rgba(47, 124, 246, 0.55);
  box-shadow: 0 0 0 4px rgba(47, 124, 246, 0.18);
}

mark.content-search-mark,
.content-search-mark {
  background: rgba(47, 124, 246, 0.22);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.pwa-install-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
html.keyboard-open .page-chat,
html.keyboard-open .chat-shell,
html.keyboard-open .chat-panel {
  padding-bottom: 0 !important;
}

/* Outer composer footer: no pad (user). Inner .composer-form keeps pill spacing. */
.composer {
  padding: 0 !important;
}
/*
 * IME open: keep outer footer at zero pad.
 * adjustResize / resizes-content already ends the layout at the keyboard top —
 * any leftover safe-area is the white abyss under the composer.
 */
html.keyboard-open .composer,
html.keyboard-open .comments-composer,
html.keyboard-open .panel-overlay .comments-composer {
  padding: 0 !important;
}

/*
 * Capacitor APK: adjustMarginsForEdgeToEdge=force already insets the WebView.
 * Any CSS env(safe-area-*) here double-counts → side gutters + composer floating
 * above the Android nav bar (OKChat: keep env() at 0 on native).
 */
html.is-native-app .page-chat,
html.is-native-app.keyboard-open .page-chat {
  padding: 0 !important;
}
html.is-native-app .composer,
html.is-native-app .comments-composer {
  padding: 0 !important;
}
html.is-native-app.keyboard-open .composer,
html.is-native-app.keyboard-open .comments-composer,
html.is-native-app.keyboard-open .panel-overlay .comments-composer {
  padding: 0 !important;
}
html.is-native-app,
html.is-native-app body,
html.is-native-app #chat-app,
html.is-native-app .page-chat,
html.is-native-app .chat-shell,
html.is-native-app .chat-panel {
  width: 100% !important;
  max-width: none !important;
  height: 100% !important;
  max-height: 100% !important;
}
html.is-native-app body.page-chat,
html.is-native-app #chat-app {
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  min-height: 0 !important;
}
html.is-native-app .chat-shell {
  flex: 1 1 auto !important;
  min-height: 0 !important;
}
html.is-native-app .composer-hint-desktop {
  display: none !important;
}

/* ── Responsive ─────────────────────────────────────────── */
/* Native / touch: same mobile shell even if WebView reports a wide CSS width. */

@media (max-width: 840px), (pointer: coarse), (hover: none) {
  .chat-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    width: 100%;
    max-width: none;
    overflow: hidden;
  }

  /* Overlay list + chat in one cell — do not auto-place into a second row. */
  .chat-shell > .sidebar,
  .chat-shell > .chat-panel {
    grid-column: 1;
    grid-row: 1;
  }

  .chat-shell > .chat-panel {
    min-height: 0;
    height: 100%;
    max-height: 100%;
    align-self: stretch;
  }

  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    /* Above .chat-header (z-index:30) so list screen is not covered by ghost chat chrome */
    z-index: 40;
    transform: none;
    transition: transform 0.34s var(--ease);
    box-shadow: none;
    border-right: none;
  }

  .sidebar.is-swipe-dragging {
    transition: none !important;
    will-change: transform;
  }

  .sidebar.is-swipe-leaving {
    will-change: transform;
    pointer-events: none !important;
  }

  body.chat-open .sidebar,
  html.chat-boot-open .sidebar {
    transform: translateX(-105%);
    pointer-events: none;
    box-shadow: none;
  }

  /* First paint with ?group=: no slide animation (avoids jerk on reload). */
  html.chat-boot-open:not(.chat-boot-ready) .sidebar {
    transition: none;
  }

  body.chat-open .sidebar.is-open,
  html.chat-boot-open .sidebar.is-open {
    transform: none;
    pointer-events: auto;
    box-shadow: var(--shadow-lg);
  }

  .sidebar-backdrop.is-visible {
    display: block;
  }

  .mobile-only { display: inline-flex; }

  /* Back control only while a chat is open (back-to-list). On the group list it must stay collapsed. */
  body.chat-open .chat-header > #btn-toggle-sidebar.mobile-only,
  html.chat-boot-open .chat-header > #btn-toggle-sidebar.mobile-only {
    display: inline-flex !important;
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    flex: none !important;
    overflow: visible !important;
    pointer-events: auto !important;
    position: relative;
    z-index: 2;
  }

  .messages-inner { padding: var(--space-4) var(--space-3) var(--space-3); }

  /* Hug content + push mine to the right. Do NOT use width:100% + auto|1fr
     (that parked outgoing blue bubbles on the left). */
  .msg {
    width: fit-content;
    max-width: min(680px, 92%);
  }
  .msg:not(.is-mine) {
    align-self: flex-start;
    margin-inline-start: 0;
    grid-template-columns: 36px minmax(0, auto);
    grid-template-areas: "avatar bubble";
  }
  .msg.is-mine {
    align-self: flex-end;
    margin-inline-start: auto;
    width: fit-content;
    max-width: min(680px, 85%);
    grid-template-columns: minmax(0, auto);
    grid-template-areas: "bubble";
  }
  .msg-bubble {
    width: auto;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
  }
  .msg.is-mine .msg-bubble {
    justify-self: end;
    width: auto;
    max-width: 100%;
  }
  .msg:not(.is-mine) .msg-bubble {
    justify-self: start;
    width: auto;
    max-width: 100%;
  }
  .msg > .msg-bubble {
    max-width: 100%;
  }

  /* Desktop Enter/Shift hint — hide on phones / Capacitor. */
  .composer-hint { display: none !important; }
  .composer-meta {
    margin-top: 0;
    min-height: 0;
  }

  .msg-action-sheet { display: none; }
  .msg.is-actions-open .msg-action-sheet,
  .msg-action-sheet.is-open { display: flex; }
}

html.is-native-app .chat-shell {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
html.is-native-app .chat-shell > .sidebar,
html.is-native-app .chat-shell > .chat-panel {
  grid-column: 1;
  grid-row: 1;
}
html.is-native-app .chat-shell > .chat-panel {
  min-height: 0;
  height: 100%;
  max-height: 100%;
}
html.is-native-app .sidebar {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  z-index: 40;
  transition: transform 0.34s var(--ease);
}
html.is-native-app .sidebar.is-swipe-dragging {
  transition: none !important;
  will-change: transform;
}
html.is-native-app .sidebar.is-swipe-leaving {
  will-change: transform;
  pointer-events: none !important;
}
html.is-native-app body.chat-open .sidebar,
html.is-native-app.chat-boot-open .sidebar {
  transform: translateX(-105%);
  pointer-events: none;
}
html.is-native-app body.chat-open .sidebar.is-open,
html.is-native-app.chat-boot-open .sidebar.is-open {
  transform: none;
  pointer-events: auto;
}
html.is-native-app .mobile-only { display: inline-flex; }
html.is-native-app body.chat-open .chat-header > #btn-toggle-sidebar.mobile-only,
html.is-native-app.chat-boot-open .chat-header > #btn-toggle-sidebar.mobile-only {
  display: inline-flex !important;
  width: 44px !important;
  min-width: 44px !important;
  height: 44px !important;
  min-height: 44px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  flex: none !important;
  overflow: visible !important;
  pointer-events: auto !important;
}

/* ── Feature: posts, verified, media tabs, lightbox ─────── */

.verified-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  padding: 2px 5px;
  line-height: 0;
  color: #0b6b3a;
  background: rgba(34, 160, 90, 0.15);
  border-radius: 4px;
  vertical-align: middle;
}
.verified-badge svg {
  display: block;
  width: 11px;
  height: 11px;
}

.msg.is-post .msg-bubble.is-post-bubble {
  max-width: min(520px, 100%);
}

.msg-post-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 6px;
}

.msg.is-mine .msg-post-label { color: rgba(255, 255, 255, 0.85); }

.msg-comments-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 2px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  cursor: pointer;
  max-width: 100%;
  transition: color 0.15s ease, opacity 0.15s ease;
}

.msg-comments-btn:hover {
  color: var(--accent-hover);
}

.msg-comments-btn:focus-visible {
  outline: 2px solid var(--accent-glow);
  outline-offset: 3px;
  border-radius: 6px;
}

.msg-comments-icon {
  flex-shrink: 0;
  opacity: 0.92;
}

.msg-comments-label {
  white-space: nowrap;
}

.msg-comments-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.msg-comments-badge[hidden] {
  display: none !important;
}

.msg.is-mine .msg-comments-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
}

.msg.is-mine .msg-comments-btn:hover {
  background: transparent;
  color: #fff;
  opacity: 1;
}

.msg.is-mine .msg-comments-btn:focus-visible {
  outline-color: rgba(255, 255, 255, 0.55);
}

.msg.is-mine .msg-comments-badge {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.media-tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px 8px;
  overflow-x: auto;
}

.media-tab {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border, #ddd);
  border-radius: 10px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.media-tab.is-active {
  background: rgba(0, 0, 0, 0.06);
  font-weight: 600;
}

.lightbox-overlay {
  background: rgba(0, 0, 0, 0.92) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.lightbox-overlay[hidden] {
  display: none !important;
}

.lightbox-card {
  position: relative;
  width: min(960px, 100%);
  max-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 40px 56px;
}

.lightbox-img {
  max-width: 100%;
  max-height: calc(100dvh - 120px);
  object-fit: contain;
  user-select: none;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  color: #fff !important;
  z-index: 2;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  z-index: 2;
}

.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }

.lightbox-footer {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
}

.lightbox-footer .btn { color: #fff; }

.comments-list {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 8px 4px 12px;
  -webkit-overflow-scrolling: touch;
}

.comments-list.messages {
  background: transparent;
}

.comments-list .messages-inner {
  min-height: 100%;
  justify-content: flex-end;
  padding: 0 8px;
}

.comments-list .msg {
  max-width: 100%;
}

.comments-empty {
  margin: auto 0;
}

.comment-row {
  display: flex;
  gap: 10px;
  padding: 0;
  border-bottom: none;
}

.comment-row .comment-avatar,
.comment-avatar {
  width: 30px !important;
  height: 30px !important;
  font-size: 12px !important;
  flex: none;
  align-self: flex-start;
}

.comment-body { flex: 1; min-width: 0; }
.comment-author {
  font-size: 12.5px;
  font-weight: 700;
}
.comment-body p {
  margin: 2px 0 0;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.comment-row time {
  font-size: 10.5px;
  color: var(--text-faint);
  opacity: 1;
  margin-top: 3px;
  display: block;
}

.verify-file-drop {
  display: block;
  border: 1.5px dashed var(--border-soft);
  background: none;
  color: var(--text-dim);
  border-radius: 12px;
  padding: 16px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.verify-file-drop:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.panel-body-pad {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
.panel-body-pad .modal-text { margin: 0; padding: 0; }
.panel-body-pad .auth-form { padding: 0; }

.expert-status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  background: rgba(201, 134, 31, 0.12);
  border-color: rgba(201, 134, 31, 0.35);
}
.expert-status-banner.is-pending {
  background: rgba(201, 134, 31, 0.12);
  border-color: rgba(201, 134, 31, 0.35);
  color: #8a5a0a;
}
.expert-status-banner.is-rejected {
  background: rgba(196, 68, 68, 0.1);
  border-color: rgba(196, 68, 68, 0.35);
  color: #a33;
}
.expert-status-banner.is-approved {
  background: rgba(49, 181, 103, 0.12);
  border-color: rgba(49, 181, 103, 0.35);
  color: #1f7a45;
}
.expert-status-banner-label {
  font-weight: 600;
  font-size: 15px;
}
.expert-status-banner-chevron {
  opacity: 0.7;
  transition: transform 0.15s ease;
}
.expert-status-banner.is-collapsed .expert-status-banner-chevron {
  transform: rotate(-90deg);
}
.expert-status-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.expert-status-panel.is-collapsed { display: none; }
.expert-status-next {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-main);
}
.expert-status-next p { margin: 0; }
.expert-status-hint {
  color: var(--text-dim);
  font-size: 13px;
}
.expert-app-details {
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
}
.expert-app-details-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.expert-app-dl {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.expert-app-dl > div {
  display: grid;
  gap: 2px;
}
.expert-app-dl dt {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}
.expert-app-dl dd {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.admin-app-card {
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-input);
  margin-bottom: 10px;
}

.poll-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.msg .avatar {
  width: 32px !important;
  height: 32px !important;
  font-size: 12.5px !important;
  align-self: flex-end;
}

.msg-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 0 5px 4px;
}

.comment-img {
  max-width: 160px;
  border-radius: 8px;
  margin-top: 6px;
}

.comments-form {
  margin: 0;
  flex: 1;
  min-width: 0;
  border-top: none;
}

.comments-composer,
.composer.comments-composer {
  flex: none;
  margin-top: auto;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-card);
  /* Inset pill so focus border + glow are not clipped by drawer overflow */
  padding: 10px 12px max(10px, env(safe-area-inset-bottom, 0px));
  position: relative;
  z-index: 2;
  overflow: visible;
  box-sizing: border-box;
}

.comments-composer .composer-form,
.comments-composer .comments-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  /* Match main chat composer pill — single border/radius */
  padding: 6px 6px 6px 8px;
  margin: 0;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 16px;
  box-sizing: border-box;
  box-shadow: none;
  outline: none;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease), background var(--duration) var(--ease);
}

.comments-composer .composer-form:focus-within,
.comments-composer .comments-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 124, 246, 0.12);
  background: var(--bg-card);
  outline: none;
}

.comments-composer .composer-input {
  border: none;
  outline: none;
  box-shadow: none;
  background: transparent;
  border-radius: 0;
}

.comments-composer .composer-input:focus,
.comments-composer .composer-input:focus-visible {
  border: none;
  outline: none;
  box-shadow: none;
}

.comments-composer .attach-menu {
  bottom: calc(100% + 6px);
  top: auto;
}

/* Quote plaque in comments — same stronger treatment as chat reply bar */
#comment-reply-bar.reply-bar,
.comments-composer .reply-bar {
  background: var(--bg-chip);
  border: 1px solid var(--border-strong);
  margin: 0 0 10px;
}

#comment-reply-bar .reply-bar-text,
.comments-composer .reply-bar-text {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}

.comments-post-preview {
  flex: none;
  margin: 10px 14px 8px;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: 12px;
  border: none;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-dim);
  max-height: 72px;
  overflow: hidden;
  opacity: 1;
}

.admin-app-card {
  padding: 12px;
  border-bottom: 1px solid var(--border, #eee);
}

.admin-docs a { font-size: 13px; }

.links-list { padding: 8px 12px; }

.link-row {
  display: block;
  padding: 10px 0;
  border-bottom: 1px solid var(--border, #eee);
  color: inherit;
  text-decoration: none;
}

.link-row small { display: block; opacity: 0.7; margin-top: 2px; }

.composer-post-opt {
  padding: 0;
  font-size: 12px;
  min-height: 0;
  gap: 7px;
  color: var(--text-dim);
  flex: none;
}

.composer-post-opt input {
  width: 15px;
  height: 15px;
}

/* DM list initials: shared via .avatar-initial rules (was rgba blue + white letter) */

/* ── Pinned bar (mockup) ─────────────────────────────────── */
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  cursor: pointer;
}
.pinned-bar-icon {
  width: 3px;
  height: 30px;
  border-radius: 3px;
  background: var(--accent);
  flex: none;
  font-size: 0;
  color: transparent;
  overflow: hidden;
}
.pinned-bar-content { flex: 1; min-width: 0; }
.pinned-bar-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}
.pinned-bar-text {
  font-size: 12.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tips-banner {
  margin: 0;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(47, 124, 246, 0.07);
  padding: 9px 24px;
  align-items: center;
}

.admin-badge,
.badge-admin {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 6px;
  text-transform: uppercase;
}

.auth-step-indicator { display: none; }

.group-item-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.group-item-top time { font-size: 11px; color: var(--text-faint); }
.group-item-bottom small { font-size: 12.5px; color: var(--text-dim); }

.msg-body,
.msg-text { font-size: 14.5px; line-height: 1.45; }
.msg-meta { font-size: 10.5px; }
.msg.is-mine .msg-meta { opacity: 0.75; }

.time-separator span,
.messages-date-sticky {
  background: var(--bg-chip) !important;
  color: var(--text-faint) !important;
  box-shadow: none !important;
}

@media (max-width: 840px), (pointer: coarse), (hover: none) {
  .messages-inner { padding: 16px 14px; }
  /* Outer composer footer: zero pad (user). Inner form keeps pill spacing. */
  .composer { padding: 0 !important; }
  .composer.comments-composer,
  .comments-composer {
    padding: 0 !important;
  }
  html.keyboard-open .composer,
  html.keyboard-open .comments-composer,
  html.keyboard-open .panel-overlay .comments-composer {
    padding: 0 !important;
  }
  html.is-native-app .composer,
  html.is-native-app .comments-composer {
    padding: 0 !important;
  }
  html.is-native-app.keyboard-open .composer,
  html.is-native-app.keyboard-open .comments-composer,
  html.is-native-app.keyboard-open .panel-overlay .comments-composer {
    padding: 0 !important;
  }
  .chat-header { padding: 12px 14px; }
  .chat-header-text {
    flex: 1 1 auto;
    max-width: none;
  }
  /* Search / tip / pin dismiss — SVG icons, keep ~44–48px tap targets on mobile */
  .chat-header-actions #btn-search {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
  }
  /* Tip + pinned dismiss × — larger glyph and ~44px tap target on mobile */
  .tips-banner,
  .pinned-bar {
    padding-right: 10px;
  }
  .tips-banner-dismiss,
  .pinned-bar #btn-unpin {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
    line-height: 1;
    border-radius: 10px;
  }
  .auth-title { font-size: 28px; }
  .auth-topbar { padding: 16px 18px; }
  .page-auth {
    min-height: var(--vv-height, 100dvh);
  }
  .auth-shell {
    justify-content: flex-start;
    min-height: var(--vv-height, 100dvh);
    padding: max(48px, calc(env(safe-area-inset-top, 0px) + 4px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
  }
  .auth-brand {
    margin-bottom: 18px;
  }
  .auth-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 14px;
  }
  .auth-subtitle {
    margin-bottom: 18px;
  }
  .auth-apps {
    margin-top: 20px;
    padding-top: 16px;
  }
}

/* ═══════════════════════════════════════════════════════════
   Mockup 1:1 — drawer, menus, profile, lightbox, composer
   ═══════════════════════════════════════════════════════════ */

.chat-header-text {
  display: flex;
  align-items: center;
  gap: 13px;
  border: none;
  background: none;
  font-family: inherit;
  text-align: left;
  color: inherit;
  /* Flex fills leftover space after actions; do NOT reserve ~200px (empty gap when icons hide/clip). */
  flex: 1 1 auto;
  min-width: 0;
  max-width: min(520px, 100%);
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: var(--avatar-initial-weight, 600);
  font-size: 16px;
  line-height: 1;
  flex: none;
  overflow: hidden;
  text-transform: uppercase;
  user-select: none;
}
.chat-header-avatar:not(.has-image):not(.is-peer):not(.avatar-initial) {
  background: var(--gradient-brand);
}

.chat-header-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header-meta .chat-title,
.chat-header-meta .chat-desc {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-desc::after {
  content: " · участники и медиа";
}

.chat-desc:empty::after { content: none; }

/* More dropdown */
.header-dropdown {
  position: absolute;
  top: 62px;
  right: 20px;
  width: 250px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.18);
  padding: 7px;
  z-index: 60;
  animation: popIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.header-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  color: var(--text-main);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.header-dropdown-item:hover { background: var(--bg-hover); }

.header-dropdown-meta {
  font-size: 12px;
  color: var(--text-dim);
  flex: none;
}

.header-dropdown-sep {
  height: 1px;
  background: var(--border-soft);
  margin: 6px 4px;
}

/* Message search */
.msg-search-bar,
#message-search-bar.msg-search-bar {
  position: relative;
  inset: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
  padding: 10px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-soft);
  animation: fadeUp 0.25s ease;
  z-index: 20;
  height: auto;
  overflow: visible;
}

.msg-search-bar .field-input,
#message-search-bar #msg-search-input {
  flex: 1 1 0%;
  min-width: 0;
  width: auto;
  max-width: none;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-input);
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 13.5px;
  min-height: 44px;
}

.msg-search-bar .field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 124, 246, 0.1);
}

.msg-search-bar .field-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  cursor: pointer;
  background: center / 14px 14px no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M6 6l12 12M18 6L6 18' stroke='%2314181f' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
  opacity: 0.72;
}

.msg-search-bar .field-input::-webkit-search-cancel-button:hover {
  opacity: 1;
}

html[data-theme="dark"] .msg-search-bar .field-input::-webkit-search-cancel-button {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M6 6l12 12M18 6L6 18' stroke='%23eef1f5' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
}

.msg-search-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: none;
  font-variant-numeric: tabular-nums;
  min-width: 2.5ch;
  text-align: center;
}

.pinned-bar { animation: fadeUp 0.25s ease; cursor: pointer; }
.pinned-bar.is-hidden,
.msg-search-bar.is-hidden,
.header-dropdown.is-hidden,
.attach-menu.is-hidden { display: none !important; }

/* Composer attach */
.composer-form { position: relative; }

.attach-wrap { position: relative; flex: none; }

.attach-btn {
  border: none;
  background: none;
  font-size: 17px;
  font-family: inherit;
  padding: 0;
}

.attach-menu {
  position: absolute;
  bottom: 56px;
  left: 0;
  width: 210px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.18);
  padding: 6px;
  z-index: 60;
  animation: popIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  color: var(--text-main);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  border-radius: 9px;
  padding: 10px 11px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.attach-menu-item:hover { background: var(--bg-hover); }

.attach-menu-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 13px;
  flex: none;
}

.attach-menu-icon-photo {
  background: rgba(47, 124, 246, 0.12);
  color: var(--accent);
}

.attach-menu-icon-video {
  background: rgba(16, 185, 129, 0.14);
  color: #059669;
}

.attach-menu-icon-poll {
  background: rgba(124, 92, 246, 0.13);
  color: #7c5cf6;
}

  .composer-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin: 0;
  /* display controlled above — desktop-only via (hover)+(pointer:fine) */
}

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 7px 4px 0;
  min-height: 22px;
}

/* DMs / no-pin: never show «Как пост…» and take zero layout space */
#compose-post-wrap.is-hidden,
#compose-post-wrap[hidden],
.composer-meta .composer-post-opt.is-hidden,
.composer-meta .composer-post-opt[hidden] {
  display: none !important;
  visibility: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  height: 0 !important;
  width: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
  position: absolute !important;
  clip: rect(0, 0, 0, 0) !important;
}

/* Collapse meta row when post opt is off and desktop hint is not shown */
.composer-meta:not(.has-post-opt) {
  justify-content: flex-start;
}
@media (hover: none), (pointer: coarse), (max-width: 840px) {
  .composer-meta:not(.has-post-opt) {
    display: none !important;
    margin: 0 !important;
    min-height: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
  }
}

/* DM chat: members button is group-only */
.is-dm #btn-members,
body.is-dm-chat #btn-members,
.chat-panel.is-dm #btn-members {
  display: none !important;
}

/* DM chat: never show «Как пост…» (zero layout space) */
body.is-dm-chat #compose-post-wrap,
.chat-panel.is-dm #compose-post-wrap,
body.is-dm-chat .composer-post-opt,
.chat-panel.is-dm .composer-post-opt {
  display: none !important;
  visibility: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  height: 0 !important;
  width: 0 !important;
  max-height: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
  position: absolute !important;
  clip: rect(0, 0, 0, 0) !important;
}
@media (hover: none), (pointer: coarse), (max-width: 840px) {
  body.is-dm-chat .composer-meta,
  .chat-panel.is-dm .composer-meta {
    display: none !important;
    margin: 0 !important;
    min-height: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
  }
}

.btn-link {
  align-self: flex-start;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 2px;
}

.btn-link:hover { color: var(--accent-hover); }

.btn-accent-soft {
  background: rgba(47, 124, 246, 0.1);
  color: var(--accent);
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 13.5px;
  font-weight: 600;
}

.btn-accent-soft:hover { background: rgba(47, 124, 246, 0.16); }

/* New group modal */
.new-group-name-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.new-group-avatar {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--gradient-brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 600;
  flex: none;
}

/* Profile / settings modal */
.modal-card-profile {
  width: min(380px, 100%);
  max-height: min(92vh, 720px);
  padding-bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.profile-modal-banner {
  position: relative;
  height: 72px;
  background: linear-gradient(135deg, #2f7cf6, #6aa6ff);
  border-radius: 21px 21px 0 0;
  flex: none;
}

.profile-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.profile-modal-close:hover { background: rgba(255, 255, 255, 0.32); }

.profile-modal-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.profile-modal-body {
  padding: 16px 24px 20px;
  margin-top: 0;
  position: relative;
  z-index: 1;
  text-align: left;
}

/* Avatar lives fully inside the body (no negative-margin overlap into the banner). */
.avatar-picker-overlap {
  width: 72px;
  height: 72px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.avatar-picker-overlap .avatar-picker-preview {
  border: 3px solid rgba(26, 29, 36, 0.06);
  box-sizing: border-box;
  font-size: 27px;
}

.profile-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-name-input {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
}

.profile-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.profile-status-line {
  margin: 4px 0 0;
}

.profile-menu-item {
  margin: 0;
}

.modal-card-profile .logout-wrap {
  margin: 12px 0 0;
  margin-left: 0;
  margin-right: 0;
}

.profile-save-bar {
  flex: none;
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(26, 29, 36, 0.08);
  background: var(--bg-card, #fff);
  display: grid;
  gap: 8px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.profile-save-bar.is-shown:not([hidden]) {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.profile-save-bar[hidden] {
  display: none !important;
}

.profile-save-hint {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--text-muted, #6b7280);
}

.profile-save-bar .btn-primary {
  min-height: 44px;
}

/* Right drawer — members / media */
.drawer-root {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
}

.drawer-root:not([hidden]) {
  pointer-events: auto;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 20, 0.35);
  animation: fadeIn 0.2s ease;
  border: none;
  cursor: pointer;
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 100vw;
  background: var(--bg-card);
  border-left: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  box-shadow: -16px 0 48px rgba(0, 0, 0, 0.16);
  animation: popIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 1;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex: none;
}

.drawer-title {
  font-size: 16px;
  font-weight: 700;
}

.drawer-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 1px;
}

.drawer-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 14px 4px;
  flex: none;
}

.drawer-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border-radius: 10px;
  padding: 9px;
  cursor: pointer;
  transition: all 0.2s;
}

.drawer-tab.is-active {
  background: var(--bg-hover);
  color: var(--text-main);
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.drawer-body.is-hidden { display: none !important; }

.drawer-empty {
  text-align: center;
  font-size: 13px;
  color: var(--text-faint);
  padding: 30px 12px;
}

.drawer-foot {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border-soft);
  flex: none;
}

.drawer-panel .member-list {
  max-height: none;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: none;
}

.drawer-members-search {
  flex: none;
  padding: 0 0 10px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-elevated, var(--bg-panel, #fff));
}

.drawer-members-search .field-input {
  width: 100%;
  box-sizing: border-box;
  min-height: 40px;
  border-radius: 10px;
  font-size: 14px;
}

.drawer-members-search.is-hidden,
.drawer-members-search[hidden] {
  display: none !important;
}

.drawer-panel .member-row {
  border-radius: 10px;
  padding: 6px 6px;
  min-height: 46px;
}

.drawer-panel .member-row .avatar,
.drawer-panel .member-avatar {
  width: 36px;
  height: 36px;
}

/* «Ещё» — footer control under the list, not beside a name */
.drawer-body > #btn-members-more,
.drawer-body > .load-more-btn {
  width: 100%;
  margin: 10px 0 4px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: none;
  flex: none;
  align-self: stretch;
}

.drawer-body > #btn-members-more:hover,
.drawer-body > .load-more-btn:hover {
  background: rgba(47, 124, 246, 0.18);
  color: var(--accent-hover);
}

.drawer-panel .photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.drawer-panel .photo-grid button,
.drawer-panel .photo-grid img {
  aspect-ratio: 1;
  border-radius: 10px;
  width: 100%;
  object-fit: cover;
  border: none;
  padding: 0;
  cursor: zoom-in;
  overflow: hidden;
  background: var(--bg-input);
}

/* Lightbox — mockup fullscreen
   Do NOT use display:!important here — it overrides [hidden]{display:none!important}
   (same specificity, later rule wins) and makes close appear broken. */
.lightbox-overlay {
  background: rgba(8, 11, 16, 0.88) !important;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  padding: 0 !important;
  place-items: stretch;
  z-index: 90;
  animation: fadeIn 0.25s ease both;
}
.lightbox-overlay[hidden] {
  display: none !important;
}

.lightbox-overlay .lightbox-card,
.lightbox-shell {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
}

.lightbox-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  color: #fff;
  flex: none;
}

.lightbox-author {
  font-size: 14px;
  font-weight: 600;
}

.lightbox-meta {
  font-size: 12px;
  opacity: 0.6;
  margin-top: 2px;
}

.lightbox-close-btn {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  transition: background 0.2s;
  flex: none;
}

.lightbox-close-btn:hover { background: rgba(255, 255, 255, 0.2); }
.lightbox-close-btn svg {
  width: 32px;
  height: 32px;
}

.lightbox-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  gap: 0;
  padding: 0 64px;
  min-height: 0;
  overflow: hidden;
}

.lightbox-stage--zoomable {
  touch-action: none;
}

.lightbox-zoom {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: min(760px, calc(100% - 8px));
  max-height: min(480px, 60vh);
  transform-origin: center center;
  will-change: transform;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-stage .lightbox-zoom .lightbox-img,
.lightbox-stage > .lightbox-img {
  width: auto;
  max-width: min(760px, calc(100% - 8px));
  max-height: min(480px, 60vh);
  border-radius: 18px;
  object-fit: contain;
  animation: popIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.lightbox-stage .lightbox-zoom .lightbox-img {
  max-width: 100%;
  max-height: min(480px, 60vh);
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.lightbox-zoom.is-zoomed .lightbox-img {
  animation: none;
}

/* Absolute beside media: override earlier static/flex arrow layout */
.lightbox-overlay .lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.lightbox-overlay .lightbox-prev { left: 12px; right: auto; }
.lightbox-overlay .lightbox-next { right: 12px; left: auto; }

.lightbox-nav:hover { background: rgba(255, 255, 255, 0.2); }
.lightbox-nav:disabled { opacity: 0.35; cursor: default; }

.lightbox-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  flex: none;
}

.lightbox-actions .btn,
.lightbox-action {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 11px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
}

.lightbox-actions .btn:hover,
.lightbox-action:hover { background: rgba(255, 255, 255, 0.2); }

.lightbox-action--danger {
  background: rgba(198, 40, 40, 0.55);
  color: #fff;
}
.lightbox-action--danger:hover {
  background: rgba(198, 40, 40, 0.75);
}

.composer-preview-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  max-width: min(120px, 28vw);
  height: 96px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.composer-preview-more:hover {
  border-color: var(--accent, #2563eb);
  color: var(--accent, #2563eb);
}
.composer-preview-thumb.is-extra {
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.compose-pending-overlay {
  z-index: 12100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(15, 17, 21, 0.45);
}
.compose-pending-sheet {
  width: min(560px, 100%);
  max-height: min(88vh, 720px);
  margin: 0;
  border-radius: 16px 16px 0 0;
  background: var(--bg, #fff);
  color: var(--text, #111);
  box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.compose-pending-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border, #e5e7eb);
  flex: none;
}
.compose-pending-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}
.compose-pending-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.compose-pending-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  padding: 14px 16px;
  overflow: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.compose-pending-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-muted, #f3f4f6);
  border: 1px solid var(--border, #e5e7eb);
}
.compose-pending-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.compose-pending-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 21, 0.78);
  color: #fff;
  cursor: pointer;
}
.compose-pending-num {
  position: absolute;
  left: 6px;
  bottom: 6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(15, 17, 21, 0.65);
  color: #fff;
  font-size: 11px;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.compose-pending-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border, #e5e7eb);
  flex: none;
}

@media (min-width: 720px) {
  .compose-pending-overlay {
    align-items: center;
  }
  .compose-pending-sheet {
    border-radius: 16px;
    max-height: min(80vh, 680px);
  }
}

/* Context actions — fixed, JS-anchored to message (above / side / below). */
.msg-action-sheet {
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  margin: 0;
  padding: 6px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
  animation: popIn 0.18s ease;
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  z-index: 120;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.msg.is-actions-open .msg-action-sheet,
.msg-action-sheet.is-open { display: flex; }

.msg-action-sheet button {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.msg-action-sheet button.msg-action-danger {
  color: var(--danger);
}

.msg-action-sheet button.msg-action-danger:hover {
  background: var(--danger-soft);
}

.reply-bar-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent);
}

.reply-bar-author { display: none; }

/* Panel overlays — right drawers (comments / verify / admin) */
.panel-overlay,
#panel-photos, #panel-add-member, #panel-comments, #panel-verification, #panel-admin {
  position: fixed;
  inset: 0;
  z-index: 75;
  background: transparent;
  overflow: visible;
  padding: 0;
  display: block;
  animation: none;
  pointer-events: none;
}

.panel-overlay .panel-backdrop {
  position: fixed;
  inset: 0;
  border: none;
  background: rgba(10, 14, 20, 0.35);
  z-index: 0;
  cursor: pointer;
  pointer-events: auto;
  animation: fadeIn 0.2s ease;
}

.panel-overlay .panel-drawer-inner {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 100vw;
  background: var(--bg-card);
  border-left: 1px solid var(--border-soft);
  box-shadow: -16px 0 48px rgba(0, 0, 0, 0.16);
  overflow: auto;
  display: flex;
  flex-direction: column;
  z-index: 1;
  pointer-events: auto;
  animation: popIn 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

#panel-admin .panel-drawer-inner {
  width: 380px;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
}

#panel-admin .media-tabs {
  flex: none;
}

#panel-admin #admin-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
  padding-bottom: 16px;
  overflow: hidden;
}

#panel-admin #admin-user-q {
  flex: none;
  width: 100%;
  box-sizing: border-box;
}

#panel-admin #admin-user-list.member-list,
#panel-admin .admin-scroll-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  height: auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

#panel-admin .admin-app-card {
  margin-bottom: 10px;
}

#panel-admin #admin-users-status {
  flex: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
  color: var(--text-faint);
}

.panel-overlay::before { display: none; }

.panel-overlay .group-info-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  margin: 0;
  border-bottom: 1px solid var(--border-soft);
  flex: none;
}

.panel-overlay .group-info-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.panel-overlay .modal-text,
.panel-overlay .auth-form,
.panel-overlay .media-tabs,
.panel-overlay #admin-body {
  padding-left: 18px;
  padding-right: 18px;
}

.panel-overlay .comments-post-preview {
  margin: 14px 16px 10px;
  padding: 11px 13px;
  background: var(--bg-input);
  border-radius: 12px;
  border: none;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-dim);
  max-height: 88px;
  overflow: hidden;
  opacity: 1;
}

.panel-overlay .comments-list {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 4px 6px 14px;
}

.panel-overlay .comments-composer {
  margin-top: auto;
  padding: 0 !important;
  overflow: visible;
}

.panel-overlay .comments-form {
  margin: 0;
  /* Keep pill inner padding from .comments-composer .composer-form — do not zero */
  border-top: none;
}

#panel-comments .panel-drawer-inner {
  overflow: hidden;
}

.panel-overlay .media-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px 4px;
}

.panel-overlay .media-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 10px;
  padding: 9px 6px;
  cursor: pointer;
}

.panel-overlay .media-tab.is-active {
  background: rgba(47, 124, 246, 0.12);
  color: var(--accent);
  font-weight: 600;
}

#panel-group-info { display: none !important; }

#message-search-bar.panel-overlay { display: none !important; }

.poll-options-edit .field-input,
.poll-option-edit input {
  border: 1.5px solid var(--border-soft);
  background: var(--bg-input);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13.5px;
  min-height: 0;
}

.modal-card-poll { width: min(420px, 100%); }

/* Poll actions (retract / stop) */
.poll-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
}

.poll-actions button,
.poll-action-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  border-radius: 9px;
  padding: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.poll-actions button:hover,
.poll-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.poll-closed-label {
  margin-top: 10px;
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  text-align: center;
}

.poll-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.poll-option .poll-check {
  width: 16px;
  height: 16px;
  border-radius: 99px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  flex: none;
}

.poll-option.is-chosen .poll-check { display: flex; }

.poll-option.is-chosen .poll-option-pct { color: var(--accent); font-weight: 600; }

.poll-option-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  z-index: 1;
}

.poll-option-label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.icon-btn-sm {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 14px;
}

.sidebar-actions .icon-btn-sm { font-size: 17px; }

.attach-menu-icon-file {
  background: rgba(49, 181, 103, 0.12);
  color: #31b567;
}

.help-list-icon {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(47, 124, 246, 0.12);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  margin-top: 1px;
}

html[data-theme="dark"] .reply-bar,
html[data-theme="dark"] #comment-reply-bar.reply-bar,
html[data-theme="dark"] .comments-composer .reply-bar {
  background: var(--bg-hover);
  border-color: var(--border-soft);
}

html[data-theme="dark"] .reply-bar-text,
html[data-theme="dark"] #comment-reply-bar .reply-bar-text {
  color: var(--text-main);
}

html[data-theme="dark"] .comments-composer .composer-form:focus-within,
html[data-theme="dark"] .comments-composer .comments-form:focus-within {
  box-shadow: 0 0 0 3px rgba(47, 124, 246, 0.22);
}

/* Dark design tokens — must be a real rule; orphaned decls are ignored by browsers */
html[data-theme="dark"] {
  --bg-page: #0e1116;
  --bg-sidebar: #12161d;
  --bg-card: #171b22;
  --bg-input: #10141a;
  --bg-hover: #1e242e;
  --bg-chip: #1e242e;
  --bg-bubble-in: #171b22;
  --text-main: #eef1f5;
  --text-dim: #98a2b0;
  --text-faint: #5f6976;
  --border-soft: #262c36;
  --border-strong: #3a4250;
  --bubble-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  --card-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  --avatar-initial-bg: rgba(47, 124, 246, 0.22);
  --avatar-initial-fg: #8bb4ff;
  color-scheme: dark;
}

/* Dark theme: quieter doodle wallpaper over navy */
html[data-theme="dark"] .messages-wrap {
  background: linear-gradient(165deg, #121820 0%, #0e141c 52%, #0b1017 100%);
}

html[data-theme="dark"] .messages-wrap::before {
  opacity: 0.055;
  mix-blend-mode: soft-light;
  filter: invert(1) brightness(1.15);
}

html[data-theme="dark"] body,
html[data-theme="dark"] .page-chat,
html[data-theme="dark"] .page-auth {
  background: var(--bg-page);
  color: var(--text-main);
}

html[data-theme="dark"] .brand-logo,
html[data-theme="dark"] .auth-logo,
html[data-theme="dark"] .empty-state-icon,
html[data-theme="dark"] .android-install-icon,
html[data-theme="dark"] .admin-site-logo {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
}

html[data-theme="dark"] .auth-logo {
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.14);
}

@media (max-width: 840px) {
  .drawer-panel { width: min(340px, 100vw); }
  .panel-overlay .panel-drawer-inner {
    width: min(360px, 100vw);
  }
  /* Fill space between back + action icons (don’t reserve ~188px and ellipsis early) */
  .chat-header-text {
    flex: 1 1 auto;
    max-width: none;
    min-width: 0;
  }
  .chat-header-actions {
    flex-shrink: 0;
    gap: 2px;
  }
  /* Drop long CTA suffix on narrow headers so type label (e.g. «Личные сообщения») fits */
  .chat-desc::after { content: none; }
  .header-dropdown { right: 12px; }
  .msg-search-bar { padding: 10px 14px; gap: 6px; }
}

/*
 * Mobile / native: message search on its own full-width row under the
 * title/avatar header — input not squeezed beside nav icons.
 * Desktop (wide + fine pointer, non-native) keeps the single-row bar.
 */
@media (max-width: 840px), (pointer: coarse), (hover: none) {
  .msg-search-bar,
  #message-search-bar.msg-search-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 6px;
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px 10px;
    flex-shrink: 0;
    background: var(--bg-input, var(--bg-card));
    border-bottom: 1px solid var(--border-soft);
  }

  .msg-search-bar .field-input,
  #message-search-bar #msg-search-input {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    min-width: 0;
    order: 1;
  }

  .msg-search-bar .msg-search-count,
  #message-search-bar .msg-search-count {
    order: 2;
    margin-left: auto;
  }

  .msg-search-bar > .icon-btn,
  #message-search-bar > .icon-btn {
    order: 2;
    flex: 0 0 auto;
  }
}

html.is-native-app .msg-search-bar,
html.is-native-app #message-search-bar.msg-search-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 6px;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px 10px;
  flex-shrink: 0;
  background: var(--bg-input, var(--bg-card));
  border-bottom: 1px solid var(--border-soft);
}

html.is-native-app .msg-search-bar .field-input,
html.is-native-app #message-search-bar #msg-search-input {
  flex: 1 1 100%;
  width: 100%;
  max-width: none;
  min-width: 0;
  order: 1;
}

html.is-native-app .msg-search-bar .msg-search-count,
html.is-native-app #message-search-bar .msg-search-count {
  order: 2;
  margin-left: auto;
}

html.is-native-app .msg-search-bar > .icon-btn,
html.is-native-app #message-search-bar > .icon-btn {
  order: 2;
  flex: 0 0 auto;
}

/* «Стать экспертом»: full-bleed on mobile/touch so list under the panel can't steal taps */
@media (max-width: 840px), (pointer: coarse), (hover: none) {
  #panel-expert-apply .panel-drawer-inner {
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    border-left: none;
    box-shadow: none;
  }
  #panel-expert-apply .panel-backdrop {
    pointer-events: none;
  }
}


.header-dropdown-item.is-hidden { display: none !important; }

@keyframes ringPulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 124, 246, 0.35); }
  100% { box-shadow: 0 0 0 14px rgba(47, 124, 246, 0); }
}
.auth-flashcall-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-dim);
  margin-top: 8px;
}
.auth-flashcall-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent);
  animation: ringPulse 1.4s ease-out infinite;
  flex: none;
}
.auth-flashcall-status.is-ok { color: var(--online); }
.auth-flashcall-status.is-ok .auth-flashcall-status-dot {
  background: var(--online);
  animation: none;
}

.auth-panel-center {
  align-items: center;
  text-align: center;
}

.auth-inline-link {
  display: inline;
  border: none;
  background: none;
  padding: 0;
  min-height: 0;
  font-size: inherit;
  font-weight: 500;
  font-family: inherit;
  color: var(--accent);
  cursor: pointer;
}
.auth-inline-link:hover { color: var(--accent-hover); }

/* Landing / login — apps */
.auth-apps {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.auth-apps-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.auth-apps-icons {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.auth-apps-btn {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 64px;
  padding: 10px 12px 8px;
  border-radius: 14px;
  text-decoration: none;
  transition: background 0.18s ease, transform 0.15s ease;
}
.auth-apps-btn--android {
  color: #1b7a3a;
  background: rgba(27, 122, 58, 0.1);
}
.auth-apps-btn--android:hover {
  background: rgba(27, 122, 58, 0.16);
}
.auth-apps-btn--android:active { transform: scale(0.97); }
.auth-apps-btn--ios {
  color: #5a6570;
  background: rgba(90, 101, 112, 0.1);
}
.auth-apps-btn--soon {
  opacity: 0.78;
  cursor: default;
  user-select: none;
}
.auth-apps-svg {
  width: 22px;
  height: 22px;
  display: block;
}
.auth-apps-caption {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.auth-apps-soon {
  position: absolute;
  right: 4px;
  top: 4px;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 9px;
  font-weight: 700;
  text-transform: lowercase;
  color: #fff;
  background: #5a6570;
  line-height: 1.3;
}

/* Soft Android install sheet — mounted on body (see apk-offer.js); above chat chrome */
.android-install-sheet {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 11000;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  max-width: 420px;
  margin: 0 auto;
  padding: 16px 18px 14px;
  border-radius: 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  box-shadow: 0 18px 48px rgba(15, 30, 55, 0.18);
  animation: androidSheetIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: auto;
}
.android-install-sheet.is-hidden,
.android-install-sheet[hidden] {
  display: none !important;
}
@keyframes androidSheetIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.android-install-icon {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: block;
  overflow: hidden;
  background: transparent;
}
.android-install-icon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.android-install-body { flex: 1; min-width: 0; }
.android-install-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.android-install-status {
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-secondary);
}
.android-install-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.android-install-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
}
.android-install-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}
#android-install-download.is-ready {
  box-shadow: 0 0 0 3px rgba(47, 124, 246, 0.18);
}

/* —— Video circles + owner video publish —— */
.composer-preview-video {
  display: block;
  max-width: 160px;
  max-height: 120px;
  border-radius: 10px;
  background: #000;
}
.msg-video-wrap {
  margin: 0;
  max-width: min(320px, 78vw);
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #0f1115;
  float: none;
  position: relative;
}
.msg-video {
  display: block;
  width: 100%;
  max-height: 360px;
  background: #000;
}
.msg-circle-wrap {
  position: relative;
  z-index: 0;
  width: 200px;
  height: 200px;
  max-width: 100%;
  border-radius: 50%;
  overflow: hidden;
  margin: 4px auto;
  background: #000;
  box-shadow: 0 2px 14px rgba(15, 17, 21, 0.18);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  float: none;
  flex-shrink: 0;
}
.msg-circle-wrap:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #2f7cf6) 55%, transparent), 0 2px 14px rgba(15, 17, 21, 0.18);
}
.msg-circle-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
  pointer-events: none;
}
.msg-circle-still {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  background: #000;
}
.msg-circle-still.is-visible {
  opacity: 1;
}
.msg-circle-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(circle at center, rgba(0, 0, 0, 0.28) 0%, rgba(0, 0, 0, 0.08) 55%, transparent 70%);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.msg-circle-play::before {
  content: '';
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(15, 17, 21, 0.55);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M9 7.5v9l7.5-4.5L9 7.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 54% 50%;
  background-size: 26px 26px;
}
.msg-circle-wrap.is-paused .msg-circle-play {
  opacity: 1;
}
.msg-circle-wrap.is-playing .msg-circle-play {
  opacity: 0;
}
.msg.is-circle .msg-bubble.is-circle-bubble,
.msg-bubble.is-circle-bubble {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}
.msg.is-mine .msg-bubble.is-circle-bubble {
  background: transparent;
}
.msg-bubble.is-circle-bubble .msg-meta {
  justify-content: flex-end;
  padding: 0 6px;
  color: var(--text-tertiary);
}
/* Circle + caption: keep normal bubble chrome; caption stays under the circle. */
.msg-bubble:has(.msg-circle-wrap):not(.is-circle-bubble) {
  max-width: min(280px, 92vw);
  padding: 10px 12px 8px;
}
.msg-bubble:has(.msg-circle-wrap):not(.is-circle-bubble) .msg-media {
  display: flex;
  justify-content: center;
  overflow: visible;
}
.msg-bubble:has(.msg-circle-wrap):not(.is-circle-bubble) .msg-body,
.msg-bubble:has(.msg-circle-wrap):not(.is-circle-bubble) .msg-text {
  padding-top: 8px;
  padding-left: 2px;
  padding-right: 2px;
}
.attach-menu-icon-circle {
  background: rgba(47, 124, 246, 0.12);
  color: var(--accent);
}

.attach-menu-item.is-hidden,
.attach-menu-item[hidden] {
  display: none !important;
}

/* Circle recorder overlay (OKChat port) */
.circle-rec-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg, #fff) 88%, transparent);
  backdrop-filter: blur(6px);
}
.circle-rec-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(72vw, 320px);
  height: min(72vw, 320px);
}
.circle-rec-ring-wrap {
  position: relative;
  width: min(72vw, 320px);
  height: min(72vw, 320px);
  isolation: isolate;
}
.circle-rec-preview {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background: #000;
  --circle-mirror: -1;
}
.circle-rec-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.06);
  z-index: 2;
  pointer-events: none;
  background: #000;
}
.circle-rec-playback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  background: #000;
  pointer-events: none;
  display: block;
}
.circle-rec-play {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(0, 0, 0, 0.28) 0%, rgba(0, 0, 0, 0.08) 55%, transparent 70%);
}
.circle-rec-play::before {
  content: '';
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(15, 17, 21, 0.55);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M9 7.5v9l7.5-4.5L9 7.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 54% 50%;
  background-size: 28px 28px;
}
.circle-rec-preview--recorded.is-paused .circle-rec-play {
  display: flex;
}
.circle-rec-preview--recorded.is-playing .circle-rec-play {
  display: none;
}
.circle-rec-preview--recorded.is-playing .circle-rec-poster {
  display: none;
}
.circle-rec-surface {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  background: #000;
  pointer-events: none;
}
.circle-rec-surface canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.06) scaleX(var(--circle-mirror, 1));
  transform-origin: center center;
  background: #000;
}
.circle-rec-ring-ui {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.circle-rec-ring-track {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-sizing: border-box;
  border: 4px solid rgba(128, 128, 128, 0.28);
}
.circle-rec-ring-fill {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    from -90deg,
    var(--accent, #2f7cf6) calc(var(--p, 0) * 360deg),
    transparent 0
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
}
.circle-rec-flip {
  position: absolute;
  right: 2px;
  bottom: 14%;
  z-index: 5;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--bg-elevated, #fff);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  pointer-events: auto;
  padding: 0;
}
.circle-rec-hint {
  margin: 0;
  max-width: min(100%, 320px);
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--text-secondary, #667085);
}
.circle-rec-bar {
  width: min(100%, 520px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 8px;
}
.circle-rec-timer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.circle-rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger, #dc3545);
  animation: circle-rec-pulse 1s ease-in-out infinite;
}
.circle-rec-cancel {
  border: none;
  background: transparent;
  color: var(--accent, #2f7cf6);
  font-size: 1rem;
  cursor: pointer;
  padding: 10px 14px;
  min-height: 44px;
  margin-left: auto;
  margin-right: auto;
}
.circle-rec-send {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 12010;
  width: 64px;
  height: 64px;
  min-width: 64px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent, #2f7cf6);
  color: #fff;
  font-size: 1.55rem;
  font-weight: 650;
  font-family: inherit;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent, #2f7cf6) 45%, transparent);
}
.circle-rec-send:disabled {
  opacity: 0.4;
  cursor: wait;
  box-shadow: none;
}
.circle-rec-send-icon {
  font-size: 1.55rem;
  line-height: 1;
  transform: translateY(-1px);
}
.circle-rec-send-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.circle-rec-send.is-ready {
  animation: circle-rec-send-pulse 1.2s ease-in-out 2;
}
@keyframes circle-rec-send-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* Photo source bottom sheet (replaces mid-screen iOS file chooser when possible) */
.photo-source-sheet {
  position: fixed;
  inset: 0;
  z-index: 13000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(15, 18, 28, 0.42);
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.photo-source-sheet.is-hidden,
.photo-source-sheet[hidden] { display: none !important; }
.photo-source-card {
  width: min(100%, 420px);
  background: var(--bg-card, #fff);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.18);
  padding: 6px;
  overflow: hidden;
  animation: popIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
.photo-source-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  color: var(--text-main, #1a1d24);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  padding: 10px 11px;
  cursor: pointer;
  border-radius: 9px;
  transition: background 0.15s;
}
.photo-source-item:hover,
.photo-source-item:active { background: var(--bg-hover, rgba(0,0,0,0.05)); }
.photo-source-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex: none;
}
.photo-source-icon svg { display: block; }
.photo-source-icon-library {
  background: rgba(47, 124, 246, 0.12);
  color: var(--accent);
}
.photo-source-icon-camera {
  background: rgba(16, 185, 129, 0.14);
  color: #059669;
}
.photo-source-icon-file {
  background: rgba(124, 92, 246, 0.13);
  color: #7c5cf6;
}
.photo-source-item.is-cancel {
  justify-content: center;
  color: var(--text-faint, #667085);
  font-weight: 500;
  margin-top: 2px;
}
/* Mobile: circle lives on composer (#btn-circle) — hide duplicate from paperclip menu */
@media (max-width: 840px), (pointer: coarse), (hover: none) {
  #attach-circle {
    display: none !important;
  }
}
@keyframes circle-rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* —— Standalone admin site —— */
.page-admin {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 8% -10%, rgba(47, 124, 246, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(26, 29, 36, 0.06), transparent 50%),
    var(--bg, #f6f7f9);
  color: var(--text, #1a1d24);
}
.admin-site {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  align-items: stretch;
}
.admin-site--fluid {
  max-width: none;
  width: 100%;
  margin: 0;
}
/* Users admin: use full viewport width (no centered narrow column). */
.page-admin:has(.admin-site--fluid) {
  width: 100%;
}
.admin-site.admin-site--fluid {
  max-width: none !important;
  width: 100%;
  margin: 0;
  box-sizing: border-box;
}
.admin-site--fluid .admin-site-main {
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}
.admin-site--fluid .admin-users-toolbar {
  width: 100%;
}
.admin-site--fluid .admin-users-search {
  max-width: none;
  flex: 1 1 320px;
}
.admin-site--fluid .admin-users-layout {
  width: 100%;
  grid-template-columns: minmax(0, 1fr) minmax(300px, min(440px, 36vw));
}
.admin-role-hint {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(47, 124, 246, 0.08);
  border: 1px solid rgba(47, 124, 246, 0.18);
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.4;
  max-width: 52rem;
}
.admin-role-hint--compact {
  margin: 0 0 8px;
  max-width: none;
  font-size: 0.82rem;
  padding: 8px 10px;
}
.admin-site-nav {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  overflow-y: auto;
  padding: 28px 20px;
  border-right: 1px solid rgba(26, 29, 36, 0.08);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  z-index: 20;
}
.admin-site-brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.admin-site-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}
.admin-site-brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.admin-site-mark {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}
.admin-site-sub {
  font-size: 0.8rem;
  color: #2f7cf6;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.admin-site-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.admin-site-links a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.admin-site-links a:hover {
  background: rgba(47, 124, 246, 0.08);
  color: var(--text);
}
.admin-site-links a.is-active {
  background: rgba(47, 124, 246, 0.12);
  color: #2f7cf6;
  font-weight: 600;
}
.admin-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 6px;
  border-radius: 999px;
  background: #2f7cf6;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.admin-site-main {
  padding: 32px 28px 48px;
  min-width: 0;
}
.admin-site-head h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
  font-weight: 700;
}
.admin-site-head p {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.admin-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 28px 0 24px;
}
.admin-kpi {
  background: #fff;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}
.admin-kpi-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: 600;
}
.admin-kpi-value {
  font-size: 1.7rem;
  letter-spacing: -0.04em;
  font-weight: 700;
  color: var(--text);
}
.admin-kpi-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.admin-card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.admin-nav-card {
  display: block;
  padding: 20px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid rgba(26, 29, 36, 0.08);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.admin-nav-card:hover {
  border-color: rgba(47, 124, 246, 0.45);
  transform: translateY(-1px);
}
.admin-nav-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  color: #2f7cf6;
}
.admin-nav-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.45;
}
.admin-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.admin-chart-card {
  background: #fff;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 14px;
  padding: 18px 18px 12px;
}
.admin-chart-card h2 {
  margin: 0;
  font-size: 1.05rem;
}
.admin-chart-sub {
  margin: 4px 0 12px;
  font-size: 0.85rem;
  color: var(--text-tertiary);
}
.admin-chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 220px;
}
.admin-chart-canvas-wrap--donut {
  height: 240px;
}
.admin-chart-card--half {
  min-height: 280px;
}
.admin-chart-empty {
  margin: 24px 0;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.9rem;
}
.admin-tables {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.admin-table-card {
  background: #fff;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 14px;
  padding: 18px;
}
.admin-table-card h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.9rem;
}
.admin-table th,
.admin-table td {
  text-align: left;
  padding: 8px 0;
  border-bottom: 1px solid rgba(26, 29, 36, 0.06);
  vertical-align: middle;
}
.admin-table th {
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.admin-table th.admin-table-num,
.admin-table td.admin-table-num,
.admin-table td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  width: 36%;
}
.admin-table th.admin-table-num {
  font-weight: 600;
}
.admin-help-form {
  max-width: 720px;
  background: #fff;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 14px;
  padding: 20px;
  margin-top: 20px;
}

/* Users admin */
.admin-users-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 20px 0 14px;
}
.admin-users-search {
  flex: 1 1 280px;
  max-width: 420px;
}
.admin-users-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-tertiary);
}
.admin-users-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
  gap: 14px;
  align-items: start;
}
.admin-users-list-card,
.admin-user-drawer {
  background: #fff;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 14px;
  overflow: hidden;
}
.admin-users-list {
  max-height: min(70dvh, 760px);
  overflow: auto;
  padding: 4px 0;
}
.admin-user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(26, 29, 36, 0.06);
}
.admin-user-row.is-selected {
  background: rgba(47, 124, 246, 0.08);
}
.admin-user-row.is-banned {
  opacity: 0.72;
}
.admin-user-row-main {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: 0;
  color: inherit;
  min-width: 0;
}
.admin-user-row-main .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: rgba(47, 124, 246, 0.12);
  color: #2f7cf6;
  font-weight: 700;
  position: relative;
}
.admin-user-row-main .avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.admin-user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}
.btn-sm {
  padding: 4px 8px;
  font-size: 0.78rem;
  border-radius: 8px;
}
.btn-danger-soft {
  color: #c0392b;
}
.admin-user-drawer-inner {
  padding: 16px 18px 24px;
  max-height: min(70dvh, 760px);
  overflow: auto;
}
.admin-user-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
}
.admin-user-drawer-head h2 {
  margin: 0;
  font-size: 1.2rem;
}
.admin-user-drawer-sub {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.admin-user-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 14px;
}
.admin-user-facts dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  font-weight: 600;
}
.admin-user-facts dd {
  margin: 2px 0 0;
  font-size: 0.92rem;
  font-weight: 600;
}
.admin-user-flags {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.admin-flag {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}
.admin-inline-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.admin-drawer-section {
  margin: 18px 0 8px;
  font-size: 0.95rem;
}
.admin-membership-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(26, 29, 36, 0.06);
}
.admin-membership-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.admin-membership-meta small {
  color: var(--text-tertiary);
}
.admin-groups-toolbar {
  margin: 0 0 8px;
}
.admin-groups-search {
  width: 100%;
}
.admin-groups-pager,
.admin-groups-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 0;
  font-size: 0.82rem;
}
.admin-groups-save-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(26, 29, 36, 0.06);
}
.admin-groups-save-hint {
  font-size: 0.8rem;
}
.admin-books-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.admin-book-edit {
  padding: 12px 14px;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 12px;
  background: var(--bg-elevated, rgba(26, 29, 36, 0.02));
}
.admin-book-edit-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.admin-book-edit .field-label {
  margin-top: 8px;
  margin-bottom: 4px;
}
.admin-book-edit .btn {
  margin-top: 10px;
}
.admin-invite-expert-card {
  margin: 0 0 18px;
  padding: 16px 18px;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 14px;
  background: var(--bg-card, #fff);
}
.admin-invite-expert-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}
.admin-invite-expert-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 420px;
}
.admin-invite-expert-form .field-label {
  margin-top: 10px;
  margin-bottom: 4px;
}
.admin-invite-expert-form .field-label:first-of-type {
  margin-top: 0;
}
.admin-book-cats,
.admin-invite-expert-form .admin-book-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 10px 0 4px;
}
.admin-create-book .field-label {
  margin-top: 8px;
}
.admin-user-drawer[hidden] {
  display: none !important;
}

/* Requests queues */
.admin-kpi--accent {
  border-color: rgba(47, 124, 246, 0.35);
  box-shadow: 0 0 0 1px rgba(47, 124, 246, 0.12);
}
.admin-kpi--accent .admin-kpi-value {
  color: #2f7cf6;
}
.admin-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 14px;
}
.admin-section-title {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}
.admin-section-sub {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
}
.admin-req-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0 18px;
}
.admin-req-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid rgba(26, 29, 36, 0.08);
  min-width: 140px;
}
.admin-req-pill-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  font-weight: 600;
}
.admin-req-pill-n {
  font-size: 1.25rem;
  font-weight: 700;
  color: #2f7cf6;
  font-variant-numeric: tabular-nums;
}
.admin-req-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}
.admin-req-block {
  background: #fff;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 180px;
}
.admin-req-block-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(26, 29, 36, 0.06);
}
.admin-req-block-head h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
}
.admin-req-block-head p {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--text-tertiary);
  line-height: 1.35;
}
.admin-req-count {
  flex-shrink: 0;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-tertiary);
  background: rgba(26, 29, 36, 0.06);
  font-variant-numeric: tabular-nums;
}
.admin-req-count.is-hot {
  background: rgba(47, 124, 246, 0.14);
  color: #2f7cf6;
}
.admin-req-list {
  padding: 8px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(62dvh, 720px);
  overflow: auto;
}
.admin-req-grid[data-req-mode="preview"] .admin-req-list {
  max-height: none;
  overflow: visible;
}
.admin-req-empty {
  margin: 12px 6px;
  font-size: 0.9rem;
  color: var(--text-tertiary);
}
.admin-req-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(26, 29, 36, 0.07);
  background: rgba(251, 252, 253, 0.9);
}
.admin-req-card-title {
  font-weight: 650;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}
.admin-req-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-tertiary);
}
.admin-req-card-body {
  margin-top: 8px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.admin-req-docs {
  margin-top: 6px;
  font-size: 0.82rem;
}
.admin-req-docs a {
  color: #2f7cf6;
}
.admin-req-docs--gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.admin-req-thumb {
  width: 56px;
  height: 56px;
  padding: 0;
  border: 1px solid rgba(26, 29, 36, 0.1);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  cursor: zoom-in;
}
.admin-req-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.admin-req-file {
  display: inline-flex;
  align-items: center;
  max-width: 140px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(47, 124, 246, 0.08);
  color: #2f7cf6;
  text-decoration: none;
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-req-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 10px 12px;
  border-top: 1px solid rgba(26, 29, 36, 0.06);
  font-size: 0.8rem;
  color: var(--text-tertiary);
}
.admin-req-pager[hidden] {
  display: none !important;
}
.admin-doc-lightbox {
  position: fixed;
  inset: 0;
  z-index: 14000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.admin-doc-lightbox[hidden] {
  display: none !important;
}
.admin-doc-lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(10, 12, 18, 0.78);
  cursor: pointer;
}
.admin-doc-lightbox-shell {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: min(88dvh, 900px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.admin-doc-lightbox-img {
  max-width: 100%;
  max-height: min(80dvh, 820px);
  object-fit: contain;
  border-radius: 10px;
  background: #111;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}
.admin-doc-lightbox-close {
  position: absolute;
  top: -8px;
  right: -8px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.admin-doc-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: #111;
  font-size: 1.5rem;
  cursor: pointer;
}
.admin-doc-lightbox-nav.prev { left: -8px; }
.admin-doc-lightbox-nav.next { right: -8px; }
.admin-doc-lightbox-nav:disabled {
  opacity: 0.35;
  cursor: default;
}
.admin-doc-lightbox-meta {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.admin-req-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.admin-req-footnote {
  margin: 18px 0 0;
  font-size: 0.85rem;
  color: var(--text-tertiary);
  line-height: 1.45;
}
.admin-req-footnote a {
  color: #2f7cf6;
}

@media (max-width: 1100px) {
  .admin-users-layout { grid-template-columns: 1fr; }
  .admin-site--fluid .admin-users-layout { grid-template-columns: 1fr; }
  .admin-user-drawer:not([hidden]) {
    position: sticky;
    top: 12px;
  }
  .admin-req-grid { grid-template-columns: 1fr; }
}
@media (max-width: 980px) {
  .admin-kpi-grid,
  .admin-card-grid,
  .admin-charts,
  .admin-tables { grid-template-columns: 1fr 1fr; }
  .admin-site {
    grid-template-columns: 180px minmax(0, 1fr);
  }
  .admin-site-nav {
    padding: 20px 12px;
  }
}
@media (max-width: 720px) {
  .admin-site {
    grid-template-columns: 1fr;
  }
  .admin-site-nav {
    position: sticky;
    top: 0;
    height: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid rgba(26, 29, 36, 0.08);
    padding: 12px 14px;
    display: block;
  }
  .admin-site-brand {
    margin-bottom: 10px;
  }
  .admin-site-links {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  .admin-site-links a {
    padding: 8px 10px;
    font-size: 0.85rem;
  }
  .admin-kpi-grid,
  .admin-card-grid,
  .admin-charts,
  .admin-tables { grid-template-columns: 1fr; }
  .admin-site-main { padding: 20px 16px 40px; }
  .admin-membership-row {
    grid-template-columns: 1fr;
  }
  .admin-user-facts { grid-template-columns: 1fr; }
  .admin-section-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
html[data-theme="dark"] .page-admin {
  background:
    radial-gradient(1000px 500px at 0% 0%, rgba(47, 124, 246, 0.16), transparent 50%),
    var(--bg);
}
html[data-theme="dark"] .admin-site-nav,
html[data-theme="dark"] .admin-kpi,
html[data-theme="dark"] .admin-nav-card,
html[data-theme="dark"] .admin-chart-card,
html[data-theme="dark"] .admin-table-card,
html[data-theme="dark"] .admin-help-form,
html[data-theme="dark"] .admin-users-list-card,
html[data-theme="dark"] .admin-user-drawer,
html[data-theme="dark"] .admin-req-block,
html[data-theme="dark"] .admin-req-pill {
  background: var(--bg-elevated, #171a21);
  border-color: rgba(255, 255, 255, 0.06);
}
html[data-theme="dark"] .admin-req-card {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.06);
}

/* Profession categories admin */
.admin-prof-add {
  margin: 0 0 20px;
  padding: 16px 18px;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 12px;
  background: var(--bg-elevated, #fff);
}
.admin-prof-add-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.admin-prof-add-row .field-input {
  flex: 1 1 220px;
  min-width: 160px;
}
.admin-prof-sort-input {
  flex: 0 0 110px !important;
  min-width: 96px !important;
  max-width: 120px;
}
.admin-prof-list-card {
  padding: 14px 16px 18px;
  border: 1px solid rgba(26, 29, 36, 0.08);
  border-radius: 12px;
  background: var(--bg-elevated, #fff);
}
.admin-prof-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.admin-prof-table-wrap {
  overflow-x: auto;
}
.admin-prof-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.admin-prof-table th,
.admin-prof-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(26, 29, 36, 0.06);
  vertical-align: middle;
}
.admin-prof-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  font-weight: 600;
}
.admin-prof-table tr.is-inactive td {
  opacity: 0.72;
}
.admin-prof-slug {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.admin-prof-actions {
  white-space: nowrap;
}
.admin-prof-actions .btn {
  margin: 2px 0;
}
.admin-prof-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.admin-prof-badge--on {
  background: rgba(46, 160, 90, 0.12);
  color: #1f7a45;
}
.admin-prof-badge--off {
  background: rgba(120, 120, 120, 0.14);
  color: #666;
}
html[data-theme="dark"] .admin-prof-add,
html[data-theme="dark"] .admin-prof-list-card {
  background: var(--bg-elevated, #171a21);
  border-color: rgba(255, 255, 255, 0.06);
}
html[data-theme="dark"] .admin-prof-badge--on {
  background: rgba(46, 160, 90, 0.2);
  color: #7ddea3;
}
html[data-theme="dark"] .admin-prof-badge--off {
  background: rgba(255, 255, 255, 0.08);
  color: #aaa;
}
