/* PSICOCHAT AI Chat Styles */

.psicochat-ai-chat-container {
  display: flex;
  flex-direction: column;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin-bottom: 100px;
}

.psicochat-ai-chat-theme-dark {
  background: #1a1a1a;
  border-color: #333;
  color: #ffffff;
}

.psicochat-ai-chat-theme-dark .psicochat-ai-chat-header {
  background: #2a2a2a;
  border-bottom-color: #333;
}

.psicochat-ai-chat-theme-dark .psicochat-ai-chat-input-container {
  background: #2a2a2a;
  border-top-color: #333;
}

.psicochat-ai-chat-theme-dark .psicochat-ai-chat-input {
  background: #333;
  border-color: #555;
  color: #ffffff;
}

.psicochat-ai-chat-theme-dark .psicochat-ai-chat-input::placeholder {
  color: #aaa;
}

.psicochat-ai-chat-theme-dark .psicochat-ai-chat-send-btn {
  background: #1c443b;
  color: #ffffff;
}

.psicochat-ai-chat-theme-dark .psicochat-ai-chat-send-btn:hover:not(:disabled) {
  background: #0f2d26;
}

.psicochat-ai-chat-theme-dark .psicochat-ai-chat-send-btn:disabled {
  background: #555;
  color: #777;
}

/* Header */
.psicochat-ai-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: #f8f9fa;
  border-bottom: 1px solid #e0e0e0;
}

.psicochat-ai-chat-title {
  display: flex;
  align-items: center;
  gap: 30px;
}

.psicochat-ai-chat-icon {
  color: #1c443b;
  font-size: 150px;
}

.psicochat-ai-chat-logo {
  width: 100px;
  height: 50px;
  object-fit: contain;
}

.psicochat-ai-chat-title h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.psicochat-ai-chat-controls {
  display: flex;
  gap: 8px;
}

.psicochat-ai-chat-clear-btn {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  color: #666;
  transition: all 0.2s ease;
}

.psicochat-ai-chat-clear-btn:hover {
  background: #e9ecef;
  color: #333;
}

/* Messages Area */
.psicochat-ai-chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100% - 140px);
  scroll-behavior: smooth;
}

.psicochat-ai-chat-welcome {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 12px;
  margin-bottom: 20px;
}

.psicochat-ai-chat-welcome-icon {
  color: #1c443b;
  font-size: 32px;
}

.psicochat-ai-chat-welcome-logo {
  width: 100px;
  height: 100px;
  object-fit: contain;
}

.psicochat-ai-chat-welcome-text h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.psicochat-ai-chat-welcome-text p {
  margin: 0;
  font-size: 14px;
  color: #666;
  line-height: 1.4;
}

/* Message Bubbles */
.psicochat-ai-chat-message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  animation: fadeInUp 0.3s ease;
}

.psicochat-ai-chat-message.user {
  justify-content: flex-end;
  flex-direction: row-reverse;
  padding-right: 20px;
}

.psicochat-ai-chat-message.ai {
  justify-content: flex-start;
  padding-left: 20px;
}

.psicochat-ai-chat-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #e9ecef;
  margin-top: 10px;
}

.psicochat-ai-chat-message.user .psicochat-ai-chat-message-avatar {
  background: #1c443b;
  color: #ffffff;
}

.psicochat-ai-chat-message.ai .psicochat-ai-chat-message-avatar {
  background: #f1f3f4;
  color: #1c443b;
}

.psicochat-ai-chat-message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.psicochat-ai-chat-message-avatar .material-icons-outlined {
  font-size: 20px;
}

.psicochat-ai-chat-message-content {
  padding: 12px 16px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
}

.psicochat-ai-chat-message.user .psicochat-ai-chat-message-content {
  background: #1c443b;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.psicochat-ai-chat-message.ai .psicochat-ai-chat-message-content {
  background: #f1f3f4;
  color: #333;
  border-bottom-left-radius: 4px;
}

.psicochat-ai-chat-message-text {
  margin: 0;
  line-height: 1.4;
  font-size: 14px;
}

/* Links in messages - always bold */
.psicochat-ai-chat-message-content a,
.psicochat-ai-chat-message-text a {
  font-weight: bold !important;
  text-decoration: underline;
}

.psicochat-ai-chat-message-content a:hover,
.psicochat-ai-chat-message-text a:hover {
  opacity: 0.8;
}

.psicochat-ai-chat-message-wrapper {
  display: flex;
  flex-direction: column;
}

.psicochat-ai-chat-message-time {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  align-self: flex-end;
}

.psicochat-ai-chat-message.ai .psicochat-ai-chat-message-time {
  align-self: flex-start;
}

/* Input Container */
.psicochat-ai-chat-input-container {
  padding: 16px 20px;
  background: #f8f9fa;
  border-top: 1px solid #e0e0e0;
}

.psicochat-ai-chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 100px;
  padding: 8px 20px;
  transition: border-color 0.2s ease;
}

.psicochat-ai-chat-input-wrapper:focus-within {
  border-color: #1c443b;
  box-shadow: 0 0 0 2px rgba(28, 68, 59, 0.1);
}

.psicochat-ai-chat-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 8px 0;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  min-height: 20px;
  background: transparent;
}

.psicochat-ai-chat-input::placeholder {
  color: #999;
}

.psicochat-ai-chat-send-btn {
  background: #1c443b;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #ffffff;
}

.psicochat-ai-chat-send-btn:hover:not(:disabled) {
  background: #0f2d26;
  transform: scale(1.05);
}

.psicochat-ai-chat-send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

.psicochat-ai-chat-send-btn i {
  font-size: 18px;
}

.psicochat-ai-chat-status {
  margin-top: 8px;
  text-align: center;
}

.psicochat-ai-chat-status-text {
  font-size: 12px;
  color: #666;
}

/* Sources */
.psicochat-ai-chat-sources {
  border-top: 1px solid #e0e0e0;
  background: #f8f9fa;
}

.psicochat-ai-chat-sources-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 1px solid #e0e0e0;
}

.psicochat-ai-chat-sources-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

.psicochat-ai-chat-sources-toggle {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: #666;
  transition: transform 0.2s ease;
}

.psicochat-ai-chat-sources-toggle:hover {
  color: #333;
}

.psicochat-ai-chat-sources-content {
  padding: 16px 20px;
  max-height: 200px;
  overflow-y: auto;
}

.psicochat-ai-chat-sources-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.psicochat-ai-chat-source-item {
  padding: 8px 12px;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 12px;
  color: #666;
}

.psicochat-ai-chat-source-item a {
  color: #1c443b;
  text-decoration: none;
}

.psicochat-ai-chat-source-item a:hover {
  text-decoration: underline;
}

/* Loading */
.psicochat-ai-chat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  color: #666;
  font-size: 14px;
}

.psicochat-ai-chat-loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e0e0e0;
  border-top: 2px solid #1c443b;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Error States */
.psicochat-ai-chat-disabled,
.psicochat-ai-chat-error {
  padding: 20px;
  text-align: center;
  color: #666;
  background: #f8f9fa;
  border-radius: 8px;
  margin: 20px;
}

.psicochat-ai-chat-error {
  color: #dc3545;
  background: #f8d7da;
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
  .psicochat-ai-chat-container {
    border-radius: 0;
    height: 100vh !important;
  }
  
  .psicochat-ai-chat-messages {
    padding: 16px;
  }
  
  .psicochat-ai-chat-message-content {
    max-width: 85%;
  }
  
  .psicochat-ai-chat-input-container {
    padding: 12px 16px;
  }
}

/* Fix for DevTools open - ensure input is always visible */
.psicochat-ai-chat-container {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 500px;
  max-height: calc(100vh - 50px);
}

.psicochat-ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 200px;
  max-height: calc(100% - 200px);
}

.psicochat-ai-chat-input-container {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

/* Scrollbar Styling */
.psicochat-ai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.psicochat-ai-chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.psicochat-ai-chat-messages::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.psicochat-ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Dynamic Loading Animation */
.psicochat-ai-chat-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  background: rgba(28, 68, 59, 0.05);
  position: relative;
  overflow: hidden;
}

.psicochat-ai-chat-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(28, 68, 59, 0.1), transparent);
  animation: psicochat-shimmer 2s infinite;
}

@keyframes psicochat-shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

.psicochat-ai-chat-loading-content {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.psicochat-ai-chat-loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e0e0e0;
  border-top: 3px solid #1c443b;
  border-radius: 50%;
  animation: psicochat-spin 1s linear infinite;
  margin-right: 12px;
}

@keyframes psicochat-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.psicochat-ai-chat-status-text {
  color: #1c443b;
  font-weight: 500;
  font-size: 14px;
  animation: psicochat-pulse 2s ease-in-out infinite;
  text-align: center;
}

@keyframes psicochat-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.psicochat-ai-chat-progress-bar {
  width: 100%;
  height: 3px;
  background: rgba(28, 68, 59, 0.1);
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
}

.psicochat-ai-chat-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #1c443b, #2d5a4f);
  border-radius: 2px;
  animation: psicochat-progress 8s ease-in-out infinite;
}

@keyframes psicochat-progress {
  0% { width: 0%; }
  25% { width: 30%; }
  50% { width: 60%; }
  75% { width: 85%; }
  100% { width: 100%; }
}

/* New Content Indicator */
.psicochat-new-content-indicator {
  position: sticky;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 68, 59, 0.9);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  margin: 10px auto;
  max-width: 200px;
  backdrop-filter: blur(10px);
}

/* RAG Admin Columns Styles */
.rag-source-type,
.rag-content-type {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rag-source-type-page {
  background-color: #e3f2fd;
  color: #1976d2;
}

.rag-source-type-post {
  background-color: #f3e5f5;
  color: #7b1fa2;
}

.rag-source-type-custom_post_type {
  background-color: #e8f5e8;
  color: #388e3c;
}

.rag-source-type-media {
  background-color: #fff3e0;
  color: #f57c00;
}

.rag-source-type-route {
  background-color: #fce4ec;
  color: #c2185b;
}

.rag-source-type-sitemap {
  background-color: #f1f8e9;
  color: #689f38;
}

/* Generic style for custom post types that don't have specific styles */
.rag-source-type:not(.rag-source-type-page):not(.rag-source-type-post):not(.rag-source-type-custom_post_type):not(.rag-source-type-media):not(.rag-source-type-route):not(.rag-source-type-sitemap) {
  background-color: #e8f5e8;
  color: #388e3c;
}

.rag-content-type-text {
  background-color: #e3f2fd;
  color: #1976d2;
}

.rag-content-type-navigation {
  background-color: #f3e5f5;
  color: #7b1fa2;
}

.rag-content-type-image {
  background-color: #fff3e0;
  color: #f57c00;
}

.rag-content-type-video {
  background-color: #e8f5e8;
  color: #388e3c;
}

.rag-content-type-audio {
  background-color: #fce4ec;
  color: #c2185b;
}

.rag-content-type-document {
  background-color: #f1f8e9;
  color: #689f38;
}

.rag-has-embedding {
  font-weight: 500;
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.rag-has-embedding-yes {
  color: #4caf50;
  background-color: rgba(76, 175, 80, 0.1);
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.rag-has-embedding-yes small {
  color: #666;
  font-size: 10px;
  display: block;
  margin-top: 2px;
}

.rag-has-embedding-no {
  color: #f44336;
  background-color: rgba(244, 67, 54, 0.1);
  border: 1px solid rgba(244, 67, 54, 0.3);
}

/* Token status badges */
.rag-token-status { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rag-token-badge { 
  padding: 2px 6px; 
  border-radius: 12px; 
  font-size: 11px; 
  line-height: 1; 
  border: 1px solid rgba(0,0,0,0.1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.rag-token-total { background: rgba(28, 68, 59, 0.1); color: #1c443b; border-color: rgba(28,68,59,0.2); font-weight: 600; }
.rag-token-ok { background: rgba(76, 175, 80, 0.12); color: #2e7d32; border-color: rgba(76,175,80,0.35); }
.rag-token-warn { background: rgba(244, 67, 54, 0.12); color: #c62828; border-color: rgba(244,67,54,0.35); }

/* Icons in token badges */
.rag-token-badge .material-icons-outlined {
  font-size: 16px;
  line-height: 1;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.rag-token-ok .rag-icon-check {
  color: #2e7d32;
}

.rag-token-warn .rag-icon-error {
  color: #c62828;
}

/* ============================================
   Token Status Layout
   ============================================ */

.rag-token-vertical {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.rag-token-total-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

/* Model Rows */
.rag-model-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.rag-model-label {
  min-width: 140px;
  font-size: 11px;
  color: #555;
  line-height: 1.4;
}

.rag-model-price {
  display: block;
  color: #666;
  font-size: 10px;
  margin-top: 2px;
}

/* Copy Summary Button */
.rag-copy-summary.button.button-small {
  margin-left: 6px;
  background: #1c443b;
  color: #fff;
  border-color: #1c443b;
  font-size: 11px;
  padding: 2px 8px;
}

.rag-copy-summary.button.button-small:hover {
  background: #0f2d26;
  border-color: #0f2d26;
}

/* ============================================
   Collapsible Models Section
   ============================================ */

.rag-models-collapsible {
  width: 100%;
  margin-top: 4px;
}

/* Toggle Button */
.rag-models-toggle {
  background: none;
  border: none;
  padding: 4px 0;
  margin: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #2271b1;
  font-size: 12px;
  text-decoration: none;
  transition: color 0.2s ease;
}

.rag-models-toggle:hover {
  color: #135e96;
  text-decoration: underline;
}

.rag-models-toggle:focus {
  outline: 1px solid #2271b1;
  outline-offset: 2px;
}

.rag-models-toggle-text {
  font-weight: 500;
}

.rag-models-toggle-icon {
  font-size: 18px;
  line-height: 1;
  transition: transform 0.2s ease;
  display: inline-flex;
  align-items: center;
}

.rag-models-toggle[aria-expanded="true"] .rag-models-toggle-icon {
  transform: rotate(180deg);
}

/* Models Content Container */
.rag-models-content {
  margin-top: 8px;
  padding-left: 8px;
  border-left: 2px solid #e0e0e0;
}

.rag-models-content .rag-model-row {
  margin-bottom: 6px;
  padding: 2px 0;
}

.rag-model-price {
  color: #666;
  font-size: 10px;
}

/* ============================================
   Floating Chat Bubble
   ============================================ */

#psicochat-floating-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1c443b;
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

/* When the toggle has a custom image, use a white background */
#psicochat-floating-toggle.psicochat-floating-has-img {
  background: #ffffff;
  border: 1px solid #e0e0e0;
}

#psicochat-floating-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

#psicochat-floating-toggle:not(.psicochat-floating-has-img):hover {
  background: #0f2d26;
}

#psicochat-floating-toggle.psicochat-floating-has-img:hover {
  background: #f8f9fa;
}

#psicochat-floating-toggle.psicochat-floating-active:not(.psicochat-floating-has-img) {
  background: #0f2d26;
}

#psicochat-floating-toggle i {
  font-size: 26px;
}

#psicochat-floating-toggle .psicochat-floating-toggle-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: contain;
}

/* Floating Chat Panel */
#psicochat-floating-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  z-index: 9998;
  width: 400px;
  height: 600px;
  max-height: calc(100vh - 110px);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  background: #ffffff;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

#psicochat-floating-panel.psicochat-floating-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

#psicochat-floating-panel .psicochat-ai-chat-container {
  height: 100%;
  width: 100%;
  border: none;
  border-radius: 0;
  margin-bottom: 0;
  min-height: 0;
  max-height: 100%;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

#psicochat-floating-panel .psicochat-ai-chat-messages {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

#psicochat-floating-panel .psicochat-ai-chat-input-container {
  flex-shrink: 0;
}

#psicochat-floating-panel .psicochat-ai-chat-header {
  flex-shrink: 0;
}

/* Mobile responsive */
@media (max-width: 480px) {
  #psicochat-floating-panel {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }

  #psicochat-floating-panel .psicochat-ai-chat-container {
    border-radius: 0;
    height: 100% !important;
  }

  #psicochat-floating-toggle {
    bottom: 16px;
    right: 16px;
  }
}