/* ============================================================
   RAG Source Library — Estilos
   Release 1, Sprint 1.1-1.5
   ============================================================ */

/* ── Layout base ──────────────────────────────────────────── */
.rag-layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* ── Sidebar esquerda — lista de fontes ───────────────────── */
.rag-sidebar {
  width: 320px;
  min-width: 260px;
  background: #fff;
  border-right: 1px solid #E2E8F0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rag-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rag-sidebar-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: #1E293B;
  flex: 1;
  margin: 0;
}

.btn-rag-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  background: #F8FAFC;
  color: #64748B;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-rag-back:hover {
  background: #E2E8F0;
  color: #1E293B;
  border-color: #94A3B8;
}

.rag-sidebar-filters {
  padding: 12px 16px;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rag-sidebar-filters input,
.rag-sidebar-filters select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  font-size: 13px;
  color: #334155;
  background: #F8FAFC;
  box-sizing: border-box;
}

.rag-source-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.rag-source-item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid #F1F5F9;
  transition: background 0.15s;
}

.rag-source-item:hover { background: #F8FAFC; }
.rag-source-item.active { background: #EFF6FF; border-left: 3px solid #3B82F6; }

.rag-source-item-name {
  font-size: 13px;
  font-weight: 600;
  color: #1E293B;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rag-source-item-meta {
  font-size: 11px;
  color: #64748B;
  margin-top: 2px;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Painel principal ─────────────────────────────────────── */
.rag-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #F8FAFC;
}

.rag-main-header {
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.rag-main-header-info { flex: 1; }

.rag-main-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #1E293B;
  margin: 0 0 4px 0;
}

.rag-main-header p {
  font-size: 13px;
  color: #64748B;
  margin: 0;
}

.rag-main-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-items: center;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.rag-tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #E2E8F0;
  padding: 0 24px;
}

.rag-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #64748B;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.rag-tab:hover { color: #3B82F6; }
.rag-tab.active { color: #3B82F6; border-bottom-color: #3B82F6; }

/* ── Conteúdo das tabs ────────────────────────────────────── */
.rag-tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* ── Cards de documentos ──────────────────────────────────── */
.rag-doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.rag-doc-card {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  padding: 14px 16px;
  transition: box-shadow 0.2s;
}

.rag-doc-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }

.rag-doc-card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.rag-doc-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #EFF6FF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.rag-doc-card-title {
  font-size: 13px;
  font-weight: 600;
  color: #1E293B;
  line-height: 1.3;
}

.rag-doc-card-version {
  font-size: 11px;
  color: #94A3B8;
  margin-top: 2px;
}

.rag-doc-card-stats {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #F1F5F9;
}

.rag-doc-stat {
  font-size: 11px;
  color: #64748B;
}

.rag-doc-stat strong {
  color: #1E293B;
  font-weight: 600;
}

.rag-doc-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

/* ── Chunks viewer ────────────────────────────────────────── */
.rag-chunk-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rag-chunk-item {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 12px 14px;
}

.rag-chunk-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.rag-chunk-index {
  font-size: 11px;
  font-weight: 600;
  color: #64748B;
  background: #F1F5F9;
  padding: 2px 7px;
  border-radius: 10px;
}

.rag-chunk-domain {
  font-size: 11px;
  color: #3B82F6;
  background: #EFF6FF;
  padding: 2px 7px;
  border-radius: 10px;
}

.rag-chunk-hierarchy {
  font-size: 11px;
  color: #8B5CF6;
  background: #EDE9FE;
  padding: 2px 7px;
  border-radius: 10px;
  font-family: monospace;
}

.rag-chunk-text {
  font-size: 12px;
  color: #475569;
  line-height: 1.5;
  max-height: 80px;
  overflow: hidden;
  position: relative;
}

.rag-chunk-text.expanded { max-height: none; }

.rag-chunk-confidence {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rag-confidence-bar {
  flex: 1;
  height: 4px;
  background: #E2E8F0;
  border-radius: 2px;
  overflow: hidden;
}

.rag-confidence-fill {
  height: 100%;
  border-radius: 2px;
  background: #10B981;
  transition: width 0.3s;
}

.rag-confidence-fill.medium { background: #F59E0B; }
.rag-confidence-fill.low    { background: #EF4444; }

.rag-confidence-label {
  font-size: 11px;
  font-weight: 600;
  color: #64748B;
  white-space: nowrap;
}

/* ── Formulário de nova fonte ─────────────────────────────── */
.rag-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.rag-form-grid .full-width { grid-column: 1 / -1; }

.rag-form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.rag-form-group label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}

.rag-form-group input,
.rag-form-group select,
.rag-form-group textarea {
  padding: 8px 10px;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  font-size: 13px;
  color: #1E293B;
  background: #fff;
  transition: border-color 0.15s;
}

.rag-form-group input:focus,
.rag-form-group select:focus,
.rag-form-group textarea:focus {
  outline: none;
  border-color: #3B82F6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.rag-form-group textarea {
  resize: vertical;
  min-height: 80px;
}

/* ── Upload area ──────────────────────────────────────────── */
.rag-upload-area {
  border: 2px dashed #CBD5E1;
  border-radius: 10px;
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #F8FAFC;
}

.rag-upload-area:hover,
.rag-upload-area.drag-over {
  border-color: #3B82F6;
  background: #EFF6FF;
}

.rag-upload-area .upload-icon { font-size: 36px; margin-bottom: 8px; }
.rag-upload-area h4 { font-size: 14px; font-weight: 600; color: #1E293B; margin: 0 0 4px 0; }
.rag-upload-area p  { font-size: 12px; color: #64748B; margin: 0; }

/* ── Status badges ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-draft        { background: #F1F5F9; color: #64748B; }
.badge-in_review    { background: #FEF3C7; color: #92400E; }
.badge-approved     { background: #DCFCE7; color: #166534; }
.badge-obsolete     { background: #FEE2E2; color: #991B1B; }
.badge-blocked      { background: #EDE9FE; color: #5B21B6; }
.badge-indexed      { background: #CFFAFE; color: #155E75; }
.badge-pending      { background: #FEF9C3; color: #713F12; }
.badge-failed       { background: #FEE2E2; color: #991B1B; }

/* ── Dashboard de qualidade ───────────────────────────────── */
.rag-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.rag-stat-card {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}

.rag-stat-card .stat-value {
  font-size: 24px;
  font-weight: 700;
  color: #1E293B;
}

.rag-stat-card .stat-label {
  font-size: 11px;
  color: #64748B;
  margin-top: 2px;
}

/* ── Modal ────────────────────────────────────────────────── */
.rag-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.rag-modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.rag-modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.rag-modal-header h3 {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: #1E293B;
  margin: 0;
}

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

.rag-modal-footer {
  padding: 14px 20px;
  border-top: 1px solid #E2E8F0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Progress bar ─────────────────────────────────────────── */
.rag-progress {
  width: 100%;
  height: 6px;
  background: #E2E8F0;
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}

.rag-progress-fill {
  height: 100%;
  background: #3B82F6;
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ── Toast de processamento ───────────────────────────────── */
.rag-process-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1E293B;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 2000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 360px;
}

/* ── Approval workflow ────────────────────────────────────── */
.rag-approval-timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rag-approval-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.rag-approval-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.rag-approval-dot.approve  { background: #DCFCE7; color: #166534; }
.rag-approval-dot.reject   { background: #FEE2E2; color: #991B1B; }
.rag-approval-dot.review   { background: #FEF3C7; color: #92400E; }
.rag-approval-dot.obsolete { background: #F1F5F9; color: #64748B; }
.rag-approval-dot.default  { background: #EFF6FF; color: #1D4ED8; }

.rag-approval-body { flex: 1; }
.rag-approval-action { font-size: 12px; font-weight: 600; color: #1E293B; }
.rag-approval-meta   { font-size: 11px; color: #64748B; }
.rag-approval-notes  { font-size: 12px; color: #475569; margin-top: 3px; }

/* ── Botões ───────────────────────────────────────────────── */
.btn-rag-primary {
  padding: 8px 14px;
  background: #3B82F6;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-rag-primary:hover { background: #2563EB; }
.btn-rag-primary:disabled { background: #93C5FD; cursor: not-allowed; }

.btn-rag-secondary {
  padding: 8px 14px;
  background: #F1F5F9;
  color: #334155;
  border: 1px solid #CBD5E1;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-rag-secondary:hover { background: #E2E8F0; }

.btn-rag-danger {
  padding: 8px 14px;
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FCA5A5;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-rag-danger:hover { background: #FECACA; }

.btn-rag-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-rag-icon {
  padding: 7px;
  background: #F1F5F9;
  border: 1px solid #E2E8F0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.btn-rag-icon:hover { background: #E2E8F0; }

/* ── Empty state ──────────────────────────────────────────── */
.rag-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  color: #94A3B8;
  text-align: center;
}

.rag-empty .empty-icon { font-size: 48px; margin-bottom: 12px; }
.rag-empty h4 { font-size: 15px; font-weight: 600; color: #64748B; margin: 0 0 6px 0; }
.rag-empty p  { font-size: 13px; margin: 0; }

/* ── Responsivo ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .rag-layout { flex-direction: column; height: auto; }
  .rag-sidebar { width: 100%; min-width: unset; height: 280px; border-right: none; border-bottom: 1px solid #E2E8F0; }
  .rag-form-grid { grid-template-columns: 1fr; }
  .rag-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
