/* --------------------------------------------------------------------------
   نور مارکتینگ Smart Filter — storefront styles
   Global CSS variables are injected from the plugin settings panel.
   -------------------------------------------------------------------------- */
.apf-product-filter {
    --apf-border: var(--apf-ui-border, #e4e4e7);
    --apf-muted: var(--apf-ui-muted, #6b7280);
    --apf-ink: var(--apf-ui-ink, #1f2937);
    --apf-bg: var(--apf-ui-bg, #ffffff);
    --apf-soft: var(--apf-ui-soft, #f8fafc);
    --apf-accent: var(--apf-ui-accent, #111827);
    --apf-accent-hover: var(--apf-ui-accent-hover, #374151);
    --apf-button-text: var(--apf-ui-button-text, #ffffff);
    --apf-reset: var(--apf-ui-reset, #b42318);
    --apf-filter-radius: var(--apf-ui-filter-radius, 14px);
    --apf-button-radius: var(--apf-ui-button-radius, 8px);
    --apf-filter-padding: var(--apf-ui-filter-padding, 18px);
    --apf-section-spacing: var(--apf-ui-section-spacing, 15px);
    box-sizing: border-box;
    width: 100%;
    border: 1px solid var(--apf-border);
    border-radius: var(--apf-filter-radius);
    background: var(--apf-bg);
    padding: var(--apf-filter-padding);
    color: var(--apf-ink);
    direction: rtl;
    text-align: right;
}

.apf-product-filter * { box-sizing: border-box; }
.apf-filter-heading { padding: 0 0 13px; border-bottom: 1px solid var(--apf-border); }
.apf-filter-heading h3 { margin: 0; color: var(--apf-ink); font-size: 18px; font-weight: 800; line-height: 1.5; }
.apf-filter-heading__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.apf-filter-sections { margin-top: 2px; }
.apf-filter-section { margin: 0; border-bottom: 1px solid var(--apf-border); }
.apf-filter-section summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: var(--apf-section-spacing) 0;
    color: var(--apf-ink);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.5;
    list-style: none;
    user-select: none;
}
.apf-filter-section summary::-webkit-details-marker { display: none; }
.apf-filter-chevron {
    display: inline-flex;
    flex: 0 0 auto;
    width: 9px;
    height: 9px;
    margin-left: 3px;
    border-bottom: 1.5px solid currentColor;
    border-left: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform .18s ease;
}
.apf-filter-section[open] .apf-filter-chevron { margin-top: 6px; transform: rotate(135deg); }
.apf-filter-section__body { padding: 0 0 var(--apf-section-spacing); }
.apf-filter-options {
    display: grid;
    max-height: 265px;
    gap: 10px;
    overflow: auto;
    padding: 2px 0 3px 6px;
    scrollbar-width: thin;
}
.apf-filter-options--tree { display: block; max-height: 280px; }
.apf-filter-options--stock { max-height: none; }
.apf-filter-option {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    color: var(--apf-ink);
    cursor: pointer;
    font-size: 13px;
    line-height: 1.55;
}
.apf-filter-option input {
    width: 16px;
    height: 16px;
    min-width: 16px;
    margin: 2px 0 0;
    accent-color: var(--apf-accent);
    cursor: pointer;
}
.apf-filter-option span { padding-top: 0; }
.apf-term-tree { margin: 0; padding: 0; list-style: none; }
.apf-term-tree__item { margin: 0; }
.apf-term-tree__row { display: flex; align-items: flex-start; gap: 4px; padding: 0 0 8px; }
.apf-term-tree__row .apf-filter-option { flex: 1; min-width: 0; }
.apf-term-tree__toggle,
.apf-term-tree__toggle-spacer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    min-width: 22px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
}
.apf-term-tree__toggle { position: relative; color: var(--apf-muted); cursor: pointer; }
.apf-term-tree__toggle:before {
    content: "";
    width: 7px;
    height: 7px;
    margin-top: -4px;
    border-bottom: 1.5px solid currentColor;
    border-left: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform .18s ease;
}
.apf-term-tree__item.is-open > .apf-term-tree__row .apf-term-tree__toggle:before { margin-top: 4px; transform: rotate(135deg); }
.apf-term-tree__toggle:focus-visible,
.apf-filter-submit:focus-visible,
.apf-price-input:focus-visible { outline: 2px solid var(--apf-accent); outline-offset: 2px; }
.apf-term-tree__children {
    margin: 0 10px 2px 0;
    padding: 0 12px 0 0;
    border-right: 1px solid var(--apf-border);
}
.apf-term-tree__children[hidden] { display: none; }
.apf-price-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.apf-price-inputs label { display: grid; gap: 6px; color: var(--apf-muted); font-size: 12px; font-weight: 600; }
.apf-price-input {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--apf-border);
    border-radius: var(--apf-button-radius);
    background: var(--apf-soft);
    color: var(--apf-ink);
    direction: ltr;
    font: inherit;
    text-align: center;
}
.apf-price-input:focus { border-color: var(--apf-accent); outline: 2px solid var(--apf-accent); outline-offset: 1px; }
.apf-price-slider { position: relative; height: 34px; margin: 12px 5px 2px; }
.apf-price-slider__track,
.apf-price-slider__range { position: absolute; top: 15px; height: 4px; border-radius: 999px; }
.apf-price-slider__track { right: 0; left: 0; background: var(--apf-soft); }
.apf-price-slider__range { background: var(--apf-accent); }
.apf-price-range {
    position: absolute;
    top: 7px;
    right: 0;
    left: 0;
    width: 100%;
    height: 18px;
    margin: 0;
    padding: 0;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    pointer-events: none;
}
.apf-price-range::-webkit-slider-runnable-track { height: 4px; border: 0; background: transparent; }
.apf-price-range::-moz-range-track { height: 4px; border: 0; background: transparent; }
.apf-price-range::-webkit-slider-thumb {
    width: 17px;
    height: 17px;
    margin-top: -6px;
    border: 2px solid var(--apf-bg);
    border-radius: 50%;
    background: var(--apf-accent);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .22);
    cursor: pointer;
    pointer-events: auto;
    -webkit-appearance: none;
    appearance: none;
}
.apf-price-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 2px solid var(--apf-bg);
    border-radius: 50%;
    background: var(--apf-accent);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .22);
    cursor: pointer;
    pointer-events: auto;
}
.apf-price-note { margin: 8px 0 0; color: var(--apf-muted); font-size: 11px; line-height: 1.6; }
.apf-filter-actions { display: grid; gap: 10px; padding-top: 16px; }
.apf-filter-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--apf-accent);
    border-radius: var(--apf-button-radius);
    background: var(--apf-accent);
    color: var(--apf-button-text);
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    transition: background-color .18s ease, border-color .18s ease, transform .18s ease;
}
.apf-filter-submit:hover { border-color: var(--apf-accent-hover); background: var(--apf-accent-hover); color: var(--apf-button-text); }
.apf-filter-submit:active { transform: translateY(1px); }
.apf-filter-reset { display: inline-flex; justify-content: center; color: var(--apf-reset); font-size: 12px; line-height: 1.5; text-decoration: none; }
.apf-filter-reset:hover { color: var(--apf-reset); text-decoration: underline; }
.apf-price-value { display: none !important; }
.apf-debug-panel { margin-top: 14px; padding: 10px 12px; border: 1px dashed #b45309; border-radius: 10px; background: #fffbeb; color: #78350f; direction: rtl; font-size: 12px; line-height: 1.7; }
.apf-debug-panel summary { cursor: pointer; font-weight: 800; }
.apf-debug-panel p { margin: 6px 0 0; }

.apf-mobile-filter-trigger,
.apf-filter-mobile-close { display: none; }

@media (max-width: 767px) {
    html.apf-mobile-filters-ready .apf-mobile-filter-trigger { display: inline-flex; }
    .apf-mobile-filter-trigger {
        display: none;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        min-height: 48px;
        margin: 0 0 14px;
        padding: 10px 16px;
        border: 1px solid var(--apf-ui-border, #e4e4e7);
        border-radius: var(--apf-ui-button-radius, 8px);
        background: var(--apf-ui-bg, #ffffff);
        color: var(--apf-ui-ink, #1f2937);
        box-shadow: 0 2px 8px rgba(15, 23, 42, .06);
        cursor: pointer;
        font: inherit;
        font-size: 14px;
        font-weight: 800;
        line-height: 1;
    }
    .apf-mobile-filter-trigger:hover { border-color: var(--apf-ui-accent, #111827); color: var(--apf-ui-accent, #111827); }
    .apf-mobile-filter-trigger:focus-visible,
    .apf-filter-mobile-close:focus-visible { outline: 2px solid var(--apf-ui-accent, #111827); outline-offset: 2px; }
    .apf-mobile-filter-trigger__icon { display: inline-flex; align-items: center; justify-content: center; }
    .apf-mobile-filter-trigger__count {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 20px;
        height: 20px;
        padding: 0 6px;
        border-radius: 999px;
        background: var(--apf-ui-accent, #111827);
        color: var(--apf-ui-button-text, #ffffff);
        font-size: 11px;
        line-height: 1;
    }
    .apf-mobile-filter-trigger__count[hidden] { display: none; }

    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced:not(.is-mobile-open) { display: none; }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 2147483000;
        width: 100vw;
        min-width: 0;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        border: 0;
        border-radius: 0;
        background: var(--apf-bg);
        box-shadow: none;
        flex-direction: column;
        overscroll-behavior: contain;
    }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-heading {
        flex: 0 0 auto;
        padding: max(14px, env(safe-area-inset-top)) 16px 14px;
        border-bottom: 1px solid var(--apf-border);
        background: var(--apf-bg);
    }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-heading h3 { margin: 0; font-size: 18px; }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-mobile-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        min-width: 38px;
        padding: 0;
        border: 1px solid var(--apf-border);
        border-radius: var(--apf-button-radius);
        background: var(--apf-soft);
        color: var(--apf-ink);
        cursor: pointer;
        font: inherit;
        font-size: 27px;
        font-weight: 400;
        line-height: 1;
    }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-sections {
        flex: 1 1 auto;
        min-height: 0;
        margin: 0;
        padding: 0 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-section summary {
        min-height: 58px;
        padding: 16px 0;
        font-size: 15px;
    }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-options,
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-options--tree {
        max-height: none;
        overflow: visible;
    }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-actions {
        flex: 0 0 auto;
        gap: 9px;
        margin: 0;
        padding: 12px 16px max(14px, env(safe-area-inset-bottom));
        border-top: 1px solid var(--apf-border);
        background: var(--apf-bg);
        box-shadow: 0 -5px 16px rgba(15, 23, 42, .05);
    }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-submit {
        min-height: 52px;
        border-radius: var(--apf-button-radius);
        font-size: 15px;
    }
    html.apf-mobile-filters-ready .apf-product-filter.apf-mobile-enhanced.is-mobile-open .apf-filter-reset { min-height: 24px; align-items: center; font-size: 13px; }
    html.apf-mobile-filter-is-open,
    body.apf-mobile-filter-is-open { overflow: hidden !important; overscroll-behavior: none; }
    .apf-product-filter { padding: 15px; }
    .apf-filter-options { max-height: 220px; }
    .apf-term-tree__children { margin-right: 7px; padding-right: 9px; }
}

/* AJAX feedback: the normal GET form remains the fallback, while enabled
   browsers receive a light, non-blocking update state. */
.apf-ajax-status {
    margin-top: 10px;
    color: var(--apf-muted);
    font-size: 12px;
    line-height: 1.6;
}
.apf-product-filter.is-ajax-loading .apf-filter-submit {
    cursor: wait;
    opacity: .72;
}
.apf-product-filter.is-ajax-loading .apf-filter-submit:before {
    content: "";
    width: 14px;
    height: 14px;
    margin-left: 8px;
    border: 2px solid currentColor;
    border-left-color: transparent;
    border-radius: 50%;
    animation: apf-ajax-spin .65s linear infinite;
}
.apf-archive-is-loading {
    position: relative;
    opacity: .56;
    pointer-events: none;
    transition: opacity .15s ease;
}
.apf-archive-is-loading:after {
    content: "";
    position: absolute;
    top: 24px;
    right: 50%;
    width: 28px;
    height: 28px;
    margin-right: -14px;
    border: 3px solid var(--apf-ui-accent, #111827);
    border-left-color: transparent;
    border-radius: 50%;
    animation: apf-ajax-spin .65s linear infinite;
}
@keyframes apf-ajax-spin { to { transform: rotate(360deg); } }
