/**
 * Advanced Filtering System - CSS
 *
 * Provides animations, transitions, and styles for:
 * - AJAX filtering interface
 * - Mobile filter drawer
 * - Product comparison bar
 * - Active filter badges
 * - Loading states
 * - Hover effects
 */

/* ============================================
   LOADING STATES
   ============================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f4f6;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.filter-updating {
    opacity: 0.6;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

/* ============================================
   MOBILE FILTER DRAWER
   ============================================ */

.filter-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    background: white;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.filter-drawer.active {
    transform: translateY(0);
}

.filter-drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.filter-drawer-backdrop.active {
    opacity: 1;
    pointer-events: all;
}

.filter-drawer-header {
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.filter-drawer-handle {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 0 auto 10px;
}

.filter-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
}

.filter-drawer-footer {
    padding: 15px 20px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    background: white;
}

/* Mobile drawer buttons */
.drawer-btn-primary {
    flex: 1;
    padding: 12px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.drawer-btn-primary:hover {
    background: #2563eb;
}

.drawer-btn-secondary {
    flex: 1;
    padding: 12px;
    background: white;
    color: #6b7280;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.drawer-btn-secondary:hover {
    border-color: #d1d5db;
    background: #f9fafb;
}

/* ============================================
   FILTER SECTIONS
   ============================================ */

.filter-section {
    margin-bottom: 24px;
}

.filter-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s ease;
}

.filter-section-header:hover {
    color: #3b82f6;
}

.filter-section-title {
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #374151;
}

.filter-section-toggle {
    transition: transform 0.3s ease;
}

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

.filter-section-body {
    max-height: 400px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.filter-section-body.collapsed {
    max-height: 0;
    opacity: 0;
}

.filter-section-search {
    margin: 10px 0;
}

.filter-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-search-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.filter-options {
    max-height: 250px;
    overflow-y: auto;
    padding: 8px 0;
}

.filter-option {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.filter-option:hover {
    background: #f3f4f6;
}

.filter-option input[type="checkbox"],
.filter-option input[type="radio"] {
    margin-right: 10px;
    cursor: pointer;
}

.filter-option-label {
    flex: 1;
    font-size: 14px;
    color: #374151;
}

.filter-option-count {
    font-size: 12px;
    color: #9ca3af;
    margin-left: 8px;
}

.filter-option.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.filter-option.disabled:hover {
    background: transparent;
}

/* Show more/less buttons */
.filter-show-more {
    display: block;
    width: 100%;
    padding: 8px;
    margin-top: 8px;
    background: transparent;
    border: 1px dashed #d1d5db;
    border-radius: 6px;
    color: #6b7280;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-show-more:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    color: #374151;
}

/* ============================================
   ACTIVE FILTER BADGES
   ============================================ */

.active-filters-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    min-height: 32px;
}

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

.filter-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: #eff6ff;
    border: 1px solid #3b82f6;
    border-radius: 20px;
    font-size: 13px;
    color: #1e40af;
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.filter-badge-remove {
    margin-left: 8px;
    background: none;
    border: none;
    color: #3b82f6;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s ease;
}

.filter-badge-remove:hover {
    background: rgba(59, 130, 246, 0.2);
}

.clear-all-filters {
    padding: 6px 12px;
    background: #fef2f2;
    border: 1px solid #ef4444;
    border-radius: 20px;
    font-size: 13px;
    color: #dc2626;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-all-filters:hover {
    background: #fee2e2;
}

/* ============================================
   PRODUCT COMPARISON BAR
   ============================================ */

.comparison-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid #3b82f6;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    padding: 15px 20px;
    z-index: 9997;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.comparison-bar.active {
    transform: translateY(0);
}

.comparison-bar-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.comparison-items {
    display: flex;
    gap: 10px;
    flex: 1;
    overflow-x: auto;
}

.comparison-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f3f4f6;
    border-radius: 8px;
    font-size: 14px;
    white-space: nowrap;
    animation: slideIn 0.2s ease;
}

.comparison-item-remove {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.comparison-item-remove:hover {
    background: #e5e7eb;
    color: #374151;
}

.comparison-actions {
    display: flex;
    gap: 10px;
}

.comparison-btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.comparison-btn-primary {
    background: #3b82f6;
    color: white;
    border: none;
}

.comparison-btn-primary:hover {
    background: #2563eb;
}

.comparison-btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.comparison-btn-secondary {
    background: white;
    color: #6b7280;
    border: 2px solid #e5e7eb;
}

.comparison-btn-secondary:hover {
    border-color: #d1d5db;
    background: #f9fafb;
}

/* ============================================
   COMPARISON MODAL
   ============================================ */

.comparison-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.comparison-modal.active {
    opacity: 1;
    pointer-events: all;
}

.comparison-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
}

.comparison-modal-content {
    position: relative;
    background: white;
    border-radius: 12px;
    max-width: 1400px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.comparison-modal.active .comparison-modal-content {
    transform: scale(1);
}

.comparison-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.comparison-modal-title {
    font-size: 20px;
    font-weight: 700;
    color: #111827;
}

.comparison-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #6b7280;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.comparison-modal-close:hover {
    background: #f3f4f6;
    color: #374151;
}

.comparison-modal-body {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    padding: 24px;
}

.comparison-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.comparison-table th,
.comparison-table td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.comparison-table th {
    background: #f9fafb;
    font-weight: 600;
    color: #374151;
    position: sticky;
    top: 0;
    z-index: 1;
}

.comparison-table tr:last-child td {
    border-bottom: none;
}

.comparison-table .spec-label {
    font-weight: 600;
    color: #6b7280;
    min-width: 150px;
}

.comparison-product-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.comparison-product-image {
    width: 100%;
    max-width: 200px;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
}

.comparison-product-name {
    font-weight: 600;
    color: #111827;
    font-size: 14px;
}

.comparison-product-price {
    font-size: 18px;
    font-weight: 700;
    color: #3b82f6;
}

/* ============================================
   PRICE RANGE SLIDER
   ============================================ */

.price-range-container {
    padding: 15px 0;
}

.price-range-inputs {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.price-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.price-input:focus {
    outline: none;
    border-color: #3b82f6;
}

.price-slider {
    width: 100%;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    position: relative;
    cursor: pointer;
}

.price-slider-fill {
    position: absolute;
    height: 100%;
    background: #3b82f6;
    border-radius: 3px;
}

.price-slider-thumb {
    position: absolute;
    width: 18px;
    height: 18px;
    background: white;
    border: 2px solid #3b82f6;
    border-radius: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    transition: box-shadow 0.2s ease;
}

.price-slider-thumb:hover,
.price-slider-thumb:active {
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.price-slider-thumb:active {
    cursor: grabbing;
}

/* ============================================
   SORT DROPDOWN
   ============================================ */

.sort-container {
    position: relative;
}

.sort-dropdown {
    padding: 10px 36px 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: white;
    font-size: 14px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px;
    transition: all 0.2s ease;
}

.sort-dropdown:hover {
    border-color: #9ca3af;
}

.sort-dropdown:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ============================================
   PRODUCT GRID ANIMATIONS
   ============================================ */

.product-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.compare-checkbox {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    z-index: 10;
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

@media (max-width: 768px) {
    .filter-section-body {
        max-height: 300px;
    }

    .filter-options {
        max-height: 200px;
    }

    .comparison-bar-content {
        flex-direction: column;
        gap: 10px;
    }

    .comparison-items {
        width: 100%;
    }

    .comparison-actions {
        width: 100%;
    }

    .comparison-btn {
        flex: 1;
    }

    .comparison-modal-content {
        max-height: 95vh;
        margin: 10px;
    }

    .comparison-table {
        font-size: 14px;
    }

    .comparison-table th,
    .comparison-table td {
        padding: 12px 8px;
    }
}

@media (max-width: 640px) {
    .filter-badge {
        font-size: 12px;
        padding: 5px 10px;
    }

    .comparison-modal-body {
        padding: 16px;
    }

    .comparison-product-image {
        max-width: 150px;
        height: 120px;
    }
}

/* ============================================
   UTILITY ANIMATIONS
   ============================================ */

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.slide-down {
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.filter-option input:focus,
.compare-checkbox:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============================================
   DARK MODE SUPPORT (Optional)
   ============================================ */

@media (prefers-color-scheme: dark) {
    .filter-drawer,
    .comparison-bar,
    .comparison-modal-content {
        background: #1f2937;
        color: #f3f4f6;
    }

    .filter-drawer-header,
    .filter-drawer-footer,
    .comparison-modal-header {
        border-color: #374151;
    }

    .filter-option:hover {
        background: #374151;
    }

    .filter-search-input,
    .price-input,
    .sort-dropdown {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }

    .filter-badge {
        background: #1e3a8a;
        border-color: #3b82f6;
        color: #93c5fd;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .filter-drawer,
    .comparison-bar,
    .filter-section,
    .comparison-btn,
    .filter-badge-remove {
        display: none !important;
    }

    .comparison-modal-content {
        max-height: none;
    }
}
