/* TrakNet.AI — Knowledge Base module styles */

#screen-knowledge-base { padding: 0; height: 100%; }

.kb-wrap {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  height: calc(100vh - 110px);
  min-height: 520px;
  background: #fff;
  border: 1px solid #e6e8ee;
  border-radius: 14px;
  overflow: hidden;
}

/* ── List pane ── */
.kb-list-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e6e8ee;
  background: #fafbfc;
  min-height: 0;
}
.kb-list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 10px;
}
.kb-list-head h2 { font-size: 16px; font-weight: 700; margin: 0; color: #1e293b; }

.kb-search {
  margin: 0 16px 10px;
  padding: 9px 12px;
  border: 1px solid #dfe3ea;
  border-radius: 9px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.kb-search:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

.kb-filters { padding: 0 14px 8px; }
.kb-chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.kb-chip {
  border: 1px solid #e1e5ec; background: #fff; color: #475569;
  font-size: 11.5px; font-weight: 500; padding: 4px 9px; border-radius: 20px;
  cursor: pointer; transition: all .15s; font-family: inherit;
}
.kb-chip span { color: #94a3b8; font-weight: 600; }
.kb-chip:hover { border-color: #c7cdd8; }
.kb-chip.active { background: #6366f1; border-color: #6366f1; color: #fff; }
.kb-chip.active span { color: #e0e2ff; }
.kb-chip-tag { color: #7c3aed; }
.kb-chip-tag.active { background: #7c3aed; border-color: #7c3aed; color: #fff; }

.kb-list { flex: 1; overflow-y: auto; padding: 4px 10px 14px; min-height: 0; }
.kb-list-empty, .kb-list-empty { color: #94a3b8; font-size: 13px; text-align: center; padding: 28px 14px; }

.kb-list-item {
  display: block; width: 100%; text-align: left;
  background: #fff; border: 1px solid #ebedf2; border-radius: 10px;
  padding: 11px 12px; margin-bottom: 7px; cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .05s; font-family: inherit;
}
.kb-list-item:hover { border-color: #c7cdd8; box-shadow: 0 2px 8px rgba(15,23,42,.06); }
.kb-list-item.active { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99,102,241,.14); }
.kb-li-top { display: flex; align-items: center; gap: 6px; }
.kb-li-title { font-size: 13.5px; font-weight: 600; color: #1e293b; line-height: 1.3; }
.kb-pin { font-size: 11px; }
.kb-li-excerpt { font-size: 12px; color: #64748b; margin: 4px 0 6px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kb-li-meta { font-size: 11px; color: #94a3b8; }
.kb-li-cat { background: #eef0f5; color: #475569; padding: 1px 7px; border-radius: 5px; font-weight: 600; font-size: 10.5px; }

/* ── Main pane ── */
.kb-main { overflow-y: auto; padding: 28px 34px; min-height: 0; }
.kb-doc, .kb-editor { max-width: 760px; margin: 0 auto; }

.kb-doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.kb-title { font-size: 28px; font-weight: 700; color: #0f172a; margin: 0 0 8px; line-height: 1.2; }
.kb-doc-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; font-size: 12px; }
.kb-doc-actions { display: flex; gap: 8px; flex-shrink: 0; }
.kb-muted { color: #94a3b8; }
.kb-tag { background: #f3e8ff; color: #7c3aed; padding: 1px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; }

/* ── Rendered markdown ── */
.kb-body { color: #334155; font-size: 15px; line-height: 1.7; }
.kb-body .kb-h { color: #0f172a; font-weight: 700; line-height: 1.3; margin: 26px 0 10px; }
.kb-body .kb-h1 { font-size: 24px; }
.kb-body .kb-h2 { font-size: 20px; border-bottom: 1px solid #eef0f5; padding-bottom: 6px; }
.kb-body .kb-h3 { font-size: 17px; }
.kb-body .kb-h4 { font-size: 15px; color: #475569; }
.kb-body .kb-p { margin: 10px 0; }
.kb-body .kb-ul, .kb-body .kb-ol { margin: 10px 0 10px 22px; }
.kb-body .kb-ul li, .kb-body .kb-ol li { margin: 4px 0; }
.kb-body .kb-quote { border-left: 3px solid #c7d2fe; background: #f8f9ff; padding: 8px 14px; margin: 12px 0; color: #475569; border-radius: 0 8px 8px 0; }
.kb-body .kb-hr { border: none; border-top: 1px solid #e6e8ee; margin: 22px 0; }
.kb-code { background: #f1f3f8; color: #be185d; padding: 1.5px 6px; border-radius: 5px; font-size: 13px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.kb-pre { background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 10px; overflow-x: auto; margin: 14px 0; }
.kb-pre code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; line-height: 1.6; }
.kb-link { color: #2563eb; text-decoration: underline; text-underline-offset: 2px; }
.kb-empty-note { color: #94a3b8; font-style: italic; }

.kb-wikilink {
  color: #6366f1; text-decoration: none; font-weight: 600;
  background: #eef0ff; padding: 1px 5px; border-radius: 5px; transition: background .15s;
}
.kb-wikilink:hover { background: #e0e3ff; }
.kb-wikilink-missing { color: #dc2626; background: #fef2f2; border-bottom: 1px dashed #fca5a5; }
.kb-wikilink-missing:hover { background: #fee2e2; }

/* ── Backlinks ── */
.kb-backlinks { margin-top: 34px; padding-top: 18px; border-top: 1px solid #eef0f5; }
.kb-backlinks h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #94a3b8; margin: 0 0 10px; }
.kb-backlinks a { margin-right: 8px; margin-bottom: 6px; display: inline-block; }

/* ── Editor ── */
.kb-input {
  padding: 9px 12px; border: 1px solid #dfe3ea; border-radius: 9px;
  font-size: 13px; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
.kb-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.kb-title-input { width: 100%; font-size: 20px; font-weight: 700; padding: 12px 14px; margin-bottom: 12px; }
.kb-edit-row { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.kb-edit-row .kb-input { flex: 1; min-width: 150px; }
.kb-pin-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #475569; white-space: nowrap; }
.kb-textarea {
  width: 100%; min-height: 360px; resize: vertical;
  padding: 16px; border: 1px solid #dfe3ea; border-radius: 10px;
  font-size: 14px; line-height: 1.7; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.kb-textarea:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.kb-edit-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 12px; flex-wrap: wrap; }
.kb-edit-foot .kb-muted { font-size: 12px; }
.kb-edit-foot code { background: #f1f3f8; padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
.kb-preview { margin-top: 18px; padding: 20px; border: 1px dashed #d7dbe4; border-radius: 12px; background: #fafbfc; }

/* ── Blank state ── */
.kb-blank { max-width: 440px; margin: 60px auto 0; text-align: center; }
.kb-blank h3 { font-size: 20px; color: #1e293b; margin: 0 0 10px; }
.kb-blank p { color: #64748b; font-size: 14px; line-height: 1.6; margin: 0 0 18px; }
.kb-blank code { background: #f1f3f8; color: #be185d; padding: 1px 6px; border-radius: 5px; font-size: 13px; }

.btn-danger { background: #ef4444; color: #fff; border: 1px solid #ef4444; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }

/* ── Mobile ── */
@media (max-width: 860px) {
  .kb-wrap { grid-template-columns: 1fr; height: auto; }
  .kb-list-pane { border-right: none; border-bottom: 1px solid #e6e8ee; max-height: 42vh; }
  .kb-main { padding: 20px 16px; }
  .kb-title { font-size: 22px; }
}
