/*
  Стили модулей ТЗ №4: фото (4.1), видео (4.2), звонки (4.3).

  Геометрия наследует NiMilex UI (ТЗ 4.1 §6.1, ТЗ 4.2 §7.2): внешний контур
  медиа-блока согласован с message bubble, внутренние стыки почти прямые, зазоры
  минимальные и равномерные. Фирменный фиолетовый — только на активных состояниях
  и маркерах, а не заливкой поверхностей.
*/

:root {
  /* Внешний радиус медиа-блока: верхняя граница диапазона ТЗ (12–14px), близкая к
     радиусу сообщения; внутренние стыки — почти прямые, единой композицией. */
  --r-media: 14px;
  --r-media-inner: 3px;
  --media-gap: 3px;          /* равномерный зазор внутри сетки (ТЗ: 2–4px) */
  --media-anim: 200ms;       /* скорость переходов между медиа (ТЗ 4.1 §5.3) */
}

/* ============================================================
   ТЗ 4.1 §6 — сетка нескольких фото/видео внутри сообщения
   ============================================================ */
.media-grid {
  display: grid;
  gap: var(--media-gap);
  margin: 2px 0 4px;
  border-radius: var(--r-media);
  overflow: hidden;                /* внешние углы режут всю композицию целиком */
  max-width: min(420px, 78vw);
}
/* Пропорции задаёт сама сетка, а карточки её полностью заполняют. Если пропорцию
   вешать на карточки, строки сетки перестают совпадать с их высотой и между
   рядами появляется лишний просвет — зазор обязан оставаться равномерным. */
.media-grid.n1 { grid-template-columns: 1fr; }
.media-grid.n2 { grid-template-columns: 1fr 1fr; aspect-ratio: 2 / 1.15; }
/* 3 фото — одна крупная карточка слева и две меньшие справа. */
.media-grid.n3 {
  grid-template-columns: 1.55fr 1fr;
  grid-template-rows: 1fr 1fr;
  aspect-ratio: 3 / 2.05;
}
.media-grid.n3 > :first-child { grid-row: 1 / span 2; }
.media-grid.n4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  aspect-ratio: 1 / 1;
}
.media-grid.n5 { grid-template-columns: repeat(3, 1fr); aspect-ratio: 3 / 2.05; }

.media-cell {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  background: var(--surface-sunken);
  border-radius: var(--r-media-inner);   /* внутренние стыки — почти прямые */
  overflow: hidden;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
}
.media-cell img,
.media-cell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Одиночный снимок показываем целиком, без обрезки под квадрат. */
.media-grid.n1 .media-cell { height: auto; }
.media-grid.n1 .media-cell img,
.media-grid.n1 .media-cell video { object-fit: contain; height: auto; max-height: 320px; }

/* «+N» на последнем видимом элементе при 5+ вложениях. */
.media-more {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .52);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 600;
}

/* Метка видео в сообщении: компактный Play + длительность (ТЗ 4.2 §7.1). */
.media-play {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .46);
  color: #fff;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.media-play svg { width: 20px; height: 20px; margin-left: 2px; }
.media-dur {
  position: absolute;
  right: 6px; bottom: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .58);
  color: #fff;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   ТЗ 4.1 §2.2 / ТЗ 4.2 §2 — единый медиапикер
   ============================================================ */
.sheet.sheet-mediapicker .sheet-body { padding-bottom: 4px; }

.mp-cam {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-card);
  overflow: hidden;
  background: #101015;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mp-cam-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mp-cam.off .mp-cam-video { display: none; }
.mp-cam-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.mp-cam-hint.hidden { display: none; }
.mp-cam-off {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--silver);
  text-align: center;
  padding: 16px;
}
.mp-cam-off-icon {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .12);
}
.mp-cam-off-icon svg { width: 26px; height: 26px; }

.mp-cam-btn {
  position: absolute;
  top: 10px;
  width: 38px; height: 38px;
  border: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .42);
  color: #fff;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.mp-cam-btn svg { width: 20px; height: 20px; }
.mp-cam-btn.hidden { display: none; }
.mp-cam-btn:disabled { opacity: .45; cursor: default; }
.mp-switch { right: 10px; }
.mp-flash { left: 10px; }
.mp-flash.is-on { background: var(--icon-active); }

/* Индикатор записи: точка + текущая длительность (ТЗ 4.2 §2.2). */
.mp-rec {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.mp-rec.hidden { display: none; }
.mp-rec-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger, #d9534f);
  animation: mp-blink 1s steps(2, start) infinite;
}
@keyframes mp-blink { to { opacity: .25; } }

.mp-shutter-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 0 6px;
}
.mp-modes {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: var(--surface-sunken);
}
.mp-modes.hidden { display: none; }
.mp-mode {
  border: none;
  background: transparent;
  padding: 5px 16px;
  border-radius: 999px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
}
.mp-mode.is-on { background: var(--icon-active); color: #fff; }

.mp-shutter {
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 3px solid var(--icon);
  background: var(--surface);
  cursor: pointer;
  position: relative;
}
.mp-shutter::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: var(--icon-active);
  transition: border-radius 160ms, inset 160ms, background 160ms;
}
.mp-shutter.is-video::after { background: var(--danger, #d9534f); }
.mp-shutter.is-recording::after { inset: 16px; border-radius: 5px; }
.mp-shutter:disabled { opacity: .4; cursor: default; }
.mp-cancel-rec {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 4px 10px;
}
.mp-cancel-rec.hidden { display: none; }

.mp-section {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 8px 2px 6px;
}
.mp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 6px;
}
.mp-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border: none;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-sunken);
  cursor: pointer;
}
.mp-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.mp-tile.is-sel { outline: 3px solid var(--icon-active); outline-offset: -3px; }
.mp-badge {
  position: absolute;
  top: 5px; right: 5px;
  min-width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  background: transparent;
  border: 2px solid rgba(255, 255, 255, .8);
}
.mp-tile.is-sel .mp-badge { background: var(--icon-active); border-color: var(--icon-active); }
.mp-vmark {
  position: absolute;
  left: 6px; bottom: 6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .5);
  color: #fff;
}
.mp-vmark svg { width: 11px; height: 11px; margin-left: 1px; }
.mp-lib {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--icon);
  background: var(--purple-08);
  font-size: 0.75rem;
  text-align: center;
  padding: 6px;
}
.mp-lib svg { width: 24px; height: 24px; }
.mp-empty { grid-column: 1 / -1; padding: 10px 2px; font-size: 0.875rem; }

.mp-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 4px;
  margin-top: 10px;
  background: var(--surface);
}
.mp-count { font-size: 0.875rem; color: var(--text-secondary); }
.mp-next { min-width: 120px; }

/* ============================================================
   ТЗ 4.1 §3.2 / ТЗ 4.2 §3 — preview перед отправкой
   ============================================================ */
.mp-preview {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  background: #0d0d11;
  color: var(--silver);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mp-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  flex: 0 0 auto;
}
.mp-top-title { font-size: 0.875rem; color: var(--silver-secondary); font-variant-numeric: tabular-nums; }
.mp-top-actions { display: flex; gap: 6px; }
.mv-btn {
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  cursor: pointer;
}
.mv-btn svg { width: 20px; height: 20px; }
.mv-btn:hover { background: rgba(255, 255, 255, .18); }
.mv-btn.hidden { display: none; }
/* Карандаш редактирования — фирменные состояния (ТЗ 4.1 §4.2, ТЗ 4.2 §4.3). */
.mv-edit { color: var(--purple-light); }
.mv-edit:hover { color: #fff; background: var(--icon-hover); }
.mv-edit:active { background: var(--icon-pressed); }
.mv-edit:disabled { color: var(--silver-disabled); background: rgba(255, 255, 255, .06); cursor: default; }

.mp-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
}
.mp-big { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.mp-vwrap { display: flex; flex-direction: column; gap: 8px; max-width: 100%; max-height: 100%; }
.mp-vwrap .mp-big { min-height: 0; }
.mp-vbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}
.mp-play {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.mp-play svg { width: 18px; height: 18px; }
.mp-seek { flex: 1 1 auto; accent-color: var(--purple-light); }
.mp-time { font-size: 0.8125rem; color: var(--silver-secondary); font-variant-numeric: tabular-nums; }
.mp-doc { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--silver); }
.mp-doc svg { width: 46px; height: 46px; }

.mp-strip {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
.mp-strip.hidden { display: none; }
.mp-sitem {
  position: relative;
  flex: 0 0 auto;
  width: 56px; height: 56px;
  border: none;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, .08);
  cursor: pointer;
}
.mp-sitem.is-cur { outline: 2px solid var(--purple-light); outline-offset: -2px; }
.mp-sthumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.mp-sthumb.file { display: flex; align-items: center; justify-content: center; color: var(--silver-secondary); }
.mp-snum {
  position: absolute;
  top: 2px; left: 2px;
  min-width: 17px; height: 17px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #fff;
  background: var(--icon-active);
}

.mp-bottom {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 14px;
}
.mp-caption {
  flex: 1 1 auto;
  height: 42px;
  padding: 0 14px;
  border-radius: var(--r-field);
  border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(255, 255, 255, .07);
  color: var(--silver);
  font-size: 0.9375rem;
}
.mp-caption::placeholder { color: var(--silver-secondary); }
.mp-caption:focus { outline: none; border-color: var(--purple-light); }
.mp-send {
  width: 46px; height: 46px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: var(--icon-active);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.mp-send svg { width: 21px; height: 21px; }
.mp-send:hover { background: var(--icon-hover); }
.mp-send:active { background: var(--icon-pressed); }

/* ============================================================
   ТЗ 4.1 §4 — редактор фотографии
   ============================================================ */
.pe, .ve {
  position: fixed;
  inset: 0;
  z-index: 1150;
  display: flex;
  flex-direction: column;
  background: #0d0d11;
  color: var(--silver);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.pe-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  flex: 0 0 auto;
}
.pe-top-mid { display: flex; gap: 6px; align-items: center; }
.pe-top-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.pe-top-btn svg { width: 20px; height: 20px; }
.pe-top-btn:hover:not(:disabled) { background: var(--icon-hover); }
.pe-top-btn:disabled { color: var(--silver-disabled); cursor: default; opacity: .55; }
.pe-save {
  border: none;
  border-radius: var(--r-field);
  padding: 9px 18px;
  background: var(--icon-active);
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}
.pe-save:hover { background: var(--icon-hover); }
.pe-save:active { background: var(--icon-pressed); }

.pe-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
.pe-canvas { touch-action: none; display: block; border-radius: 6px; }
.pe-del {
  position: absolute;
  width: 30px; height: 30px;
  border: none; border-radius: 50%;
  background: var(--danger, #d9534f);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.pe-del svg { width: 15px; height: 15px; }
.pe-del.hidden { display: none; }

.pe-width, .pe-croprow {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
}
.pe-width.hidden, .pe-croprow.hidden { display: none; }
.pe-croprow { justify-content: center; }
/* Редакторы всегда тёмные, поэтому светлые кнопки страницы здесь нечитаемы —
   задаём им собственную пару цветов. */
.pe .btn.secondary,
.ve .btn.secondary {
  background: rgba(255, 255, 255, .12);
  color: var(--silver);
  border-color: transparent;
}
.pe .btn.secondary:hover,
.ve .btn.secondary:hover { background: rgba(255, 255, 255, .2); }
.pe-width-label { font-size: 0.8125rem; color: var(--silver-secondary); }
.pe-width-range { flex: 1 1 auto; accent-color: var(--purple-light); }
.pe-width-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--purple-light);
  flex: 0 0 auto;
}

.pe-tools {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-around;
  gap: 4px;
  padding: 8px 8px 14px;
}
.pe-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--purple-light);       /* Archive Ink — обычное состояние */
  font-size: 0.6875rem;
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
}
.pe-tool svg { width: 22px; height: 22px; }
.pe-tool:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.pe-tool:active { background: var(--icon-pressed); color: #fff; }
.pe-tool.is-on { background: var(--icon-active); color: #fff; }
.pe-tool:disabled { color: var(--silver-disabled); cursor: default; }
.pe-textinput {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--r-field);
  border: 1px solid var(--separator);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: 1rem;
}

/* ============================================================
   ТЗ 4.2 §4–5 — редактор видео
   ============================================================ */
.ve-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
.ve-video { max-width: 100%; max-height: 100%; display: block; border-radius: 8px; }
.ve-play {
  position: absolute;
  width: 54px; height: 54px;
  border: none; border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.ve-play svg { width: 22px; height: 22px; }
.ve-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  padding: 4px 16px;
  font-size: 0.8125rem;
  color: var(--silver-secondary);
  font-variant-numeric: tabular-nums;
}

.ve-timeline {
  position: relative;
  flex: 0 0 auto;
  height: 56px;
  margin: 4px 16px 8px;
  border-radius: 8px;
  overflow: visible;
  touch-action: none;
  cursor: pointer;
}
.ve-frames {
  position: absolute;
  inset: 0;
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, .06);
}
.ve-frames.plain { background: rgba(255, 255, 255, .1); }
.ve-frame { flex: 1 1 0; height: 100%; object-fit: cover; min-width: 0; }
/* Вне выбранного диапазона — затемняем (ТЗ 4.2 §4.2). */
.ve-shade {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(10, 10, 14, .68);
  pointer-events: none;
}
.ve-shade.left { left: 0; border-radius: 8px 0 0 8px; }
.ve-shade.right { right: 0; border-radius: 0 8px 8px 0; }
/* Активный диапазон выделен рамкой фирменного цвета — без заливки всей ленты. */
.ve-range {
  position: absolute;
  top: 0; bottom: 0;
  border: 2px solid var(--purple-light);
  border-radius: 6px;
  pointer-events: none;
}
.ve-handle {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 14px;
  margin-left: -7px;
  border-radius: 5px;
  background: var(--purple-light);
  cursor: ew-resize;
}
.ve-handle::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2px; height: 16px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .85);
}
.ve-playhead {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
  pointer-events: none;
}

/* Кадр-превью при перемотке (ТЗ 4.2 §5) — появляется только во время жеста. */
.ve-scrub {
  position: absolute;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .72);
  pointer-events: none;
  opacity: 1;
  transition: opacity 160ms ease;
}
.ve-scrub.hidden { opacity: 0; }
.ve-scrub-img { width: 84px; height: 48px; object-fit: cover; border-radius: 5px; display: block; }
.ve-scrub-time { font-size: 0.6875rem; color: #fff; font-variant-numeric: tabular-nums; }

.ve-tools {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px 14px;
}
.ve-tool {
  display: flex;
  align-items: center;
  gap: 7px;
  border: none;
  border-radius: 12px;
  padding: 9px 14px;
  background: rgba(255, 255, 255, .08);
  color: var(--purple-light);
  font-size: 0.8125rem;
  cursor: pointer;
}
.ve-tool svg { width: 18px; height: 18px; }
.ve-tool:hover { color: #fff; background: var(--icon-hover); }
.ve-tool.is-on { background: var(--icon-active); color: #fff; }
.ve-rangelbl { font-size: 0.8125rem; }
.ve-title { font-size: 0.9375rem; font-weight: 600; }

.ve-prog {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 16px;
}
.ve-prog.hidden { display: none; }
.ve-prog-text { font-size: 0.875rem; color: var(--silver-secondary); }
.ve-prog-track {
  flex: 1 1 auto;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .14);
  overflow: hidden;
}
.ve-prog-fill { display: block; height: 100%; width: 0; background: var(--purple-light); }

/* ============================================================
   ТЗ 4.1 §5 / ТЗ 4.2 §8 — полноэкранный просмотр медиа
   ============================================================ */
.mvw {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, .94);
  overflow: hidden;
  overscroll-behavior: contain;
}
.mvw.hidden { display: none; }

.mvw-track {
  display: flex;
  width: 100%;
  height: 100%;
  will-change: transform;
  touch-action: none;            /* зум/листание/закрытие ведём сами */
}
.mvw-slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mvw-media {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  display: block;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.mvw-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px;
  background: linear-gradient(rgba(0, 0, 0, .5), transparent);
  transition: opacity var(--media-anim) ease;
}
.mvw-counter {
  color: #fff;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.mvw-btn {
  width: 42px; height: 42px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.mvw-btn svg { width: 21px; height: 21px; }
.mvw-btn:hover { background: rgba(255, 255, 255, .24); }

/* Экранные стрелки — рабочий путь листания на компьютере (ТЗ 4.1 §5.3). */
.mvw-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
  transition: opacity var(--media-anim) ease;
}
.mvw-arrow svg { width: 22px; height: 22px; }
.mvw-arrow:hover { background: rgba(255, 255, 255, .22); }
.mvw-arrow.prev { left: 14px; }
.mvw-arrow.next { right: 14px; }
.mvw-arrow.hidden { display: none; }
/* На сенсорных экранах листают свайпом — стрелки не занимают место. */
@media (hover: none) and (pointer: coarse) {
  .mvw-arrow { display: none; }
}

.mvw-vbar {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(transparent, rgba(0, 0, 0, .62));
  transition: opacity var(--media-anim) ease;
}
.mvw-vbar.hidden { display: none; }
.mvw-vbtn {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.mvw-vbtn svg { width: 18px; height: 18px; }
.mvw-seek { flex: 1 1 auto; accent-color: var(--purple-light); }
.mvw-vol { width: 84px; flex: 0 0 auto; accent-color: var(--purple-light); }
.mvw-time {
  color: #fff;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
@media (max-width: 560px) { .mvw-vol { display: none; } }

/* Автоскрытие: элементы гаснут за 200 мс, движение/тап возвращает их. */
.mvw.chrome-off .mvw-top,
.mvw.chrome-off .mvw-vbar,
.mvw.chrome-off .mvw-arrow { opacity: 0; pointer-events: none; }

/* ============================================================
   ТЗ 4.3 — дополнения к экрану звонка
   ============================================================ */

/* §10.2 Автоскрытие управления примерно через 3 с бездействия: гаснет за 200 мс,
   без spring и bounce; любое движение или касание возвращает элементы. */
.call-screen .call-actions,
.call-screen .call-center {
  transition: opacity var(--media-anim) ease;
}
.call-screen.video-mode.controls-off .call-actions,
.call-screen.video-mode.controls-off .call-center {
  opacity: 0;
  pointer-events: none;
}

/* §6.1 Предложение включить видео — поверх разговора, звонок при этом не рвётся. */
.call-ask {
  position: absolute;
  left: 50%;
  bottom: calc(120px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: var(--r-card);
  background: rgba(20, 20, 26, .92);
  color: var(--silver);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.call-ask.hidden { display: none; }
.call-ask-text { font-size: 0.9375rem; text-align: center; }
.call-ask-row { display: flex; gap: 8px; }
.call-ask-row .btn { flex: 1 1 0; }
.call-ask-row .btn.secondary { background: rgba(255, 255, 255, .12); color: var(--silver); border-color: transparent; }

/* §4: во время исходящего видеовызова своё изображение занимает основную площадь —
   чужого потока ещё нет. После принятия карточка возвращается в угол. */
.call-screen.self-stage .call-local {
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%; height: 100%;
  border-radius: 0;
  box-shadow: none;
  cursor: default;
  transform: scaleX(-1);        /* себя показываем зеркально, как в зеркале */
}

/* §12 «Переподключение…» — состояние заметно, но без тревожной анимации. */
.call-screen.is-reconnecting .call-state { color: var(--warning, #C58A2E); }

/* §16.2 Состояния интерактивных иконок — фирменная палитра Ink.
   Красный остаётся только у завершения вызова (destructive action). */
.call-btn.control:hover:not(:disabled) { background: var(--icon-hover); color: #fff; }
.call-btn.control:active { background: var(--icon-pressed); color: #fff; }
.call-btn.control:disabled { color: var(--silver-disabled); box-shadow: none; cursor: default; }
.call-btn[data-role="accept-audio"] { background: var(--icon); }
.call-btn[data-role="accept-audio"]:hover { background: var(--icon-hover); }

/* Выбранная строка в шторках звонка (аудиовыход, удержание). */
.group-row.is-on { color: var(--icon-active); font-weight: 600; }
.group-row.is-on svg { color: var(--icon-active); }

/* ТЗ 4.1 §7.1 — полоса «в ответ на …» над полем ввода. */
.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 0 4px 4px;
  border-radius: var(--r-field);
  background: var(--surface-sunken);
  border-left: 3px solid var(--icon-active);
}
.reply-bar.hidden { display: none; }
.reply-bar > svg { width: 18px; height: 18px; color: var(--icon); flex: none; }
.reply-bar-main { flex: 1 1 auto; min-width: 0; }
.reply-bar-who { font-size: 0.75rem; font-weight: 600; color: var(--icon-active); }
.reply-bar-text { font-size: 0.8125rem; color: var(--text-secondary); }
.reply-bar-close {
  flex: none;
  width: 28px; height: 28px;
  border: none; border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.reply-bar-close svg { width: 15px; height: 15px; }
.reply-bar-close:hover { background: var(--surface-hover); }

/* ТЗ 4.1 §7.1 — цитата ответа внутри пузыря. Оба пузыря (входящий/исходящий)
   используют --text-primary, поэтому цвета одни на обе темы, без белого «поверх». */
.reply-quote {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  cursor: pointer;
  padding: 5px 9px;
  margin: 0 0 5px;
  border-radius: 8px;
  border-left: 3px solid var(--purple);
  background: var(--purple-08);
  color: inherit;
}
.reply-quote.deleted { opacity: .75; font-style: italic; }
.reply-quote-who { font-size: 0.75rem; font-weight: 600; color: var(--accent-text); }
.reply-quote-text { font-size: 0.8125rem; color: var(--text-secondary); }

/* §7.2 — метка «Переслано от …». */
.bubble-fwd {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--accent-text);
  margin-bottom: 4px;
}
.bubble-fwd svg { width: 13px; height: 13px; }

/* Короткая подсветка сообщения, к которому перешли из цитаты. */
.msg.flash .bubble { animation: msg-flash 1.2s ease; }
@keyframes msg-flash {
  0%, 100% { box-shadow: var(--shadow-row); }
  25% { box-shadow: 0 0 0 2px var(--icon-active); }
}

/* ============================================================
   ТЗ 4.4 — видеосообщения в 26-угольнике
   ============================================================ */

/* Общий контейнер-фигура: видео обрезано маской правильного 26-угольника. */
.vn-gon {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
}
.vn-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  clip-path: var(--polygon26);      /* фирменная форма, не круг/квадрат/прямоугольник */
  background: #000;
  display: block;
}
/* Контур-индикатор: пройдено — фиолетовый, осталось — серебристо-нейтральный (§5). */
.vn-ring { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.vn-ring-base, .vn-ring-prog { fill: none; stroke-width: 3; }
.vn-ring-base { stroke: #A7ADB7; }                 /* оставшаяся часть */
.vn-ring-prog {
  stroke: #55207A;                                 /* NiMilex Violet — пройденная часть */
  stroke-linejoin: round;
  transition: stroke-dashoffset 120ms linear;
}
.near-limit .vn-ring-prog { stroke: #542366; }      /* §6 мягкий акцент, без красного мигания */

/* Оверлей записи. */
.vn-overlay {
  position: fixed;
  inset: 0;
  z-index: 1180;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(8, 8, 12, .82);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  padding: env(safe-area-inset-top, 0px) 20px env(safe-area-inset-bottom, 0px);
}
.vn-stage { width: min(280px, 72vw); }
.vn-stage > .vn-gon { transition: transform 120ms ease; }   /* §10 мягкое уменьшение к отмене */
.vn-timer {
  color: #fff;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.vn-armhint, .vn-hint {
  color: rgba(255, 255, 255, .82);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.vn-hint svg { width: 16px; height: 16px; }
.vn-hint.hidden, .vn-armhint.hidden, .vn-actions.hidden { display: none; }
/* Пока держим (до старта) — прячем подсказки жестов; в записи — показываем. */
.vn-overlay:not(.recording) .vn-hint { display: none; }
.vn-overlay.recording .vn-armhint { display: none; }
.vn-overlay.locked .vn-hint { display: none; }
.vn-overlay.will-cancel { background: rgba(40, 10, 10, .82); }
.vn-overlay.will-cancel .vn-hint.cancel { color: #ff8a8a; font-weight: 600; }

.vn-actions { display: flex; gap: 16px; }
.vn-btn {
  width: 54px; height: 54px;
  border: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
}
.vn-btn svg { width: 24px; height: 24px; }
.vn-btn.send { background: var(--purple); }
.vn-btn.send:hover { background: var(--purple-active); }

/* Карточка видеосообщения в ленте (§12). Компактная, форму не ломаем. */
.vn-note {
  width: 200px;
  max-width: 62vw;
  margin: 2px 0 4px;
  cursor: pointer;
}
.vn-note .vn-play {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 46px; height: 46px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .42);
  color: #fff;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  transition: opacity 160ms ease;
}
.vn-note .vn-play svg { width: 20px; height: 20px; margin-left: 2px; }
.vn-note.playing .vn-play { opacity: 0; }
.vn-note:hover .vn-play { opacity: 1; }
.vn-note .vn-dur {
  position: absolute;
  left: 50%; bottom: 6%;
  transform: translateX(-50%);
  padding: 1px 7px;
  border-radius: 7px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

/* ТЗ 4.5 §11 — панель записи голосового над composer. */
.vr-overlay {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 1180;
  display: flex;
  justify-content: center;
  padding: 0 12px calc(14px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}
.vr-bar {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(560px, 100%);
  padding: 10px 14px;
  border-radius: var(--r-card);
  background: var(--surface);
  box-shadow: 0 -2px 24px rgba(0, 0, 0, .22);
  border: 1px solid var(--separator);
}
.vr-overlay.will-cancel .vr-bar { border-color: var(--danger); }
.vr-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger, #d9534f);
  flex: none;
  animation: mp-blink 1s steps(2, start) infinite;
}
.vr-overlay.paused .vr-dot { animation: none; opacity: .5; }
.vr-timer { font-variant-numeric: tabular-nums; font-size: 0.95rem; flex: none; }
.vr-level {
  flex: 1 1 auto;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-sunken);
  position: relative;
  overflow: hidden;
}
.vr-level::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: calc(var(--lvl, 0) * 100%);
  background: var(--purple);
  border-radius: 3px;
  transition: width 90ms linear;
}
.vr-hint { font-size: 0.78rem; color: var(--text-secondary); flex: none; }
.vr-armhint { font-size: 0.85rem; color: var(--text-secondary); }
.vr-hint.hidden, .vr-armhint.hidden, .vr-actions.hidden { display: none; }
.vr-overlay:not(.recording) .vr-hint,
.vr-overlay:not(.recording) .vr-level,
.vr-overlay:not(.recording) .vr-dot { display: none; }
.vr-overlay.recording .vr-armhint { display: none; }
.vr-actions { display: flex; gap: 8px; flex: none; }
.vr-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-sunken);
  color: var(--text-primary);
  cursor: pointer;
}
.vr-btn svg { width: 20px; height: 20px; }
.vr-btn.send { background: var(--purple); color: #fff; }
.vr-btn.send:hover { background: var(--purple-active); }

/* Телефон: крупнее зоны нажатия. */
@media (hover: none) and (pointer: coarse) {
  .mv-btn, .pe-top-btn, .mvw-btn { width: 44px; height: 44px; }
  .ve-handle { width: 18px; margin-left: -9px; }
  .vr-hint { display: none; }
}

/* ============================================================
   ТЗ 4.5 — правка, закрепление, важное, системная история, опросы, контакт
   ============================================================ */

/* §5 «изменено» — компактная отметка рядом со временем, без истории версий. */
.bubble-edited {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-style: italic;
}

/* §9 «Важное» в рабочем чате — небольшой золотой акцент, не заливка. */
.bubble-important {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--brass);
  margin-bottom: 4px;
}
.bubble-important .nmx-sign { width: 14px; height: 14px; color: var(--brass); }
.bubble.important { box-shadow: inset 2px 0 0 var(--brass); }

/* §15 Закреплённое: тонкая фирменная грань слева, без крупной заливки. */
.bubble.is-pinned { box-shadow: inset 2px 0 0 var(--ink-dry); }

/* §15 Компактная полоса закреплённого под шапкой диалога. */
.pin-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px var(--pad-screen);
  border-bottom: 1px solid var(--separator);
  background: var(--surface);
}
.pin-bar.hidden { display: none; }
.pin-bar-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border: 0;
  border-radius: var(--r-row);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pin-bar-main:hover { background: var(--surface-hover); }
.pin-bar-main > svg { width: 16px; height: 16px; color: var(--icon); flex: none; }
.pin-bar-text { min-width: 0; }
.pin-bar-who { font-size: 0.75rem; font-weight: 600; color: var(--accent-text); }
.pin-bar-preview { font-size: 0.8125rem; color: var(--text-secondary); }
.pin-bar-next, .pin-bar-off {
  flex: none;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-row);
  background: transparent; color: var(--icon);
  cursor: pointer;
}
.pin-bar-next:hover, .pin-bar-off:hover { background: var(--surface-hover); color: var(--icon-hover); }
.pin-bar-next svg, .pin-bar-off svg { width: 16px; height: 16px; }
.pin-bar-next svg { transform: rotate(90deg); }

/* §9 Системная история рабочего чата — строка по центру, не пузырь. */
.msg.system { display: flex; justify-content: center; margin: 6px 0; }
.system-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(560px, 90%);
  padding: 5px 12px;
  border-radius: var(--r-row);
  background: var(--surface-sunken);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}
.system-line .nmx-sign { width: 14px; height: 14px; color: var(--brass); flex: none; }
.system-time { color: var(--text-tertiary); font-size: 0.6875rem; }

/* §10 Опрос внутри пузыря. Фиолетовый — только смысловой акцент прогресса. */
.poll { display: flex; flex-direction: column; gap: 6px; min-width: min(280px, 60vw); }
.poll-head { margin-bottom: 2px; }
.poll-q { font-weight: 600; }
.poll-kind { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 2px; }
.poll-opt {
  position: relative;
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--separator);
  border-radius: var(--r-row);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}
.poll-opt:hover:not(:disabled) { background: var(--surface-hover); }
.poll-opt.picked { border-color: var(--ink-dry); }
.poll-opt:disabled { cursor: default; }
.poll-mark { display: grid; place-items: center; color: var(--icon-active); }
.poll-mark svg { width: 15px; height: 15px; }
.poll-opt-text { min-width: 0; }
.poll-share { font-size: 0.8125rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.poll-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: transparent;
}
.poll-bar-fill { display: block; height: 100%; background: var(--ink-violet); transition: width var(--dur) var(--ease); }
.poll-voters { font-size: 0.75rem; color: var(--text-tertiary); padding: 0 10px 2px; }
.poll-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.poll-total { font-size: 0.75rem; color: var(--text-tertiary); flex: 1; }
.poll-edit-options { display: flex; flex-direction: column; gap: 8px; }
.poll-edit-row { display: flex; align-items: center; gap: 6px; }
.poll-edit-row .field { flex: 1; min-width: 0; }

/* §16 Карточка контакта в сообщении. */
.contact-card { display: flex; flex-direction: column; gap: 8px; min-width: min(240px, 56vw); }
.contact-main { display: flex; align-items: center; gap: 10px; }
.contact-name { font-weight: 600; }
.contact-line { font-size: 0.8125rem; color: var(--text-secondary); }
.contact-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* §8/§18 Сведения о чате: шапка, участники и их действия. */
.chat-info { display: flex; flex-direction: column; gap: 4px; }
.chat-info-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.chat-info-id { min-width: 0; }
.chat-info-id .name { font-size: 1.125rem; font-weight: 700; }
.chat-info-id .role { font-size: 0.875rem; color: var(--text-secondary); }
.work-line { display: flex; align-items: center; gap: 6px; font-size: 0.8125rem; color: var(--brass); margin-top: 2px; }
.work-line .nmx-sign { width: 15px; height: 15px; color: var(--brass); }
.member-block { display: flex; flex-direction: column; }
.member-actions { display: flex; gap: 6px; padding: 0 12px 10px; flex-wrap: wrap; }
.member-row .value { font-size: 0.8125rem; color: var(--text-tertiary); }

/* ТЗ 4.4 §7: смена камеры и закрытие предпросмотра поверх оверлея записи. */
.vn-flip, .vn-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  background: var(--glass-fill);
  color: var(--silver);
  cursor: pointer;
}
.vn-flip { right: 16px; }
.vn-close { left: 16px; }
.vn-flip svg, .vn-close svg { width: 20px; height: 20px; }
/* Во время записи менять камеру нельзя — кадр потеряется (§7). */
.vn-overlay.recording .vn-flip,
.vn-overlay.recording .vn-close { display: none; }

/* §6: при открытом меню выбранное сообщение слегка выделяется, остальная лента
   мягко приглушается. Тяжёлый blur не применяем — только прозрачность. */
.dialog-body.menu-dim .msg { opacity: .45; transition: opacity var(--dur) var(--ease); }
.dialog-body.menu-dim .msg.menu-focus { opacity: 1; }
.dialog-body.menu-dim .msg.menu-focus .bubble { box-shadow: 0 0 0 2px var(--ink-dry); }

/* §4: короткий свайп вправо — быстрый Reply. За порогом показываем, что жест
   сработает: подсвечиваем пузырь фирменной гранью. */
.msg.swipe-armed .bubble { box-shadow: inset 3px 0 0 var(--ink-violet); }
