/* Стили раздела «chat» (P-370, рефакторинг P-365 · Р-5). Подключается в
   templates/base.html сразу после styles.css, в порядке разделов: patients, schedule, leads, chat, tasks, money, analytics.
   Новый блок раздела пишется сюда, общее — в styles.css. */

/* Диалоги: кто это — фото из WhatsApp или инициалы (Паша, 29.09.2026) */
.ava { position: relative; width: 40px; height: 40px; border-radius: 999px; overflow: hidden;
  flex-shrink: 0; display: grid; place-items: center;
  background: var(--primary-tint-strong); color: var(--primary-hover); }
.ava b { font-size: 15px; font-weight: 600; }
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ava-lg { width: 44px; height: 44px; }
.inbox-list .dlg { display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 10px; row-gap: 2px; }
.inbox-list .dlg > .ava { grid-row: 1 / span 3; align-self: center; }
.inbox-list .dlg > :not(.ava) { grid-column: 2; }
.chat-head { justify-content: flex-start; }
.chat-head .chat-who { flex: 1; min-width: 0; }

/* файл в пузыре: фото картинкой, документ строкой */
.msg-photo { display: block; margin: -3px -6px 6px; border-radius: var(--r-sm); overflow: hidden; line-height: 0; }
.msg-photo img { display: block; max-width: 100%; width: 280px; max-height: 320px; object-fit: cover; background: var(--surface-sunken); }
.msg-photo:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.msg-audio { display: block; width: 260px; max-width: 100%; height: 36px; margin-bottom: 4px; }
.msg-video { display: block; width: 280px; max-width: 100%; border-radius: var(--r-sm); margin-bottom: 6px; }
.msg-doc { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px;
  align-items: center; min-width: 200px; max-width: 300px; padding: 6px 10px 6px 6px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg);
  color: var(--ink); text-decoration: none; }
a.msg-doc:hover { border-color: var(--primary); }
a.msg-doc:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.msg-doc-ext { grid-row: 1 / 3; width: 40px; height: 40px; border-radius: var(--r-sm); display: grid; place-items: center;
  background: var(--primary-tint); color: var(--primary); font-size: 11px; font-weight: 600; }
.msg-doc-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-doc-size { font-size: 11.5px; color: var(--muted); }
.msg-doc.is-missing .msg-doc-ext { background: var(--surface-sunken); color: var(--muted); }
.msg > .msg-doc:last-child, .msg > .msg-photo:last-child { margin-bottom: 0; }
@media (prefers-reduced-motion: reduce) { .attach-chip { animation: none; } }

/* ── Диалоги · вкладки номеров: отключённый и «только смотрим» подписаны прямо на вкладке (30.09.2026) ── */
.funnel-tab .tab-note { color: var(--muted); font-weight: 400; }

/* ── Диалоги · «Показать ещё» под списком переписок (01.10.2026) ── */
.dlg-more { display: block; margin: var(--sp-3); text-align: center; }

/* Быстрые ответы в переписке (I-15): список над полем ответа и страница шаблонов */
.chat-send[data-attach] { position: relative; }
.tpl-pop { position: absolute; left: var(--sp-5); right: var(--sp-5); bottom: calc(100% - 4px);
  z-index: var(--z-dropdown); background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg); padding: 8px;
  display: flex; flex-direction: column; gap: 6px; max-height: min(420px, 60vh);
  animation: menu-in 140ms cubic-bezier(0.22, 1, 0.36, 1); }
.tpl-pop[hidden] { display: none; }
.tpl-q { border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 8px 10px;
  font: inherit; font-size: 13.5px; outline: none; }
.tpl-q:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.tpl-list { overflow-y: auto; display: flex; flex-direction: column; gap: 1px; min-height: 0; }
.tpl-item { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit;
  color: var(--ink); padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.tpl-item:hover, .tpl-item.is-on { background: var(--primary-tint); }
.tpl-item b { display: block; font-size: 13px; font-weight: 600; }
.tpl-item span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tpl-empty { padding: 10px; font-size: 12.5px; color: var(--muted); }
.tpl-manage { font-size: 12.5px; color: var(--primary); padding: 2px 10px 0; align-self: flex-start; }
@media (prefers-reduced-motion: reduce) { .tpl-pop { animation: none; } }
.replies-page { display: flex; flex-direction: column; gap: var(--sp-4); max-width: 760px; }
.reply-row { border-top: 1px solid var(--border); }
.reply-row summary { cursor: pointer; padding: 10px 0; display: flex; flex-direction: column; gap: 2px;
  list-style: none; }
.reply-row summary::-webkit-details-marker { display: none; }
.reply-row summary b { font-size: 13.5px; font-weight: 600; }
.reply-preview { font-size: 12.5px; color: var(--muted); }
.reply-edit { display: flex; flex-direction: column; gap: var(--sp-3); padding-bottom: var(--sp-4); }
.reply-edit .form-actions { margin-top: 0; }
@media (max-width: 640px) { .tpl-pop { left: var(--sp-3); right: var(--sp-3); } }

/* телефон: поле ответа — своей строкой во всю ширину, кнопки под ним (I-15) */
@media (max-width: 640px) {
  .chat-send-row { flex-wrap: wrap; }
  .chat-send-row textarea { order: -1; flex-basis: 100%; }
  .chat-send-row [data-send] { margin-left: auto; }
}

/* ── P-115: «Квалифицирован» в шапке переписки ──
   Знак вопроса стоит рядом с кнопкой, а не под ней. Кнопок в шапке стало семь:
   они переносятся на вторую строку, а не наезжают на имя человека */
.qualify-form { display: inline-flex; align-items: center; gap: 2px; }
.chat-actions { flex-wrap: wrap; justify-content: flex-end; }
.chat-head .chat-who { min-width: 160px; }

/* ── P-115: знак у «Квалифицирован» виден всегда, а не при наведении ──
   Паша 02.10.2026: «не вижу вопросительного знака рядом с кнопкой».
   У этапов воронки (P-109) знак — при наведении, как у всех подсказок: Паша 02.10 вернул
   задачу словами «при наведении мыши» */
.qualify-form .hint-mark { opacity: 1; }

/* ── P-133: шапка переписки на телефоне ──
   Кнопок в шапке до семи, и колонкой справа от имени они уходили за край экрана.
   На узком экране они встают строкой под имя и переносятся по ширине */
@media (max-width: 720px) {
  .chat-head { flex-wrap: wrap; }
  .chat-head .chat-who { flex: 1 1 0; min-width: 0; }
  .chat-actions { flex: 1 1 100%; justify-content: flex-start; }
}
/* P-135: когда написали — разделитель дня в ленте, время под сообщением, время в строке списка.
   Разделитель не «прилипает»: лента одна на все дни, и прилипшие плашки ложились стопкой
   друг на друга (тестер, 08.10.2026). */
.day-sep { align-self: center; display: flex; justify-content: center; margin: 6px 0 2px; }
.day-sep span { padding: 3px 10px; border-radius: 999px; background: var(--surface-sunken);
  border: 1px solid var(--border); font-size: 12px; font-weight: 500; color: var(--muted);
  box-shadow: 0 1px 2px oklch(0.24 0.015 235 / 0.06); }
.msg-time { font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--muted); }
.dlg-time { flex: none; margin-left: auto; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.dlg.is-wait .dlg-time { color: var(--ink); font-weight: 500; }

/* ── P-291: звонок служебной строкой в ленте переписки ──────────────────── */
.msg-call { align-self: center; max-width: 85%; margin: 4px auto; padding: 3px 12px; font-size: 12px; color: var(--muted); background: var(--surface, #fff); border: 1px dashed var(--border-strong, #ccc); border-radius: 999px; text-align: center; }

/* P-358 · служебный чат «Уведомления» администраторов: первой строкой «Диалогов» */
.dlg-notices { border-left: 3px solid var(--primary); }
.dlg-notices-ava { background: var(--primary); color: #fff; font-size: 16px; }
.dlg-notices-ava b { color: #fff; font-size: 17px; }
.dlg-notices-count { background: var(--primary); color: #fff; border-radius: 10px; font-size: 12px;
  font-weight: 600; padding: 0 7px; line-height: 18px; flex: none; }
.notice-msg { max-width: min(560px, 92%); }
.notice-title { font-weight: 600; margin-bottom: 2px; }
.notice-comment { background: var(--surface-sunken); border-radius: 6px; padding: 6px 8px; margin-top: 6px; }
.notice-link { display: inline-block; margin-top: 6px; font-weight: 600; color: var(--primary); }
