/* RAG Chat Styles - Light Theme - Full Screen */

/* Boton flotante para abrir el chat */
.rag-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
  transition: all 0.3s ease;
  z-index: 1000;
}

.rag-chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(99, 102, 241, 0.4);
}

.rag-chat-fab svg {
  width: 28px;
  height: 28px;
  color: white;
}

/* Modal del chat - Full Screen */
#ragChatModal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

#ragChatModal.active {
  opacity: 1;
  visibility: visible;
}

.rag-chat-container {
  width: 100%;
  height: 100%;
  background: var(--bg-primary, #ffffff);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.98);
  transition: transform 0.3s ease;
}

#ragChatModal.active .rag-chat-container {
  transform: scale(1);
}

/* Header del chat */
.rag-chat-header {
  padding: 16px 24px;
  background: var(--bg-secondary, #f8f9fa);
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.rag-chat-header-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rag-chat-header-icon svg {
  width: 24px;
  height: 24px;
  color: white;
}

.rag-chat-header-info {
  flex: 1;
}

.rag-chat-header-info h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary, #1f2937);
}

.rag-chat-status {
  font-size: 13px;
  color: var(--text-secondary, #6b7280);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.rag-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.rag-status-dot.online {
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.rag-status-dot.offline {
  background: #ef4444;
}

.rag-chat-close {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.rag-chat-close:hover {
  background: var(--bg-hover, rgba(0,0,0,0.05));
  color: var(--text-primary, #1f2937);
}

/* Export Dropdown */
.rag-export-dropdown {
  position: relative;
}

.rag-chat-export {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.rag-chat-export:hover {
  background: var(--bg-hover, rgba(0,0,0,0.05));
  color: var(--text-primary, #1f2937);
}

.rag-chat-export svg {
  width: 20px;
  height: 20px;
}

.rag-export-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  padding: 8px;
  min-width: 180px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  z-index: 100;
}

.rag-export-dropdown:hover .rag-export-menu,
.rag-export-menu.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.rag-export-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-primary, #374151);
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s ease;
  text-align: left;
}

.rag-export-option:hover {
  background: var(--bg-hover, rgba(99, 102, 241, 0.1));
  color: var(--accent-color, #6366f1);
}

.rag-export-option svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Config Dropdown */
.rag-config-dropdown {
  position: relative;
}

.rag-chat-config {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.rag-chat-config:hover {
  background: var(--bg-hover, rgba(0,0,0,0.05));
  color: var(--text-primary, #1f2937);
}

.rag-chat-config svg {
  width: 20px;
  height: 20px;
}

.rag-config-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  padding: 16px;
  min-width: 280px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  z-index: 100;
}

.rag-config-menu.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.rag-config-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rag-config-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary, #374151);
  white-space: nowrap;
}

.rag-config-divider {
  height: 1px;
  background: var(--border-color, #e5e7eb);
  margin: 12px 0;
}

/* Segmented control (3 options) */
.rag-config-options {
  display: flex;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  overflow: hidden;
}

.rag-config-option {
  padding: 6px 10px;
  border: none;
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary, #6b7280);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.rag-config-option:not(:last-child) {
  border-right: 1px solid var(--border-color, #e5e7eb);
}

.rag-config-option.active {
  background: var(--accent-color, #6366f1);
  color: white;
  font-weight: 500;
}

.rag-config-option:hover:not(.active) {
  background: var(--bg-hover, rgba(99, 102, 241, 0.1));
}

/* Toggle switch */
.rag-config-toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.rag-config-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.rag-toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #d1d5db;
  border-radius: 22px;
  transition: 0.3s;
}

.rag-toggle-slider:before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}

.rag-config-toggle input:checked + .rag-toggle-slider {
  background: var(--accent-color, #6366f1);
}

.rag-config-toggle input:checked + .rag-toggle-slider:before {
  transform: translateX(18px);
}

.rag-config-section-vertical {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

/* Admin: user list for conversation management */
.rag-config-user-list {
  max-height: 200px;
  overflow-y: auto;
  margin: 8px 0;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
}
.rag-config-user-list::-webkit-scrollbar { width: 4px; }
.rag-config-user-list::-webkit-scrollbar-thumb { background: #c0c0c0; border-radius: 2px; }

.rag-config-user-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid #f0f0f0;
}
.rag-config-user-item:last-child { border-bottom: none; }
.rag-config-user-item:hover { background: #f5f5f5; }

.rag-config-user-check {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  accent-color: var(--accent-color, #6366f1);
}
.rag-config-user-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-color, #1f2937);
}
.rag-config-user-badge-admin {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 5px;
  border-radius: 3px;
  background: #ede9fe;
  color: #7c3aed;
  flex-shrink: 0;
}
.rag-config-user-loading {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted, #9ca3af);
}

.rag-config-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: #fee2e2;
  color: #dc2626;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.rag-config-delete-btn:hover:not(:disabled) {
  background: #fecaca;
}
.rag-config-delete-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Export notification toast */
.rag-export-toast {
  position: fixed;
  bottom: 100px;
  right: 24px;
  background: #1f2937;
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  z-index: 3000;
  animation: ragToastIn 0.3s ease;
}

.rag-export-toast.success {
  background: #059669;
}

.rag-export-toast.error {
  background: #dc2626;
}

@keyframes ragToastIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Area de mensajes */
.rag-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--bg-primary, #ffffff);
}

/* Welcome message */
.rag-welcome {
  text-align: center;
  padding: 60px 40px;
  color: var(--text-secondary, #6b7280);
  max-width: 600px;
  margin: auto;
}

.rag-welcome-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rag-welcome-icon svg {
  width: 40px;
  height: 40px;
  color: white;
}

.rag-welcome h3 {
  margin: 0 0 12px;
  font-size: 24px;
  color: var(--text-primary, #1f2937);
}

.rag-welcome p {
  margin: 0 0 32px;
  font-size: 15px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
}

.rag-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.rag-suggestion-btn {
  padding: 12px 20px;
  background: var(--bg-secondary, #f3f4f6);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 24px;
  color: var(--text-secondary, #6b7280);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.rag-suggestion-btn:hover {
  background: var(--bg-hover, rgba(99, 102, 241, 0.1));
  border-color: var(--accent-color, #6366f1);
  color: var(--accent-color, #6366f1);
}

/* Mensajes */
.rag-message {
  display: flex;
  gap: 16px;
  max-width: 900px;
}

.rag-message.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.rag-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.rag-avatar.user {
  background: var(--accent-color, #6366f1);
}

.rag-avatar.assistant {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.rag-avatar svg {
  width: 22px;
  height: 22px;
  color: white;
}

.rag-message-body {
  flex: 1;
  min-width: 0;
}

.rag-message-content {
  padding: 16px 20px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.7;
}

.rag-message.user .rag-message-content {
  background: var(--accent-color, #6366f1);
  color: white;
  border-bottom-right-radius: 4px;
}

.rag-reuse-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  color: var(--text-secondary, #9ca3af);
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
  align-self: flex-end;
}

.rag-message.user:hover .rag-reuse-btn {
  opacity: 0.7;
}

.rag-reuse-btn:hover {
  opacity: 1 !important;
  color: var(--accent-color, #6366f1);
}

.rag-message.assistant .rag-message-content {
  background: var(--bg-secondary, #f3f4f6);
  color: var(--text-primary, #1f2937);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color, #e5e7eb);
}

/* ============================================
   MARKDOWN STYLES
   ============================================ */

.rag-message-content h1,
.rag-message-content h2,
.rag-message-content h3,
.rag-message-content h4,
.rag-message-content h5,
.rag-message-content h6 {
  margin: 0 0 12px 0;
  font-weight: 600;
  line-height: 1.3;
}

.rag-message-content h1 { font-size: 1.5em; border-bottom: 1px solid var(--border-color, #e5e7eb); padding-bottom: 8px; }
.rag-message-content h2 { font-size: 1.3em; }
.rag-message-content h3 { font-size: 1.15em; }
.rag-message-content h4 { font-size: 1em; }

.rag-message.user .rag-message-content h1,
.rag-message.user .rag-message-content h2,
.rag-message.user .rag-message-content h3 {
  border-bottom-color: rgba(255,255,255,0.3);
}

.rag-message-content p {
  margin: 0 0 12px 0;
}

.rag-message-content p:last-child {
  margin-bottom: 0;
}

.rag-message-content ul,
.rag-message-content ol {
  margin: 0 0 12px 0;
  padding-left: 24px;
}

.rag-message-content li {
  margin: 6px 0;
}

.rag-message-content li > ul,
.rag-message-content li > ol {
  margin: 6px 0 0 0;
}

/* Inline code */
.rag-message-content code {
  background: rgba(0,0,0,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.rag-message.user .rag-message-content code {
  background: rgba(255,255,255,0.2);
}

/* Code blocks */
.rag-message-content pre {
  margin: 12px 0;
  padding: 16px;
  background: #1e1e1e;
  border-radius: 8px;
  overflow-x: auto;
}

.rag-message-content pre code {
  background: none;
  padding: 0;
  color: #d4d4d4;
  font-size: 13px;
  line-height: 1.5;
  display: block;
}

/* Blockquotes */
.rag-message-content blockquote {
  margin: 12px 0;
  padding: 12px 16px;
  border-left: 4px solid var(--accent-color, #6366f1);
  background: rgba(99, 102, 241, 0.05);
  color: var(--text-secondary, #6b7280);
  font-style: italic;
}

.rag-message.user .rag-message-content blockquote {
  background: rgba(255,255,255,0.1);
  border-left-color: rgba(255,255,255,0.5);
  color: rgba(255,255,255,0.9);
}

/* Tables */
.rag-message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.95em;
}

.rag-message-content th,
.rag-message-content td {
  padding: 10px 12px;
  border: 1px solid var(--border-color, #e5e7eb);
  text-align: left;
}

.rag-message-content th {
  background: var(--bg-secondary, #f3f4f6);
  font-weight: 600;
}

.rag-message.user .rag-message-content th,
.rag-message.user .rag-message-content td {
  border-color: rgba(255,255,255,0.3);
}

.rag-message.user .rag-message-content th {
  background: rgba(255,255,255,0.15);
}

/* Horizontal rule */
.rag-message-content hr {
  margin: 16px 0;
  border: none;
  border-top: 1px solid var(--border-color, #e5e7eb);
}

.rag-message.user .rag-message-content hr {
  border-top-color: rgba(255,255,255,0.3);
}

/* Links */
.rag-message-content a {
  color: var(--accent-color, #6366f1);
  text-decoration: underline;
}

.rag-message.user .rag-message-content a {
  color: rgba(255,255,255,0.9);
}

/* Images */
.rag-message-content img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

/* Strong and emphasis */
.rag-message-content strong {
  font-weight: 600;
}

.rag-message-content em {
  font-style: italic;
}

/* Strikethrough */
.rag-message-content del {
  text-decoration: line-through;
  opacity: 0.7;
}

/* Task lists */
.rag-message-content input[type="checkbox"] {
  margin-right: 8px;
  vertical-align: middle;
}

/* Loading animation */
.rag-loading {
  display: flex;
  gap: 6px;
  padding: 8px 0;
}

.rag-loading-dot {
  width: 10px;
  height: 10px;
  background: var(--text-secondary, #9ca3af);
  border-radius: 50%;
  animation: ragLoadingBounce 1.4s infinite ease-in-out;
}

.rag-loading-dot:nth-child(1) { animation-delay: 0s; }
.rag-loading-dot:nth-child(2) { animation-delay: 0.2s; }
.rag-loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ragLoadingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Sources */
.rag-sources {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg-tertiary, #f9fafb);
  border-radius: 10px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.rag-sources-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 10px;
}

.rag-sources-header svg {
  width: 16px;
  height: 16px;
}

.rag-sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rag-source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-secondary, #ffffff);
  border-radius: 8px;
  font-size: 12px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.rag-source-type {
  font-weight: 600;
  color: var(--accent-color, #6366f1);
}

.rag-source-project {
  color: var(--text-secondary, #6b7280);
}

.rag-source-score {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

/* Input area */
.rag-chat-input-area {
  padding: 20px 32px;
  background: var(--bg-secondary, #f8f9fa);
  border-top: 1px solid var(--border-color, #e5e7eb);
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-shrink: 0;
}

.rag-chat-input-wrapper {
  flex: 1;
  position: relative;
}

.rag-chat-input {
  width: 100%;
  padding: 14px 20px;
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 14px;
  color: var(--text-primary, #1f2937);
  font-size: 15px;
  resize: none;
  max-height: 150px;
  font-family: inherit;
  line-height: 1.5;
  vertical-align: top;
}

.rag-chat-input:focus {
  outline: none;
  border-color: var(--accent-color, #6366f1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.rag-chat-input::placeholder {
  color: var(--text-secondary, #9ca3af);
}

.rag-chat-send {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.rag-chat-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.rag-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.rag-chat-send svg {
  width: 22px;
  height: 22px;
}

/* Pasted text chip - input area */
.rag-pasted-chip-container:empty {
  display: none;
}

.rag-pasted-chip-container {
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rag-pasted-chip {
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  position: relative;
  max-width: 100%;
  transition: border-color 0.2s ease;
}

.rag-pasted-chip:hover {
  border-color: var(--accent-color, #6366f1);
}

.rag-pasted-chip-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-color, #6366f1);
}

.rag-pasted-chip-icon svg {
  width: 16px;
  height: 16px;
}

.rag-pasted-chip-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rag-pasted-chip-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rag-pasted-chip-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-color, #6366f1);
  background: rgba(99, 102, 241, 0.1);
  padding: 1px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rag-pasted-chip-count {
  font-size: 11px;
  color: var(--text-secondary, #9ca3af);
}

.rag-pasted-chip-preview {
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.rag-pasted-chip-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #9ca3af);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  padding: 0;
}

.rag-pasted-chip-close:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.rag-pasted-chip-close svg {
  width: 14px;
  height: 14px;
}

/* Pasted text chip - inline in user message bubble */
.rag-pasted-chip-inline {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rag-pasted-chip-inline .rag-pasted-chip-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rag-pasted-chip-inline .rag-pasted-chip-label {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.2);
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rag-pasted-chip-inline .rag-pasted-chip-count {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.6);
}

.rag-pasted-chip-inline .rag-pasted-chip-preview {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.rag-chat-clear {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  border: 1px solid var(--border-color, #e5e7eb);
  background: transparent;
  color: var(--text-secondary, #9ca3af);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.rag-chat-clear:hover {
  background: var(--bg-hover, rgba(239, 68, 68, 0.1));
  border-color: #ef4444;
  color: #ef4444;
}

.rag-chat-clear svg {
  width: 20px;
  height: 20px;
}

/* Scrollbar */
.rag-chat-messages::-webkit-scrollbar {
  width: 8px;
}

.rag-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.rag-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color, #d1d5db);
  border-radius: 4px;
}

.rag-chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary, #9ca3af);
}

/* Code block syntax highlighting helpers */
.rag-message-content pre .keyword { color: #569cd6; }
.rag-message-content pre .string { color: #ce9178; }
.rag-message-content pre .number { color: #b5cea8; }
.rag-message-content pre .comment { color: #6a9955; }
.rag-message-content pre .function { color: #dcdcaa; }

/* ============================================
   CITATIONS INTERACTIVOS
   ============================================ */

.rag-citation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 600;
  color: #6366f1;
  background: rgba(99, 102, 241, 0.15);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  vertical-align: super;
  margin: 0 2px;
}

.rag-citation:hover {
  background: rgba(99, 102, 241, 0.3);
  transform: scale(1.1);
}

/* Citations en mensajes de usuario */
.rag-message.user .rag-citation {
  color: white;
  background: rgba(255, 255, 255, 0.25);
}

/* ============================================
   TOOLTIP RICO PARA CITATIONS
   ============================================ */

.rag-tooltip {
  position: fixed;
  z-index: 10000;
  max-width: 480px;
  min-width: 320px;
  padding: 14px 18px;
  background: #ffffff;
  color: #334155;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.6;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(99, 102, 241, 0.08);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.rag-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.rag-tooltip strong {
  color: #4f46e5;
  font-size: 13px;
}

.rag-tip-dim {
  color: #94a3b8;
  font-size: 11px;
}

.rag-tip-subject {
  color: #475569;
  font-weight: 600;
  font-size: 12px;
}

.rag-tip-preview {
  display: block;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e5e7eb;
  color: #475569;
  font-size: 12px;
  line-height: 1.55;
  font-style: italic;
  max-height: 120px;
  overflow-y: auto;
}

.rag-tip-score {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 8px;
  background: #eef2ff;
  border-radius: 10px;
  color: #4f46e5;
  font-size: 11px;
  font-weight: 600;
}

.rag-tip-dblclick {
  display: block;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #e2e8f0;
  color: #94a3b8;
  font-size: 10.5px;
  font-style: italic;
}

/* ============================================
   QUERY ANALYSIS BADGES
   ============================================ */

.rag-query-analysis {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.rag-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  color: #6b7280;
  background: #f3f4f6;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rag-badge-strategy {
  color: #8b5cf6;
  background: rgba(139, 92, 246, 0.1);
}

/* ============================================
   RESPONSE DURATION
   ============================================ */

.rag-duration {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 8px;
  font-size: 11px;
  color: #9ca3af;
  user-select: none;
}

.rag-duration svg {
  opacity: 0.6;
  flex-shrink: 0;
}

/* ============================================
   SOURCES MEJORADOS
   ============================================ */

.rag-sources {
  margin-top: 16px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  border-radius: 12px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.rag-sources-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #374151);
  margin-bottom: 12px;
  cursor: pointer;
}

.rag-sources-header svg {
  width: 16px;
  height: 16px;
  color: #6b7280;
}

.rag-sources-toggle {
  margin-left: auto;
  display: flex;
  align-items: center;
  color: #9ca3af;
  transition: transform 0.2s ease;
}

.rag-sources.collapsed .rag-sources-toggle svg {
  transform: rotate(-90deg);
}

.rag-sources.collapsed .rag-sources-list {
  display: none;
}

.rag-sources-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rag-source-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: white;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  transition: all 0.2s ease;
  cursor: pointer;
}

.rag-source-item:hover {
  border-color: #6366f1;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}

.rag-source-item.cited {
  border-left: 3px solid #22c55e;
}

.rag-source-item.highlight {
  background: rgba(99, 102, 241, 0.1);
  border-color: #6366f1;
  animation: citationPulse 0.5s ease;
}

@keyframes citationPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.rag-source-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 11px;
  font-weight: 600;
  color: #6366f1;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 6px;
}

.rag-source-icon {
  font-size: 18px;
}

.rag-source-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.rag-source-type {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary, #374151);
}

.rag-source-project {
  font-size: 11px;
  color: #6b7280;
}

.rag-source-name {
  font-size: 11px;
  color: #4b5563;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.rag-source-item.openable {
  cursor: pointer;
}

.rag-source-item.openable:hover {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.04);
}

.rag-source-item.openable:hover::after {
  content: '↗';
  position: absolute;
  right: 8px;
  top: 4px;
  font-size: 10px;
  color: #6366f1;
  opacity: 0.6;
}

.rag-source-date {
  font-size: 10px;
  color: #9ca3af;
}

.rag-source-score {
  font-size: 11px;
  font-weight: 600;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
  padding: 4px 8px;
  border-radius: 6px;
}

/* ============================================
   LOADING MEJORADO
   ============================================ */

.rag-loading-text {
  display: block;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary, #6b7280);
  animation: loadingPulse 2s infinite;
}

@keyframes loadingPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ============================================
   REASONING STREAMING
   ============================================ */

.rag-reasoning {
  max-height: 220px;
  overflow-y: auto;
  font-size: 12px;
  color: #7c6f9b;
  font-family: 'Consolas', 'Courier New', monospace;
  background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
  border-radius: 0 10px 10px 0;
  padding: 14px 14px 14px 16px;
  margin-top: 12px;
  border: 1px solid #ddd6fe;
  border-left: 3px solid #8b5cf6;
  line-height: 1.6;
  animation: reasoningSlideIn 0.35s ease-out;
  position: relative;
}

/* Cuando el reasoning es hermano de rag-message-content (respuesta final) */
.rag-message-body > .rag-reasoning {
  margin-top: 0;
  margin-bottom: 10px;
}

/* Scrollbar personalizado */
.rag-reasoning::-webkit-scrollbar { width: 5px; }
.rag-reasoning::-webkit-scrollbar-track { background: transparent; }
.rag-reasoning::-webkit-scrollbar-thumb { background: #c4b5fd; border-radius: 10px; }
.rag-reasoning::-webkit-scrollbar-thumb:hover { background: #a78bfa; }

@keyframes reasoningSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.rag-reasoning-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #7c3aed;
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: 'Segoe UI', sans-serif;
  user-select: none;
}

/* Icono cerebro animado */
.rag-reasoning-icon {
  width: 16px;
  height: 16px;
  animation: reasoningPulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes reasoningPulse {
  0%, 100% { opacity: 0.6; transform: scale(0.95); }
  50%      { opacity: 1; transform: scale(1.1); }
}

.rag-reasoning-content {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Cursor parpadeante mientras streammea */
.rag-reasoning-content.streaming::after {
  content: '▊';
  color: #8b5cf6;
  animation: reasoningBlink 0.8s step-end infinite;
  font-size: 13px;
  margin-left: 1px;
}

@keyframes reasoningBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* Estado colapsado (post-respuesta) */
.rag-reasoning.collapsed {
  max-height: 38px;
  overflow: hidden;
  cursor: pointer;
  padding: 9px 14px 9px 16px;
  transition: max-height 0.3s ease, padding 0.3s ease;
}
.rag-reasoning.collapsed .rag-reasoning-content { display: none; }
.rag-reasoning.collapsed .rag-reasoning-header { margin-bottom: 0; }
.rag-reasoning.collapsed .rag-reasoning-icon { animation: none; opacity: 0.6; }

/* Expandir de nuevo al hacer click */
.rag-reasoning.expanded {
  max-height: 220px;
  cursor: pointer;
  transition: max-height 0.3s ease, padding 0.3s ease;
}
.rag-reasoning.expanded .rag-reasoning-content { display: block; }

/* Chevron toggle */
.rag-reasoning-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 2px;
  border-radius: 3px;
  color: #a78bfa;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  margin-left: auto;
}
.rag-reasoning-copy:hover {
  opacity: 1;
  background: rgba(139, 92, 246, 0.12);
  color: #7c3aed;
}
.rag-reasoning-copy.copied {
  opacity: 1;
  color: #22c55e;
}

.rag-reasoning-toggle {
  font-size: 14px;
  color: #a78bfa;
  transition: transform 0.25s ease;
  line-height: 1;
}
.rag-reasoning.collapsed .rag-reasoning-toggle { transform: rotate(-90deg); }

/* Modo progreso (análisis multi-chunk) */
.rag-reasoning.rag-progress-mode {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-color: #bfdbfe;
  border-left-color: #3b82f6;
}
.rag-reasoning.rag-progress-mode .rag-reasoning-header { color: #2563eb; }
.rag-reasoning.rag-progress-mode .rag-reasoning-content { color: #475569; }
.rag-reasoning.rag-progress-mode .rag-reasoning-content.streaming::after { color: #3b82f6; }
.rag-reasoning.rag-progress-mode::-webkit-scrollbar-thumb { background: #93c5fd; }
.rag-reasoning.rag-progress-mode::-webkit-scrollbar-thumb:hover { background: #60a5fa; }

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .rag-chat-header {
    padding: 12px 16px;
  }

  .rag-chat-messages {
    padding: 16px;
  }

  .rag-chat-input-area {
    padding: 16px;
    gap: 10px;
  }

  .rag-chat-input {
    padding: 12px 14px;
    font-size: 14px;
    min-height: 60px;
  }

  .rag-chat-send,
  .rag-chat-clear {
    width: 44px;
    height: 44px;
  }

  .rag-message {
    max-width: 95%;
  }

  .rag-suggestions {
    flex-direction: column;
  }

  .rag-suggestion-btn {
    width: 100%;
    text-align: left;
  }

  .rag-welcome {
    padding: 40px 20px;
  }

  /* Config menu responsive */
  .rag-config-menu {
    max-height: 65vh;
    overflow-y: auto;
    padding: 12px;
  }

  .rag-config-user-list {
    max-height: 150px;
  }
}

/* En pantallas muy pequeñas anclar el menú a los bordes del viewport */
@media (max-width: 430px) {
  .rag-config-menu {
    position: fixed;
    top: 64px;
    left: 8px;
    right: 8px;
    width: auto;
    min-width: unset;
    max-height: calc(100svh - 80px);
    overflow-y: auto;
    z-index: 10000;
    padding: 12px;
  }

  .rag-config-section {
    flex-wrap: wrap;
    gap: 8px;
  }

  .rag-config-label {
    white-space: normal;
  }

  .rag-config-options {
    width: 100%;
    justify-content: stretch;
  }

  .rag-config-option {
    flex: 1;
    text-align: center;
  }

  .rag-config-user-list {
    max-height: 130px;
  }
}

/* ============================================
   MERMAID DIAGRAMS
   ============================================ */

.rag-mermaid-container {
  margin: 16px 0;
  padding: 20px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  overflow-x: auto;
}

.rag-mermaid-container:hover {
  border-color: #a5b4fc;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.1);
}

.rag-mermaid-diagram {
  display: flex;
  justify-content: center;
}

.rag-mermaid-diagram svg {
  max-width: 100%;
  height: auto;
}

.rag-mermaid-hint {
  text-align: center;
  margin-top: 10px;
  font-size: 11px;
  color: #94a3b8;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.rag-mermaid-container:hover .rag-mermaid-hint {
  opacity: 1;
}

/* Mermaid Modal */

.rag-mermaid-modal {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.rag-mermaid-modal.active {
  opacity: 1;
}

.rag-mermaid-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.rag-mermaid-modal-content {
  position: relative;
  width: 92vw;
  max-width: 1200px;
  max-height: 90vh;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.rag-mermaid-modal.active .rag-mermaid-modal-content {
  transform: scale(1);
}

.rag-mermaid-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600;
  font-size: 15px;
  color: #1f2937;
}

.rag-mermaid-modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 22px;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
}

.rag-mermaid-modal-close:hover {
  background: #f1f5f9;
  color: #1f2937;
}

.rag-mermaid-modal-body {
  flex: 1;
  overflow: auto;
  padding: 24px;
}

/* Zoom controls */
.rag-mermaid-zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  margin-right: 12px;
}

.rag-mermaid-zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  color: #475569;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.rag-mermaid-zoom-btn:hover {
  background: #e0e7ff;
  border-color: #6366f1;
  color: #4338ca;
}

.rag-mermaid-zoom-btn:active {
  transform: scale(0.95);
}

.rag-mermaid-zoom-label {
  min-width: 40px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #6366f1;
  user-select: none;
}

/* Zoom wrapper - transform-origin top left so scroll works naturally */
.rag-mermaid-zoom-wrapper {
  transform-origin: top left;
  display: inline-block;
  min-width: 100%;
}

.rag-mermaid-zoom-wrapper svg {
  display: block;
  height: auto;
}

/* ============================================
   HISTORY BUTTON & MODAL
   ============================================ */

.rag-chat-history {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.rag-chat-history:hover {
  background: var(--bg-hover, rgba(0,0,0,0.05));
  color: var(--text-primary, #1f2937);
}

.rag-chat-history svg {
  width: 20px;
  height: 20px;
}

/* History panel — slides over the messages area */
.rag-history-panel {
  position: absolute;
  inset: 0;
  background: var(--bg-primary, #ffffff);
  z-index: 10;
  display: flex;
  flex-direction: column;
  animation: ragHistorySlideIn 0.25s ease;
}

@keyframes ragHistorySlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.rag-history-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  flex-shrink: 0;
}

.rag-history-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary, #1f2937);
  flex-shrink: 0;
}

.rag-history-search-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.rag-history-search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-secondary, #9ca3af);
  pointer-events: none;
}

.rag-history-search {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  background: var(--bg-primary, #ffffff);
  color: var(--text-primary, #1f2937);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.rag-history-search:focus {
  border-color: var(--accent-color, #6366f1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.rag-history-search::placeholder {
  color: var(--text-secondary, #9ca3af);
}

.rag-history-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.rag-history-close:hover {
  background: var(--bg-hover, rgba(0,0,0,0.05));
  color: var(--text-primary, #1f2937);
}

.rag-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.rag-history-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary, #9ca3af);
  font-size: 14px;
}

.rag-history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.rag-history-item:hover {
  background: var(--bg-secondary, #f3f4f6);
  border-color: var(--border-color, #e5e7eb);
}

.rag-history-item:active {
  transform: scale(0.995);
}

.rag-history-item-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.rag-history-item-icon svg {
  width: 18px;
  height: 18px;
  color: white;
}

.rag-history-item-info {
  flex: 1;
  min-width: 0;
}

.rag-history-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary, #1f2937);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rag-history-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-secondary, #9ca3af);
}

.rag-history-item-user {
  font-weight: 500;
  color: var(--accent-color, #6366f1);
}

.rag-history-item-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(99, 102, 241, 0.1);
  color: var(--accent-color, #6366f1);
  white-space: nowrap;
}

.rag-history-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: all 0.15s ease;
}

.rag-history-item:hover .rag-history-item-actions {
  opacity: 1;
}

.rag-history-item-delete,
.rag-history-item-copy {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #9ca3af);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.rag-history-item-delete svg,
.rag-history-item-copy svg {
  width: 16px;
  height: 16px;
}

.rag-history-item-delete:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.rag-history-item-copy:hover {
  background: rgba(99, 102, 241, 0.1);
  color: var(--accent-color, #6366f1);
}

.rag-history-item-delete:active,
.rag-history-item-copy:active {
  transform: scale(0.9);
}

/* Scrollbar */
.rag-history-list::-webkit-scrollbar { width: 6px; }
.rag-history-list::-webkit-scrollbar-track { background: transparent; }
.rag-history-list::-webkit-scrollbar-thumb { background: var(--border-color, #d1d5db); border-radius: 3px; }
.rag-history-list::-webkit-scrollbar-thumb:hover { background: var(--text-secondary, #9ca3af); }

/* ============================================
   INSIGHTS / ESTADÍSTICAS PANEL
   ============================================ */

/* Insights header button — same style as export/config */
.rag-chat-insights {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.rag-chat-insights:hover {
  background: var(--bg-hover, rgba(0,0,0,0.05));
  color: var(--text-primary, #1f2937);
}
.rag-chat-insights svg {
  width: 20px;
  height: 20px;
}

/* Panel overlay — sits on top of messages area */
.rag-insights-panel {
  position: absolute;
  top: 64px; /* below header */
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary, #ffffff);
  z-index: 20;
  display: flex;
  flex-direction: column;
  animation: ragInsightsSlideIn 0.25s ease;
}

@keyframes ragInsightsSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.rag-insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  flex-shrink: 0;
}
.rag-insights-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary, #1f2937);
}
.rag-insights-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.rag-insights-close:hover {
  background: var(--bg-hover, rgba(0,0,0,0.05));
  color: var(--text-primary, #1f2937);
}

/* Filters bar */
.rag-insights-filters {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.rag-insights-filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rag-insights-filter-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.rag-insights-filter-group input[type="date"],
.rag-insights-filter-group select {
  padding: 6px 10px;
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-primary, #1f2937);
  background: var(--bg-primary, #fff);
  outline: none;
  transition: border-color 0.2s;
}
.rag-insights-filter-group input[type="date"]:focus,
.rag-insights-filter-group select:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}
.rag-insights-apply {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.rag-insights-apply:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Body — scrollable content */
.rag-insights-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.rag-insights-body::-webkit-scrollbar { width: 6px; }
.rag-insights-body::-webkit-scrollbar-track { background: transparent; }
.rag-insights-body::-webkit-scrollbar-thumb { background: var(--border-color, #d1d5db); border-radius: 3px; }

/* Loading state */
.rag-insights-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 20px;
  color: var(--text-secondary, #6b7280);
  font-size: 14px;
}
.rag-insights-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color, #e5e7eb);
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: ragSpin 0.6s linear infinite;
}
@keyframes ragSpin { to { transform: rotate(360deg); } }

.rag-insights-error {
  text-align: center;
  padding: 60px 20px;
  color: #ef4444;
  font-size: 14px;
}
.rag-insights-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary, #6b7280);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.rag-insights-empty p {
  margin: 0;
}

/* ── Overview cards ── */
.rag-insights-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.rag-insights-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary, #f9fafb);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.rag-insights-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.rag-insights-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(139,92,246,0.1));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.rag-insights-card-icon svg {
  width: 18px;
  height: 18px;
  color: #6366f1;
}
.rag-insights-card-body {
  min-width: 0;
}
.rag-insights-card-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary, #1f2937);
  line-height: 1.2;
}
.rag-insights-card-label {
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 500;
}

/* ── Section wrappers ── */
.rag-insights-section {
  margin-bottom: 24px;
}
.rag-insights-section h4 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #1f2937);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Vertical bar chart (questions per day) ── */
.rag-chart-vertical {
  background: var(--bg-secondary, #f9fafb);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  padding: 16px 12px 8px;
  overflow-x: auto;
}
.rag-chart-bars-v {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 140px;
  min-width: fit-content;
}
.rag-bar-v-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 22px;
  height: 100%;
  justify-content: flex-end;
}
.rag-bar-v {
  width: 100%;
  max-width: 28px;
  background: linear-gradient(180deg, #6366f1, #8b5cf6);
  border-radius: 4px 4px 0 0;
  position: relative;
  min-height: 2px;
  transition: height 0.4s ease;
}
.rag-bar-v-val {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  white-space: nowrap;
}
.rag-bar-v-label {
  font-size: 9px;
  color: var(--text-secondary, #9ca3af);
  margin-top: 4px;
  white-space: nowrap;
  transform: rotate(-45deg);
  transform-origin: center;
}

/* ── Horizontal bar charts ── */
.rag-insights-hbars {
  background: var(--bg-secondary, #f9fafb);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  padding: 12px 16px;
}
.rag-hbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}
.rag-hbar-label {
  width: 60px;
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  text-align: right;
  flex-shrink: 0;
}
.rag-hbar-track {
  flex: 1;
  height: 16px;
  background: var(--bg-tertiary, #f3f4f6);
  border-radius: 4px;
  overflow: hidden;
}
.rag-hbar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  border-radius: 4px;
  transition: width 0.5s ease;
  min-width: 2px;
}
.rag-hbar-fill-alt {
  background: linear-gradient(90deg, #10b981, #34d399);
}
.rag-hbar-fill-source {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}
.rag-hbar-fill-project {
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
}
.rag-hbar-fill-rt {
  background: linear-gradient(90deg, #ef4444, #f87171);
}
.rag-hbar-val {
  width: 36px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary, #1f2937);
  text-align: right;
  flex-shrink: 0;
}

/* ── Two-column layout ── */
.rag-insights-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ── Table ── */
.rag-insights-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-secondary, #f9fafb);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  overflow: hidden;
}
.rag-insights-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #6b7280);
  background: var(--bg-tertiary, #f3f4f6);
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.rag-insights-table td {
  padding: 8px 12px;
  color: var(--text-primary, #1f2937);
  border-bottom: 1px solid var(--border-color, #f3f4f6);
}
.rag-insights-table tbody tr:last-child td {
  border-bottom: none;
}
.rag-insights-table tbody tr:hover {
  background: rgba(99,102,241,0.04);
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .rag-insights-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  .rag-insights-two-col {
    grid-template-columns: 1fr;
  }
  .rag-insights-filters {
    flex-direction: column;
    align-items: stretch;
  }
  .rag-hbar-label {
    width: 50px;
    font-size: 11px;
  }
}
