/**
 * Variation Swatches Enhancement CSS
 * تحسين مظهر الـ Swatches لعرض أفضل وأكثر احترافية
 * متوافق مع: Variation Swatches for WooCommerce by Emran Ahmed
 * @version 1.0.0
 */

/* ==========================================================================
   تحسين الحاوية الرئيسية للـ Variations
   ========================================================================== */

/* Variations Container */
.variations_form .variations {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.variations_form .variations tr {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f5;
}

.variations_form .variations tr:last-child {
    border-bottom: none;
}

/* Label Styling */
.variations_form .variations .label,
.variations_form .variations th.label {
    font-weight: 600;
    font-size: 14px;
    color: #1a1a2e;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.variations_form .variations .label label::after {
    content: ":";
}

/* ==========================================================================
   تنسيق Swatches - الحجم والشكل
   ========================================================================== */

/* Swatches Container */
.cfvsw-swatches-container,
.tawcvs-swatches,
.woo-variation-swatches,
.variable-items-wrapper {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
    padding: 5px 0 !important;
    max-width: 100% !important;
}

/* Individual Swatch - حجم مناسب */
.cfvsw-swatches-option,
.swatch,
.variable-item,
.tawcvs-swatch {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    border-radius: 8px !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    overflow: hidden !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-sizing: border-box !important;
    flex-shrink: 0 !important;
}

/* Color Type Swatches */
.cfvsw-swatches-option[data-type="color"],
.cfvsw-swatches-option[data-attribute_type="color"],
.swatch-color,
.variable-item-color,
.color-variable-item {
    border: 2px solid rgba(0, 0, 0, 0.1) !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08) !important;
}

/* Image Type Swatches */
.cfvsw-swatches-option[data-type="image"],
.swatch-image,
.variable-item-image {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    max-width: 44px !important;
    max-height: 44px !important;
    border: 2px solid #e5e5e5 !important;
    padding: 2px !important;
    background: #fff !important;
}

.cfvsw-swatches-option[data-type="image"] img,
.swatch-image img,
.variable-item-image img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border-radius: 4px !important;
}

/* Label/Button Type Swatches */
.cfvsw-swatches-option[data-type="label"],
.cfvsw-swatches-option[data-type="button"],
.swatch-label,
.variable-item-button {
    width: auto !important;
    min-width: 40px !important;
    max-width: none !important;
    height: 36px !important;
    padding: 0 14px !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    background: #f8f9fa !important;
    border: 2px solid #e5e5e5 !important;
    color: #333 !important;
}

/* ==========================================================================
   حالة Hover
   ========================================================================== */

.cfvsw-swatches-option:hover,
.swatch:hover,
.variable-item:hover {
    transform: scale(1.1) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    z-index: 10 !important;
}

.cfvsw-swatches-option[data-type="label"]:hover,
.swatch-label:hover,
.variable-item-button:hover {
    background: #e9ecef !important;
    border-color: #adb5bd !important;
}

/* ==========================================================================
   حالة Selected (المختار)
   ========================================================================== */

.cfvsw-swatches-option.cfvsw-selected-swatch,
.cfvsw-swatches-option.selected,
.swatch.selected,
.variable-item.selected,
.variable-item-selected {
    transform: scale(1.05) !important;
    box-shadow: 0 0 0 3px var(--hozi-primary, #007AFF),
        0 4px 15px rgba(0, 122, 255, 0.25) !important;
}

/* Checkmark for selected */
.cfvsw-swatches-option.cfvsw-selected-swatch::after,
.cfvsw-swatches-option.selected::after,
.swatch.selected::after,
.variable-item.selected::after {
    content: "✓" !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    font-size: 14px !important;
    font-weight: bold !important;
    color: #fff !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5) !important;
    z-index: 5 !important;
}

/* White/Light color checkmark */
.cfvsw-swatches-option[data-slug="white"].cfvsw-selected-swatch::after,
.cfvsw-swatches-option[data-value="white"].cfvsw-selected-swatch::after,
.cfvsw-swatches-option[data-slug*="أبيض"].cfvsw-selected-swatch::after {
    color: #333 !important;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8) !important;
}

/* Label type selected */
.cfvsw-swatches-option[data-type="label"].cfvsw-selected-swatch,
.swatch-label.selected,
.variable-item-button.selected {
    background: var(--hozi-primary, #007AFF) !important;
    border-color: var(--hozi-primary, #007AFF) !important;
    color: #fff !important;
}

.cfvsw-swatches-option[data-type="label"].cfvsw-selected-swatch::after,
.swatch-label.selected::after {
    display: none !important;
}

/* ==========================================================================
   حالة Disabled (غير متوفر)
   ========================================================================== */

.cfvsw-swatches-option.cfvsw-disabled,
.swatch.disabled,
.variable-item.disabled,
.cfvsw-out-of-stock {
    opacity: 0.4 !important;
    cursor: not-allowed !important;
    position: relative !important;
}

.cfvsw-swatches-option.cfvsw-disabled::before,
.swatch.disabled::before,
.variable-item.disabled::before {
    content: "" !important;
    position: absolute !important;
    top: 50% !important;
    left: -5% !important;
    width: 110% !important;
    height: 2px !important;
    background: #dc3545 !important;
    transform: rotate(-45deg) !important;
    z-index: 10 !important;
}

/* ==========================================================================
   الـ Table الافتراضي لقالب Hozi
   ========================================================================== */

/* تحويل الجدول لعرض أفضل */
.variation-prices table,
.radio-variation-prices table {
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 8px !important;
}

.variation-prices tr,
.radio-variation-prices tr {
    display: flex !important;
    align-items: center !important;
    padding: 10px 15px !important;
    background: #f8f9fa !important;
    border-radius: 10px !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
    gap: 12px !important;
}

.variation-prices tr:hover,
.radio-variation-prices tr:hover {
    background: #e9ecef !important;
}

.variation-prices tr.checked,
.variation-prices tr.checked-var,
.radio-variation-prices tr.checked-var {
    background: linear-gradient(135deg, #e8f4ff, #dbeafe) !important;
    box-shadow: 0 0 0 2px var(--hozi-primary, #007AFF) !important;
}

/* Radio Button */
.variation-prices input[type="radio"],
.radio-variation-prices input[type="radio"] {
    width: 20px !important;
    height: 20px !important;
    accent-color: var(--hozi-primary, #007AFF) !important;
}

/* Variation Name */
.variation-prices td:nth-child(2),
.radio-variation-prices td:nth-child(2) {
    flex: 1 !important;
    font-weight: 500 !important;
    color: #1a1a2e !important;
}

/* Price */
.variation-prices td:last-child,
.radio-variation-prices td:last-child {
    font-weight: 600 !important;
    color: var(--hozi-primary, #007AFF) !important;
}

.variation-prices .crossed-price,
.radio-variation-prices del {
    color: #999 !important;
    font-size: 0.85em !important;
    margin-right: 8px !important;
}

/* ==========================================================================
   صف اختيار اللون في نموذج Hozi المخصص
   ========================================================================== */

/* Color row in custom form */
.codplugin-color-options,
.hozi-color-swatches {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding: 10px 0 !important;
}

/* ==========================================================================
   Responsive - الجوال
   ========================================================================== */

@media (max-width: 576px) {

    /* Smaller swatches on mobile */
    .cfvsw-swatches-option,
    .swatch,
    .variable-item {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        max-width: 32px !important;
        max-height: 32px !important;
    }

    .cfvsw-swatches-option[data-type="image"],
    .swatch-image {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
    }

    .cfvsw-swatches-option[data-type="label"],
    .swatch-label {
        height: 32px !important;
        padding: 0 10px !important;
        font-size: 12px !important;
    }

    .cfvsw-swatches-container,
    .tawcvs-swatches,
    .variable-items-wrapper {
        gap: 8px !important;
    }

    /* Compact variation table on mobile */
    .variation-prices tr,
    .radio-variation-prices tr {
        padding: 8px 12px !important;
    }
}

/* ==========================================================================
   إخفاء النص داخل swatches اللون
   ========================================================================== */

.cfvsw-swatches-option[data-type="color"] .cfvsw-swatch-inner,
.cfvsw-swatches-option[data-type="color"] span:not(.selection-checkmark),
.swatch-color span,
.variable-item-color span {
    font-size: 0 !important;
    color: transparent !important;
    display: none !important;
}

/* ==========================================================================
   تحسين عرض "نفذت الكمية" و Tooltip
   ========================================================================== */

.cfvsw-swatches-option[data-tooltip]::before,
.swatch[data-tooltip]::before {
    content: attr(data-tooltip) !important;
    position: absolute !important;
    bottom: calc(100% + 5px) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    background: #1a1a2e !important;
    color: #fff !important;
    padding: 4px 8px !important;
    border-radius: 4px !important;
    font-size: 11px !important;
    white-space: nowrap !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: all 0.2s ease !important;
    z-index: 100 !important;
}

.cfvsw-swatches-option:hover[data-tooltip]::before,
.swatch:hover[data-tooltip]::before {
    opacity: 1 !important;
    visibility: visible !important;
}

/* ==========================================================================
   تحسين تكامل مع الإضافة
   ========================================================================== */

/* Emran Ahmed Plugin specific */
.woo-variation-swatches .wvs-style-squared .variable-item {
    border-radius: 8px !important;
}

.woo-variation-swatches .wvs-style-rounded .variable-item {
    border-radius: 50% !important;
}

/* CartFlows Plugin specific */
.cfvsw-swatches-container .cfvsw-swatches-option {
    margin: 0 !important;
}

/* ==========================================================================
   Animation للاختيار
   ========================================================================== */

@keyframes swatch-select-pulse {

    0%,
    100% {
        transform: scale(1.05);
    }

    50% {
        transform: scale(1.1);
    }
}

.cfvsw-swatches-option.cfvsw-selected-swatch,
.swatch.selected,
.variable-item.selected {
    animation: swatch-select-pulse 0.3s ease-out !important;
}

/* ==========================================================================
   إخفاء القائمة المنسدلة المكررة عند وجود Swatches
   ========================================================================== */

/* إخفاء الـ select الأصلي عند عرض swatches */
.variations_form .variations td.value select {
    display: none !important;
}

/* ولكن أظهره إذا لم تكن هناك swatches */
.variations_form .variations td.value:not(:has(.variable-items-wrapper)) select,
.variations_form .variations td.value:not(:has(.woo-variation-swatches)) select,
.variations_form .variations td.value:not(:has(.cfvsw-swatches-container)) select {
    display: block !important;
}

/* إخفاء زر "تحديد أحد الخيارات" المكرر */
.variations_form .variations .reset_variations {
    display: none !important;
}

/* أظهر زر إعادة التعيين الموحد فقط */
.variations_form .single_variation_wrap .reset_variations,
.woocommerce-variation-add-to-cart .reset_variations {
    display: inline-block !important;
}

/* ==========================================================================
   إصلاح الفراغ الكبير في الصفحة
   ========================================================================== */

/* إصلاح overflow في الصفحة */
body.single-product,
body.woocommerce,
body.woocommerce-page {
    overflow-x: hidden !important;
}

/* إصلاح الحاوية الرئيسية */
.site-content,
.content-area,
#content,
.woocommerce-page .woocommerce,
.single-product .woocommerce {
    overflow-x: hidden !important;
    max-width: 100% !important;
}

/* إصلاح نموذج الطلب */
#codplugin-checkout {
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* إصلاح الفوتر */
.footer-main,
.site-footer,
.footer-bottom,
footer {
    max-width: 100% !important;
    overflow-x: hidden !important;
}

/* إصلاح أي عنصر يتجاوز العرض */
* {
    box-sizing: border-box;
}

/* منع عناصر محددة من التسبب في scroll أفقي */
.hozi-state-dropdown,
.hozi-toast-container,
.hozi-checkout-progress {
    max-width: 100vw !important;
}

/* ==========================================================================
   إصلاح تجاوب الصفحة في RTL
   ========================================================================== */

html[dir="rtl"] body,
body.rtl {
    overflow-x: hidden !important;
}

html[dir="rtl"] .site-content,
html[dir="rtl"] .content-area,
body.rtl .site-content,
body.rtl .content-area {
    overflow-x: hidden !important;
}

/* ==========================================================================
   إصلاح عرض الـ Swatches بدون تكرار
   ========================================================================== */

/* تأكد من ظهور swatches واحدة فقط */
.variations_form .variations .value {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ملاحظة: لا حاجة لإخفاء عناصر محددة - الـ select المخفي أعلاه كافي */

/* تحديد عرض swatches */
.variable-items-wrapper,
.woo-variation-swatches,
.cfvsw-swatches-container {
    width: 100% !important;
    max-width: 100% !important;
}