/*
 Theme Name:   Woodmart Child
 Description:  Woodmart Child Theme
 Author:       XTemos
 Author URI:   http://xtemos.com
 Template:     woodmart
 Version:      1.0.0
 Text Domain:  woodmart
*/

/*
 * سفارشی سازی استایل حمل و نقل در صفحه پرداخت
 */

/* 1. کادر اصلی هر ردیف حمل و نقل را به یک گرید (Grid) تبدیل می‌کنیم */
.woocommerce-checkout #shipping_method li {
    display: grid;
    /* * تعریف 3 ستون:
     * ستون 1 (راست): 1fr (بزرگترین بخش، برای عنوان/توضیحات)
     * ستون 2 (وسط): auto (برای قیمت)
     * ستون 3 (چپ): auto (برای دکمه رادیویی)
     */
    grid-template-columns: 1fr auto auto;
    grid-template-rows: auto auto; /* دو ردیف برای عنوان و توضیحات */
    gap: 0 15px; /* 0 فاصله عمودی، 15 پیکسل فاصله افقی بین ستون‌ها */
    align-items: right; /* همه چیز از بالا تراز شود */
    
    /* استایل ظاهری کادر */
    padding: 15px !important;
    margin-bottom: 10px !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 8px;
}

/* 2. چیدمان عناصر در گرید */

/* عنوان (مثال: ارسال فوری) */
.woocommerce-checkout #shipping_method li label {
    grid-column: 1; /* ستون 1 (راست) */
    grid-row: 1; /* ردیف 1 (بالا) */
    font-weight: ;
    padding: 0 !important; /* حذف پدینگ اضافه */
}

/* توضیحات */
.woocommerce-checkout #shipping_method li .woocommerce-shipping-method-description,
.woocommerce-checkout #shipping_method li small {
    grid-column: 1; /* ستون 1 (راست) */
    grid-row: 2; /* ردیف 2 (پایین) */
    font-size: 0.9em;
    color: #555;
    margin-top: 5px;
}

/* قیمت */
.woocommerce-checkout #shipping_method li .woocommerce-Price-amount.amount {
    grid-column: 2; /* ستون 2 (وسط) */
    grid-row: 1; /* ردیف 1 (بالا) */
    font-weight: bold;
    font-size: 1.1em;
    
    white-space: nowrap; /* جلوگیری از شکستن قیمت */
}

/* دکمه رادیویی */
.woocommerce-checkout #shipping_method li input[type="radio"] {
    grid-column: 3; /* ستون 3 (چپ) */
    grid-row: 1; /* ردیف 1 (بالا) */
    margin: 3px 0 0 10px !important; /* تنظیم فاصله دکمه */
    align-self: start;
}
/* راست‌چین کردن توضیحات داخل باکس روش حمل و نقل */
.woocommerce-checkout #shipping_method li .woocommerce-shipping-method-description,
.woocommerce-checkout #shipping_method li small,
.shipping-method-description {
    text-align: right !important;
    direction: rtl !important;
    display: block !important;
    line-height: 1.8;
    color: #444 !important;
}
/* * این کد فونت سربرگ‌های جدول (محصول، جمع جزء) و 
 * ردیف‌های فوتر (جمع جزء، مجموع) را به فونت 'virab' (فونت ضخیم پوسته) تغییر می‌دهد.
*/
.woocommerce-checkout-review-order-table thead th,
.woocommerce-checkout-review-order-table tfoot th {
    font-family: virab, roboto, "woodmart-font", dashicons !important;
    font-weight: 600 !important; /* اطمینان از اعمال وزن ضخیم */
}
/*راستچین کردن*/
/* راست‌چین کردن بخش پرداخت (زرین‌پال و مشابه) */
.woocommerce-checkout .wc_payment_methods,
.woocommerce-checkout .wc_payment_method,
.woocommerce-checkout .payment_box,
.woocommerce-checkout .payment_method_zarinpal {
    text-align: right !important;
    direction: rtl !important;
}

/* راست‌چین کردن برچسب و چک‌باکس آدرس دیگر */
.woocommerce-checkout #ship-to-different-address,
.woocommerce-checkout #ship-to-different-address label,
.woocommerce-checkout #ship-to-different-address-checkbox {
    text-align: right !important;
    direction: rtl !important;
    justify-content: flex-end !important;
    display: flex !important;
    align-items: center !important;
}

/* برای اطمینان از چیدمان درست ورودی‌ها */
.woocommerce-checkout label,
.woocommerce-checkout input[type="checkbox"] {
    float: right !important;
}
/* جابجایی کل بخش "سفارش به آدرس دیگری حمل شود؟" به سمت راست */
#ship-to-different-address {
    direction: rtl !important;
    text-align: right !important;
    display: flex !important;
    justify-content: flex-end !important; /* ترازبندی به سمت راست */
    margin-right: 0 !important;
    margin-left: auto !important;
    width: fit-content !important; /* اندازه به اندازه محتوا */
}

/* چیدمان داخلش (تیک در راست و متن در چپ) */
#ship-to-different-address label {
    display: flex !important;
    flex-direction: row-reverse !important;
    align-items: center !important;
    gap: 6px !important;
}

/* تنظیم فاصله چک‌باکس */
#ship-to-different-address input[type="checkbox"] {
    margin-left: 6px !important;
    margin-right: 0 !important;
}
/* پنهان کردن کامل بخش فیلدهای مخفی digits در صفحه checkout */
#digits_customer_checkout,
#digits_vcustomer_phone,
#digits_vbill_phone,
#digits_guest_vbill_phone,
#dig_wc_check_page,
.dig_nounce,
#dig_wc_bill_code,
#dig_wc_bill_csrf {
    display: none !important;
}

/* اطمینان از حذف فاصله‌های ایجادشده توسط <p> و <br> */
p:has(#digits_customer_checkout) {
    display: none !important;
}
/* فقط تراز راست عنوان "جزئیات پرداخت" */
.woocommerce-billing-fields > h3 {
    text-align: right !important;
    direction: rtl !important;
}
/* راست‌چین کردن بخش کوپن تخفیف در صفحه چک‌اوت */
.woocommerce-form-coupon-toggle,
.woocommerce-form-coupon-toggle .woocommerce-info {
    direction: rtl !important;
    text-align: right !important;
}

/* لینک داخل متن هم راست‌چین و هماهنگ با متن فارسی شود */
.woocommerce-form-coupon-toggle .woocommerce-info a {
    direction: rtl !important;
    text-align: right !important;
    display: inline-block;
}
/* راست‌چین کردن و هماهنگ‌سازی فونت سرفصل جدول محصولات */
.woocommerce table.shop_table thead,
.woocommerce table.shop_table thead th {
    direction: rtl !important;
    text-align: right !important;
    font-family: inherit !important; /* همان فونت اصلی قالب */
    font-weight: 600; /* کمی ضخیم‌تر برای تیترها */
    letter-spacing: 0; /* جلوگیری از فاصله غیرعادی بین حروف */
    vertical-align: middle;
}

/* اطمینان از هم‌راستایی ستون‌ها با متن فارسی */
.woocommerce table.shop_table th.product-name,
.woocommerce table.shop_table th.product-price,
.woocommerce table.shop_table th.product-quantity,
.woocommerce table.shop_table th.product-subtotal {
    text-align: right !important;
}

/* برای ستون حذف آیتم و تصویر (چپ باقی بمانند تا ظاهر جدول حفظ شود) */
.woocommerce table.shop_table th.product-remove,
.woocommerce table.shop_table th.product-thumbnail {
    text-align: center !important;
}
/* راست‌چین کردن لیبل روش‌های ارسال */
.woocommerce-checkout .shipping_method label,
label[for="shipping_method_0_flat_rate13"] {
    text-align: right !important;
    direction: rtl !important;
    display: block !important;
    font-family: inherit !important; /* استفاده از فونت اصلی قالب */
}
/* راست‌چین کردن لیبل روش‌های ارسال */
.woocommerce-checkout .shipping_method label,
label[for="shipping_method_0_flat_rate1"] {
    text-align: right !important;
    direction: rtl !important;
    display: block !important;
    font-family: inherit !important; /* استفاده از فونت اصلی قالب */
}
/* راست‌چین کردن لیبل روش‌های ارسال */
.woocommerce-checkout .shipping_method label,
label[for="shipping_method_0_flat_rate7"] {
    text-align: right !important;
    direction: rtl !important;
    display: block !important;
    font-family: inherit !important; /* استفاده از فونت اصلی قالب */
}
/* راست‌چین کردن لیبل روش‌های ارسال */
.woocommerce-checkout .shipping_method label,
label[for="shipping_method_0_flat_rate8"] {
    text-align: right !important;
    direction: rtl !important;
    display: block !important;
    font-family: inherit !important; /* استفاده از فونت اصلی قالب */
}
/* راست‌چین کردن لیبل روش‌های ارسال */
.woocommerce-checkout .shipping_method label,
label[for="shipping_method_0_flat_rate11"] {
    text-align: right !important;
    direction: rtl !important;
    display: block !important;
    font-family: inherit !important; /* استفاده از فونت اصلی قالب */
}
/* راست‌چین کردن لیبل روش‌های ارسال */
.woocommerce-checkout .shipping_method label,
label[for="shipping_method_0_flat_rate12"] {
    text-align: right !important;
    direction: rtl !important;
    display: block !important;
    font-family: inherit !important; /* استفاده از فونت اصلی قالب */
}
/***************************************************
 * شورت‌کد نمایش کد ملی ثبت‌شده در سفارش
 * استفاده: [order_national_code]  یا  [order_national_code order_id="4656"]
 */
function ecs_get_order_national_code_shortcode( $atts ) {

    // تنظیمات شورت‌کد (پذیرفتن order_id به‌صورت دستی در صورت نیاز)
    $atts = shortcode_atts(
        array(
            'order_id' => 0,
        ),
        $atts,
        'order_national_code'
    );

    $order_id = absint( $atts['order_id'] );

    // اگر در شورت‌کد order_id داده نشده، سعی کن از کانتکست ووکامرس بگیری
    if ( ! $order_id ) {

        // 1) صفحه «نمایش سفارش» در حساب کاربری: /my-account/view-order/123
        global $wp;
        if ( isset( $wp->query_vars['view-order'] ) ) {
            $order_id = absint( $wp->query_vars['view-order'] );
        }

        // 2) صفحه تشکر / دریافت سفارش: /checkout/order-received/123
        if ( ! $order_id && isset( $wp->query_vars['order-received'] ) ) {
            $order_id = absint( $wp->query_vars['order-received'] );
        }

        // 3) صفحه پرداخت سفارش: /checkout/order-pay/123
        if ( ! $order_id && isset( $wp->query_vars['order-pay'] ) ) {
            $order_id = absint( $wp->query_vars['order-pay'] );
        }

        // 4) اگر پلاگین فاکتور، پُست فعلی را خودِ سفارش قرار دهد
        if ( ! $order_id ) {
            $current_id = get_the_ID();
            if ( $current_id && 'shop_order' === get_post_type( $current_id ) ) {
                $order_id = $current_id;
            }
        }
    }

    // اگر هنوز شناسه سفارش مشخص نیست، خروجی خالی بده
    if ( ! $order_id ) {
        return '';
    }

    // خواندن مقدار متای کد ملی که در سفارش ذخیره شده است
    $national_code = get_post_meta( $order_id, 'billing_national_code', true );

    if ( empty( $national_code ) ) {
        return '';
    }

    // برگرداندن مقدار برای استفاده در المنتور / شورت‌کد
    return esc_html( $national_code );
}
add_shortcode( 'order_national_code', 'ecs_get_order_national_code_shortcode' );

/* --- 1. نمایش قیمت‌ها به صورت عمودی در همه بخش‌ها --- */
.price {
    display: flex !important;
    flex-direction: column !important; /* عمودی شدن قیمت‌ها */
    align-items: flex-start;           /* تراز سمت چپ */
}

/* فاصله بین قیمت اولیه و قیمت تخفیف */
.price del {
    margin-bottom: 4px;
}

/* --- 2. قیمت اولیه (خط‌خورده) = طوسی پررنگ + بولد + خط تنظیم شده --- */
.price del .woocommerce-Price-amount {
    color: #666 !important;                     /* رنگ عدد */
    font-weight: 700 !important;                /* بولد */
    text-decoration: line-through;              /* خط خورده */
    text-decoration-color: #666 !important;    /* رنگ خط = طوسی */
    text-decoration-thickness: 2px !important; /* ضخامت خط */
    text-underline-offset: 4px !important;     /* فاصله خط از عدد */
}

/* --- 3. قیمت نهایی در کالاهای تخفیف‌دار = قرمز و بولد --- */
.price ins .woocommerce-Price-amount {
    color: red !important;
    font-weight: 800 !important;
}

/* --- 4. قیمت کالاهای تک‌قیمتی (بدون تخفیف) در همه بخش‌ها = قرمز و بولد --- */
.price > .woocommerce-Price-amount,
span.woocommerce-Price-amount.amount:not(.price del .woocommerce-Price-amount) {
    color: red !important;
    font-weight: 800 !important;
}

/* === WooCommerce Payment Methods - Full Width RTL Labels ===کدهای مرتب سازی ستون های روش پرداخت و چک باکس هایشان */
/* === Fix: Payment methods RTL full-width right aligned (Override YellowPencil) === */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method{
  direction: rtl !important;
  text-align: right !important;
}

/* YellowPencil has forced some radios to width:50px; neutralize it */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method input.input-radio{
  width: auto !important;
  min-width: 0 !important;
}

/* Your markup wraps label inside <p> and adds <br/> before text */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method > p{
  margin: 0 !important;
  padding: 0 !important;
}

/* Hide that leading <br/> so the row doesn't shift */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method > p > label > br{
  display: none !important;
}

/* Make each method a 2-column grid: (radio) | (full-width label aligned to right edge) */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method{
  display: grid !important;
  grid-template-columns: 22px 1fr; /* radio | content */
  align-items: center;
  column-gap: 10px;
  padding: 12px 10px;
}

/* Radio column */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method > input[type="radio"]{
  grid-column: 1;
  justify-self: center;
  margin: 0 !important;
}

/* Full-width label area in column 2, pinned to the right edge */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method > p > label{
  grid-column: 2;
  width: 100%;
  display: flex !important;
  align-items: center;
  justify-content: flex-end;   /* stick to right */
  text-align: right !important;
  direction: rtl !important;
  gap: 8px;
  margin: 0 !important;
}

/* Keep logo + text on one line (like your green-check example) */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method > p > label{
  white-space: nowrap;
}

/* Logo sizing */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method > p > label img{
  max-height: 22px;
  height: auto;
  width: auto;
  margin: 0 !important;
}

/* Payment description box spans full width under the row */
.woocommerce-checkout #payment .wc_payment_methods li.wc_payment_method .payment_box{
  grid-column: 1 / -1;
  margin-top: 8px;
}
/* =========================================
   FIX SHIPPING METHOD ALIGNMENT (WOODMART)
   Cart & Checkout | All Provinces
اصلاح ظاهری نوشته های تحویل حضوری درب انبار
========================================= */

/* سلول حمل و نقل */
.woocommerce-cart td[data-title="حمل و نقل"],
.woocommerce-checkout td[data-title="حمل و نقل"] {
    text-align: right !important;
    direction: rtl;
}

/* لیست روش‌های حمل */
.woocommerce-cart ul#shipping_method,
.woocommerce-checkout ul#shipping_method {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* هر روش حمل */
.woocommerce-cart ul#shipping_method li,
.woocommerce-checkout ul#shipping_method li {
    display: flex !important;
    flex-direction: row-reverse !important; /* رادیو سمت راست */
    justify-content: flex-start !important;
    align-items: flex-start !important;
    text-align: right !important;
    width: 100%;
}
/* رادیو باتن */
.woocommerce-cart ul#shipping_method li input[type="radio"],
.woocommerce-checkout ul#shipping_method li input[type="radio"] {
    margin-left: 6px !important;
    margin-right: 0 !important;

}

/* متن روش حمل */
.woocommerce-cart ul#shipping_method li label,
.woocommerce-checkout ul#shipping_method li label {
    display: block !important;
    width: 100% !important;
    text-align: right !important;
    white-space: normal !important;
    margin: 0 !important;
}

/* === غیرفعال‌سازی کامل محدودیت عنوان محصولات Woodmart (معادل تنظیمات قالب) === */

/* حذف محدودیت تعداد خطوط */
body.woocommerce-shop {
    --wd-entities-title-line-clamp: unset;
}

/* آزاد کردن ارتفاع و برش عنوان */
body.woocommerce-shop .wd-entities-title {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
}

/* اطمینان از چندخطی شدن خود لینک عنوان */
body.woocommerce-shop .wd-entities-title a {
    white-space: normal !important;
    overflow: visible !important;
    display: block;
}
/* =========================================
   اصلاح کامل نمایش عنوان محصولات Woodmart
   ========================================= */

.product-title a,
.wd-entities-title a {
    display: block !important;
    white-space: normal !important;
    overflow: visible !important;
}

/* خط اول */
.product-title .wd-title-line-1,
.wd-entities-title .wd-title-line-1 {
    display: block;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.6;
    color: #222;
}

/* خط دوم (مدل / کد) */
.product-title .wd-title-line-2,
.wd-entities-title .wd-title-line-2 {
    display: block;
    font-size: 13px;
    font-weight: 400;
    color: #666;
    direction: ltr;
    text-align: right;
}
