/* Чат: сообщения, итоги прогона, отчёт, индикатор размышления, метки владельца, фильтры.
   Цвета — переменные темы из style.css, поэтому всё работает и в тёмной, и в светлой теме. */

#chat-title { font-family: var(--hfont); }
.mono, .code { font-family: var(--mono); font-weight: 500; }
.code { font-size: 13px; }

/* --- ответ системы: значок, подпись, текст --- */
.bot { display: flex; gap: 12px; align-items: flex-start; max-width: 860px; align-self: flex-start; width: 100%; }
.bot .ava { flex: 0 0 28px; width: 28px; height: 28px; border-radius: 8px; background: var(--accent-soft);
  color: var(--accent); display: flex; align-items: center; justify-content: center; }
.bot-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.bot .who { display: flex; align-items: baseline; gap: 8px; font-size: 13px; line-height: 18px; color: var(--muted); }
.bot .who b { color: var(--text); font-weight: 600; }
.bot-text { font-size: 15px; line-height: 23px; white-space: pre-line; overflow-wrap: anywhere; }
.bot-text .muted { color: var(--muted); }

/* --- сообщение менеджера: пузырь справа, время под ним --- */
.me { align-self: flex-end; max-width: min(560px, 85%); display: flex; flex-direction: column;
  align-items: flex-end; gap: 4px; }
.me .bub { padding: 10px 14px; border-radius: 14px 14px 4px 14px; background: var(--accent-soft);
  border: 1px solid var(--accent-line); font-size: 15px; line-height: 22px; white-space: pre-line;
  overflow-wrap: anywhere; }
.me .bub.mono { font-size: 14px; }
.me .tm { font-size: 12px; color: var(--muted); }
.me.pending { opacity: .6; }
.me.failed .bub { border-color: var(--red); }
.me .msg-state { display: none; font-size: 12px; color: var(--muted); }
.me.pending .msg-state, .me.failed .msg-state { display: block; }
.me.failed .msg-state { color: var(--red); }
.src-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.src-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 28px;
  padding: 3px 10px; box-sizing: border-box; border-radius: 999px; border: 1px solid var(--accent-line);
  background: var(--panel); font-size: 13px; line-height: 18px; }
.src-chip .countries { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.bub-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* --- итоги прогона: карточка на источник --- */
.rcard { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); overflow: hidden; }
.rhead { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.rhead b { flex: 1; font-size: 15px; }
.rrow { display: grid; grid-template-columns: minmax(110px, 160px) minmax(0, 1fr) auto; gap: 12px;
  align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 14px; line-height: 20px; }
.rrow:last-child { border-bottom: 0; }
.rrow.dim { color: var(--muted); }
.rrow .price { font-family: var(--mono); font-size: 15px; font-weight: 500; white-space: nowrap; }
.rnote { padding: 10px 16px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); }
.tag { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--green); }
.tag.warn { background: var(--warn-soft); color: var(--yellow); }
.tag.bad { background: var(--bad-soft); color: var(--red); }
.tag.idle { background: var(--panel-2); color: var(--muted); }

/* --- отчёт: карточка файла с кнопкой --- */
.file-card { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 14px 16px;
  border: 1px solid var(--accent-line); border-radius: 12px; background: var(--panel); }
.file-ico { flex: 0 0 40px; width: 40px; height: 44px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--xlsx); display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 6px; box-sizing: border-box; font: 700 10px var(--mono); }
.file-meta { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-meta .name { font-family: var(--mono); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta .sub { font-size: 13px; color: var(--muted); }
a.dl-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 8px;
  background: var(--primary-bg); color: var(--primary-fg); font-weight: 600; font-size: 14px; text-decoration: none;
  transition: background .15s ease, transform .12s ease; }
a.dl-btn:hover { background: var(--primary-hover); }
a.dl-btn:active { transform: scale(.97); }
.user-file { display: inline-flex; align-items: center; gap: 8px; }

/* --- размышление: звёздочка меняет форму, подпись переливается, рядом таймер --- */
.think { display: flex; align-items: center; gap: 8px; font-size: 15px; line-height: 22px; min-height: 28px; }
.spark { display: inline-block; width: 18px; text-align: center; color: var(--spark); font-size: 18px;
  line-height: 22px; animation: spark-breathe 1.6s ease-in-out infinite; }
.spark::before { content: "·"; animation: spark-glyph 1.2s steps(1) infinite; }
@keyframes spark-glyph { 0% { content: "·"; } 16% { content: "✢"; } 33% { content: "✳"; }
  50% { content: "✶"; } 66% { content: "✻"; } 83% { content: "✽"; } }
@keyframes spark-breathe { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.15); opacity: .75; } }
.think .verb { font-weight: 600; background: linear-gradient(90deg, var(--text) 0%, var(--text) 40%, var(--shine) 50%,
  var(--text) 60%, var(--text) 100%); background-size: 250% 100%; -webkit-background-clip: text; background-clip: text;
  color: transparent; animation: shimmer-text 2.4s linear infinite, verb-in .35s ease-out; }
@keyframes shimmer-text { from { background-position: 100% 0; } to { background-position: -150% 0; } }
@keyframes verb-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.think .el { color: var(--muted); font-size: 13px; }

.prog { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px; }
.prog-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; }
.prog-head span { color: var(--muted); }
.prog .bar { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.prog .bar > div { height: 100%; border-radius: 999px; background: var(--accent); transition: width .6s ease; }
.pl-row { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  font-size: 14px; line-height: 20px; padding: 4px 0; }
.pl-row.wait { color: var(--muted); }
.pl-row .n { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.pl-ico { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; }
.mini-spin { width: 12px; height: 12px; border-radius: 999px; border: 2px solid var(--accent-line);
  border-top-color: var(--accent); animation: spin .9s linear infinite; box-sizing: border-box; }
.wait-dot { width: 10px; height: 10px; border-radius: 999px; border: 1.5px solid var(--border-strong); box-sizing: border-box; }
.prog .pl-more { font-size: 13px; color: var(--muted); }

/* --- остановка поиска вместо отправки --- */
#btn-stop { display: inline-flex; align-items: center; gap: 8px; height: 42px; font-weight: 600; }
#btn-stop .sq { width: 10px; height: 10px; border-radius: 2px; background: currentColor; }

/* --- владелец чата: «Мой чат» или логин сотрудника --- */
.own { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.own.me { background: var(--accent-soft); color: var(--accent); }
.own.emp { background: var(--emp-soft); color: var(--emp); font-family: var(--mono); font-weight: 500; }
.chat-item .meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; min-width: 0; }
.chat-item .meta .d { margin-top: 0; }
.owner-pill.emp { border-color: transparent; background: var(--emp-soft); color: var(--emp); font-weight: 600; }

/* --- фильтры руководителя и администратора --- */
#manager-filter-wrap { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex;
  flex-direction: column; gap: 8px; }
.seg { display: flex; padding: 3px; gap: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.seg button { flex: 1; height: 30px; padding: 0 6px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); font-size: 13px; }
.seg button:hover:not(:disabled) { background: transparent; color: var(--text); }
.seg button.on, .seg button.on:hover:not(:disabled) { background: var(--panel); color: var(--text); font-weight: 600;
  box-shadow: 0 1px 2px rgba(11, 27, 51, .08); }
.filter-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.emp-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 4px 4px 10px;
  border-radius: 8px; background: var(--emp-soft); color: var(--emp); font-size: 13px; }
.emp-chip button { width: 26px; height: 26px; padding: 0; border: 0; color: inherit; }
.emp-chip button:hover:not(:disabled) { background: transparent; }

/* --- узкое окно: список чатов выезжает поверх, а не сжимает переписку --- */
@media (max-width: 760px) {
  #sidebar { position: absolute; z-index: 20; top: 0; bottom: 0; left: 0; width: min(300px, 86vw);
    min-width: 0; box-shadow: 0 16px 48px -12px rgba(11, 27, 51, .35); }
  #messages { padding: 16px; }
  #chat-header { padding: 12px 16px 12px 56px; }
  #composer { padding: 10px 12px 14px; }
  .me { max-width: 92%; }
  .rrow { grid-template-columns: minmax(0, 1fr) auto; }
  .rrow > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
}

/* появление новых сообщений — плавно, как и раньше */
.bot.appear, .me.appear { animation: msg-in .25s ease-out; }

.muted { color: var(--muted); }

/* Результаты поиска: таблица предложений, как в отчёте */
.res-block { border: 1px solid var(--border); border-radius: 10px; background: var(--panel, transparent); }
.res-block > summary { cursor: pointer; padding: 10px 14px; font-weight: 700; font-size: 14px; }
.res-pos { padding: 4px 14px 12px; }
.res-title { font-size: 14px; margin: 6px 0 8px; }
.res-title .muted { color: var(--muted); }
.res-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.res-table { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 18px; min-width: 520px; }
.res-table th, .res-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.res-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.res-table .num { text-align: right; white-space: nowrap; }
.res-table td.num .sub { display: block; color: var(--muted); font-size: 11.5px; white-space: normal; max-width: 230px; margin-left: auto; }
.res-table td.code { font-family: "JetBrains Mono", monospace; font-size: 12.5px; white-space: nowrap; }
.res-table td.code a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.res-table tr.dim td { color: var(--muted); }

/* Узкий экран: строка таблицы становится карточкой, цена всегда на виду */
@media (max-width: 680px) {
  .res-table { min-width: 0; }
  .res-table thead { display: none; }
  .res-table, .res-table tbody { display: block; }
  .res-table tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
  .res-table td { display: block; border: 0; padding: 1px 0; min-width: 0; overflow-wrap: anywhere; }
  .res-table td:nth-child(1) { grid-column: 1; font-weight: 700; }
  .res-table td:nth-child(2) { grid-column: 1; }
  .res-table td:nth-child(3) { grid-column: 1; }
  .res-table td:nth-child(4) { grid-column: 1; color: var(--muted); }
  .res-table td:nth-child(4)::before { content: "Фасовка: "; }
  .res-table td.num { grid-column: 2; grid-row: 1 / span 4; text-align: right; font-weight: 700; }
  .res-table td.num .sub { font-weight: 400; max-width: 150px; }
}
