/* ===================================
   Checkout Page - Design
   =================================== */

body.woocommerce-checkout {
    background: #f5f7fa;
    font-family: 'Tajawal', sans-serif;
}

.woocommerce-checkout .woocommerce {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* Container */
.custom-checkout-wrapper {
    direction: rtl;
}

/* Header */
.checkout-header {
    text-align: center;
    margin-bottom: 40px;
    padding: 40px;
    background: linear-gradient(135deg, #a8d5ba 0%, #7cb89d 100%);
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(124, 184, 157, 0.2);
}

.checkout-title {
    font-size: 32px;
    font-weight: 700;
    margin: 0 0 10px 0;
    color: #1a202c;
}

.checkout-subtitle {
    font-size: 15px;
    color: #2d3748;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* Layout */
.checkout-layout {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 30px;
    align-items: start;
    width: 100%;
}

/* Sidebar */
.checkout-sidebar {
    position: sticky;
    top: 20px;
    width: 100%;
}

.checkout-main {
    width: 100%;
    min-width: 0;
    /* prevents overflow in grid */
}


.order-summary-box {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
}

.order-summary-box>h3,
.order-summary-box .section-heading {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 25px 0;
    padding-bottom: 15px;
    border-bottom: 2px solid #edf2f7;
    color: #1a202c;
}

/* Product Items */
.checkout-product-item {
    display: flex;
    gap: 15px;
    padding: 20px 0;
    border-bottom: 1px solid #f7fafc;
    align-items: flex-start;
}

.product-details {
    flex: 1;
}

.product-name {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #1a202c;
    line-height: 1.4;
}

.product-meta {
    font-size: 13px;
    color: #718096;
    margin: 0;
    line-height: 1.6;
}

.product-price-desktop {
    font-size: 16px;
    font-weight: 700;
    color: #7cb89d;
}

.product-price-mobile {
    display: none;
}

/* Section Headings */
.section-heading {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 25px 0;
    padding-bottom: 15px;
    border-bottom: 2px solid #edf2f7;
    color: #1a202c;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Contact & Payment Sections */
.contact-section,
.payment-section {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

/* ==========================================
   ENHANCED BILLING FIELDS
   ========================================== */

.custom-billing-fields {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.field-row {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.field-row.two-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.field-row.single-column {
    display: block;
}

/* Form field styling */
.custom-billing-fields .form-row {
    margin: 0 !important;
}

.custom-billing-fields label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 8px;
}

.custom-billing-fields label .required {
    color: #e53e3e;
}

.custom-billing-fields input[type="text"],
.custom-billing-fields input[type="email"],
.custom-billing-fields input[type="tel"],
.custom-billing-fields select {
    width: 100%;
    padding: 14px 16px;
    font-size: 15px;
    font-family: 'Tajawal', sans-serif;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    transition: all 0.3s ease;
    color: #1a202c;
}

.custom-billing-fields input[type="text"]:focus,
.custom-billing-fields input[type="email"]:focus,
.custom-billing-fields input[type="tel"]:focus,
.custom-billing-fields select:focus {
    outline: none;
    border-color: #7cb89d;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(124, 184, 157, 0.15);
}

.custom-billing-fields input::placeholder {
    color: #a0aec0;
}

/* Ensure City and Address fields match exactly */
#billing_city,
#billing_address_1,
.custom-billing-fields input[type="text"],
.custom-billing-fields input[type="email"],
.custom-billing-fields input[type="tel"],
.custom-billing-fields select {
    border: 1.5px solid #e2e8f0 !important;
    border-radius: 12px !important;
    background-color: #f8fafc !important;
    transition: all 0.2s ease !important;
}

.custom-billing-fields input:hover,
.custom-billing-fields select:hover,
#billing_city:hover,
#billing_address_1:hover {
    border-color: #cbd5e0 !important;
    background-color: #edf2f7 !important;
}

/* Invalid state - Consolidated & Strengthened */
#billing_city.woocommerce-invalid,
#billing_city[aria-invalid="true"],
#billing_address_1.woocommerce-invalid,
#billing_address_1[aria-invalid="true"],
.woocommerce-invalid input,
.woocommerce-invalid select,
.woocommerce-invalid textarea,
.form-row.woocommerce-invalid input,
.form-row.woocommerce-invalid select,
.form-row.woocommerce-invalid textarea,
input.woocommerce-invalid,
select.woocommerce-invalid,
textarea.woocommerce-invalid,
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: #e53e3e !important;
    border-width: 1.5px !important;
    background-color: #fff5f5 !important;
    box-shadow: 0 0 0 1px #e53e3e !important;
    transition: all 0.2s ease !important;
}

.custom-billing-fields .woocommerce-validated input {
    border-color: #68d391;
}

/* Hide wc-order-attribution-inputs */
wc-order-attribution-inputs {
    display: none;
}

/* Field wrapper enhancement */
.custom-billing-fields .woocommerce-input-wrapper {
    display: block;
}

/* Optional field label */
.custom-billing-fields label:not(.required_field) {
    font-weight: 500;
    color: #4a5568;
}

/* Section heading icon */
.section-heading {
    position: relative;
}

.section-heading::before {
    content: "";
    position: absolute;
    right: 0;
    bottom: -17px;
    left: 0;
    height: 2px;
    background: linear-gradient(90deg, #7cb89d 0%, transparent 100%);
}

/* Form field hover effect */
.custom-billing-fields input:hover,
.custom-billing-fields select:hover {
    border-color: #cbd5e0;
}

/* Focus ring enhancement */
@keyframes field-focus {
    0% {
        box-shadow: 0 0 0 0 rgba(124, 184, 157, 0.4);
    }

    100% {
        box-shadow: 0 0 0 3px rgba(124, 184, 157, 0.15);
    }
}

.custom-billing-fields input:focus,
.custom-billing-fields select:focus {
    animation: field-focus 0.3s ease;
}

/* ==========================================
   PAYMENT METHODS - ENHANCED DESIGN
   ========================================== */

.payment-methods-wrapper {
    margin-top: 20px;
}

.wc_payment_methods {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow: visible;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.wc_payment_methods li {
    margin: 0;
    padding: 18px 20px;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    display: flex;
    flex-wrap: wrap;
    /* Allow payment_box to drop to next line */
    align-items: center;
    gap: 0;
    row-gap: 0;
    overflow: visible;
    position: relative;
    background: #ffffff;
}

/* Hover effect */
.wc_payment_methods li:hover {
    border-color: #7cb89d;
    background: linear-gradient(135deg, #f7fbfa 0%, #f0fdf9 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(124, 184, 157, 0.15);
}

/* Selected state */
.wc_payment_methods li.selected,
.wc_payment_methods li:has(input:checked) {
    border-color: #7cb89d;
    background: linear-gradient(135deg, #f0f9f4 0%, #dcfce7 100%);
    box-shadow: 0 4px 20px rgba(124, 184, 157, 0.25);
}

/* Selected indicator - checkmark badge */
.wc_payment_methods li.selected::before,
.wc_payment_methods li:has(input:checked)::before {
    content: "✓";
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #7cb89d 0%, #5a9d7e 100%);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(124, 184, 157, 0.4);
    animation: popIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* HIDE default radio button - the label is the click target
   CRITICAL: Keep input in DOM for form submission, but hide visually */
.wc_payment_methods input[type="radio"] {
    position: absolute !important;
    left: -9999px !important;
    top: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
    /* NOT display:none - that would break form submission! */
}

/* Redundant backup for input-radio class */
.wc_payment_methods .input-radio {
    position: absolute !important;
    left: -9999px !important;
    top: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Radio button states are now handled by li.selected/:has(input:checked) states above
   The actual input[type="radio"] is hidden and the label is the click target */

/* Removed unused @keyframes dotPop animation */

/* Payment method label - main label text */
.wc_payment_methods label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 17px;
    font-weight: 700;
    color: #1a202c;
    flex: 1;
    gap: 12px;
    transition: color 0.3s ease;
    user-select: none;
    line-height: 1.4;
}

/* Selected label styling */
.wc_payment_methods li.selected label,
.wc_payment_methods li:has(input:checked) label {
    color: #065f46;
}

.wc_payment_methods li:hover label {
    color: #2d3748;
}

.wc_payment_methods label img {
    width: 60px;
    height: auto;
    max-height: 35px;
    object-fit: contain;
    margin-left: auto;
    filter: grayscale(20%);
    transition: all 0.3s ease;
    padding: 8px 12px;
    background: white;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.wc_payment_methods li:hover label img {
    filter: grayscale(0%);
    transform: scale(1.05);
    border-color: #7cb89d;
}

.wc_payment_methods li.selected label img,
.wc_payment_methods li:has(input:checked) label img {
    filter: grayscale(0%);
    border-color: #7cb89d;
    box-shadow: 0 2px 8px rgba(124, 184, 157, 0.2);
}

/* Payment method label text enhancement */
.wc_payment_methods label>span {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.wc_payment_methods label .payment-name {
    font-size: 16px;
    font-weight: 600;
    color: #1a202c;
}

.wc_payment_methods label .payment-desc {
    font-size: 13px;
    font-weight: 400;
    color: #718096;
}

/* Badge for recommended payment method */
.wc_payment_methods li.recommended {
    border-color: #f6ad55;
    background: linear-gradient(135deg, #fffaf0 0%, #fff7ed 100%);
}

.wc_payment_methods li.recommended::after {
    content: "موصى به";
    position: absolute;
    top: 10px;
    left: 10px;
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    box-shadow: 0 2px 6px rgba(237, 137, 54, 0.3);
}

.wc_payment_methods li.recommended:hover {
    border-color: #ed8936;
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
}

.wc_payment_methods li.recommended.selected,
.wc_payment_methods li.recommended:has(input:checked) {
    border-color: #ed8936;
    background: linear-gradient(135deg, #ffedd5 0%, #fed7aa 100%);
}

/* Payment Box - Always show for selected payment method */
.wc_payment_methods li.selected .payment_box,
.wc_payment_methods li:has(input:checked) .payment_box {
    display: block !important;
    flex-basis: 100% !important;
    /* Force full width so it sits on its own line */
    width: 100% !important;
    margin-top: 8px;
    padding: 10px 0 2px 0;
    background: transparent !important;
    border: none !important;
    border-top: 1px solid #e2e8f0 !important;
    border-radius: 0;
    position: relative;
    z-index: 1;
}

/* Payment box text styling */
.wc_payment_methods li.selected .payment_box p,
.wc_payment_methods li:has(input:checked) .payment_box p {
    margin: 0;
    padding: 0;
    font-size: 14px;
    color: #718096;
    line-height: 1.6;
}

/* Payment Box - Hidden by default, shown when selected */
.payment_box {
    display: none;
    margin-top: 15px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    position: relative;
    z-index: 1;
}

/* Terms & Conditions */
.terms-section {
    background: #f0fdf5;
    border-radius: 12px;
    padding: 20px;
}

.terms-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    font-size: 14px;
    color: #065f46;
    line-height: 1.6;
}

.terms-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-width: 20px;
    margin-top: 2px;
    cursor: pointer;
    accent-color: #10b981;
    flex-shrink: 0;
}

/* Place Order Button */
#place_order,
.custom-place-order-btn {
    width: 100%;
    background: linear-gradient(135deg, #7cb89d 0%, #5a9d7e 100%);
    color: white;
    border: none;
    padding: 18px 40px;
    font-size: 18px;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(124, 184, 157, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
    font-family: 'Tajawal', sans-serif;
    pointer-events: auto !important;
    z-index: 9999 !important;
    position: relative !important;
}

#place_order:hover,
.custom-place-order-btn:hover {
    background: linear-gradient(135deg, #5a9d7e 0%, #4a8a6a 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(124, 184, 157, 0.5);
}

#place_order:active,
.custom-place-order-btn:active {
    transform: translateY(0);
}

/* Shake animation for disabled button tap on mobile */
#place_order.shake-animation,
.custom-place-order-btn.shake-animation {
    animation: shake-disabled 0.5s ease-in-out;
}

@keyframes shake-disabled {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-10px);
    }

    40% {
        transform: translateX(10px);
    }

    60% {
        transform: translateX(-10px);
    }

    80% {
        transform: translateX(10px);
    }
}

/* Hide WooCommerce default payment section - BUT keep it functional for AJAX
   CRITICAL: Do NOT remove from DOM or set width/height to 0 - this breaks checkout updates */
.woocommerce-checkout-payment {
    position: absolute !important;
    left: -9999px !important;
    top: -9999px !important;
    visibility: hidden !important;
    /* Don't set width/height to 0 - WooCommerce needs this element for AJAX updates */
    /* Don't use display:none - that would remove it from DOM completely */
}

/* Hide the place order button inside WooCommerce's payment section */
.woocommerce-checkout-payment .place-order,
.woocommerce-checkout-payment #place_order {
    display: none !important;
    visibility: hidden !important;
}

/* Hide WooCommerce's native coupon form that may duplicate */
.woocommerce-form-coupon-toggle,
.woocommerce-checkout .woocommerce-form-coupon,
.woocommerce-checkout .coupon-form,
.woocommerce-checkout .checkout_coupon {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    left: -9999px !important;
}

/* Also hide WooCommerce coupon notices that might conflict with custom UI */
.woocommerce-checkout>.woocommerce-info:has(.showcoupon),
.woocommerce-checkout>.woocommerce-info:contains('كوبون'),
.woocommerce-checkout>.woocommerce-info:contains('coupon') {
    display: none !important;
}

/* CRITICAL: Prevent duplication - ensure only one checkout layout is visible */
.woocommerce-checkout .checkout-layout:not(.custom-checkout-wrapper .checkout-layout) {
    display: none !important;
}

/* Hide Default Table */
.woocommerce-checkout-review-order-table {
    display: none;
}

/* Security Features */
.security-features {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #edf2f7;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.security-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #4a5568;
}

.security-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #7cb89d;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

/* ==========================================
   RESPONSIVE - FIX MOBILE ISSUES
   ========================================== */

/* Tablet & Mobile: single column stacked layout */
@media (max-width: 1024px) {
    .checkout-layout {
        display: flex !important;
        /* Force flexbox over grid */
        flex-direction: column !important;
        gap: 20px !important;
    }

    .checkout-main,
    .checkout-sidebar {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        position: relative !important;
        top: 0 !important;
    }

    /* Form fields appear FIRST, then order summary below */
    .checkout-main {
        order: 1;
    }

    .checkout-sidebar {
        order: 2;
    }
}


/* Mobile */
@media (max-width: 768px) {

    /* CRITICAL: Prevent any duplicate checkout layouts on mobile
       NOTE: Do NOT hide form inputs or radio buttons - they must submit!
       IMPORTANT: Also do NOT apply this on the order-received (thank-you) page!
       body.woocommerce-checkout is applied to BOTH checkout AND order-received pages. */
    body.woocommerce-checkout:not(.woocommerce-order-received) .woocommerce>*:not(.custom-checkout-wrapper),
    body.woocommerce-checkout:not(.woocommerce-order-received) form.checkout>*:not(.checkout-layout) {
        display: none !important;
    }

    /* Ensure only our custom wrapper is visible on checkout form */
    body.woocommerce-checkout:not(.woocommerce-order-received) .custom-checkout-wrapper {
        display: block !important;
        width: 100% !important;
    }

    /* CRITICAL: Ensure order-received thank-you page content is visible on mobile */
    body.woocommerce-order-received .woocommerce,
    body.woocommerce-order-received .woocommerce-order,
    body.woocommerce-order-received .tawon-thankyou-wrapper,
    body.woocommerce-order-received .tawon-success-banner,
    body.woocommerce-order-received .tawon-overview-cards,
    body.woocommerce-order-received .tawon-order-details-section,
    body.woocommerce-order-received .woocommerce-customer-details {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }


    .checkout-header {
        padding: 30px 20px;
    }

    .checkout-title {
        font-size: 24px;
    }

    .contact-section,
    .payment-section,
    .order-summary-box {
        padding: 25px 20px;
        position: relative;
        z-index: 1;
    }

    .product-price-desktop {
        display: none;
    }

    .product-price-mobile {
        display: block;
        margin-top: 8px;
        font-size: 15px;
        font-weight: 700;
        color: #7cb89d;
    }

    /* Enhanced billing fields - mobile */
    .field-row.two-columns {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .custom-billing-fields {
        gap: 15px;
    }

    .custom-billing-fields input[type="text"],
    .custom-billing-fields input[type="email"],
    .custom-billing-fields input[type="tel"],
    .custom-billing-fields select {
        padding: 12px 14px;
        font-size: 16px;
    }

    /* Payment Methods - ENHANCED MOBILE STYLING */
    .wc_payment_methods {
        gap: 10px !important;
    }

    .wc_payment_methods li {
        padding: 16px 15px !important;
        min-height: 60px !important;
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        border-radius: 14px !important;
    }

    /* Checkmark badge - adjust position for RTL */
    .wc_payment_methods li.selected::before,
    .wc_payment_methods li:has(input:checked)::before {
        width: 26px !important;
        height: 26px !important;
        font-size: 13px !important;
        top: -6px !important;
        right: -6px !important;
    }

    /* RTL support - adjust badge position */
    html[dir="rtl"] .wc_payment_methods li.selected::before,
    html[dir="rtl"] .wc_payment_methods li:has(input:checked)::before {
        left: -6px !important;
        right: auto !important;
    }

    /* Radio button is hidden on all screen sizes - label is the click target
       See desktop CSS above for .wc_payment_methods input[type="radio"] rules */

    /* Ensure .input-radio is also hidden on mobile */
    .wc_payment_methods .input-radio::before,
    .wc_payment_methods .input-radio::after {
        display: none !important;
        content: none !important;
    }

    /* Label styling - better for mobile touch */
    .wc_payment_methods label {
        font-size: 15px !important;
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        width: auto !important;
        flex: 1 !important;
        pointer-events: auto !important;
        min-height: 44px !important;
        /* iOS touch target */
    }

    /* Payment name and desc styling */
    .wc_payment_methods label .payment-name {
        font-size: 15px !important;
    }

    .wc_payment_methods label .payment-desc {
        font-size: 12px !important;
    }

    /* Icons - larger touch targets */
    .wc_payment_methods label img {
        width: 50px !important;
        max-height: 30px !important;
        padding: 6px 10px !important;
    }

    /* Recommended badge - smaller on mobile */
    .wc_payment_methods li.recommended::after {
        font-size: 10px !important;
        padding: 3px 8px !important;
        top: 8px !important;
        left: 8px !important;
    }

    /* RTL support for recommended badge */
    html[dir="rtl"] .wc_payment_methods li.recommended::after {
        right: 8px !important;
        left: auto !important;
    }

    /* Payment box for mobile - show for selected */
    .wc_payment_methods li.selected .payment_box,
    .wc_payment_methods li:has(input:checked) .payment_box {
        display: block !important;
        visibility: visible !important;
        margin-top: 8px !important;
        padding: 10px 0 !important;
        background: transparent !important;
        border: none !important;
        position: relative !important;
        z-index: 1 !important;
    }

    /* Payment box text on mobile */
    .wc_payment_methods li.selected .payment_box p,
    .wc_payment_methods li:has(input:checked) .payment_box p {
        margin: 0 !important;
        padding: 0 !important;
        font-size: 13px !important;
        color: #718096 !important;
        line-height: 1.6 !important;
    }

    /* Label styling - better for mobile touch */
    .wc_payment_methods label {
        font-size: 16px !important;
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        width: auto !important;
        flex: 1 !important;
        pointer-events: auto !important;
        min-height: 44px !important;
        font-weight: 700 !important;
        /* iOS touch target */
    }

    /* Selected label on mobile */
    .wc_payment_methods li.selected label,
    .wc_payment_methods li:has(input:checked) label {
        color: #065f46 !important;
    }

    /* Button - ensure clickable on mobile */
    #place_order,
    .custom-place-order-btn {
        z-index: 9999 !important;
        position: relative !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(124, 184, 157, 0.3) !important;
        min-height: 56px !important;
        /* iOS minimum touch target */
        font-size: 17px !important;
    }

    /* Terms checkbox */
    .terms-checkbox input[type="checkbox"],
    #terms {
        pointer-events: auto !important;
        visibility: visible !important;
        display: inline-block !important;
        width: 22px !important;
        height: 22px !important;
        min-width: 22px !important;
    }

    /* Form inputs */
    .custom-billing-fields input,
    .custom-billing-fields select,
    #billing_phone,
    #billing_email {
        pointer-events: auto !important;
        cursor: text !important;
        position: relative !important;
        z-index: 1 !important;
        font-size: 16px !important;
        /* Prevents iOS zoom on focus */
    }

    /* Payment method radio buttons - CRITICAL: keep in DOM for form submission */
    .wc_payment_methods input[type="radio"].input-radio {
        position: absolute !important;
        left: -9999px !important;
        opacity: 0 !important;
        /* display:none is FORBIDDEN here - would break form submission */
    }

    .wc_payment_methods label {
        position: relative !important;
        z-index: 1 !important;
        touch-action: manipulation !important;
        min-height: 48px !important;
        /* Android touch target */
    }

    /* Payment list items */
    .wc_payment_methods li {
        touch-action: manipulation !important;
        cursor: pointer !important;
    }

    /* Order summary box on mobile - less padding */
    .order-summary-box {
        padding: 20px 15px !important;
    }

    /* Coupon section mobile */
    .coupon-section {
        margin-top: 15px;
    }

    /* Security features - horizontal scroll on very small screens */
    .security-features {
        gap: 8px;
    }

    .security-item {
        font-size: 13px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .woocommerce-checkout .woocommerce {
        padding: 15px 12px;
    }

    .contact-section,
    .payment-section {
        padding: 20px 15px;
    }

    .section-heading {
        font-size: 16px;
    }

    #place_order,
    .custom-place-order-btn {
        font-size: 16px !important;
        padding: 16px 20px !important;
    }

    .wc_payment_methods li {
        padding: 14px 12px !important;
    }

    .wc_payment_methods label img {
        width: 45px !important;
    }
}

/* ============================
   STICKY MOBILE CHECKOUT BUTTON
   Shows a floating checkout bar at the bottom on mobile
   ============================ */
@media (max-width: 768px) {

    /* Add bottom padding to avoid content hidden behind sticky bar */
    body.woocommerce-checkout {
        padding-bottom: 80px;
    }

    /* Sticky checkout bar - appears when user scrolls */
    .tawon-sticky-checkout {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 88888;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        padding: 12px 16px;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
        border-top: 1px solid #e2e8f0;
        display: none;
        /* shown via JS after scroll */
        align-items: center;
        gap: 12px;
    }

    .tawon-sticky-checkout.visible {
        display: flex;
    }

    .tawon-sticky-checkout-total {
        flex: 1;
        font-size: 14px;
        font-weight: 600;
        color: #1a202c;
        direction: rtl;
    }

    .tawon-sticky-checkout-total span {
        display: block;
        font-size: 12px;
        color: #718096;
        font-weight: 400;
    }

    .tawon-sticky-checkout-btn {
        background: linear-gradient(135deg, #7cb89d 0%, #5a9d7e 100%);
        color: white;
        border: none;
        padding: 14px 24px;
        border-radius: 12px;
        font-size: 15px;
        font-weight: 700;
        font-family: 'Tajawal', sans-serif;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(124, 184, 157, 0.3);
        box-shadow: 0 4px 12px rgba(124, 184, 157, 0.4);
        white-space: nowrap;
    }
}


/* ===================================
   ENHANCED ERROR DISPLAY
   Ensures WooCommerce errors are visible and properly styled
   =================================== */

/* Main error container */
.woocommerce-error,
.woocommerce-message,
.woocommerce-info {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    background: #fff;
    border: 2px solid #e53e3e;
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
    position: relative;
    z-index: 1000;
    box-shadow: 0 4px 15px rgba(229, 62, 62, 0.15);
    direction: rtl;
    text-align: right;
}

/* Error styling specifically */
.woocommerce-error {
    border-color: #e53e3e;
    background: linear-gradient(135deg, #fff5f5 0%, #fff 100%);
}

/* Success styling */
.woocommerce-message {
    border-color: #38a169;
    background: linear-gradient(135deg, #f0fff4 0%, #fff 100%);
}

/* Info styling */
.woocommerce-info {
    border-color: #3182ce;
    background: linear-gradient(135deg, #ebf8ff 0%, #fff 100%);
}

/* Error heading */
.woocommerce-error strong {
    color: #e53e3e;
    font-size: 16px;
    font-weight: 700;
    display: block;
    margin-bottom: 10px;
}

/* Success heading */
.woocommerce-message strong {
    color: #38a169;
    font-size: 16px;
    font-weight: 700;
}

/* Error list */
.woocommerce-error ul,
.woocommerce-error li {
    color: #2d3748;
    font-size: 15px;
    line-height: 1.6;
    margin: 5px 0;
    padding-right: 20px;
}

/* Fix WooCommerce Blocks notice banner styling */
.wc-block-components-notice-banner {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    align-items: flex-start;
    gap: 12px;
    background: white !important;
    border-radius: 12px !important;
    border: 1px solid #e2e8f0 !important;
    padding: 16px 20px !important;
    margin: 16px 0 !important;
    /* direction will be inherited from the page's html[dir] or body */
}

/* RTL (Arabic) pages */
html[dir="rtl"] .wc-block-components-notice-banner,
body.rtl .wc-block-components-notice-banner {
    direction: rtl !important;
    text-align: right !important;
}

/* LTR (English) pages */
html[dir="ltr"] .wc-block-components-notice-banner,
body:not(.rtl) .wc-block-components-notice-banner {
    direction: ltr !important;
    text-align: left !important;
}

.wc-block-components-notice-banner.is-success {
    border-color: #38a169 !important;
    background: #f0fff4 !important;
}

.wc-block-components-notice-banner.is-success svg {
    color: #38a169 !important;
    fill: #38a169 !important;
    flex-shrink: 0;
    width: 24px !important;
    height: 24px !important;
    min-width: 24px;
}

.wc-block-components-notice-banner.is-error {
    border-color: #e53e3e !important;
    background: #fff5f5 !important;
}

.wc-block-components-notice-banner__content {
    flex: 1;
    color: #2d3748 !important;
    font-size: 15px !important;
    line-height: 1.6 !important;
}

.wc-block-components-notice-banner.is-error svg,
.wc-block-components-notice-banner svg {
    flex-shrink: 0;
    width: 24px !important;
    height: 24px !important;
    min-width: 24px;
}

/* Ensure errors are visible in checkout form */
.woocommerce-checkout .woocommerce-error,
.woocommerce-checkout .woocommerce-message,
.woocommerce-checkout .woocommerce-info,
.checkout-main .woocommerce-error,
.checkout-main .woocommerce-message,
.checkout-main .woocommerce-info {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Error at top of checkout */
.custom-checkout-wrapper .woocommerce-error:first-child,
.custom-checkout-wrapper>.woocommerce-error {
    margin-top: 20px;
}

/* Highlight invalid fields */
.woocommerce-invalid .input-text,
.woocommerce-invalid select,
.woocommerce-invalid input[type="text"],
.woocommerce-invalid input[type="email"],
.woocommerce-invalid input[type="tel"],
input.woocommerce-invalid,
select.woocommerce-invalid {
    border-color: #e53e3e !important;
    background-color: #fff5f5 !important;
    box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.1) !important;
}

/* Required field indicator */
.form-row .required {
    color: #e53e3e;
    font-weight: bold;
}

/* Hide empty/hidden WooCommerce notices that might be styled as blocks */
.woocommerce-error:empty,
.woocommerce-message:empty,
.woocommerce-info:empty {
    display: none !important;
}

/* Scroll to error when validation fails */
.woocommerce-checkout.processing .woocommerce-error {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-10px);
    }

    75% {
        transform: translateX(10px);
    }
}

/* Fix for hidden fields - make city field visible */
#billing_city_field {
    display: block !important;
    visibility: visible !important;
}

#billing_city {
    width: 100% !important;
    padding: 12px 15px !important;
    border: 1.5px solid #e2e8f0 !important;
    border-radius: 12px !important;
    font-size: 15px !important;
    background-color: #f8fafc !important;
    color: #2d3748 !important;
    transition: all 0.2s ease !important;
}

#billing_city:focus {
    outline: none !important;
    border-color: #7cb89d !important;
    box-shadow: 0 0 0 3px rgba(124, 184, 157, 0.1) !important;
}

/* ==========================================
   FIX AUTOFILL INTERFERENCE
   Allow users to manually edit all billing fields
   ========================================== */

/* Disable autofill popup styling that blocks input */
#billing_city:-webkit-autofill,
#billing_city:-webkit-autofill:hover,
#billing_city:-webkit-autofill:focus,
#billing_email:-webkit-autofill,
#billing_email:-webkit-autofill:hover,
#billing_email:-webkit-autofill:focus,
#billing_phone:-webkit-autofill,
#billing_phone:-webkit-autofill:hover,
#billing_phone:-webkit-autofill:focus,
#billing_first_name:-webkit-autofill,
#billing_first_name:-webkit-autofill:hover,
#billing_first_name:-webkit-autofill:focus,
#billing_last_name:-webkit-autofill,
#billing_last_name:-webkit-autofill:hover,
#billing_last_name:-webkit-autofill:focus {
    -webkit-text-fill-color: #2d3748 !important;
    -webkit-box-shadow: 0 0 0px 1000px #f8fafc inset !important;
    transition: background-color 5000s ease-in-out 0s !important;
    caret-color: #2d3748 !important;
}

/* Make billing fields fully editable */
#billing_city,
#billing_email,
#billing_phone,
#billing_first_name,
#billing_last_name {
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
}

/* RTL for phone field on Arabic pages */
html[lang^="ar"] #billing_phone,
html[dir="rtl"] #billing_phone {
    direction: rtl !important;
    text-align: right !important;
}

/* LTR for phone field on English pages */
html[lang^="en"] #billing_phone,
html[dir="ltr"] #billing_phone {
    direction: ltr !important;
    text-align: left !important;
}

/* Remove readonly attribute effect - use JS if needed, not CSS (readonly is not a valid CSS property) */
#billing_city[readonly],
#billing_email[readonly],
#billing_phone[readonly],
#billing_first_name[readonly],
#billing_last_name[readonly] {
    background-color: #f8fafc !important;
    cursor: text !important;
    pointer-events: auto !important;
    color: #2d3748 !important;
}

/* Field container visibility */
#billing_city_field,
#billing_email_field,
#billing_phone_field {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* City field specific styling - make it prominent */
#billing_city_field label {
    color: #2d3748 !important;
    font-weight: 600 !important;
    font-size: 15px !important;
    display: block !important;
    margin-bottom: 8px !important;
}

#billing_city_field .required {
    color: #e53e3e !important;
}

/* ==========================================
   INLINE ERROR VALIDATION STYLES
   ========================================== */

/* Hide global WooCommerce error containers as per user request */
.woocommerce-error,
.woocommerce-message,
.woocommerce-info,
.tawzon-error-container,
.tawzon-checkout-error {
    display: none !important;
}

/* Style for inline error messages below fields */
.field-error-message {
    color: #e53e3e !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    margin: 6px 0 0 0 !important;
    display: block !important;
    text-align: right !important;
    /* Right align for Arabic */
    animation: field-error-shake 0.4s ease-in-out;
}

/* RELIABLE INVALID FIELD STYLING - High Specificity */
.woocommerce-checkout .woocommerce .woocommerce-invalid input,
.woocommerce-checkout .woocommerce .woocommerce-invalid select,
.woocommerce-checkout .woocommerce .woocommerce-invalid textarea,
.woocommerce-checkout .woocommerce input.woocommerce-invalid,
.woocommerce-checkout .woocommerce select.woocommerce-invalid,
.woocommerce-checkout .woocommerce textarea.woocommerce-invalid,
.woocommerce-checkout .woocommerce input[aria-invalid="true"],
.woocommerce-checkout .woocommerce select[aria-invalid="true"],
.woocommerce-checkout .woocommerce textarea[aria-invalid="true"],
#billing_city.woocommerce-invalid,
#billing_city[aria-invalid="true"],
#billing_address_1.woocommerce-invalid,
#billing_address_1[aria-invalid="true"] {
    border-color: #e53e3e !important;
    border-width: 1.5px !important;
    background-color: #fff5f5 !important;
    box-shadow: 0 0 0 1px #e53e3e !important;
    transition: all 0.2s ease !important;
}

/* Remove default focus outline when invalid to keep our red border */
.woocommerce-invalid input:focus,
input[aria-invalid="true"]:focus,
input.woocommerce-invalid:focus {
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.2) !important;
}

@keyframes field-error-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

@media (max-width: 768px) {
    .field-error-message {
        font-size: 12px !important;
    }
}