/* chat.css — ИИ-чат (js/chat.js): беседы слева, разговор по центру с прижатым композером, ответ ИИ с ссылками-чипами
   [n] и списком «Источники». Структура — по claude-me css/pages/chat.css (беседы · колонка сообщений · композер),
   значения — только токены темы. Состояние не только цветом: текущая беседа — заливка + обводка + вес; ошибка —
   иконка и полоса; скрытый ответ — замок. ≤ 900px — беседы выезжающей панелью. Владелец — агент `kb`. */

main.chat-main { padding: 0; max-width: none; height: calc(100dvh - var(--topbar-h)); overflow: hidden; }
.kc { --side-w: 272px; position: relative; display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr);
  height: 100%; min-height: 420px; overflow: hidden; }
.kc .icon { width: var(--cx-ic); height: var(--cx-ic); }

/* ---------- беседы ---------- */
.kc-side { display: flex; flex-direction: column; gap: var(--s3); min-height: 0; padding: var(--s4) var(--s3);
  border-right: var(--border-w) solid var(--border); background: var(--surface-1); overflow-y: auto; }
.kc-side-head { display: flex; align-items: center; gap: var(--s2); }
.kc-new { flex: 1 1 auto; }
.kc-side-close { display: none; }
.kc-empty { padding: var(--s2) var(--s3); }
.kc-threads { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; grid-template-columns: minmax(0, 1fr); }
.kc-thread > a { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-height: var(--nav-h); min-width: 0;
  padding: var(--s1) var(--s3); border-radius: var(--r); border: var(--border-w) solid transparent;
  color: var(--fg); text-decoration: none; transition: background var(--dur-fast) var(--ease); }
.kc-thread > a:hover { background: var(--surface-2); }
.kc-thread > a:active { background: var(--surface-3); }
.kc-thread > a[aria-current="page"] { background: var(--accent-soft); border-color: var(--accent); }
.kc-thread > a[aria-current="page"] .t-title { font-weight: var(--fw-semibold); }
.t-title { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--fs-sm); line-height: var(--lh-tight); }
.t-when { font-size: var(--fs-xs); color: var(--fg-muted); }

/* ---------- разговор ---------- */
.kc-main { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; position: relative; }
.kc-head { display: flex; align-items: center; gap: var(--s2); min-width: 0; padding: var(--s3) var(--s5);
  border-bottom: var(--border-w) solid var(--border); background: var(--surface-1); }
.kc-title { flex: 1 1 auto; min-width: 0; margin: 0; font-size: var(--fs-lg); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.kc-side-open { display: none; flex: none; }
.kc-actions { flex: none; gap: 2px; }
.kc-scroll { overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.kc-feed { list-style: none; max-width: 820px; margin: 0 auto; padding: var(--s5) var(--s5) var(--s4);
  display: flex; flex-direction: column; gap: var(--s4); }
.kc-feed:empty { padding: 0; }

.turn.user { align-self: flex-end; max-width: 85%; display: flex; flex-direction: column; align-items: flex-end; gap: var(--s1); }
.turn.user .bubble { padding: var(--s3) var(--s4); border-radius: var(--r-xl); border: var(--border-w) solid var(--border);
  background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.turn-time { font-size: var(--fs-xs); color: var(--fg-muted); font-family: var(--font-data); font-variant-numeric: tabular-nums; }

.turn.ai { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; padding: var(--s3) var(--s4);
  border: var(--border-w) solid var(--border); border-radius: var(--r-lg); background: var(--surface-1); box-shadow: var(--shadow); }
.ai-head { display: flex; align-items: center; gap: var(--s2); min-height: var(--control-h-sm); }
.ai-badge { display: inline-flex; align-items: center; gap: var(--s1); padding: 2px var(--s2); border-radius: var(--r-pill);
  background: var(--accent-soft); color: var(--accent); font-size: var(--fs-xs); font-weight: var(--fw-semibold); }
.ai-badge .icon { width: var(--cx-ic-xs); height: var(--cx-ic-xs); }
.kc-copy { margin-left: auto; color: var(--fg-muted); }
.ai-body { min-width: 0; }
.kc-md { line-height: var(--lh-loose); }
.kc-md code { font-family: var(--font-mono); font-size: var(--fs-sm); background: var(--code-bg); color: var(--code-fg);
  padding: 1px var(--s1h); border-radius: var(--r-xs); }
.kc-md pre.code { overflow-x: auto; padding: var(--s3); border-radius: var(--r); background: var(--code-bg); color: var(--code-fg); }
.kc-md pre.code code { padding: 0; background: none; }
.kc-note { display: flex; align-items: flex-start; gap: var(--s2); color: var(--fg-muted); }
.kc-note .icon { margin-top: 3px; flex: none; }
.turn.ai.st-error { border-color: var(--danger); }

/* ссылка [n] внутри ответа — компактный чип с номером, цель ≥ 24px по высоте строки */
.cite { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
  margin: 0 1px; vertical-align: 1px; border-radius: var(--r-pill); border: var(--border-w) solid var(--border-strong);
  background: var(--surface-2); color: var(--fg); font: var(--fw-semibold) var(--fs-xs)/1 var(--font-data);
  text-decoration: none; }
.md a.cite { color: var(--fg); }
.cite:hover, .cite:focus-visible { background: var(--accent-soft); border-color: var(--accent); color: var(--fg); }

/* источники под ответом — только доступные, ссылки перепроверяют доступ при открытии */
.kc-sources { margin-top: var(--s3); padding-top: var(--s3); border-top: var(--border-w) dashed var(--border); }
.kc-sources-h { display: flex; align-items: center; gap: var(--s1h); margin: 0 0 var(--s2); font-size: var(--fs-xs);
  font-weight: var(--fw-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--fg-muted); }
.src-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2); }
.src-chip { display: inline-flex; align-items: center; gap: var(--s2); max-width: 100%; min-height: 32px; padding: var(--s1) var(--s3) var(--s1) var(--s1);
  border: var(--border-w) solid var(--border); border-radius: var(--r-pill); background: var(--surface-1); color: var(--fg);
  font-size: var(--fs-sm); text-decoration: none; transition: background var(--dur-fast) var(--ease); }
.src-chip:hover { background: var(--surface-2); border-color: var(--border-strong); }
.src-chip:active { background: var(--surface-3); }
.src-n { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: var(--r-pill);
  background: var(--accent-soft); color: var(--accent); font: var(--fw-semibold) var(--fs-xs)/1 var(--font-data); flex: none; }
.src-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 340px; }
.src-meta { flex: none; color: var(--fg-muted); font-size: var(--fs-xs); }

/* «думает…» — три точки; без анимации при reduced-motion текст остаётся */
.kc-thinking { display: flex; align-items: center; gap: var(--s2); color: var(--fg-muted); font-size: var(--fs-sm); }
.kc-thinking[hidden] { display: none; }
.turn.ai.pending .kc-md:not(:empty) { margin-top: var(--s2); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-muted); }
@media (prefers-reduced-motion: no-preference) {
  .dots i { animation: kc-dot 1.2s var(--ease) infinite; }
  .dots i:nth-child(2) { animation-delay: .15s; }
  .dots i:nth-child(3) { animation-delay: .3s; }
}
@keyframes kc-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* приветствие пустой беседы и примеры вопросов */
.kc-hello { max-width: 560px; margin: 10vh auto var(--s5); padding: 0 var(--s4); text-align: center; display: flex;
  flex-direction: column; align-items: center; gap: var(--s3); }
.kc-hello h2 { font-size: var(--fs-2xl); }
.kc-hello-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: var(--r-lg);
  background: var(--accent-soft); color: var(--accent); }
.kc-hello-mark .icon { width: var(--cx-ic-lg); height: var(--cx-ic-lg); }
.kc-examples { list-style: none; margin: var(--s2) 0 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s2); }
.suggest-chip { max-width: 100%; min-height: 32px; padding: var(--s1h) var(--s3); border-radius: var(--r-pill);
  border: var(--border-w) solid var(--border-strong); background: var(--surface-1); color: var(--fg);
  font: var(--fw-regular) var(--fs-sm) var(--font); cursor: pointer; text-align: left; overflow-wrap: anywhere; }
.suggest-chip:hover { background: var(--surface-2); border-color: var(--fg-muted); }
.suggest-chip:active { background: var(--surface-3); }

/* ---------- композер ---------- */
.composer { --composer-border: var(--border-strong); width: calc(100% - 2 * var(--s5)); max-width: 820px; margin: 0 auto var(--s4);
  padding: var(--s2) var(--s2) var(--s2) var(--s4); border: var(--border-w) solid var(--composer-border); border-radius: var(--r-xl);
  background: var(--surface-1); box-shadow: var(--shadow); }
.composer:focus-within { --composer-border: var(--accent); box-shadow: var(--shadow-focus); }
.composer textarea { width: 100%; min-height: 28px; max-height: 260px; padding: var(--s2) 0; border: 0; background: transparent;
  color: var(--fg); font: inherit; resize: none; outline: none; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.kc-hint { flex: 1 1 auto; min-width: 0; }
.kc-send { flex: none; }

/* ---------- адаптив: ≤ 900px беседы — выезжающая панель; телефон 390px без горизонтальной прокрутки ---------- */
@media (max-width: 900px) {
  .kc { grid-template-columns: minmax(0, 1fr); }
  .kc-side { display: none; }
  .kc.side-open .kc-side { display: flex; position: absolute; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: var(--z-panel);
    background: var(--surface-raised); border-right: var(--border-w) solid var(--border-raised); box-shadow: var(--shadow-lg); }
  .kc-scrim:not([hidden]) { position: absolute; inset: 0; z-index: calc(var(--z-panel) - 1); background: var(--overlay); }
  .kc-side-close, .kc-side-open { display: inline-flex; }
  .kc-head { padding: var(--s2) var(--s3); }
  .kc-feed { padding: var(--s4) var(--s3); }
  .composer { width: calc(100% - 2 * var(--s3)); margin-bottom: var(--s3); }
}
@media (max-width: 480px) {
  .turn.user { max-width: 92%; }
  .turn.ai { padding: var(--s3); }
  .kc-hint { font-size: var(--fs-xs); }
  .composer textarea { min-height: calc(2 * var(--lh-body) * 1em + var(--s4)); }   /* подсказка в две строки не режется */
  .src-title { max-width: 200px; }
  .kc-hello { margin-top: var(--s5); }
}
