/* ============================================================
   ESTEI Lesson Chatbot — CSS Widget
   Asistente IA flotante para páginas de lección LearnPress
   ============================================================ */

:root {
    --estei-chat-primary:     #6c3fc5;
    --estei-chat-primary-dark:#5230a0;
    --estei-chat-secondary:   #f0ebff;
    --estei-chat-bg:          #ffffff;
    --estei-chat-surface:     #f8f7ff;
    --estei-chat-border:      #e8e2f8;
    --estei-chat-text:        #1a1a2e;
    --estei-chat-muted:       #6b7280;
    --estei-chat-user-bg:     #6c3fc5;
    --estei-chat-user-text:   #ffffff;
    --estei-chat-ai-bg:       #f0ebff;
    --estei-chat-ai-text:     #1a1a2e;
    --estei-chat-shadow:      0 8px 32px rgba(108, 63, 197, 0.18), 0 2px 8px rgba(0,0,0,0.08);
    --estei-chat-radius:      18px;
    --estei-chat-z:           99999;
}

/* ── Contenedor raíz ─────────────────────────────────────── */
#estei-chatbot-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--estei-chat-z);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
}

/* ── Botón flotante ──────────────────────────────────────── */
#estei-chat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--estei-chat-primary), #9b59b6);
    border: none;
    cursor: pointer;
    box-shadow: var(--estei-chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), box-shadow 0.3s ease;
    outline: none;
}

#estei-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(108, 63, 197, 0.3);
}

#estei-chat-toggle:active {
    transform: scale(0.95);
}

#estei-chat-toggle.estei-chat-active {
    background: linear-gradient(135deg, #5230a0, #7d3cba);
}

.estei-chat-icon {
    font-size: 26px;
    line-height: 1;
    transition: transform 0.3s ease;
}

/* ── Badge de notificación ───────────────────────────────── */
#estei-chat-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: estei-badge-pulse 2s infinite;
}

@keyframes estei-badge-pulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.15); }
}

/* ── Panel de chat ───────────────────────────────────────── */
#estei-chat-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 360px;
    max-height: 520px;
    background: var(--estei-chat-bg);
    border: 1px solid var(--estei-chat-border);
    border-radius: var(--estei-chat-radius);
    box-shadow: var(--estei-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(.34,1.56,.64,1);
    backdrop-filter: blur(10px);
}

#estei-chat-panel.estei-chat-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Header ──────────────────────────────────────────────── */
#estei-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--estei-chat-primary), #8b52e0);
    color: #fff;
    flex-shrink: 0;
}

.estei-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.estei-chat-avatar {
    width: 38px;
    height: 38px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.estei-chat-title {
    font-weight: 700;
    font-size: 14px;
    line-height: 1.2;
}

.estei-chat-subtitle {
    font-size: 11px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
}

.estei-chat-subtitle::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
    animation: estei-online-pulse 2s infinite;
}

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

#estei-chat-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
    outline: none;
}

#estei-chat-close:hover {
    background: rgba(255,255,255,0.3);
}

/* ── Área de mensajes ────────────────────────────────────── */
#estei-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#estei-chat-messages::-webkit-scrollbar { width: 4px; }
#estei-chat-messages::-webkit-scrollbar-track { background: transparent; }
#estei-chat-messages::-webkit-scrollbar-thumb { background: var(--estei-chat-border); border-radius: 2px; }

/* ── Burbujas ────────────────────────────────────────────── */
.estei-msg {
    display: flex;
    max-width: 85%;
    animation: estei-msg-in 0.3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes estei-msg-in {
    from { opacity: 0; transform: translateY(8px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.estei-msg-user {
    align-self: flex-end;
}

.estei-msg-ai {
    align-self: flex-start;
}

.estei-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.55;
    word-break: break-word;
}

.estei-msg-user .estei-msg-bubble {
    background: var(--estei-chat-user-bg);
    color: var(--estei-chat-user-text);
    border-bottom-right-radius: 4px;
}

.estei-msg-ai .estei-msg-bubble {
    background: var(--estei-chat-ai-bg);
    color: var(--estei-chat-ai-text);
    border-bottom-left-radius: 4px;
}

/* ── Indicador "pensando" ────────────────────────────────── */
#estei-chat-thinking {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--estei-chat-muted);
    font-size: 12px;
    font-style: italic;
    flex-shrink: 0;
}

.estei-thinking-dots {
    display: flex;
    gap: 4px;
}

.estei-thinking-dots span {
    width: 6px;
    height: 6px;
    background: var(--estei-chat-primary);
    border-radius: 50%;
    animation: estei-dot-bounce 1.2s infinite;
}

.estei-thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.estei-thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes estei-dot-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%            { transform: scale(1);   opacity: 1; }
}

/* ── Área de input ───────────────────────────────────────── */
#estei-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--estei-chat-border);
    background: var(--estei-chat-surface);
    flex-shrink: 0;
}

#estei-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--estei-chat-border);
    border-radius: 12px;
    padding: 9px 13px;
    font-size: 13px;
    font-family: inherit;
    color: var(--estei-chat-text);
    background: var(--estei-chat-bg);
    line-height: 1.4;
    min-height: 38px;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s;
}

#estei-chat-input:focus {
    border-color: var(--estei-chat-primary);
    box-shadow: 0 0 0 3px rgba(108, 63, 197, 0.1);
}

#estei-chat-input::placeholder {
    color: var(--estei-chat-muted);
}

#estei-chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#estei-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--estei-chat-primary);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
    outline: none;
}

#estei-chat-send:hover:not(:disabled) {
    background: var(--estei-chat-primary-dark);
    transform: scale(1.08);
}

#estei-chat-send:disabled {
    background: var(--estei-chat-border);
    cursor: not-allowed;
    transform: none;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 480px) {
    #estei-chatbot-widget {
        bottom: 16px;
        right: 16px;
    }

    #estei-chat-panel {
        width: calc(100vw - 32px);
        right: -4px;
        bottom: 68px;
        max-height: 70vh;
    }
}
