/*
 * Product Quantity & Variation Styles
 * Optimized for WoodMart Child Theme & Elementor
 */

/* =========================================
   1. متغیرهای سراسری
   ========================================= */
:root {
    --gk-primary: var(--wd-primary-color, #7eb934);
    --gk-primary-600: var(--wd-primary-color-hover, #6aa02c);
    --gk-text: var(--wd-text-color, #333);
    --gk-surface: #fff;
    --gk-border-color: var(--wd-form-border-color, #e1e1e1);

    --gk-neutral-100: #f7f7f7;
    --gk-neutral-200: #e9e9e9;
    --gk-neutral-400: #999;
    --gk-neutral-600: #666;
    --gk-neutral-900: #222;
    --gk-accent: var(--wd-primary-color, #7eb934);

    --gk-radius-lg: 5px;
    --gk-shadow: 0 4px 12px rgba(0,0,0,0.1);

    --gk-font-base: inherit;
    --gk-heading-weight: 700;
}

/* =========================================
   2. رفع تداخل‌های ساختاری (مهم برای وودمارت)
   ========================================= */

/* مخفی کردن دکمه‌های پیش‌فرض وودمارت */
.gk-qty-container .quantity .minus,
.gk-qty-container .quantity .plus,
.gk-qty-container .quantity > input[type="button"] {
    display: none !important;
}

/* اصلاح کانتینر .quantity ووکامرس/وودمارت */
/* این کد حیاتی است: باعث می‌شود این دیو مزاحم فضای دکمه‌های ما را اشغال نکند */
.gk-qty-container .quantity {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    /* تنظیمات فلکس برای پر کردن فضای وسط */
    flex: 1 1 auto !important;
    width: auto !important;
    min-width: 0 !important; /* جلوگیری از باگ عرض در فایرفاکس */

    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 100% !important;
    background: transparent !important;
    box-shadow: none !important;
}

/* چیدمان فرم اصلی */
.woocommerce div.product form.cart:not(.variations_form),
.woocommerce div.product .woocommerce-variation-add-to-cart,
.elementor-widget-wd_single_product_add_to_cart form.cart {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 15px !important;
    width: 100% !important;
}

/* =========================================
   3. استایل کانتینر اختصاصی (GK Container)
   ========================================= */
.gk-qty-container {
    display: flex;
    flex-wrap: nowrap !important; /* جلوگیری از شکستن خط */
    align-items: center;
    justify-content: space-between;
    border: 2px solid var(--gk-border-color);
    border-radius: var(--gk-radius-lg);
    background: var(--gk-surface);
    height: 50px;
    width: 100%;
    padding: 0;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
    margin-bottom: 0;
}

/* دکمه‌های + و - اختصاصی ما */
.gk-qty-btn {
    /* فیکس کردن عرض دکمه‌ها تا له نشوند */
    flex: 0 0 50px !important;
    width: 50px !important;
    min-width: 50px !important;

    height: 100%;
    background: var(--gk-neutral-100);
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--gk-text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    margin: 0 !important; /* حذف مارجین‌های احتمالی قالب */
}

.gk-qty-btn:hover {
    background: var(--gk-neutral-200);
    color: var(--gk-neutral-900);
}

/* استایل اینپوت عددی */
.gk-qty-container input.qty {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    background: transparent !important;
    text-align: center !important;
    font-family: var(--gk-font-base);
    font-weight: var(--gk-heading-weight);
    font-size: 20px !important;
    color: var(--gk-text) !important;
    padding: 0 !important;
    margin: 0 !important;
    z-index: 5;
    position: relative;
    box-shadow: none !important;
    appearance: textfield !important;
    -moz-appearance: textfield !important;
}

.gk-qty-container input.qty::-webkit-outer-spin-button,
.gk-qty-container input.qty::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* برچسب واحد (متر/عدد) */
.gk-unit-label {
    position: absolute;
    /* تنظیم دقیق موقعیت */
    left: 60px;
    top: 50%;
    transform: translateY(-50%);

    font-size: 12px;
    color: var(--gk-neutral-400);
    font-weight: 400;
    pointer-events: none;
    z-index: 6;
    user-select: none;
    background: rgba(255,255,255,0.85);
    padding: 2px 5px;
    border-radius: 4px;
}

/* =========================================
   4. باکس قیمت نهایی
   ========================================= */
.gk-final-price-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gk-surface);
    border: 1px dashed var(--gk-accent);
    border-radius: var(--gk-radius-lg);
    padding: 10px 15px;
    width: 100%;
    box-sizing: border-box;
    min-height: 45px;
}

.gk-final-price-box .label {
    font-size: 14px;
    color: var(--gk-neutral-600);
    font-weight: 500;
}

.gk-final-price-box .price-value {
    font-size: 18px;
    font-weight: var(--gk-heading-weight);
    color: var(--gk-accent);
}

/* مخفی کردن قیمت‌های پیش‌فرض ووکامرس */
.woocommerce-variation-price,
.single_variation .price {
    display: none !important;
}

/* =========================================
   5. دکمه افزودن به سبد خرید
   ========================================= */
button.single_add_to_cart_button {
    width: 100% !important;
    display: block !important;
    margin: 0 !important;
    float: none !important;
    border-radius: var(--gk-radius-lg) !important;
    padding: 14px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    background-color: var(--gk-primary) !important;
    color: #fff !important;
    border: none !important;
    height: auto !important;
    line-height: 1.4 !important;
    transition: all 0.25s ease !important;
}

button.single_add_to_cart_button:hover {
    background-color: var(--gk-primary-600) !important;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

button.single_add_to_cart_button.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: var(--gk-neutral-400) !important;
    transform: none;
    box-shadow: none;
}

/* =========================================
   6. جدول و انتخابگرهای Variations
   ========================================= */
table.variations {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    display: block;
}

table.variations tbody, table.variations tr, table.variations td {
    display: block;
    width: 100%;
}

table.variations tr { margin-bottom: 15px; }
table.variations td { padding: 0; text-align: right; }
table.variations td.label { margin-bottom: 5px; }

table.variations label {
    font-size: 14px;
    font-weight: 700;
    color: var(--gk-text);
}

/* استایل سلکت باکس */
.variations select {
    width: 100%;
    height: 45px;
    padding: 0 15px;
    font-size: 14px;
    color: var(--gk-text);
    background-color: var(--gk-surface);
    border: 1px solid var(--gk-border-color);
    border-radius: var(--gk-radius-lg);
    cursor: pointer;
}

.variations select:focus {
    border-color: var(--gk-primary);
}

a.reset_variations {
    display: inline-block !important;
    font-size: 12px;
    color: var(--gk-neutral-600);
    margin-top: 5px;
    text-decoration: none;
    visibility: hidden;
}

@media (max-width: 768px) {
    .gk-qty-container { height: 45px; }
    .gk-qty-btn { width: 45px !important; flex: 0 0 45px !important; font-size: 16px; }
    .gk-qty-container input.qty { font-size: 18px !important; }
    .gk-unit-label { left: 50px; }
}
