/* =====================================================================
   Phase 13: Apple HIG Light + OLED Dark + Ferrari Red accent
   ===================================================================== */
:root {
  /* Phase 13.2: критично для Android Chrome / Samsung Internet.
     color-scheme отключает принудительный "Force Dark Mode" движка, который
     инвертирует наш OLED-чёрный в "грязный" серый. Браузер теперь уважает
     нашу @media (prefers-color-scheme: dark) переменную system theme. */
  color-scheme: light dark;
  /* ----- Phase 13 базовые токены (Light) ----- */
  --bg-main:       #FFFFFF;                    /* основной фон */
  --bg-surface:    #F2F2F7;                    /* приподнятые поверхности */
  --accent:        #E52E2D;                    /* Ferrari Red */
  --text-primary:  rgba(0, 0, 0, 0.96);
  --text-secondary:#8E8E93;
  --divider:       #E5E5EA;
  --nav-bg:        rgba(255, 255, 255, 0.9);   /* для blur'а под bottom-tabs */

  /* ----- Совместимость со старыми именами Apple HIG ----- */
  --apple-bg: var(--bg-main);
  --apple-bg-secondary: var(--bg-surface);
  --apple-surface: var(--bg-main);
  --apple-text: var(--text-primary);
  --apple-text-secondary: #3C3C43;
  --apple-text-muted: var(--text-secondary);
  --apple-text-tertiary: #C7C7CC;
  --apple-separator: var(--divider);
  --apple-overlay: rgba(0, 0, 0, 0.4);
  --apple-shadow: rgba(0, 0, 0, 0.08);

  /* Типографика */
  --apple-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
                 "Helvetica Neue", "Segoe UI", Roboto, system-ui, sans-serif;
  --apple-fs-large-title: 34px;
  --apple-fs-title1: 28px;
  --apple-fs-title2: 22px;
  --apple-fs-headline: 17px;
  --apple-fs-body: 17px;
  --apple-fs-subhead: 15px;
  --apple-fs-footnote: 13px;
  --apple-fs-caption: 12px;

  /* Радиусы */
  --apple-radius-s: 8px;
  --apple-radius-m: 12px;
  --apple-radius-l: 16px;
  --apple-radius-xl: 22px;
  --apple-squircle: 28%;

  /* ----- Legacy aliases (старый компонентный CSS) ----- */
  --bg-deep:       var(--bg-main);
  --bg-elevated:   var(--bg-surface);
  --bg-hover:      #E5E5EA;
  --border:        var(--divider);
  --border-strong: #AEAEB2;

  --accent-hover:  #FF4F4E;
  --accent-bright: var(--accent);
  --accent-pressed:#B81F1E;
  --accent-dim:    rgba(229, 46, 45, 0.12);
  --accent-glow:   rgba(229, 46, 45, 0.30);

  --text:          var(--text-primary);
  --text-muted:    var(--text-secondary);
  --text-faint:    var(--apple-text-tertiary);

  --danger:        var(--accent);
  --danger-hover:  #B81F1E;
  --success:       #34C759;
  --warning:       #FF9500;
  --gold:          #FFCC00;

  /* iOS palette для аватарок */
  --avatar-1: #E52E2D;
  --avatar-2: #FF9500;
  --avatar-3: #FFCC00;
  --avatar-4: #34C759;
  --avatar-5: #5AC8FA;
  --avatar-6: #AF52DE;
}

/* ===== OLED Dark Theme — автоматически по системной настройке ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-main:       #000000;                  /* OLED true black */
    --bg-surface:    #111111;
    --accent:        #E52E2D;                  /* Ferrari Red — единый цвет */
    --text-primary:  rgba(255, 255, 255, 0.96);
    --text-secondary:#8E8E93;
    --divider:       #222222;
    --nav-bg:        rgba(10, 10, 10, 0.9);

    /* Remapping Apple-aliases для dark */
    --apple-bg: var(--bg-main);
    --apple-bg-secondary: var(--bg-surface);
    --apple-surface: var(--bg-main);
    --apple-text: var(--text-primary);
    --apple-text-secondary: rgba(255,255,255,0.7);
    --apple-text-muted: var(--text-secondary);
    --apple-text-tertiary: #48484A;
    --apple-separator: var(--divider);
    --apple-overlay: rgba(0, 0, 0, 0.6);
    --apple-shadow: rgba(0, 0, 0, 0.5);

    --bg-deep: var(--bg-main);
    --bg-elevated: var(--bg-surface);
    --bg-hover: #1C1C1E;
    --border: var(--divider);
    --border-strong: #38383A;

    --text: var(--text-primary);
    --text-muted: var(--text-secondary);
    --text-faint: var(--apple-text-tertiary);
  }
  /* iOS PWA имеет белый theme-color — для dark переопределяем */
  body { background: var(--bg-main); color: var(--text-primary); }
}

body { background: var(--bg-main); color: var(--text-primary); }

/* ===== Reset ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* ===== Динамическая высота приложения =====
   --app-height — единый источник правды для высоты всего UI.
   Дефолт: 100dvh (CSS dynamic viewport — учитывает URL-bar / клавиатуру в современных браузерах).
   На Android JS-функция syncAppHeight() (см. app.js) обновляет переменную
   ПОКАДРОВО через visualViewport.resize, чтобы инпут плавно ехал вниз вместе
   с уходящей клавиатурой (без зависания «пустого фона»). */
:root {
  --app-height: 100dvh;
}
@supports not (height: 100dvh) {
  :root { --app-height: 100vh; }
}

/* ===== iOS PWA hard lock =====
   Жёсткая блокировка скролла body: iOS Safari при появлении клавиатуры
   принудительно скроллит body вверх (double-shift bug), из-за чего composer
   улетает на середину экрана. position: fixed на html+body это запрещает.
   Скроллятся только внутренние контейнеры (.chat-list, .messages). */
html, body {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--app-height);
  overflow: hidden !important;
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
}

html {
  text-size-adjust: 100%;
  /* touch-action: pan-x pan-y задан в html, body выше — позволяет панорамирование
     внутри скроллируемых контейнеров (.chat-list, .messages) и блокирует pinch-zoom
     (user-scalable=no в viewport уже не даёт zoom через двойной тап). */
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  /* По умолчанию весь UI неселектируемый, чтобы случайное удержание не выделяло кнопки/заголовки */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;       /* отключает iOS-меню при долгом нажатии */
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
/* Контентные текстовые элементы выделить МОЖНО */
.msg-text, .msg-text *,
.post-text, .post-text *,
.post-caption,
.reply-quote-text, .reply-quote-name,
.online-row-id, .me-id, #my-id-display,
.id-box code, .id-box .nick,
input, textarea, [contenteditable] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
button { font-family: inherit; cursor: pointer; border: none; outline: none; color: inherit; }
input, textarea { font-family: inherit; outline: none; border: none; color: inherit; }
code { font-family: "SF Mono", Consolas, Monaco, monospace; font-size: 12px; }

/* ===== Screens ===== */
/* Все full-screen экраны привязаны к --app-height — обновляется purerendering
   через JS visualViewport, либо CSS dvh при отсутствии JS-апдейта. */
.screen { display: none; height: var(--app-height); }
.screen.active { display: flex; }
#auth-screen {
  justify-content: center; align-items: center;
  background:
    radial-gradient(circle at 20% 30%, rgba(165, 29, 45, 0.12), transparent 60%),
    radial-gradient(circle at 80% 70%, rgba(217, 70, 89, 0.08), transparent 60%),
    var(--bg-deep);
  padding: 16px;
  overflow-y: auto;
}
#app-screen { display: none; }
#app-screen.active { display: flex; }

/* ===== Phase 16: Passkey-only Auth (минимализм) ===== */
.auth-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 40px 32px 32px;
  border-radius: 18px;
  width: 380px; max-width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
  position: relative;
}

.auth-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.auth-panel[hidden] { display: none; }

/* Иконка-кот: 80×80 круглая, центр, аккуратная */
.auth-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px;
  display: block;
  margin: 0 auto;
}

.auth-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0;
}

/* Главная CTA: крупная Ferrari Red */
.auth-cta {
  width: 100%;
  background: var(--accent-color, #E52E2D);
  color: #fff;
  border: 0;
  padding: 16px 18px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 100ms ease, opacity 150ms ease, background 150ms ease;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 6px 20px rgba(229, 46, 45, 0.32);
  margin-top: 4px;
}
.auth-cta:hover  { background: #ff4040; }
.auth-cta:active { transform: scale(0.98); opacity: 0.92; }
.auth-cta:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

/* Текст "Нет аккаунта? Создать" / "Назад ко входу" */
.auth-foot {
  margin: 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.55);
}
.auth-foot a {
  color: var(--accent-color, #E52E2D);
  text-decoration: none;
  font-weight: 500;
}
.auth-foot a:hover { text-decoration: underline; }

/* Описание для create-panel */
.auth-rules {
  font-size: 14px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.75);
  margin: 0;
  text-align: center;
}

/* Информационный блок (где сохранится Passkey) — мелкий серый */
.auth-info {
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.45);
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  width: 100%;
  box-sizing: border-box;
}

/* ===== Buttons ===== */
.btn {
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  width: 100%;
}
.btn-primary { background: var(--accent); color: white; box-shadow: 0 2px 8px rgba(165,29,45,0.3); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(165,29,45,0.4); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 6px 12px; font-size: 12px; width: auto; }
.btn-add { margin-top: 8px; }
/* Старые кнопки в шапке сайдбара спрятаны — их действия теперь в Context Sheet
   через long-press по Bottom Tab Bar. Биндинги в JS оставлены живыми
   (они программно открывают модалки из ContextSheet). */
.sidebar-buttons { display: none !important; }

/* ===== Phase 13: Stories-карусель (круги вместо squircle) ===== */
.pinned-row {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 16px 14px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-bottom: 0.5px solid var(--divider);
  background: var(--bg-main);
}
.pinned-row::-webkit-scrollbar { display: none; }
.pinned-row:empty { display: none; }
.pinned-cell {
  flex: 0 0 auto;
  width: 72px;
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  background: transparent; border: 0; padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* Phase 13: круг с обводкой-«историей». По умолчанию — приглушённая (просмотрено). */
.pinned-cell .avatar {
  width: 60px; height: 60px;
  font-size: 22px;
  border-radius: 50% !important;            /* перебиваем squircle */
  border: 2px solid var(--divider);
  padding: 2px;                              /* зазор между обводкой и аватаркой */
  background-clip: content-box;              /* обводка вокруг content-box */
}
/* Непрочитанные / новые — яркая красная обводка */
.pinned-cell.unread .avatar,
.pinned-cell.story-fresh .avatar {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(229, 46, 45, 0.18);
}
.pinned-cell .pinned-name {
  font-family: var(--apple-font);
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  max-width: 70px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
/* Кнопка «Твоя история» / «+» — тонкая красная обводка, прозрачный фон */
.pinned-cell.add .avatar {
  background: transparent !important;
  background-clip: border-box;
  color: var(--accent) !important;
  border: 1px solid var(--accent);
  font-size: 24px;
  font-weight: 300;
}
.pinned-cell.add .pinned-name { color: var(--text-secondary); }
.pinned-cell:active { transform: scale(0.95); transition: transform 0.08s; }
.icon-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.recording { color: var(--danger); animation: pulse 1.2s infinite; }

/* ===== Layout ===== */
#app-screen { background: var(--bg-deep); }

/* Sidebar — единая flex-column от верха до низа.
   ┌─────────────────────────┐
   │  .sidebar-header        │  ← flex-shrink:0; max-height: 0 ↔ 80px
   ├─────────────────────────┤
   │  .sidebar-content       │  ← flex:1; overflow-y:auto
   │  ├─ #pinned-row         │     (внутри скроллящийся блок)
   │  └─ #chat-list          │
   ├─────────────────────────┤
   │  .status-bar            │  ← flex-shrink:0
   └─────────────────────────┘
   При .sidebar.search-active заголовок раскрывается от 0 до 80px —
   и Flexbox АВТОМАТИЧЕСКИ сжимает .sidebar-content (просто меньше высоты).
   Никаких ручных padding-top, никаких прыжков, никаких overlap'ов. */
/* Phase 12/13: Apple Large Title «Nero.» с красной точкой */
.sidebar-brand-title {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  padding: 16px 16px 8px;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
  background: var(--bg-main);
}
.sidebar-brand-title::after {
  content: '.';
  color: var(--accent);                       /* Ferrari Red */
}
/* На мобилке учитываем safe-area сверху (notch / Dynamic Island) */
@media (max-width: 768px) {
  .sidebar-brand-title {
    padding-top: max(16px, calc(env(safe-area-inset-top, 0px) + 8px));
  }
}

.sidebar {
  width: 340px;
  /* Phase 13.1: на Android тёмная тема показывала «грязный» серый фон.
     Сливаем с --bg-main (OLED-чёрный / чисто-белый). */
  background: var(--bg-main);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform 0.25s ease;
  /* --search-h: высота раскрытого поиска. max(env(safe-area-inset-top), 47px)
     гарантирует отступ под Dynamic Island / Notch даже если iOS PWA вернёт env() === 0
     (известный баг Safari). На iPhone без челки safe-area=0 → 47px эквивалентно
     обычной статус-баре, выглядит нативно. */
  --search-h: calc(max(env(safe-area-inset-top), 47px) + 56px);
}

/* Telegram-style pull-to-reveal: max-height-аккордеон, не transform.
   max-height: 0 → 80px анимируется плавно; Flexbox автоматически забирает
   у .sidebar-content столько же. На iOS работает корректно (не «сплющивается»),
   потому что элемент находится в нормальном flex-flow, а не absolute. */
.sidebar-header {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 0;
  overflow: hidden;
  padding: 0 12px;
  border-bottom: 0;
  background: var(--apple-bg);
  box-sizing: border-box;
  transition: max-height 0.3s ease, padding 0.3s ease, border-color 0.3s ease;
}
.sidebar.search-active .sidebar-header {
  max-height: var(--search-h);
  padding: 8px 12px;
  /* max(env(safe-area-inset-top), 47px) — гарантия отступа под челку даже
     когда env() в iOS PWA отдаёт 0 (баг Safari в standalone-режиме). */
  padding-top: max(env(safe-area-inset-top), 47px);
  border-bottom: 1px solid var(--apple-separator);
}
.sidebar-header .me { display: none !important; }

/* Wrapper для pinned-row + chat-list. Это и есть скролл-контейнер. */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  min-height: 0;                 /* fix flex children overflow bug */
}
.me-info { flex: 1; min-width: 0; }
.me-name { font-weight: 600; font-size: 15px; }
.me-id { font-size: 11px; color: var(--text-muted); font-family: "SF Mono", Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-wrap {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  padding: 0;
  margin: 0;
}
#search-input {
  box-sizing: border-box;
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 20px;
  font-size: 14px;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-faint); }

/* ===== Chat list =====
   Скролл выполняет родительский .sidebar-content (он flex:1; overflow-y:auto).
   Здесь chat-list — просто внутренний блок без собственного скролла,
   чтобы избежать «двойной прокрутки» когда родитель тоже скроллируемый. */
.chat-list {
  /* нет своего overflow — родитель .sidebar-content скроллит */
}
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
/* Phase 13: Classic flat list — никаких карточек, фон прозрачный, только нижний разделитель */
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.1s;
  background: transparent;                    /* сливаемся с --bg-main */
  border-bottom: 0.5px solid var(--divider);
}
.chat-item:last-child { border-bottom: 0; }
.chat-item:hover { background: var(--bg-surface); }
.chat-item:active { background: var(--bg-surface); }
.chat-item.active {
  background: var(--bg-surface);              /* мягкая подсветка без градиента */
}
.chat-item.active .chat-name,
.chat-item.active .chat-preview,
.chat-item.active .chat-time { color: inherit; }
.chat-meta { flex: 1; min-width: 0; }
.chat-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-name {
  font-weight: 600; font-size: 16px;
  color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pin-badge { font-size: 11px; margin-left: 4px; opacity: 0.85; vertical-align: middle; }
.chat-time {
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0; margin-left: 8px;
  font-weight: 400;
}
.chat-preview {
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}
/* Phase 13: Ferrari Red unread-badge */
.chat-unread, .unread-badge {
  background: var(--accent);                   /* Ferrari Red */
  color: #FFF;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 6px;
  margin-left: 6px;
  flex-shrink: 0;
}

/* ===== Phase 13: Avatar — минималистичный круг ===== */
.avatar {
  width: 48px; height: 48px;
  border-radius: 50%;                                  /* Phase 13: круг */
  background: var(--bg-surface);                       /* нейтральный фон */
  color: var(--text-primary); font-weight: 600; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; position: relative;
  font-family: var(--apple-font);
  /* Phase 15.11: clip-protection — даже если в DOM окажется длинный текст,
     он не вылезет за круглые границы аватарки и не наедет на соседние блоки. */
  overflow: hidden;
  text-align: center;
  line-height: 1;
}
.avatar.online::after {
  content: ""; position: absolute; bottom: 0; right: 0;
  width: 12px; height: 12px; background: var(--success);
  border: 2px solid var(--bg-surface); border-radius: 50%;
}
.avatar.p2p::after { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.avatar.color-1 { background: var(--avatar-1); }
.avatar.color-2 { background: var(--avatar-2); }
.avatar.color-3 { background: var(--avatar-3); }
.avatar.color-4 { background: var(--avatar-4); }
.avatar.color-5 { background: var(--avatar-5); }
.avatar.color-6 { background: var(--avatar-6); }
/* Phase 13.1: «Избранное» — кастомная картинка (неоновый кот) */
.avatar.saved {
  background-color: #0A0A0A !important;
  background-image: url('images/saved-icon.png') !important;
  background-size: cover !important;
  background-position: center !important;
  color: transparent !important;                     /* прячем старый эмодзи */
  border: 1px solid rgba(255, 94, 0, 0.5) !important;
  box-shadow: 0 0 12px rgba(255, 94, 0, 0.35) !important;
}
.avatar.room { background: var(--apple-bg-secondary); color: var(--apple-text); border: 1px solid var(--apple-separator); font-size: 22px; }

/* ===== Status bar ===== */
.status-bar {
  padding: 8px 14px; font-size: 12px; color: var(--text-muted);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }

/* ===== Chat area ===== */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg-deep); min-width: 0; }
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--text-faint); padding: 24px;
  text-align: center;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.4; color: var(--accent); }
.empty-state h2 { font-weight: 500; margin-bottom: 8px; color: var(--text-muted); }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  padding: 12px 18px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.peer-info { flex: 1; min-width: 0; }
.peer-name { font-weight: 600; font-size: 15px; }
.peer-status { font-size: 12px; color: var(--text-muted); }
.peer-status.online { color: var(--success); }
.peer-status.p2p { color: var(--gold); }
.btn-back-mobile { display: none; }

/* ===== Route toggle (P2P / Сервер) ===== */
.route-toggle {
  display: inline-flex;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  align-self: center;
}
.route-opt {
  background: transparent;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 14px;
  transition: all 0.15s;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
}
.route-opt.active { background: var(--accent); color: white; }
.route-opt:hover:not(.active) { color: var(--text); }
.route-opt.fallback {
  background: rgba(212, 164, 67, 0.18);
  color: var(--gold);
}
.route-opt.fallback::after {
  content: "↺";
  position: absolute; top: -2px; right: -2px;
  width: 12px; height: 12px;
  background: var(--gold); color: var(--bg-deep);
  border-radius: 50%;
  font-size: 9px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.route-opt .compact { display: none; }

/* ===== Messages =====
   Аналогично chat-list — скролл только внутри, body снаружи заблокирован.
   -webkit-overflow-scrolling: touch обязательно для плавного скролла в iOS. */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 18px;
  background: var(--apple-bg);                  /* чистый белый, как iOS Messages */
  display: flex; flex-direction: column; gap: 4px;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: var(--apple-text-tertiary); border-radius: 3px; }

.msg {
  max-width: 70%;
  padding: 8px 12px 6px;
  border-radius: 14px;
  word-wrap: break-word; position: relative;
  font-size: 14px; line-height: 1.4;
  /* Жёсткая блокировка нативного выделения / teardrops / системного меню Android.
     !important нужен потому, что глобальные input/textarea-правила или iOS-default
     могут переопределять user-select даже после нашего none.
     -webkit-touch-callout: none гарантированно убирает Android-popup на long-press. */
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}
/* Также блокируем выделение внутри пузыря (текст и атрибуты) */
.msg, .msg * {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}
/* Внутренние интерактивы — реакции и реплай-цитата — остаются кликабельными.
   Сам текст сообщения visually selectable нам не нужен (есть кнопка «Копир.»). */

/* ===== Кликабельные аватарки для смены изображения =====
   .avatar.editable — добавляется JS на аватарки в редактируемых модалках
   (Profile, Chat info, Bot constructor). На hover/active показывает 📷-оверлей. */
.avatar.editable {
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar.editable::after {
  content: "📷";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(14px, 30%, 22px);
  background: rgba(0,0,0,0.45);
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.avatar.editable:hover::after,
.avatar.editable:active::after,
.avatar.editable:focus-visible::after { opacity: 1; }

/* Когда аватарка показывает реальное изображение — скрываем дефолтный текст
   (initial letter) через .has-avatar-image. Применяется в applyAvatarImage. */
.avatar.has-avatar-image {
  color: transparent;
}
.msg.in {
  background: var(--apple-bg-secondary);      /* iOS systemGroupedBackground */
  color: var(--apple-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg.out {
  background: var(--accent);                   /* iOS systemRed */
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg.system {
  align-self: center;
  background: rgba(0,0,0,0.4);
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 12px;
  max-width: 80%;
  text-align: center;
}
.msg-text { white-space: pre-wrap; word-wrap: break-word; word-break: break-word; }
.msg-text:empty { display: none; }

/* ======================================================================
   Phase 15.7 (final) — Bot reposts (RSSHub feed messages).
   Safe whitelisted HTML render: <b>, <i>, <u>, <p>, <br>, <img>.
   ====================================================================== */

/* Bot-message bubble distinction */
.msg.bot .msg-text,
.msg.bot .msg-forwarded-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
}
/* Внутри bot-сообщений <p> рендерится с разумными отступами (1 строка между абзацами) */
.msg.bot .msg-text p,
.msg.bot .msg-forwarded-text p {
  margin: 0 0 8px 0;
  padding: 0;
  display: block;
}
.msg.bot .msg-text p:last-child,
.msg.bot .msg-forwarded-text p:last-child { margin-bottom: 0; }

/* Reset стилей для разрешённых тегов — родительский .msg-text мог их
   нивелировать (если где-то задан all: unset или unhandled). */
.msg.bot .msg-text b,
.msg.bot .msg-forwarded-text b { font-weight: 700; }
.msg.bot .msg-text i,
.msg.bot .msg-forwarded-text i { font-style: italic; }
.msg.bot .msg-text u,
.msg.bot .msg-forwarded-text u { text-decoration: underline; }

/* ----------------------------------------------------------------------
   Phase 19.2 — расширение whitelist: <a>, <blockquote>, multi-<img>.
   ---------------------------------------------------------------------- */

/* Безопасные ссылки в bot-постах (Ferrari red, hover-underline) */
.msg.bot .msg-text a,
.msg.bot .msg-forwarded-text a {
  color: var(--accent-color, #E52E2D);
  text-decoration: none;
  word-break: break-word;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: opacity 120ms ease;
}
.msg.bot .msg-text a:hover,
.msg.bot .msg-forwarded-text a:hover { text-decoration: underline; }
.msg.bot .msg-text a:active,
.msg.bot .msg-forwarded-text a:active { opacity: 0.7; }
/* Inert-ссылка (без href, отсеяна по схеме) — без курсора */
.msg.bot .msg-text a:not([href]),
.msg.bot .msg-forwarded-text a:not([href]) {
  color: inherit;
  cursor: default;
  text-decoration: none;
}

/* Цитата в bot-посте (Apple-style: акцент-бордер слева + лёгкий фон).
   Phase 19.3 (Hotfix): цвета через theme-tokens, чтобы в light-режиме НЕ было
   белого текста на светло-сером (bg-surface = #F2F2F7) — теперь использует
   currentColor от родительского .msg (var(--apple-text) автоматически
   переключается между rgba(0,0,0,0.96) и rgba(255,255,255,0.96)). */
.msg.bot .msg-text blockquote,
.msg.bot .msg-forwarded-text blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--accent, #E52E2D);
  background: rgba(127, 127, 127, 0.10);   /* нейтральный серый — виден на любом фоне */
  border-radius: 6px;
  color: inherit;                          /* наследуем от .msg.in/.msg.out — авто-контраст */
  font-style: normal;
  white-space: pre-wrap;
  opacity: 0.92;
}
.msg.bot .msg-text blockquote p,
.msg.bot .msg-forwarded-text blockquote p { margin: 0; }
.msg.bot .msg-text blockquote p + p,
.msg.bot .msg-forwarded-text blockquote p + p { margin-top: 6px; }

/* Множественные inline-картинки внутри bot-поста: стекаются вертикально,
   каждая на полную ширину с aapple-style скруглением и спейсингом.
   Сохраняется простота layout'а (text + img + text + img всё в одном
   block-flow), без риска поломать flex-перенос текста. */
.msg.bot .msg-text .msg-image + .msg-image,
.msg.bot .msg-forwarded-text .msg-image + .msg-image {
  margin-top: 4px;
}

/* ======================================================================
   Phase 19.2 (Block 3) — Кастомный видеоплеер для bot-постов.
   Telegram-style: тёмная подложка, glass-Play-button с blur'ом,
   крупный кликабельный overlay, hover-scale анимация, toast ±10s.
   ====================================================================== */

.msg-video-wrapper {
  position: relative;
  max-width: 100%;
  margin-top: 8px;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Apple-style тень для отделения от фона bubble'а */
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset,
              0 2px 12px rgba(0, 0, 0, 0.35);
}
.msg-video-wrapper video {
  display: block;
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  outline: none;
  border: none;
  background: #000;
}

/* Overlay поверх видео — кликабельный, скрывается при play */
.msg-video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.30);
  cursor: pointer;
  z-index: 2;
  transition: opacity 180ms cubic-bezier(0.25, 1, 0.5, 1),
              visibility 0s linear 0ms;
  -webkit-tap-highlight-color: transparent;
}
.msg-video-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms cubic-bezier(0.25, 1, 0.5, 1),
              visibility 0s linear 180ms;
}

/* Glass Play-button: круг, blur, тонкая обводка, белый ▶ */
.msg-video-play-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  backdrop-filter: blur(8px) saturate(140%);
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
  color: #fff;
  /* Чуть сдвигаем треугольник вправо — у Unicode ▶ оптический центр смещён влево */
  padding-left: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45),
              0 0 0 0 rgba(255, 255, 255, 0.2);
  transition: transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1),
              background 180ms ease,
              box-shadow 220ms ease;
  user-select: none;
  -webkit-user-select: none;
}
.msg-video-overlay:hover .msg-video-play-btn {
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.28);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.55),
              0 0 0 6px rgba(255, 255, 255, 0.08);
}
.msg-video-overlay:active .msg-video-play-btn {
  transform: scale(0.96);
  transition-duration: 80ms;
}

/* Toast "+10s" / "-10s" — выезжает сверху после dblclick-жеста */
.msg-video-toast {
  position: absolute;
  top: 12px;
  background: rgba(0, 0, 0, 0.65);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  z-index: 3;
  pointer-events: none;
  letter-spacing: 0.02em;
  transform: translateY(-4px) scale(0.96);
  transition: opacity 200ms ease, transform 220ms cubic-bezier(0.25, 1, 0.5, 1);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* Мобилка: чуть меньше play-button, чтобы не давил видео */
@media (max-width: 540px) {
  .msg-video-play-btn {
    width: 56px;
    height: 56px;
    font-size: 22px;
  }
  .msg-video-wrapper video {
    max-height: 320px;
  }
}

/* ======================================================================
   Phase 19.4 — Книга контактов: модалка-список с поиском и quick-actions.
   ====================================================================== */
.contacts-scroll-area {
  max-height: 50vh;
  overflow-y: auto;
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  -webkit-overflow-scrolling: touch;
}
.contacts-scroll-area:empty::before {
  content: "Список пуст. Добавьте контакт через кнопку «+ Контакт».";
  display: block;
  padding: 22px 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  font-style: italic;
}
.contacts-book-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 120ms ease;
  -webkit-tap-highlight-color: transparent;
}
.contacts-book-item:last-child { border-bottom: 0; }
.contacts-book-item:hover { background: rgba(255, 255, 255, 0.04); }
.contacts-book-item:active { background: rgba(255, 255, 255, 0.07); }
.contacts-book-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}
.contacts-book-meta {
  flex: 1;
  min-width: 0;
}
.contacts-book-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contacts-book-status {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.contacts-book-status .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  vertical-align: middle;
  margin-right: 4px;
}
.contacts-book-status.offline .dot { background: var(--text-muted); opacity: 0.5; }
.contacts-book-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.contacts-book-action {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, border-color 120ms ease;
}
.contacts-book-action:hover  { background: rgba(255, 255, 255, 0.12); }
.contacts-book-action:active { transform: scale(0.92); }
.contacts-book-action.danger { color: var(--danger); }
.contacts-book-action.danger:hover { background: rgba(229, 46, 45, 0.14); border-color: rgba(229, 46, 45, 0.4); }
.contacts-book-action.primary { color: var(--accent); }
.contacts-book-action.primary:hover { background: rgba(229, 46, 45, 0.10); border-color: rgba(229, 46, 45, 0.3); }

@media (max-width: 540px) {
  .contacts-scroll-area { max-height: 55vh; }
  .contacts-book-action { width: 36px; height: 36px; font-size: 16px; }
}

/* ======================================================================
   Phase 19.3 (Hotfix) — Прогресс-бар загрузки вложений.
   Floating popup внизу-по-центру (над композером), Apple-style glass.
   ====================================================================== */
.file-progress {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  min-width: 280px;
  max-width: 92%;
  padding: 12px 16px;
  background: rgba(28, 28, 32, 0.92);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5),
              0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  color: #fff;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms cubic-bezier(0.25, 1, 0.5, 1),
              transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
  font-size: 13px;
}
.file-progress.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.file-progress-label {
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 500;
  word-break: break-word;
  /* запрещаем overflow в одну линию: видна полная подпись */
  white-space: normal;
}
.file-progress-bar {
  position: relative;
  height: 4px;
  background: rgba(255, 255, 255, 0.10);
  border-radius: 2px;
  overflow: hidden;
}
.file-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, #E52E2D 0%, #ff6b6b 100%);
  border-radius: 2px;
  transition: width 180ms cubic-bezier(0.25, 1, 0.5, 1),
              background 220ms ease;
  box-shadow: 0 0 12px rgba(229, 46, 45, 0.5);
}
.file-progress-pct {
  margin-top: 6px;
  text-align: right;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.65);
  font-weight: 500;
}
.file-progress.done .file-progress-fill {
  background: linear-gradient(90deg, #2ECC71 0%, #58E194 100%);
  box-shadow: 0 0 14px rgba(46, 204, 113, 0.55);
}
.file-progress.done .file-progress-label::before {
  content: '✓ ';
  color: #2ECC71;
  font-weight: 700;
}
.file-progress.fail .file-progress-fill {
  width: 100% !important;
  background: linear-gradient(90deg, #E52E2D 0%, #ff4040 100%);
  box-shadow: 0 0 14px rgba(229, 46, 45, 0.6);
}
.file-progress.fail .file-progress-label::before {
  content: '⚠ ';
  color: #ff4040;
}
.file-progress.fail .file-progress-pct { color: #ff6b6b; }

@media (max-width: 540px) {
  .file-progress {
    bottom: 80px;
    min-width: 0;
    width: 88%;
  }
}

/* Inline-картинка из RSS-поста (whitelist <img>) */
.msg-image {
  display: block;
  max-width: 100%;
  max-height: 400px;
  width: auto;
  height: auto;
  border-radius: 8px;
  margin: 6px 0;
  object-fit: cover;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  transition: opacity 150ms ease;
}
.msg-image:active { opacity: 0.85; }

/* Phase 15.8: главное фото-аттачмент над текстом bot-поста.
   Вставляется через DOM API из buildMessageEl. Click → fullscreen. */
.msg-photo-attachment {
  display: block;
  max-width: 100%;
  max-height: 350px;
  width: auto;
  height: auto;
  border-radius: 8px;
  margin-bottom: 6px;
  object-fit: cover;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  transition: opacity 150ms ease;
}
.msg-photo-attachment:active { opacity: 0.85; }

/* Fullscreen overlay для просмотра кликнутой картинки */
.msg-image-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 180ms ease-out;
  cursor: zoom-out;
  -webkit-tap-highlight-color: transparent;
}
.msg-image-overlay.open { opacity: 1; }
.msg-image-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7);
  /* Apple-style лёгкий scale-in */
  transform: scale(0.96);
  transition: transform 220ms cubic-bezier(0.25, 1, 0.5, 1);
}
.msg-image-overlay.open img { transform: scale(1); }

/* Кнопка-ссылка «Открыть источник» под текстом поста */
.msg-source-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--accent-color, #E52E2D);
  text-decoration: none;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}
.msg-source-link:hover  { opacity: 0.8; }
.msg-source-link:active { opacity: 0.6; }
.msg-author {
  font-size: 12px;
  color: var(--accent-bright);
  font-weight: 600;
  margin-bottom: 2px;
}
.msg-meta {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  margin-top: 2px; text-align: right;
  display: flex; gap: 4px; justify-content: flex-end; align-items: center;
}
.msg.out .msg-meta { color: rgba(255,255,255,0.78); }
.msg.in  .msg-meta { color: var(--apple-text-muted); }
.msg-tick { font-size: 12px; }
.msg-tick.sent      { color: rgba(255,255,255,0.78); }
.msg-tick.delivered { color: rgba(255,255,255,0.95); }
.msg-tick.read      { color: #FFD60A; font-weight: 700; }   /* iOS systemYellow */
.msg-tick.failed    { color: #FFD60A; }
.msg-tick.p2p { color: var(--gold); }

.msg-react-btn {
  position: absolute; top: -10px;
  width: 28px; height: 28px;
  background: var(--bg-elevated); color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 50%; display: none;
  align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4); z-index: 2;
}
.msg.in .msg-react-btn { right: -10px; }
.msg.out .msg-react-btn { left: -10px; }
.msg:hover .msg-react-btn { display: flex; }
.msg-react-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--accent); }

/* ===== Quotes ===== */
.reply-quote {
  border-left: 3px solid var(--accent-bright);
  background: rgba(217,70,89,0.12);
  padding: 4px 8px; margin-bottom: 6px;
  border-radius: 4px; cursor: pointer;
  max-width: 100%; overflow: hidden;
}
.msg.in .reply-quote { border-left-color: var(--gold); background: rgba(212,164,67,0.12); }
.reply-quote-name { font-size: 12px; color: var(--accent-bright); font-weight: 600; }
.msg.in .reply-quote-name { color: var(--gold); }
.reply-quote-text {
  font-size: 13px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg.flash { animation: flash 1.5s; }
@keyframes flash {
  0%, 100% { box-shadow: none; }
  20% { box-shadow: 0 0 0 3px var(--gold); }
}

/* ===== Reactions ===== */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reaction-chip {
  background: rgba(0,0,0,0.3); color: var(--text);
  border-radius: 12px; padding: 2px 8px; font-size: 12px;
  cursor: pointer; border: 1px solid transparent;
  transition: all 0.1s; display: inline-flex; align-items: center; gap: 3px;
}
.reaction-chip:hover { background: rgba(0,0,0,0.45); }
.reaction-chip.mine { background: var(--accent-dim); border-color: var(--accent); }
.reaction-chip .count { font-size: 11px; opacity: 0.85; }

.reaction-picker {
  position: fixed; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 24px;
  padding: 6px 8px; display: flex; gap: 2px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6); animation: popIn 0.15s;
}
.reaction-picker button {
  background: transparent; font-size: 22px;
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s;
}
.reaction-picker button:hover { transform: scale(1.3); background: var(--bg-hover); }

/* ===== Msg menu — iOS HIG Message Action Stack =====
   Полноэкранный бэкдроп с лёгким blur. По клику на backdrop меню закрывается. */
.msg-menu-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.msg-menu-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* «Отрыв» пузыря — клон создаётся в <body> через JS, чтобы выйти из stacking
   context'а #app-screen (который position:fixed → создаёт собственный context).
   z-index клона 10000 побьёт z-index бэкдропа 9999 в body.
   ОРИГИНАЛЬНЫЙ пузырь получает .msg-hidden (visibility:hidden) — он остаётся
   в DOM-flow (геометрия чата не ломается), но не двоится с клоном.
   pointer-events: auto на клоне — пользователь может выделить текст,
   тапнуть реакцию или ссылку. */
.msg.msg-elevated {
  position: fixed;
  z-index: 10000;
  transform: scale(1.04);
  transform-origin: left top;       /* default — для входящих (left-fixed); see .in/.out below */
  box-shadow: 0 12px 32px rgba(0,0,0,0.20);
  /* Только transform/shadow анимируются. top/left устанавливаются JS'ом в одну
     setTimeout-фазу с финальной позицией — клон не «телепортируется» из 0,0. */
  transition: transform 0.2s ease,
              box-shadow 0.2s ease;
  pointer-events: auto;             /* интерактивен для selection / реакций */
  margin: 0;                        /* fixed-position не нуждается в margin'ах flex-flow */
}
.msg.msg-elevated.out { transform-origin: right top; }
.msg.msg-elevated.in  { transform-origin: left top;  }

/* Скрытие исходного пузыря: visibility:hidden сохраняет место в DOM-flow,
   чтобы геометрия .messages не схлопнулась и клон не «прыгнул» при появлении.
   pointer-events:none — клики на этом месте сразу пробрасываются на backdrop. */
.msg.msg-hidden {
  visibility: hidden !important;
  pointer-events: none;
}

/* Временно разрешаем выделение текста в активном (поднятом) пузыре.
   Базовое правило `.msg, .msg * { user-select: none !important }` остаётся;
   override применяется только когда висит класс .msg-elevated (только клон). */
.msg.msg-elevated,
.msg.msg-elevated * {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

/* Phase 11: Apple-style панель реакций над контекстным меню (только мобилка) */
.ios-reaction-bar {
  display: none;                 /* по умолчанию скрыта — JS включает на мобилке */
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--apple-separator);
  font-size: 26px;
  background: var(--bg-surface);
  user-select: none;
}
.ios-reaction-emoji {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease;
  padding: 4px;
  border-radius: 50%;
  line-height: 1;
}
.ios-reaction-emoji:active { transform: scale(1.25); }
.ios-reaction-emoji.mine { background: rgba(0,122,255,0.18); }

/* Phase 11/11.1: на мобилке нативная кнопка реакций на пузыре скрыта —
   используем .ios-reaction-bar внутри msg-menu. Ловим все варианты имени класса. */
@media (max-width: 600px) {
  .msg-react-btn,
  .msg-react-quick-btn,
  .msg-inline-react-btn { display: none !important; }
}

/* Плавающая панель меню — «капелька», вытекающая из пузыря.
   Дефолт: scale(0) + opacity(0) + pointer-events:none — невидима, но в DOM-flow.
   При классе .msg-menu-active → scale(1) + opacity(1) с spring cubic-bezier.
   transform-origin задаётся inline через JS под isOut/menuAbove. */
.msg-menu {
  position: fixed;
  z-index: 10001;
  background: var(--bg-surface);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.08);
  overflow: hidden;
  width: max-content;
  min-width: 180px;
  max-width: 280px;
  font-family: var(--apple-font);
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
  transform-origin: left top;                               /* override через JS inline */
  /* Spring overshoot для transform (Apple-style лёгкая «пружина»),
     opacity — обычная плавная ease. */
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity   0.18s ease;
}
.msg-menu.msg-menu-active {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

/* Верхний ряд — быстрые действия в горизонтальном flex */
.msg-menu-quick {
  display: flex;
  align-items: stretch;
  background: var(--bg-surface);
}
.msg-menu-quick-btn {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 12px 8px 10px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  color: var(--apple-text);
  font-family: var(--apple-font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
  min-width: 56px;
}
.msg-menu-quick-btn + .msg-menu-quick-btn {
  border-left: 0.5px solid var(--apple-separator);
}
.msg-menu-quick-btn:active { background: var(--apple-bg-secondary); }
.msg-menu-quick-btn .msg-menu-icon {
  font-size: 22px;
  line-height: 1;
}
.msg-menu-quick-btn .msg-menu-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1px;
}

/* Разделитель верх / низ */
.msg-menu-list {
  border-top: 1px solid var(--apple-separator);
  background: var(--bg-surface);
}

/* Нижний список — вертикальный, с inset-разделителями */
.msg-menu-list-btn {
  display: flex; align-items: center;
  gap: 12px;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 12px 16px;
  text-align: left;
  font-size: 16px;
  font-family: var(--apple-font);
  color: var(--apple-text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
  min-height: 44px;
}
.msg-menu-list-btn + .msg-menu-list-btn {
  border-top: 0.5px solid var(--apple-separator);
}
.msg-menu-list-btn:active { background: var(--apple-bg-secondary); }
.msg-menu-list-btn .msg-menu-icon {
  font-size: 18px;
  width: 24px; text-align: center;
}
.msg-menu-list-btn.danger,
.msg-menu-list-btn.danger .msg-menu-icon {
  color: #FF3B30;          /* iOS systemRed */
}

/* ===== Attachments ===== */
.attachment { margin-bottom: 4px; border-radius: 8px; overflow: hidden; max-width: 320px; }
.attachment.image {
  cursor: pointer; background: rgba(0,0,0,0.3);
  min-height: 120px; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 13px;
}
.attachment.image img { display: block; max-width: 100%; max-height: 320px; border-radius: 8px; }
.attachment.file {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: rgba(0,0,0,0.3);
  border-radius: 8px; cursor: pointer; min-width: 220px;
  transition: background 0.1s;
}
.attachment.file:hover { background: rgba(0,0,0,0.5); }
.file-icon {
  width: 38px; height: 38px;
  background: var(--accent-dim); color: var(--accent-bright);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Phase 16.4: inline-file (Base64 в E2EE-payload) — есть data-inline, кликабелен */
.attachment.file.has-inline {
  cursor: pointer;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
}
.attachment.file.has-inline:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(229,46,45,0.4);
}
.attachment.file.has-inline:active { transform: scale(0.98); }
.attachment.file .file-action {
  font-size: 11px;
  color: var(--accent-color, #E52E2D);
  font-weight: 600;
  margin-left: 8px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.attachment.voice {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: rgba(0,0,0,0.3);
  border-radius: 18px; min-width: 220px;
}
.voice-play {
  width: 36px; height: 36px;
  background: var(--accent); color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer; flex-shrink: 0;
}
.voice-play.playing { background: var(--accent-hover); }
.voice-bar { flex: 1; height: 3px; background: rgba(255,255,255,0.2); border-radius: 2px; position: relative; cursor: pointer; }
.voice-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent-bright); border-radius: 2px; width: 0%; }
.voice-dur { font-size: 12px; color: var(--text-muted); min-width: 32px; text-align: right; }

.attachment.circle {
  width: 200px; height: 200px;
  border-radius: 50%; overflow: hidden;
  background: #000; cursor: pointer;
  position: relative;
}
.attachment.circle video { width: 100%; height: 100%; object-fit: cover; }
.attachment.circle .circle-play-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; color: white;
  background: rgba(0,0,0,0.3); pointer-events: none;
}
.attachment.circle.playing .circle-play-overlay { display: none; }
.attachment.circle .circle-dur {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6); color: white;
  padding: 2px 8px; border-radius: 10px; font-size: 11px;
}

.attachment.video video {
  display: block; max-width: 100%; max-height: 320px;
  border-radius: 8px; background: #000;
}
.attachment.audio audio { display: block; width: 280px; }

/* Phase 19.3 (Hotfix) — inline-видео (Base64 в E2EE-payload).
   Контейнер прозрачный — внутри сидит .msg-video-wrapper из buildVideoPlayerEl
   со своим chrome'ом (glass Play, overlay, dblclick-жесты). Сбрасываем
   возможные легасовые отступы/фон унаследованные от .attachment. */
.attachment.video.inline {
  background: transparent;
  padding: 0;
  border: 0;
  min-height: 0;
}
.attachment.video.inline .msg-video-wrapper {
  margin: 0;          /* в .msg.bot мы давали margin-top:8px — внутри 1-1 чата не надо */
}

/* ===== Attachment preview ===== */
.attachment-preview {
  background: var(--bg-elevated); padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.att-prev-icon {
  width: 40px; height: 40px;
  background: var(--accent-dim); color: var(--accent-bright);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0; overflow: hidden;
}
.att-prev-icon img { max-width: 100%; max-height: 100%; object-fit: cover; }
.att-prev-info { flex: 1; min-width: 0; }
.att-prev-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-prev-size { font-size: 11px; color: var(--text-muted); }

/* ===== Reply bar ===== */
.reply-bar {
  background: var(--bg-elevated); padding: 8px 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.reply-bar-icon { color: var(--accent-bright); font-size: 18px; flex-shrink: 0; }
.reply-bar-content { flex: 1; min-width: 0; border-left: 2px solid var(--accent-bright); padding-left: 8px; }
.reply-bar-label { font-size: 12px; color: var(--accent-bright); font-weight: 600; }
.reply-bar-text { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Recording bar ===== */
.recording-bar {
  background: var(--bg-elevated); padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.rec-dot {
  width: 12px; height: 12px; background: var(--danger);
  border-radius: 50%; animation: pulse 1.2s infinite;
}
.rec-time { font-family: "SF Mono", Consolas, monospace; font-size: 14px; }
.rec-hint { flex: 1; color: var(--text-muted); font-size: 13px; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }

/* ===== Composer =====
   ВАЖНО: composer — flex-child внутри .chat-view (flex-column).
   НИ В КОЕМ СЛУЧАЕ не используем position: fixed — иначе iOS-клавиатура
   подымет экран и composer улетит наверх. Flex + 100dvh = iOS жмёт dvh,
   композер остаётся ровно над клавиатурой. */
.composer {
  position: relative;
  bottom: auto;
  flex-shrink: 0;
  padding: 10px 12px;
  background: var(--bg-surface);              /* фон до края — закрывает «дыру» */
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 4px;
}
#msg-input {
  flex: 1;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 16px; border-radius: 22px;
  font-size: 14px;
  transition: border-color 0.15s;
}
#msg-input:focus { border-color: var(--accent); }
#msg-input::placeholder { color: var(--text-faint); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
  box-shadow: 0 2px 10px rgba(165,29,45,0.4);
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(217,70,89,0.5);
}

/* ===== Circle recorder ===== */
.circle-recorder {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 250;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.circle-recorder-box { display: flex; flex-direction: column; align-items: center; gap: 24px; max-width: 100%; }
.circle-preview-wrap {
  width: 320px; height: 320px; max-width: 90vw; max-height: 60vh;
  aspect-ratio: 1;
  border-radius: 50%; overflow: hidden;
  background: #000; position: relative;
  box-shadow: 0 0 0 4px var(--accent-glow);
}
.circle-preview-wrap video {
  width: 100%; height: 100%; object-fit: cover;
  transform: scaleX(-1); /* зеркалим превью */
}
.circle-rec-indicator {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.7); color: white;
  padding: 4px 12px; border-radius: 14px;
  display: flex; align-items: center; gap: 6px;
  font-family: "SF Mono", Consolas, monospace; font-size: 13px;
}
.circle-recorder-controls { display: flex; gap: 12px; }

/* ===== Mesh видео-сетка для групповых звонков =====
   На 1-on-1: единственное видео занимает всю ячейку (auto-fit обеспечивает full-size).
   На N>2: grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) — адаптивная сетка. */
.video-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  padding: 8px;
  place-items: center;
  z-index: 0;
}
.video-grid video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  background: #000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.40);
}
/* В 1-on-1 (одно видео) — растягиваем на весь экран без скругления */
.video-grid:has(> video:only-child) {
  padding: 0;
  gap: 0;
}
.video-grid:has(> video:only-child) > video {
  border-radius: 0;
  box-shadow: none;
}

/* ===== Calls ===== */
.call-screen {
  position: fixed; inset: 0;
  background: var(--bg-deep);
  z-index: 9000;
  display: flex; flex-direction: column;
  -webkit-user-select: none; user-select: none;
}
.call-remote-video {
  flex: 1; width: 100%; height: 100%;
  background: #000; object-fit: cover;
}
.call-local-video {
  position: absolute; right: 16px; top: 16px;
  width: 180px; height: 240px;
  border-radius: 12px; background: #000;
  object-fit: cover; box-shadow: 0 4px 20px rgba(0,0,0,0.7);
  z-index: 9001;
  transform: scaleX(-1); /* зеркалим себя */
}
.call-info {
  position: absolute; top: 28px; left: 0; right: 0;
  text-align: center; z-index: 9002;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8);
  pointer-events: none;
}
.call-peer-name { font-size: 22px; font-weight: 600; }
.call-state { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.call-timer { font-family: "SF Mono", Consolas, monospace; font-size: 16px; margin-top: 4px; color: var(--success); }
.call-controls {
  position: absolute; bottom: 36px; left: 0; right: 0;
  display: flex; gap: 16px; justify-content: center;
  z-index: 9002; padding: 0 16px;
}
.call-btn {
  width: 60px; height: 60px; border-radius: 50%;
  background: rgba(255,255,255,0.12); color: white;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 0.1s, background 0.15s;
  border: 1px solid rgba(255,255,255,0.1);
}
.call-btn:hover { transform: scale(1.05); }
.call-btn:active { transform: scale(0.96); }
.call-btn.muted { background: rgba(217, 38, 38, 0.7); }
.call-hangup { background: var(--danger); border-color: rgba(255,255,255,0.2); }
.call-hangup:hover { background: var(--danger-hover); }
.call-accept { background: var(--success); }
.call-accept:hover { background: #5dbf61; }

/* Noise suppression toggle: active = голубое свечение, inactive = серая иконка ветра */
.call-btn-noise.active {
  background: rgba(0, 122, 255, 0.35);
  border-color: rgba(255,255,255,0.25);
  box-shadow: 0 0 12px rgba(0, 122, 255, 0.5);
}
.call-btn-noise:not(.active) {
  background: rgba(120, 120, 128, 0.30);
  opacity: 0.85;
}
.call-btn-noise .call-btn-noise-icon { font-size: 22px; line-height: 1; }

/* =====================================================================
   In-App PiP Звонки — кнопки сворачивания/разворачивания + два состояния
   ===================================================================== */

/* Кнопка «свернуть» в левом верхнем углу полноэкранного звонка */
.call-minimize-btn {
  position: absolute;
  top: max(16px, env(safe-area-inset-top, 16px));
  left: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  z-index: 9001;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, background 0.15s;
}
.call-minimize-btn:active { transform: scale(0.92); }

/* Плашка для свёрнутого audio (видна только при .call-audio-minimized) */
.call-minimized-info {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%; height: 100%;
  padding: 0 16px;
  color: #fff;
  font-family: var(--apple-font);
  font-size: 15px; font-weight: 500;
  gap: 12px;
}
.call-mini-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-mini-timer {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
  opacity: 0.9;
  min-width: 40px;
  text-align: right;
}
.call-mini-maximize {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.20);
  color: #fff; border: 0;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, background 0.15s;
}
.call-mini-maximize:active { transform: scale(0.92); }

/* ---- Состояние: AUDIO-PiP — пилюля с зелёным фоном.
       Desktop: центрирована, width: max-content (не растягивается на всю ширину).
       Mobile (<= 600px): растягивается left:16px/right:16px. ---- */
.call-screen.call-audio-minimized {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 16px));
  left: 50%;
  right: auto;
  bottom: auto;
  inset: auto;
  transform: translateX(-50%);
  width: max-content;
  min-width: 300px;
  max-width: calc(100vw - 32px);
  height: 50px;
  background: rgba(40,200,80,0.95);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: 25px;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
/* Мобилка: классическая пилюля «слева до права» */
@media (max-width: 600px) {
  .call-screen.call-audio-minimized {
    left: 16px;
    right: 16px;
    transform: none;
    width: auto;
    min-width: 0;
    max-width: none;
  }
}
/* В audio-PiP скрываем всё, кроме плашки .call-minimized-info */
.call-screen.call-audio-minimized .call-remote-video,
.call-screen.call-audio-minimized .call-local-video,
.call-screen.call-audio-minimized .call-info,
.call-screen.call-audio-minimized .call-controls,
.call-screen.call-audio-minimized .call-minimize-btn {
  display: none !important;
}
.call-screen.call-audio-minimized .call-minimized-info {
  display: flex;
}

/* ---- Состояние: VIDEO-PiP — мини-окошко с видео в углу ---- */
.call-screen.call-video-minimized {
  position: fixed;
  width: 120px;
  height: 160px;
  bottom: 80px;
  right: 16px;
  top: auto;
  left: auto;
  inset: auto;
  z-index: 999999;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.30), 0 2px 8px rgba(0,0,0,0.18);
  cursor: grab;
  touch-action: none;                    /* блокируем нативный скролл во время drag */
}
.call-screen.call-video-minimized:active { cursor: grabbing; }
/* В video-PiP скрываем всё, кроме remote-video и кнопки maximize */
.call-screen.call-video-minimized .call-local-video,
.call-screen.call-video-minimized .call-info,
.call-screen.call-video-minimized .call-controls,
.call-screen.call-video-minimized .call-minimize-btn,
.call-screen.call-video-minimized .call-minimized-info > .call-mini-label,
.call-screen.call-video-minimized .call-minimized-info > .call-mini-timer {
  display: none !important;
}
.call-screen.call-video-minimized .call-remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute; inset: 0;
}
.call-screen.call-video-minimized .call-minimized-info {
  display: flex;
  position: absolute;
  top: 8px; right: 8px;
  bottom: auto; left: auto;
  width: auto; height: auto;
  padding: 0;
  background: transparent;
  z-index: 2;
}
.call-screen.call-video-minimized .call-mini-maximize {
  background: rgba(0,0,0,0.55);
  width: 28px; height: 28px;
  font-size: 12px;
}

/* ===== Incoming call ===== */
.incoming-call {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 9100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.incoming-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  padding: 36px 40px;
  border-radius: 18px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
  animation: ringPulse 1.6s infinite;
  max-width: 100%;
}
.incoming-avatar {
  width: 96px; height: 96px; font-size: 36px; margin: 0 auto 16px;
}
.incoming-name { font-size: 22px; font-weight: 600; }
.incoming-type { color: var(--text-muted); margin: 6px 0 24px; }
.incoming-actions { display: flex; gap: 32px; justify-content: center; }
@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 22px rgba(217,70,89,0); }
}

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
  animation: fadeIn 0.15s;
}
.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 22px;
  border-radius: 14px;
  width: 480px; max-width: 100%; max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
}
.modal-box h3 { margin-bottom: 12px; color: var(--accent-bright); font-weight: 600; }
.modal-box .hint { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; line-height: 1.5; }
.modal-box .hint code { background: rgba(0,0,0,0.4); padding: 1px 5px; border-radius: 3px; }
.modal-box input[type="text"], .modal-box input[type="password"], .modal-box textarea {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px; border-radius: 8px; font-size: 14px;
  margin-bottom: 12px; resize: vertical;
}
.modal-box hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-actions .btn { width: auto; flex: 1; min-width: 100px; }
.profile-row { margin-bottom: 12px; }
.profile-row label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.name-edit-row { display: flex; gap: 6px; align-items: center; }
.name-edit-row input { flex: 1; margin-bottom: 0 !important; }

/* ===== Server / online list ===== */
.online-list { max-height: 400px; overflow-y: auto; margin-top: 8px; margin-bottom: 12px; }
.online-list::-webkit-scrollbar { width: 6px; }
.online-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
.online-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; cursor: pointer; border-radius: 6px;
  transition: background 0.1s;
}
.online-row:hover { background: var(--accent-dim); }
.online-row .avatar { width: 36px; height: 36px; font-size: 14px; }
.online-row-info { flex: 1; min-width: 0; }
.online-row-name { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-row-id { font-size: 11px; color: var(--text-faint); font-family: "SF Mono", Consolas, monospace; }
.online-row-tag { font-size: 11px; color: var(--text-muted); }
.online-empty { padding: 24px; text-align: center; color: var(--text-faint); font-size: 13px; }

.server-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--bg-deep); border-radius: 6px;
  margin-bottom: 4px; font-size: 13px;
}
.server-url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: "SF Mono", Consolas, monospace; font-size: 12px; }
.server-status { font-size: 11px; padding: 2px 6px; border-radius: 4px; flex-shrink: 0; }
.server-status.online { background: rgba(76,175,80,0.2); color: var(--success); }
.server-status.offline { background: rgba(217,38,38,0.2); color: var(--danger); }
.server-status.connecting { background: rgba(255,152,0,0.2); color: var(--warning); }
.server-row .icon-btn { width: 28px; height: 28px; font-size: 14px; }
.server-add-row { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.server-add-row input { flex: 1; margin-bottom: 0 !important; }
.server-add-row .btn { flex: 0 0 auto; }
.push-status-row {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 8px;
}
.push-status-row #push-status-text { font-weight: 500; }

.select-row {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M2 4 L6 8 L10 4' stroke='%238b8580' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 32px;
}
.select-row:focus { border-color: var(--accent); outline: none; }
.select-row option { background: var(--bg-elevated); color: var(--text); }

/* ===== Rooms ===== */
/* Phase 14.1: .emoji-suggest удалён — старая legacy-модалка снесена. */
.room-type-toggle { display: flex; gap: 6px; margin-bottom: 14px; }
.room-type-toggle label {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 10px; background: var(--bg-deep);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  text-transform: none; letter-spacing: normal; font-weight: 400;
  font-size: 13px; color: var(--text); margin-bottom: 0;
}
.room-type-toggle input[type="radio"] { accent-color: var(--accent); }
.room-type-toggle label.active { background: var(--accent-dim); border-color: var(--accent); }
.room-type-badge { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: var(--accent-dim); color: var(--accent-bright); margin-left: 4px; vertical-align: middle; }
/* Phase 15.4: бот-парсер — отдельный визуальный класс */
.room-type-badge.bot { background: rgba(229, 46, 45, 0.18); color: var(--accent-color, #E52E2D); }

/* ===== Channels ===== */
.channel-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; cursor: pointer; border-radius: 6px;
  transition: background 0.1s;
}
.channel-row:hover { background: var(--accent-dim); }
.channel-row .avatar {
  width: 44px; height: 44px; font-size: 16px;
  background: linear-gradient(135deg, var(--accent), #4a0d18);
}
.channel-row-info { flex: 1; min-width: 0; }
.channel-row-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-row-meta { font-size: 11px; color: var(--text-muted); }
.channel-row-tag { font-size: 11px; color: var(--accent-bright); }

/* Композер поста: сетка превью с подписью под каждой */
.post-attach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px; margin-top: 12px;
}
.post-attach-item {
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
  display: flex; flex-direction: column;
}
.post-attach-item img {
  width: 100%; height: 100px; object-fit: cover; display: block;
}
.post-attach-item input {
  border: none; border-top: 1px solid var(--border);
  background: transparent; color: var(--text);
  padding: 6px 8px; font-size: 12px; outline: none;
}
.post-attach-item .att-remove {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.6); color: white;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 12px; line-height: 1;
}
.post-attach-wrap { position: relative; }

/* Лента постов в канале */
.channel-feed {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.channel-feed::-webkit-scrollbar { width: 6px; }
.channel-feed::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

.post-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  max-width: 640px;
  width: 100%;
  align-self: center;
}
.post-card .post-author {
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 6px;
  display: flex; align-items: baseline; gap: 8px;
}
.post-card .post-author .post-time { color: var(--text-faint); font-size: 11px; }
.post-card .post-text {
  font-size: 14px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
  margin-bottom: 8px;
}
.post-card .post-text:empty { display: none; }

.post-images {
  display: grid;
  gap: 4px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 8px;
}
.post-images.cnt-1 { grid-template-columns: 1fr; }
.post-images.cnt-2 { grid-template-columns: 1fr 1fr; }
.post-images.cnt-3 { grid-template-columns: 1fr 1fr 1fr; }
.post-images.cnt-4 { grid-template-columns: 1fr 1fr; }
.post-images.cnt-many { grid-template-columns: 1fr 1fr 1fr; }
.post-image {
  position: relative;
  background: var(--bg-deep);
  cursor: pointer;
  aspect-ratio: 1;
  overflow: hidden;
}
.post-images.cnt-1 .post-image { aspect-ratio: 16/10; max-height: 480px; }
.post-image img { width: 100%; height: 100%; object-fit: cover; }
.post-image .post-caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 8px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  color: white; font-size: 12px;
  pointer-events: none;
}

.post-actions {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 4px;
  font-size: 12px;
}
.post-react {
  background: rgba(0,0,0,0.3); color: var(--text); padding: 4px 10px;
  border-radius: 12px; cursor: pointer; transition: all 0.12s;
  border: 1px solid transparent;
  user-select: none;
  -webkit-user-select: none;
  font-size: 13px;
}
.post-react:hover { background: rgba(0,0,0,0.5); border-color: var(--accent); }
.post-react:active { transform: scale(0.94); }
.post-react.mine {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-bright);
  font-weight: 600;
}
.post-react.heart {
  background: rgba(217, 70, 89, 0.18);
  border-color: rgba(217, 70, 89, 0.5);
}
.post-react.heart:hover { background: rgba(217, 70, 89, 0.3); }
.post-react-add {
  font-weight: 700;
  font-size: 16px;
  padding: 2px 10px 4px;
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
}
.post-react-add:hover { border-style: solid; border-color: var(--accent); }
.post-views { color: var(--text-faint); margin-left: auto; align-self: center; }

.feed-loader {
  text-align: center; color: var(--text-muted);
  padding: 12px; font-size: 12px;
}

.channel-empty {
  text-align: center; color: var(--text-muted);
  padding: 60px 20px; font-size: 14px;
}

/* Кнопка нового поста — внизу справа */
.fab-new-post {
  position: absolute; bottom: 20px; right: 20px;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: white;
  font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(165,29,45,0.5);
  z-index: 5;
  border: none;
}
.fab-new-post:hover { background: var(--accent-hover); transform: scale(1.05); }

/* ===== Polls ===== */
.poll-card {
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  padding: 12px;
  max-width: 360px;
  margin-bottom: 4px;
}
.poll-question {
  font-weight: 600; font-size: 14px; line-height: 1.35;
  margin-bottom: 4px;
  word-break: break-word;
}
.poll-meta {
  font-size: 11px; color: var(--text-muted);
  margin-bottom: 10px;
}
.poll-options { display: flex; flex-direction: column; gap: 4px; }
.poll-option {
  position: relative;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.1s;
}
.poll-option:hover { border-color: var(--accent); }
.poll-option.voted {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.poll-option-bar {
  position: absolute; top: 0; left: 0; bottom: 0;
  background: rgba(217, 70, 89, 0.18);
  transition: width 0.3s ease;
  pointer-events: none;
}
.poll-option.voted .poll-option-bar { background: rgba(217, 70, 89, 0.32); }
.poll-option-row {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
.poll-option-check {
  width: 14px; height: 14px; flex-shrink: 0;
  font-weight: 700; color: var(--accent-bright);
  text-align: center;
}
.poll-option-text {
  flex: 1; min-width: 0;
  white-space: pre-wrap; word-break: break-word;
}
.poll-option-pct {
  font-size: 12px; color: var(--text-muted);
  font-weight: 600; flex-shrink: 0;
}
.poll-option-count {
  font-size: 11px; color: var(--text-faint); margin-left: 4px;
}

/* ===== Bot-filter constructor ===== */
.chip-pool {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px; background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: 8px; min-height: 44px;
}
.chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 16px;
  cursor: pointer; font-size: 13px;
  color: var(--text);
  transition: all 0.12s;
  user-select: none;
}
.chip:hover { border-color: var(--accent); }
.chip.on {
  background: var(--accent); border-color: var(--accent);
  color: white; font-weight: 600;
}

.dyn-list { display: flex; flex-direction: column; gap: 6px; }
.dyn-row {
  display: flex; gap: 6px; align-items: center;
}
.dyn-row input {
  flex: 1; min-width: 0;
  background: var(--bg-deep); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px;
  border-radius: 8px; font-size: 14px;
  margin: 0 !important;
}
.dyn-row input:focus { border-color: var(--accent); }
.dyn-row .icon-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  background: var(--bg-elevated);
  color: var(--danger);
}
.dyn-row .icon-btn:hover { background: rgba(217,38,38,0.18); }

/* Карточка доставки в ленте бота */
.bot-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  max-width: 640px; width: 100%;
  align-self: center;
}
.bot-card .bot-card-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-muted);
  margin-bottom: 6px;
}
.bot-card .bot-source-tag {
  background: var(--accent-dim);
  color: var(--accent-bright);
  padding: 2px 8px; border-radius: 10px;
  font-weight: 600; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.bot-card .bot-card-title {
  font-weight: 600; font-size: 15px;
  margin-bottom: 4px;
  line-height: 1.35;
}
.bot-card .bot-card-title a { color: var(--accent-bright); text-decoration: none; }
.bot-card .bot-card-title a:hover { text-decoration: underline; }
.bot-card .bot-card-body {
  font-size: 13px; line-height: 1.45;
  color: var(--text); white-space: pre-wrap; word-break: break-word;
  -webkit-line-clamp: 6; -webkit-box-orient: vertical;
  display: -webkit-box; overflow: hidden;
}
.bot-card .bot-card-hits {
  margin-top: 8px; display: flex; gap: 4px; flex-wrap: wrap;
}
.bot-card .bot-hit-kw {
  background: var(--gold); color: var(--bg-deep);
  padding: 1px 8px; border-radius: 8px;
  font-size: 11px; font-weight: 700;
}

/* Аватар бота в chat-list */
.avatar.bot {
  background: var(--apple-bg-secondary);
  color: var(--accent);
  font-size: 20px;
  border: 1px solid var(--border-strong);
}

/* Источники со статусом ошибки в инфо-панели */
.bot-source-status {
  font-size: 11px; padding: 2px 6px; border-radius: 4px;
}
.bot-source-status.ok { background: rgba(76,175,80,0.18); color: var(--success); }
.bot-source-status.err { background: rgba(217,38,38,0.18); color: var(--danger); }
.bot-source-status.disabled { background: rgba(255,152,0,0.18); color: var(--warning); }

/* =====================================================================
   Bot-parser constructor — Apple HIG Inset Grouped List
   ===================================================================== */
/* Модалка целиком — светло-серый iOS Settings бэкграунд */
.bot-modal { padding: 0; align-items: stretch; justify-content: stretch; background: rgba(0,0,0,0.4); }
.bot-modal-box {
  background: var(--apple-bg-secondary);    /* #F2F2F7 — фон iOS Settings */
  width: 560px; max-width: 100%;
  height: 100%; max-height: 100%;
  margin: 0 auto;
  display: flex; flex-direction: column;
  overflow: hidden;
  font-family: var(--apple-font);
}
@media (min-width: 769px) {
  .bot-modal { align-items: center; padding: 16px; }
  .bot-modal-box { max-height: 92vh; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
}

/* Шапка: Отмена / Заголовок / Готово */
.ios-modal-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, calc(env(safe-area-inset-top, 0px) + 8px));
  background: var(--apple-bg-secondary);
  border-bottom: 1px solid var(--apple-separator);
}
.ios-modal-header .ios-modal-title {
  font-size: 17px; font-weight: 600;
  color: var(--apple-text);
  flex: 1; text-align: center;
}
.ios-modal-cancel, .ios-modal-done {
  background: transparent; border: 0; padding: 0;
  font-size: 17px; cursor: pointer;
  font-family: var(--apple-font);
  -webkit-tap-highlight-color: transparent;
  min-width: 60px;
}
.ios-modal-cancel { color: var(--accent); text-align: left; }
.ios-modal-done   { color: var(--accent); font-weight: 600; text-align: right; }
.ios-modal-cancel:active, .ios-modal-done:active { opacity: 0.5; }

/* Скроллируемое тело */
.ios-modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 16px 32px;
  padding-bottom: max(32px, calc(env(safe-area-inset-bottom, 0px) + 24px));
}

/* Группа = заголовок + карточка(и) */
.ios-group { margin-bottom: 24px; }
.ios-group:last-child { margin-bottom: 0; }
.ios-group-title {
  font-size: 13px; font-weight: 400;
  color: var(--apple-text-muted);
  text-transform: uppercase;
  letter-spacing: -0.08px;
  padding: 0 16px 6px;
  margin: 0;
}

/* Белая карточка с группой настроек */
.ios-card {
  /* Phase 13.1: dark-mode compatible — белые «карточки» в OLED становятся #111 */
  background: var(--apple-bg-secondary);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
}
.ios-card.flush { padding: 0; }

/* Строка внутри карточки: label слева, значение / input справа */
.ios-row {
  display: flex; align-items: center;
  padding: 11px 16px;
  border-top: 0.5px solid var(--apple-separator);
  gap: 12px;
  min-height: 44px;
  font-size: 17px;
}
.ios-row:first-child { border-top: 0; }
.ios-row > label {
  flex-shrink: 0;
  color: var(--apple-text);
  font-size: 17px;
  font-weight: 400;
  letter-spacing: -0.4px;
}
.ios-row > input[type="text"], .ios-row > .ios-select {
  flex: 1;
  border: 0; background: transparent;
  padding: 0;
  margin: 0 !important;
  font-size: 17px;
  font-family: var(--apple-font);
  color: var(--apple-text);
  text-align: right;
  min-width: 0;
}
.ios-row > input[type="text"]::placeholder { color: var(--apple-text-tertiary); }
.ios-row > input[type="text"]:focus { outline: none; }
.ios-row.column {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px 16px;
}
.ios-row.column > label {
  font-size: 13px;
  color: var(--apple-text-muted);
  letter-spacing: 0.1px;
  text-transform: none;
}
.ios-row-hint {
  font-size: 12px;
  color: var(--apple-text-muted);
  padding: 0;
}

/* Стилизованный <select> в iOS-стиле */
.ios-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M3 4.5 L6 7.5 L9 4.5' stroke='%238E8E93' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0 center;
  background-size: 12px;
  padding-right: 18px;
  cursor: pointer;
  color: var(--apple-text-muted);
}
.ios-select option { color: var(--apple-text); }

/* Секция внутри карточки (под segmented control) */
.ios-card-section {
  border-top: 0.5px solid var(--apple-separator);
}

/* Phase 15: legacy .platform-grid / .platform-cell удалены — старый бот-конструктор снесён. */

/* iOS Segmented Control */
.segmented-control {
  display: flex;
  background: var(--apple-bg-secondary);
  border-radius: 9px;
  padding: 2px;
  margin: 10px 14px;
  position: relative;
}
.segmented-control .seg-opt {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 6px 12px;
  font-size: 13px; font-weight: 500;
  font-family: var(--apple-font);
  color: var(--apple-text);
  border-radius: 7px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.18s, box-shadow 0.18s;
}
.segmented-control .seg-opt.active {
  background: #FFF;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08), 0 1px 1px rgba(0,0,0,0.04);
}

/* Phase 15: legacy бот-конструктор стили удалены полностью.
   .chip-input / .sources-list / .ios-add-btn / .ios-form-error / .btn-create-parser /
   .bot-avatar-row / .bot-avatar-wrap / #bot-avatar-preview — старый UI снесён.
   Новый Unified Bot Constructor использует .app-modal-* + .bc-*. */

/* =====================================================================
   Apple HIG: переиспользуемые компоненты для вкладки Профиля и Настроек
   ===================================================================== */

/* Hero-карточка профиля: большая squircle-аватарка, имя, био. Tap → редактирование. */
.profile-view {
  padding: 16px;
  padding-top: max(24px, calc(env(safe-area-inset-top, 0px) + 16px));
}
.profile-hero {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 16px 16px 24px;
  cursor: pointer;
  font-family: var(--apple-font);
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s;
}
.profile-hero:active { opacity: 0.7; }
.profile-hero-avatar.avatar {
  width: 100px; height: 100px;
  font-size: 38px;
  border-radius: var(--apple-squircle);
  box-shadow: 0 2px 14px rgba(0,0,0,0.10);
}
.profile-hero-name {
  font-size: 22px; font-weight: 700;
  color: var(--apple-text);
  letter-spacing: -0.4px;
  text-align: center;
}
.profile-hero-bio {
  font-size: 14px;
  color: var(--apple-text-muted);
  text-align: center;
  max-width: 260px;
  line-height: 1.35;
}
.profile-hero-bio:empty::before {
  content: "Tap to edit";
  color: var(--apple-text-tertiary);
  font-style: italic;
}

/* Кнопка-строка внутри .ios-card: иконка слева, лейбл, шеврон справа. */
.ios-row-action {
  display: flex; align-items: center;
  gap: 12px;
  width: 100%;
  background: transparent;
  border: 0;
  border-top: 0.5px solid var(--apple-separator);
  padding: 12px 16px;
  font-family: var(--apple-font);
  font-size: 17px;
  color: var(--apple-text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
  min-height: 44px;
}
.ios-row-action:first-child { border-top: 0; }
.ios-row-action:active { background: var(--apple-bg-secondary); }
.ios-row-icon {
  font-size: 20px;
  width: 28px; text-align: center;
  flex-shrink: 0;
}
.ios-row-label { flex: 1; font-weight: 400; }

/* Apple-style шеврон в конце ряда */
.ios-chevron {
  flex-shrink: 0;
  width: 12px;
  color: var(--apple-text-tertiary);
  display: inline-flex; align-items: center; justify-content: flex-end;
}
.ios-chevron::after {
  content: "›";
  font-size: 22px;
  line-height: 1;
  font-weight: 400;
  font-family: var(--apple-font);
}

/* Красная «опасная» строка */
.ios-row-danger { color: #FF3B30; }
.ios-row-danger .ios-row-icon { color: #FF3B30; }
.ios-row-danger .ios-row-label { color: #FF3B30; font-weight: 400; }
.ios-row-danger .ios-chevron { display: none; }

/* Inline-кнопка внутри .ios-row.column (например «Копировать строку») */
.ios-inline-btn {
  display: inline-block;
  background: rgba(0,122,255,0.10);
  color: #007AFF;
  border: 0;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 14px; font-weight: 500;
  font-family: var(--apple-font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  align-self: flex-start;
  transition: opacity 0.12s;
}
.ios-inline-btn:active { opacity: 0.6; }
.ios-inline-btn-muted {
  background: var(--apple-bg-secondary);
  color: var(--apple-text);
}

/* Полноразмерный select внутри ios-row.column */
.ios-select-block {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--apple-bg-secondary);
  color: var(--apple-text);
  border: 0;
  border-radius: 10px;
  padding: 12px 36px 12px 14px;
  font-size: 15px;
  font-family: var(--apple-font);
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M3 4.5 L6 7.5 L9 4.5' stroke='%238E8E93' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
}

/* В Settings: textarea и input одинакового вида */
#modal-settings textarea,
#modal-settings input[type="text"] {
  width: 100%;
  background: var(--apple-bg-secondary);
  color: var(--apple-text);
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--apple-font);
  resize: vertical;
  margin: 0 !important;
}
#modal-settings textarea { font-family: "SF Mono", Consolas, monospace; font-size: 12px; }
#modal-settings #servers-list { margin-top: 4px; }

/* Переключение содержимого sidebar-content между вкладками.
   ВАЖНО: каждое правило строго scoped под .sidebar.tab-profile —
   никаких глобальных селекторов с одиночным #chat-list, иначе чаты
   пропадут навсегда. Также: НЕ ставим [hidden] на #profile-view —
   глобальное [hidden]{display:none!important} победит этот display:block. */
#profile-view { display: none; }
.sidebar.tab-profile #pinned-row,
.sidebar.tab-profile #chat-list { display: none !important; }
.sidebar.tab-profile #profile-view { display: block; }

/* =====================================================================
   Phase 1: Ephemeral messages — UI для редактирования + chat-info
   ===================================================================== */

/* Маленькая метка «ред.» внутри .msg-meta — рядом со временем и галочкой */
.msg-edited {
  font-size: 10px;
  opacity: 0.65;
  margin-right: 4px;
  font-style: italic;
  letter-spacing: 0.1px;
}
.msg.out .msg-edited { color: rgba(255,255,255,0.85); }
.msg.in  .msg-edited { color: var(--apple-text-muted); }

/* Edit-bar — pattern совпадает с #reply-bar (.reply-bar). Используем CSS-класс
   .reply-bar (уже стилизованный) + добавляем тонкую красную полосу слева, чтобы
   визуально отличать режим редактирования от ответа. */
.edit-bar.reply-bar {
  border-left: 3px solid var(--accent);
  background: rgba(255,59,48,0.06);
}
.edit-bar .reply-bar-icon {
  color: var(--accent);
}

/* peer-info теперь <button> — сбрасываем стиль и делаем кликабельным */
.chat-header .peer-info {
  background: transparent;
  border: 0;
  text-align: left;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
  min-width: 0;
  flex: 1;
  transition: opacity 0.12s;
}
.chat-header .peer-info:active { opacity: 0.6; }

/* Phase 14.5: стили .chat-info-hero / .chat-info-avatar / .chat-info-name /
   .chat-info-id удалены вместе с #modal-chat-info. */

/* =====================================================================
   Phase 10: Каталог публичных каналов — список с разделителями + кнопка Join
   ===================================================================== */
.discover-channel-row {
  display: flex; align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 0.5px solid var(--apple-separator);
  min-height: 56px;
}
.discover-channel-row:first-child { border-top: 0; }
.discover-channel-row .avatar {
  width: 44px; height: 44px;
  font-size: 18px;
  flex-shrink: 0;
}
.discover-channel-meta {
  flex: 1; min-width: 0;
}
.discover-channel-name {
  font-size: 16px; font-weight: 500;
  color: var(--apple-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.discover-channel-members {
  font-size: 12px; color: var(--apple-text-muted);
  margin-top: 2px;
}
.discover-channel-join-btn {
  flex-shrink: 0;
  background: rgba(0,122,255,0.12);
  color: #007AFF;
  border: 0;
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 14px; font-weight: 600;
  font-family: var(--apple-font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s, background 0.12s;
}
.discover-channel-join-btn:active { opacity: 0.6; }
.discover-channel-join-btn.joined {
  background: rgba(52,199,89,0.16);
  color: #1B7F3A;
  cursor: default;
}
.discover-channel-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--apple-text-muted);
  font-size: 14px;
}

/* Phase 11: история редактирования сообщения */
.edit-history-entry {
  padding: 12px 16px;
  border-top: 0.5px solid var(--apple-separator);
}
.edit-history-entry:first-child { border-top: 0; }
.edit-history-current {
  background: rgba(0,122,255,0.06);
}
.edit-history-meta {
  font-size: 11px;
  color: var(--apple-text-muted);
  margin-bottom: 4px;
  font-family: var(--apple-font);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.edit-history-current .edit-history-meta {
  color: #007AFF;
  font-weight: 600;
}
.edit-history-text {
  font-size: 15px;
  color: var(--apple-text);
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.4;
}

/* =====================================================================
   Phase 11.1: #modal-edit-history → Apple Bottom Sheet на мобилке.
   На десктопе/планшете остаётся обычной центрированной модалкой (bot-modal).
   ===================================================================== */
@media (max-width: 600px) {
  /* Wrapper становится полупрозрачным оверлеем; контент прижат к низу */
  #modal-edit-history {
    position: fixed;
    top: auto; bottom: 0; left: 0; right: 0;
    inset: 0;
    height: 100%; width: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;          /* контент прижат вниз */
    align-items: stretch;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  /* [hidden] глобально прячет — но когда hidden снят, активируем */
  #modal-edit-history:not([hidden]) {
    opacity: 1;
    pointer-events: auto;
  }

  /* Карточка-шторка: 50dvh, выезжает снизу */
  #modal-edit-history .bot-modal-box {
    position: relative;
    height: 50dvh;
    width: 100%;
    max-height: calc(100% - 60px);     /* защита от перекрытия notch'а */
    margin: 0;
    border-radius: 20px 20px 0 0;       /* скруглён только верх */
    background: var(--bg-surface);
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  #modal-edit-history:not([hidden]) .bot-modal-box {
    transform: translateY(0);
  }

  /* Шапка-шторка чуть компактнее, разделитель */
  #modal-edit-history .ios-modal-header {
    padding: 12px 16px;
    border-bottom: 0.5px solid var(--apple-separator);
    background: var(--bg-surface);
    flex-shrink: 0;
  }

  /* Тело — скроллируемое (свежее сообщение сверху) */
  #modal-edit-history .ios-modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 0 24px;
  }
}

/* =====================================================================
   Apple HIG iOS-style Switch (тумблер)
   ===================================================================== */
.ios-switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}
.ios-switch input[type="checkbox"] {
  opacity: 0;
  width: 100%; height: 100%;
  position: absolute; inset: 0;
  margin: 0; padding: 0;
  z-index: 2;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.ios-switch-track {
  position: absolute; inset: 0;
  background: #E9E9EA;                  /* iOS systemFill light off */
  border-radius: 16px;
  transition: background 0.2s ease;
}
.ios-switch-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  background: #FFFFFF;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15), 0 1px 2px rgba(0,0,0,0.06);
  transition: transform 0.22s cubic-bezier(0.34, 1.20, 0.64, 1);
  pointer-events: none;
}
/* Checked state — двигаем thumb вправо + меняем фон дорожки на iOS-green */
.ios-switch input[type="checkbox"]:checked ~ .ios-switch-track {
  background: #34C759;                  /* iOS systemGreen */
}
.ios-switch input[type="checkbox"]:checked ~ .ios-switch-thumb {
  transform: translateX(20px);
}

/* =====================================================================
   Модалка удаления сообщения (Apple HIG style)
   ===================================================================== */
.bot-modal-box.delete-msg-box {
  max-width: 360px;
  width: 100%;
  height: auto;
  max-height: none;
  margin: auto;
  border-radius: 16px;
  align-self: center;
}
.delete-msg-title {
  padding: 16px 16px 4px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  color: var(--apple-text);
}
.delete-msg-subtitle {
  padding: 0 16px 16px;
  font-size: 13px;
  text-align: center;
  color: var(--apple-text-muted);
}
.delete-msg-row-switch {
  padding: 10px 16px;
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.delete-msg-row-switch .ios-row-label {
  flex: 1;
  font-size: 17px;
}
.delete-msg-actions {
  display: flex; flex-direction: column;
  gap: 8px;
  padding: 0 16px;
}
.btn-delete-msg-confirm {
  width: 100%;
  background: #FF3B30;                  /* iOS systemRed */
  color: #FFF;
  border: 0;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 17px; font-weight: 600;
  font-family: var(--apple-font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 14px rgba(255,59,48,0.18);
  transition: transform 0.08s ease, opacity 0.12s ease;
}
.btn-delete-msg-confirm:active { transform: scale(0.98); opacity: 0.92; }
.btn-delete-msg-cancel {
  width: 100%;
  background: var(--apple-bg-secondary);
  color: var(--apple-text);
  border: 0;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 17px; font-weight: 500;
  font-family: var(--apple-font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-delete-msg-cancel:active { background: #E5E5EA; }
/* Модалка delete на mobile стоит как bottom-sheet с центрированием */
.bot-modal.modal:has(.delete-msg-box) {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ===== Image viewer ===== */
.image-viewer {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.95); z-index: 300;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.image-viewer img { max-width: 96vw; max-height: 96vh; border-radius: 4px; }
.image-close {
  position: absolute; top: 20px; right: 20px;
  background: rgba(255,255,255,0.1); color: white;
  width: 40px; height: 40px; border-radius: 50%; font-size: 18px;
}
.image-close:hover { background: rgba(255,255,255,0.2); }

/* ===== Location ===== */
.attachment.location {
  cursor: pointer; background: rgba(0,0,0,0.3);
  border-radius: 8px; overflow: hidden;
  width: 280px; display: block;
  text-decoration: none; color: inherit;
}
.attachment.location img {
  width: 100%; height: 160px; object-fit: cover; display: block;
  background: var(--bg-elevated);
}
.attachment.location .loc-info {
  padding: 8px 12px;
  display: flex; align-items: center; gap: 8px;
}
.attachment.location .loc-icon { font-size: 18px; color: var(--accent-bright); }
.attachment.location .loc-text { flex: 1; min-width: 0; }
.attachment.location .loc-title { font-size: 13px; font-weight: 500; }
.attachment.location .loc-coords { font-size: 11px; color: var(--text-muted); font-family: "SF Mono", Consolas, monospace; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 9500; font-size: 14px;
  animation: slideUp 0.2s; max-width: 90vw;
}
.toast.error { background: var(--danger); border-color: var(--danger); color: white; }
.toast.success { background: var(--success); border-color: var(--success); color: white; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ===== Mobile keyboard / viewport fixes ===== */
/* Никакого rubber-band overscroll на body — иначе шапка чата уезжает */
html, body { overscroll-behavior: none; }

/* Визуальный вьюпорт (учитывает клавиатуру). По умолчанию = 100dvh.
   JS обновляет в пикселях через visualViewport API для старых iOS, где dvh
   не сжимается полностью при появлении клавиатуры. */
:root {
  --vv-height: 100dvh;
  --kb-offset: 0px;
  /* --sab — safe-area-inset-bottom как числовая величина для JS.
     Читается через getComputedStyle(...).getPropertyValue('--sab').
     На iPhone без notch'а → 0px; на iPhone X+ → ~34px. */
  --sab: env(safe-area-inset-bottom, 0px);
}
@supports not (height: 100dvh) { :root { --vv-height: 100vh; } }

/* ===== Adaptive: phones (portrait + small landscape) ===== */
@media (max-width: 768px) {
  /* Заполняем фон под status bar / home indicator одинаковым цветом */
  html, body { background: var(--bg-deep); }

  /* Закрепляем app, чтобы iOS не мог "пролистнуть" страницу при появлении клавиатуры.
     --app-height — единая высота, обновляется JS-функцией syncAppHeight
     покадрово через visualViewport. Если JS отвалился — fallback на CSS dvh. */
  #app-screen.active {
    position: fixed; inset: 0;
    width: 100%;
    height: var(--app-height);
    background: var(--bg-deep);
    display: flex;
    flex-direction: row;
  }
  /* В режиме открытого чата экран — flex-колонка от верха до низа.
     Высота тоже привязана к --app-height — поле ввода едет вместе с клавиатурой. */
  #app-screen.show-chat {
    height: var(--app-height);
    display: flex;
    flex-direction: column;
  }
  /* Шапки уважают safe-area сверху (notch / Dynamic Island).
     Используем var(--safe-top) — JS его выставляет с правильным значением
     даже когда env() возвращает 0 (бывает в iOS PWA в некоторых случаях). */
  .chat-header {
    padding-top: max(10px, calc(var(--safe-top, env(safe-area-inset-top, 0px)) + 6px));
  }
  /* sidebar-header — flex-аккордеон. Базовое padding-top: 0 (закрыт).
     При .sidebar.search-active — гарантированный отступ под notch:
     max(env, 47px) подстрахует iOS PWA standalone, где env() иногда отдаёт 0. */
  .sidebar.search-active .sidebar-header {
    padding-top: max(env(safe-area-inset-top), 47px);
  }
  /* Боковые отступы тоже учитываем (landscape с notch) */
  .chat-header, .sidebar-header, .composer, .messages {
    padding-left: max(var(--side-pad, 12px), env(safe-area-inset-left, 0px));
    padding-right: max(var(--side-pad, 12px), env(safe-area-inset-right, 0px));
  }
  .composer { --side-pad: 8px; }
  .messages { --side-pad: 12px; }
}
/* Для PWA standalone на iPhone: если env() сглючил и вернул 0, дадим разумный дефолт */
@media (display-mode: standalone) and (max-width: 768px) {
  .chat-header { padding-top: max(50px, calc(var(--safe-top, env(safe-area-inset-top, 0px)) + 8px)); }
  /* PWA standalone: env() может вернуть 0 — max(..., 47px) гарантирует место под notch */
  .sidebar.search-active .sidebar-header { padding-top: max(env(safe-area-inset-top), 47px); }
  /* Pinned-row сам уважает safe-area сверху, т.к. header теперь схлопнут */
  .pinned-row { padding-top: max(12px, calc(var(--safe-top, env(safe-area-inset-top, 0px)) + 8px)); }
}
@media (max-width: 768px) {
  /* Возобновляем оставшуюся часть медиа-блока (ниже идут другие правила) */
  .sidebar {
    width: 100%; position: absolute;
    z-index: 10; height: 100%;
    transition: transform 0.25s ease;
  }
  #app-screen.show-chat .sidebar { transform: translateX(-100%); }
  /* Flex chain: app-screen.show-chat → chat-area → chat-view → (header / messages / composer)
     гарантирует, что 100dvh сжимается клавиатурой и composer остаётся на месте. */
  .chat-area { width: 100%; height: 100%; flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .chat-view { height: 100%; flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  /* Чат-вью: header — sticky к самому верху чат-area, чтобы случайно не уехал */
  .chat-header {
    position: sticky; top: 0;
    z-index: 5;
    /* подстрахует если родитель внезапно станет скроллируемым */
  }
  /* Композер — flex-child в .chat-view (flex column).
     position: relative + flex-shrink: 0 + bottom: auto: при поднятии клавиатуры
     iOS жмёт 100dvh, и composer остаётся ровно над ней (никаких улетающих инпутов).
     Безопасная зона от home indicator — через padding-bottom env(...), без сдвига. */
  .composer {
    position: relative;
    bottom: auto;
    flex-shrink: 0;
    padding: 8px 8px;
    padding-bottom: env(safe-area-inset-bottom);
    gap: 2px;
    background: var(--bg-surface);
  }
  /* Чтобы input не "выпихивал" send-кнопку вправо при длинном тексте */
  #msg-input {
    flex: 1; min-width: 0;
    padding: 10px 14px;
    font-size: 16px; /* против iOS zoom-in */
  }
  .composer .icon-btn { width: 36px; height: 36px; }
  .send-btn { width: 40px; height: 40px; flex-shrink: 0; }
  .btn-back-mobile { display: flex; }
  .auth-container { padding: 32px 24px; border-radius: 14px; }
  .auth-container h1 { font-size: 24px; }
  .auth-title { font-size: 22px; }
  .modal-box { padding: 18px; border-radius: 12px; }
  .modal-actions .btn { min-width: auto; flex: 1; }
  .msg { max-width: 85%; font-size: 15px; }
  .messages { padding: 12px 12px; }
  /* НЕ переопределяем padding целиком — иначе теряется padding-top с safe-area.
     Меняем только нужные стороны через longhand. */
  .chat-header { padding-bottom: 10px; gap: 6px; }
  .sidebar-content { -webkit-overflow-scrolling: touch; }
  .circle-preview-wrap { width: 240px; height: 240px; }
  .call-local-video { width: 96px; height: 128px; right: 10px; top: 10px; }
  .call-controls { bottom: 24px; gap: 12px; }
  .call-btn { width: 56px; height: 56px; font-size: 20px; }
  .incoming-card { padding: 28px 24px; }
  .incoming-avatar { width: 80px; height: 80px; font-size: 32px; }
  .reaction-picker { max-width: 92vw; flex-wrap: wrap; justify-content: center; }
  /* Phase 11.1: на мобилке реакции ставятся ТОЛЬКО через #msg-menu-reactions
     внутри Action Stack меню. Inline-кнопку на пузыре жёстко прячем. */
  .msg-react-btn,
  .msg-react-quick-btn,
  .msg-inline-react-btn { display: none !important; }
  body { font-size: 15px; }

  /* Toggle компактнее на мобилке: только иконки */
  .route-opt .full { display: none; }
  .route-opt .compact { display: inline; }
  .route-opt { padding: 5px 8px; font-size: 14px; }
}

/* Очень маленькие экраны */
@media (max-width: 380px) {
  .sidebar-buttons .btn { font-size: 11px; padding: 8px 4px; }
  .auth-container { padding: 22px 16px; }
  .modal-box { padding: 14px; }
  .call-btn { width: 50px; height: 50px; font-size: 18px; }
  .call-controls { gap: 10px; }
}

/* Альбомная ориентация телефонов */
@media (max-height: 480px) and (orientation: landscape) {
  .auth-container { padding: 20px; }
  .auth-logo .cat-logo { width: 48px; height: 48px; }
  .auth-container h1 { font-size: 22px; margin-bottom: 4px; }
  .auth-subtitle { margin-bottom: 16px; }
  .call-info { top: 10px; }
  .call-peer-name { font-size: 18px; }
  .call-controls { bottom: 16px; }
  .call-btn { width: 48px; height: 48px; }
  .call-local-video { width: 88px; height: 66px; }
}

/* Touch-friendly: всё что меньше 40px - увеличиваем */
@media (hover: none) and (pointer: coarse) {
  .icon-btn { width: 42px; height: 42px; }
  .msg-react-btn { width: 32px; height: 32px; }
  .reaction-chip { padding: 4px 10px; font-size: 13px; }
  .reaction-picker button { width: 40px; height: 40px; font-size: 24px; }
}

/* =====================================================================
   Apple-HIG Mobile shell:
   • Bottom Tab Bar (mobile) / тонкий sidebar (desktop)
   • Context Sheet (bottom action sheet)
   • Squircle-аватарка (profile)
   • Focus Mode badge (показывает активный режим)
   ===================================================================== */

/* ---------- Squircle (border-radius в iOS-стиле) ---------- */
.avatar.squircle,
.app-squircle {
  border-radius: var(--apple-squircle);
}

/* ---------- Bottom Tab Bar ----------
   Монолитный блок: фиксированная высота 56px на контент + env(safe-area-inset-bottom)
   на home-indicator. align-items: center центрирует иконки в верхней (контентной) части.
   padding-bottom = env() — фон тянется до самого низа экрана, никакой «дыры». */
/* Phase 13: blurred translucent backdrop (Apple-style) */
.bottom-tabs {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 90;
  background: var(--nav-bg);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-top: 0.5px solid var(--divider);
  height: calc(56px + env(safe-area-inset-bottom));
  padding-top: 0;
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  justify-content: space-around;
  align-items: center;                   /* Иконки центрированы в 56px-полосе */
  box-sizing: border-box;
  -webkit-user-select: none; user-select: none;
}
.bottom-tabs .tab-btn {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 8px 0 6px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  color: var(--text-secondary);             /* Phase 13: inactive — text-secondary */
  font-family: var(--apple-font);
  font-size: 10px; font-weight: 500;
  letter-spacing: 0.1px;
  cursor: pointer;
  transition: color 0.12s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.bottom-tabs .tab-btn:active { transform: scale(0.92); }
/* Phase 13: активный таб — Ferrari Red текст + filled SVG */
.bottom-tabs .tab-btn.active { color: var(--accent); }
/* Phase 13: иконки контурные (outline) — stroke text-secondary, fill: none */
.bottom-tabs .tab-btn svg {
  width: 26px; height: 26px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  transition: fill 0.15s, stroke 0.15s;
}
/* Активный таб — иконка залита Ferrari Red */
.bottom-tabs .tab-btn.active svg {
  fill: var(--accent);
  stroke: var(--accent);
}
/* Лейбл под иконкой; на узких экранах прячем чтобы оставить только иконку */
.bottom-tabs .tab-btn .tab-label { line-height: 1; opacity: 0.9; }

/* Мобилка: показываем bottom-tabs, прячем существующую кнопочную панель в сайдбаре,
   у списка чатов оставляем место под таб-баром */
@media (max-width: 768px) {
  .bottom-tabs { display: flex; }
  /* Контент сайдбара чуть короче, чтобы последний чат не уходил под таб-бар.
     Padding на скролл-контейнере (.sidebar-content), не на .chat-list — он больше
     не скроллится сам, а его последний элемент может оказаться под таб-баром. */
  .sidebar-content { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  /* Правило скрытия при .show-chat вынесено отдельным блоком ниже с !important */
}

/* Десктоп: bottom-tabs остаётся горизонтальной полосой в самом низу левой колонки
   (sidebar шириной 340px), а не уезжает в отдельный вертикальный sidebar слева.
   Так панель вкладок логически принадлежит списку чатов и не ломает основной layout. */
@media (min-width: 769px) {
  .bottom-tabs {
    display: flex;
    flex-direction: row;
    left: 0; right: auto;
    bottom: 0; top: auto;
    width: 340px;                    /* совпадает с .sidebar width */
    border-top: 1px solid var(--apple-separator);
    border-right: 1px solid var(--apple-separator);
    padding-top: 6px;
    padding-bottom: 6px;
    align-items: stretch;
    justify-content: space-around;
    background: var(--apple-bg);
  }
  .bottom-tabs .tab-btn { flex: 1; padding: 8px 0 6px; }
  /* Резервируем место в скролл-контейнере чтобы последний чат не уезжал под таб-бар */
  .sidebar-content { padding-bottom: 72px; }
}

/* На мобилке при открытом чате таб-бар обязан исчезнуть полностью —
   иначе он перекрывает композер и поле ввода при появлении клавиатуры.
   Единая точка истины — body.chat-active (ставится в openChat/openChannel/openBot,
   снимается в closeChatToList/closeChannelView/closeBotView).
   #app-screen.show-chat оставлен ради обратной совместимости. */
@media (max-width: 768px) {
  body.chat-active #bottom-tabs,
  body.chat-active .bottom-tabs,
  #app-screen.show-chat .bottom-tabs { display: none !important; }

  /* Apple-style композер на мобилке:
     - Скрепка (📎) → выезжает Context Sheet с «Опросом» и «Местоположением».
     - Голос (🎤) и Видео-кружок (⬤) остаются в композере — частые действия,
       не должны быть скрыты за двумя тапами. */
  .composer #btn-poll,
  .composer #btn-location { display: none !important; }

  /* Композер flex-row: инпут растягивается, кнопки справа — фиксированной ширины.
     min-width: 0 на инпуте критично — без него flex-item не сжимается ниже
     своего content-size и кнопки уезжают за правый край экрана. */
  .composer { gap: 4px; }
  #msg-input { flex: 1; min-width: 0; }
  .composer #btn-attach,
  .composer #btn-circle,
  .composer #btn-record,
  .composer .send-btn { flex-shrink: 0; }
  /* На узких экранах <380px иконки чуть компактнее */
  .composer .icon-btn { width: 36px; height: 36px; }
}

/* ---------- iOS PWA: компактный bottom-tabs ----------
   @media (display-mode: standalone) на iOS не срабатывает из-за исторического
   `apple-mobile-web-app-capable=yes`. Маркер `body.is-ios-pwa` ставит JS
   (см. setupIOSPWAKeyboardFix() в app.js) — определяется через
   navigator.standalone + userAgent. Так надёжнее.
   height: auto + min-height: 65px позволяет панели слегка расти если контент
   требует, но базово компактна. Игнорируем гигантский env(safe-area-inset-bottom)
   и ставим аккуратный 15px зазор от Home Indicator. */
body.is-ios-pwa .bottom-tabs {
  height: auto !important;
  min-height: 65px !important;
  padding-top: 10px !important;
  padding-bottom: 15px !important;
}

/* ---------- Скрытие P2P/Server route-toggle в шапке чата ----------
   В DOM элемент — #route-toggle.route-toggle (см. index.html, .chat-header).
   JS-логику оставляем как есть — просто прячем визуально по просьбе UX. */
.chat-header #route-toggle,
.chat-header .route-toggle,
#route-toggle,
.route-toggle {
  display: none !important;
}

/* ---------- Context Sheet (bottom action sheet, Apple-style) ---------- */
.context-sheet-backdrop {
  position: fixed; inset: 0;
  background: var(--apple-overlay);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.context-sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.context-sheet {
  position: fixed;
  left: 8px; right: 8px;
  bottom: 0;
  z-index: 201;
  transform: translateY(120%);
  opacity: 0;
  transition: transform 0.28s cubic-bezier(.2,.8,.25,1), opacity 0.22s ease;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.context-sheet.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.context-sheet-card {
  background: var(--apple-surface);
  border-radius: var(--apple-radius-l);
  overflow: hidden;
  margin-bottom: 8px;
  box-shadow: 0 -4px 24px var(--apple-shadow);
}
.context-sheet-title {
  font-family: var(--apple-font);
  font-size: var(--apple-fs-headline);
  font-weight: 600;
  color: var(--apple-text);
  padding: 16px 16px 4px;
}
.context-sheet-subtitle {
  font-family: var(--apple-font);
  font-size: var(--apple-fs-footnote);
  color: var(--apple-text-muted);
  padding: 0 16px 12px;
}
.context-sheet-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 14px 16px;
  font-family: var(--apple-font);
  font-size: var(--apple-fs-body);
  color: var(--apple-text);
  text-align: left;
  border-top: 1px solid var(--apple-separator);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.context-sheet-option:first-child { border-top: 0; }
.context-sheet-option:active,
.context-sheet-option.active { background: var(--apple-bg-secondary); }
.context-sheet-option .opt-emoji { font-size: 20px; width: 24px; text-align: center; }
.context-sheet-option .opt-label { flex: 1; }
.context-sheet-option .opt-check {
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
}
.context-sheet-option.selected .opt-label {
  color: var(--accent);
  font-weight: 600;
}
.context-sheet-cancel {
  display: block;
  width: 100%;
  border: 0;
  background: var(--apple-surface);
  border-radius: var(--apple-radius-l);
  padding: 16px;
  text-align: center;
  font-family: var(--apple-font);
  font-size: var(--apple-fs-headline);
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  box-shadow: 0 -2px 12px var(--apple-shadow);
}
.context-sheet-cancel:active { background: var(--apple-bg-secondary); }

/* ---------- Focus Mode badge ---------- */
.focus-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--apple-font);
  font-size: var(--apple-fs-footnote);
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
}
.focus-badge[data-mode="all"] { display: none; } /* при mode=all бейдж скрыт */
.focus-badge .focus-emoji { font-size: 13px; }

/* =====================================================================
   Phase 13.1 (FINAL) — глобальные overrides в конце файла. Размещены здесь
   для максимальной специфичности в каскаде, гарантированно побивая любые
   предыдущие правила в компонентных секциях.
   ===================================================================== */

/* Task 1: жёсткое OLED-чёрное (или белое в light) для всех панелей.
   Убирает «грязный» серый фон на Android в OLED-теме, sidebar и chat-area
   сливаются с body. */
body, html, .sidebar, .chat-area, #app-screen, .empty-state {
  background-color: var(--bg-main) !important;
}

/* Phase 13.2: бренд-тайтл «Nero.» сам учитывает safe-area-inset-top.
   Убраны лишние «+8px» из math — на iPhone X+ был огромный отступ. */
.sidebar-brand-title {
  padding-top: max(12px, env(safe-area-inset-top, 0px)) !important;
  padding-bottom: 4px !important;
}
/* Базовый padding-top шапки = 4px (никаких safe-area, оно уже в тайтле) */
.sidebar-header {
  padding-top: 4px !important;
}
@media (max-width: 768px) {
  .sidebar-header {
    padding-top: 8px !important;     /* убрали env(safe-area-inset-top) */
  }
  /* При раскрытом поиске даём ему чуть больше воздуха — но всё ещё без двойной safe-area */
  .sidebar.search-active .sidebar-header {
    padding-top: max(8px, calc(env(safe-area-inset-top, 0px) + 8px)) !important;
  }
}
@media (display-mode: standalone) and (max-width: 768px) {
  .sidebar.search-active .sidebar-header {
    padding-top: max(8px, calc(env(safe-area-inset-top, 0px) + 8px)) !important;
  }
}

/* Phase 13.2: bottom-tabs через max() — старые iPhone без home indicator
   получают гарантированный 15px зазор, новые iPhone X+ — реальную safe-area.
   max() гарантирует, что отступ не будет МЕНЬШЕ 15px ни на каком устройстве. */
body.is-ios-pwa .bottom-tabs {
  padding-bottom: max(15px, env(safe-area-inset-bottom, 0px)) !important;
  height: calc(56px + max(15px, env(safe-area-inset-bottom, 0px))) !important;
  min-height: auto !important;
  padding-top: 0 !important;
}

/* ======================================================================
   Phase 14.1 (refit) — Modal Popup «Новая комната»
   Apple-style centered modal: scale(0.9)→1 + opacity 0→1 за 200ms.
   OLED-чёрный backdrop, тёмно-серая карточка, Ferrari Red акцент.
   ====================================================================== */

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.app-modal[hidden] { display: none; }
.app-modal.open { pointer-events: auto; }

/* Полупрозрачный затемнённый бэкдроп */
.app-modal .app-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 200ms cubic-bezier(0.25, 1, 0.5, 1);
}
.app-modal.open .app-modal-backdrop { opacity: 1; }

/* Карточка-окно по центру — компактная (360–400px) */
.app-modal .app-modal-panel {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: #111;                          /* --bg-card */
  color: #fff;
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* Apple modal entry animation */
  transform: scale(0.9);
  opacity: 0;
  transition:
    transform 200ms cubic-bezier(0.25, 1, 0.5, 1),
    opacity   200ms cubic-bezier(0.25, 1, 0.5, 1);
}
.app-modal.open .app-modal-panel {
  transform: scale(1);
  opacity: 1;
}

/* Large Title внутри окна */
.app-modal .app-modal-title {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  color: #fff;
}

/* Текстовое поле */
.app-modal .app-modal-input {
  width: 100%;
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px 16px;
  color: #fff;
  font-size: 17px;
  font-family: inherit;
  outline: none;
  transition: border-color 150ms ease, background 150ms ease;
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
}
.app-modal .app-modal-input::placeholder { color: rgba(255, 255, 255, 0.35); }
.app-modal .app-modal-input:focus {
  border-color: var(--accent-color, #E52E2D);
  background: #1c1c1e;
}

/* iOS Segmented Control */
.app-modal .segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #1c1c1e;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  position: relative;
}
.app-modal .segmented-option {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 200ms ease, color 200ms ease, transform 100ms ease;
}
.app-modal .segmented-option:active { transform: scale(0.97); }
.app-modal .segmented-option.active {
  background: var(--accent-color, #E52E2D);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* TTL slider row */
.app-modal .ttl-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}
.app-modal .ttl-label {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}
.app-modal .ttl-label strong {
  color: var(--accent-color, #E52E2D);
  font-weight: 700;
}

/* iOS-style range slider */
.app-modal .ttl-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: linear-gradient(
    to right,
    var(--accent-color, #E52E2D) 0%,
    var(--accent-color, #E52E2D) var(--ttl-fill, 20%),
    rgba(255, 255, 255, 0.15) var(--ttl-fill, 20%),
    rgba(255, 255, 255, 0.15) 100%
  );
  border-radius: 2px;
  outline: none;
  margin: 4px 0;
}
.app-modal .ttl-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: transform 100ms ease;
}
.app-modal .ttl-slider::-webkit-slider-thumb:active { transform: scale(1.08); }
.app-modal .ttl-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
.app-modal .ttl-slider::-moz-range-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

/* Actions row */
.app-modal .app-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.app-modal .app-modal-btn {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 150ms ease, opacity 150ms ease, transform 100ms ease;
}
.app-modal .app-modal-btn:active { transform: scale(0.98); }

.app-modal .app-modal-btn-cancel {
  background: transparent;
  color: rgba(255, 255, 255, 0.55);
}
.app-modal .app-modal-btn-cancel:hover { color: rgba(255, 255, 255, 0.85); }

.app-modal .app-modal-btn-primary {
  background: var(--accent-color, #E52E2D);
  color: #fff;
}
.app-modal .app-modal-btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* ----------------------------------------------------------------------
   Phase 14.2 — Avatar picker для модалки «Новый канал»
   Круглый 84×84 px над input'ом имени. Тёмно-серый чуть светлее панели.
   ---------------------------------------------------------------------- */
.cc-avatar-wrap {
  display: flex;
  justify-content: center;
  margin: 4px 0 4px;
}
.cc-avatar-preview {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: #1c1c1e;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  background-size: cover;
  background-position: center;
  transition: transform 100ms ease, background-color 150ms ease;
}
.cc-avatar-preview:hover  { background-color: #2a2a2c; }
.cc-avatar-preview:active { transform: scale(0.96); }
/* Если установлена картинка — фон становится прозрачным (видна background-image),
   и иконку фотоаппарата прячем. */
.cc-avatar-preview.has-image {
  background-color: transparent;
}
.cc-avatar-preview.has-image .cc-avatar-icon { display: none; }
.cc-avatar-icon {
  font-size: 28px;
  opacity: 0.55;
  line-height: 1;
}

/* ----------------------------------------------------------------------
   Phase 14.3 — Settings modals (#modal-room-settings / #modal-channel-settings)
   ---------------------------------------------------------------------- */

/* Заголовок секции (label-стиль) */
.app-modal .app-modal-section-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.45);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 6px 4px -4px;
}

/* Текстовый блок описания канала */
.app-modal .app-modal-section-text {
  font-size: 15px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.75);
  background: #1c1c1e;
  border-radius: 12px;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Список участников — скроллируемый, чтобы модалка не растягивалась */
.app-modal .app-modal-members-list {
  background: #1c1c1e;
  border-radius: 12px;
  padding: 4px 6px;
  max-height: 200px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.app-modal .app-modal-member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px;
  border-radius: 8px;
}
.app-modal .app-modal-member-row + .app-modal-member-row {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.app-modal .app-modal-member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #2a2a2c;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.app-modal .app-modal-member-name {
  font-size: 15px;
  color: #fff;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-modal .app-modal-member-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-color, #E52E2D);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

/* Invite link row */
.app-modal .app-modal-invite-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.app-modal .app-modal-invite-row input {
  flex: 1;
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 12px;
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
.app-modal .app-modal-invite-copy {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: var(--accent-color, #E52E2D);
  color: #fff;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 150ms ease, transform 100ms ease;
  flex-shrink: 0;
}
.app-modal .app-modal-invite-copy:active { transform: scale(0.97); }
.app-modal .app-modal-invite-copy.copied { opacity: 0.6; }

/* Phase 15.5: Mute switch row (Уведомления + .ios-switch) */
.app-modal .app-modal-mute-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #1c1c1e;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 4px 0;
}
.app-modal .app-modal-mute-label {
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  flex: 1;
}

/* Phase 15.5: во время edge-swipe панель уезжает за пальцем без transition */
.app-modal .app-modal-panel.is-edge-swiping {
  transition: none !important;
}

/* Danger-кнопка (Выйти) */
.app-modal .app-modal-btn-danger {
  background: transparent;
  color: var(--accent-color, #E52E2D);
  border: 1px solid rgba(229, 46, 45, 0.35);
}
.app-modal .app-modal-btn-danger:hover {
  background: rgba(229, 46, 45, 0.08);
}

/* Кликабельные строки участников — для перехода в профиль (Phase 14.4) */
.app-modal .app-modal-member-row {
  cursor: pointer;
  transition: background 120ms ease;
}
.app-modal .app-modal-member-row:hover {
  background: rgba(255, 255, 255, 0.04);
}
.app-modal .app-modal-member-row:active {
  background: rgba(255, 255, 255, 0.08);
}
.app-modal .app-modal-member-row.self {
  cursor: default;
}
.app-modal .app-modal-member-row.self:hover,
.app-modal .app-modal-member-row.self:active {
  background: transparent;
}

/* ----------------------------------------------------------------------
   Phase 14.4 — User Profile Modal (#modal-user-profile)
   Apple Contacts-style: огромный круглый аватар, имя крупным шрифтом, ID моноширинно.
   ---------------------------------------------------------------------- */
.app-modal .up-avatar-wrap {
  display: flex;
  justify-content: center;
  margin: 8px 0 4px;
}
.app-modal .up-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: #1c1c1e;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  /* iOS Contacts-style: subtle лёгкая тень + 1px светлая обводка */
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}
.app-modal .up-avatar.has-image {
  background-color: transparent;
}
.app-modal .up-avatar.has-image .up-avatar-initial { display: none; }
.app-modal .up-avatar-initial {
  font-size: 42px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  line-height: 1;
  user-select: none;
}
.app-modal .up-id {
  text-align: center;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: rgba(255, 255, 255, 0.45);
  word-break: break-all;
  padding: 0 4px;
  margin: -4px 0 4px;
  line-height: 1.4;
}

/* ----------------------------------------------------------------------
   Phase 14.4 — Кликабельные имена авторов в групповых сообщениях
   ---------------------------------------------------------------------- */
.msg-author {
  cursor: pointer;
  transition: opacity 120ms ease;
  -webkit-tap-highlight-color: transparent;
}
.msg-author:hover { opacity: 0.7; }
.msg-author:active { opacity: 0.5; }

/* ----------------------------------------------------------------------
   Phase 14.6 — Swipe-to-Reply
   Гарантируем отсутствие горизонтального скролла страницы при translateX.
   ---------------------------------------------------------------------- */
#messages {
  overflow-x: hidden;
}
.msg {
  /* Reset-анимация после swipe. Во время drag JS ставит inline transition: none. */
  transition: transform 200ms ease-out;
  will-change: transform;
}
.msg.is-swiping {
  transition: none;
}
/* Floating ↩ icon, отображается справа от пузыря во время свайпа */
.msg-reply-hint {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%) scale(0.6);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(229, 46, 45, 0.18);
  color: var(--accent-color, #E52E2D);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease-out, transform 120ms ease-out;
}
.msg-reply-hint.active {
  /* scale = 1 при достижении порога свайпа */
  transform: translateY(-50%) scale(1);
}

/* ======================================================================
   Phase 15 — Unified Bot Constructor (#modal-bot-constructor)
   Минимальный набор поверх .app-modal-* — без legacy iOS-классов.
   ====================================================================== */

/* Phase 15.1: конструктор длинный — даём ему скролл, чтобы не обрезались
   кнопки внизу. Scoped по ID, чтобы не сломать профиль/настройки. */
#modal-bot-constructor .app-modal-panel {
  max-height: 85dvh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* Резерв снизу — чтобы Action-кнопки не прилипали к краю на маленьких экранах */
  padding-bottom: 24px;
}
@media (min-width: 768px) {
  /* На десктопе резервируем чуть больше места под dvh, плюс плавный fallback */
  #modal-bot-constructor .app-modal-panel { max-height: 90vh; }
}
/* Тонкий скроллбар в OLED-палитре */
#modal-bot-constructor .app-modal-panel::-webkit-scrollbar {
  width: 6px;
}
#modal-bot-constructor .app-modal-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}
#modal-bot-constructor .app-modal-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Селект под стиль .app-modal-input — компактный, без хрома */
.app-modal .app-modal-select {
  width: 100%;
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px 16px;
  color: #fff;
  font-size: 17px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%23ffffff80' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
  padding-right: 36px;
  box-sizing: border-box;
  transition: border-color 150ms ease;
}
.app-modal .app-modal-select:focus {
  border-color: var(--accent-color, #E52E2D);
}
/* На iOS Safari `<select>` всё равно открывает нативный барабан — это поведение
   по умолчанию, никаких дополнительных хаков не нужно. */

/* Источники: ряд = input + кнопка удаления */
.app-modal #bc-sources-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.app-modal .bc-source-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.app-modal .bc-source-row input {
  flex: 1;
  min-width: 0;
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 14px;
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  transition: border-color 150ms ease;
}
.app-modal .bc-source-row input::placeholder { color: rgba(255, 255, 255, 0.35); }
.app-modal .bc-source-row input:focus {
  border-color: var(--accent-color, #E52E2D);
}
.app-modal .bc-source-row .bc-source-remove {
  flex-shrink: 0;
  width: 40px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.5);
  font-size: 18px;
  font-family: inherit;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.app-modal .bc-source-row .bc-source-remove:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
}
/* Если в списке остался один ряд — крестик скрыт (нельзя удалить последний) */
.app-modal #bc-sources-list:has(> .bc-source-row:only-child) .bc-source-remove {
  display: none;
}

/* Phase 15.3: стили .app-modal-select[multiple] и .app-modal-hint удалены —
   секция «Куда пересылать» снесена, бот теперь = свой собственный канал. */

/* «+ Добавить источник» — текстовая ссылка-кнопка с Ferrari Red */
.app-modal .bc-add-source-btn {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: var(--accent-color, #E52E2D);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 6px 4px;
  cursor: pointer;
  align-self: flex-start;
  transition: opacity 120ms ease;
}
.app-modal .bc-add-source-btn:hover { opacity: 0.8; }
.app-modal .bc-add-source-btn:active { opacity: 0.6; }

/* ======================================================================
   Phase 15.4 — Slide-анимация между вкладками (chats ↔ channels ↔ profile)
   Hardware-accelerated transform + opacity. Длительность каждой фазы ~160ms,
   общий цикл ~320ms (out + in). Не ломает scrollTop внутри списков — transform
   на родительском .sidebar-content, scroll-контейнер остаётся в DOM.
   ====================================================================== */

/* Контейнер вкладок: контент по умолчанию в исходном положении.
   `overflow: hidden` на родительском .sidebar — гарантирует, что
   transform: translateX(±X%) не вызовет горизонтальный скролл страницы. */
.sidebar {
  overflow-x: hidden;
}
.sidebar-content {
  will-change: transform, opacity;
}

/* --- Slide OUT (старый контент уезжает) --- */
.sidebar-content.tab-anim-out-left,
.sidebar-content.tab-anim-out-right {
  transition: transform 160ms ease-out, opacity 160ms ease-out;
  opacity: 0;
}
.sidebar-content.tab-anim-out-left  { transform: translateX(-22%); }
.sidebar-content.tab-anim-out-right { transform: translateX( 22%); }

/* --- Slide IN: стартовое положение за кадром (без transition, мгновенно) --- */
.sidebar-content.tab-anim-from-left,
.sidebar-content.tab-anim-from-right {
  transition: none;
  opacity: 0;
}
.sidebar-content.tab-anim-from-left  { transform: translateX(-22%); }
.sidebar-content.tab-anim-from-right { transform: translateX( 22%); }

/* --- Slide IN (новый контент въезжает к 0) --- */
.sidebar-content.tab-anim-in {
  transition: transform 200ms cubic-bezier(0.32, 0.72, 0, 1),
              opacity   200ms ease-out;
  transform: translateX(0);
  opacity: 1;
}

/* Если у юзера включён prefers-reduced-motion — никакой анимации.
   JS-сторона тоже проверяет это и просто меняет контент мгновенно,
   но дублируем защитой и в CSS. */
@media (prefers-reduced-motion: reduce) {
  .sidebar-content,
  .sidebar-content.tab-anim-out-left,
  .sidebar-content.tab-anim-out-right,
  .sidebar-content.tab-anim-from-left,
  .sidebar-content.tab-anim-from-right,
  .sidebar-content.tab-anim-in {
    transition: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
}

/* ----------------------------------------------------------------------
   Phase 14.6 — Пересланные сообщения (forwarded)
   ---------------------------------------------------------------------- */
.msg-forwarded-block {
  border-left: 2px solid var(--accent-color, #E52E2D);
  padding-left: 8px;
  margin-bottom: 6px;
  border-radius: 2px;
}
.msg-forwarded-header {
  font-size: 12px;
  font-style: italic;
  color: rgba(255, 255, 255, 0.5);
  line-height: 1.3;
  margin-bottom: 2px;
}
.msg-forwarded-text {
  font-size: inherit;
  line-height: inherit;
  color: inherit;
}

/* ======================================================================
   Phase 19 — Image Viewer + Collaborative Canvas
   ====================================================================== */
.viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  -webkit-tap-highlight-color: transparent;
}
.viewer-modal[hidden] { display: none; }
.viewer-backdrop {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
}
.viewer-stage {
  position: relative;
  max-width: calc(100% - 40px);
  max-height: calc(100% - 140px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.viewer-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 200ms cubic-bezier(0.25, 1, 0.5, 1);
  transform-origin: center center;
  background: #111;
  border-radius: 8px;
  box-shadow: 0 12px 60px rgba(0, 0, 0, 0.6);
}
.viewer-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  pointer-events: auto;
  touch-action: none;          /* отдаём жесты canvas-обработчику */
  background: transparent;
}
/* В canvas-режиме у самой картинки убираем transition transforma, чтобы
   canvas-overlay не «отъезжал» от изображения */
.viewer-modal.is-canvas-mode .viewer-image { transition: none; }

/* Стрелки навигации галереи (по бокам) */
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 32px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.viewer-nav:hover  { background: rgba(255, 255, 255, 0.18); }
.viewer-nav:active { background: rgba(255, 255, 255, 0.25); }
.viewer-nav-prev   { left: 16px; }
.viewer-nav-next   { right: 16px; }
.viewer-nav[hidden] { display: none; }

/* Тулбар внизу */
.viewer-toolbar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: rgba(20, 20, 20, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: 14px;
  padding: 6px;
  z-index: 2;
}
.viewer-tool {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.viewer-tool:hover  { background: rgba(255, 255, 255, 0.1); }
.viewer-tool:active { background: rgba(255, 255, 255, 0.2); }
.viewer-tool-close  { color: rgba(255, 255, 255, 0.7); }

/* Кнопка «Холст» в правом верхнем углу */
.viewer-canvas-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--accent-color, #E52E2D);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(229, 46, 45, 0.32);
  z-index: 2;
  transition: transform 100ms ease, opacity 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.viewer-canvas-btn:hover  { opacity: 0.92; }
.viewer-canvas-btn:active { transform: scale(0.97); }
.viewer-modal.is-canvas-mode .viewer-canvas-btn { display: none; }

/* Тулбар рисования (показывается только в canvas-режиме) */
.viewer-draw-toolbar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(20, 20, 20, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: 14px;
  padding: 8px 10px;
  z-index: 3;
}
.viewer-draw-toolbar[hidden] { display: none; }
.draw-color {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  padding: 0;
  transition: transform 100ms ease, border-color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.draw-color:hover  { transform: scale(1.1); }
.draw-color.active { border-color: var(--accent-color, #E52E2D); transform: scale(1.15); }
.draw-tool {
  background: transparent;
  border: 0;
  color: #fff;
  width: 36px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: background 150ms ease;
  font-family: inherit;
}
.draw-tool:hover  { background: rgba(255, 255, 255, 0.1); }
.draw-tool.active { background: rgba(229, 46, 45, 0.35); }
.draw-tool-exit { color: rgba(255, 255, 255, 0.7); }
#draw-size {
  width: 80px;
  accent-color: var(--accent-color, #E52E2D);
}

/* Phase 19.1: Невесомая canvas-карточка — чистый CSS, без Data URL.
   Белый прямоугольник 240×160 с надписью «🎨 Нажмите, чтобы рисовать». */
.msg-canvas-card {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 240px;
  height: 160px;
  background: #fff;
  color: #555;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  position: relative;
  transition: transform 100ms ease;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.msg-canvas-card:active { transform: scale(0.98); }
.msg-canvas-card::before {
  content: "🎨 Нажмите, чтобы рисовать";
  pointer-events: none;
}
/* Когда есть мазки — убираем надпись (canvas-карточка рисуется через viewer на клике). */
.msg-canvas-card.has-strokes::before { content: ""; }
.msg-canvas-card.has-strokes {
  background-image: linear-gradient(135deg, rgba(229,46,45,0.08), rgba(255,255,255,1));
}

/* Lightweight canvas-mode в viewer — белый stage, img скрыт. */
.viewer-stage.lightweight-canvas {
  background: #fff;
  width: 80vw;
  max-width: 1000px;
  height: 60vh;
  max-height: 700px;
  border-radius: 8px;
}

/* Hand-tool (✋) активен — canvas прозрачен для тачей (pinch-zoom работает). */
.viewer-modal.hand-tool .viewer-canvas {
  pointer-events: none;
  touch-action: auto;
  cursor: grab;
}
.viewer-modal.hand-tool .viewer-image {
  touch-action: pinch-zoom;
}

