/* Delivery Instructions & Large Items Notice Styling */

/* Wallet Buttons Wrapper */
.delivery-wallet-buttons-wrapper {
    margin: 15px 0;
    padding: 0;
    box-sizing: border-box;
}

.delivery-wallet-buttons-wrapper > * {
    margin-bottom: 10px;
}

.delivery-wallet-buttons-wrapper > *:last-child {
    margin-bottom: 0;
}

/* Hide wrapper by default until JavaScript initializes */
#delivery-wallet-buttons-wrapper:not(.delivery-validation-passed),
#delivery-wallet-buttons-wrapper-checkout:not(.delivery-validation-passed) {
    display: none;
}

/* Show wrapper when validation passes */
#delivery-wallet-buttons-wrapper.delivery-validation-passed,
#delivery-wallet-buttons-wrapper-checkout.delivery-validation-passed {
    display: block !important;
}

/* Force all wallet button elements inside to be visible when validation passes */
#delivery-wallet-buttons-wrapper.delivery-validation-passed *,
#delivery-wallet-buttons-wrapper-checkout.delivery-validation-passed * {
    visibility: visible !important;
    opacity: 1 !important;
}

/* Specifically target Stripe elements */
#delivery-wallet-buttons-wrapper-checkout.delivery-validation-passed #wc-stripe-express-checkout-element,
#delivery-wallet-buttons-wrapper-checkout.delivery-validation-passed #wc-stripe-express-checkout-element-applePay,
#delivery-wallet-buttons-wrapper-checkout.delivery-validation-passed #wc-stripe-express-checkout-element-googlePay {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Force hide when validation failed */
#delivery-wallet-buttons-wrapper.delivery-validation-failed-hidden,
#delivery-wallet-buttons-wrapper-checkout.delivery-validation-failed-hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
}

/* Hide all contents when wrapper is hidden */
#delivery-wallet-buttons-wrapper.delivery-validation-failed-hidden *,
#delivery-wallet-buttons-wrapper-checkout.delivery-validation-failed-hidden * {
    display: none !important;
}

/* Cart Page Wrapper */
.delivery-instructions-wrapper {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
    box-sizing: border-box;
}

/* Field Containers */
.delivery-instructions-field,
.billing-phone-field,
.large-items-field,
.gdpr-field {
    margin-bottom: 15px;
}

.delivery-instructions-field:last-child,
.billing-phone-field:last-child,
.large-items-field:last-child,
.gdpr-field:last-child {
    margin-bottom: 0;
}

/* Labels */
.delivery-instructions-field label,
.billing-phone-field label,
.large-items-field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

/* Required Asterisk */
.required {
    color: #e74c3c;
    font-weight: bold;
    margin-left: 2px;
}

/* Text Input and Textarea */
.delivery-instructions-field input[type="text"],
.delivery-instructions-field textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    transition: border-color 0.3s ease;
}

.billing-phone-field input[type="tel"] {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 0 !important;
    font-size: 14px;
    box-sizing: border-box;
    transition: border-color 0.3s ease;
}

.delivery-instructions-field textarea {
    resize: none;
    font-family: inherit;
}

.delivery-instructions-field input[type="text"]:focus,
.delivery-instructions-field textarea:focus,
.billing-phone-field input[type="tel"]:focus {
    outline: none;
    border-color: #999;
}

.delivery-instructions-field input[type="text"].error-field,
.delivery-instructions-field textarea.error-field,
.billing-phone-field input[type="tel"].error-field {
    border-color: #e74c3c;
}

.delivery-instructions-field input[type="text"].error-field:focus,
.delivery-instructions-field textarea.error-field:focus,
.billing-phone-field input[type="tel"].error-field:focus {
    border-color: #e74c3c;
    box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.1);
}

/* Checkbox Container */
.large-items-field .checkbox-label,
.gdpr-field .checkbox-label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    margin: 0;
}

.large-items-field input[type="checkbox"],
.gdpr-field input[type="checkbox"] {
    margin-right: 10px;
    margin-top: 2px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.large-items-field input[type="checkbox"].error-field {
    outline: 2px solid #e74c3c;
    outline-offset: 2px;
}

.large-items-field .checkbox-label span,
.gdpr-field .checkbox-label span {
    flex: 1;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
}

.large-items-field .checkbox-label span .required {
    color: #e74c3c;
}

/* Error Messages */
.error-message {
    display: block;
    color: #e74c3c;
    font-size: 13px;
    margin-top: 8px;
    font-weight: 500;
}

/* Checkout Button States */
.checkout-button.disabled,
.wc-proceed-to-checkout a.disabled,
.checkout-button.delivery-disabled,
.wc-proceed-to-checkout a.delivery-disabled,
a.checkout-button.disabled,
.wc-forward.disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    border-color: #cccccc !important;
    color: #666666 !important;
}

/* Style disabled checkout button */
.wc-proceed-to-checkout .checkout-button:disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* Hide Stripe Wallet buttons when validation not passed */
body.large-items-notice-empty #wc-stripe-express-checkout-element,
body.large-items-notice-empty #wc-stripe-express-checkout-element-googlePay,
body.large-items-notice-empty #wc-stripe-express-checkout-element-applePay,
body.large-items-notice-empty #wc-stripe-express-checkout-element-link {
    display: none !important;
}

body.delivery-validation-failed #wc-stripe-express-checkout-element,
body.delivery-validation-failed #wc-stripe-express-checkout-element-googlePay,
body.delivery-validation-failed #wc-stripe-express-checkout-element-applePay,
body.delivery-validation-failed #wc-stripe-express-checkout-element-link {
    display: none !important;
}

/* Hide PayPal buttons when validation not passed */
body.large-items-notice-empty .ppcp-express-checkout-buttons,
body.large-items-notice-empty .ppcp-messages,
body.large-items-notice-empty #ppc-button-ppcp-gateway,
body.large-items-notice-empty [id^="ppcp-"],
body.large-items-notice-empty .woocommerce-paypal-payments-wrapper,
body.large-items-notice-empty .wc-ppcp-funding-source-wrapper {
    display: none !important;
}

body.delivery-validation-failed .ppcp-express-checkout-buttons,
body.delivery-validation-failed .ppcp-messages,
body.delivery-validation-failed #ppc-button-ppcp-gateway,
body.delivery-validation-failed [id^="ppcp-"],
body.delivery-validation-failed .woocommerce-paypal-payments-wrapper,
body.delivery-validation-failed .wc-ppcp-funding-source-wrapper {
    display: none !important;
}

/* Error message styling */
.large-items-checkbox-error {
    color: #e2401c;
    display: block;
    margin-top: 5px;
    font-size: 14px;
}

/* Force hide wallet buttons when validation not passed */
body .wc-block-components-express-payment__event-buttons,
body .wc-block-components-express-payment,
body .gpay-button,
body .google-pay-button,
body .apple-pay-button,
body [id*="paypal"],
body [class*="paypal"],
body [id*="apple-pay"],
body [class*="apple-pay"],
body [id*="google-pay"],
body [class*="google-pay"],
body [id*="gpay"],
body [class*="gpay"],
body #wc-stripe-payment-request-wrapper,
body #wc-stripe-payment-request-button,
body .wc-stripe-payment-request-button-separator,
body .payment_method_stripe_googlepay,
body .payment_method_stripe_applepay,
body .wcpay-payment-request-button,
body .wcpay-payment-request-button-wrapper,
body [data-payment-method-type="payment_request"],
body .wc-gateway-ppcp-payment-buttons,
body .ppcp-button-container,
body #ppc-button-ppcp-gateway,
body .express-payment-buttons,
body .payment-request-button {
    /* These will be hidden by JavaScript initially */
}

/* When explicitly hidden by our plugin */
.delivery-instructions-hide-wallet {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
}

/* Checkout Page Styles */
.large-items-checkout-field .form-row {
    margin: 0;
    padding: 0;
}

.large-items-checkout-field .checkbox {
    display: flex;
    align-items: flex-start;
    margin: 0;
}

.large-items-checkout-field input[type="checkbox"] {
    margin-right: 10px;
    margin-top: 2px;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Character Counter */
.char-counter {
    display: block;
    font-size: 12px;
    color: #666;
    margin-top: 5px;
    text-align: right;
}

/* Order Comments Field on Checkout */
#order_comments_field textarea {
    max-height: 100px;
    min-height: 60px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .delivery-instructions-wrapper {
        padding: 15px;
    }
    
    .delivery-instructions-field input[type="text"],
    .delivery-instructions-field textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .large-items-field .checkbox-label span,
    .large-items-checkout-field .checkbox span {
        font-size: 13px;
    }
}

/* WooCommerce compatibility */
.woocommerce .delivery-instructions-wrapper,
.woocommerce-page .delivery-instructions-wrapper {
    width: 100%;
}

/* Terms Notice */
.terms-notice,
.terms-notice-checkout {
    margin-top: 15px;
    padding: 12px 15px;
    background-color: #f6f5f5;
    font-size: 16px;
    line-height: 1.6;
}

.terms-notice p,
.terms-notice-checkout p {
    margin: 0;
    color: #555;
}

/* Prevent gray background on links when checkout button disabled */
.terms-notice a,
.terms-notice-checkout a {
    background-color: transparent !important;
}

/* Checkout specific - before place order button */
.terms-notice-checkout {
    margin-bottom: 15px;
}

/* Responsive font size for small screens */
@media (max-width: 768px) {
    .terms-notice,
    .terms-notice-checkout {
        font-size: 14px;
    }
}

/* Hide wallet buttons when .woocommerce has minimum-not-reached class */
body.minimum-not-reached #wc-stripe-express-checkout-element-googlePay,
body.minimum-not-reached #wc-stripe-express-checkout-element,
body.minimum-not-reached [id*="express-checkout-element"],
body.minimum-not-reached [id*="googlePay"],
body.minimum-not-reached .StripeElement,
body.minimum-not-reached #delivery-wallet-buttons-wrapper,
body.minimum-not-reached #payment-request-button,
body.minimum-not-reached #apple-pay-button,
body.minimum-not-reached #google-pay-button,
body.minimum-not-reached .apple-pay-button,
body.minimum-not-reached .google-pay-button,
body.minimum-not-reached [id*="apple-pay"],
body.minimum-not-reached [id*="google-pay"],
body.minimum-not-reached [id*="payment-request"],
body.minimum-not-reached [class*="apple-pay"],
body.minimum-not-reached [class*="google-pay"],
body.minimum-not-reached [class*="payment-request"],
body.minimum-not-reached .stripe-payment-request-button-element,
body.minimum-not-reached div[id*="stripe-payment-request"],
body.minimum-not-reached .wc-block-components-express-payment,
.woocommerce.minimum-not-reached #wc-stripe-express-checkout-element-googlePay,
.woocommerce.minimum-not-reached #wc-stripe-express-checkout-element,
.woocommerce.minimum-not-reached [id*="express-checkout-element"],
.woocommerce.minimum-not-reached [id*="googlePay"],
.woocommerce.minimum-not-reached .StripeElement,
.woocommerce.minimum-not-reached #delivery-wallet-buttons-wrapper,
.woocommerce.minimum-not-reached #payment-request-button,
.woocommerce.minimum-not-reached #apple-pay-button,
.woocommerce.minimum-not-reached #google-pay-button,
.woocommerce.minimum-not-reached .apple-pay-button,
.woocommerce.minimum-not-reached .google-pay-button,
.woocommerce.minimum-not-reached [id*="apple-pay"],
.woocommerce.minimum-not-reached [id*="google-pay"],
.woocommerce.minimum-not-reached [id*="payment-request"],
.woocommerce.minimum-not-reached [class*="apple-pay"],
.woocommerce.minimum-not-reached [class*="google-pay"],
.woocommerce.minimum-not-reached [class*="payment-request"],
.woocommerce.minimum-not-reached .stripe-payment-request-button-element,
.woocommerce.minimum-not-reached div[id*="stripe-payment-request"],
.woocommerce.minimum-not-reached .wc-block-components-express-payment {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
}

/* Checkout Button Spinner Overlay */
#delivery-checkout-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
}

#delivery-checkout-spinner .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #333;
    border-radius: 50%;
    animation: delivery-spin 1s linear infinite;
}

@keyframes delivery-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Hide WooCommerce default order comments field */
.hidden-field,
.woocommerce-checkout .form-row.notes,
#order_comments_field {
    display: none !important;
}

/* Hide Stripe Express Checkout button separator */
#wc-stripe-express-checkout-button-separator {
    display: none !important;
}
