/* ai-os-admin-design · lib/chat.css — переписка с агентами как мессенджер.

   Общие куски окна разговора на сцене (office/talk.js) и страницы
   /agents/<slug>/dialog (agentcard/dialog.js): аватар, строка сообщения,
   разделитель дня, строка «печатает», поле ввода. Раскладку каждый экран
   держит у себя (office/talk.css, agentcard/dialog.css). Цвет — только
   токенами из tokens.css. */

/* ── аватар: портрет из кадра idle (lib/portrait.js) или буква ────── */
.ava {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--paper-mute);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}
.ava.pic {
  background-repeat: no-repeat;
  background-size: 100% 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.ava.owner { background: var(--fg); border-color: var(--fg); color: var(--fg-on-ink); }
.ava.system { background: var(--info-bg); border-color: transparent; color: var(--info); }
.ava svg { display: block; }
.ava .sdot {
  position: absolute;
  right: -3px;
  bottom: -3px;
  box-sizing: content-box;
  width: 8px;
  height: 8px;
  border: 2px solid var(--paper-card);
}
.ava.lg { width: 44px; height: 44px; border-radius: 11px; }
/* агент печатает — кольцо вокруг аватара */
.ava.typing::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--ok-dot);
  border-radius: 13px;
  opacity: .6;
  animation: ava-ring 1.6s var(--ease-out) infinite;
}
@keyframes ava-ring {
  0% { transform: scale(.92); opacity: .7; }
  70% { transform: scale(1.08); opacity: 0; }
  100% { opacity: 0; }
}

/* ── лента ─────────────────────────────────────────────────────────── */
.ch-feed {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  margin: 0;
  padding: 8px 0 16px;
  overflow-y: auto;
  list-style: none;
}
.ch-feed > * { flex: none; }
.ch-feed > li { list-style: none; }

.ch-day {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px 6px;
  color: var(--fg-label);
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.ch-day::before, .ch-day::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.ch-msg {
  position: relative;
  display: grid;
  grid-template-columns: 36px 1fr;
  column-gap: 12px;
  padding: 6px 20px;
  transition: background var(--dur-fast);
}
.ch-msg:hover { background: var(--paper-raised); }
.ch-msg.cont { padding-top: 2px; padding-bottom: 2px; }
.ch-msg.cont .ava { visibility: hidden; height: 0; }
.ch-msg.cont .ch-head { display: none; }
.ch-body { grid-column: 2; min-width: 0; }
.ch-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
  line-height: 1.3;
}
.ch-who { font-size: var(--fs-sm); font-weight: 600; }
.ch-who a { color: inherit; }
.ch-who a:hover { text-decoration: underline; }
.ch-time {
  color: var(--fg-label);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  font-variant-numeric: tabular-nums;
}
.ch-subj {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 5px;
  background: var(--paper-mute);
  color: var(--fg-muted);
  font-size: var(--fs-label);
  font-weight: 500;
}
.ch-subj.system { background: var(--info-bg); color: var(--info); }
.ch-subj.office { background: var(--d-amber-bg); color: var(--d-amber); }
.ch-text {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* Разметка письма (mdlite, 20.09.2026): агенты пишут markdown, и лента
   показывает его как разметку. Набор тот же, что у прозы .md в styles.css,
   но размер и цвет — реплики, а не карточки. pre-wrap остаётся для голого
   <pre> своей реплики до перезагрузки (agentcard/dialog.js). */
.ch-text > * { margin: 0; white-space: normal; }
.ch-text > * + * { margin-top: 6px; }
.ch-text h2, .ch-text h3, .ch-text h4, .ch-text h5, .ch-text h6 {
  font-size: var(--fs-body);
  font-weight: 600;
}
.ch-text h4, .ch-text h5, .ch-text h6 {
  color: var(--fg-label);
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.ch-text * + h2, .ch-text * + h3, .ch-text * + h4 { margin-top: 12px; }
.ch-text ul, .ch-text ol { margin: 0; padding-left: 4px; list-style: none; }
.ch-text li { position: relative; margin: 2px 0; padding-left: 14px; }
.ch-text ul > li::before { content: "·"; position: absolute; left: 2px; color: var(--fg-label); }
.ch-text ol { counter-reset: ch-num; }
.ch-text ol > li { padding-left: 22px; counter-increment: ch-num; }
.ch-text ol > li::before {
  content: counter(ch-num) ".";
  position: absolute;
  left: 0;
  color: var(--fg-label);
  font-variant-numeric: tabular-nums;
}
.ch-text li > ul, .ch-text li > ol { margin-top: 2px; }
.ch-text strong { font-weight: 600; }
.ch-text em { font-style: italic; color: var(--fg-muted); }
.ch-text a { color: var(--info); text-decoration: underline; text-underline-offset: 2px; }
.ch-text a:hover { opacity: .75; }
.ch-text hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.ch-text pre {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--paper-mute);
  overflow-x: auto;
  white-space: pre;
}
.ch-text pre code {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: 12.5px;
  line-height: 1.55;
}
.ch-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  color: var(--fg-label);
  font-size: var(--fs-xs);
}
.ch-meta.err { color: var(--err); }
.ch-meta.denied { color: var(--d-amber); }
.ch-reason { margin: 0 0 3px; color: var(--fg-label); font-size: var(--fs-xs); }
.ch-reason a { color: var(--info); text-decoration: underline dotted; }
.ch-thread {
  display: inline-flex;
  margin-top: 4px;
  padding: 2px 8px 2px 6px;
  border-left: 2px solid var(--border-strong);
  color: var(--fg-label);
  font-size: var(--fs-xs);
}
.ch-attach {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 10px 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--fg-soft);
  font-size: var(--fs-xs);
}
.ch-attach svg { flex: none; }

/* ответ агента прикреплён к письму тонкой линией — это обмен, а не два
   случайных сообщения */
.ch-msg.reply { padding-top: 4px; }
.ch-msg.reply .ch-body { margin-left: -14px; padding-left: 12px; border-left: 2px solid var(--border-strong); }
.ch-msg.reply:hover .ch-body { border-left-color: var(--fg-faint); }
.ch-run {
  display: inline-flex;
  gap: 10px;
  color: var(--fg-label);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  font-variant-numeric: tabular-nums;
}
.ch-msg.err-run .ch-text { color: var(--err); }
/* письмо коллеге, написанное в этом запуске */
.ch-msg.sent .ch-body { padding: 8px 12px; border-radius: var(--radius-lg); background: var(--paper-mute); }
.ch-msg.sent .ch-who::before { content: "→ "; color: var(--fg-label); font-weight: 400; }

/* свёртка длинного текста */
.ch-fold summary { display: block; cursor: pointer; list-style: none; color: var(--fg); }
.ch-fold summary::-webkit-details-marker { display: none; }
.ch-fold .ch-preview { font-size: var(--fs-body); line-height: 1.5; overflow-wrap: anywhere; }
.ch-fold .ch-more { display: inline-block; margin-top: 4px; color: var(--info); font-size: var(--fs-xs); }
.ch-fold[open] summary { display: none; }
.ch-fold .ch-less { display: none; margin-top: 4px; color: var(--info); font-size: var(--fs-xs); cursor: pointer; }
.ch-fold[open] .ch-less { display: inline-block; }

/* агент печатает */
.ch-msg.typing-row .ch-head { align-items: center; }
.ch-typing-label { color: var(--fg-label); font-size: var(--fs-xs); }
.ch-typing-label b { color: var(--ok); font-weight: 500; }
.ch-typing-timer {
  color: var(--fg-label);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  font-variant-numeric: tabular-nums;
}
.ch-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  margin-top: 2px;
  padding: 0 12px;
  border-radius: 15px;
  background: var(--paper-mute);
}
.ch-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-muted);
  animation: ch-wave 1.1s ease-in-out infinite;
}
.ch-typing i:nth-child(2) { animation-delay: .15s; }
.ch-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ch-wave {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}
.ch-msg.enter { animation: ch-rise var(--dur-base) var(--ease-out); }
@keyframes ch-rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.ch-msg.reveal .ch-text { animation: ch-reveal .5s var(--ease-out); }
@keyframes ch-reveal { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

.ch-empty {
  margin: auto;
  padding: 40px 20px;
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  text-align: center;
}
.ch-empty strong { display: block; margin-bottom: 4px; color: var(--fg); font-weight: 600; }
.ch-older { padding: 8px 0 4px; text-align: center; }

/* ── статус-строка: ошибки сети, сессия ────────────────────────────── */
.ch-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 20px;
  border-top: 1px solid var(--border-faint);
  color: var(--fg-soft);
  font-size: var(--fs-xs);
}
.ch-status[hidden] { display: none; }
/* .btn задаёт свой display, который иначе перебивает атрибут hidden у
   кнопки «Повторить» внутри статус-строки (окно Дэйва держит статус
   «не на связи» подолгу — без этого правила кнопка висела бы всегда). */
.ch-status .btn[hidden] { display: none; }
.ch-status[data-kind="err"] { color: var(--err); }
.ch-status[data-kind="warn"] { color: var(--warn); }

/* ── поле ввода ────────────────────────────────────────────────────── */
.ch-composer { flex: none; margin: 0; padding: 10px 20px 16px; }
.ch-box {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--paper-card);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.ch-box:focus-within { border-color: var(--fg-muted); box-shadow: 0 0 0 3px rgba(28, 25, 23, .06); }
.ch-box.is-err { border-color: var(--err); }
.ch-composer.locked .ch-box { background: var(--paper-mute); }
.ch-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  max-height: 200px;
  padding: 10px 12px 4px;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  line-height: 1.45;
  outline: 0;
  resize: none;
}
.ch-input::placeholder { color: var(--fg-label); }
.ch-bar { display: flex; align-items: center; gap: 10px; padding: 4px 8px 8px 12px; }
.ch-hint { flex: 1; color: var(--fg-label); font-size: var(--fs-label); }
.ch-hint.err { color: var(--err); }
.ch-count {
  color: var(--fg-faint);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  font-variant-numeric: tabular-nums;
}
.ch-send { justify-content: center; width: 32px; height: 32px; padding: 0; border-radius: var(--radius); }
.ch-send svg { display: block; }

/* ── шапка комнаты ─────────────────────────────────────────────────── */
.ch-room-head {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
}
.ch-room-title { display: flex; flex: 1; flex-direction: column; min-width: 0; line-height: 1.25; }
.ch-room-title strong { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.ch-room-title .mono-dim { font-size: var(--fs-label); }
.ch-room-links { display: flex; gap: 14px; color: var(--fg-muted); font-size: var(--fs-xs); }
.ch-room-links a:hover { color: var(--fg); text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .ava.typing::after, .ch-typing i, .ch-msg.enter, .ch-msg.reveal .ch-text { animation: none; }
}
