/* МУРАВЕЙ — экран чата (owner: chat, docs/CONTRACT.md §7.4).
   Исходящие — жёлтые пузыри с тёмным текстом, входящие — тёмные панели; инструменты и отправка — соты.
   Общие классы (шапка, .hex-btn, .empty-state, .modal, .spin) — из app.css и common.css. */

.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header { flex-shrink: 0; }

/* ===== Шапка: собеседник и звонок ===== */
.chat-peer { flex: 1; min-width: 0; display: flex; }
.chat-peer-btn {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 2px 4px;
  background: none; border: none; border-radius: 12px;
  font-family: inherit; text-align: left; color: var(--text);
  cursor: pointer;
}
.chat-peer-btn:active { opacity: 0.75; }
.chat-peer-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-peer-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 15px; font-weight: 800; line-height: 1.2; color: #fff;
}
.chat-peer-role { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--text-muted); }
.chat-peer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-call { flex-shrink: 0; text-decoration: none; }

/* ===== Тело: список сообщений ===== */
.chat-body { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-empty { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 0 var(--gutter); }
.chat-list {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px var(--gutter) 12px;
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chat-list::-webkit-scrollbar { display: none; }
.chat-list > * { flex-shrink: 0; }

.chat-day {
  align-self: center;
  margin: 8px 0 4px; padding: 4px 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line-soft); border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; color: var(--text-muted);
}

.chat-row { display: flex; }
.chat-row.mine { justify-content: flex-end; }
.chat-row.theirs { justify-content: flex-start; }
.chat-bubble {
  max-width: 80%;
  padding: 9px 12px 6px;
  border-radius: 18px;
  font-size: 14px; line-height: 1.4;
  overflow-wrap: anywhere;
}
.chat-row.mine .chat-bubble {
  background: linear-gradient(165deg, #FFDE5A 0%, #F0BB10 100%);
  color: var(--ink);
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 18px rgba(255, 214, 64, 0.18);
}
.chat-row.theirs .chat-bubble {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: 6px;
}
.chat-row.pending .chat-bubble { opacity: 0.65; }
.chat-text {
  margin: 0;
  white-space: pre-wrap;
  -webkit-user-select: text; user-select: text;
}
.chat-voice-label { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.chat-voice-label svg { flex-shrink: 0; width: 15px !important; height: 15px !important; }
.chat-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 5px;
  margin-top: 3px;
  font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: rgba(245, 247, 250, 0.55);
}
.chat-row.mine .chat-meta { color: rgba(10, 22, 40, 0.6); }
.chat-spinner {
  width: 10px; height: 10px; flex-shrink: 0;
  border: 1.5px solid currentColor; border-top-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Фото: фиксированная рамка 4:3, чтобы список не прыгал при загрузке картинок */
.chat-photo {
  display: block; width: 240px; max-width: 100%; aspect-ratio: 4 / 3;
  margin: 0 0 6px; padding: 0;
  overflow: hidden;
  background: rgba(8, 20, 38, 0.5);
  border: none; border-radius: 12px;
  cursor: zoom-in;
}
.chat-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.chat-audio {
  display: block; width: 240px; max-width: 100%; height: 40px;
  margin: 0 0 4px;
  color-scheme: dark;
}

.chat-new {
  position: absolute; left: 50%; bottom: 12px; z-index: 2;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  transform: translateX(-50%);
  background: var(--yellow); color: var(--ink);
  border: none; border-radius: 999px;
  font-family: inherit; font-size: 12px; font-weight: 800; letter-spacing: 0.04em; white-space: nowrap;
  box-shadow: 0 6px 20px rgba(255, 214, 64, 0.35);
  cursor: pointer;
}
.chat-new svg { width: 14px !important; height: 14px !important; }

/* ===== Композер ===== */
.chat-composer {
  flex-shrink: 0;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  background: rgba(8, 20, 38, 0.9);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 214, 64, 0.08);
}
.chat-lock {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  font-size: 12px; font-weight: 600; line-height: 1.35; color: var(--yellow);
  background: rgba(255, 214, 64, 0.07);
  border: 1px solid rgba(255, 214, 64, 0.22); border-radius: 14px;
}
.chat-lock svg { flex-shrink: 0; width: 15px !important; height: 15px !important; }
.chat-input-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-field {
  flex: 1; min-width: 0;
  display: flex;
  padding: 4px 14px;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-field:focus-within {
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(255, 214, 64, 0.12);
}
.chat-composer.locked .chat-field { opacity: 0.55; }
.chat-input {
  flex: 1; min-width: 0; min-height: 36px; max-height: 128px;
  padding: 8px 0;
  background: none; border: none; outline: none;
  resize: none;
  font-family: inherit; font-size: 15px; line-height: 1.4; color: var(--text);
  color-scheme: dark;
  -webkit-user-select: text; user-select: text;
}
.chat-input::placeholder { color: rgba(245, 247, 250, 0.35); }
.chat-input:disabled { cursor: not-allowed; }

.chat-tool,
.chat-send {
  position: relative; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; padding: 0;
  border: none;
  clip-path: var(--hex-clip);
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s, background 0.2s;
}
.chat-tool { background: rgba(255, 214, 64, 0.12); color: var(--yellow); }
.chat-tool:hover { background: rgba(255, 214, 64, 0.2); }
.chat-send { background: linear-gradient(165deg, #FFDE5A 0%, #F0BB10 100%); color: var(--ink); }
.chat-tool svg,
.chat-send svg { width: 18px !important; height: 18px !important; }
.chat-tool:active,
.chat-send:active { transform: scale(0.94); }
/* clip-path cuts the outline off, so focus is shown as a fill change */
.chat-tool:focus-visible { outline: none; background: var(--yellow); color: var(--ink); }
.chat-send:focus-visible { outline: none; background: #fff; }
.chat-tool:disabled,
.chat-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.chat-tool.busy:disabled { opacity: 0.8; cursor: progress; }
.chat-tool.busy > svg { visibility: hidden; }
.chat-tool.busy::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border: 2.5px solid rgba(255, 214, 64, 0.3); border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Запись голоса вместо строки ввода */
.chat-recording {
  display: flex; align-items: center; gap: 10px;
  min-height: 54px; padding: 0 6px 0 14px;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.4); border-radius: 18px;
}
.chat-rec-dot {
  flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  animation: recPulse 1s ease-in-out infinite;
}
@keyframes recPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.chat-rec-time {
  min-width: 44px;
  font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; color: #fff;
}
.chat-rec-hint {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; color: var(--text-muted);
}

/* ===== Просмотр фото ===== */
.modal.chat-lightbox {
  max-width: min(96vw, 720px);
  background: none; border: none; box-shadow: none;
}
.chat-lightbox .modal-body { padding: 0; }
.chat-lightbox .modal-close { background: rgba(8, 20, 38, 0.85); }
.chat-lightbox-img {
  display: block; max-width: 100%; max-height: 78vh;
  margin: 0 auto;
  object-fit: contain;
  border-radius: 16px;
}
