/* ═══════════════════════════════════════════════════════════════════════════
   А-ГРАМ Design System v2.2 — 1:1 Flutter Windows & Android UI Parity
   Pure Vector SVG Icons — Zero Emoji/Stickers
   ═══════════════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'RussianRailGPro';
  src: url('/assets/fonts/RussianRailGPro-Regular.otf') format('opentype');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* ── Theme Presets (1:1 with AppThemeService in Flutter) ────────────────── */

:root,
[data-theme="standard"],
[data-theme="green"] {
  --primary: #2E7D32;
  --primary-hover: #256628;
  --primary-light: #4CAF50;
  --primary-soft: rgba(46, 125, 50, 0.12);
  --primary-container: #C8E6C9;
  --on-primary-container: #0D3B12;
  --secondary-container: #E8F5E9;
  --tonal-bg: #DCEFE0;
  --tonal-fg: #1B5E20;

  --bg-app: #F4F6F8;
  --bg-surface: #FFFFFF;
  --bg-surface-alt: #F0F2F5;
  --bg-hover: rgba(46, 125, 50, 0.06);
  --bg-active: rgba(46, 125, 50, 0.13);
  --bg-chat-canvas: #E8F0E8;

  --text-primary: #1B241E;
  --text-secondary: #5C6B61;
  --text-muted: #8A998E;
  --text-on-primary: #FFFFFF;

  --border: #E0E5E1;
  --border-strong: #C6D1C8;

  --bubble-out-bg: #2E7D32;
  --bubble-out-text: #FFFFFF;
  --bubble-out-meta: rgba(255, 255, 255, 0.78);
  --bubble-in-bg: #FFFFFF;
  --bubble-in-text: #1B241E;
  --bubble-in-meta: #6E7D73;

  --profile-header-start: #E8F5E9;
  --profile-header-end: #C8E6C9;
  --profile-header-text: #1B5E20;

  --danger: #D32F2F;
  --warning: #F57C00;
  --success: #2E7D32;
  --online: #4CAF50;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.07);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.18);
}

[data-theme="gray"] {
  --primary: #3E8B59;
  --primary-hover: #337449;
  --primary-light: #56A873;
  --primary-soft: rgba(62, 139, 89, 0.14);
  --primary-container: #C8E6C9;
  --on-primary-container: #0D3B12;
  --secondary-container: #E0E6E2;
  --tonal-bg: #D5E3DA;
  --tonal-fg: #1B5E20;

  --bg-app: #E6E9ED;
  --bg-surface: #F2F4F7;
  --bg-surface-alt: #DDE1E6;
  --bg-hover: rgba(62, 139, 89, 0.08);
  --bg-active: rgba(62, 139, 89, 0.16);
  --bg-chat-canvas: #DCE1E6;

  --text-primary: #1F2429;
  --text-secondary: #5A626A;
  --text-muted: #828B94;

  --border: #CFD5DC;
  --border-strong: #B8C0C9;

  --bubble-out-bg: #3E8B59;
  --bubble-out-text: #FFFFFF;
  --bubble-out-meta: rgba(255, 255, 255, 0.8);
  --bubble-in-bg: #FFFFFF;
  --bubble-in-text: #1F2429;
  --bubble-in-meta: #68707A;
}

[data-theme="dark"] {
  --primary: #4FA36C;
  --primary-hover: #428E5C;
  --primary-light: #66BB6A;
  --primary-soft: rgba(79, 163, 108, 0.18);
  --primary-container: #1B4D2E;
  --on-primary-container: #C8E6C9;
  --secondary-container: #1B2E22;
  --tonal-bg: #213D2B;
  --tonal-fg: #A5D6A7;

  --bg-app: #0F1210;
  --bg-surface: #171C19;
  --bg-surface-alt: #202722;
  --bg-hover: rgba(79, 163, 108, 0.1);
  --bg-active: rgba(79, 163, 108, 0.22);
  --bg-chat-canvas: #121714;

  --text-primary: #E8F0EA;
  --text-secondary: #9BA99E;
  --text-muted: #6C7A70;

  --border: #263029;
  --border-strong: #344238;

  --bubble-out-bg: #2E6B43;
  --bubble-out-text: #F1F8F3;
  --bubble-out-meta: rgba(241, 248, 243, 0.72);
  --bubble-in-bg: #202722;
  --bubble-in-text: #E8F0EA;
  --bubble-in-meta: #8FA093;

  --profile-header-start: #1B3322;
  --profile-header-end: #142619;
  --profile-header-text: #A5D6A7;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.65);
}

/* ── Reset & Base ───────────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'RussianRailGPro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 11.5px;
  line-height: 1.3;
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

#app-root,
#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button,
input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* ── Vector SVG Icons (Strictly Sized!) ─────────────────────────────────── */

svg.icon-svg,
svg.ui-icon {
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  max-width: 18px;
  max-height: 18px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

svg.icon-svg.sm {
  width: 13px;
  height: 13px;
  min-width: 13px;
  min-height: 13px;
}

svg.icon-svg.lg {
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  max-width: 20px;
  max-height: 20px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(120, 135, 125, 0.32);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 135, 125, 0.52);
}

/* ── Common Buttons & Inputs ────────────────────────────────────────────── */

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 9px;
  background: var(--primary);
  color: #FFFFFF;
  font-weight: 600;
  font-size: 12px;
  transition: background 0.15s;
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 11.5px;
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.tonal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 8px;
  background: var(--tonal-bg);
  color: var(--tonal-fg);
  font-weight: 600;
  font-size: 11.5px;
  transition: filter 0.15s;
}

.tonal-btn:hover {
  filter: brightness(0.96);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label,
.profile-field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.field-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg-surface-alt);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.field-input:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
}

/* ── Avatars (with Initials Always Rendered Underneath Image) ───────────── */

.avatar {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11.5px;
  flex-shrink: 0;
  user-select: none;
  overflow: visible;
}

.avatar > span:not(.online-dot) {
  position: relative;
  z-index: 1;
}

.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  z-index: 2;
}

.avatar.sm {
  width: 28px;
  height: 28px;
  font-size: 10px;
}

.avatar.lg {
  width: 42px;
  height: 42px;
  font-size: 14px;
}

.avatar.xl {
  width: 64px;
  height: 64px;
  font-size: 20px;
}

.avatar.xxl {
  width: 78px;
  height: 78px;
  font-size: 24px;
}

.avatar.favorites {
  background: linear-gradient(135deg, #2E7D32, #4CAF50);
  color: #FFFFFF;
}

.avatar .online-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--online);
  border: 1.5px solid var(--bg-surface);
  z-index: 3;
}

/* ── Auth Screen (1:1 LoginScreen / RegisterScreen / OtpVerifyScreen) ──── */

.auth-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(145deg, var(--secondary-container, #E8F5E9) 0%, var(--bg-app, #ECEFEF) 100%);
  overflow-y: auto;
  box-sizing: border-box;
}

.auth-card {
  width: 100%;
  max-width: 390px;
  background: var(--bg-surface, #FFFFFF);
  border-radius: 24px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.06));
  padding: 34px 28px;
  box-sizing: border-box;
  animation: authCardPop 0.25s cubic-bezier(0.2, 0, 0, 1);
}

@keyframes authCardPop {
  0% { opacity: 0; transform: scale(0.96) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.auth-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 8px rgba(46, 125, 50, 0.15));
}

.auth-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary, #2E7D32);
  margin: 0;
  letter-spacing: 0.5px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-secondary, #666666);
  margin: 4px 0 0 0;
}

/* 2-Segmented Switch */
.auth-switch {
  display: flex;
  background: var(--bg-surface-alt, #F0F2F5);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 22px;
  position: relative;
}

.auth-switch-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 14px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary, #666666);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  outline: none;
}

.auth-switch-btn:hover {
  color: var(--text-primary, #222222);
}

.auth-switch-btn.active {
  background: var(--bg-surface, #FFFFFF);
  color: var(--primary, #2E7D32);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  font-weight: 700;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary, #444444);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.auth-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-input-icon {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--text-muted, #888888);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.auth-input {
  width: 100%;
  height: 48px;
  padding: 0 14px 0 42px;
  border-radius: 12px;
  border: 1.5px solid var(--border, #E0E0E0);
  background: var(--bg-surface-alt, #FAFAFA);
  font-size: 15px;
  color: var(--text-primary, #222222);
  outline: none;
  transition: all 0.2s ease;
  box-sizing: border-box;
  font-family: inherit;
}

.auth-input:focus {
  border-color: var(--primary, #2E7D32);
  background: var(--bg-surface, #FFFFFF);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.auth-input:focus + .auth-input-icon,
.auth-input-wrap:focus-within .auth-input-icon {
  color: var(--primary, #2E7D32);
}

.auth-input.otp {
  padding: 0 14px;
  text-align: center;
  font-size: 24px;
  letter-spacing: 10px;
  font-weight: 700;
  height: 52px;
}

.auth-btn-primary {
  height: 50px;
  background: var(--primary, #2E7D32);
  color: #FFFFFF;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px rgba(46, 125, 50, 0.25);
  font-family: inherit;
  margin-top: 4px;
}

.auth-btn-primary:hover:not(:disabled) {
  background: #256828;
  box-shadow: 0 6px 18px rgba(46, 125, 50, 0.32);
}

.auth-btn-primary:active:not(:disabled) {
  transform: scale(0.99);
}

.auth-btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  box-shadow: none;
}

.auth-info-banner {
  background: var(--primary-container, #E8F5E9);
  border: 1px solid rgba(46, 125, 50, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.auth-info-text {
  font-size: 12px;
  color: var(--primary, #1B5E20);
}

.auth-info-phone {
  font-weight: 700;
  font-size: 13px;
  display: block;
  margin-top: 2px;
  color: var(--text-primary);
}

.auth-change-link {
  background: none;
  border: none;
  color: var(--primary, #2E7D32);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  text-decoration: underline;
}

.auth-resend-btn {
  background: none;
  border: none;
  color: var(--text-secondary, #555555);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  text-align: center;
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.auth-resend-btn:hover:not(:disabled) {
  color: var(--primary, #2E7D32);
}

.auth-resend-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-bottom-toggle {
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-secondary, #666666);
}

.auth-bottom-link {
  background: none;
  border: none;
  color: var(--primary, #2E7D32);
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
}

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: btnSpin 0.7s linear infinite;
  display: inline-block;
}

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

@media (max-width: 480px) {
  .auth-wrapper {
    padding: 16px 12px;
  }
  .auth-card {
    padding: 28px 20px;
    border-radius: 20px;
  }
}

/* ── HomeScreen Shell (1:1 lib/features/home/home_screen.dart) ──────────── */

.app-shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-app);
}

.home-top-appbar {
  height: 44px;
  min-height: 44px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 6px;
  z-index: 30;
  flex-shrink: 0;
}

.home-brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: contain;
  flex-shrink: 0;
}

.home-brand-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.home-brand-title {
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.15px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-brand-subtitle {
  font-size: 9.5px;
  line-height: 1.15;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-appbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* 2x2 _ConnectionMatrixIndicator (1:1 lib/features/home/home_screen.dart:747-950) */
.conn-matrix {
  width: 26px;
  height: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
  cursor: pointer;
}

.conn-matrix-row {
  position: relative;
  width: 22px;
  height: 8px;
}

.conn-lamp {
  position: absolute;
  top: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(158, 158, 158, 0.35);
}

.conn-lamp.left {
  left: 0;
}

.conn-lamp.right {
  right: 0;
}

.conn-lamp.dim {
  background: rgba(158, 158, 158, 0.27);
}

.conn-lamp.idle {
  background: rgba(158, 158, 158, 0.35);
}

.conn-lamp.green {
  background: #4CAF50;
  box-shadow: 0 0 6px 0.6px rgba(76, 175, 80, 0.48);
}

.conn-lamp.red {
  background: #E53935;
  box-shadow: 0 0 6px 0.6px rgba(229, 57, 53, 0.48);
}

.conn-lamp.runner {
  left: 0;
  background: #FFCA28;
  box-shadow: 0 0 6px 0.6px rgba(255, 202, 40, 0.55);
  z-index: 2;
  animation: connLampSlide 720ms cubic-bezier(0.65, 0, 0.35, 1) infinite alternate;
}

@keyframes connLampSlide {
  0% {
    transform: translateX(0px) scale(1.08);
  }
  100% {
    transform: translateX(14px) scale(1.08);
  }
}

.conn-matrix-label {
  display: none;
}

/* Desktop (Windows/Mac/Linux mouse pointer) vs Mobile (Android/iOS touch) */
@media (hover: hover) and (pointer: fine) {
  .mobile-overflow-btn {
    display: none !important;
  }
  .mobile-bottom-nav {
    display: none !important;
  }
}

@media (hover: none), (pointer: coarse) {
  .desktop-hamburger-btn {
    display: none !important;
  }
}

/* ── Desktop Navigation Drawer (_DesktopNavigationDrawer) ───────────────── */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 200;
  display: flex;
}

.desktop-drawer {
  width: 265px;
  max-width: 82vw;
  height: 100%;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--profile-header-start), var(--profile-header-end));
  color: var(--profile-header-text);
}

.drawer-header-info {
  min-width: 0;
  flex: 1;
}

.drawer-header-title {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-header-sub {
  font-size: 11px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.drawer-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  transition: background 0.14s;
}

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

.drawer-item.active {
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 700;
}

.drawer-divider {
  height: 1px;
  background: var(--border);
  margin: 5px 4px;
}

.drawer-section-label {
  padding: 4px 10px 3px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Main Workspace & Split View ────────────────────────────────────────── */

.workspace {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  overflow: hidden;
  position: relative;
}

.full-tab-page {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg-surface);
}

.chats-split-layout {
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;
}

.chats-sidebar-pane {
  width: 350px;
  min-width: 260px;
  max-width: 650px;
  height: 100%;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  flex-shrink: 0;
}

.chats-sidebar-resizer {
  width: 10px;
  margin-left: -5px;
  margin-right: -5px;
  height: 100%;
  cursor: col-resize;
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: none;
  background: transparent;
  flex-shrink: 0;
}

.chats-resizer-line {
  width: 2px;
  height: 100%;
  background: transparent;
  transition: background 0.15s ease;
  pointer-events: none;
}

.chats-sidebar-resizer:hover .chats-resizer-line,
.chats-sidebar-resizer.active .chats-resizer-line,
body.is-resizing-sidebar .chats-resizer-line {
  background: var(--primary, #2E7D32);
}

body.is-resizing-sidebar {
  cursor: col-resize !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

body.is-resizing-sidebar * {
  cursor: col-resize !important;
  user-select: none !important;
}

.chat-room-pane {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat-canvas);
  position: relative;
  overflow: hidden;
}

@media (max-width: 749px) {
  .chats-sidebar-pane {
    width: 100% !important;
    max-width: 100% !important;
    border-right: none;
  }
  .chats-sidebar-resizer {
    display: none !important;
  }
  .chat-room-pane {
    display: none;
  }
  .chats-split-layout.mobile-chat-open .chats-sidebar-pane {
    display: none;
  }
  .chats-split-layout.mobile-chat-open .chat-room-pane {
    display: flex;
    width: 100%;
  }
}

.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.chat-placeholder-pill {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

/* ── Search, Folder Chips, Chat List & FABs ─────────────────────────────── */

.search-bar-wrap {
  padding: 5px 8px 3px;
  flex-shrink: 0;
}

.search-pill {
  height: 30px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.search-pill:focus-within {
  border-color: var(--primary);
  background: var(--bg-surface);
}

.search-pill input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  color: var(--text-primary);
  font-size: 11.5px;
  min-width: 0;
}

.folder-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 5px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  scrollbar-width: none;
}

.folder-bar::-webkit-scrollbar {
  display: none;
}

.folder-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.folder-chip.active {
  background: var(--primary-container);
  border-color: transparent;
  color: var(--on-primary-container);
}

.folder-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.chat-date-section {
  padding: 8px 12px 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--bg-surface);
}

.chat-tile {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.chat-tile.pinned {
  background: rgba(46, 125, 50, 0.03);
}

.chat-tile.bot-chat {
  background: rgba(255, 193, 7, 0.055);
}

.chat-tile:hover {
  background: var(--bg-hover);
}

.chat-tile.active {
  background: var(--bg-active);
}

.chat-tile-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-tile-top,
.chat-tile-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.chat-tile-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-tile-time {
  font-size: 9.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-tile-preview {
  font-size: 10.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.draft-tag {
  color: var(--danger);
  font-weight: 600;
}

.unread-badge {
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--primary);
  color: #FFFFFF;
  font-size: 9.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.unread-badge.muted {
  background: var(--text-muted);
}

.fab-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--primary);
  color: #FFFFFF;
  box-shadow: var(--shadow-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.fab-extended {
  position: absolute;
  right: 14px;
  bottom: 14px;
  height: 36px;
  padding: 0 12px;
  border-radius: 11px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 700;
  font-size: 11.5px;
  box-shadow: var(--shadow-md);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  z-index: 20;
}

/* ── ChatRoomScreen ─────────────────────────────────────────────────────── */

.chat-room-header {
  height: 50px;
  min-height: 50px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
  flex-shrink: 0;
}

@media (min-width: 750px) {
  .mobile-back-btn {
    display: none !important;
  }
}

.chat-room-peer {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.chat-room-peer-info {
  min-width: 0;
  flex: 1;
}

.chat-room-peer-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-peer-sub {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-peer-sub.online {
  color: var(--primary);
  font-weight: 600;
}

.chat-room-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.pinned-banner {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
  flex-shrink: 0;
  min-height: 44px;
  box-sizing: border-box;
}

.pinned-banner-indicator {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 3px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 2px;
  overflow: hidden;
}

.pinned-seg {
  flex: 1;
  background: var(--primary);
  opacity: 0.28;
  border-radius: 1px;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.pinned-seg.active {
  opacity: 1;
}

.pinned-banner-thumb {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.08);
}

.pinned-banner-body {
  min-width: 0;
  flex: 1;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  user-select: none;
}

.pinned-banner-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.pinned-banner-counter {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.72;
  color: var(--text-secondary);
}

.pinned-banner-text {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.pinned-banner-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.pinned-banner-actions .icon-btn {
  width: 28px;
  height: 28px;
  color: var(--text-secondary);
}
.pinned-banner-actions .icon-btn:hover {
  color: var(--text-primary);
}

/* Модальное окно всех закреплённых сообщений */
.pinned-modal-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
  padding: 8px 12px;
}

.pinned-modal-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-surface-alt, rgba(0, 0, 0, 0.04));
  cursor: pointer;
  transition: background 0.15s ease;
}

.pinned-modal-item:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.08));
}

.pinned-modal-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.pinned-modal-content {
  min-width: 0;
  flex: 1;
}

.pinned-modal-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.pinned-modal-sender {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
}

.pinned-modal-time {
  font-size: 10px;
  color: var(--text-muted);
}

.pinned-modal-text {
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chat-scroll-bottom-btn {
  position: absolute;
  right: 16px;
  bottom: 64px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-surface);
  color: var(--primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 25;
  transition: transform 0.15s ease, background 0.15s ease;
}

.chat-scroll-bottom-btn.visible {
  display: inline-flex;
}

.chat-scroll-bottom-btn:hover {
  background: var(--bg-surface-alt);
  transform: translateY(-1px);
}

/* Подсветка всей строки и сообщения при переходе (закрепление, ответ, поиск) */
.msg-row.highlighted-pulse {
  position: relative;
}

.msg-row.highlighted-pulse::before {
  content: '';
  position: absolute;
  left: -24px;
  right: -24px;
  top: -4px;
  bottom: -4px;
  pointer-events: none;
  z-index: 0;
  animation: rowFullWidthHighlight 3.5s cubic-bezier(0.2, 0, 0, 1) forwards;
}

@keyframes rowFullWidthHighlight {
  0% {
    background-color: rgba(46, 125, 50, 0.35);
  }
  30% {
    background-color: rgba(46, 125, 50, 0.35);
  }
  65% {
    background-color: rgba(46, 125, 50, 0.16);
  }
  100% {
    background-color: transparent;
  }
}

.msg-bubble.highlighted-pulse {
  position: relative;
  outline: none;
  z-index: 1;
}

.msg-bubble.highlighted-pulse::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 2;
  animation: msgBubbleHighlightIn 3.5s cubic-bezier(0.2, 0, 0, 1) forwards;
}

.msg-row.outgoing .msg-bubble.highlighted-pulse::after {
  animation-name: msgBubbleHighlightOut;
}

@keyframes msgBubbleHighlightIn {
  0% {
    background-color: rgba(46, 125, 50, 0.28);
    box-shadow: 0 0 16px rgba(46, 125, 50, 0.28);
  }
  30% {
    background-color: rgba(46, 125, 50, 0.22);
    box-shadow: 0 0 12px rgba(46, 125, 50, 0.2);
  }
  100% {
    background-color: transparent;
    box-shadow: none;
  }
}

@keyframes msgBubbleHighlightOut {
  0% {
    background-color: rgba(255, 255, 255, 0.45);
    box-shadow: 0 0 18px rgba(255, 255, 255, 0.45);
  }
  30% {
    background-color: rgba(255, 255, 255, 0.35);
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
  }
  100% {
    background-color: transparent;
    box-shadow: none;
  }
}

.messages-viewport {
  overscroll-behavior: contain;
  overflow-anchor: auto;
}

/* Скелетон загрузки переписки (вместо «пустого» состояния) */
.msg-skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 0;
  margin-top: auto;
}

.msg-skel {
  height: 34px;
  border-radius: 14px;
  background: linear-gradient(
    90deg,
    var(--bubble-in-bg) 0%,
    var(--bg-surface-alt) 50%,
    var(--bubble-in-bg) 100%
  );
  background-size: 200% 100%;
  animation: msgSkelShimmer 1.3s ease-in-out infinite;
  opacity: 0.85;
}

.msg-skel.in {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg-skel.out {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

@keyframes msgSkelShimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.date-separator {
  display: flex;
  justify-content: center;
  margin: 6px 0;
}

.date-separator span {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.36);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 600;
}

.msg-row {
  display: flex;
  width: 100%;
}

.msg-row.outgoing {
  justify-content: flex-end;
}

.msg-row.incoming {
  justify-content: flex-start;
}

.msg-row.system {
  justify-content: center;
}

.msg-system-pill {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: #FFFFFF;
  font-size: 11px;
}

.msg-bubble {
  max-width: min(76%, 500px);
  padding: 6px 10px;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-row.outgoing .msg-bubble {
  background: var(--bubble-out-bg);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
}

.msg-row.incoming .msg-bubble {
  background: var(--bubble-in-bg);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 4px;
}

.msg-sender-name {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}

.msg-reply-quote {
  border-left: 3px solid currentColor;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  padding: 3px 7px;
  margin-bottom: 4px;
  font-size: 11.5px;
}

.quote-author {
  font-weight: 700;
}

.quote-text {
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-attachments {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 4px;
}

.msg-image-wrap img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}

.msg-video-wrap video {
  max-width: 100%;
  max-height: 240px;
  border-radius: 8px;
}

.msg-audio-card {
  display: flex;
  align-items: center;
  gap: 6px;
}

.msg-audio-card audio {
  height: 32px;
  max-width: 210px;
}

.msg-file-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.1);
  color: inherit;
  text-decoration: none;
}

.msg-file-info {
  flex: 1;
  min-width: 0;
}

.msg-file-name {
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-file-size {
  font-size: 10.5px;
  opacity: 0.8;
}

.msg-text {
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.msg-text a {
  color: inherit;
  text-decoration: underline;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 10px;
  margin-top: 2px;
  opacity: 0.82;
}

.msg-Meta svg,
.read-icon svg {
  width: 13px;
  height: 13px;
}

/* Composer */
.composer-reply-bar {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
}

.reply-bar-body {
  flex: 1;
  min-width: 0;
}

.reply-bar-title {
  font-size: 11.5px;
  font-weight: 700;
}

.reply-bar-text {
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-bar {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.composer-input-wrap {
  flex: 1;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
}

.composer-textarea {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  max-height: 96px;
  font-size: 13px;
  line-height: 1.35;
}

.composer-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.voice-rec-indicator {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  color: var(--danger);
  font-weight: 600;
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

/* ── Contacts, Telephony, Calls, Profile Tabs ───────────────────────────── */

.contacts-section-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.section-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.section-count {
  color: var(--text-secondary);
  font-weight: 600;
}

.section-chevron {
  margin-left: auto;
  transition: transform 0.15s;
}

.section-chevron:not(.expanded) {
  transform: rotate(-90deg);
}

.alpha-letter-divider {
  padding: 3px 12px;
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
}

.alpha-strip {
  position: absolute;
  right: 3px;
  top: 60px;
  bottom: 70px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 1px;
  z-index: 15;
  box-shadow: var(--shadow-sm);
}

.alpha-strip-btn {
  font-size: 9px;
  font-weight: 700;
  color: var(--primary);
  padding: 1.5px 3px;
  line-height: 1.15;
  border-radius: 4px;
  transition: background 0.12s, color 0.12s;
}

.alpha-strip-btn:hover {
  background: var(--primary-soft);
}

.alpha-strip-btn.active {
  background: var(--primary);
  color: #fff;
}

.alpha-strip-btn.reset {
  color: var(--danger);
  font-size: 11px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1px;
}

.alpha-filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11.5px;
}

.alpha-filter-clear-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 6px;
}

.alpha-filter-clear-btn:hover {
  background: rgba(46, 125, 50, 0.12);
}

.contact-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.contacts-list-with-strip .contact-tile,
.contacts-list-with-strip .section-header {
  padding-right: 28px;
}

.contact-tile:hover {
  background: var(--bg-hover);
}

.contact-tile-body {
  flex: 1;
  min-width: 0;
}

.contact-tile-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-tile-sub {
  font-size: 10.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-tile-sub.online {
  color: var(--primary);
  font-weight: 600;
}

.contact-tile-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.contact-action-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.contact-action-icon:hover {
  background: var(--primary-soft);
}

.telephony-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

/* Segmented Control (CallHistoryScreen & SettingsScreen) */
.segmented-control {
  display: flex;
  margin: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-surface-alt);
}

.segment-btn {
  flex: 1;
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.segment-btn.active {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.call-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.call-tile:hover {
  background: var(--bg-hover);
}

.call-status-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--primary-soft);
  color: var(--primary);
}

.call-status-circle.missed,
.call-status-circle.declined {
  background: rgba(211, 47, 47, 0.12);
  color: var(--danger);
}

.call-tile-body {
  flex: 1;
  min-width: 0;
}

.call-tile-title {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-tile-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-tile-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ProfileScreen */
.profile-page-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.profile-page-card {
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-avatar-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-bottom: 2px;
}

.profile-avatar-wrap {
  position: relative;
  display: inline-flex;
}

.profile-camera-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #FFFFFF;
  border: 2px solid var(--bg-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
}

.profile-hero-name {
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
  line-height: 1.2;
}

.profile-hero-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--primary);
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
}

.profile-form-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.profile-field-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.profile-inline-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.profile-inline-row .field-input {
  flex: 1;
  min-width: 0;
}

.profile-save-btn {
  width: auto !important;
  flex-shrink: 0;
  padding: 6px 12px !important;
  font-size: 11.5px !important;
  height: 32px;
}

.profile-phone-caption {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Mobile Bottom NavigationBar (< 750px) ──────────────────────────────── */

.mobile-bottom-nav {
  height: 50px;
  min-height: 50px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  z-index: 30;
  flex-shrink: 0;
}

.mobile-bottom-nav.hidden-on-chat {
  display: none !important;
}

.mobile-nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 1px;
  color: var(--text-secondary);
  font-size: 9.5px;
  font-weight: 500;
}

.mobile-nav-item.active {
  color: var(--primary);
  font-weight: 700;
}

.nav-badge {
  position: absolute;
  top: 1px;
  right: calc(50% - 17px);
  min-width: 14px;
  height: 14px;
  padding: 0 3.5px;
  border-radius: 999px;
  background: var(--primary);
  color: #FFFFFF;
  font-size: 9px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Modals, ContactProfileScreen, GroupInfoScreen, SettingsScreen ──────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 17, 0.48);
  backdrop-filter: blur(2px);
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  max-height: 82vh;
  background: var(--bg-surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-toolbar {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-surface);
  flex-shrink: 0;
}

.modal-toolbar-sub {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-alt);
}

.modal-quick-row {
  display: flex;
  gap: 6px;
}

.modal-channel-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 2px;
}

.modal-channel-toggle input {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
}

.selected-chips-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 64px;
  overflow-y: auto;
}

.selected-member-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-size: 10.5px;
  font-weight: 600;
}

.modal-list-scroll {
  flex: 1;
  min-height: 120px;
  max-height: 54vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.modal-list-row:last-child {
  border-bottom: none;
}

.modal-list-row:hover {
  background: var(--bg-hover);
}

.modal-list-row.selected {
  background: var(--primary-soft);
}

.modal-check-box {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #FFFFFF;
}

.modal-check-box.checked {
  background: var(--primary);
  border-color: var(--primary);
}

.modal-empty-state {
  padding: 24px 14px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.folder-color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: transform 0.12s, box-shadow 0.12s;
}

.folder-color-swatch.active {
  transform: scale(1.15);
  border-color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.modal-body {
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.profile-dialog-header {
  background: linear-gradient(135deg, var(--profile-header-start), var(--profile-header-end));
  color: var(--profile-header-text);
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex-shrink: 0;
}

.profile-dialog-top-row {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}

.profile-close-btn {
  color: rgba(255, 255, 255, 0.9) !important;
}

.profile-close-btn:hover {
  background: rgba(255, 255, 255, 0.16) !important;
  color: #FFFFFF !important;
}

.profile-dialog-name {
  font-size: 14.5px;
  font-weight: 700;
  margin-top: 6px;
}

.profile-dialog-status {
  font-size: 11px;
  opacity: 0.88;
  margin-top: 1px;
}

.profile-quick-actions {
  display: flex;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
}

.profile-quick-action-btn {
  flex: 1;
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: 9px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.profile-quick-action-btn:hover {
  background: var(--bg-hover);
}

.profile-dialog-body {
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-app);
  flex: 1;
}

.profile-info-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.profile-card-section-title,
.settings-section-title {
  padding: 7px 10px 3px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
}

.profile-info-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}

.profile-info-row:last-child {
  border-bottom: none;
}

.info-icon,
.media-icon {
  color: var(--primary);
  display: inline-flex;
  flex-shrink: 0;
}

.info-content {
  flex: 1;
  min-width: 0;
}

.info-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-label {
  font-size: 10.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-media-counter-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.profile-media-counter-row:last-child {
  border-bottom: none;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: var(--bg-hover);
}

.media-label {
  flex: 1;
  font-size: 11.5px;
}

.media-count {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
}

.media-chevron {
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
}

.shared-media-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-alt);
  overflow-x: auto;
}

.shared-media-tab-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.shared-media-tab-btn.active {
  background: var(--primary);
  color: #FFFFFF;
}

.shared-media-tab-badge {
  font-size: 10px;
  opacity: 0.85;
}

.shared-media-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.shared-media-photo-cell {
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-surface-alt);
  cursor: pointer;
  border: 1px solid var(--border);
}

.shared-media-photo-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.15s;
}

.shared-media-photo-cell:hover img {
  transform: scale(1.04);
}

.shared-media-list-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  margin-bottom: 6px;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shared-media-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.shared-media-video-player {
  width: 100%;
  max-height: 200px;
  border-radius: 6px;
  background: #000;
}

.shared-media-audio-player {
  width: 100%;
  height: 32px;
}

.role-badge {
  font-size: 9.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.switch-row:last-child {
  border-bottom: none;
}

.switch-title {
  font-weight: 600;
  font-size: 12px;
}

.switch-sub {
  font-size: 10.5px;
  color: var(--text-secondary);
}

.switch-toggle {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  flex-shrink: 0;
}

.switch-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #FFFFFF;
  transition: transform 0.16s;
}

.switch-toggle.on {
  background: var(--primary);
}

.switch-toggle.on::after {
  transform: translateX(16px);
}

/* ── Context Menu, Lightbox & Toast ─────────────────────────────────────── */

.context-menu {
  position: fixed;
  z-index: 400;
  min-width: 185px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: flex;
  flex-direction: column;
}

.context-menu.composer-attach-menu {
  border-radius: 12px;
  padding: 6px;
  min-width: 195px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.16), 0 0 0 1px var(--border);
  animation: attachMenuPop 0.14s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom left;
}

.context-menu.composer-attach-menu .context-menu-item {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  gap: 10px;
}

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

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
}

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

.context-menu-item.danger {
  color: var(--danger);
}

.context-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox-top {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
}

.lightbox-top .icon-btn {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.14);
}

.lightbox-overlay img {
  max-width: 92vw;
  max-height: 84vh;
  border-radius: 8px;
  object-fit: contain;
}

#toast-root {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.toast-item {
  background: #1B241E;
  color: #FFFFFF;
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

.toast-item.error {
  background: var(--danger);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Расширенные функции чата: реакции, пересылка, выбор, медиа, голос, кружки
   ═══════════════════════════════════════════════════════════════════════════ */

.icon-btn.danger { color: var(--danger); }

.msg-bubble { position: relative; }
.msg-row { align-items: flex-end; gap: 6px; }
.msg-row .msg-bubble { min-width: 0; }
.msg-bubble.pending { opacity: 0.9; }

/* Выбор сообщений */
.msg-select-check {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--text-secondary); background: var(--bg-surface);
  flex-shrink: 0; align-self: center; display: inline-flex;
  align-items: center; justify-content: center; color: transparent;
}
.msg-select-check.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.msg-select-check.ghost { border-color: transparent; background: transparent; }
.msg-row.outgoing .msg-select-check { order: 2; }
.msg-row.selecting { cursor: pointer; }
.msg-row.selected { background: rgba(46, 125, 50, 0.14); border-radius: 10px; }
.msg-row.selecting .msg-bubble * { pointer-events: none; }
.selection-header { background: var(--primary-soft, var(--bg-surface)); }
.sel-count { flex: 1; font-weight: 700; font-size: 13.5px; color: var(--text-primary); }

/* Кнопка «действия» на пузыре */
.msg-more-btn {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px;
  border-radius: 50%; display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.28); color: #fff; z-index: 3;
}
.msg-bubble:hover .msg-more-btn { display: inline-flex; }
@media (hover: none) { .msg-more-btn { display: none !important; } }

/* Удалённое */
.msg-bubble.deleted { opacity: 0.85; }
.msg-deleted { display: flex; align-items: center; gap: 6px; font-style: italic; font-size: 12.5px; opacity: 0.85; }

/* Пересланное и ответ */
.msg-forwarded {
  display: flex; align-items: center; gap: 5px; font-size: 11.5px;
  font-weight: 600; margin-bottom: 3px; color: var(--primary);
}
.msg-row.outgoing .msg-forwarded { color: rgba(255, 255, 255, 0.92); }
.msg-reply-quote { display: flex; gap: 7px; align-items: stretch; cursor: pointer; }
.msg-reply-quote .quote-body { min-width: 0; flex: 1; }
.quote-thumb { width: 34px; height: 34px; border-radius: 5px; object-fit: cover; flex-shrink: 0; }
.msg-star { display: inline-flex; color: #FFB300; }
.msg-star svg { fill: currentColor; }

/* Реакции */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.msg-react-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 999px; font-size: 12px; line-height: 1.3;
  background: rgba(0, 0, 0, 0.08); color: inherit; border: 1px solid transparent;
}
.msg-row.outgoing .msg-react-chip { background: rgba(255, 255, 255, 0.2); }
.msg-react-chip.mine { border-color: currentColor; background: rgba(46, 125, 50, 0.16); font-weight: 700; }
.msg-row.outgoing .msg-react-chip.mine { background: rgba(255, 255, 255, 0.34); }
.msg-react-count { font-size: 11px; font-weight: 600; }

/* Меню сообщения */
.message-menu { min-width: 230px; max-width: 280px; padding: 6px; }
.msg-menu-reactions, .msg-menu-reactions-all { display: flex; flex-wrap: wrap; gap: 2px; padding: 2px 2px 6px; }
.msg-menu-reactions-all { border-top: 1px solid var(--border); padding-top: 6px; max-height: 150px; overflow-y: auto; }
.msg-menu-reactions-all[hidden] { display: none; }
.msg-menu-react {
  width: 32px; height: 32px; border-radius: 50%; font-size: 18px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.msg-menu-react:hover { background: var(--bg-hover); transform: scale(1.12); }
.msg-menu-react.active { background: var(--primary-soft, rgba(46, 125, 50, 0.16)); }
.msg-menu-react.more { color: var(--text-secondary); background: var(--bg-surface-alt); }

/* Сетка фото/видео (1:1 Android & Desktop Telegram) */
.msg-attachments {
  max-width: 100%;
}

/* Медиа-сообщения (has-media) — оформлены как единый пузырь (как на Android и ПК) */
.msg-bubble.has-media {
  padding: 6px 6px 4px 6px;
  width: fit-content;
  min-width: 90px;
  max-width: min(76vw, 360px);
  box-sizing: border-box;
}

@media (min-width: 768px) {
  .msg-bubble.has-media {
    max-width: min(420px, 46vw);
  }
}

.msg-bubble.has-media.has-caption {
  max-width: min(76vw, 420px);
}

@media (min-width: 768px) {
  .msg-bubble.has-media.has-caption {
    max-width: min(500px, 46vw);
  }
}

.msg-bubble.has-media .msg-sender-name,
.msg-bubble.has-media .msg-forwarded,
.msg-bubble.has-media .msg-reply-quote {
  margin: 2px 4px 6px 4px;
  max-width: 100%;
  box-sizing: border-box;
}

.msg-bubble.has-media .msg-text {
  margin-top: 6px;
  padding: 0 4px;
}

.msg-bubble.has-media .msg-reactions {
  margin-top: 5px;
  padding: 0 4px;
}

.msg-bubble.has-media .msg-meta {
  margin-top: 3px;
  padding: 0 2px 1px 2px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 10px;
  line-height: 1.2;
}

.msg-row.outgoing .msg-bubble.has-media .msg-meta {
  color: var(--bubble-out-text, #ffffff);
}
.msg-row.outgoing .msg-bubble.has-media .msg-meta svg,
.msg-row.outgoing .msg-bubble.has-media .read-icon svg {
  color: currentColor;
  stroke: currentColor;
  fill: none;
}

/* Сетка и плитки */
.msg-media-grid {
  display: block;
  position: relative;
  width: fit-content;
  max-width: 100%;
  border-radius: 8px;
  overflow: hidden;
}

.mg-tile {
  position: relative;
  border-radius: inherit;
  overflow: hidden;
}

/* Одиночное фото/видео (mg-1) */
.msg-media-grid.mg-1 {
  display: block;
  width: fit-content;
  max-width: 100%;
  border-radius: 8px;
}

.msg-media-grid.mg-1 .mg-tile {
  display: block;
  position: relative;
  width: fit-content;
  max-width: min(72vw, 348px);
  max-height: min(65vh, 460px);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.05);
  cursor: zoom-in;
}

@media (min-width: 768px) {
  .msg-media-grid.mg-1 .mg-tile {
    max-width: min(408px, 45vw);
    max-height: 500px;
  }
  .msg-media-grid.mg-1 .mg-tile.is-portrait {
    max-width: min(320px, 35vw);
  }
}

.msg-media-grid.mg-1 .mg-tile img,
.msg-media-grid.mg-1 .mg-tile video {
  display: block;
  width: auto;
  height: auto;
  max-width: min(72vw, 348px);
  max-height: min(65vh, 460px);
  object-fit: contain;
  border-radius: 8px;
}

@media (min-width: 768px) {
  .msg-media-grid.mg-1 .mg-tile img,
  .msg-media-grid.mg-1 .mg-tile video {
    max-width: min(408px, 45vw);
    max-height: 500px;
  }
  .msg-media-grid.mg-1 .mg-tile.is-portrait img,
  .msg-media-grid.mg-1 .mg-tile.is-portrait video {
    max-width: min(320px, 35vw);
  }
}


/* 2 фото */
.msg-media-grid.mg-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  width: min(76vw, 360px);
  border-radius: inherit;
  overflow: hidden;
}
@media (min-width: 768px) {
  .msg-media-grid.mg-2 {
    width: min(420px, 46vw);
  }
}
.msg-media-grid.mg-2 .mg-tile {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.07);
  cursor: zoom-in;
}

/* 3 фото (1 большое слева, 2 колонкой справа — как во Flutter и Telegram) */
.msg-media-grid.mg-3 {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 3px;
  width: min(76vw, 360px);
  height: 220px;
  border-radius: inherit;
  overflow: hidden;
}
@media (min-width: 768px) {
  .msg-media-grid.mg-3 {
    width: min(420px, 46vw);
    height: 240px;
  }
}
.msg-media-grid.mg-3 .mg-tile {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.07);
  cursor: zoom-in;
}
.msg-media-grid.mg-3 .mg-tile:nth-child(1) {
  grid-row: 1 / span 2;
  grid-column: 1;
}
.msg-media-grid.mg-3 .mg-tile:nth-child(2) {
  grid-row: 1;
  grid-column: 2;
}
.msg-media-grid.mg-3 .mg-tile:nth-child(3) {
  grid-row: 2;
  grid-column: 2;
}

/* 4 фото (2х2 сетка) */
.msg-media-grid.mg-4 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 3px;
  width: min(76vw, 360px);
  border-radius: inherit;
  overflow: hidden;
}
@media (min-width: 768px) {
  .msg-media-grid.mg-4 {
    width: min(420px, 46vw);
  }
}
.msg-media-grid.mg-4 .mg-tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.07);
  cursor: zoom-in;
}

/* 5+ фото */
.msg-media-grid.mg-5 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  width: min(76vw, 360px);
  border-radius: inherit;
  overflow: hidden;
}
@media (min-width: 768px) {
  .msg-media-grid.mg-5 {
    width: min(420px, 46vw);
  }
}
.msg-media-grid.mg-5 .mg-tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.07);
  cursor: zoom-in;
}

/* Картинки и видео внутри мультиплиток */
.msg-media-grid.mg-2 .mg-tile img,
.msg-media-grid.mg-2 .mg-tile video,
.msg-media-grid.mg-3 .mg-tile img,
.msg-media-grid.mg-3 .mg-tile video,
.msg-media-grid.mg-4 .mg-tile img,
.msg-media-grid.mg-4 .mg-tile video,
.msg-media-grid.mg-5 .mg-tile img,
.msg-media-grid.mg-5 .mg-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Видео значок плей и длительность */
.mg-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.48);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.mg-video-dur {
  position: absolute;
  left: 6px;
  top: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* Кнопка действий для медиа-сообщений */
.msg-bubble.has-media .msg-more-btn {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #ffffff;
  z-index: 3;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.msg-bubble.has-media:hover .msg-more-btn {
  display: inline-flex;
}

/* Прогресс загрузки поверх медиа */
.mg-upload-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  border-radius: 0;
  margin: 0;
  z-index: 3;
  background: rgba(0, 0, 0, 0.28);
}
.upload-progress { height: 3px; border-radius: 2px; background: rgba(0, 0, 0, 0.18); overflow: hidden; margin-top: 4px; }
.upload-progress-fill { height: 100%; background: #fff; width: 0; transition: width 0.15s linear; }
.msg-row.incoming .upload-progress-fill { background: var(--primary); }

/* Голосовое сообщение */
.voice-msg { display: flex; align-items: center; gap: 9px; min-width: 230px; max-width: 290px; padding: 2px 0; }
.voice-play-btn {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff;
}
.msg-row.outgoing .voice-play-btn { background: rgba(255, 255, 255, 0.24); }
.voice-wave-wrap { position: relative; flex: 1; height: 28px; cursor: pointer; min-width: 90px; }
.voice-wave {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; gap: 2px;
  color: currentColor; opacity: 0.38;
}
.voice-wave i { display: block; width: 3px; border-radius: 2px; background: currentColor; flex: 1; max-width: 3px; }
.voice-wave.fill { opacity: 1; color: var(--primary); clip-path: inset(0 calc(100% - var(--p, 0%)) 0 0); }
.msg-row.outgoing .voice-wave.fill { color: #fff; }
.voice-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 36px; }
.voice-dur { font-size: 11px; font-variant-numeric: tabular-nums; opacity: 0.9; }
.voice-speed {
  font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.12); color: inherit;
}
.audio-file { display: flex; flex-direction: column; gap: 4px; }
.audio-file-name { display: flex; gap: 5px; align-items: center; font-size: 12px; font-weight: 600; }
.audio-file audio { height: 32px; max-width: 240px; }

/* Видеокружок в сообщении */
.msg-bubble.circle-bubble { background: transparent !important; box-shadow: none; padding: 0; }
.msg-bubble.circle-bubble .msg-meta {
  position: static; display: inline-flex; align-self: flex-end; padding: 1px 8px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.4); color: #fff; opacity: 1; margin-top: 3px;
}
.msg-bubble.circle-bubble { display: flex; flex-direction: column; align-items: flex-end; }
.vcircle { position: relative; width: 210px; height: 210px; border-radius: 50%; cursor: pointer; flex-shrink: 0; }
.vcircle video { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #1b1f1c; display: block; }
.vcircle-ring { position: absolute; inset: -3px; width: calc(100% + 6px); height: calc(100% + 6px); transform: rotate(-90deg); pointer-events: none; }
.vcircle-ring .prog { fill: none; stroke: var(--primary); stroke-width: 2.6; stroke-linecap: butt; }
.vcircle-overlay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 48px; height: 48px; border-radius: 50%; background: rgba(0, 0, 0, 0.45); color: #fff;
  display: flex; align-items: center; justify-content: center; pointer-events: none; transition: opacity 0.15s;
}
.vcircle.playing .vcircle-overlay { opacity: 0; }
.vcircle-time {
  position: absolute; left: 10px; bottom: 10px; font-size: 11px; padding: 1px 7px;
  border-radius: 999px; background: rgba(0, 0, 0, 0.5); color: #fff; font-variant-numeric: tabular-nums;
}
.vcircle-time:empty { display: none; }

/* Опросы и задачи */
.msg-poll-hint, .msg-poll-total { font-size: 10.5px; opacity: 0.75; margin: 2px 0; }
.msg-poll-opt.mine .msg-poll-fill { background: var(--primary); }
.msg-poll-opt { cursor: pointer; padding: 3px 0; }
.msg-task { border-left: 3px solid var(--primary); padding: 3px 8px; margin: 3px 0; font-size: 12px; }
.msg-task-title { display: flex; align-items: center; gap: 5px; font-weight: 700; }
.msg-task-status { font-size: 10.5px; opacity: 0.8; }

/* Композер */
.composer-bar[data-has-text="0"] .send-only { display: none; }
.composer-bar[data-has-text="1"] .rec-only { display: none; }
.composer-bar.readonly { justify-content: center; align-items: center; color: var(--text-secondary); font-size: 12px; padding: 12px; }
.composer-bar.recording { align-items: center; }
.voice-rec-indicator .rec-dot { animation: recPulse 1s ease-in-out infinite; }
.voice-rec-indicator.paused .rec-dot { animation: none; opacity: 0.4; }
.voice-rec-indicator .rec-label { font-weight: 500; font-size: 12px; color: var(--text-secondary); }
#voice-rec-timer { font-variant-numeric: tabular-nums; }
@keyframes recPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.chat-room-pane.drag-over::after {
  content: 'Отпустите файлы, чтобы отправить'; position: absolute; inset: 8px; z-index: 40;
  border: 2px dashed var(--primary); border-radius: 14px; background: rgba(46, 125, 50, 0.12);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--primary);
  pointer-events: none;
}

/* Удаление, опрос, предпросмотр вложений */
.del-everyone-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12.5px; color: var(--text-primary); cursor: pointer; }
.del-everyone-row.disabled { opacity: 0.5; cursor: not-allowed; }
.attach-preview-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px;
  padding: 12px; max-height: 300px; overflow-y: auto;
}
.ap-item { position: relative; }
.ap-thumb { aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg-surface-alt); position: relative; }
.ap-thumb img, .ap-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ap-play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; text-shadow: 0 0 6px rgba(0, 0, 0, 0.6); }
.ap-file { width: 100%; height: 100%; padding: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; color: var(--text-secondary); }
.ap-file span { font-size: 10.5px; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ap-file small { font-size: 10px; }
.ap-remove { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0, 0, 0, 0.55); color: #fff; display: flex; align-items: center; justify-content: center; }
.attach-preview-caption { padding: 0 12px 10px; }
.attach-preview-caption textarea {
  width: 100%; resize: none; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  background: var(--bg-surface-alt); color: var(--text-primary); font: inherit; font-size: 13px; outline: none;
}
.attach-preview-caption textarea:focus { border-color: var(--primary); }

/* Просмотр фото и видео */
.mv-overlay { position: fixed; inset: 0; z-index: 900; background: rgba(8, 10, 9, 0.94); display: flex; flex-direction: column; color: #fff; }
.mv-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; z-index: 3; background: linear-gradient(rgba(0, 0, 0, 0.55), transparent); }
.mv-title-main { font-weight: 700; font-size: 13.5px; }
.mv-title-sub { font-size: 11px; opacity: 0.75; }
.mv-actions { display: flex; gap: 2px; }
.mv-btn { color: #fff; }
.mv-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.mv-media { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; transition: transform 0.18s ease; cursor: zoom-in; }
.mv-media.zoomed { transform: scale(2.2); cursor: zoom-out; }
video.mv-media { cursor: default; }
.mv-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.16); color: #fff; z-index: 3; display: flex; align-items: center; justify-content: center;
}
.mv-nav:hover { background: rgba(255, 255, 255, 0.28); }
.mv-prev { left: 12px; }
.mv-next { right: 12px; }
.mv-counter { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 12px; padding: 2px 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.5); }
.mv-counter:empty { display: none; }

/* Запись видеокружка */
.vc-overlay { position: fixed; inset: 0; z-index: 900; background: rgba(8, 10, 9, 0.92); display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 16px 16px 28px; color: #fff; }
.vc-close { align-self: flex-end; color: #fff; }
.vc-stage { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.vc-circle { position: relative; width: min(72vw, 300px); height: min(72vw, 300px); border-radius: 50%; }
.vc-circle video { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #111; display: block; }
.vc-circle video.mirror { transform: scaleX(-1); }
.vc-ring { position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px); transform: rotate(-90deg); pointer-events: none; }
.vc-ring circle { fill: none; stroke-width: 2.2; }
.vc-ring .track { stroke: rgba(255, 255, 255, 0.25); }
.vc-ring .prog { stroke: #ff4d4d; stroke-linecap: butt; }
.vc-timer { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.vc-hint { font-size: 12px; opacity: 0.75; text-align: center; max-width: 280px; }
.vc-controls { display: flex; align-items: center; justify-content: center; gap: 36px; }
.vc-side-btn { width: 46px; height: 46px; border-radius: 50%; background: rgba(255, 255, 255, 0.16); color: #fff; }
.vc-side-btn:disabled { opacity: 0.35; }
.vc-record-btn { width: 68px; height: 68px; border-radius: 50%; border: 4px solid #fff; display: flex; align-items: center; justify-content: center; padding: 0; }
.vc-record-btn span { width: 48px; height: 48px; border-radius: 50%; background: #ff3b3b; transition: all 0.18s ease; }
.vc-overlay.recording .vc-record-btn span { width: 26px; height: 26px; border-radius: 6px; }

/* Скелетон переписки */
@media (max-width: 749px) {
  .vcircle { width: 190px; height: 190px; }
  .voice-msg { min-width: 200px; }
}