/**
 * Floating Category Filter - Professional Design
 * Modern, responsive, and accessible category filter
 */

:root {
    --ts-filter-primary: #1b8058;
    --ts-filter-primary-dark: #156843;
    --ts-filter-secondary: #f8f9fa;
    --ts-filter-border: #e1e4e8;
    --ts-filter-text: #24292e;
    --ts-filter-text-muted: #586069;
    --ts-filter-shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --ts-filter-shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --ts-filter-shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
    --ts-filter-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --ts-filter-radius: 12px;
}

/* Main Container - ALWAYS FIXED - IGNORE ALL SCROLL */
.ts-floating-filter,
.ts-floating-filter.ts-always-fixed {
    position: fixed !important;
    top: 125px !important;
    right: 20px !important;
    left: auto !important;
    bottom: auto !important;
    z-index: 9999 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Removed wrapper - not needed anymore */

/* Trigger Button */
.ts-filter-trigger {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--ts-filter-primary);
    color: white;
    border: none;
    border-radius: var(--ts-filter-radius);
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--ts-filter-transition);
    box-shadow: var(--ts-filter-shadow-md);
    position: relative;
    overflow: hidden;
}

.ts-filter-trigger::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.ts-filter-trigger:hover {
    background: var(--ts-filter-primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--ts-filter-shadow-lg);
}

.ts-filter-trigger:hover::before {
    left: 100%;
}

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

.ts-filter-icon {
    font-size: 18px;
    color: white;
}

.ts-filter-label {
    font-weight: 500;
}

.ts-filter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: white;
    color: var(--ts-filter-primary);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

/* Ignore floating state - always same position */
.ts-floating-filter.is-floating {
    position: fixed !important;
    top: 125px !important;
    right: 20px !important;
    left: auto !important;
    bottom: auto !important;
}



/* Filter Panel - FORCE CENTER WITH FULL HEIGHT */
.ts-filter-panel {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) scale(0.9) !important;
    width: 450px !important;
    max-width: 90vw !important;
    height: 95vh !important;
    max-height: 95vh !important;
    margin: 0 !important;
    background: white;
    border-radius: var(--ts-filter-radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999 !important;
}

.ts-filter-panel[aria-hidden="false"],
.ts-filter-panel.is-open {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translate(-50%, -50%) scale(1) !important;
}

/* Animation variants */
.ts-floating-filter[data-animation="fade"] .ts-filter-panel {
    transform: translate(-50%, -50%) scale(0.95);
}

.ts-floating-filter[data-animation="fade"] .ts-filter-panel[aria-hidden="false"],
.ts-floating-filter[data-animation="fade"] .ts-filter-panel.is-open {
    transform: translate(-50%, -50%) scale(1);
}

.ts-floating-filter[data-animation="slide"] .ts-filter-panel {
    transform: translate(-50%, -40%) scale(0.95);
}

.ts-floating-filter[data-animation="slide"] .ts-filter-panel[aria-hidden="false"],
.ts-floating-filter[data-animation="slide"] .ts-filter-panel.is-open {
    transform: translate(-50%, -50%) scale(1);
}

/* Panel Header */
.ts-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ts-filter-border);
    background: var(--ts-filter-secondary);
}

.ts-panel-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--ts-filter-text);
}

.ts-panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ts-btn-view-all,
.ts-btn-close {
    padding: 6px 12px;
    background: white;
    border: 1px solid var(--ts-filter-border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ts-filter-text-muted);
    cursor: pointer;
    transition: var(--ts-filter-transition);
}

.ts-btn-view-all:hover,
.ts-btn-close:hover {
    background: var(--ts-filter-primary);
    color: white;
    border-color: var(--ts-filter-primary);
}

.ts-btn-close {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Search Box */
.ts-panel-search {
    position: relative;
    padding: 12px 20px;
    background: white;
    border-bottom: 1px solid var(--ts-filter-border);
}

.ts-search-input {
    width: 100%;
    padding: 10px 36px 10px 12px;
    border: 2px solid var(--ts-filter-border);
    border-radius: 8px;
    font-size: 14px;
    transition: var(--ts-filter-transition);
    background: white;
}

.ts-search-input:focus {
    outline: none;
    border-color: var(--ts-filter-primary);
    box-shadow: 0 0 0 3px rgba(27, 128, 88, 0.1);
}

.ts-search-icon {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ts-filter-text-muted);
    pointer-events: none;
}

/* Panel Content */
.ts-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    background: white;
    
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.ts-panel-content::-webkit-scrollbar {
    width: 6px;
}

.ts-panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.ts-panel-content::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

.ts-panel-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

/* Category List */
.ts-category-list {
    padding: 0;
}

/* Category Wrapper */
.ts-category-wrapper {
    margin: 4px 0;
}

/* Category Item */
.ts-category-item {
    display: flex;
    align-items: center;
    margin: 0 8px;
    border-radius: 8px;
    transition: var(--ts-filter-transition);
    position: relative;
    min-height: 48px;
}

.ts-category-item:hover {
    background: var(--ts-filter-secondary);
}

.ts-category-item.is-current {
    background: linear-gradient(to right, rgba(27, 128, 88, 0.1), transparent);
    border-left: 3px solid var(--ts-filter-primary);
}

.ts-category-item.has-children {
    padding-left: 0;
}

.ts-category-link {
    display: flex;
    align-items: center;
    flex: 1;
    padding: 10px 12px;
    text-decoration: none;
    color: var(--ts-filter-text);
    gap: 12px;
    min-height: 48px;
}

.ts-category-thumb {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--ts-filter-secondary);
    flex-shrink: 0;
}

.ts-category-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s;
}

.ts-category-item:hover .ts-category-thumb img {
    transform: scale(1.1);
}

.ts-category-info {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ts-category-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--ts-filter-text);
    line-height: 1.4;
}

.ts-category-count {
    font-size: 12px;
    color: var(--ts-filter-text-muted);
    background: var(--ts-filter-secondary);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Category Toggle - RIGHT side with BLACK color */
.ts-category-toggle {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--ts-filter-transition);
    margin: 0 8px 0 4px;
    flex-shrink: 0;
    color: #000000 !important;
}

.ts-category-toggle:hover {
    background: var(--ts-filter-secondary);
    color: var(--ts-filter-primary);
}

.ts-category-toggle.is-open .ts-icon-chevron {
    transform: rotate(-90deg);
}

.ts-icon-chevron {
    transition: transform 0.3s;
    display: block;
    font-size: 14px;
    color: #000000;
}

/* Subcategories */
.ts-subcategories {
    display: none;
    padding-left: 52px;
    margin: 0;
}

.ts-subcategories.is-open {
    display: block;
}

/* Subcategory items */
.ts-subcategories .ts-category-wrapper {
    margin: 2px 0;
}

.ts-subcategories .ts-category-item {
    min-height: 40px;
    font-size: 14px;
    background: var(--ts-filter-secondary);
    margin: 2px 8px 2px 0;
}

.ts-subcategories .ts-category-item:hover {
    background: white;
}

.ts-subcategories .ts-category-thumb {
    width: 28px;
    height: 28px;
}

.ts-subcategories .ts-category-name {
    font-size: 13px;
}

/* Third level */
.ts-subcategories .ts-subcategories {
    padding-left: 24px;
}

.ts-subcategories .ts-subcategories .ts-category-item {
    min-height: 36px;
    font-size: 12px;
}

/* Loading State */
.ts-subcategories.is-loading::after {
    content: '';
    display: block;
    width: 30px;
    height: 30px;
    margin: 20px auto;
    border: 3px solid var(--ts-filter-border);
    border-top-color: var(--ts-filter-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Panel Footer */
.ts-panel-footer {
    padding: 12px 20px;
    background: var(--ts-filter-secondary);
    border-top: 1px solid var(--ts-filter-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ts-filter-stats {
    font-size: 13px;
    color: var(--ts-filter-text-muted);
}

/* Overlay - HIGH Z-INDEX */
.ts-filter-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 999998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.ts-filter-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

/* RTL Support */
[dir="rtl"] .ts-floating-filter.is-floating {
    right: auto;
    left: 20px;
}

[dir="rtl"] .ts-filter-panel {
    right: auto;
    left: 0;
}

[dir="rtl"] .ts-category-item.is-current {
    border-left: none;
    border-right: 3px solid var(--ts-filter-primary);
}

[dir="rtl"] .ts-subcategories {
    padding-left: 0;
    padding-right: 48px;
}

[dir="rtl"] .ts-search-icon {
    right: auto;
    left: 32px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    /* Mobile button positioning */
    .ts-floating-filter,
    .ts-floating-filter.ts-always-fixed,
    .ts-floating-filter.is-floating {
        position: fixed !important;
        top: auto !important;
        bottom: 60px !important;
        right: 0px !important;
        left: auto !important;
        z-index: 999 !important;
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
    }
    
    .ts-filter-trigger {
        position: fixed !important;
        bottom: 60px !important;
        right: 0px !important;
        z-index: 999 !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
    }
    
    /* Fullscreen panel on mobile with HIGH Z-INDEX */
    .ts-filter-panel,
    .ts-floating-filter[data-animation="fade"] .ts-filter-panel,
    .ts-floating-filter[data-animation="slide"] .ts-filter-panel {
        position: fixed !important;
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        max-width: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        transform: translateY(100%) !important;
        margin: 0 !important;
        z-index: 999999 !important;
        background: white !important;
    }
    
    .ts-filter-panel[aria-hidden="false"],
    .ts-filter-panel.is-open,
    .ts-floating-filter[data-animation="fade"] .ts-filter-panel[aria-hidden="false"],
    .ts-floating-filter[data-animation="fade"] .ts-filter-panel.is-open,
    .ts-floating-filter[data-animation="slide"] .ts-filter-panel[aria-hidden="false"],
    .ts-floating-filter[data-animation="slide"] .ts-filter-panel.is-open {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        transform: translateY(0) !important;
        border-radius: 0 !important;
        z-index: 999999 !important;
    }
    
    .ts-panel-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: white;
    }
    
    
    /* Mobile floating action button style */
    .ts-filter-trigger {
        display: flex !important;
        width: 56px !important;
        height: 56px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        justify-content: center !important;
        align-items: center !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.25) !important;
        background: var(--ts-filter-primary) !important;
        position: relative !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    .ts-filter-trigger .ts-filter-label {
        display: none !important;
    }
    
    .ts-filter-trigger .ts-filter-badge {
        display: none !important;
    }
    
    .ts-filter-icon {
        font-size: 24px !important;
        color: white !important;
        display: block !important;
    }
    
    /* Panel content adjustments for mobile */
    .ts-panel-content {
        height: calc(100% - 140px); /* Account for header */
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 60px;
        position: relative;
        z-index: 1;
    }
    
    /* Ensure all elements are clickable */
    .ts-filter-panel * {
        pointer-events: auto !important;
    }
    
    .ts-category-link,
    .ts-category-toggle,
    .ts-btn-close,
    .ts-btn-view-all {
        cursor: pointer !important;
        pointer-events: auto !important;
    }
    
    /* Animation for fullscreen panel */
    @keyframes slideUpFullscreen {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    
    .ts-filter-panel {
        animation: none;
    }
    
    .ts-filter-panel.is-open {
        animation: slideUpFullscreen 0.3s ease-out;
    }
}

/* Accessibility */
.ts-filter-trigger:focus-visible,
.ts-btn-view-all:focus-visible,
.ts-btn-close:focus-visible,
.ts-category-toggle:focus-visible {
    outline: 2px solid var(--ts-filter-primary);
    outline-offset: 2px;
}

/* No Results State */
.ts-no-results {
    padding: 40px 20px;
    text-align: center;
    color: var(--ts-filter-text-muted);
}

.ts-no-results-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    opacity: 0.3;
}

.ts-no-results-text {
    font-size: 14px;
    margin: 0;
}

/* Print Styles */
@media print {
    .ts-floating-filter {
        display: none;
    }
}