/**
 * Bộ Lọc Sản Phẩm WooCommerce An Tâm - Frontend CSS
 * Tác giả: webantam.com
 */

/* ===== Wrapper ===== */
.boloc-wat-filter-wrapper {
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    contain: layout style paint !important;
    min-width: 0 !important;
    /* Ngăn layout shift khi load */
    display: block !important;
    float: none !important;
    clear: both !important;
}

.boloc-wat-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e5e5;
}

.boloc-wat-filter-wrapper *,
.boloc-wat-filter-wrapper *::before,
.boloc-wat-filter-wrapper *::after {
    box-sizing: border-box;
}

.boloc-wat-filter-form {
    max-width: 100% !important;
    overflow: hidden;
    min-width: 0 !important;
}

/* ===== Search và Results ===== */
.boloc-wat-search-wrapper {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    max-width: 100%;
    box-sizing: border-box;
}

.boloc-wat-search-form {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
}

.boloc-wat-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.boloc-wat-search-input {
    width: 100% !important;
    padding: 8px 70px 8px 12px !important;
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
    font-size: 14px !important;
    background: #fff !important;
    transition: all 0.2s ease !important;
    box-shadow: none !important;
    height: auto !important;
    margin-bottom: 0;
}

.boloc-wat-search-input:focus {
    outline: none;
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
}

.boloc-wat-search-clear {
    position: absolute;
    right: 40px;
    top: 0;
    height: 100%;
    padding: 0 10px;
    color: #999;
    cursor: pointer;
    transition: color 0.2s ease;
    display: none;
    align-items: center;
    justify-content: center;
}

.boloc-wat-search-clear:hover {
    color: #666;
}

.boloc-wat-search-input-wrapper.has-value .boloc-wat-search-clear {
    display: flex;
}

.boloc-wat-search-icon {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    padding: 0 15px;
    color: #666;
    cursor: pointer;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.boloc-wat-search-icon:hover {
    color: #2271b1;
}

.boloc-wat-search-icon i {
    font-size: 16px;
}

.boloc-wat-results-count {
    font-size: 14px;
    color: #666;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
}

.boloc-wat-results-count .filtered-count {
    font-weight: 700;
    color: #2271b1;
}

.boloc-wat-results-count .of-total {
    display: none;
}

.boloc-wat-results-count.has-filter .of-total {
    display: inline;
}

.boloc-wat-results-count .total-count {
    font-weight: 500;
    color: #333;
}

/* ===== Filter Options (Stacked/Scrolling toggle) ===== */
.boloc-wat-filter-options {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    max-width: 100%;
    box-sizing: border-box;
}

.boloc-wat-filter-label {
    font-size: 14px;
    color: #666;
}

.boloc-wat-option-btn {
    padding: 6px 14px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    color: #333;
    font-size: 13px;
    cursor: pointer !important;
    transition: all 0.2s ease;
    margin-bottom: 0;
    line-height: normal;
    text-transform: capitalize;
}

.boloc-wat-option-btn:hover {
    border-color: #2271b1;
    color: #2271b1;
}

.boloc-wat-option-btn.active {
    background: #2271b1;
    border-color: #2271b1;
    color: #fff;
}

/* ===== Attributes Container - Scrolling Style ===== */
.boloc-wat-attributes-container {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 10px;
    margin-bottom: 15px;
    max-width: 100% !important;
    box-sizing: border-box;
    min-width: 0 !important;
}

.boloc-wat-attributes-container.boloc-wat-scrolling {
    flex-wrap: nowrap;
}

.boloc-wat-attributes-container.boloc-wat-stacked {
    flex-wrap: wrap;
}

/* Custom scrollbar */
.boloc-wat-attributes-container::-webkit-scrollbar {
    height: 6px;
}

.boloc-wat-attributes-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.boloc-wat-attributes-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.boloc-wat-attributes-container::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ===== Attribute Group ===== */
.boloc-wat-attribute-group {
    min-width: 180px;
    max-width: 250px;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    background: #fafafa;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.boloc-wat-stacked .boloc-wat-attribute-group {
    flex: 1;
    min-width: 150px;
}

.boloc-wat-attribute-header {
    padding: 10px 12px;
    background: #f5f5f5;
    border-bottom: 1px solid #e5e5e5;
    border-radius: 6px 6px 0 0;
}

.boloc-wat-attribute-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    display: block;
}

/* Terms search */
.boloc-wat-terms-search {
    padding: 8px;
    border-bottom: 1px solid #e5e5e5;
}

.boloc-wat-term-search {
   width: 100% !important;
    padding: 6px 10px !important;
    border: 1px solid #ddd !important;
    border-radius: 3px !important;
    font-size: 13px !important;
    box-shadow: none !important;
}

.boloc-wat-term-search:focus {
    outline: none;
    border-color: #2271b1;
}

/* Terms list */
.boloc-wat-terms-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 5px 0;
}

.boloc-wat-terms-list::-webkit-scrollbar {
    width: 6px;
}

.boloc-wat-terms-list::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.boloc-wat-terms-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Term item */
.boloc-wat-term-item {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    cursor: pointer;
    transition: background 0.15s ease;
}

/* Group clear button */
.boloc-wat-group-clear {
    padding: 8px 12px;
    border-top: 1px solid #e5e5e5;
    text-align: center;
    margin-top: auto;
    display: none;
}

.boloc-wat-attribute-group.has-active .boloc-wat-group-clear {
    display: block;
}

.boloc-wat-clear-btn {
    color: #2271b1;
    font-size: 13px;
    cursor: pointer;
    transition: color 0.2s ease;
}

.boloc-wat-clear-btn:hover {
    color: #135e96;
    text-decoration: underline;
}

.boloc-wat-term-item:hover {
    background: #f0f0f0;
}

.boloc-wat-term-item.selected {
    background: #e8f4fc;
}

.boloc-wat-term-item input[type="checkbox"] {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin-bottom: 0;
}

.boloc-wat-term-name {
    flex: 1;
    font-size: 13px;
    color: #333;
}

.boloc-wat-term-count {
    font-size: 12px;
    color: #999;
    margin-left: auto;
}

/* ===== Actions ===== */
.boloc-wat-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding-top: 10px;
    border-top: 1px solid #e5e5e5;
    max-width: 100%;
    box-sizing: border-box;
    align-items: center;
}

.boloc-wat-reset-btn,
.boloc-wat-apply-btn {
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: normal;
    text-transform: capitalize;
    margin-bottom: 0;
}

.boloc-wat-reset-btn {
    background: #fff;
    border: 1px solid #ddd;
    color: #666;
    margin-bottom: 0;
}

.boloc-wat-reset-btn:hover {
    border-color: #999;
    color: #333;
}

.boloc-wat-apply-btn {
    background: #2271b1;
    border: 1px solid #2271b1;
    color: #fff;
}

.boloc-wat-apply-btn:hover {
    background: #135e96;
    border-color: #135e96;
}

/* Button hidden state */
.boloc-wat-btn-hidden {
    display: none !important;
}

/* Button loading state */
.boloc-wat-btn-loading {
    opacity: 0.8;
    pointer-events: none;
    cursor: wait;
}

.boloc-wat-btn-loading i.fa-spinner {
    margin-right: 5px;
    display: inline-block;
}

/* Fallback spinner nếu FontAwesome không load */
.boloc-wat-btn-loading .boloc-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: boloc-spin 0.75s linear infinite;
    margin-right: 5px;
    vertical-align: middle;
}

@keyframes boloc-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Loading state ===== */
.boloc-wat-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.boloc-wat-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2271b1;
    border-radius: 50%;
    animation: boloc-wat-spin 1s linear infinite;
}

@keyframes boloc-wat-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== Hide filtered terms ===== */
.boloc-wat-term-item.hidden {
    display: none;
}

/* ===== Active filters indicator ===== */
.boloc-wat-attribute-group.has-active {
    border-color: #2271b1;
}

.boloc-wat-attribute-group.has-active .boloc-wat-attribute-header {
    background: #e8f4fc;
    border-color: #2271b1;
}

/* ===== Responsive ===== */
@media screen and (max-width: 768px) {
    .boloc-wat-filter-wrapper {
        padding: 10px;
    }
    
    .boloc-wat-search-wrapper {
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }
    
    .boloc-wat-search-form {
        flex: 1;
        min-width: 0;
    }
    
    .boloc-wat-search-wrapper > .boloc-wat-results-count {
        flex-shrink: 0;
        white-space: nowrap;
    }
    
    .boloc-wat-filter-options {
        justify-content: center;
    }
    
    /* Cuộn ngang trên mobile */
    .boloc-wat-scrolling .boloc-wat-attributes-container {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .boloc-wat-scrolling .boloc-wat-attribute-group {
        min-width: 200px;
        max-width: 250px;
        flex-shrink: 0;
    }
    
    /* Xếp chồng trên mobile */
    .boloc-wat-stacked .boloc-wat-attributes-container {
        flex-direction: column;
    }
    
    .boloc-wat-stacked .boloc-wat-attribute-group {
        min-width: 100%;
        max-width: 100%;
    }
    
    .boloc-wat-actions {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .boloc-wat-reset-btn,
    .boloc-wat-apply-btn {
        flex: 1;
        text-align: center;
        min-width: 120px;
        margin: 0;
        text-transform: capitalize;
    }
    
    .boloc-wat-actions .boloc-wat-results-count {
        width: 100%;
        justify-content: center;
        margin-top: 10px;
    }
}

@media screen and (max-width: 480px) {
    /* Cuộn ngang trên mobile nhỏ */
    .boloc-wat-scrolling .boloc-wat-attribute-group {
        min-width: 180px;
        max-width: 220px;
    }
    
    /* Xếp chồng trên mobile nhỏ - giữ nguyên */
    .boloc-wat-stacked .boloc-wat-attribute-group {
        min-width: 100%;
        max-width: 100%;
    }
    
    .boloc-wat-filter-options {
        width: 100%;
        justify-content: space-between;
    }
    
    .boloc-wat-option-btn {
       flex: 1;
        text-align: center;
        min-width: 20px;
        margin: 0;
        text-transform: capitalize;
        font-size: 12px;
    }
}

/* ===== Widget specific styles ===== */
.boloc-wat-widget .boloc-wat-filter-wrapper {
    border: none;
    padding: 0;
    border-radius: 0;
}

.boloc-wat-widget .boloc-wat-attributes-container {
    flex-direction: column;
}

.boloc-wat-widget .boloc-wat-attribute-group {
    min-width: 100%;
    max-width: 100%;
}

/* ===== Flatsome Theme Compatibility ===== */
/* Ngăn filter gây layout shift trong grid system của Flatsome */
.shop-container .boloc-wat-filter-wrapper,
.category-page-row .boloc-wat-filter-wrapper,
.row .boloc-wat-filter-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    contain: layout style paint !important;
    position: relative !important;
}

/* Đảm bảo parent container không bị tràn */
.shop-container,
.col .shop-container {
    max-width: 100% !important;
    overflow: hidden !important;
}

/* Fix cho Flatsome column grid */
.col.large-9 .boloc-wat-filter-wrapper,
.col.large-8 .boloc-wat-filter-wrapper,
.col.large-6 .boloc-wat-filter-wrapper {
    max-width: 100% !important;
    width: 100% !important;
}

/* Ngăn các attribute group làm tràn container */
.boloc-wat-scrolling .boloc-wat-attributes-container {
    width: 100% !important;
    max-width: 100% !important;
}

/* Đảm bảo bộ lọc không gây layout reflow */
.boloc-wat-filter-wrapper {
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ===== Fix cho Flatsome Grid - ngăn column bị đẩy xuống ===== */
/* Quan trọng: Ngăn không cho nội dung trong col làm cho col vượt quá chiều rộng */
.category-page-row > .col {
    min-width: 0 !important;
}

.category-page-row .col.large-9,
.category-page-row .col.large-8 {
    min-width: 0 !important;
    overflow: hidden !important;
}

/* Đảm bảo shop-container không vượt quá width */
.col > .shop-container {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
}

/* Fix: Đảm bảo filter form không vượt quá container */
.boloc-wat-filter-form {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
}

/* Đảm bảo attributes container cuộn ngang thay vì đẩy ra ngoài */
.boloc-wat-attributes-container.boloc-wat-scrolling {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
}

/* Không cho attribute groups đẩy container ra ngoài */
.boloc-wat-filter-wrapper,
.boloc-wat-filter-wrapper * {
    max-width: 100% !important;
}

.boloc-wat-filter-wrapper .boloc-wat-attribute-group {
    max-width: 250px !important;
}
