/* =========================================================
   Alice Chat — Estilos profesionales
   ========================================================= */

/* ── Reset y base ── */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f0f2f5;
  color: #1f2937;
  font-size: 14px;
  line-height: 1.6;
}

/* ── Shell ── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px 0;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

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

.header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #111827;
}

.header-text p {
  margin: 0;
  font-size: 12px;
  color: #6b7280;
}

/* ── Header right (status + new conversation) ── */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-new-conversation {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: #6b7280;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  min-width: auto;
}

.btn-new-conversation:hover {
  background: #f1f5f9;
  color: #374151;
}

/* ── Status indicator ── */
.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #6b7280;
  cursor: default;
  user-select: none;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.status-dot.loading {
  background: #f59e0b;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.status-dot.error {
  background: #ef4444;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Layout ── */
.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 12px;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  min-height: 0;
}

/* ── Mensajes ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

/* ── Mensaje de bienvenida ── */
.welcome-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  background: #f8faff;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  color: #374151;
  font-size: 14px;
}

.welcome-message p {
  margin: 0;
}

/* ── Burbujas de mensaje ── */
.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.message-user {
  flex-direction: row-reverse;
}

.message-assistant {
  flex-direction: row;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.assistant-avatar {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #ffffff;
}

.message-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.6;
  word-break: break-word;
  font-size: 14px;
}

.message-user .message-bubble {
  background: #2563eb;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
  background: #f3f4f6;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

/* ── Burbuja de error ── */
.message-error .message-bubble {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-bottom-left-radius: 4px;
}

.message-error .message-bubble strong {
  color: #7f1d1d;
}

/* ── Contenido markdown dentro de burbujas ── */
.message-bubble p {
  margin: 0 0 8px;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong {
  font-weight: 700;
}

.message-bubble em {
  font-style: italic;
}

.message-bubble code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12.5px;
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

.message-user .message-bubble code {
  background: rgba(255, 255, 255, 0.2);
}

.message-bubble pre {
  margin: 8px 0;
  border-radius: 8px;
  overflow-x: auto;
  background: #1e293b;
  padding: 12px 14px;
}

.message-bubble pre code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12.5px;
  color: #e2e8f0;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.message-bubble ul,
.message-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.message-bubble li {
  margin-bottom: 3px;
}

.message-bubble a {
  color: #2563eb;
  text-decoration: underline;
}

.message-user .message-bubble a {
  color: #bfdbfe;
}

.message-bubble table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  margin: 8px 0;
}

.message-bubble th,
.message-bubble td {
  border: 1px solid #d1d5db;
  padding: 6px 10px;
  text-align: left;
}

.message-bubble th {
  background: #f9fafb;
  font-weight: 600;
}

/* ── Chips de sugerencia ── */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding-left: 36px; /* alineado con la burbuja, dejando espacio al avatar */
}

.chip {
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 500;
  background: #f0f4ff;
  color: #2563eb;
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  cursor: pointer;
  min-width: auto;
  transition: background 0.15s, border-color 0.15s;
  text-align: left;
  line-height: 1.4;
}

.chip:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

/* ── Typing indicator ── */
.typing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-bottom: 4px;
}

.typing-indicator.hidden {
  display: none !important;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
}

.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: bounce-dot 1.4s ease-in-out infinite;
}

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

@keyframes bounce-dot {
  0%, 80%, 100% {
    transform: translateY(0);
    background: #9ca3af;
  }
  40% {
    transform: translateY(-6px);
    background: #6b7280;
  }
}

/* ── Streaming — cursor parpadeante ── */
.message-bubble.streaming::after {
  content: "▍";
  display: inline-block;
  color: #2563eb;
  animation: blink-cursor 0.8s step-end infinite;
  margin-left: 1px;
  vertical-align: baseline;
  font-size: 0.95em;
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Tool indicator — "Consultando datos…" ── */
.tool-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  margin-left: 36px;
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
}

.tool-indicator.hidden {
  display: none !important;
}

.tool-dots {
  display: flex;
  gap: 3px;
}

.tool-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9ca3af;
  animation: bounce-dot 1.2s ease-in-out infinite;
}

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

/* ── Formulario ── */
.chat-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  flex-shrink: 0;
}

/* ── Context hint (collapsible) ── */
.context-hint-wrapper {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
}

.context-hint-wrapper summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: #6b7280;
  cursor: pointer;
  user-select: none;
  list-style: none;
  background: #f9fafb;
  transition: background 0.15s;
}

.context-hint-wrapper summary::-webkit-details-marker {
  display: none;
}

.context-hint-wrapper summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform 0.2s;
}

.context-hint-wrapper[open] summary::before {
  transform: rotate(90deg);
}

.context-hint-wrapper summary:hover {
  background: #f1f5f9;
}

.optional-tag {
  font-size: 10.5px;
  background: #e5e7eb;
  color: #6b7280;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 500;
  margin-left: auto;
}

.context-hint-wrapper textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 13px;
  border: none;
  border-top: 1px solid #e2e8f0;
  border-radius: 0;
  resize: none;
  font-family: inherit;
  color: #374151;
  background: #ffffff;
  outline: none;
  min-height: 70px;
  display: block;
}

/* ── Input row ── */
.input-row {
  position: relative;
}

.input-row textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  resize: none;
  font-family: inherit;
  color: #1f2937;
  background: #ffffff;
  outline: none;
  line-height: 1.5;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

.input-row textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-row textarea:disabled {
  background: #f9fafb;
  color: #9ca3af;
  cursor: not-allowed;
}

/* ── Actions row ── */
.chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Botones ── */
button {
  padding: 9px 20px;
  font-size: 13.5px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
  line-height: 1;
}

#submitBtn {
  background: #2563eb;
  color: #ffffff;
  min-width: 110px;
}

#submitBtn:hover:not(:disabled) {
  background: #1d4ed8;
}

#submitBtn:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

.btn-cancel {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  min-width: 90px;
}

.btn-cancel:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

/* ── Debug panel ── */
.debug-panel {
  width: 280px;
  flex-shrink: 0;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  align-self: flex-start;
  max-height: calc(100dvh - 100px);
  overflow-y: auto;
}

.debug-panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.debug-panel pre {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11.5px;
  color: #e2e8f0;
  background: #1e293b;
  padding: 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

/* ── Utilidades ── */
.hidden {
  display: none !important;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .app-shell {
    padding: 8px 8px 0;
  }

  .debug-panel {
    display: none;
  }

  .message-bubble {
    max-width: 92%;
  }

  .app-header {
    padding: 10px 12px;
  }
}
