/* ================================
   Knowledge Base Management
   Prefix: .kb-
   ================================ */

.kb-page {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Header */
.kb-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.kb-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
  margin: 0;
}
.kb-subtitle {
  color: #64748b;
  font-size: 0.875rem;
  margin: 4px 0 0;
}

/* Stats */
.kb-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}
.kb-stat {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}
.kb-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #334155;
}
.kb-stat--green { color: #16a34a; }
.kb-stat--blue  { color: #2563eb; }
.kb-stat-label {
  font-size: 0.75rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Search */
.kb-search {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 20px;
  gap: 10px;
  transition: border-color .2s;
}
.kb-search:focus-within {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.08);
}
.kb-search input {
  border: none;
  outline: none;
  flex: 1;
  font-size: 0.9375rem;
  color: #334155;
  background: transparent;
}
.kb-search input::placeholder { color: #cbd5e1; }

/* Loading / Empty */
.kb-loading, .kb-empty {
  text-align: center;
  padding: 48px 20px;
  color: #94a3b8;
  font-size: 0.9375rem;
}

/* Card List */
.kb-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.kb-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
  transition: border-color .2s, box-shadow .2s;
}
.kb-card:hover {
  border-color: #c7d2fe;
  box-shadow: 0 2px 8px rgba(99,102,241,0.06);
}
.kb-card--inactive {
  opacity: 0.6;
}
.kb-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
}
.kb-card-info { flex: 1; min-width: 0; }
.kb-card-top {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.kb-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1e293b;
  margin: 0 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kb-card-keywords {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* Badges */
.kb-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.kb-badge--code {
  background: #eef2ff;
  color: #4338ca;
}
.kb-badge--cat {
  background: #f0fdf4;
  color: #15803d;
}
.kb-badge--sub {
  background: #fefce8;
  color: #a16207;
}
.kb-badge--inactive {
  background: #fef2f2;
  color: #dc2626;
}
.kb-badge--embedded {
  background: #eff6ff;
  color: #2563eb;
}
.kb-badge--no-embed {
  background: #fef2f2;
  color: #dc2626;
}

.kb-keyword {
  display: inline-block;
  font-size: 0.6875rem;
  color: #64748b;
  background: #f1f5f9;
  padding: 1px 7px;
  border-radius: 4px;
}

/* Chevron */
.kb-chevron {
  flex-shrink: 0;
  color: #94a3b8;
  transition: transform .2s;
}
.kb-chevron--open {
  transform: rotate(180deg);
}

/* Card Body (expanded) */
.kb-card-body {
  border-top: 1px solid #f1f5f9;
  padding: 16px 20px;
  animation: kbSlideDown .2s ease;
}
@keyframes kbSlideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kb-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  font-size: 0.8125rem;
  color: #64748b;
  margin-bottom: 12px;
}
.kb-card-meta strong { color: #475569; }

.kb-content {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px 16px;
  font-family: 'Menlo', 'Consolas', 'Courier New', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.kb-card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Buttons */
.kb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.kb-btn:active { transform: scale(0.97); }
.kb-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.kb-btn--primary {
  background: #6366f1;
  color: #fff;
}
.kb-btn--primary:hover:not(:disabled) { background: #4f46e5; }

.kb-btn--outline {
  background: transparent;
  color: #64748b;
  border: 1px solid #e2e8f0;
}
.kb-btn--outline:hover { background: #f8fafc; }

.kb-btn--sm {
  font-size: 0.8125rem;
  padding: 7px 14px;
}
.kb-btn--edit {
  background: #eff6ff;
  color: #2563eb;
}
.kb-btn--edit:hover { background: #dbeafe; }
.kb-btn--delete {
  background: #fef2f2;
  color: #dc2626;
}
.kb-btn--delete:hover { background: #fee2e2; }

/* Modal Overlay */
.kb-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15,23,42,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: kbFadeIn .15s ease;
}
@keyframes kbFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.kb-modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  animation: kbModalIn .2s ease;
}
@keyframes kbModalIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.kb-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #f1f5f9;
}
.kb-modal-header h3 {
  margin: 0;
  font-size: 1.125rem;
  color: #1e293b;
}
.kb-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #94a3b8;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.kb-modal-close:hover { color: #475569; }

.kb-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* Form */
.kb-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.kb-form-group {
  margin-bottom: 14px;
}
.kb-form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 5px;
}
.kb-req { color: #ef4444; }
.kb-hint { font-weight: 400; color: #94a3b8; font-size: 0.75rem; }

.kb-form-group input,
.kb-form-group select,
.kb-form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.875rem;
  color: #334155;
  background: #fff;
  transition: border-color .2s;
  font-family: inherit;
  box-sizing: border-box;
}
.kb-form-group input:focus,
.kb-form-group select:focus,
.kb-form-group textarea:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.08);
}
.kb-form-group input:disabled {
  background: #f1f5f9;
  color: #94a3b8;
}
.kb-form-group textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.5;
}

.kb-form-note {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.8125rem;
  color: #92400e;
  line-height: 1.5;
}

.kb-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid #f1f5f9;
}

/* Responsive */
@media (max-width: 768px) {
  .kb-page { padding: 16px; }
  .kb-header { flex-direction: column; }
  .kb-stats { flex-wrap: wrap; }
  .kb-stat { flex: 1; min-width: 70px; padding: 10px 14px; }
  .kb-form-row { grid-template-columns: 1fr; }
  .kb-modal { max-width: 100%; margin: 10px; }
  .kb-card-header { padding: 12px 16px; }
  .kb-card-body { padding: 12px 16px; }
  .kb-card-title { white-space: normal; }
}
