/**
 * SureForms Conversational Styling
 * Modern, Typeform-style appearance for one-question-at-a-time experience
 * Version: 1.0
 */

/* ============================================
   PREVENT FLASH OF UNSTYLED CONTENT (FOUC)
   ============================================ */

/* Hide form initially until JavaScript transforms it */
form.srfm-form {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in, visibility 0s linear 0.3s;
}

/* Show form once JavaScript has initialized it */
form.srfm-form.cf-initialized {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease-in, visibility 0s;
}

/* ============================================
   CONTAINER & LAYOUT
   ============================================ */

.conversational-form-container {
    max-width: 700px;
    margin: 60px auto;
    padding: 50px 40px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
    min-height: 400px;
}

@media (max-width: 768px) {
    .conversational-form-container {
        margin: 20px 15px;
        padding: 30px 20px;
        min-height: 350px;
    }
}

/* ============================================
   PROGRESS BAR
   ============================================ */

.cf-progress-bar {
    margin-bottom: 50px;
    padding-bottom: 20px;
}

.cf-progress-text {
    font-size: 15px;
    color: #64748b;
    margin-bottom: 12px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.cf-progress-text .cf-current {
    color: #6366f1;
    font-weight: 700;
    font-size: 16px;
}

.cf-progress-track {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.cf-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 10px;
    position: relative;
}

.cf-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* ============================================
   FIELD BLOCKS
   ============================================ */

.conversational-form-container .srfm-block-single {
    opacity: 0;
    animation: fadeInUp 0.5s ease-out forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hide SureForms default styling conflicts */
.conversational-form-container .srfm-form {
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
}

/* ============================================
   reCAPTCHA FIX (JAVASCRIPT CLASS TRIGGER)
   ============================================ */

/* 1. Hide reCAPTCHA globally by default */
.conversational-form-container .g-recaptcha,
.conversational-form-container .srfm-recaptcha {
    display: none !important;
}

/* 2. Show reCAPTCHA ONLY when the JS adds the 'cf-is-last-step' class */
.conversational-form-container.cf-is-last-step .g-recaptcha,
.conversational-form-container.cf-is-last-step .srfm-recaptcha {
    display: flex !important;
    justify-content: center !important;
    width: 100% !important;
    margin: 20px auto 30px auto !important;
    opacity: 1 !important;
    visibility: visible !important;
    clear: both !important;
    animation: fadeInRecaptcha 0.5s ease-in forwards;
}

/* Animation */
@keyframes fadeInRecaptcha {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Scaling */
@media (max-width: 768px) {
    .conversational-form-container.cf-is-last-step .srfm-recaptcha {
        transform: scale(0.85); 
        margin: 10px auto 25px auto !important;
    }
}

/* ============================================
   LABELS
   ============================================ */

.conversational-form-container label {
    font-size: 24px !important;
    font-weight: 600 !important;
    color: #1e293b !important;
    margin-bottom: 16px !important;
    display: block !important;
    line-height: 1.4 !important;
}

.conversational-form-container label abbr {
    color: #ef4444;
    text-decoration: none;
    font-weight: 700;
}

@media (max-width: 768px) {
    .conversational-form-container label {
        font-size: 20px !important;
    }
}

/* ============================================
   INPUT FIELDS
   ============================================ */

.conversational-form-container input[type="text"],
.conversational-form-container input[type="email"],
.conversational-form-container input[type="tel"],
.conversational-form-container select,
.conversational-form-container textarea {
    width: 100% !important;
    padding: 18px 20px !important;
    font-size: 18px !important;
    color: #1e293b !important;
    border: 2px solid #e2e8f0 !important;
    border-radius: 10px !important;
    background: #ffffff !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    margin-top: 8px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
}

.conversational-form-container input:focus,
.conversational-form-container select:focus,
.conversational-form-container textarea:focus {
    outline: none !important;
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), 0 1px 3px rgba(0, 0, 0, 0.05) !important;
    transform: translateY(-1px);
}

.conversational-form-container input::placeholder,
.conversational-form-container textarea::placeholder {
    color: #94a3b8 !important;
}

/* Select Dropdown */
.conversational-form-container select {
    cursor: pointer !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23334155' d='M6 9L1 4h10z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 16px center !important;
    background-size: 12px !important;
    padding-right: 40px !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
}

/* Textarea */
.conversational-form-container textarea {
    min-height: 120px !important;
    resize: vertical !important;
    font-family: inherit !important;
}

/* Phone Input with Country Code */
.conversational-form-container .srfm-phone-block-wrap .iti {
    width: 100% !important;
}

.conversational-form-container .srfm-phone-block-wrap input[type="tel"],
.conversational-form-container input[type="tel"],
.conversational-form-container .iti__tel-input {
    padding-left: 90px !important;
}

/* Ensure country selector doesn't overlap */
.conversational-form-container .srfm-phone-block-wrap .iti__selected-flag {
    padding: 0 8px !important;
}

/* Force the flag container positioning */
.conversational-form-container .iti__flag-container {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
}

/* ============================================
   ERROR STATES
   ============================================ */

.cf-error-field {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1) !important;
}

.cf-validation-error {
    color: #ef4444;
    font-size: 14px;
    font-weight: 500;
    margin-top: 10px;
    display: flex;
    align-items: center;
    animation: slideDown 0.3s ease-out;
}

.cf-validation-error:before {
    content: "⚠";
    margin-right: 6px;
    font-size: 16px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cf-shake {
    animation: shake 0.4s;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-8px);
    }
    75% {
        transform: translateX(8px);
    }
}

/* Hide SureForms native error messages (we show our own) */
.conversational-form-container .srfm-error-wrap {
    display: none !important;
}

/* ============================================
   NAVIGATION BUTTONS
   ============================================ */

.cf-nav-buttons {
    display: flex;
    gap: 12px;
    margin-top: 30px;
    align-items: center;
}

.cf-btn {
    padding: 16px 32px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    border: none !important;
    border-radius: 10px !important;
    cursor: pointer !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    text-decoration: none !important;
}

.cf-btn-next,
.cf-btn-submit {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%) !important;
    color: white !important;
    flex: 1;
}

.cf-btn-next:hover,
.cf-btn-submit:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4) !important;
}

.cf-btn-next:active,
.cf-btn-submit:active {
    transform: translateY(0) !important;
}

.cf-btn-prev {
    background: #f1f5f9 !important;
    color: #475569 !important;
    padding: 16px 24px !important;
}

.cf-btn-prev:hover {
    background: #e2e8f0 !important;
    transform: translateY(-1px) !important;
}

.cf-btn-icon {
    font-size: 18px;
    font-weight: 700;
}

/* Hide original SureForms submit buttons (user should delete from SureForms editor) */
form.srfm-form .srfm-btn-submit:not(.cf-btn-submit),
.cf-original-submit {
    display: none !important;
}

/* Our custom submit button styling */
.conversational-form-container .cf-nav-buttons .cf-btn-submit {
    display: inline-flex !important;
}

/* ============================================
   CHECKBOXES & TERMS (FINAL ROBUST FIX)
   ============================================ */

/* 1. The Container (Label) */
/* We use Flexbox here. This forces the Box and Text to sit side-by-side. 
   They physically cannot overlap in this mode. */
.conversational-form-container .srfm-checkbox-block-wrap label {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important; /* Aligns box with top line of text */
    justify-content: flex-start !important;
    text-indent: 0 !important;
    margin-bottom: 20px !important;
    width: 100% !important;
    cursor: pointer !important;
}

/* 2. The Text */
.conversational-form-container .srfm-checkbox-block-wrap label span, 
.conversational-form-container .srfm-checkbox-block-wrap label {
    font-size: 16px !important;
    line-height: 1.5 !important;
    color: #475569 !important;
    /* No padding needed here because flexbox handles the gap via margin on the input */
}

/* 3. The Checkbox (The Box) */
.conversational-form-container input[type="checkbox"] {
    /* RESET everything to strip theme styles */
    -webkit-appearance: none !important;
    appearance: none !important;
    float: none !important;
    position: relative !important;
    
    /* STRICT SIZING - Prevents it from disappearing */
    width: 22px !important;
    height: 22px !important;
    min-width: 22px !important; 
    min-height: 22px !important;
    flex-shrink: 0 !important; /* Critical: Stops text from squishing the box */
    
    /* SPACING - This creates the gap between box and text */
    margin: 2px 12px 0 0 !important; 
    
    /* STYLING */
    background-color: #ffffff !important;
    border: 2px solid #cbd5e1 !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    outline: none !important;
}

/* 4. Checked State (Background) */
.conversational-form-container input[type="checkbox"]:checked {
    background-color: #6366f1 !important;
    border-color: #6366f1 !important;
}

/* 5. The Tick (Checkmark) */
.conversational-form-container input[type="checkbox"]::after {
    content: '' !important;
    position: absolute !important;
    
    /* POSITIONING - Centered in 22px box */
    left: 7px !important;
    top: 3px !important;
    
    /* SHAPE (The "L") */
    width: 6px !important;
    height: 11px !important;
    border: solid white !important;
    border-width: 0 2px 2px 0 !important;
    
    /* ROTATION */
    transform: rotate(45deg) !important;
    
    /* VISIBILITY - Hidden by default */
    display: none !important; 
}

/* 6. REVEAL TICK (The Trigger) */
.conversational-form-container input[type="checkbox"]:checked::after {
    display: block !important; /* Force it to appear */
}

/* 7. Hover Effects */
.conversational-form-container input[type="checkbox"]:hover {
    border-color: #6366f1 !important;
}

/* 8. Link Styling */
.conversational-form-container .srfm-checkbox-block-wrap a {
    color: #6366f1;
    text-decoration: underline;
    margin-left: 4px;
    display: inline-block !important; /* Keeps it with text */
}

/* ============================================
   LOADING STATE
   ============================================ */

.cf-btn-submit.loading {
    position: relative;
    color: transparent !important;
}

.cf-btn-submit.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin-left: -10px;
    margin-top: -10px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   MOBILE RESPONSIVE (BUTTON STACKING FIX)
   ============================================ */

@media (max-width: 768px) {
    .conversational-form-container {
        padding: 25px 20px 35px 20px;
        margin: 20px 15px;
    }

    .conversational-form-container input,
    .conversational-form-container select,
    .conversational-form-container textarea {
        font-size: 16px !important;
        padding: 14px 16px !important;
    }

    .cf-btn {
        padding: 14px 20px !important;
        font-size: 16px !important;
        width: 100% !important;
        justify-content: center !important;
        box-sizing: border-box !important; /* Prevents padding from breaking width */
    }

    .cf-nav-buttons {
        display: flex !important;
        flex-direction: column !important; /* Stack vertically */
        gap: 15px !important; /* Space between buttons */
        margin-top: 30px !important;
        width: 100% !important;
    }

    /* Primary Action (Submit/Next) goes to Top */
    .cf-btn-next,
    .cf-btn-submit {
        order: 1 !important;
        width: 100% !important;
        margin-bottom: 0 !important;
    }

    /* Secondary Action (Previous) goes to Bottom */
    .cf-btn-prev {
        order: 2 !important;
        width: 100% !important;
        margin-top: 0 !important;
        background-color: transparent !important;
        border: 2px solid #e2e8f0 !important; /* Hollow style for prev button on mobile */
    }
    
    /* Ensure hidden buttons don't mess up layout */
    .cf-btn[style*="display: none"] {
        display: none !important;
    }

    /* reCAPTCHA Mobile Scaling */
    .conversational-form-container .g-recaptcha,
    .conversational-form-container .srfm-recaptcha {
        transform: scale(0.77) !important;
        transform-origin: 0 0 !important;
        margin: 20px 0 25px 0 !important;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.cf-btn:focus,
.conversational-form-container input:focus,
.conversational-form-container select:focus,
.conversational-form-container textarea:focus {
    outline: 2px solid #6366f1 !important;
    outline-offset: 2px !important;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============================================
   HIDE SEPARATORS
   ============================================ */

.conversational-form-container .wp-block-uagb-separator {
    display: none !important;
}

/* ============================================
   SAFETY: ALLOW BUTTONS TO BE HIDDEN
   ============================================ */
.conversational-form-container .cf-btn[style*="display: none"],
.conversational-form-container .cf-btn-submit[style*="display: none"],
.conversational-form-container .cf-btn-next[style*="display: none"] {
    display: none !important;
}