/* Страница «Помощник»: база знаний и материалы (public/panel/knowledge.js). Токены — из panel.css; классы kn-, kt-, kb-. */

/* Противоречия */
.kn-conflicts {
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--danger-bg);
  min-width: 0;
}
.kn-conflicts-title { margin: 0; font-size: 14px; font-weight: 600; color: var(--danger); }
.kn-conflicts-sub { margin: 4px 0 10px; font-size: 12.5px; color: var(--ink-2); line-height: 1.45; }
.kn-note {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.45;
}
.kn-toggle { align-self: flex-start; min-height: 32px; }
.kn-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.kn-date { font-size: 12.5px; color: var(--ink-3); }
.kn-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.kn-edit { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

@media (max-width: 900px) {
  .kn-toggle { min-height: 40px; }
  .kn-conflicts { padding: 12px; }
}
@media (max-width: 480px) {
  .kn-actions .btn { flex: 1 1 100%; justify-content: center; }
  .kn-conflicts .btn { width: 100%; }
}

/* ==========================================================================
   База знаний и материалы (kt-, kb-): один список, фильтры, окна. Стиль — по мастеру М21:
   мягкие карточки, чипы-таблетки, акцентный градиент; анимируются только transform/opacity.
   ========================================================================== */

.kt { min-width: 0; }
.kt [hidden], .kt-overlay [hidden] { display: none !important; }
.kt-cat:focus-visible, .kt-chip-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.kt-panel { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* Поиск и действия */
.kt-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.kt-toolbar-end { justify-content: flex-end; }
.kt-search { flex: 1 1 260px; min-width: 0; }
.kt-search-input { border-radius: var(--r-pill); padding: 0 18px; }

/* База знаний: воздух между блоками, крупные заголовки групп */
.kb { display: flex; flex-direction: column; gap: 18px; padding: 24px; }
.kb > .card-head { margin-bottom: 0; }
.kb-slot { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.kb-slot:empty, .kb-slot:has(> [hidden]:only-child) { display: none; }
.kb-slot-bottom { gap: 4px; padding-top: 6px; border-top: 1px solid var(--line); }
.kb-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; }
.kb-filter { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 0 1 220px; }
.kb-filter-label { font-size: 12.5px; font-weight: 500; color: var(--ink-3); }
.kb-flags { display: flex; flex-wrap: wrap; gap: 8px; }
.kb-flag-gap.is-active, .kb-flag-conflict.is-active { background: var(--warn-bg); border-color: var(--warn-ink); color: var(--warn-ink); }
.kb-flag-gap.is-active .kt-cat-count, .kb-flag-conflict.is-active .kt-cat-count { background: var(--warn-ink); color: var(--warn-bg); }
.kb-list { display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.kb-group { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.kb-group-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; min-width: 0; }
.kb-group-title { margin: 0; font-family: 'Inter Tight', Inter, sans-serif; font-size: 18px; font-weight: 600; letter-spacing: -.02em; }
.kb-group-count { padding: 2px 10px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; font-weight: 500; }
.kb-group-head .kt-listhead { margin-left: auto; min-height: 44px; }
.kb-group-head .kb-confirm-all { margin-left: auto; }
.kb-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
/* .kt-row.kt-row-note: общее .kt-row объявлено ниже и при равной специфичности перебивало фон, рамку и сетку пробела. */
.kt-row.kt-row-note { background: var(--warn-bg); border-color: transparent; grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding-left: 16px; }
.kt-row-note .kt-a { color: var(--warn-ink); }

/* Блоки внутри базы: без рамки карточки (кандидаты FAQ, вопросы недели, ответы без модели) */
.kb-embed { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.kb-embed[hidden] { display: none; }
.kb-embed-title { margin: 0; font-family: 'Inter Tight', Inter, sans-serif; font-size: 18px; font-weight: 600; letter-spacing: -.02em; }
.kb-embed-sub { margin: -6px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--ink-2); }
.kb-embed .rows { margin: 0; }
.kb-fold { min-width: 0; }
.kb-fold > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.kb-fold > summary::-webkit-details-marker { display: none; }
.kb-fold > summary::before {
  content: '';
  width: 7px;
  height: 7px;
  margin-right: 12px;
  border-right: 2px solid var(--ink-3);
  border-bottom: 2px solid var(--ink-3);
  transform: rotate(-45deg);
  transition: transform .2s var(--ease-out);
}
.kb-fold[open] > summary::before { transform: rotate(45deg); }
.kb-fold > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
.kb-fold-body { padding: 4px 4px 12px; }

/* Категории-чипы со счётчиками */
.kt-cats { display: flex; flex-wrap: wrap; gap: 8px; }
.kt-cat {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 8px 0 16px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .2s var(--ease-out), border-color .2s var(--ease-out), color .2s var(--ease-out);
}
.kt-cat:hover { background: var(--surface-2); color: var(--ink); }
.kt-cat-count {
  min-width: 26px;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  text-align: center;
}
.kt-cat.is-active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.kt-cat.is-active .kt-cat-count { background: var(--accent); color: #fff; }

/* Массовые действия */
.kt-bulk {
  position: sticky;
  top: 8px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1), 0 0 0 1.5px var(--accent) inset;
}
.kt-bulk-count { font-size: 14px; font-weight: 600; }
.kt-bulk-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.kt-bulk-cat { width: auto; min-width: 150px; height: 34px; font-size: 13px; border-radius: var(--r-pill); background-position: calc(100% - 17px) 14px, calc(100% - 12px) 14px; }

/* Список */
.kt-listhead {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
}
.kt input[type="checkbox"]:not([role="switch"]), .kt input[type="radio"], .kt-overlay input[type="radio"], .kt-overlay input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; flex: none; margin: 0; }
.kt input[type="checkbox"]:focus-visible, .kt input[type="radio"]:focus-visible, .kt-overlay input[type="radio"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kt-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.kt-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px 12px;
  padding: 14px 16px 14px 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  min-width: 0;
  transition: border-color .2s var(--ease-out), box-shadow .2s var(--ease-out);
}
.kt-row:hover { box-shadow: var(--shadow-1); }
.kt-row.is-selected { border-color: var(--accent); background: var(--accent-bg); }
.kt-row.is-off .kt-q, .kt-row.is-off .kt-a { opacity: .6; }
.kt-row-material { grid-template-columns: minmax(0, 1fr) auto; padding-left: 16px; }
/* Карточка факта: заголовок и текст на всю ширину, действия — отдельной строкой внизу (всё в потоке, без наложений).
   Правила стоят после .kt-row, иначе его три колонки перебивают одну. */
.kt-row-fact { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px; }
.kt-row-fact > .kt-fact-actions { grid-column: 1 / -1; justify-content: flex-start; padding-top: 12px; border-top: 1px solid var(--line); }
.kt-row-fact .kt-meta { gap: 6px 8px; }
.kt-conflict { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: var(--r-md); background: var(--warn-bg); color: var(--ink); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.kt-conflict-title { margin: 0; font-weight: 600; color: var(--warn-ink); }
.kt-conflict-list { margin: 0; padding-left: 18px; color: var(--ink-2); }
.kt-check { display: inline-flex; align-items: center; justify-content: center; width: 44px; min-height: 44px; cursor: pointer; }
.kt-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding-top: 2px; }
.kt-mhead { display: flex; align-items: center; gap: 10px; min-width: 0; }
.kt-q { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; min-width: 0; }
.kt-a {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.kt-a.is-clamped { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.kt-meta { align-items: center; }
.kt-chats { font-size: 12.5px; color: var(--ink-2); }
.kt-src-link { text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.kt-src-link:hover { text-decoration: underline; }
.kt-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; padding-top: 2px; }
.kt-del { color: var(--danger-ink); }

/* Другие формулировки */
.kt-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.kt-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 4px 12px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.35;
}
.kt-chip-text { min-width: 0; overflow-wrap: anywhere; }
.kt-chip-more { background: var(--accent-bg); color: var(--accent); }
.kt-chips-edit .kt-chip { padding-right: 4px; }
.kt-chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  flex: none;
}
.kt-chip-x:hover { background: var(--line-2); color: var(--ink); }
.kt-chip-x svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; }
.kt-alias-add { display: flex; gap: 8px; }
.kt-alias-add input { flex: 1 1 auto; min-width: 0; }

.kt-switch { min-height: 44px; }
.kt-more { display: flex; }
.kt-empty { padding: 36px 16px; text-align: center; border-radius: var(--r-lg); background: var(--surface-2); }
.kt-empty-title { margin: 0 0 4px; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.kt-empty-text { margin: 0 0 12px; font-size: 13.5px; color: var(--ink-2); line-height: 1.5; }
.kt-empty .btn { margin-top: 4px; }

/* Журнал */
.kt-log { margin-top: 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.kt-log-title { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.kt-logs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.kt-logrow { display: flex; flex-direction: column; gap: 4px; padding: 10px 0; }
.kt-logrow + .kt-logrow { box-shadow: 0 -1px 0 var(--line); }
.kt-logrow-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; min-width: 0; }
.kt-logrow-label { font-size: 13.5px; font-weight: 500; overflow-wrap: anywhere; min-width: 0; }
.kt-logrow-stats { font-size: 13px; color: var(--ink-2); }

/* Окна */
body.kt-sheet-open { overflow: hidden; }
.kt-overlay {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 10, 15, .45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: kt-fade .2s var(--ease-out);
}
.kt-overlay-side { justify-content: flex-end; align-items: stretch; padding: 0; }
.kt-sheet {
  display: flex;
  flex-direction: column;
  width: min(640px, 100%);
  max-height: 100%;
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-2), var(--shadow-glow);
  outline: none;
  animation: kt-rise .28s var(--ease-out);
}
.kt-sheet-narrow { width: min(460px, 100%); }
.kt-sheet-side { width: min(520px, 100%); height: 100%; max-height: none; border-radius: var(--r-xl) 0 0 var(--r-xl); animation: kt-slide .28s var(--ease-out); }
.kt-sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 24px 24px 12px; }
.kt-sheet-titles { min-width: 0; }
.kt-sheet-title { margin: 0; font-family: 'Inter Tight', Inter, sans-serif; font-size: 20px; font-weight: 600; letter-spacing: -.03em; overflow-wrap: anywhere; }
.kt-sheet-sub { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); line-height: 1.45; }
.kt-sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 4px 24px 20px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.kt-sheet-foot { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); }
.kt-sheet-foot:empty { display: none; }
.kt-sheet-foot .btn { flex: 1 1 140px; min-height: 44px; }
.kt-form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.kt-counter { align-self: flex-end; }
.kt-source-note { margin: 0; padding: 10px 14px; border-radius: var(--r-md); background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; line-height: 1.45; overflow-wrap: anywhere; }
.kt-confirm-text { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ink-2); overflow-wrap: anywhere; }
.kt-intro { margin: 0; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.kt-status { margin: 0; min-height: 0; font-size: 13px; color: var(--accent); }
.kt-status:empty { display: none; }

/* Выбор типа материала */
.kt-types { display: grid; gap: 10px; }
.kt-type {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  min-height: 44px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .2s var(--ease-out), background-color .2s var(--ease-out);
}
.kt-type:hover { background: var(--surface-2); }
.kt-type:has(input:checked) { border-color: var(--accent); background: var(--accent-bg); }
.kt-type:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.kt-type input { margin-top: 2px; }
.kt-type-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kt-type-title { font-size: 14.5px; font-weight: 600; }
.kt-type-text { font-size: 13px; line-height: 1.45; color: var(--ink-2); }

/* Итог добавления */
.kt-result { display: flex; flex-direction: column; gap: 14px; padding: 8px 0; }
.kt-result-title { margin: 0; font-size: 16px; font-weight: 600; }
.kt-result-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.kt-result-cell { display: flex; flex-direction: column; gap: 2px; padding: 14px 12px; border-radius: var(--r-lg); background: var(--surface-2); min-width: 0; }
.kt-result-num { font-family: 'Inter Tight', Inter, sans-serif; font-size: 28px; font-weight: 600; letter-spacing: -.03em; }
.kt-result-label { font-size: 12.5px; color: var(--ink-2); line-height: 1.35; overflow-wrap: anywhere; }

@keyframes kt-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes kt-rise { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes kt-slide { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .kt-overlay, .kt-sheet, .kt-sheet-side { animation: none; }
  .kt-row, .kt-cat, .kt-type, .kb-fold > summary::before { transition: none; }
}

/* Планшет и телефон: строка в одну колонку, действия под текстом, окна — снизу */
@media (max-width: 900px) {
  .kt-row { grid-template-columns: auto minmax(0, 1fr); }
  .kt-row-material, .kt-row.kt-row-note, .kt-row-fact { grid-template-columns: minmax(0, 1fr); }
  .kt-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .kt-row:not(.kt-row-material):not(.kt-row-note):not(.kt-row-fact) .kt-actions { padding-left: 4px; }
  .kb { padding: 18px 16px; }
  .kt .btn-sm { height: auto; min-height: 44px; }
  .kt-bulk-cat { height: 44px; background-position: calc(100% - 17px) 20px, calc(100% - 12px) 20px; }
}
@media (max-width: 640px) {
  .kt-overlay, .kt-overlay-side { align-items: flex-end; justify-content: center; padding: 0; }
  .kt-sheet, .kt-sheet-narrow, .kt-sheet-side {
    width: 100%;
    height: auto;
    max-height: 92vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation: kt-rise .28s var(--ease-out);
  }
  .kt-sheet-head { padding: 20px 18px 10px; }
  .kt-sheet-body { padding: 4px 18px 16px; }
  .kt-sheet-foot { padding: 14px 18px; }
  .kt-toolbar > .btn { flex: 1 1 100%; min-height: 44px; }
  .kb-filter { flex: 1 1 100%; }
  .kb-group-head .kt-listhead, .kb-group-head .kb-confirm-all { margin-left: 0; }
  .kb-empty-actions .btn { flex: 1 1 100%; justify-content: center; }
  .kt-bulk { top: 4px; }
  .kt-bulk-actions .btn, .kt-bulk-cat { flex: 1 1 calc(50% - 8px); }
  .kt-actions .btn { flex: 1 1 auto; }
  .kt-result-stats { grid-template-columns: 1fr; }
  .kt .chip { white-space: normal; height: auto; min-height: 26px; padding-top: 3px; padding-bottom: 3px; }
}
