/* ====================================================================
   Чат КИТ: чат, списки, формы, модалки. Тёмная тема — через переменные
   дизайн-системы (style.css) и блок @media (prefers-color-scheme: dark) ниже.
   ==================================================================== */
.muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.hidden { display: none; }

/* --- Чат ------------------------------------------------------------- */
main.main-chat { max-width: 1400px; padding-top: 20px; padding-bottom: 20px; }
.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: stretch;
  height: calc(100vh - 150px); min-height: 480px; }
.chat-side, .chat-main { margin: 0; display: flex; flex-direction: column; min-height: 0; }
.chat-new { justify-content: center; margin-bottom: 12px; }
.dlg-list { overflow-y: auto; min-height: 0; flex: 1; margin: 0 -6px; padding: 0 6px; }
.dlg-item { display: flex; align-items: center; gap: 2px; border-radius: 8px; margin-bottom: 4px;
  border: 1px solid transparent; }
.dlg-item:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dlg-item.active { background: color-mix(in srgb, var(--accent) 16%, transparent); border-color: var(--accent); }
.dlg-link { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 7px 8px;
  color: var(--text-primary); text-decoration: none; }
.dlg-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.dlg-date { font-size: 11px; color: var(--text-muted); }
.dlg-btn { flex: 0 0 26px; width: 26px; height: 26px; border: none; background: none; border-radius: 6px;
  color: var(--text-muted); cursor: pointer; font-size: 15px; line-height: 1; }
.dlg-btn:hover { color: var(--text-primary); background: var(--page-plane); }

.chat-head { display: flex; align-items: baseline; gap: 12px; }
.chat-head #chat-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-usage { font-size: 12px; font-weight: 400; color: var(--text-muted); white-space: nowrap; }

.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 4px 12px; }
.msg { display: flex; flex-direction: column; margin-bottom: 14px; }
.msg-user { align-items: flex-end; }
.msg-assistant { align-items: flex-start; }
.bubble { max-width: min(860px, 88%); padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.55;
  border: 1px solid var(--border); background: var(--surface-1); overflow-wrap: anywhere; }
.msg-user .bubble { background: color-mix(in srgb, var(--accent) 16%, var(--surface-1));
  border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.bubble.plain { white-space: pre-wrap; }
.msg-greeting .bubble { color: var(--text-secondary); }
.msg-assistant.st-queued .bubble, .msg-assistant.st-running .bubble {
  display: inline-flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.msg-assistant.st-error .bubble {
  background: color-mix(in srgb, var(--status-critical) 10%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-critical) 55%, transparent); }
.msg-assistant.st-cancelled .bubble { background: color-mix(in srgb, var(--text-muted) 12%, var(--surface-1));
  color: var(--text-secondary); }
.msg-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; min-height: 14px; }

/* markdown ответа */
.bubble.md > :first-child { margin-top: 0; }
.bubble.md > :last-child { margin-bottom: 0; }
.bubble.md p, .bubble.md ul, .bubble.md ol, .bubble.md pre, .bubble.md table, .bubble.md blockquote { margin: 0 0 10px; }
.bubble.md ul, .bubble.md ol { padding-left: 22px; }
.bubble.md h1, .bubble.md h2, .bubble.md h3, .bubble.md h4 { font-size: 15px; margin: 12px 0 6px; }
.bubble.md code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
  background: var(--page-plane); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.bubble.md pre { background: var(--page-plane); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; overflow-x: auto; }
.bubble.md pre code { border: none; padding: 0; background: none; }
.bubble.md table { border-collapse: collapse; width: auto; }
.bubble.md th, .bubble.md td { border: 1px solid var(--gridline); padding: 4px 8px; text-align: left; }
.bubble.md blockquote { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  background: var(--page-plane); color: var(--text-secondary); }
.bubble.md a { color: var(--accent); }

/* Поле ввода: высота растёт только по тексту, минимум постоянный — кнопки не съезжают. */
.composer { border-top: 2px solid var(--sect-border, var(--border)); padding-top: 12px; }
.composer textarea { width: 100%; min-height: 64px; height: 64px; max-height: 260px; resize: none;
  box-sizing: border-box; background: var(--page-plane); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font: inherit; font-size: 14px; color: var(--text-primary); }
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.composer-bar { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.think-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary);
  cursor: pointer; white-space: nowrap; }
.composer-err { flex: 1; font-size: 12.5px; color: var(--status-critical); min-width: 0; }
.send-slot { display: inline-flex; justify-content: flex-end; min-width: 120px; }
.send-slot .btn { min-width: 120px; justify-content: center; }

/* --- Списки и поиск (стиль Кит, эталон grafost) ------------------------ */
.list-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.list-toolbar .table-filter { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 260px; }
.filter-label { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.filter-count { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.filter-mode-toggle { background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer;
  padding: 3px 9px; transition: background 0.12s, color 0.12s, border-color 0.12s; }
.filter-mode-toggle:hover { background: var(--page-plane); color: var(--text-primary); }
.filter-mode-toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.table-filter input[type="search"] { width: 100%; max-width: 360px; background: var(--page-plane);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 14px; color: var(--text-primary); }
.table-filter input[type="search"]:focus { outline: none; border-color: var(--accent); }
.list-table tbody tr:not(.empty-row):hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.list-table tbody tr.selected td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.list-table tbody tr.row-bad td { background: color-mix(in srgb, var(--status-critical) 8%, transparent); }
.list-table tbody tr.match td { background: rgba(240,190,0,0.22); color: var(--text-primary); }
.list-table tbody tr.cursor td { background: rgba(42,120,214,0.20); color: var(--text-primary); }
.list-table tbody tr.cursor.match td { background: rgba(240,190,0,0.36); }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 10px; border: 1px solid; white-space: nowrap; }
.tag-green { color: var(--status-good); border-color: var(--status-good); background: rgba(12,163,12,0.10); }
.tag-red { color: var(--status-critical); border-color: var(--status-critical); background: rgba(208,59,59,0.10); }
.tag-amber { color: #b07400; border-color: var(--status-warning); background: rgba(250,178,25,0.14); }

/* --- Формы: подпись слева от поля, в одну строку (правило КИТ, эталон Make1s) --- */
.field.row-field { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.field.row-field.top { align-items: flex-start; }
.field.row-field > label { min-width: 210px; margin: 0; white-space: nowrap; }
.modal .field.row-field > label { min-width: 140px; }
.field.row-field input[type="text"], .field.row-field input[type="password"], .field.row-field .select { flex: 1; }
.field.row-field textarea { flex: 1; max-width: 760px; background: var(--page-plane); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; font: inherit; font-size: 13px; color: var(--text-primary); resize: vertical; }
.field.row-field textarea:focus { outline: none; border-color: var(--accent); }
.settings-form .field.row-field input[type="text"] { flex: 0 0 140px; max-width: 140px; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.settings-form section.card { margin-bottom: 18px; }

/* --- Модалки ----------------------------------------------------------- */
.modal-wide { width: 720px; }
.modal-xwide { width: 1180px; max-height: 90vh; }
.modal .modal-body { overflow-y: auto; }
.log-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.log-pair .modal-section { margin-bottom: 0; min-width: 0; }
.log-pair pre.code { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 46vh; overflow-y: auto; }
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--text-muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

@media (prefers-color-scheme: dark) {
  .list-table tbody tr.match td { background: rgba(240,190,0,0.26); }
  .list-table tbody tr.cursor td { background: rgba(57,135,229,0.30); }
  .list-table tbody tr.cursor.match td { background: rgba(240,190,0,0.40); }
  .tag-amber { color: #ffc94d; }
}

@media (max-width: 860px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-side { max-height: 220px; }
  .chat-main { height: calc(100vh - 120px); }
  .log-pair { grid-template-columns: 1fr; }
  .field.row-field { flex-wrap: wrap; }
}
