/* Раздел «Чаты»: список, лента сообщений, поле ввода. */

/* ---------- Лента сообщений ---------- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overscroll-behavior: contain;
}

.day-sep {
  align-self: center;
  margin: 14px 0 10px;
  padding: 4px 12px;
  border-radius: var(--r-full);
  background: rgba(0, 0, 0, 0.06);
  color: var(--label-secondary);
  font-size: 12px;
  font-weight: 600;
}

.msg {
  display: flex;
  gap: 8px;
  max-width: 76%;
  align-self: flex-start;
  animation: msg-in var(--dur) var(--ease);
}

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

.msg.is-out {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* Подряд идущие сообщения одного автора прижимаются друг к другу */
.msg.is-grouped {
  margin-top: -1px;
}

.msg-avatar-slot {
  width: 32px;
  flex: 0 0 32px;
  display: flex;
  align-items: flex-end;
}

.msg.is-out .msg-avatar-slot,
.msg.is-grouped .avatar {
  visibility: hidden;
}

.bubble {
  position: relative;
  padding: 7px 12px 6px;
  border-radius: 18px;
  background: var(--bubble-in);
  color: var(--label);
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg.is-out .bubble {
  background: var(--bubble-out);
  color: #fff;
}

/* Хвостик у последнего сообщения в группе */
.msg.is-tail .bubble {
  border-bottom-left-radius: 5px;
}

.msg.is-out.is-tail .bubble {
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 5px;
}

.msg-author {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 2px;
}

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

.msg-text.is-deleted {
  font-style: italic;
  opacity: 0.6;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--label-secondary);
  user-select: none;
}

.msg.is-out .msg-meta {
  color: rgba(255, 255, 255, 0.75);
}

.msg-edited {
  font-style: italic;
}

/* Галочки доставки и прочтения */
.ticks {
  width: 16px;
  height: 11px;
  flex: 0 0 16px;
}

.ticks.is-read {
  color: #fff;
}

/* Блок «в ответ на» */
.reply-quote {
  border-left: 3px solid var(--blue);
  padding: 3px 8px;
  margin-bottom: 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.05);
  font-size: 14px;
  cursor: pointer;
}

.msg.is-out .reply-quote {
  border-left-color: #fff;
  background: rgba(255, 255, 255, 0.16);
}

.reply-quote-author {
  font-weight: 600;
  font-size: 13px;
  color: var(--blue);
}

.msg.is-out .reply-quote-author {
  color: #fff;
}

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

.forwarded-mark {
  font-size: 13px;
  font-style: italic;
  opacity: 0.75;
  margin-bottom: 3px;
}

/* Подсветка сообщения при переходе по ответу */
.msg.is-highlighted .bubble {
  animation: highlight 1.6s var(--ease);
}

@keyframes highlight {
  0%, 40% { box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.5); }
  100% { box-shadow: 0 0 0 0 rgba(0, 122, 255, 0); }
}

/* ---------- Вложения ---------- */

.attach {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border-radius: var(--r-sm);
  margin-top: 4px;
  /* Вложение — это ссылка, но общий синий цвет ссылок здесь совпал бы
     с синим фоном своего пузыря и текст стал бы невидимым. */
  color: inherit;
}

.attach:hover {
  text-decoration: none;
  background: rgba(0, 0, 0, 0.05);
}

.msg.is-out .attach:hover {
  background: rgba(255, 255, 255, 0.14);
}

.attach-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
}

.msg.is-out .attach-icon {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.attach-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-size {
  font-size: 12px;
  opacity: 0.7;
}

.attach-image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--r-md);
  margin-top: 4px;
}

/* ---------- Голосовое сообщение ---------- */

.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
  min-width: 190px;
}

.voice-play {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: var(--r-full);
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur-fast) var(--ease);
}

.voice-play:active {
  transform: scale(0.92);
}

.msg.is-out .voice-play {
  background: #fff;
  color: var(--blue);
}

.voice-wave {
  flex: 1;
  height: 30px;
  display: block;
  cursor: pointer;
}

.voice-time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
  flex: 0 0 auto;
}

/* ---------- «Печатает» ---------- */

.typing {
  padding: 2px 16px 6px;
  font-size: 13px;
  color: var(--blue);
  height: 22px;
}

.typing-dots span {
  display: inline-block;
  animation: typing-bounce 1.2s var(--ease) infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* ---------- Поле ввода ---------- */

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--separator);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

/* Панель ответа или редактирования над полем ввода */
.composer-context {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 8px;
  border-left: 3px solid var(--blue);
  margin-bottom: 6px;
  border-radius: 4px;
  background: var(--bg-hover);
}

.composer-context-body {
  flex: 1;
  min-width: 0;
}

.composer-context-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
}

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

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer-input {
  flex: 1;
  min-height: 38px;
  max-height: 160px;
  padding: 8px 14px;
  border-radius: 19px;
  background: var(--bg-input);
  border: 1px solid transparent;
  outline: none;
  resize: none;
  font-size: 16px;
  line-height: 1.35;
  overflow-y: auto;
  transition: border-color var(--dur-fast) var(--ease);
}

.composer-input:focus {
  border-color: var(--blue);
  background: var(--bg);
}

.composer-send {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: var(--r-full);
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}

.composer-send:disabled {
  opacity: 0.35;
}

.composer-send:active:not(:disabled) {
  transform: scale(0.9);
}

/* Запись голосового: поле ввода заменяется индикатором */
.recording {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  padding: 0 6px;
}

.rec-dot {
  width: 11px;
  height: 11px;
  border-radius: var(--r-full);
  background: var(--red);
  animation: rec-pulse 1.1s var(--ease) infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.rec-time {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 500;
}

.rec-hint {
  font-size: 13px;
  color: var(--label-secondary);
  flex: 1;
}

/* Выбранные, но ещё не отправленные файлы */
.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.attach-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  border-radius: var(--r-sm);
  background: var(--bg-input);
  font-size: 13px;
  max-width: 240px;
}

.attach-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-chip-remove {
  color: var(--label-secondary);
  display: flex;
}

/* Полоса загрузки файла */
.upload-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--bg-active);
  overflow: hidden;
  margin-bottom: 8px;
}

.upload-bar-fill {
  height: 100%;
  background: var(--blue);
  width: var(--progress, 0%);
  transition: width var(--dur-fast) linear;
}

/* ---------- Список чатов ---------- */

.chat-row-time {
  font-size: 12px;
  color: var(--label-secondary);
  white-space: nowrap;
}

.chat-row-preview {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.chat-case-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--orange);
  background: rgba(255, 149, 0, 0.12);
  padding: 1px 7px;
  border-radius: var(--r-full);
  margin-top: 3px;
}

.pin-mark {
  width: 13px;
  height: 13px;
  color: var(--label-tertiary);
}
