/* ═══════════════════════════════════════════════════════════
   CHAT WIDGET — Asistente IA
   ═══════════════════════════════════════════════════════════ */

#chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
}

/* ─── Toggle Button ───────────────────────────────────────── */

#chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ABF53, #059669);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 24px;
    box-shadow: 0 4px 24px rgba(10, 191, 83, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow .3s;
    position: relative;
    overflow: hidden;
}

#chat-toggle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ABF53, #34D399, #059669, #0ABF53);
    background-size: 300% 300%;
    z-index: -1;
    animation: toggleGlow 4s ease infinite;
    opacity: 0.5;
}

@keyframes toggleGlow {
    0%, 100% { background-position: 0% 50%; opacity: 0.5; }
    50% { background-position: 100% 50%; opacity: 0.8; }
}

#chat-toggle::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ABF53, #059669);
    z-index: -1;
}

#chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 40px rgba(10, 191, 83, 0.45), 0 0 0 3px rgba(10, 191, 83, 0.2);
}

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

#chat-toggle svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
    position: relative;
    z-index: 1;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

#chat-toggle .chat-notification {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #f59e0b;
    border: 2.5px solid #0a0a0f;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
    animation: notifPulse 2s ease-in-out infinite;
    z-index: 2;
}

@keyframes notifPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 12px rgba(245, 158, 11, 0.5); }
    50% { transform: scale(1.15); box-shadow: 0 0 20px rgba(245, 158, 11, 0.7); }
}

/* ─── Chat Panel ──────────────────────────────────────────── */

#chat-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 370px;
    height: 530px;
    background: #0d0d14;
    border: 1px solid rgba(10, 191, 83, 0.12);
    border-radius: 18px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

#chat-panel.open {
    display: flex;
    animation: panelIn 0.2s ease;
}

@keyframes panelIn {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Chat Header ─────────────────────────────────────────── */

#chat-header {
    padding: 16px 18px;
    background: linear-gradient(135deg, rgba(10, 191, 83, 0.1), rgba(52, 211, 153, 0.06));
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

#chat-header .chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ABF53, #34D399);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-header .chat-avatar svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}

#chat-header .chat-title {
    flex: 1;
}

#chat-header .chat-title strong {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: #e8e8f0;
}

#chat-header .chat-title small {
    font-size: 11px;
    color: rgba(232, 232, 240, 0.5);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 1px;
}

#chat-header .chat-title small .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #0ABF53;
    display: inline-block;
    animation: pulse-dot 2s ease-in-out infinite;
}

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

#chat-close {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: rgba(232, 232, 240, 0.5);
    cursor: pointer;
    font-size: 18px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, color .2s;
    flex-shrink: 0;
}

#chat-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #e8e8f0;
}

/* ─── Messages Area ───────────────────────────────────────── */

#chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 4px; }
#chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.15); }

#chat-messages .message {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    animation: msgIn .3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

#chat-messages .message.user {
    background: linear-gradient(135deg, rgba(10, 191, 83, 0.15), rgba(52, 211, 153, 0.08));
    color: #e8e8f0;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    border: 1px solid rgba(10, 191, 83, 0.08);
}

#chat-messages .message.assistant {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(232, 232, 240, 0.92);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

#chat-messages .typing {
    align-self: flex-start;
    padding: 12px 18px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 5px;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

#chat-messages .typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(10, 191, 83, 0.5);
    animation: typing 1.4s ease-in-out infinite;
}

#chat-messages .typing span:nth-child(2) { animation-delay: .2s; background: rgba(52, 211, 153, 0.5); }
#chat-messages .typing span:nth-child(3) { animation-delay: .4s; background: rgba(245, 158, 11, 0.5); }

@keyframes typing {
    0%, 60%, 100% { opacity: .3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-6px); }
}

/* ─── Input Area ──────────────────────────────────────────── */

#chat-input-area {
    padding: 12px 16px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.04);
    color: #e8e8f0;
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    font-size: 13px;
    resize: none;
    outline: none;
    max-height: 80px;
    line-height: 1.4;
    transition: border-color .2s;
}

#chat-input::placeholder {
    color: rgba(232, 232, 240, 0.3);
    font-size: 12.5px;
}

#chat-input:focus {
    border-color: rgba(10, 191, 83, 0.3);
    background: rgba(10, 191, 83, 0.03);
}

#chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ABF53, #34D399);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity .2s, transform .2s;
    box-shadow: 0 2px 12px rgba(10, 191, 83, 0.2);
}

#chat-send:not(:disabled):hover {
    transform: scale(1.08);
}

#chat-send:disabled {
    opacity: .35;
    cursor: default;
    box-shadow: none;
}

/* ─── FAQ Buttons ─────────────────────────────────────────── */

.faq-container {
    padding: 6px 0 2px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    animation: msgIn .35s cubic-bezier(0.4, 0, 0.2, 1);
}

.faq-label {
    font-size: 11.5px;
    color: rgba(232, 232, 240, 0.35);
    margin-bottom: 2px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.faq-btn {
    background: rgba(10, 191, 83, 0.06);
    border: 1px solid rgba(10, 191, 83, 0.12);
    border-radius: 20px;
    padding: 7px 14px;
    color: rgba(232, 232, 240, 0.8);
    font-size: 12.5px;
    cursor: pointer;
    text-align: left;
    transition: all .2s;
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    line-height: 1.4;
}

.faq-btn:hover {
    background: rgba(10, 191, 83, 0.12);
    border-color: rgba(10, 191, 83, 0.25);
    color: #e8e8f0;
    transform: translateX(3px);
}

.faq-btn::before {
    content: '\203A';
    margin-right: 6px;
    color: #0ABF53;
    font-weight: 700;
    font-size: 15px;
}

/* ═══════════════════════════════════════════════════════════
   MÓVIL — Teléfonos y tablets pequeñas
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {

    /* Panel ocupa toda la pantalla como sheet modal */
    #chat-widget {
        bottom: 0;
        right: 0;
        z-index: 10001;
    }

    /* Overlay oscuro detrás del panel */
    #chat-panel.open {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: #0d0d14;
    }

    /* Botón toggle — solo cambia posición, misma apariencia que desktop */
    #chat-toggle {
        position: fixed;
        bottom: 20px;
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        right: 14px;
        z-index: 9999;
    }

    /* Esconder toggle cuando el panel está abierto */
    #chat-widget:has(#chat-panel.open) #chat-toggle {
        display: none;
    }

    /* Header */
    #chat-header {
        padding: 14px 16px;
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
        border-radius: 0;
    }

    #chat-header .chat-avatar {
        width: 36px;
        height: 36px;
    }

    #chat-close {
        width: 36px;
        height: 36px;
        font-size: 22px;
        border-radius: 10px;
    }

    /* Messages */
    #chat-messages {
        padding: 12px 14px;
        gap: 8px;
    }

    #chat-messages .message {
        font-size: 13px;
        padding: 10px 14px;
        max-width: 92%;
    }

    /* Input area — pegado al teclado */
    #chat-input-area {
        padding: 10px 12px 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 12px));
        gap: 8px;
        background: rgba(0, 0, 0, 0.25);
    }

    #chat-input {
        font-size: 16px;
        padding: 10px 14px;
        border-radius: 20px;
    }

    #chat-send {
        width: 42px;
        height: 42px;
        min-width: 42px;
    }

    /* FAQ buttons más grandes */
    .faq-container {
        gap: 6px;
    }

    .faq-btn {
        font-size: 13px;
        padding: 10px 14px;
        min-height: 46px;
        border-radius: 16px;
        display: flex;
        align-items: center;
    }

    .faq-label {
        font-size: 12px;
    }
}

/* ─── Móvil pequeño ─── */
@media (max-width: 400px) {
    #chat-toggle {
        bottom: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        right: 10px;
    }

    #chat-messages .message {
        font-size: 12.5px;
        padding: 8px 12px;
        max-width: 94%;
    }

    #chat-input {
        padding: 8px 12px;
    }

    #chat-send {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }
}
