/* =========================================================================
   🏛️ INCOFI — SISTEMA DE DISEÑO BASADO EN PALETA Y LAYOUT DE MIA
   Paleta requerida:
     - #2c1c2f (Fondo Principal Deep Plum)
     - #74242c (Acento Carmesí / Vino Profundo)
     - #c29a82 (Arena Cálido Accent)
     - #91756a (Taupe Arcilla / Bordes)
     - #a494e4 (Lavanda Eléctrico / Acento Primario & Glow)
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #2c1c2f;
  --bg-card: rgba(44, 28, 47, 0.85);
  --bg-input: #1e1321;
  --bg-input-hover: #36223a;
  
  --accent-lavender: #a494e4;
  --accent-crimson: #74242c;
  --accent-sand: #c29a82;
  --accent-taupe: #91756a;
  
  --border-color: rgba(145, 117, 106, 0.35);
  --border-focus: #a494e4;

  --text-primary: #f8fafc;
  --text-secondary: #c29a82;
  --text-placeholder: #91756a;

  --bubble-user-bg: #3d4a5c;
  --bubble-user-gradient: linear-gradient(135deg, #3d4a5c, #2c3746);
  --bubble-user-border: rgba(164, 148, 228, 0.25);
  --bubble-user-shadow: rgba(61, 74, 92, 0.4);
  
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html, body {
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  position: relative;
  background-image: 
    radial-gradient(circle at 50% 30%, rgba(164, 148, 228, 0.08) 0%, transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(116, 36, 44, 0.15) 0%, transparent 50%);
}

/* ── MAIN CONTAINER (FULL-HEIGHT MIA LAYOUT) ─────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  z-index: 10;
}

/* ── CHAT BOX & AVATAR CONTAINER ─────────────────────────────────────── */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
}

#chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  scroll-behavior: smooth;
}

#chat-box::-webkit-scrollbar {
  width: 5px;
}
#chat-box::-webkit-scrollbar-track {
  background: transparent;
}
#chat-box::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 10px;
}

/* ── WELCOME HEADER (se muestra antes del primer mensaje) ──────────── */
.welcome-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 2rem auto 1.5rem auto;
  position: relative;
}

.welcome-ring {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  padding: 4px;
  background: linear-gradient(135deg, var(--accent-lavender), var(--accent-crimson), var(--accent-sand));
  background-size: 200% 200%;
  animation: rotateRing 6s linear infinite, glowPulse 3s ease-in-out infinite alternate;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 25px rgba(164, 148, 228, 0.35);
}

@keyframes rotateRing {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes glowPulse {
  0% { box-shadow: 0 0 15px rgba(164, 148, 228, 0.3); }
  100% { box-shadow: 0 0 35px rgba(116, 36, 44, 0.6); }
}

.welcome-img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bg-primary);
  background-color: var(--bg-input);
}

/* ── THINKING INDICATOR (aparece debajo del mensaje del usuario) ────── */
.msg-row.thinking {
  justify-content: center;
  padding: 1.5rem 0;
}

.thinking-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.thinking-ring {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  padding: 3px;
  background: linear-gradient(135deg, var(--accent-lavender), #7ec8e3, var(--accent-sand), var(--accent-lavender));
  background-size: 300% 300%;
  animation: thinkingSpin 0.8s linear infinite, thinkingGlow 0.6s ease-in-out infinite alternate;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thinking-img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bg-primary);
  background-color: var(--bg-input);
}

.thinking-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  opacity: 0.8;
}

@keyframes thinkingSpin {
  0% { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

@keyframes thinkingGlow {
  0% { box-shadow: 0 0 15px rgba(164, 148, 228, 0.3); }
  100% { box-shadow: 0 0 35px rgba(126, 200, 227, 0.5); }
}

.welcome-title {
  margin-top: 1rem;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-primary);
}

.welcome-subtitle {
  font-size: 0.8rem;
  color: var(--accent-sand);
  margin-top: 4px;
  letter-spacing: 0.5px;
}

/* ── BUBBLES SIN IDENTIFICADOR DE AUTOR (ESTILO MIA) ─────────────────── */
.msg-row {
  display: flex;
  width: 100%;
  animation: fadeIn 0.25s ease;
}

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

.msg-row.user {
  justify-content: flex-end;
}

.msg-row.bot {
  justify-content: flex-start;
}

.bubble {
  max-width: 82%;
  padding: 0.85rem 1.15rem;
  border-radius: 18px;
  font-size: 0.94rem;
  line-height: 1.6;
  word-wrap: break-word;
}

/* Globo Usuario (Gris azulado obscuro elegante) */
.msg-row.user .bubble {
  background: var(--bubble-user-gradient);
  color: #f8fafc;
  border: 1px solid var(--bubble-user-border);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 18px var(--bubble-user-shadow);
}

/* Globo Bot INCOFI (Estilo Dark Card) */
.msg-row.bot .bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Formateo de elementos Markdown dentro de las burbujas */
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  color: var(--accent-sand);
  font-weight: 700;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  line-height: 1.35;
}

.bubble h1 { font-size: 1.15rem; border-bottom: 1px solid var(--border-color); padding-bottom: 4px; }
.bubble h2 { font-size: 1.08rem; color: var(--accent-lavender); }
.bubble h3 { font-size: 1.02rem; color: var(--accent-sand); }
.bubble h4 { font-size: 0.96rem; color: var(--text-primary); }

.bubble p {
  margin-bottom: 0.6rem;
}

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

.bubble strong {
  color: #ffffff;
  font-weight: 600;
}

.bubble em {
  color: var(--accent-sand);
  font-style: italic;
}

.bubble ul, .bubble ol {
  margin: 0.5rem 0 0.75rem 1.25rem;
  padding-left: 0.5rem;
}

.bubble li {
  margin-bottom: 0.35rem;
  line-height: 1.5;
}

.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.88rem;
}

.bubble th, .bubble td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  text-align: left;
}

.bubble th {
  background: rgba(164, 148, 228, 0.15);
  color: var(--accent-lavender);
  font-weight: 600;
}

.bubble td {
  background: rgba(30, 19, 33, 0.4);
}

.legal-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(164, 148, 228, 0.15);
  color: var(--accent-lavender);
  border: 1px solid rgba(164, 148, 228, 0.3);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
}

.file-preview-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(116, 36, 44, 0.3);
  border: 1px solid var(--accent-crimson);
  color: var(--accent-sand);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  margin-bottom: 8px;
}

/* ── INPUT BAR (MIA BOTTOM BAR FIX) ─────────────────────────────────── */
.input-bar-container {
  padding: 0.75rem 1rem 1rem 1rem;
  background: linear-gradient(to top, var(--bg-primary) 80%, transparent);
  position: relative;
  z-index: 20;
}

.input-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.incofi-textarea {
  width: 100%;
  min-height: 48px;
  max-height: 140px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 12px 130px 12px 18px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  resize: none;
  outline: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.incofi-textarea:focus {
  border-color: var(--accent-lavender);
  box-shadow: 0 0 15px rgba(164, 148, 228, 0.2);
}

.incofi-textarea::placeholder {
  color: var(--text-placeholder);
}

.input-actions {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 30;
}

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  color: var(--accent-lavender);
  background: var(--bg-input-hover);
}

.action-btn.recording {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
  animation: pulse-rec 1.2s infinite;
}

@keyframes pulse-rec {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.btn-send {
  background: linear-gradient(135deg, var(--accent-lavender), #8b7ad8);
  color: #ffffff;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(164, 148, 228, 0.4);
  transition: all 0.2s ease;
}

.btn-send:hover {
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(164, 148, 228, 0.6);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
