/* EveryIdea — вкладка «Мессенджер» (M2-UI, минимальная).
   docs/messenger-arch-2026-10-03.md (раздел 10, M2). Только var()-токены
   тем (base.css), новых theme-токенов не вводим. Тач-таргеты 44px
   (--size-touch). Мобила: список ↔ лента по .editor-open (как заметки). */

.messenger-view { display: none; }
.messenger-view.active-view { display: flex; }

/* ============ Список разговоров ============ */
.msg-list-pane {
  width: 320px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--separator);
}

.msg-new-btn { flex: none; display: inline-flex; align-items: center; gap: var(--s1); }

.msg-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: var(--s2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 56px;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-control);
  text-align: left;
  color: var(--text);
  transition: background-color 120ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .msg-row:hover { background: var(--fill); }
}
.msg-row:active { background: var(--fill); }

.msg-row-avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.msg-row-avatar .icon { width: 20px; height: 20px; }

.msg-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.msg-row-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-row-sub {
  font-size: 12px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-row-meta {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}
.msg-row-time {
  font-size: var(--font-xs);
  color: var(--hint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.msg-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: var(--font-xs);
  font-weight: 700;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}

/* ============ Лента чата ============ */
.msg-feed-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.msg-feed-header { gap: var(--s2); }
.msg-feed-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-e2e {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-strong); /* текст 11px на accent-soft: AMOLED 2.46:1 → strong даёт ≥4.5 во всех темах */
  font-size: var(--font-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.msg-e2e .icon { width: 13px; height: 13px; }
.msg-menu-btn {
  flex: none;
  width: var(--size-touch);
  height: var(--size-touch);
  margin: calc((var(--size-touch) - 40px) / -2);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--hint);
  transition: background-color 120ms ease, color 120ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .msg-menu-btn:hover { color: var(--text); background: var(--fill); }
}
.msg-menu-btn:active { background: var(--fill); }
.msg-menu-btn .icon { width: 20px; height: 20px; }

.msg-feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.msg-feed-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  color: var(--hint);
  text-align: center;
  padding: var(--s6);
}
.msg-feed-empty .icon { width: 28px; height: 28px; color: var(--accent); }

.msg-bubble-wrap { display: flex; }
.msg-bubble-wrap.me { justify-content: flex-end; }
.msg-bubble-wrap.peer { justify-content: flex-start; }

.msg-bubble {
  max-width: min(76%, 560px);
  padding: var(--s2) var(--s3);
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.42;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-bubble-wrap.me .msg-bubble {
  background: var(--accent);
  color: var(--accent-contrast);
  border-bottom-right-radius: 6px;
}
.msg-bubble-wrap.peer .msg-bubble {
  background: var(--fill);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.msg-bubble-text { display: block; }
.msg-bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-size: var(--font-xs);
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}
.msg-status { display: inline-flex; }
.msg-status-icon { width: 13px; height: 13px; }
.msg-status-failed { color: var(--destructive); opacity: 1; }
/* M3: ✓✓ доставлено (ack адресата дошёл до отправителя через poll). */
.msg-status-delivered { color: var(--accent); opacity: 1; }
/* M3 (баг, пойман CDP-скриншотом): статус живёт ВНУТРИ своего пузыря
   (фон — accent) → accent-иконка невидима. На своём пузыре — accent-contrast;
   failed остаётся destructive (различим на accent). */
.msg-bubble-wrap.me .msg-status { color: var(--accent-contrast); }
.msg-bubble-wrap.me .msg-status-failed { color: var(--destructive); }
/* M3: индикатор отозванного устройства в шапке чата. */
.msg-revoked {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--destructive);
  font-size: var(--font-xs);
  flex: none;
}
.msg-revoked.hidden { display: none; }
.msg-revoked-icon { width: 14px; height: 14px; }

/* ============ Композер ============ */
.msg-composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  padding-bottom: calc(var(--s3) + var(--safe-area-inset-bottom));
  border-top: 1px solid var(--separator);
  background: var(--surface);
}
.msg-input {
  flex: 1;
  min-width: 0;
  min-height: var(--size-touch);
  max-height: 132px;
  padding: 10px var(--s3);
  border: 1px solid var(--separator);
  border-radius: var(--r-card);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.4;
  resize: none;
}
.msg-input:focus { outline: none; border-color: var(--accent); }
.msg-send-btn {
  flex: none;
  width: var(--size-touch);
  height: var(--size-touch);
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0;
}
.msg-send-btn .icon { width: 20px; height: 20px; }

/* ============ Invite-диалог ============ */
.msg-invite-hint { font-size: 13px; color: var(--hint); margin: 0 0 var(--s3); }
.msg-invite-link {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  padding: var(--s3);
  border-radius: var(--r-control);
  background: var(--fill);
  color: var(--text);
  word-break: break-all;
  user-select: all;
  margin-bottom: var(--s4);
}

/* ============ Мобила: список ↔ лента (как заметки) ============ */
@media (max-width: 600px) {
  .msg-list-pane { width: 100%; border-right: none; }
  .msg-feed-pane { display: none; }
  .messenger-view.editor-open .msg-list-pane { display: none; }
  .messenger-view.editor-open .msg-feed-pane {
    display: flex;
    position: absolute;
    inset: 0;
    /* Лента не заходит под постоянный таб-бар: низ = верх бара. Композер
       внутри панели, поэтому его safe-area-паддинг на мобиле не нужен
       (перебит ниже) — иначе двойной отступ. */
    bottom: calc(var(--tabbar-h) + var(--safe-area-inset-bottom));
    z-index: 10;
    background: var(--surface);
  }
  .msg-composer { padding-bottom: var(--s3); }
  /* Список разговоров: последний чат не прячется под баром. */
  .msg-list { padding-bottom: calc(var(--bottom-ui) + var(--s2)); }
  .msg-bubble { max-width: 86%; }
}
