/* =============================================
   WhatsApp Button – Guidev v3.6
   ============================================= */

#wa-float-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2147483647; /* máximo posible */
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
}

#wa-float-container.right {
    right: 20px;
    left: auto;
    align-items: flex-end;
}

#wa-float-container.left {
    left: 20px;
    right: auto;
    align-items: flex-start;
}

/* ── Botón flotante ── */
#wa-float-button {
    background-color: #25d366;
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    font-size: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#wa-float-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

#wa-float-button.wa-icon-button {
    background-color: #25d366;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* ── Caja del formulario (escritorio) ── */
#wa-form-box {
    display: none;
    flex-direction: column;
    background: white;
    margin-bottom: 10px;
    border-radius: 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
    /* FIX: ancho adaptable para pantallas intermedias */
    width: min(320px, calc(100vw - 40px));
    /* FIX: altura máxima relativa a la pantalla con margen para que no toque el botón */
    max-height: min(80vh, calc(100vh - 100px));
    overflow: hidden; /* el scroll lo maneja el form interno */
    animation: waFadeInUp 0.35s ease forwards;
    z-index: 2147483647;
}

#wa-form-box.show {
    display: flex !important;
}

@keyframes waFadeInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ── Header ── */
#wa-header {
    background: #25d366;
    color: white;
    padding: 14px 16px;
    font-weight: bold;
    font-size: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 14px 14px 0 0;
    flex-shrink: 0;
}

#wa-close-button {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

/* ── Globo de recordatorio ── */
#wa-reminder-balloon {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 10px 12px 0 12px;
    font-size: 12px;
    color: #5d4037;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    line-height: 1.4;
    flex-shrink: 0;
}

#wa-reminder-balloon .wa-balloon-icon {
    font-size: 15px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* ── Alerta de filtro de piano ── */
#wa-piano-warning {
    display: none;
    background: #fdecea;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    padding: 10px 14px;
    margin: 0; /* vive dentro del form, el gap lo separa */
    font-size: 13px;
    color: #721c24;
    line-height: 1.5;
    flex-shrink: 0;
}

/* ── Formulario ── */
#wa-form-box form {
    padding: 12px 15px 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#wa-form-box label {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: -4px;
}

#wa-form-box input,
#wa-form-box textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-sizing: border-box;
    font-size: 14px;
    color: #333;
    background: #fafafa;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

#wa-form-box input:focus,
#wa-form-box textarea:focus {
    border-color: #25d366;
    outline: none;
    background: #fff;
}

#wa-form-box textarea {
    resize: none;
}

#wa-form-box button[type="submit"] {
    background: #25d366;
    color: white;
    padding: 12px;
    padding-bottom: 50px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 15px;
    transition: background 0.2s ease;
    min-height: 44px;
    flex-shrink: 0;
}

#wa-form-box button[type="submit"]:hover {
    background: #1ebe5d;
}

#wa-form-box button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Grupo de teléfono ── */
.wa-phone-group {
    display: flex;
}

.wa-phone-prefix {
    background: #eee;
    border: 1px solid #ddd;
    border-right: none;
    padding: 10px 12px;
    border-radius: 8px 0 0 8px;
    font-size: 14px;
    color: #555;
    white-space: nowrap;
    display: flex;
    align-items: center;
}

.wa-phone-input {
    border-radius: 0 8px 8px 0 !important;
    border-left: none !important;
    flex: 1;
}

/* ── reCAPTCHA ── */
.grecaptcha-badge {
    visibility: hidden;
}

/* ── FIX: z-index del mobile tab bar ─────────────────────────────────────────
   Cuando el formulario está abierto (.show), forzamos al tab bar a quedar
   por debajo. Usamos !important porque el tab bar normalmente declara
   su z-index inline o en otro stylesheet con alta especificidad.
   ─────────────────────────────────────────────────────────────────────────── */
body:has(#wa-form-box.show) #page-mobile-tabs,
body:has(#wa-form-box.show) .page-mobile-tabs {
    z-index: 0 !important;
    position: relative !important; /* quiebra el stacking context propio */
}

/* Fallback para navegadores sin :has() (Firefox < 121) */
#page-mobile-tabs.wa-behind,
.page-mobile-tabs.wa-behind {
    z-index: 0 !important;
    position: relative !important;
}

/* =============================================
   PANTALLAS INTERMEDIAS (768px – 1024px)
   Evita que el formulario quede demasiado
   grande o cortado en laptops pequeñas.
   ============================================= */
@media (min-width: 768px) and (max-width: 1024px) {
    #wa-form-box {
        width: min(300px, calc(100vw - 40px));
        max-height: min(75vh, calc(100vh - 100px));
        font-size: 14px;
    }
}

/* =============================================
   MÓVIL — diseño de panel completo
   ============================================= */
@media (max-width: 767px) {

    /* Evitar zoom en inputs iOS */
    #wa-form-box input,
    #wa-form-box textarea,
    #wa-form-box select {
        font-size: 16px !important;
    }

    /* El contenedor flotante se ancla abajo centrado */
    #wa-float-container,
    #wa-float-container.right,
    #wa-float-container.left {
        bottom: 16px;
        right: 16px;
        left: auto;
        align-items: flex-end;
    }

    #wa-float-container.left {
        right: auto;
        left: 16px;
        align-items: flex-start;
    }

    /* Panel de formulario: ocupa exactamente el viewport visible */
    #wa-form-box {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: 0;
        width: 100%;

        height: 100dvh;
        height: 100svh; /* fallback Safari */
        max-height: 100dvh;
        max-height: 100svh;

        border-radius: 0;
        margin: 0;
        box-shadow: none;
        z-index: 2147483647;
        animation: none;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex !important;
        flex-direction: column;
        opacity: 1;
        overflow: hidden;
        visibility: hidden;
    }

    #wa-form-box.show {
        transform: translateY(0) !important;
        visibility: visible;
    }

    #wa-form-box:not(.show) {
        pointer-events: none;
    }

    /* Header fijo arriba, respeta notch/isla dinámica */
    #wa-header {
        border-radius: 0;
        padding: 14px 20px;
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
        font-size: 17px;
        flex-shrink: 0;
    }

    #wa-close-button {
        font-size: 24px;
        padding: 0 2px;
    }

    /* Zona de contenido: sin colapso */
    #wa-form-box > *:not(#wa-header) {
        flex-shrink: 0;
    }

    /* El form crece y hace scroll si hace falta */
    #wa-form-box form {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px 20px;
        /* FIX: padding inferior que respeta barra de gestos Y asegura
           que el botón Enviar no quede cortado */
        padding-bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px));
        gap: 12px;
    }

    /* Recordatorio y aviso */
    #wa-reminder-balloon {
        margin: 12px 20px 0 20px;
        font-size: 13px;
    }

    #wa-piano-warning {
        margin: 0;
        font-size: 14px;
    }

    #wa-form-box label {
        font-size: 14px;
    }

    #wa-form-box input,
    #wa-form-box textarea {
        padding: 13px 14px;
        border-radius: 10px;
    }

    /* FIX: Botón Enviar — padding vertical simétrico y safe-area correcta */
    #wa-form-box button[type="submit"] {
        padding: 15px 15px;
        font-size: 16px;
        border-radius: 10px;
        margin-top: 6px;
        /* Garantizamos que el botón tenga altura visible mínima */
        min-height: 52px;
        /* El margen inferior empuja el botón sobre la barra de gestos */
        margin-bottom: env(safe-area-inset-bottom, 8px);
    }

    .wa-phone-prefix {
        padding: 13px 14px;
        font-size: 16px;
    }
}