/* Разговор с системой: лента реплик, источники ответа и предложения.
   Страница `/dialogue` и боковая панель используют одни и те же классы. */

.dialogue-page {
  align-items: stretch;
}

.dialogue-page__chat {
  display: flex;
  flex-direction: column;
  /* Лента занимает высоту экрана, поле ввода остаётся видимым. */
  max-height: calc(100vh - var(--header-h) - 132px);
  min-height: 360px;
}

.dialogue-page__chat .chat {
  min-height: 0;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  flex: 1;
  min-height: 0;
}

.chat__feed {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  overflow-y: auto;
  padding-right: var(--s-2);
  flex: 1;
  min-height: 0;
  scroll-behavior: smooth;
}

.chat--compact .chat__feed {
  max-height: min(52vh, 460px);
}

/* --- Знакомство ------------------------------------------------------------ */

.chat-intro {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-inset);
}

.chat-intro__title {
  margin: 0;
  font-size: var(--fs-title);
  font-weight: 600;
}

.chat-intro p {
  margin: 0;
}

/* --- Реплики --------------------------------------------------------------- */

.chat-line {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  max-width: 92%;
}

.chat-line--mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-line__core {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-control);
  color: var(--accent);
  margin-top: 2px;
}

.chat-bubble {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--sheen), var(--panel-raised-glass);
  box-shadow: var(--shadow-card);
}

.chat-line--mine .chat-bubble {
  background: var(--surface-control);
  border-color: var(--accent-dim);
}

.chat-bubble__author {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.chat-bubble__text {
  margin: 0;
  font-size: var(--fs-md);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.chat-bubble__note {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--warning);
}

/* Ответ собирается: три точки вместо текста. */
.chat-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 18px;
}

.chat-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.45;
  animation: chat-dot 1.1s var(--ease) infinite;
}

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

@keyframes chat-dot {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* --- Источники ответа ------------------------------------------------------- */

.chat-sources {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.chat-source {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-inset);
  color: var(--muted);
  font-size: var(--fs-xs);
  text-align: left;
  cursor: pointer;
}

.chat-source:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.chat-source--fact {
  cursor: default;
  border-style: dashed;
}

.chat-source .entity-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 24ch;
}

/* --- Предложения ------------------------------------------------------------ */

.chat-offers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.chat-offer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent-dim);
  background: var(--surface-control);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  max-width: 100%;
}

.chat-offer:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-control);
}

.chat-offer__label {
  font-size: var(--fs-sm);
  font-weight: 600;
}

.chat-offer__note {
  font-size: var(--fs-xs);
  color: var(--muted);
  overflow-wrap: anywhere;
}

.chat-offer--done {
  cursor: default;
  flex-direction: row;
  align-items: center;
  gap: var(--s-2);
  border-color: var(--success-dim);
  background: var(--success-dim);
  color: var(--success);
}

.chat-offer--done .chat-offer__note {
  color: var(--muted);
}

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

.chat__composer {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
}

.chat__input {
  flex: 1;
  min-width: 0;
  resize: none;
}

.chat__send {
  flex: none;
  height: 34px;
  padding: 0 var(--s-4);
}

.chat__mark {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--muted);
}

/* --- Что изменилось ---------------------------------------------------------- */

.chat-change {
  width: 100%;
  text-align: left;
  cursor: pointer;
}

/* --- Боковая панель ----------------------------------------------------------- */

.chat-panel {
  position: fixed;
  right: var(--s-5);
  bottom: var(--s-5);
  top: calc(var(--header-h) + var(--s-5));
  /* Ниже панели деталей: источник из разговора открывается поверх. */
  z-index: 45;
  width: min(420px, calc(100vw - 2 * var(--s-4)));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel .chat {
  min-height: 0;
}

.chat-panel .chat--compact .chat__feed {
  max-height: none;
}

@media (max-width: 860px) {
  .chat-panel {
    right: var(--s-3);
    left: var(--s-3);
    bottom: 76px;
    width: auto;
  }

  .chat-line {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-dots i { animation: none; }
  .chat__feed { scroll-behavior: auto; }
}

:root[data-motion="reduced"] .chat-dots i { animation: none; }
:root[data-motion="reduced"] .chat__feed { scroll-behavior: auto; }
