/**
 * Elavon Checkout Fix - CSS Overrides for Page Builders
 * 
 * This file fixes layout conflicts between the Elavon Converge Gateway plugin
 * and page builders (Breakdance, Oxygen, etc.) without modifying the original plugin.
 * 
 * The original plugin CSS can interfere with page builder layouts by applying
 * fixed margins, inline displays, and other styles that conflict with builder controls.
 */

/* Ensure payment gateway container doesn't interfere with page builder layouts */
#wgc-payment-gateway {
    display: block !important;
    width: 100%;
    position: relative;
    box-sizing: border-box;
}

/* Reset problematic display properties that conflict with page builders */
#wgc-payment-gateway label {
    display: block !important;
    font-weight: 400;
    margin-bottom: 0.5em;
    width: auto;
}

/* Allow page builders to control spacing instead of fixed margins */
#wgc-payment-gateway .save-for-later-use {
    margin-left: 0 !important;
    margin-top: 1em !important;
    margin-bottom: 1em;
}

/* Reset padding to allow builder control */
#wgc-payment-gateway #wgc-payment-gateway-fields {
    padding-bottom: 0 !important;
    margin-bottom: 1em;
}

/* Reset input margins to allow builder spacing control */
#wgc-payment-gateway #wgc-payment-gateway-fields div > input {
    margin: 0 !important;
    margin-bottom: 0.5em !important;
}

/* Ensure proper spacing for save-for-later message */
#wgc-payment-gateway .save-for-later-use-message {
    margin-top: 0.5em !important;
    margin-bottom: 0.5em;
}

/* Preserve error color styling */
#wgc-payment-gateway .red {
    color: red;
}

/* Fix for page builder checkout field containers */
.woocommerce-checkout #wgc-payment-gateway,
.woocommerce-checkout-review-order #wgc-payment-gateway {
    display: block !important;
    position: relative;
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
}

/* Ensure radio buttons and labels work properly in builders */
#wgc-payment-gateway #wgc-payment-gateway-fields div {
    display: flex !important;
    align-items: center;
    margin-bottom: 0.75em;
    gap: 0.5em;
}

#wgc-payment-gateway #wgc-payment-gateway-fields div label {
    display: inline-block !important;
    margin-bottom: 0;
    margin-left: 0.5em;
    flex: 1;
}

/* Ensure checkbox and its label work together */
#wgc-payment-gateway .save-for-later-use {
    display: flex !important;
    align-items: flex-start;
    gap: 0.5em;
}

#wgc-payment-gateway .save-for-later-use input[type="checkbox"] {
    margin: 0 !important;
    flex-shrink: 0;
}

#wgc-payment-gateway .save-for-later-use label {
    display: inline-block !important;
    margin-bottom: 0;
    flex: 1;
}

/* Preserve subscription table styling */
table.woocommerce_subscriptions_table {
    border: 1px solid rgba(0, 0, 0, .1);
    margin: 0 -1px 24px 0;
    text-align: left;
    width: 100%;
    border-collapse: separate;
    border-radius: 5px;
}

table.woocommerce_subscriptions_table th,
table.woocommerce_subscriptions_table td {
    padding: 1em;
}

table.woocommerce_subscriptions_table td {
    border-top: 1px solid rgba(0, 0, 0, .1);
    line-height: 1.5em;
}

/* Ensure hidden form stays hidden */
#wc-elavon-converge-gateway-cc-form {
    display: none !important;
}

/* ============================================
   CHECKOUT FORM FIELDS - Page Builder Compatibility
   ============================================ */

/* Ensure checkout form fields have proper styling for page builders */
.woocommerce-checkout .woocommerce-billing-fields input[type="text"],
.woocommerce-checkout .woocommerce-billing-fields input[type="email"],
.woocommerce-checkout .woocommerce-billing-fields input[type="tel"],
.woocommerce-checkout .woocommerce-billing-fields input[type="number"],
.woocommerce-checkout .woocommerce-billing-fields input[type="password"],
.woocommerce-checkout .woocommerce-billing-fields select,
.woocommerce-checkout .woocommerce-billing-fields textarea,
.woocommerce-checkout .woocommerce-shipping-fields input[type="text"],
.woocommerce-checkout .woocommerce-shipping-fields input[type="email"],
.woocommerce-checkout .woocommerce-shipping-fields input[type="tel"],
.woocommerce-checkout .woocommerce-shipping-fields input[type="number"],
.woocommerce-checkout .woocommerce-shipping-fields select,
.woocommerce-checkout .woocommerce-shipping-fields textarea,
.woocommerce-checkout .woocommerce-additional-fields textarea {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 12px 16px !important;
    margin: 0 !important;
    border: 1px solid #d1d5db !important;
    border-radius: 4px !important;
    font-size: 16px !important;
    line-height: 1.5 !important;
    background-color: #ffffff !important;
    color: #1f2937 !important;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out !important;
}

/* Focus states for better UX */
.woocommerce-checkout .woocommerce-billing-fields input:focus,
.woocommerce-checkout .woocommerce-billing-fields select:focus,
.woocommerce-checkout .woocommerce-billing-fields textarea:focus,
.woocommerce-checkout .woocommerce-shipping-fields input:focus,
.woocommerce-checkout .woocommerce-shipping-fields select:focus,
.woocommerce-checkout .woocommerce-shipping-fields textarea:focus,
.woocommerce-checkout .woocommerce-additional-fields textarea:focus {
    outline: none !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}

/* Ensure form rows and paragraph containers work with page builders */
/* Exclude form-row-first and form-row-last from this rule */
.woocommerce-checkout .woocommerce-billing-fields .form-row:not(.form-row-first):not(.form-row-last),
.woocommerce-checkout .woocommerce-shipping-fields .form-row:not(.form-row-first):not(.form-row-last),
.woocommerce-checkout .woocommerce-additional-fields .form-row,
.woocommerce-checkout .woocommerce-billing-fields p:not(.form-row-first):not(.form-row-last),
.woocommerce-checkout .woocommerce-shipping-fields p:not(.form-row-first):not(.form-row-last),
.woocommerce-checkout .woocommerce-additional-fields p {
    display: block !important;
    width: 100% !important;
    margin: 0 0 1.5em 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
}

/* Two-column layout for first name and last name fields */
/* Target by ID for maximum specificity to override Breakdance and other CSS */
/* Use flex properties since parent uses flexbox with gap */
#billing_first_name_field,
#billing_last_name_field,
#shipping_first_name_field,
#shipping_last_name_field,
.woocommerce-checkout .woocommerce-billing-fields p.form-row-first,
.woocommerce-checkout .woocommerce-shipping-fields p.form-row-first,
.woocommerce-checkout .woocommerce-billing-fields .form-row.form-row-first,
.woocommerce-checkout .woocommerce-shipping-fields .form-row.form-row-first {
    flex: 0 0 calc(50% - 8px) !important;
    width: calc(50% - 8px) !important;
    max-width: calc(50% - 8px) !important;
    margin-right: 0 !important;
    margin-bottom: 1.5em !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
}

#billing_last_name_field,
#shipping_last_name_field,
.woocommerce-checkout .woocommerce-billing-fields p.form-row-last,
.woocommerce-checkout .woocommerce-shipping-fields p.form-row-last,
.woocommerce-checkout .woocommerce-billing-fields .form-row.form-row-last,
.woocommerce-checkout .woocommerce-shipping-fields .form-row.form-row-last {
    flex: 0 0 calc(50% - 8px) !important;
    width: calc(50% - 8px) !important;
    max-width: calc(50% - 8px) !important;
    margin-right: 0 !important;
    margin-bottom: 1.5em !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Ensure labels are above inputs in the two-column fields */
#billing_first_name_field label,
#billing_last_name_field label,
#shipping_first_name_field label,
#shipping_last_name_field label,
.woocommerce-checkout .woocommerce-billing-fields .form-row-first label,
.woocommerce-checkout .woocommerce-billing-fields .form-row-last label,
.woocommerce-checkout .woocommerce-shipping-fields .form-row-first label,
.woocommerce-checkout .woocommerce-shipping-fields .form-row-last label {
    display: block !important;
    width: 100% !important;
    margin-bottom: 0.5em !important;
    order: -1 !important;
}

/* Ensure fields inside two-column layout are full width */
.woocommerce-checkout .woocommerce-billing-fields .form-row-first input,
.woocommerce-checkout .woocommerce-billing-fields .form-row-first select,
.woocommerce-checkout .woocommerce-billing-fields .form-row-last input,
.woocommerce-checkout .woocommerce-billing-fields .form-row-last select,
.woocommerce-checkout .woocommerce-shipping-fields .form-row-first input,
.woocommerce-checkout .woocommerce-shipping-fields .form-row-first select,
.woocommerce-checkout .woocommerce-shipping-fields .form-row-last input,
.woocommerce-checkout .woocommerce-shipping-fields .form-row-last select {
    width: 100% !important;
}

/* Labels should be properly styled */
.woocommerce-checkout .woocommerce-billing-fields label,
.woocommerce-checkout .woocommerce-shipping-fields label,
.woocommerce-checkout .woocommerce-additional-fields label {
    display: block !important;
    margin-bottom: 0.5em !important;
    font-weight: 500 !important;
    color: #374151 !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
}

/* Ensure select2 dropdowns work properly */
.woocommerce-checkout .select2-container {
    width: 100% !important;
    box-sizing: border-box !important;
}

.woocommerce-checkout .select2-container .select2-selection {
    border: 1px solid #d1d5db !important;
    border-radius: 4px !important;
    min-height: 48px !important;
    padding: 0 !important;
}

/* Make sure form containers don't break page builder layouts */
.woocommerce-checkout .woocommerce-billing-fields,
.woocommerce-checkout .woocommerce-shipping-fields,
.woocommerce-checkout .woocommerce-additional-fields {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* Hide empty form rows that might appear after phone number or elsewhere */
.woocommerce-checkout .woocommerce-billing-fields .form-row:empty,
.woocommerce-checkout .woocommerce-shipping-fields .form-row:empty,
.woocommerce-checkout .woocommerce-additional-fields .form-row:empty,
.woocommerce-checkout .woocommerce-billing-fields p.form-row:empty,
.woocommerce-checkout .woocommerce-shipping-fields p.form-row:empty,
.woocommerce-checkout .woocommerce-additional-fields p.form-row:empty {
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    visibility: hidden !important;
}

/* Hide form rows that only contain hidden inputs (no visible content) */
.woocommerce-checkout .woocommerce-billing-fields .form-row:only-child input[type="hidden"],
.woocommerce-checkout .woocommerce-shipping-fields .form-row:only-child input[type="hidden"] {
    display: none !important;
}

/* Hide form rows with minimal height that appear empty */
.woocommerce-checkout .woocommerce-billing-fields .form-row[style*="height: 0"],
.woocommerce-checkout .woocommerce-shipping-fields .form-row[style*="height: 0"] {
    display: none !important;
}

/* Fix place order button text visibility */
.woocommerce-checkout #place_order,
.woocommerce-checkout button[name="woocommerce_checkout_place_order"],
.woocommerce-checkout .woocommerce-checkout-place-order button,
.woocommerce-checkout .woocommerce-checkout-place-order #place_order {
    color: #ffffff !important;
    background-color: #2271b1 !important;
    border-color: #2271b1 !important;
    padding: 12px 24px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    line-height: 1.5 !important;
    text-align: center !important;
    cursor: pointer !important;
    border-radius: 4px !important;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out !important;
}

.woocommerce-checkout #place_order:hover,
.woocommerce-checkout button[name="woocommerce_checkout_place_order"]:hover,
.woocommerce-checkout .woocommerce-checkout-place-order button:hover {
    background-color: #135e96 !important;
    border-color: #135e96 !important;
    color: #ffffff !important;
}

.woocommerce-checkout #place_order:focus,
.woocommerce-checkout button[name="woocommerce_checkout_place_order"]:focus,
.woocommerce-checkout .woocommerce-checkout-place-order button:focus {
    outline: 2px solid #2271b1 !important;
    outline-offset: 2px !important;
    color: #ffffff !important;
}

