/**
 * AVM Product Filter — frontend styles.
 */

/* ─── Layout: flex sidebar + content ─── */

.avm-shop-layout {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.avm-filters-wrapper {
    width: 260px;
    min-width: 260px;
    flex-shrink: 0;
}

.avm-shop-content {
    flex: 1;
    min-width: 0;
    position: relative;
}

.avm-products-wrap {
    position: relative;
}

/* ─── Toolbar: search + sorting + result count ─── */

.avm-shop-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.avm-search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.avm-search-box input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: #fff;
}

.avm-search-box input:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
}

.avm-toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.avm-toolbar-right .woocommerce-result-count {
    margin: 0;
    font-size: 13px;
    color: #666;
    white-space: nowrap;
}

.avm-toolbar-right .woocommerce-ordering {
    margin: 0;
}

.avm-toolbar-right .woocommerce-ordering select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}

/* Hide Blocksy's woo-listing-top wrapper (anonymous closures, can't remove via PHP) */
.avm-shop-content .woo-listing-top,
.woo-listing-top {
    display: none !important;
}

/* Loading overlay */
.avm-products-wrap.avm-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.65);
    z-index: 10;
    pointer-events: none;
}

.avm-products-wrap.avm-loading::before {
    content: '';
    position: absolute;
    top: 100px;
    left: 50%;
    width: 36px;
    height: 36px;
    margin-left: -18px;
    border: 3px solid #e0e0e0;
    border-top-color: #2271b1;
    border-radius: 50%;
    animation: avm-spin 0.7s linear infinite;
    z-index: 11;
}

@keyframes avm-spin {
    to { transform: rotate(360deg); }
}

/* ─── Filter container ─── */

.avm-filters {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 16px;
    font-size: 14px;
    line-height: 1.5;
    position: sticky;
    top: 20px;
}

/* ─── Active filter tags ─── */

.avm-active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0;
}

.avm-active-filters:empty {
    display: none;
}

.avm-active-filters:not(:empty) {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid #e8e8e8;
}

.avm-active-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f0f6fc;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 12px;
    line-height: 1.4;
}

.avm-tag-remove {
    background: none;
    border: none;
    color: #1d4ed8;
    cursor: pointer;
    padding: 0;
    font-size: 15px;
    line-height: 1;
    margin-left: 2px;
    opacity: 0.7;
}

.avm-tag-remove:hover {
    opacity: 1;
}

.avm-clear-all {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 12px;
    padding: 3px 6px;
    text-decoration: underline;
}

.avm-clear-all:hover {
    color: #333;
}

.avm-search-tag {
    background: #fef3c7;
    color: #92400e;
    border-color: #fcd34d;
}

/* ─── Filter sections ─── */

.avm-filter-section {
    margin-bottom: 4px;
}

.avm-filter-section:last-child {
    margin-bottom: 0;
}

.avm-filter-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: #1a1a1a;
    border-bottom: 1px solid #f0f0f0;
    user-select: none;
}

.avm-filter-section-header:hover {
    color: #2271b1;
}

.avm-toggle-icon {
    font-size: 10px;
    transition: transform 0.2s;
    color: #999;
}

.avm-section-collapsed .avm-toggle-icon {
    transform: rotate(-90deg);
}

.avm-section-collapsed .avm-filter-section-body {
    display: none;
}

.avm-filter-section-body {
    padding: 8px 0;
    max-height: 320px;
    overflow-y: auto;
}

/* Custom scrollbar */
.avm-filter-section-body::-webkit-scrollbar {
    width: 5px;
}

.avm-filter-section-body::-webkit-scrollbar-track {
    background: transparent;
}

.avm-filter-section-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* ─── Filter options (checkboxes) ─── */

.avm-filter-option {
    display: flex;
    align-items: center;
    padding: 3px 0;
}

.avm-filter-option label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    flex: 1;
    line-height: 1.4;
}

.avm-filter-option label:hover {
    color: #111;
}

.avm-filter-checkbox {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #2271b1;
}

.avm-filter-count {
    color: #999;
    font-size: 12px;
    margin-left: auto;
    white-space: nowrap;
}

/* Dimmed options (0 results) */
.avm-filter-empty {
    opacity: 0.45;
}

/* ─── Hierarchical tree ─── */

.avm-tree-node {
    position: relative;
}

.avm-tree-children {
    display: none;
    padding-left: 20px;
    border-left: 1px solid #e8e8e8;
    margin-left: 8px;
}

.avm-tree-expanded > .avm-tree-children {
    display: block;
}

.avm-tree-expand {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 9px;
    color: #888;
    padding: 0;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s;
    margin-right: 2px;
}

.avm-tree-expand:hover {
    color: #333;
}

.avm-tree-expanded > .avm-filter-option .avm-tree-expand {
    transform: rotate(90deg);
}

/* ─── Mobile toggle button ─── */

.avm-filters-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    background: #2271b1;
    color: #fff;
    border: none;
    border-radius: 25px;
    padding: 12px 28px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.avm-filters-toggle:hover {
    background: #135e96;
}

/* ─── Responsive ─── */

@media (max-width: 991px) {
    .avm-shop-layout {
        display: block;
    }

    .avm-shop-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .avm-toolbar-right {
        justify-content: space-between;
    }

    .avm-filters-wrapper {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 9999;
        background: rgba(0, 0, 0, 0.5);
        margin: 0;
    }

    .avm-filters-wrapper.avm-filters-open {
        display: flex;
        align-items: flex-end;
        justify-content: center;
    }

    .avm-filters-wrapper.avm-filters-open .avm-filters {
        width: 100%;
        max-width: 100%;
        max-height: 80vh;
        overflow-y: auto;
        border-radius: 16px 16px 0 0;
        padding: 20px 20px 80px;
        animation: avm-slide-up 0.3s ease-out;
        position: static;
    }

    @keyframes avm-slide-up {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    .avm-filters-toggle {
        display: block;
    }
}

@media (min-width: 992px) {
    .avm-filters-wrapper {
        display: block !important;
    }
}
