/* ════════════════════════════════════════════════════════════════════════════
   WhatsApp Gravity Connector — Frontend CSS
   ════════════════════════════════════════════════════════════════════════════ */

/* Variables CSS (sobreescritas inline según configuración del admin) */
:root {
    --wgc-color:       #25D366;
    --wgc-color-dark:  #128C7E;
    --wgc-size:        60px;
    --wgc-radius:      16px;
    --wgc-z:           9999;
    --wgc-shadow:      0 4px 20px rgba(0,0,0,0.25);
    --wgc-font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    --wgc-transition:  0.25s cubic-bezier(0.4, 0, 0.2, 1);
}


/* ─── Wrapper ──────────────────────────────────────────────────────────────── */

#wgc-wrapper {
    position: fixed;
    z-index: var(--wgc-z);
    font-family: var(--wgc-font);
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

/* ── Posiciones: esquinas ── */
.wgc-position-bottom-right { bottom: 24px; right: 24px; align-items: flex-end; }
.wgc-position-bottom-left  { bottom: 24px; left: 24px;  align-items: flex-start; }

/* ── Posiciones: centro lateral (mitad vertical de la pantalla) ── */
.wgc-position-right-center {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    align-items: flex-end;
}
.wgc-position-left-center {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    align-items: flex-start;
}

/* Botón con borde redondeado solo en el lado interior cuando está en el borde */
.wgc-position-right-center .wgc-float-btn {
    border-radius: 50% 0 0 50%;
    width: calc(var(--wgc-size) * 0.85);
    min-width: calc(var(--wgc-size) * 0.85);
}
.wgc-position-left-center .wgc-float-btn {
    border-radius: 0 50% 50% 0;
    width: calc(var(--wgc-size) * 0.85);
    min-width: calc(var(--wgc-size) * 0.85);
}

/* Tooltip para posiciones laterales */
.wgc-position-right-center .wgc-tooltip {
    bottom: auto;
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
}
.wgc-position-right-center .wgc-tooltip::after {
    top: 50%;
    right: -12px;
    left: auto;
    transform: translateY(-50%) rotate(-90deg);
    border-top-color: transparent;
    border-left-color: rgba(30, 30, 30, 0.92);
}
.wgc-position-left-center .wgc-tooltip {
    bottom: auto;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
}
.wgc-position-left-center .wgc-tooltip::after {
    top: 50%;
    left: -12px;
    right: auto;
    transform: translateY(-50%) rotate(90deg);
    border-top-color: transparent;
    border-right-color: rgba(30, 30, 30, 0.92);
}

/* Ocultar en mobile si está configurado */
@media (max-width: 768px) {
    .wgc-hide-mobile { display: none !important; }
}


/* ─── Botón flotante ────────────────────────────────────────────────────────── */

.wgc-float-btn {
    width: var(--wgc-size);
    height: var(--wgc-size);
    min-width: var(--wgc-size);
    border-radius: 50%;
    background-color: var(--wgc-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--wgc-shadow);
    transition: transform var(--wgc-transition), box-shadow var(--wgc-transition);
    position: relative;
    z-index: 1;
    padding: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.wgc-float-btn svg {
    width: 52%;
    height: 52%;
    display: block;
    pointer-events: none;
}

.wgc-float-btn:hover,
.wgc-float-btn:focus-visible {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0,0,0,0.35);
    outline: 3px solid rgba(255,255,255,0.6);
    outline-offset: 2px;
}

.wgc-float-btn:active { transform: scale(0.96); }

/* Estado "abierto" del botón */
.wgc-float-btn[aria-expanded="true"] {
    transform: rotate(0deg) scale(1.05);
}


/* ─── Animaciones del botón ─────────────────────────────────────────────────── */

@keyframes wgc-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.55); }
    65%  { box-shadow: 0 0 0 16px rgba(37, 211, 102, 0); }
    100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}

@keyframes wgc-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-12px); }
}

@keyframes wgc-shake {
    0%, 100% { transform: rotate(0deg); }
    15%       { transform: rotate(-12deg); }
    30%       { transform: rotate(10deg); }
    45%       { transform: rotate(-8deg); }
    60%       { transform: rotate(6deg); }
    75%       { transform: rotate(-4deg); }
}

.wgc-anim-pulse  .wgc-float-btn { animation: wgc-pulse  2.2s ease-in-out infinite; }
.wgc-anim-bounce .wgc-float-btn { animation: wgc-bounce 2s   ease-in-out infinite; }
.wgc-anim-shake  .wgc-float-btn { animation: wgc-shake  2.5s ease-in-out infinite; }

/* Pausar animaciones cuando el panel está abierto */
.wgc-panel-open .wgc-float-btn { animation: none !important; }


/* ─── Tooltip ───────────────────────────────────────────────────────────────── */

.wgc-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    background: rgba(30, 30, 30, 0.92);
    color: #fff;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity var(--wgc-transition), transform var(--wgc-transition);
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* Flechita del tooltip */
.wgc-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    border: 6px solid transparent;
    border-top-color: rgba(30, 30, 30, 0.92);
}

.wgc-position-bottom-right .wgc-tooltip         { right: 0; }
.wgc-position-bottom-right .wgc-tooltip::after  { right: calc(var(--wgc-size)/2 - 6px); }
.wgc-position-bottom-left  .wgc-tooltip         { left: 0; }
.wgc-position-bottom-left  .wgc-tooltip::after  { left: calc(var(--wgc-size)/2 - 6px); }

#wgc-wrapper:hover .wgc-tooltip,
.wgc-float-btn:focus-visible ~ .wgc-tooltip {
    opacity: 1;
    transform: translateY(0);
}


/* ─── Overlay (fondo oscuro) ────────────────────────────────────────────────── */

.wgc-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: calc(var(--wgc-z) + 1);
    opacity: 0;
    transition: opacity var(--wgc-transition);
}

.wgc-panel--modal .wgc-overlay { display: block; }
.wgc-overlay.wgc-overlay--visible { opacity: 1; }


/* ─── Panel (contenedor del popup/sidebar) ──────────────────────────────────── */
/* #wgc-panel se renderiza FUERA de #wgc-wrapper (directo en <body>)
   para que position:fixed se calcule correctamente contra el viewport */

#wgc-panel {
    position: fixed;
    inset: 0;
    z-index: calc(var(--wgc-z) + 1);
    pointer-events: none;
}

#wgc-panel[aria-hidden="false"] {
    pointer-events: auto;
}


/* ─── Panel Box ─────────────────────────────────────────────────────────────── */

.wgc-panel-box {
    position: fixed;
    background: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    overflow: hidden;
    transition: transform var(--wgc-transition), opacity var(--wgc-transition);
    z-index: calc(var(--wgc-z) + 2);
}

/* ── Modo MODAL ── */
.wgc-panel--modal .wgc-panel-box {
    border-radius: var(--wgc-radius);
    width: 92vw;
    max-width: 600px;
    max-height: 88vh;
    /* Centrado horizontal y vertical */
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
}

/* Visible — mantiene el centrado */
.wgc-panel--modal .wgc-panel-box.wgc-panel-box--visible {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* ── Modo SIDEBAR ── */
.wgc-panel--sidebar .wgc-overlay { display: block; }

.wgc-panel--sidebar .wgc-panel-box {
    top: 0;
    bottom: 0;
    width: 380px;
    max-width: 100vw;
    border-radius: 0;
    opacity: 1;
}

#wgc-panel.wgc-panel--sidebar.wgc-position-bottom-right .wgc-panel-box {
    right: 0;
    transform: translateX(100%);
}
#wgc-panel.wgc-panel--sidebar.wgc-position-bottom-left  .wgc-panel-box {
    left: 0;
    transform: translateX(-100%);
}

.wgc-panel--sidebar .wgc-panel-box.wgc-panel-box--visible { transform: translateX(0); }


/* ─── Panel Header ──────────────────────────────────────────────────────────── */

.wgc-panel-header {
    padding: 18px 20px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.wgc-panel-header-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.wgc-panel-avatar {
    width: 46px;
    height: 46px;
    min-width: 46px;
    background: rgba(255,255,255,0.95);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wgc-panel-avatar svg {
    width: 26px;
    height: 26px;
}

.wgc-panel-header-text { min-width: 0; }

.wgc-panel-header-text h3 {
    margin: 0 0 3px;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wgc-panel-header-text p {
    margin: 0;
    font-size: 12px;
    color: rgba(255,255,255,0.85);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wgc-panel-close {
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--wgc-transition);
    flex-shrink: 0;
    padding: 0;
    outline: none;
}

.wgc-panel-close:hover,
.wgc-panel-close:focus-visible {
    background: rgba(255,255,255,0.35);
    outline: 2px solid rgba(255,255,255,0.5);
}


/* ─── Panel Body ────────────────────────────────────────────────────────────── */

.wgc-panel-body {
    padding: 24px 22px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

/* Sin formulario */
.wgc-no-form {
    text-align: center;
    color: #666;
    padding: 20px;
}

.wgc-no-form p { margin: 8px 0; }
.wgc-no-form a { color: var(--wgc-color); }

/* Bloquear scroll del body cuando panel está abierto */
body.wgc-body-locked {
    overflow: hidden;
}


/* ════════════════════════════════════════════════════════════════════════════
   OVERRIDES DE GRAVITY FORMS — diseño dentro del panel
   ════════════════════════════════════════════════════════════════════════════ */

/* Wrapper principal */
.wgc-panel-body .gform_wrapper,
.wgc-panel-body .gform_wrapper.gravity-theme {
    margin: 0 !important;
    font-family: var(--wgc-font) !important;
}

.wgc-panel-body .gform_wrapper .gform_body  { padding: 0 !important; }

/* ─── Grid 2 columnas automático ─── */
/* Campos de texto simples quedan de a 2 por fila.
   Campos complejos (nombre+apellido juntos), selects y textareas
   ocupan el ancho completo automáticamente. */
.wgc-panel-body .gform_wrapper .gform_fields {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    column-gap: 14px !important;
    margin: 0 !important;
}

/* ─── Espaciado entre campos ─── */
.wgc-panel-body .gform_wrapper .gfield {
    grid-column: span 1 !important;
    margin-bottom: 14px !important;
    padding: 0 !important;
}

/* Campos que siempre ocupan ancho completo */
.wgc-panel-body .gform_wrapper .gfield:has(select),
.wgc-panel-body .gform_wrapper .gfield:has(textarea),
.wgc-panel-body .gform_wrapper .gfield:has(.ginput_complex) {
    grid-column: 1 / -1 !important;
}

/* Fallback para navegadores sin :has() — si se agregan clases GF manualmente */
.wgc-panel-body .gform_wrapper .gfield.gf_full_width,
.wgc-panel-body .gform_wrapper .gfield.gf_wide {
    grid-column: 1 / -1 !important;
}

.wgc-panel-body .gform_wrapper .gfield:last-of-type { margin-bottom: 4px !important; }

/* ─── Etiqueta ─── */
.wgc-panel-body .gform_wrapper .gfield_label,
.wgc-panel-body .gform_wrapper label.gfield_label {
    display: block !important;
    font-size: 12.5px !important;
    font-weight: 600 !important;
    color: #374151 !important;
    margin-bottom: 5px !important;
    letter-spacing: 0.2px !important;
    text-transform: none !important;
}

/* Asterisco requerido */
.wgc-panel-body .gform_wrapper .gfield_required {
    color: #ef4444 !important;
    margin-left: 2px !important;
}

/* ─── Inputs, select, textarea ─── */
.wgc-panel-body .gform_wrapper input[type="text"],
.wgc-panel-body .gform_wrapper input[type="email"],
.wgc-panel-body .gform_wrapper input[type="tel"],
.wgc-panel-body .gform_wrapper input[type="number"],
.wgc-panel-body .gform_wrapper input[type="url"],
.wgc-panel-body .gform_wrapper select,
.wgc-panel-body .gform_wrapper textarea {
    width: 100% !important;
    box-sizing: border-box !important;
    background: #f9fafb !important;
    border: 1.5px solid #e5e7eb !important;
    border-radius: 10px !important;
    padding: 11px 14px !important;
    font-size: 14px !important;
    font-family: var(--wgc-font) !important;
    color: #111827 !important;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    line-height: 1.5 !important;
}

/* Select — flecha custom */
.wgc-panel-body .gform_wrapper select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 14px center !important;
    padding: 7px 14px !important;
    cursor: pointer !important;
}

/* Textarea */
.wgc-panel-body .gform_wrapper textarea {
    resize: vertical !important;
    min-height: 72px !important;
    max-height: 140px !important;
}

/* Focus */
.wgc-panel-body .gform_wrapper input[type="text"]:focus,
.wgc-panel-body .gform_wrapper input[type="email"]:focus,
.wgc-panel-body .gform_wrapper input[type="tel"]:focus,
.wgc-panel-body .gform_wrapper input[type="number"]:focus,
.wgc-panel-body .gform_wrapper select:focus,
.wgc-panel-body .gform_wrapper textarea:focus {
    border-color: var(--wgc-color) !important;
    background: #fff !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.18) !important;
}

/* Placeholder */
.wgc-panel-body .gform_wrapper input::placeholder,
.wgc-panel-body .gform_wrapper textarea::placeholder {
    color: #9ca3af !important;
    font-size: 13.5px !important;
}

/* ─── Campo complejo (nombre con subcampos) ─── */
.wgc-panel-body .gform_wrapper .ginput_complex {
    display: flex !important;
    gap: 10px !important;
}

.wgc-panel-body .gform_wrapper .ginput_complex > span {
    flex: 1 !important;
    min-width: 0 !important;
}

.wgc-panel-body .gform_wrapper .ginput_complex label {
    font-size: 11px !important;
    color: #6b7280 !important;
    display: block !important;
    margin-top: 4px !important;
    font-weight: 400 !important;
}

/* ─── Mensajes de validación / error ─── */
.wgc-panel-body .gform_wrapper .gfield_error input,
.wgc-panel-body .gform_wrapper .gfield_error select,
.wgc-panel-body .gform_wrapper .gfield_error textarea {
    border-color: #f87171 !important;
    background: #fff8f8 !important;
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.15) !important;
}

.wgc-panel-body .gform_wrapper .gfield_error .gfield_label {
    color: #b91c1c !important;
}

/* Texto de error inline */
.wgc-panel-body .gform_wrapper .gfield_description.validation_message,
.wgc-panel-body .gform_wrapper .gfield_error .gfield_description {
    font-size: 12px !important;
    color: #b91c1c !important;
    margin-top: 5px !important;
    display: flex !important;
    align-items: flex-start !important;
    gap: 4px !important;
    line-height: 1.4 !important;
}

/* ─── Ocultar resumen de validación superior (redundante con errores inline) ─── */
.wgc-panel-body .gform_wrapper .validation_error,
.wgc-panel-body .gform_wrapper .gform_validation_errors {
    display: none !important;
}

/* ─── Footer y botón de envío ─── */
.wgc-panel-body .gform_wrapper .gform_footer,
.wgc-panel-body .gform_wrapper .gform_page_footer {
    padding: 8px 0 0 !important;
    margin: 0 !important;
    border: none !important;
}

.wgc-panel-body .gform_wrapper input[type="submit"],
.wgc-panel-body .gform_wrapper button[type="submit"],
.wgc-panel-body .gform_wrapper .gform_button {
    width: 100% !important;
    background: var(--wgc-color) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 12px !important;
    padding: 14px 20px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    font-family: var(--wgc-font) !important;
    letter-spacing: 0.2px !important;
    cursor: pointer !important;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s !important;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.4) !important;
    display: block !important;
    text-align: center !important;
    margin: 0 !important;
}

.wgc-panel-body .gform_wrapper input[type="submit"]:hover,
.wgc-panel-body .gform_wrapper button[type="submit"]:hover,
.wgc-panel-body .gform_wrapper .gform_button:hover {
    background: var(--wgc-color-dark) !important;
    box-shadow: 0 6px 18px rgba(37, 211, 102, 0.45) !important;
    transform: translateY(-1px) !important;
}

.wgc-panel-body .gform_wrapper input[type="submit"]:active,
.wgc-panel-body .gform_wrapper button[type="submit"]:active,
.wgc-panel-body .gform_wrapper .gform_button:active {
    transform: translateY(0) !important;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3) !important;
}

/* ─── Mensaje de confirmación ─── */
.wgc-panel-body .gform_confirmation_wrapper {
    text-align: center !important;
    padding: 10px 0 !important;
}

.wgc-panel-body .gform_confirmation_message,
.wgc-panel-body .gform_wrapper .gform_confirmation_message {
    background: linear-gradient(135deg, #f0fdf4, #dcfce7) !important;
    border: 1.5px solid #86efac !important;
    border-radius: 14px !important;
    padding: 24px 20px !important;
    color: #166534 !important;
    font-size: 14.5px !important;
    line-height: 1.7 !important;
    font-weight: 500 !important;
}

/* ─── Ocultar título del formulario dentro del modal ─── */
.wgc-panel-body .gform_wrapper .gform_heading,
.wgc-panel-body .gform_wrapper .gform_title {
    display: none !important;
}

/* ─── Texto de descripción del form ─── */
.wgc-panel-body .gform_wrapper .gform_description {
    font-size: 13px !important;
    color: #6b7280 !important;
    margin-bottom: 16px !important;
    line-height: 1.5 !important;
}

/* ─── Checkbox y radio ─── */
.wgc-panel-body .gform_wrapper .gfield_checkbox li,
.wgc-panel-body .gform_wrapper .gfield_radio li {
    margin-bottom: 6px !important;
}

.wgc-panel-body .gform_wrapper .gfield_checkbox input[type="checkbox"],
.wgc-panel-body .gform_wrapper .gfield_radio input[type="radio"] {
    accent-color: var(--wgc-color) !important;
    width: auto !important;
    margin-right: 6px !important;
}

/* ─── Spinner de carga AJAX ─── */
.wgc-panel-body .gform_wrapper .gform_ajax_spinner {
    width: 20px !important;
    height: 20px !important;
}


/* ─── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
    #wgc-wrapper {
        bottom: 16px;
    }

    #wgc-wrapper.wgc-position-bottom-right { right: 16px; }
    #wgc-wrapper.wgc-position-bottom-left  { left: 16px; }

    .wgc-panel--modal .wgc-panel-box {
        width: calc(100vw - 16px);
        max-width: none;
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        max-height: 92vh;
    }

    /* En mobile, el grid colapsa a 1 columna */
    .wgc-panel-body .gform_wrapper .gform_fields {
        grid-template-columns: 1fr !important;
    }

    .wgc-panel-body .gform_wrapper .gfield {
        grid-column: 1 / -1 !important;
    }

    .wgc-panel--sidebar .wgc-panel-box {
        width: 100vw;
    }
}


/* ─── Botón WhatsApp en confirmación ─────────────────────────────────────── */

.wgc-wa-confirm-wrap {
    margin-top: 18px;
    text-align: center;
}

#wgc-wa-confirm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #25D366;
    color: #fff !important;
    text-decoration: none !important;
    font-family: var(--wgc-font);
    font-size: 15px;
    font-weight: 600;
    padding: 13px 28px;
    border-radius: 50px;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.45);
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    cursor: pointer;
    border: none;
    white-space: nowrap;
}

#wgc-wa-confirm-btn:hover {
    background: #1ebe5d;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(37, 211, 102, 0.55);
}
