/**
 * Public Styles for Advanced Visa Forms
 * @package Advanced_Visa_Forms
 */

/* ========================================
   RTL Support
   ======================================== */

.avf-form-container {
    direction: rtl;
    text-align: right;
}

/* ========================================
   Form Container
   ======================================== */

.avf-form-container {
    max-width: 900px;
    margin: 30px auto;
    padding: 0;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: visible !important;
    position: relative;
}

.avf-form-header {
    background: linear-gradient(135deg, #2036A4 0%, #8C95FF 100%);
    color: #fff;
    padding: 30px;
    text-align: center;
    border-radius: 16px 16px 0 0;
}

.avf-form-title {
    margin: 0;
    font-size: 28px;
    font-weight: 600;
}

/* ========================================
   Progress Bar (Multi-step)
   ======================================== */

.avf-progress-bar {
    padding: 30px 20px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.avf-progress-steps {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    position: relative;
}

.avf-progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    position: relative;
    z-index: 2;
}

.avf-step-number {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #dee2e6;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    margin-bottom: 8px;
    transition: all 0.3s ease;
}

.avf-progress-step.active .avf-step-number {
    background: #2036A4;
    color: #fff;
    transform: scale(1.1);
}

.avf-progress-step.completed .avf-step-number {
    background: #28a745;
    color: #fff;
}

.avf-step-title {
    font-size: 12px;
    color: #6c757d;
    text-align: center;
}

.avf-progress-step.active .avf-step-title {
    color: #2036A4;
    font-weight: 600;
}

.avf-progress-line {
    position: relative;
    height: 4px;
    background: #dee2e6;
    border-radius: 2px;
    overflow: hidden;
}

.avf-progress-fill {
    height: 100%;
    background: #2036A4;
    transition: width 0.5s ease;
}

/* ========================================
   Form Content
   ======================================== */

.avf-form-content,
.avf-form-steps {
    padding: 30px;
}

.avf-form-step {
    position: absolute;
    left: -9999px;
    visibility: hidden;
    height: 0;
    overflow: hidden;
    pointer-events: none;
}

.avf-form-step.active {
    position: static;
    left: auto;
    visibility: visible;
    height: auto;
    overflow: visible;
    pointer-events: auto;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.avf-step-heading {
    margin: 0 0 10px !important;
    font-size: 28px !important;
    color: #333 !important;
    text-align: center !important;
}

.avf-step-description {
    margin: 0 0 25px !important;
    color: #666 !important;
    font-size: 16px !important;
    font-weight: 700 !important;
    text-align: center !important;
}

/* ========================================
   Sections
   ======================================== */

.avf-section {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 6px;
}

.avf-section-title {
    margin: 0 0 15px;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.required {
    color: #dc3545;
}

/* ========================================
   Products Section
   ======================================== */

.avf-products-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}

.avf-product-option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 15px;
    background: #fff;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.avf-product-option:hover {
    border-color: #2036A4;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.avf-product-option input[type="checkbox"] {
    margin-top: 3px;
}

.avf-product-option input[type="checkbox"]:checked + .avf-product-details {
    color: #2036A4;
}

.avf-product-option:has(input:checked) {
    border-color: #2036A4;
    background: #f8f9fe;
}

.avf-product-details {
    flex: 1;
}

.avf-product-label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: #333;
}

.avf-product-price {
    display: block;
    font-size: 18px;
    color: #2036A4;
    font-weight: 700;
    margin-bottom: 5px;
}

.avf-product-description {
    display: block;
    font-size: 13px;
    color: #666;
}

/* ========================================
   Business Days Section
   ======================================== */

.avf-business-days-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.avf-business-days-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: #fff;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.avf-business-days-option:hover {
    border-color: #2036A4;
}

.avf-business-days-option:has(input:checked) {
    border-color: #2036A4;
    background: #f8f9fe;
}

.avf-bd-details {
    flex: 1;
}

.avf-bd-label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 3px;
}

.avf-bd-price {
    display: block;
    color: #2036A4;
    font-weight: 600;
}

/* ========================================
   Applicants Section
   ======================================== */

.avf-num-applicants {
    margin-bottom: 25px;
    padding: 15px;
    background: #fff;
    border-radius: 6px;
}

.avf-num-applicants label {
    display: block;
    margin-bottom: 8px;
}

.avf-num-applicants select {
    width: 100%;
    max-width: 200px;
    padding: 10px;
    font-size: 16px;
    border: 1px solid #ced4da;
    border-radius: 4px;
}

.avf-applicant {
    padding: 20px;
    margin-bottom: 20px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
}

.avf-applicant-title {
    margin: 0 0 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #2036A4;
    color: #333;
    font-size: 20px;
}

/* ========================================
   Fields Grid
   ======================================== */

.avf-fields-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 20px;
}

.avf-field {
    display: flex;
    flex-direction: column;
}

/* Field width control */
.avf-field-full {
    grid-column: span 6;
}

.avf-field-half {
    grid-column: span 3;
}

.avf-field-third {
    grid-column: span 2;
}

.avf-field label {
    margin-bottom: 6px;
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.avf-field input[type="text"],
.avf-field input[type="email"],
.avf-field input[type="tel"],
.avf-field input[type="number"],
.avf-field input[type="date"],
.avf-field select,
.avf-field textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 16px; /* Prevents iOS zoom */
    border: 1px solid #ced4da;
    border-radius: 4px;
    transition: border-color 0.2s ease;
    -webkit-text-size-adjust: 100%;
}

/* Text formatting based on backend setting (data-text-format attribute) */
.avf-field input[data-text-format="uppercase"],
.avf-field textarea[data-text-format="uppercase"] {
    text-transform: uppercase;
}

.avf-field input[data-text-format="capitalize"],
.avf-field textarea[data-text-format="capitalize"] {
    text-transform: capitalize;
}

.avf-field input:focus,
.avf-field select:focus,
.avf-field textarea:focus {
    outline: none;
    border-color: #2036A4;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.avf-field input[type="file"] {
    padding: 8px;
    font-size: 14px;
}

.avf-file-info {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: #6c757d;
}

.avf-field-hint {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: #6c757d;
    line-height: 1.4;
}

/* Above-input variant: placeholder rendered as a hint between label and input,
   used when long placeholders would be clipped inside the input on mobile. */
.avf-field-hint--above {
    margin-top: 0;
    margin-bottom: 6px;
}

.avf-calculated-date {
    display: block;
    margin-top: 5px;
    font-size: 13px;
    color: #2036A4;
    font-weight: 500;
}

.avf-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

/* ========================================
   Step Navigation
   ======================================== */

.avf-step-navigation {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #dee2e6;
    direction: rtl; /* RTL for button order */
}

/* All buttons same size */
.avf-step-navigation .avf-btn {
    flex: 1 1 0; /* Equal width for all buttons */
    min-width: 0; /* No minimum width - let flex handle it */
    max-width: none;
    text-align: center;
    box-sizing: border-box; /* Include padding in width calculation */
}

/* ========================================
   Buttons
   ======================================== */

.avf-btn {
    padding: 12px 24px !important;
    font-size: 16px !important;
    font-weight: 600;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none !important;
    outline: none !important;
    box-shadow: none !important;
    line-height: 1.4 !important;
    white-space: nowrap;
    height: auto !important;
    min-height: 48px !important;
    max-height: none !important;
    text-align: center !important;
}

/* All buttons use primary style for consistency */
.avf-btn,
.avf-btn-primary,
.avf-btn-secondary {
    background: linear-gradient(135deg, #2036A4 0%, #8C95FF 100%);
    color: #fff !important;
    border-color: #2036A4 !important;
}

.avf-btn:hover,
.avf-btn:focus,
.avf-btn-primary:hover,
.avf-btn-primary:focus,
.avf-btn-secondary:hover,
.avf-btn-secondary:focus {
    background: linear-gradient(135deg, #1a2d8a 0%, #7680e6 100%);
    color: #fff !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(32, 54, 164, 0.4) !important;
    text-decoration: none !important;
    border-color: #1a2d8a !important;
}

.avf-btn:active,
.avf-btn:visited,
.avf-btn-primary:active,
.avf-btn-primary:visited,
.avf-btn-secondary:active,
.avf-btn-secondary:visited {
    background: linear-gradient(135deg, #2036A4 0%, #8C95FF 100%);
    color: #fff !important;
    text-decoration: none !important;
}

.avf-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Override ANY link styles from WordPress/theme */
a.avf-btn,
button.avf-btn,
.avf-btn:link,
.avf-btn:visited,
.avf-btn:hover,
.avf-btn:active,
.avf-btn:focus {
    text-decoration: none !important;
    outline: none !important;
}

/* Remove focus outline from WordPress */
.avf-btn:focus-visible {
    outline: 2px solid #2036A4 !important;
    outline-offset: 2px !important;
}

/* ========================================
   Submit Section
   ======================================== */

.avf-submit-section {
    margin-top: 30px;
    padding: 25px;
    background: #f8f9fa;
    border-radius: 6px;
    text-align: center;
    overflow: visible !important;
    position: relative;
}

.avf-total-price {
    margin-bottom: 20px;
    font-size: 24px;
}

.avf-total-amount {
    color: #2036A4;
    font-weight: 700;
}

.avf-btn-submit {
    min-width: 200px;
}

.avf-privacy-note {
    margin-top: 15px;
    font-size: 12px;
    color: #6c757d;
}

/* ========================================
   Summary Section
   ======================================== */

.avf-summary-warning {
    background: linear-gradient(135deg, #fff3cd 0%, #fff8e1 100%);
    border: 2px solid #ffc107;
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.2);
}

.avf-summary-warning p {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #856404;
    display: flex;
    align-items: center;
    gap: 10px;
}

.avf-summary-content {
    background: #fff;
    padding: 20px;
    border-radius: 6px;
}

.avf-summary-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #dee2e6;
}

.avf-summary-section:last-child {
    border-bottom: none;
}

.avf-summary-section h4 {
    margin: 0 0 15px;
    color: #2036A4;
    font-size: 18px;
}

.avf-summary-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}

.avf-summary-item strong {
    color: #333;
}

/* ========================================
   Loading State
   ======================================== */

.avf-form.loading {
    opacity: 0.6;
    pointer-events: none;
}

.avf-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   Messages & Alerts
   ======================================== */

.avf-auto-select-message {
    padding: 12px 15px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 14px;
    animation: fadeIn 0.3s ease;
}

.avf-error {
    padding: 15px;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #721c24;
    margin-bottom: 20px;
}

/* ========================================
   Phone Country Code
   ======================================== */

select[id$="_country_code"] {
    font-size: 15px;
}

select[id$="_country_code"] option {
    font-size: 15px;
}

.avf-field.has-error input,
.avf-field.has-error select,
.avf-field.has-error textarea {
    border-color: #dc3545;
}

.avf-field-error {
    display: block;
    margin-top: 5px;
    font-size: 13px;
    color: #dc3545;
}

/* ========================================
   reCAPTCHA Styling
   ======================================== */

/* reCAPTCHA container and wrapper */
.avf-recaptcha-container {
    min-height: 120px;
    padding-bottom: 20px;
    position: relative;
    z-index: 10;
    overflow: visible !important;
}

.avf-recaptcha-wrapper {
    margin: 25px 0;
    text-align: center;
    padding: 15px;
    background: rgba(32, 54, 164, 0.02);
    border-radius: 12px;
    border: 1px dashed #e9ecef;
    overflow: visible !important;
}

/* Center the reCAPTCHA checkbox */
.g-recaptcha {
    display: inline-block !important;
    margin: 0 auto !important;
}

/* Center and fix the reCAPTCHA challenge popup */
.rc-anchor-container,
.rc-anchor-normal,
.rc-anchor-compact {
    margin: 0 auto !important;
}

/* Prevent all reCAPTCHA iframes from exceeding viewport width */
iframe[src*="google.com/recaptcha"],
iframe[src*="recaptcha"],
iframe[title*="recaptcha"] {
    max-width: 100vw !important;
    box-sizing: border-box !important;
}

/* Fix reCAPTCHA checkbox positioning on mobile */
@media screen and (max-width: 768px) {
    /* Center the checkbox wrapper */
    .avf-recaptcha-wrapper {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }

    /* Scale down checkbox for tablets */
    .g-recaptcha {
        transform: scale(0.85) !important;
        -webkit-transform: scale(0.85) !important;
        transform-origin: center center !important;
        -webkit-transform-origin: center center !important;
        margin: 10px auto !important;
    }
}

@media screen and (max-width: 480px) {
    /* Scale down checkbox significantly for small phones */
    .g-recaptcha {
        transform: scale(0.75) !important;
        -webkit-transform: scale(0.75) !important;
        transform-origin: center center !important;
        -webkit-transform-origin: center center !important;
        margin: 8px auto !important;
    }
}

@media screen and (max-width: 360px) {
    /* Scale down even more for very small screens */
    .g-recaptcha {
        transform: scale(0.65) !important;
        -webkit-transform: scale(0.65) !important;
        transform-origin: center center !important;
        -webkit-transform-origin: center center !important;
        margin: 5px auto !important;
    }
}

/* ========================================
   Responsive Design
   ======================================== */

@media screen and (max-width: 768px) {
    /* Prevent horizontal scroll on mobile */
    body, html {
        overflow-x: hidden;
        max-width: 100vw;
    }

    .avf-form-container {
        margin: 10px;
        max-width: calc(100vw - 20px); /* Account for margins */
        overflow: visible !important;
        box-sizing: border-box;
    }

    .avf-form-content,
    .avf-form-steps {
        padding: 15px 10px;
        box-sizing: border-box;
        width: 100%;
        max-width: 100%;
    }

    /* Ensure navigation doesn't overflow */
    .avf-form-step {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .avf-section {
        padding: 15px 10px;
    }

    .avf-applicant {
        padding: 15px 10px;
        margin-bottom: 15px;
    }

    /* Warning message responsive */
    .avf-summary-warning {
        padding: 12px 15px;
        margin-bottom: 15px;
    }

    .avf-summary-warning p {
        font-size: 14px;
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

    .avf-summary-warning p span:first-child {
        font-size: 28px;
    }

    .avf-products-list,
    .avf-fields-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .avf-field {
        width: 100%;
        max-width: 100%;
    }

    /* Force all fields to full width on mobile */
    .avf-field-full,
    .avf-field-half,
    .avf-field-third {
        grid-column: span 1;
    }

    .avf-field input,
    .avf-field select,
    .avf-field textarea {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    .avf-step-number {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .avf-step-title {
        font-size: 11px;
    }

    .avf-step-navigation {
        direction: rtl; /* RTL: previous on right, next on left */
        justify-content: space-between;
        flex-wrap: nowrap;
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
    }

    .avf-btn {
        flex: 1 1 0 !important; /* Equal width */
        min-width: 0 !important; /* Critical: allow buttons to shrink */
        max-width: none !important;
        width: auto !important;
        justify-content: center;
        text-align: center;
        padding: 14px 8px !important; /* Reduced padding for mobile */
        font-size: 14px !important;
        font-weight: 700 !important;
        white-space: normal !important; /* Allow text wrap if needed */
        line-height: 1.3 !important;
        box-sizing: border-box !important;
    }

    /* Date inputs on mobile - Prevent iOS zoom */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        width: 100% !important;
        max-width: 100% !important;
        padding: 14px 12px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        -webkit-text-size-adjust: 100%;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    /* Entry date section */
    .avf-entry-date-section .avf-field {
        width: 100%;
    }

    #avf_entry_date {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Number selects on mobile */
    select,
    input[type="number"] {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }

    /* Keep terms checkbox visible but make it compact on mobile */
    .avf-form-step[data-step="4"] .avf-terms-checkbox {
        margin: 15px 0 !important;
        padding: 12px !important;
        font-size: 13px !important;
    }
}

@media screen and (max-width: 480px) {
    .avf-form-title {
        font-size: 22px;
    }

    .avf-form-header {
        padding: 25px 20px;
    }

    .avf-progress-steps {
        flex-wrap: wrap;
        gap: 10px;
    }

    .avf-step-title {
        font-size: 11px;
        margin-top: 3px;
    }

    .avf-step-heading {
        font-size: 22px;
    }

    .avf-step-description {
        font-size: 14px;
    }

    /* Larger buttons on very small screens for better touch targets */
    .avf-btn {
        padding: 12px 6px !important; /* Minimal padding for small screens */
        font-size: 13px !important;
        font-weight: 700 !important;
        min-height: 50px !important; /* Comfortable touch target */
        flex: 1 1 0 !important; /* Equal width */
        min-width: 0 !important; /* Critical: allow shrinking */
        text-align: center !important;
        white-space: normal !important;
        line-height: 1.2 !important;
        box-sizing: border-box !important;
    }

    /* Keep RTL direction (previous right, next left) */
    .avf-step-navigation {
        direction: rtl;
        gap: 6px; /* Smaller gap on very small screens */
        width: 100%;
        padding: 0;
        margin-left: 0;
        margin-right: 0;
    }

    /* Fix phone country code dropdown width on mobile */
    select[id$="_country_code"] {
        width: 75px !important;
        min-width: 75px !important;
        max-width: 75px !important;
        padding: 10px 4px !important;
        font-size: 14px !important;
    }

    input.avf-phone-number {
        flex: 1 !important;
        min-width: 0 !important;
    }
}

/* Searchable Select Dropdown */
.avf-searchable-wrapper {
    position: relative;
    width: 100%;
}

.avf-searchable-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    font-size: 16px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.avf-searchable-display:hover {
    border-color: #adb5bd;
}

.avf-searchable-open .avf-searchable-display {
    border-color: #2036A4;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.avf-searchable-arrow {
    font-size: 12px;
    color: #6c757d;
    transition: transform 0.2s ease;
}

.avf-searchable-open .avf-searchable-arrow {
    transform: rotate(180deg);
}

.avf-searchable-text {
    color: #495057;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.avf-searchable-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    z-index: 100;
    margin-top: 4px;
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.avf-searchable-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    border: none;
    border-bottom: 1px solid #e9ecef;
    border-radius: 4px 4px 0 0;
    outline: none;
    box-sizing: border-box;
}

.avf-searchable-input:focus {
    border-bottom-color: #2036A4;
}

.avf-searchable-options {
    max-height: 200px;
    overflow-y: auto;
}

.avf-searchable-option {
    padding: 10px 12px;
    font-size: 15px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.avf-searchable-option:hover {
    background: #f0f4ff;
}

.avf-searchable-option.avf-searchable-selected {
    background: #e8edff;
    font-weight: 600;
}

/* Error state */
.avf-field.has-error .avf-searchable-display {
    border-color: #dc3545;
}
