/* ==========================================================================
   Taxonomy Filter Subcategory Dropdown v3
   Structure: search.e-filter > button.e-filter-item[data-filter]
   ========================================================================== */

/* The parent <search> needs to allow overflow for dropdowns */
.e-filter {
    overflow: visible !important;
}

/* Each button with children gets a wrapper via JS (.tfsd-wrap) */
.tfsd-wrap {
    position: relative;
    display: inline-block;
}

/* Arrow indicator */
.tfsd-wrap > button.e-filter-item::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 5px;
    vertical-align: middle;
    border-left: 3.5px solid transparent;
    border-right: 3.5px solid transparent;
    border-top: 4px solid currentColor;
    transition: transform 0.2s ease;
}

.tfsd-wrap:hover > button.e-filter-item::after,
.tfsd-wrap.tfsd-open > button.e-filter-item::after {
    transform: rotate(180deg);
}

/* Dropdown panel */
.tfsd-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    z-index: 99999;
    min-width: 190px;
    max-width: 280px;
    background: #fff;
    border: 1px solid #e2e2e2;
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    padding: 4px 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, visibility 0.18s ease, transform 0.18s ease;
}

/* Invisible bridge */
.tfsd-dropdown::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
}

/* Desktop hover */
@media (min-width: 1025px) {
    .tfsd-wrap:hover .tfsd-dropdown {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: translateX(-50%) translateY(0);
    }
}

/* Touch / click toggle */
.tfsd-wrap.tfsd-open .tfsd-dropdown {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

/* Dropdown links */
.tfsd-dropdown__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 14px;
    color: #333;
    text-decoration: none !important;
    font-size: 13px;
    line-height: 1.4;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.12s ease;
}

.tfsd-dropdown__link:hover {
    background: #f5f5f5;
    color: #111;
}

.tfsd-dropdown__name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tfsd-dropdown__count {
    flex-shrink: 0;
    font-size: 11px;
    color: #999;
    background: #f0f0f0;
    padding: 1px 6px;
    border-radius: 8px;
}

/* Hide uncategorized (JS adds this class) */
button.e-filter-item.tfsd-hidden {
    display: none !important;
}

/* ==========================================================================
   Responsive ≤ 1024px — Bottom sheet
   ========================================================================== */
@media (max-width: 1024px) {
    .tfsd-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0 !important;
        right: 0;
        transform: translateY(100%) !important;
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
        padding: 12px 0 env(safe-area-inset-bottom, 16px);
        max-height: 55vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tfsd-dropdown::before {
        display: none;
    }

    /* Drag handle */
    .tfsd-dropdown::after {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #ccc;
        border-radius: 2px;
        margin: 0 auto 8px;
    }

    .tfsd-wrap.tfsd-open .tfsd-dropdown {
        transform: translateY(0) !important;
    }

    .tfsd-dropdown__link {
        padding: 14px 20px;
        font-size: 15px;
    }

    .tfsd-dropdown__link:not(:last-child) {
        border-bottom: 1px solid #f0f0f0;
    }

    /* Backdrop */
    .tfsd-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 99998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s ease, visibility 0.2s ease;
    }

    .tfsd-backdrop.tfsd-visible {
        opacity: 1;
        visibility: visible;
    }
}
