/* =========================================================
   知识库模块化样式表 (Knowledge Base Module Styles)
   职责：收纳知识库页面专用排版、高频提炼问答卡片、规则表格与模拟沙盒
   ========================================================= */

/* 顶部与整体布局 */
.kb-container {
  padding-bottom: 40px;
}

.kb-top-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}

.kb-top-bar .btn-secondary {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 5px !important;
  height: 30px !important;
  padding: 0 12px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  border-radius: 6px !important;
  background: #ffffff !important;
  color: #374151 !important;
  border: 1px solid #d1d5db !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  box-sizing: border-box !important;
  text-decoration: none !important;
  transition: all .15s ease !important;
}

.kb-top-bar .btn-secondary:hover {
  background: #f9fafb !important;
  border-color: #9ca3af !important;
  color: #111827 !important;
}

.kb-top-bar .btn-primary {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 5px !important;
  height: 30px !important;
  padding: 0 14px !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  border-radius: 6px !important;
  background: #4f46e5 !important;
  color: #fff !important;
  border: 1px solid #4338ca !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  box-sizing: border-box !important;
  transition: all .15s ease !important;
}

.kb-top-bar .btn-primary:hover {
  background: #4338ca !important;
}

/* 核心主体：规则列表面板及头部工具栏 */
.kb-table-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 0 !important;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  margin-bottom: 20px;
}

.kb-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid #edf2f7;
  background: #fff;
  gap: 12px;
  flex-wrap: wrap;
}

.kb-stat-bar {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 30px;
  padding: 4px 14px;
  gap: 12px;
  font-size: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.kb-stat-bar .stat-item {
  color: #64748b;
}

.kb-stat-bar .stat-item strong {
  font-weight: 700;
  color: #0f172a;
}

.kb-stat-bar .stat-item.active {
  color: #16a34a;
}

.kb-stat-bar .stat-item.active strong {
  color: #16a34a;
}

.kb-stat-bar .stat-item.hit {
  color: #4f46e5;
}

.kb-stat-bar .stat-item.hit strong {
  color: #4f46e5;
}

.kb-stat-bar .stat-divider {
  color: #cbd5e1;
}

.kb-table-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kb-search-input {
  width: 220px !important;
  height: 38px !important;
  font-size: 13px !important;
  padding: 0 12px !important;
  margin: 0 !important;
  border-radius: 7px !important;
}

.kb-search-btn {
  height: 38px;
  padding: 0 16px;
  border-radius: 7px;
  font-size: 13px;
  flex-shrink: 0;
}

@media (max-width: 700px) {
  .kb-table-search-wrap {
    width: 100%;
  }
  .kb-search-input {
    flex: 1;
    width: auto !important;
    min-width: 0;
  }
}

/* 规则列表表格专用类 (兼容 CSP style-src 'self'，防止列挤压竖排) */
.kb-rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.kb-rules-table thead tr {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  color: #64748b;
  font-size: 12px;
  text-align: left;
}

.kb-rules-table th,
.kb-rules-table td {
  padding: 12px 10px;
  vertical-align: middle;
}

.kb-rules-table th.col-priority,
.kb-rules-table td.col-priority {
  width: 50px;
  text-align: center;
}

.kb-rules-table th.col-theme,
.kb-rules-table td.col-theme {
  width: 130px;
}

.kb-rules-table th.col-match,
.kb-rules-table td.col-match {
  width: 90px;
  white-space: nowrap;
}

.kb-rules-table th.col-kw,
.kb-rules-table td.col-kw {
  width: 150px;
}

.kb-rules-table th.col-reply,
.kb-rules-table td.col-reply {
  min-width: 180px;
}

.kb-rules-table th.col-hits,
.kb-rules-table td.col-hits {
  width: 60px;
  text-align: center;
}

.kb-rules-table th.col-status,
.kb-rules-table td.col-status {
  width: 85px;
  text-align: center;
  white-space: nowrap;
}

.kb-rules-table th.col-action,
.kb-rules-table td.col-action {
  width: 124px;
  text-align: center;
  white-space: nowrap;
}

.kb-action-wrap {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  white-space: nowrap !important;
}

.kb-action-wrap form {
  margin: 0 !important;
  display: inline-flex !important;
}

/* 操作列小按钮：风格与一键采纳严格统一，尺寸严格控制 */
.kb-btn-sm,
.kb-action-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  height: 25px !important;
  padding: 0 9px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  border-radius: 6px !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  line-height: 25px !important;
  box-sizing: border-box !important;
  transition: all .15s ease !important;
  text-decoration: none !important;
  margin: 0 !important;
}

/* 编辑按钮：与图二「一键采纳」背景颜色与纯白字体严格一致 */
.kb-action-btn.edit,
.kb-btn-sm.primary {
  background: #4f46e5 !important;
  color: #ffffff !important;
  border: 1px solid #4338ca !important;
}

.kb-action-btn.edit:hover,
.kb-btn-sm.primary:hover {
  background: #4338ca !important;
}

.kb-btn-sm.secondary {
  background: #ffffff !important;
  color: #374151 !important;
  border: 1px solid #d1d5db !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
}

.kb-btn-sm.secondary:hover {
  background: #f9fafb !important;
  border-color: #9ca3af !important;
  color: #111827 !important;
}

.kb-btn-sm.danger,
.kb-action-btn.delete {
  background: #fef2f2 !important;
  color: #dc2626 !important;
  border: 1px solid #fecaca !important;
}

.kb-btn-sm.danger:hover,
.kb-action-btn.delete:hover {
  background: #fee2e2 !important;
  color: #b91c1c !important;
}

/* 底部机器人问答模拟测试沙盒 */
.kb-sandbox-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  margin-top: 20px;
}

.kb-sandbox-header {
  margin-bottom: 14px;
}

.kb-sandbox-title-wrap {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: 8px !important;
}

.kb-sandbox-icon {
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.kb-sandbox-title {
  margin: 0 !important;
  font-size: 14px !important;
  color: #0f172a !important;
  font-weight: 700 !important;
  line-height: 1.4 !important;
  display: inline-block !important;
  white-space: nowrap !important;
  flex-shrink: 0;
}

.kb-sandbox-desc {
  font-size: 12px !important;
  color: #64748b !important;
  line-height: 1.4 !important;
  display: inline-block !important;
  white-space: nowrap !important;
}

.kb-sandbox-form {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 10px !important;
  width: 100% !important;
}

.kb-sandbox-input {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  width: auto !important;
  height: 38px !important;
  border-radius: 6px !important;
  font-size: 13px !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

.kb-sandbox-btn {
  flex: 0 0 auto !important;
  flex-shrink: 0 !important;
  white-space: nowrap !important;
  height: 38px !important;
  padding: 0 22px !important;
  border-radius: 6px !important;
  background: #4f46e5 !important;
  font-weight: 600 !important;
  margin: 0 !important;
}

.kb-stat-capsule {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 30px;
  padding: 4px 14px;
  gap: 10px;
  font-size: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.kb-stat-capsule .divider {
  color: #cbd5e1;
}

/* 智能提炼 Top 20 高频问答面板 */
.kb-mined-panel {
  display: none;
  margin-bottom: 24px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
}

.kb-mined-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid #edf2f7;
  padding-bottom: 12px;
}

.kb-mined-header .title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.kb-mined-header h3 {
  margin: 0;
  font-size: 15px;
  color: #0f172a;
  font-weight: 700;
}

.kb-mined-header .subtitle {
  font-size: 12px;
  color: #64748b;
}

.kb-close-btn {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #64748b !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  padding: 4px 8px !important;
  border-radius: 6px !important;
  line-height: normal !important;
  transition: all .15s ease !important;
}

.kb-close-btn:hover {
  background: #e2e8f0 !important;
  color: #0f172a !important;
}

/* 高频问答卡片网格系统 (响应式平铺流式布局，不出现局部滚动条) */
.kb-mined-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
}

.kb-mined-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.kb-mined-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.kb-mined-card.adopted {
  border-color: #bbf7d0;
  background: #fafdfa;
}

/* 卡片内部结构 */
.kb-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kb-rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.kb-rank-badge.top1 { background: #ef4444; }
.kb-rank-badge.top2 { background: #f97316; }
.kb-rank-badge.top3 { background: #eab308; }
.kb-rank-badge.normal { background: #4f46e5; }

.kb-card-title {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.kb-count-pill {
  font-size: 11px;
  color: #475569;
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 500;
}

/* 问答对话气泡区 (清晰区分客户与客服) */
.kb-qa-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kb-client-bubble {
  background: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: #475569;
  line-height: 1.5;
}

.kb-client-bubble .label {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 2px;
}

.kb-reply-bubble {
  background: #eff6ff;
  border-left: 3px solid #3b82f6;
  border-radius: 0 8px 8px 0;
  padding: 8px 10px;
  font-size: 12px;
  color: #1e3a8a;
  line-height: 1.5;
}

.kb-reply-bubble .label {
  font-size: 11px;
  font-weight: 600;
  color: #2563eb;
  margin-bottom: 2px;
}

.kb-keywords-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.kb-kw-tag {
  display: inline-flex;
  align-items: center;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.4;
  font-family: monospace;
}

/* 卡片底部操作栏 */
.kb-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #f1f5f9;
  padding-top: 10px;
  margin-top: auto;
}

.kb-btn-sm {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  height: 28px !important;
  padding: 0 10px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  border-radius: 6px !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  line-height: 28px !important;
  box-sizing: border-box !important;
  transition: all .15s ease !important;
}

.kb-btn-sm.secondary {
  background: #f1f5f9 !important;
  color: #475569 !important;
  border: 1px solid #cbd5e1 !important;
}

.kb-btn-sm.secondary:hover {
  background: #e2e8f0 !important;
  color: #0f172a !important;
}

.kb-btn-sm.primary {
  background: #4f46e5 !important;
  color: #fff !important;
  border: 1px solid #4338ca !important;
}

.kb-btn-sm.primary:hover {
  background: #4338ca !important;
}

.kb-sandbox-result {
  margin-top: 18px !important;
  display: none;
}
.kb-sandbox-result.is-visible {
  display: block;
}

/* 模拟测试匹配结果卡片专用样式 (摆脱 inline-style，兼容 CSP style-src 'self') */
#testResultContainer {
  margin-top: 18px !important;
}

.kb-test-result-box {
  border-radius: 10px !important;
  padding: 16px 20px !important;
  box-sizing: border-box !important;
  transition: all .2s ease !important;
}

.kb-test-result-box.matched {
  background: #f6ffed !important;
  border: 1px solid #b7eb8f !important;
}

.kb-test-result-box.unmatched {
  background: #fff7e6 !important;
  border: 1px solid #ffd591 !important;
}

.kb-test-result-header {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  margin-bottom: 12px !important;
  line-height: 1.4 !important;
}

.kb-test-result-box.matched .kb-test-result-header {
  color: #237804 !important;
}

.kb-test-result-box.unmatched .kb-test-result-header {
  color: #d46b08 !important;
}

.kb-test-info-row {
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  font-size: 13px !important;
  color: #334155 !important;
  margin-bottom: 8px !important;
  line-height: 1.5 !important;
}

.kb-test-info-label {
  font-weight: 600 !important;
  color: #0f172a !important;
}

.kb-test-kw-badge {
  display: inline-flex !important;
  align-items: center !important;
  background: #e6f4ff !important;
  color: #0958d9 !important;
  border: 1px solid #91caff !important;
  padding: 2px 8px !important;
  border-radius: 4px !important;
  font-size: 12px !important;
  font-family: monospace !important;
  font-weight: 600 !important;
  line-height: 1.4 !important;
}

.kb-test-reply-card {
  margin-top: 12px !important;
  background: #ffffff !important;
  border: 1px solid #d9d9d9 !important;
  border-radius: 8px !important;
  padding: 12px 16px !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02) !important;
}

.kb-test-reply-title {
  font-size: 13px !important;
  font-weight: 700 !important;
  color: #0f172a !important;
  margin-bottom: 6px !important;
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
}

.kb-test-reply-content {
  font-size: 13px !important;
  color: #1e293b !important;
  line-height: 1.7 !important;
  white-space: pre-wrap !important;
  word-break: break-word !important;
}

.kb-test-fallback-tip {
  font-size: 13px !important;
  color: #64748b !important;
  line-height: 1.6 !important;
}

.kb-test-meta-muted {
  color: #94a3b8 !important;
  font-size: 12px !important;
}

/* 弹窗样式必须来自外部 CSS，以兼容当前 style-src 'self' 策略。 */
.kb-modal-overlay { padding: 20px; box-sizing: border-box; }
.kb-modal-card {
  background: #fff;
  color: #0f172a;
  border-radius: 12px;
  width: 100%;
  max-width: 580px;
  max-height: calc(100dvh - 40px);
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.kb-modal-card > div:first-child {
  padding: 16px 20px;
  border-bottom: 1px solid #edf2f7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  flex-shrink: 0;
}
.kb-modal-card h3 { margin: 0; font-size: 16px; color: #0f172a; }
#modalCloseBtn {
  border: 0;
  background: transparent;
  color: #64748b;
  box-shadow: none;
  font-size: 24px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
}
.kb-modal-card form { padding: 20px; margin: 0; overflow-y: auto; min-height: 0; }
.kb-modal-card form > div:nth-of-type(1),
.kb-modal-card form > div:nth-of-type(2) {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.kb-modal-card label { display: block; margin: 0 0 12px; font-size: 13px; font-weight: 600; color: #475569; }
.kb-modal-card input:not([type="checkbox"]),
.kb-modal-card select, .kb-modal-card textarea {
  width: 100%;
  box-sizing: border-box;
  margin: 6px 0 0;
  font: inherit;
}
.kb-modal-card textarea { min-height: 100px; resize: vertical; }
.kb-modal-card input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: #4f46e5;
  cursor: pointer;
}
.kb-checkbox-row {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  margin: 4px 0 16px 0 !important;
}
.kb-checkbox-input {
  width: 16px !important;
  height: 16px !important;
  margin: 0 !important;
  flex: 0 0 auto !important;
  accent-color: #4f46e5 !important;
  cursor: pointer !important;
  vertical-align: middle !important;
}
.kb-checkbox-text {
  margin: 0 !important;
  padding: 0 !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  color: #334155 !important;
  line-height: 1 !important;
  cursor: pointer !important;
  display: inline-flex !important;
  align-items: center !important;
  user-select: none !important;
}
.kb-modal-card label:has(input[type="checkbox"]) { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 0; }
.kb-modal-card form > div:has(> input[type="checkbox"]) { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.kb-modal-card form > div:last-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid #edf2f7;
  padding-top: 14px;
}
.kb-modal-card form > div:last-child > div { display: flex; gap: 8px; margin-left: auto; }
.kb-modal-card form > div:last-child > button:first-child { margin-left: auto; }
.kb-modal-card small { color: #64748b; }
@media (max-width: 600px) {
  .kb-modal-overlay { padding: 12px; }
  .kb-modal-card { max-height: calc(100dvh - 24px); }
  .kb-modal-card form { padding: 16px; }
  .kb-modal-card form > div:nth-of-type(1),
  .kb-modal-card form > div:nth-of-type(2) { grid-template-columns: 1fr; gap: 0; }
  .kb-mined-grid { grid-template-columns: minmax(0, 1fr); }
}
