/* ==============================================
   PETCIMAGENES AGENTKIT - ESTILO CLAUDE CODE
   V3 - Diseño profesional inspirado en Claude
   ============================================== */

:root {
  --bg-main: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-chat: #fafafa;
  --text-primary: #1f1f1f;
  --text-secondary: #6b6b6b;
  --border-subtle: #e8e8e8;

  /* Colores corporativos imagemIA */
  --accent: #8B5CF6;
  --accent-hover: #7C3AED;
  --accent-light: #A78BFA;
  --cyan: #22D3EE;
  --cyan-hover: #06B6D4;

  --success: #10b981;
  --error: #ef4444;
  --sidebar-width: 260px;
  --max-content-width: 800px;
  --message-spacing: 32px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
               "Oxygen", "Ubuntu", "Cantarell", sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* Logo en sidebar - CENTRADO */
.sidebar-logo {
  padding: 20px 16px 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: 20px;
  font-weight: 700;
  color: #1f1f1f;
  letter-spacing: -0.5px;
}

.new-chat-btn {
  width: 100%;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--cyan) 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
}

.new-chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.conversations {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversations ul {
  list-style: none;
}

.conversation-item {
  padding: 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  position: relative;
}

.conversation-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.conversation-item.active {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.08) 0%, rgba(34, 211, 238, 0.08) 100%);
  border-left: 3px solid var(--accent);
  box-shadow: 0 1px 3px rgba(139, 92, 246, 0.15);
}

.conversation-actions {
  display: none;
  position: relative;
}

.conversation-item:hover .conversation-actions {
  display: block;
}

.conversation-menu-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 18px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.2s;
}

.conversation-menu-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
}

.conversation-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  background: white;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 160px;
  z-index: 100;
  display: none;
  margin-top: 4px;
}

.conversation-dropdown.show {
  display: block;
}

.conversation-dropdown button {
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.conversation-dropdown button:hover {
  background: var(--bg-secondary);
}

.conversation-dropdown button:first-child {
  border-radius: 8px 8px 0 0;
}

.conversation-dropdown button:last-child {
  border-radius: 0 0 8px 8px;
}

.conversation-dropdown button.danger {
  color: var(--error);
}

.conversation-dropdown button.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.sidebar-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 16px;
  flex-shrink: 0;
}

.upload-kb-btn {
  width: 100%;
  padding: 12px 16px;
  background: white;
  color: var(--text-primary);
  border: 2px solid var(--cyan);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.kb-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.upload-kb-btn:hover {
  background: var(--cyan);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(34, 211, 238, 0.3);
}

.upload-kb-btn:hover .kb-icon {
  filter: brightness(1.2) drop-shadow(0 2px 4px rgba(255, 255, 255, 0.3));
}

.user-info {
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

/* ===== MAIN CHAT AREA - MAXIMIZADA ===== */
.main-chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-chat);
}

.chat-header {
  height: 72px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--bg-main);
  flex-shrink: 0;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-company-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 6px;
}

.header-agent-text {
  font-size: 24px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent) 0%, var(--cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
  transition: all 0.3s ease;
}

.header-agent-text:hover {
  transform: translateY(-1px);
  filter: drop-shadow(0 2px 4px rgba(139, 92, 246, 0.3));
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.toggle-sidebar {
  display: none;
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  padding: 12px;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  border-radius: 8px;
}

.toggle-sidebar:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ===== AREA DE MENSAJES - 80% DEL VIEWPORT ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  scroll-behavior: smooth;
}

/* ===== MENSAJES ESTILO CLAUDE ===== */
.message {
  width: 100%;
  padding: var(--message-spacing) 0;
}

.message.user {
  background: var(--bg-main);
}

.message.assistant {
  background: var(--bg-chat);
}

.message.system {
  background: transparent;
  border-bottom: none;
  padding: 16px 0;
  display: flex;
  justify-content: center;
}

.message-content {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 0 32px;
  width: 100%;
}

.message.system .message-content {
  background: #f0f0f0;
  color: #666;
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 13px;
  max-width: 60%;
  text-align: center;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.message-role {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.message-time {
  font-size: 12px;
  color: var(--text-secondary);
}

.message-text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  word-wrap: break-word;
}

/* Mensajes de usuario - burbuja */
.message.user .message-content {
  display: flex;
  justify-content: flex-end;
}

.message.user .message-text {
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--cyan) 100%);
  color: white;
  border-radius: 18px;
  display: inline-block;
  max-width: 80%;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.25);
}

/* Mensajes del asistente - texto justificado */
.message.assistant .message-text {
  text-align: justify;
}

/* Markdown en mensajes */
.message-text p {
  margin-bottom: 12px;
}

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

.message-text a {
  color: #2563eb;
  text-decoration: none;
  border-bottom: 1px solid #2563eb;
  transition: all 0.2s;
}

.message-text a:hover {
  background: #eff6ff;
  border-bottom-color: transparent;
}

.message-text code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.message-text pre {
  background: #1f1f1f;
  color: #f0f0f0;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
}

.message-text pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.message-text ul, .message-text ol {
  margin-left: 24px;
  margin-bottom: 12px;
}

.message-text li {
  margin-bottom: 6px;
}

/* ===== INDICADOR DE ESCRITURA ===== */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* ===== INPUT AREA - ESTILO CLAUDE ===== */
.input-area {
  padding: 24px 32px 32px;
  background: var(--bg-main);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

#chat-form {
  max-width: var(--max-content-width);
  margin: 0 auto;
}

.attached-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.attached-file {
  background: white;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.attached-file button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  transition: color 0.2s;
}

.attached-file button:hover {
  color: var(--error);
}

.input-wrapper {
  background: var(--bg-secondary);
  border: 2px solid var(--border-subtle);
  border-radius: 24px;
  padding: 8px 12px 8px 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.attach-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  color: var(--text-secondary);
  transition: all 0.2s;
  flex-shrink: 0;
}

.attach-btn:hover {
  color: var(--cyan);
  transform: scale(1.1);
}

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 15px;
  line-height: 1.6;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  max-height: 300px;
  min-height: 24px;
  padding: 8px 0;
}

#message-input::placeholder {
  color: var(--text-secondary);
}

.send-btn {
  background: linear-gradient(135deg, var(--accent) 0%, var(--cyan) 100%);
  border: none;
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(139, 92, 246, 0.3);
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.send-btn:disabled {
  background: var(--border-subtle);
  cursor: not-allowed;
  opacity: 0.5;
}

/* ===== SCROLLBAR PERSONALIZADO ===== */
.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #c8c8c8;
}

.conversations::-webkit-scrollbar {
  width: 6px;
}

.conversations::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 16px;
  padding: 32px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
  margin-bottom: 8px;
  font-size: 20px;
}

.modal-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.upload-zone {
  border: 2px dashed var(--border-subtle);
  border-radius: 12px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 16px;
}

.upload-zone:hover {
  border-color: var(--cyan);
  background: rgba(34, 211, 238, 0.05);
}

.upload-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.file-list {
  margin: 16px 0;
  max-height: 200px;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

.btn-primary, .btn-secondary {
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--cyan) 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
}

.btn-secondary {
  background: white;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    width: 80%;
    height: 100vh;
    z-index: 1000;
    transition: left 0.3s;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.1);
  }

  .sidebar.visible {
    left: 0;
  }

  /* Limitar conversaciones para mostrar botón almacén */
  .conversations {
    max-height: calc(100vh - 320px); /* Espacio para header + footer + botón almacén */
    overflow-y: auto;
  }

  .sidebar-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-secondary);
    z-index: 10;
  }

  .toggle-sidebar {
    display: block;
  }

  /* Ajustar altura de main-chat para móvil */
  .main-chat {
    height: 100dvh; /* dvh = dynamic viewport height, se ajusta cuando aparecen/desaparecen barras */
  }

  .chat-header {
    padding: 0 16px;
    height: 60px; /* Reducir altura en móvil */
    flex-shrink: 0;
  }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 100px; /* Espacio para input fijo */
  }

  .input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-main);
    border-top: 1px solid var(--border-subtle);
    z-index: 100;
  }

  .message-content {
    padding: 0 16px;
  }

  .header-logo-full {
    height: 50px;
  }

  .header-agent-text {
    font-size: 24px;
  }

  .header-title {
    gap: 12px;
  }

  #chat-form {
    padding: 0;
  }

  .message.user .message-text {
    max-width: 90%;
  }
}

/* ===== ANIMACIONES ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message {
  animation: fadeIn 0.3s ease-out;
}

/* ===== ESTADOS DE CARGA ===== */
.loading {
  pointer-events: none;
  opacity: 0.6;
}

.processing .message-text {
  color: var(--text-secondary);
}
