/**
 * Frontend styles for Smart Attribute Filter
 * WoodMart Theme Compatible
 */

/* ===================================
   Main Filter Wrapper
   =================================== */

.saf-filters-wrapper {
    position: relative;
    margin-bottom: 30px;
    padding: 0;
}

.saf-filters-container {
    border: none;
    border-radius: 20px;
    padding: 25px;
    transition: opacity 0.3s ease;
}

.saf-filters-container.saf-loading {
    opacity: 0.6;
    pointer-events: none;
}

/* ===================================
   Filter Header
   =================================== */

.saf-filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f5f5f5;
}

.saf-filters-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #333;
}

.saf-reset-filters {
    background: transparent;
    border: 1px solid #ddd;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    transition: all 0.3s ease;
}

.saf-reset-filters:hover {
    background: #f5f5f5;
    border-color: #999;
    color: #333;
}

/* ===================================
   Filter Grid
   =================================== */

.saf-filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.saf-filter-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.saf-filter-label {
    font-weight: 600;
    font-size: 18px;
    color: #333;
    text-transform: capitalize;
    letter-spacing: 0.5px;
}

.saf-filter-label label {
    margin: 0;
    display: block;
    font-weight: 600;
}

/* ===================================
   Dropdown Filter Style
   =================================== */

.saf-filter-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    color: #333;
    background: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    /* Remove height constraints for native select */
    height: auto;
    min-height: 40px;
    /* Hide native multi-select scrolling appearance */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

/* Style for when Select2 is NOT available - use custom dropdown */
.saf-filter-control:not(.saf-has-select2) .saf-filter-select {
    display: none; /* Hide native select, we'll use custom dropdown */
}

.saf-filter-select:hover {
    border-color: #999;
    background: #f5f5f5;
}

.saf-filter-select:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 1px #0073aa;
}

/* Custom Dropdown (when Select2 not available) */
.saf-custom-dropdown {
    position: relative;
    width: 100%;
}

.saf-dropdown-toggle {
    width: 100%;
    padding: 10px 35px 10px 12px;
    border: 1px solid #ddd;
    border-radius: 12px;
    font-size: 14px;
    color: #333;
    background: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 40px;
    box-shadow: 0 0 0 1px #0073aa;
}

.saf-dropdown-toggle:hover {
    border-color: #999;
    background: #f5f5f5;
}

.saf-dropdown-toggle.active {
    border-color: #0073aa;
    box-shadow: 0 0 0 1px #0073aa;
}

.saf-dropdown-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    transition: transform 0.3s ease;
}

.saf-dropdown-toggle.active .saf-dropdown-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.saf-dropdown-arrow::before {
    content: "▼";
    font-size: 10px;
    color: #666;
}

.saf-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.saf-dropdown-menu.active {
    display: block;
}

.saf-dropdown-option {
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.saf-dropdown-option:hover {
    background: #f5f5f5;
}

.saf-dropdown-option.selected {
    background: #e3f2fd;
    color: #0073aa;
    font-weight: 500;
}

.saf-dropdown-option input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.saf-dropdown-placeholder {
    color: #999;
}

.saf-selected-count {
    background: #0073aa;
    color: #fff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

/* Select2 Integration (if available) */
.saf-filter-control .select2-container {
    width: 100% !important;
}

.saf-filter-control .select2-container--default .select2-selection--multiple {
    border: 1px solid #ddd;
    border-radius: 4px;
    min-height: 40px;
    padding: 5px;
}

.saf-filter-control .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background: #0073aa;
    border-color: #0073aa;
    color: #fff;
    padding: 3px 8px;
    border-radius: 3px;
}

.saf-filter-control .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: #fff;
    margin-right: 5px;
}

.saf-filter-control .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #fff;
}

/* Dropdown scrollbar styling */
.saf-dropdown-menu::-webkit-scrollbar {
    width: 8px;
}

.saf-dropdown-menu::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.saf-dropdown-menu::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.saf-dropdown-menu::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ===================================
   Checkbox Filter Style
   =================================== */

.saf-checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.saf-checkbox-list::-webkit-scrollbar {
    width: 6px;
}

.saf-checkbox-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.saf-checkbox-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.saf-checkbox-list::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.saf-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 5px;
    border-radius: 3px;
    transition: background 0.2s ease;
}

.saf-checkbox-item:hover {
    background: #fff;
}

.saf-filter-checkbox {
    margin: 0;
    cursor: pointer;
}

.saf-checkbox-label {
    font-size: 14px;
    color: #555;
    cursor: pointer;
    user-select: none;
}

.saf-term-count {
    color: #999;
    font-size: 13px;
}

/* ===================================
   Color Swatch Filter Style
   =================================== */

.saf-color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.saf-color-swatch {
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.saf-color-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.saf-color-inner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #e0e0e0;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.saf-color-swatch:hover .saf-color-inner {
    border-color: #999;
    transform: scale(1.1);
}

.saf-color-swatch.active .saf-color-inner {
    border-color: #0073aa;
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.saf-color-name {
    font-size: 11px;
    color: #666;
    text-align: center;
    max-width: 50px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===================================
   Active Filters
   =================================== */

.saf-active-filters {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.saf-active-filters-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.saf-active-label {
    font-weight: 600;
    font-size: 13px;
    color: #666;
    margin-right: 5px;
}

.saf-active-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #0073aa;
    color: #fff;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}

.saf-remove-filter {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
}

.saf-remove-filter:hover {
    background: rgba(255, 255, 255, 0.2);
}

.saf-remove-filter span {
    display: block;
    line-height: 1;
}

/* ===================================
   Loading Overlay
   =================================== */

.saf-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    z-index: 999;
}

.saf-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #0073aa;
    border-radius: 50%;
    animation: saf-spin 1s linear infinite;
}

@keyframes saf-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===================================
   WoodMart Theme Compatibility
   =================================== */

/* WoodMart uses specific classes and styles */
.woodmart-shop-tools .saf-filters-wrapper {
    margin-bottom: 20px;
}

/* Match WoodMart button styles */
body.woodmart-theme .saf-reset-filters {
    background: var(--wd-primary-color, #83b735);
    color: #fff;
    border: none;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

body.woodmart-theme .saf-reset-filters:hover {
    background: var(--wd-primary-color-hover, #6d9b2a);
}

/* Match WoodMart active tag colors */
body.woodmart-theme .saf-active-filter-tag {
    background: var(--wd-primary-color, #83b735);
}

/* Match WoodMart form elements */
body.woodmart-theme .saf-filter-select,
body.woodmart-theme .saf-dropdown-toggle {
    border-color: var(--wd-border-color, #e0e0e0);
}

body.woodmart-theme .saf-filter-select:focus,
body.woodmart-theme .saf-dropdown-toggle.active {
    border-color: var(--wd-primary-color, #83b735);
    box-shadow: 0 0 0 1px var(--wd-primary-color, #83b735);
}

/* Match WoodMart checkbox styles */
body.woodmart-theme .saf-filter-checkbox:checked {
    accent-color: var(--wd-primary-color, #83b735);
}

/* WoodMart dropdown options */
body.woodmart-theme .saf-dropdown-option.selected {
    background: rgba(131, 183, 53, 0.1);
    color: var(--wd-primary-color, #83b735);
}

body.woodmart-theme .saf-selected-count {
    background: var(--wd-primary-color, #83b735);
}

/* ===================================
   Responsive Design
   =================================== */

@media (max-width: 1024px) {
    .saf-filters-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 15px;
    }
}

@media (max-width: 768px) {
    .saf-filters-container {
        padding: 20px 15px;
    }
    
    .saf-filters-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .saf-filters-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .saf-reset-filters {
        width: 100%;
        text-align: center;
    }
    
    .saf-active-filters-list {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .saf-filters-title {
        font-size: 18px;
    }
    
    .saf-color-swatches {
        justify-content: center;
    }
    
    .saf-checkbox-list {
        max-height: 150px;
    }
}

/* ===================================
   Print Styles
   =================================== */

@media print {
    .saf-filters-wrapper {
        display: none;
    }
}

/* ===================================
   Accessibility
   =================================== */

.saf-filter-checkbox:focus,
.saf-color-input:focus + .saf-color-inner {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.saf-remove-filter:focus {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .saf-filters-container {
        border-width: 2px;
    }
    
    .saf-active-filter-tag {
        border: 2px solid #000;
    }
}

/* ===================================
   Price Filter Slider
   =================================== */

.saf-price-filter {
    margin-bottom: 30px;
    padding: 0;
}

.saf-price-slider-wrapper {
    margin-top: 20px;
    padding-top: 40px;
    position: relative;
}

.saf-price-tooltip {
    position: absolute;
    background: #1e73be;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    top: -35px;
    transform: translateX(-50%);
    transition: left 0.1s ease-out;
}

.saf-price-tooltip::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #1e73be;
}

.saf-price-scale {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    padding: 0 10px;
}

.saf-scale-value {
    font-size: 13px;
    color: #999;
    font-weight: 400;
}

.saf-price-slider-container {
    position: relative;
    height: 48px;
    margin: 0 10px;
    padding: 15px 0;
}

.saf-price-slider-track {
    position: absolute;
    width: 100%;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    top: 50%;
    transform: translateY(-50%);
}

.saf-price-slider-range {
    position: absolute;
    height: 4px;
    background: #1e73be;
    border-radius: 2px;
}

.saf-price-range {
    position: absolute;
    width: 100%;
    height: 48px;
    background: transparent;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    top: 0;
    margin: 0;
    padding: 0;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    z-index: 2;
}

.saf-price-range:focus {
    outline: none;
}

.saf-price-range:focus::-webkit-slider-thumb {
    outline: 2px solid #1e73be;
    outline-offset: 2px;
}

.saf-price-range:focus::-moz-range-thumb {
    outline: 2px solid #1e73be;
    outline-offset: 2px;
}

.saf-price-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: #1e73be;
    border: 3px solid #fff;
    border-radius: 50%;
    cursor: grab;
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    transition: all 0.2s ease;
    position: relative;
}

.saf-price-range::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: #1e73be;
    border: 3px solid #fff;
    border-radius: 50%;
    cursor: grab;
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    transition: all 0.2s ease;
}

.saf-price-range:active::-webkit-slider-thumb {
    cursor: grabbing;
    transform: scale(1.15);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

.saf-price-range:active::-moz-range-thumb {
    cursor: grabbing;
    transform: scale(1.15);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

.saf-price-range::-webkit-slider-thumb:hover {
    background: #155a94;
    transform: scale(1.1);
}

.saf-price-range::-moz-range-thumb:hover {
    background: #155a94;
    transform: scale(1.1);
}

/* Remove default track styling */
.saf-price-range::-webkit-slider-runnable-track {
    background: transparent;
}

.saf-price-range::-moz-range-track {
    background: transparent;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .saf-price-slider-wrapper {
        padding-top: 50px;
    }
    
    .saf-price-tooltip {
        font-size: 12px;
        padding: 5px 10px;
        top: -40px;
    }
    
    .saf-scale-value {
        font-size: 11px;
    }
    
    .saf-price-slider-container {
        height: 50px;
        padding: 20px 0;
    }
    
    .saf-price-slider-track {
        height: 6px;
    }
    
    .saf-price-slider-range {
        height: 6px;
    }
    
    .saf-price-range {
        height: 50px;
    }
    
    .saf-price-range::-webkit-slider-thumb {
        width: 30px;
        height: 30px;
        border: 4px solid #fff;
    }
    
    .saf-price-range::-moz-range-thumb {
        width: 30px;
        height: 30px;
        border: 4px solid #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .saf-filters-container,
    .saf-reset-filters,
    .saf-checkbox-item,
    .saf-color-inner {
        transition: none;
    }
    
    .saf-spinner {
        animation: none;
        border-top-color: transparent;
    }
    
    .saf-price-range::-webkit-slider-thumb,
    .saf-price-range::-moz-range-thumb {
        transition: none;
    }
}

