/**
 * WP RAG Docs Chatbot - Frontend Widget Stylesheet
 * Rich Aesthetics: Glassmorphism, Micro-animations, Premium Typography
 */

:root {
    --rag-primary: #0f2b5c;
    --rag-accent: #cfa847;
    --rag-bg: #ffffff;
    --rag-text: #1e293b;
    --rag-subtext: #64748b;
    --rag-glass: rgba(255, 255, 255, 0.92);
    --rag-shadow: 0 20px 40px -15px rgba(15, 43, 92, 0.25), 0 0 15px rgba(0, 0, 0, 0.06);
    --rag-radius: 20px;
    --rag-transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#wp-rag-chatbot-root {
    position: fixed;
    bottom: 24px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    box-sizing: border-box;
}

#wp-rag-chatbot-root * {
    box-sizing: border-box;
}

.wp-rag-position-right {
    right: 24px;
}

.wp-rag-position-left {
    left: 24px;
}

/* --- Botón Flotante (Launcher) --- */
.wp-rag-launcher {
    position: relative;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--rag-primary) 0%, #1c499c 100%);
    color: #ffffff;
    border: none;
    box-shadow: 0 8px 24px rgba(15, 43, 92, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--rag-transition);
    outline: none;
}

.wp-rag-launcher:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 28px rgba(15, 43, 92, 0.45);
}

.wp-rag-launcher:active {
    transform: scale(0.95);
}

.wp-rag-launcher-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wp-rag-launcher .icon-close {
    display: none;
}

.wp-rag-launcher.is-active .icon-chat {
    display: none;
}

.wp-rag-launcher.is-active .icon-close {
    display: block;
}

.wp-rag-launcher-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--rag-accent);
    animation: ragPulse 2.4s infinite cubic-bezier(0.25, 1, 0.5, 1);
    pointer-events: none;
}

@keyframes ragPulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

.wp-rag-launcher-tooltip {
    position: absolute;
    bottom: 74px;
    background: #1e293b;
    color: #ffffff;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: var(--rag-transition);
}

.wp-rag-position-right .wp-rag-launcher-tooltip {
    right: 0;
}

.wp-rag-position-left .wp-rag-launcher-tooltip {
    left: 0;
}

.wp-rag-launcher:hover .wp-rag-launcher-tooltip {
    opacity: 1;
    transform: translateY(0);
}

/* --- Ventana de Chat (Glassmorphism & Animaciones) --- */
.wp-rag-window {
    position: absolute;
    bottom: 76px;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 120px);
    background: var(--rag-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--rag-radius);
    box-shadow: var(--rag-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: ragSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.wp-rag-position-left .wp-rag-window {
    left: 0;
    transform-origin: bottom left;
}

.wp-rag-position-right .wp-rag-window {
    right: 0;
    transform-origin: bottom right;
}

@keyframes ragSlideUp {
    0% {
        opacity: 0;
        transform: scale(0.92) translateY(20px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Header */
.wp-rag-header {
    background: linear-gradient(135deg, var(--rag-primary) 0%, #163d7e 100%);
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.wp-rag-header-avatar {
    position: relative;
}

.avatar-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 1.5px solid var(--rag-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
}

.avatar-status-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--rag-primary);
}

.wp-rag-header-text {
    flex: 1;
    overflow: hidden;
}

.wp-rag-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wp-rag-subtitle {
    font-size: 11px;
    color: #cbd5e1;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wp-rag-header-actions {
    display: flex;
    gap: 6px;
}

.btn-action {
    background: transparent;
    border: none;
    color: #cbd5e1;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--rag-transition);
}

.btn-action:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.15);
}

/* Banner */
.wp-rag-banner {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #64748b;
}

.wp-rag-banner svg {
    color: var(--rag-accent);
    flex-shrink: 0;
}

/* Mensajes */
.wp-rag-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.wp-rag-messages::-webkit-scrollbar {
    width: 5px;
}

.wp-rag-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.wp-rag-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
}

.wp-rag-msg-bot {
    align-self: flex-start;
}

.wp-rag-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.wp-rag-msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--rag-primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 4px;
}

.wp-rag-msg-bubble {
    padding: 12px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.wp-rag-msg-bot .wp-rag-msg-bubble {
    background: #f1f5f9;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    border: 1px solid #e2e8f0;
}

.wp-rag-msg-user .wp-rag-msg-bubble {
    background: linear-gradient(135deg, var(--rag-primary) 0%, #1e4ea1 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.wp-rag-msg-content p {
    margin: 0 0 8px 0;
}

.wp-rag-msg-content p:last-child {
    margin-bottom: 0;
}

.wp-rag-msg-content ul, 
.wp-rag-msg-content ol {
    margin: 6px 0;
    padding-left: 18px;
}

.wp-rag-msg-content li {
    margin-bottom: 4px;
}

.wp-rag-msg-time {
    display: block;
    font-size: 9.5px;
    color: #94a3b8;
    margin-top: 4px;
    text-align: right;
}

.wp-rag-msg-user .wp-rag-msg-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Fuentes / Citas */
.wp-rag-sources {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #e2e8f0;
    font-size: 11px;
    color: #64748b;
}

.wp-rag-source-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #e2e8f0;
    color: var(--rag-primary);
    padding: 2px 8px;
    border-radius: 12px;
    margin-top: 4px;
    text-decoration: none;
    font-weight: 500;
    transition: var(--rag-transition);
}

.wp-rag-source-tag:hover {
    background: var(--rag-accent);
    color: #ffffff;
}

/* Preguntas sugeridas */
.wp-rag-prompts-container {
    margin-top: 4px;
}

.prompts-label {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

.prompts-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wp-rag-prompt-chip {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: var(--rag-primary);
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
    transition: var(--rag-transition);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.wp-rag-prompt-chip:hover {
    background: #f8fafc;
    border-color: var(--rag-accent);
    transform: translateX(3px);
}

/* Indicador de tipeo */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Formulario de Entrada */
.wp-rag-input-form {
    padding: 12px 16px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
}

.wp-rag-input-wrapper {
    display: flex;
    align-items: center;
    background: #f1f5f9;
    border-radius: 24px;
    padding: 4px 6px 4px 14px;
    border: 1px solid #e2e8f0;
    transition: var(--rag-transition);
}

.wp-rag-input-wrapper:focus-within {
    background: #ffffff;
    border-color: var(--rag-primary);
    box-shadow: 0 0 0 3px rgba(15, 43, 92, 0.12);
}

.wp-rag-input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 13.5px;
    color: #1e293b;
    padding: 6px 0;
}

.wp-rag-input-wrapper button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--rag-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--rag-transition);
}

.wp-rag-input-wrapper button:hover {
    background: var(--rag-accent);
    transform: scale(1.05);
}

/* Responsividad móvil */
@media (max-width: 480px) {
    #wp-rag-chatbot-root {
        bottom: 16px;
        right: 16px;
        left: 16px;
    }

    .wp-rag-window {
        width: 100%;
        height: calc(100vh - 100px);
        bottom: 70px;
        right: 0;
        left: 0;
        border-radius: 16px;
    }
}
