/**
 * AI Page Styles
 * Centro IA - Chat interface with sidebar
 */

.ai-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--surface);
}

.ai-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============= SIDEBAR ============= */

.ai-sidebar {
  width: 280px;
  background: #f9fafb;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ai-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.ai-sidebar-header h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-primary);
  font-weight: 600;
}

.icon-button {
  background: none;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 150ms ease;
}

.icon-button:hover {
  background: #e5e7eb;
  border-color: var(--brand);
}

.ai-conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-conversations-list .placeholder {
  padding: 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin: auto;
}

.ai-conversation-item {
  padding: 12px;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  transition: all 150ms ease;
  border-left: 3px solid transparent;
  overflow: hidden;
}

.ai-conversation-item:hover {
  background: #f3f4f6;
  border-left-color: var(--brand);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.ai-conv-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-conv-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ============= CHAT MAIN ============= */

.ai-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  overflow: hidden;
}

/* Header */

.ai-chat-header {
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--brand) 0%, #2d6e5f 100%);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.ai-header-content h2 {
  margin: 0 0 4px 0;
  font-size: 1.3rem;
  font-weight: 600;
}

.ai-subtitle {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
}

.ai-header-info {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ai-source-badge {
  background: rgba(255,255,255,0.2);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}

/* Messages */

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-welcome {
  text-align: center;
  padding: 32px 24px;
  margin: auto;
}

.ai-welcome-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

.ai-welcome h3 {
  margin: 0 0 12px 0;
  font-size: 1.3rem;
  color: var(--text-primary);
}

.ai-welcome p {
  margin: 8px 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.ai-welcome-note {
  font-size: 0.85rem;
  color: var(--brand);
  font-weight: 500;
  margin-top: 12px;
}

/* Suggested Questions */

.ai-suggested-questions {
  margin: 16px 0;
}

.suggested-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}

.suggested-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.suggested-question-btn {
  padding: 12px 14px;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f7ff 100%);
  border: 1px solid #a8d8ff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--brand);
  font-weight: 500;
  transition: all 150ms ease;
  text-align: left;
  line-height: 1.4;
}

.suggested-question-btn:hover {
  background: linear-gradient(135deg, var(--brand-faint) 0%, #d6f1e8 100%);
  border-color: var(--brand);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(24,74,58,0.1);
}

/* Messages */

.ai-message {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  animation: slideIn 300ms ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-user-message {
  align-items: flex-end;
}

.ai-user-message .ai-message-content {
  background: var(--brand);
  color: white;
  border-radius: 12px 12px 4px 12px;
  max-width: 70%;
}

.ai-bot-message {
  align-items: flex-start;
}

.ai-bot-message .ai-message-content {
  background: #f3f4f6;
  color: var(--text-primary);
  border-radius: 12px 12px 12px 4px;
  max-width: 85%;
}

.ai-message-content {
  padding: 12px 14px;
  word-wrap: break-word;
}

.ai-message-content p {
  margin: 0 0 8px 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

.ai-message-content p:last-child {
  margin-bottom: 0;
}

.ai-message time {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
  padding: 0 4px;
}

/* Error message */

.ai-error .ai-message-content {
  background: #fee;
  color: #c33;
}

/* Typing indicator */

.ai-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.ai-typing-dots span {
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.ai-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.5;
  }
  30% {
    opacity: 1;
  }
}

/* Sources */

.ai-sources {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #e5e7eb;
}

.sources-title {
  margin: 0 0 12px 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.source-group {
  margin-bottom: 16px;
}

.source-group h4 {
  margin: 0 0 8px 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brand);
}

.source-item {
  padding: 10px;
  background: white;
  border-left: 3px solid var(--brand-faint);
  border-radius: 4px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.source-title {
  margin: 0 0 4px 0;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.source-desc {
  margin: 4px 0;
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.4;
}

.source-meta {
  margin: 4px 0;
  color: #6b7280;
  font-size: 0.8rem;
  font-weight: 500;
}

.source-author {
  margin: 4px 0 0 0;
  color: #9ca3af;
  font-size: 0.75rem;
  font-style: italic;
}

.source-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
  transition: color 150ms ease;
}

.source-link:hover {
  color: #0f766e;
}

.sources-empty {
  padding: 8px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-style: italic;
}

/* Footer */

.ai-chat-footer {
  padding: 16px 24px;
  background: white;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.ai-chat-input-form {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.ai-chat-input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 150ms ease;
}

.ai-chat-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(24,74,58,0.1);
  background: white;
}

.ai-send-button {
  padding: 12px 20px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.ai-send-button:hover:not(:disabled) {
  background: #0f766e;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(24,74,58,0.2);
}

.ai-send-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ai-input-help {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ============= RESPONSIVE ============= */

@media (max-width: 1024px) {
  .ai-sidebar {
    width: 240px;
  }

  .ai-chat-header {
    padding: 16px;
  }

  .ai-header-content h2 {
    font-size: 1.1rem;
  }

  .ai-subtitle {
    font-size: 0.85rem;
  }

  .ai-chat-messages {
    padding: 16px;
  }

  .suggested-buttons {
    grid-template-columns: 1fr;
  }

  .ai-user-message .ai-message-content {
    max-width: 80%;
  }

  .ai-bot-message .ai-message-content {
    max-width: 95%;
  }
}

@media (max-width: 768px) {
  .ai-container {
    flex-direction: column;
  }

  .ai-sidebar {
    width: 100%;
    height: auto;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid #e5e7eb;
    flex-direction: row;
  }

  .ai-sidebar-header {
    padding: 12px 16px;
    border-bottom: none;
    border-right: 1px solid #e5e7eb;
  }

  .ai-conversations-list {
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 12px;
  }

  .ai-conversation-item {
    min-width: 150px;
    flex-shrink: 0;
  }

  .ai-chat-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
  }

  .ai-header-info {
    width: 100%;
    justify-content: flex-end;
  }

  .ai-header-content h2 {
    font-size: 1rem;
  }

  .ai-chat-messages {
    padding: 12px;
    gap: 12px;
  }

  .ai-user-message .ai-message-content {
    max-width: 85%;
  }

  .ai-bot-message .ai-message-content {
    max-width: 100%;
  }

  .ai-chat-footer {
    padding: 12px;
  }

  .ai-input-help {
    font-size: 0.75rem;
  }
}

@media (max-width: 480px) {
  .ai-sidebar {
    max-height: 150px;
  }

  .ai-sidebar-header {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .ai-chat-header {
    padding: 10px 12px;
  }

  .ai-header-content h2 {
    font-size: 0.95rem;
  }

  .ai-subtitle {
    font-size: 0.8rem;
  }

  .ai-source-badge {
    font-size: 0.75rem;
    padding: 4px 8px;
  }

  .ai-chat-messages {
    padding: 10px;
  }

  .ai-welcome {
    padding: 20px 12px;
  }

  .ai-welcome-icon {
    font-size: 2rem;
  }

  .ai-welcome h3 {
    font-size: 1.1rem;
  }

  .ai-welcome p {
    font-size: 0.85rem;
  }

  .suggested-buttons {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .suggested-question-btn {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .ai-message-content {
    padding: 10px 12px;
  }

  .ai-message-content p {
    font-size: 0.9rem;
  }

  .ai-chat-input-form {
    gap: 8px;
  }

  .ai-chat-input {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .ai-send-button {
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .source-item {
    padding: 8px;
  }

  .source-title {
    font-size: 0.8rem;
  }

  .source-desc {
    font-size: 0.75rem;
  }
}

/* Scrollbar */
.ai-conversations-list::-webkit-scrollbar,
.ai-chat-messages::-webkit-scrollbar {
  width: 8px;
}

.ai-conversations-list::-webkit-scrollbar-track,
.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-conversations-list::-webkit-scrollbar-thumb,
.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.ai-conversations-list::-webkit-scrollbar-thumb:hover,
.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}
