/* ===========================================================
   WIDGET DE WHATSAPP - Boton flotante y popup de chat
   =========================================================== */

/* Contenedor principal */
.wa-widget {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 9998;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---- Boton flotante (FAB) ---- */
.wa-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #25D366;
    border: none;
    box-shadow: 0 4px 16px rgba(37, 211, 102, 0.45);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.wa-fab:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 24px rgba(37, 211, 102, 0.6);
}

.wa-fab-active {
    background: #128C7E;
}

.wa-fab-close-icon {
    display: none;
}

/* Pulso animado */
.wa-fab::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #25D366;
    z-index: -1;
    animation: waPulse 2s ease-out infinite;
}

.wa-fab-active::after {
    animation: none;
}

@keyframes waPulse {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ---- Burbuja de invitacion ---- */
.wa-bubble {
    position: absolute;
    bottom: 72px;
    left: 0;
    background: #fff;
    border-radius: 12px;
    padding: 12px 36px 12px 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 260px;
    min-width: 200px;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: all 0.3s ease;
    pointer-events: none;
}

.wa-bubble-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.wa-bubble-text {
    font-size: 14px;
    color: #333;
    line-height: 1.4;
}

.wa-bubble-close {
    position: absolute;
    top: 4px;
    right: 8px;
    background: none;
    border: none;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
}

.wa-bubble-close:hover {
    color: #333;
}

/* Flecha de la burbuja apuntando abajo */
.wa-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 26px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #fff;
}

/* ---- Popup de chat ---- */
.wa-popup {
    position: absolute;
    bottom: 72px;
    left: 0;
    width: 340px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    visibility: hidden;
}

.wa-popup-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
}

/* Header del popup */
.wa-popup-header {
    background: #128C7E;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.wa-popup-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wa-popup-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.wa-popup-name {
    color: #fff;
    font-weight: 600;
    font-size: 15px;
}

.wa-popup-status {
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
}

.wa-popup-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.wa-popup-close:hover {
    color: #fff;
}

/* Body del popup */
.wa-popup-body {
    background: #e5ddd5;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='p' width='20' height='20' patternUnits='userSpaceOnUse'%3E%3Ccircle cx='2' cy='2' r='0.8' fill='%23d4cfc4' opacity='0.4'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='100' height='100' fill='url(%23p)'/%3E%3C/svg%3E");
    padding: 16px;
    min-height: 180px;
}

/* Mensaje recibido estilo WhatsApp */
.wa-msg-received {
    background: #fff;
    border-radius: 0 10px 10px 10px;
    padding: 10px 14px;
    max-width: 90%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin-bottom: 12px;
    position: relative;
}

.wa-msg-received p {
    margin: 0 0 6px;
    font-size: 13.5px;
    color: #303030;
    line-height: 1.45;
}

.wa-msg-received p:last-of-type {
    margin-bottom: 2px;
}

.wa-msg-time {
    font-size: 11px;
    color: #999;
    float: right;
    margin-top: 2px;
}

/* Flecha del mensaje */
.wa-msg-received::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-top: 0 solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 8px solid #fff;
}

/* Area de input */
.wa-input-area {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin-top: 12px;
}

.wa-input {
    flex: 1;
    border: none;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    resize: none;
    outline: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    font-family: inherit;
    line-height: 1.4;
    max-height: 80px;
}

.wa-input::placeholder {
    color: #999;
}

.wa-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #25D366;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.wa-send-btn:hover {
    background: #1FAD54;
}

/* ---- Ocultar burbuja de invitacion en pantallas medianas/pequenas ---- */
@media (max-width: 1400px) {
    .wa-bubble {
        display: none !important;
    }
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .wa-widget {
        /* Respetar safe-area de iOS (gesture bar) */
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
        left: 16px;
    }

    .wa-fab {
        width: 52px;
        height: 52px;
    }

    .wa-fab svg {
        width: 26px;
        height: 26px;
    }

    .wa-popup {
        width: calc(100vw - 32px);
        left: 0;
        bottom: calc(max(16px, env(safe-area-inset-bottom, 16px)) + 64px);
    }

    .wa-bubble {
        max-width: calc(100vw - 100px);
    }
}
