/* --- 1. RESET & BASICS --- */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --accent: #ec4899;
    --bg-color: #f8fafc;
    --glass-bg: rgba(255, 255, 255, 0.95);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --recording-color: #ef4444;
    --success-color: #10b981; /* Verde esmeralda */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0; padding: 0;
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(236, 72, 153, 0.08) 0%, transparent 20%);
    height: 100dvh;
    width: 100%; 
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- 2. HEADER --- */
#header {
    height: 65px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    background: var(--glass-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.6); z-index: 50; box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo-img { height: 32px; width: auto; display: block; }
.brand-text { font-family: 'Outfit', sans-serif; font-weight: 700; font-size: 18px; color: #1e293b; letter-spacing: -0.5px; }

/* --- 3. CHAT AREA --- */
#chat-container {
    flex-grow: 1; overflow-y: auto; padding: 20px 15px; padding-bottom: 100px;
    display: flex; flex-direction: column; gap: 15px; scroll-behavior: smooth;
}

/* ESTILOS DE MENSAJES */
.message {
    max-width: 88%; padding: 12px 16px; font-size: 15px; line-height: 1.5;
    position: relative; word-wrap: break-word; white-space: pre-wrap;
    opacity: 0; transform: translateY(10px) scale(0.98);
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    transition: all 0.5s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.message.visible { opacity: 1; transform: translateY(0) scale(1); }

.bot { background: #ffffff; color: #334155; border-radius: 18px 18px 18px 4px; border: 1px solid rgba(226, 232, 240, 0.8); }
.user { background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%); color: white; align-self: flex-end; border-radius: 18px 18px 4px 18px; box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25); }
.message b, .message strong { font-weight: 700; color: inherit; }
.bot b { color: var(--primary-dark); }

/* --- ⚡ ANIMACIONES DEL BOT (RENOMBRADAS PARA EVITAR CACHÉ) --- */

/* Estado 1: Procesando */
.message.bot.processing {
    min-width: 60px; min-height: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    background: #fff; border-color: #e2e8f0;
    padding: 0 !important; 
}
.typing-dots { display: flex; gap: 6px; }
.typing-dots .dot {
    width: 8px; height: 8px; background: #94a3b8; border-radius: 50%;
    animation: bounceDots 1.4s infinite ease-in-out both;
}
.typing-dots .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dots .dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounceDots { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* Estado 2: Éxito */
.message.bot.success-state {
    min-width: 60px; min-height: 48px; height: 48px;
    background: #ecfdf5; border-color: #34d399; color: var(--success-color);
    display: flex; align-items: center; justify-content: center;
    padding: 0 !important;
    transform: scale(1.05);
}

/* --- CLASES NUEVAS (V2) PARA FORZAR ACTUALIZACIÓN --- */
.checkmark-svg { width: 32px; height: 32px; display: block; } /* Un poco más grande */

/* Clase RENOMBRADA a -new para saltar la caché */
.checkmark-path-new {
    fill: none; 
    stroke: var(--success-color); 
    stroke-width: 3;
    stroke-linecap: round; 
    stroke-linejoin: round;
    /* Valor alto seguro para cubrir cualquier dibujo */
    stroke-dasharray: 100; 
    stroke-dashoffset: 100;
    /* Animación lenta (1.2s) */
    animation: drawCheckNew 1.2s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

@keyframes drawCheckNew { 
    0% { stroke-dashoffset: 100; }
    100% { stroke-dashoffset: 0; } 
}

/* Estado 3: Texto Final */
.message.bot.final-text {
    background: #ffffff; border-color: rgba(226, 232, 240, 0.8);
    color: #334155; transform: scale(1); 
    height: auto; min-height: auto;
    padding: 12px 16px !important;
}

/* --- 4. INPUT AREA --- */
#input-wrapper {
    position: absolute; bottom: 0; left: 0; width: 100%;
    background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255,255,255,0.6);
    padding: 12px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 8px; z-index: 100;
}
#file-preview {
    display: none; background: #eff6ff; color: var(--primary);
    padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 600;
    border: 1px dashed #bfdbfe; align-self: flex-start; margin-left: 4px;
    animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.input-row { display: flex; align-items: center; gap: 8px; width: 100%; position: relative; }
.icon-btn {
    width: 44px; height: 44px; border-radius: 50%; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s; flex-shrink: 0;
}
.secondary-btn { background: #f1f5f9; color: #64748b; border-radius: 14px; }
.secondary-btn:active { transform: scale(0.9); }
.secondary-btn.active { color: var(--primary); background: #e0e7ff; }
#send-btn { background: linear-gradient(135deg, var(--primary), var(--accent)); color: white; box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3); }
#send-btn:active { transform: scale(0.9); }
#mic-btn { background: #f1f5f9; color: #64748b; }
#mic-btn.recording { background: var(--recording-color); color: white; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); } 70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }
#recording-ui { display: none; flex-grow: 1; align-items: center; gap: 10px; padding-left: 10px; color: var(--recording-color); font-weight: 600; font-size: 16px; }
#message-input { flex-grow: 1; min-width: 0; background: #f1f5f9; border: 1px solid transparent; border-radius: 22px; padding: 12px 16px; font-size: 16px; outline: none; transition: all 0.2s; color: #1e293b; }
#message-input:focus { background: #fff; border-color: var(--primary); }

/* --- 5. AUTH OVERLAY --- */
#auth-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
#auth-overlay.unlocked { opacity: 0; transform: scale(1.1); pointer-events: none; }
.auth-box {
    background: white; padding: 40px 30px; border-radius: 30px;
    box-shadow: 0 20px 60px rgba(99, 102, 241, 0.25);
    text-align: center; width: 85%; max-width: 340px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    position: relative; overflow: hidden; transition: transform 0.2s;
}
.auth-box.error { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}
.auth-box h3 { margin: 10px 0 8px 0; color: #1e293b; font-weight: 800; font-size: 22px; }
.auth-box p { margin: 0 0 25px 0; color: #64748b; font-size: 14px; font-weight: 500; }
#pin-input {
    width: 100%; padding: 16px; font-size: 32px; text-align: center;
    border: 2px solid #e2e8f0; border-radius: 16px; margin-bottom: 20px;
    outline: none; letter-spacing: 8px; font-weight: 800; color: var(--primary);
    background: #f8fafc; transition: all 0.3s ease;
}
#pin-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1); transform: scale(1.02); }
#pin-input.input-error { border-color: #ef4444 !important; color: #ef4444 !important; background: #fef2f2 !important; box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1) !important; }
#auth-btn {
    width: 100%; padding: 18px; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white; border: none; border-radius: 16px; font-weight: 700; font-size: 16px;
    cursor: pointer; transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; gap: 8px;
}
#auth-btn:active { transform: scale(0.94); }
#auth-btn.success { background: #10b981 !important; pointer-events: none; transform: scale(1.05); }

/* Animación Entrada */
body.content-hidden #chat-container, body.content-hidden #input-wrapper, body.content-hidden #header { opacity: 0; transform: translateY(40px); transition: none; }
body.content-visible #chat-container, body.content-visible #input-wrapper, body.content-visible #header { opacity: 1; transform: translateY(0); transition: all 0.8s cubic-bezier(0.34, 1.56, 0.64, 1); }
body.content-visible #header { transition-delay: 0.1s; }
body.content-visible #chat-container { transition-delay: 0.2s; }
body.content-visible #input-wrapper { transition-delay: 0.3s; }