/* filters.css - Version 2.5.0 - Sidebar filter system with WCAG compliant reset button */

/* ====================================================================
   DESKTOP SIDEBAR LAYOUT
   ==================================================================== */
.main-content-with-sidebar {
    display: flex;
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
}

.filter-sidebar {
    width: 330px;
    flex-shrink: 0;
}

.content-area {
    flex: 1;
    min-width: 0; /* Prevents flex item from overflowing */
}

.desktop-filters .filters {
    display: flex;
    flex-direction: column; /* Vertical stacking */
    gap: 25px;
    background: #f8f9fa;
    padding: 15px 8px; /* Reduced horizontal padding for more text space */
    border-radius: 8px;
    position: sticky;
    top: 20px;
    min-height: calc(100vh - 40px); /* At least viewport height */
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scrolling */
}

/* Remove the old horizontal layout */
.filter-tags,
.filter-right {
    flex: none;
}

.filter-right {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.filter-column {
    display: flex;
    flex-direction: column; /* Single column per section */
    width: 100%; /* Full sidebar width */
}

.filter-column h3 {
    margin: 0 0 15px 0;
    font-size: 1.1rem;
    color: #333;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 8px;
}

.filter-group {
    display: flex;
    flex-direction: column; /* Stack filter options vertically */
    gap: 8px;
    width: 100%; /* Prevent wrapping */
}

/* Ensure tag-filters is visible and single-column */
.tag-filters {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap; /* Prevent wrapping */
    width: 100%; /* Full width */
    column-count: 1; /* Disable multi-column */
    visibility: visible; /* Ensure visibility */
}


/* ====================================================================
   CHECKBOX STYLING - Explicit light mode appearance
   ==================================================================== */
.filter-option input[type="checkbox"] {
    appearance: auto;
    -webkit-appearance: checkbox;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    cursor: pointer;
    accent-color: #007bff;
    color-scheme: light;
}

/* ====================================================================
   FILTER OPTIONS AND PROGRESSIVE FILTERING
   ==================================================================== */
.filter-option {
    display: flex;
    align-items: flex-start; /* Align checkbox/emoji to top when text wraps */
    gap: 4px; /* Tighter spacing between elements */
    font-size: 0.95rem;
    color: #555;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 6px 0;
    box-sizing: border-box;
    line-height: 1.4;
}

/* Checkbox - fixed at top */
.filter-option input[type="checkbox"] {
    margin-top: 2px; /* Align with first line of text */
    flex-shrink: 0;
}

/* Icon/Emoji - fixed width, doesn't shrink, vertically centered */
.filter-option .filter-emoji {
    flex-shrink: 0;
    width: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Label text + count wrapper - can wrap naturally */
.filter-option .filter-label {
    flex: 1;
    min-width: 0; /* Allow text to wrap */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Count stays inline with last word */
.filter-option .tool-count {
    color: #595959;
    font-size: 0.85em;
    white-space: nowrap;
}

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

.filter-option.disabled input {
    pointer-events: none;
    cursor: not-allowed;
}

/* Legacy .tool-count outside of .filter-label (backwards compatibility) */
.filter-option > .tool-count {
    color: #666;
    font-size: 0.8em;
    margin-left: 4px;
    font-weight: 500;
    white-space: nowrap;
}

.filter-option.disabled .tool-count {
    color: #ccc;
}

.filter-option:hover:not(.disabled) {
    background-color: #e9ecef;
    border-radius: 4px;
}

/* ====================================================================
   RESET BUTTON - ALWAYS VISIBLE WITH WCAG COMPLIANT CONTRAST
   ==================================================================== */
.filter-reset-container {
    min-height: 48px; /* Reserve space for CLS prevention */
    display: flex;
    justify-content: stretch;
    margin-bottom: 15px; /* Spacing below button */
}

.reset-button {
    background: #e9ecef;
    color: #343a40; /* Darker gray for much better contrast */
    border: 2px solid #dee2e6;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: not-allowed;
    transition: all 0.3s ease;
    display: flex !important; /* Always visible */
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    opacity: 0.8; /* Slightly more visible than before */
    width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none; /* Disabled when no filters */
}

/* Active state when filters are applied */
.reset-button.has-filters {
    opacity: 1;
    background: #dc3545;
    color: white;
    border-color: #dc3545;
    pointer-events: auto; /* Enable clicking */
    cursor: pointer;
}

.reset-button.has-filters:hover {
    background: #c82333;
    border-color: #bd2130;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.3);
}

/* Inactive state styling improvements - WCAG compliant */
.reset-button:not(.has-filters) {
    background: #e9ecef;
    color: #343a40; /* Much darker gray for better contrast */
    border-color: #ced4da; /* Slightly darker border */
    cursor: not-allowed;
}

.active-filters-count {
    background: rgba(255, 255, 255, 0.9);
    color: #dc3545;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* When filters are active, count badge styling */
.reset-button.has-filters .active-filters-count {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

/* Legacy support for old visible class (remove after testing) */
.reset-button.visible {
    opacity: 1;
}

/* ====================================================================
   MOBILE FILTER SECTION
   ==================================================================== */
.mobile-filter-section {
    display: none; /* Hidden by default, shown on mobile */
    margin: 1rem 0;
}

.mobile-filter-button {
    background: #0069d9;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
    transition: background-color 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mobile-filter-button:hover {
    background: #0056b3;
}

.mobile-filter-count {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

/* ====================================================================
   ACTIVE FILTER CHIPS
   ==================================================================== */
.active-filters-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 0.5rem;
}

.filter-chip {
    background-color: #007bff;
    color: white;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: fadeIn 0.3s ease;
}

.filter-chip-remove {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    margin-left: 4px;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

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

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

/* ====================================================================
   MOBILE FILTER MODAL
   ==================================================================== */
.filter-modal-overlay {
    display: none; /* Hidden until activated */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.filter-modal-overlay.active {
    display: flex; /* Show when active */
    opacity: 1;
}

.filter-modal {
    background: white;
    border-radius: 12px 12px 0 0;
    width: 100%;
    max-height: 90vh;
    margin-top: auto;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.filter-modal-overlay.active .filter-modal {
    transform: translateY(0); /* Slide up when active */
}

.filter-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
    border-radius: 12px 12px 0 0;
}

.filter-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #495057; /* Improved contrast */
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.modal-close:hover {
    background: #e9ecef;
    color: #343a40; /* Darker on hover */
}

.filter-modal-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    max-height: calc(90vh - 140px);
}

.modal-filter-section {
    margin-bottom: 2rem;
}

.modal-filter-section h4 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 0.5rem;
}

.modal-filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.modal-filter-option {
    display: flex;
    align-items: flex-start; /* Align to top for wrapping text */
    gap: 8px;
    cursor: pointer;
    padding: 8px 0;
    transition: background-color 0.2s ease;
    border-radius: 4px;
    line-height: 1.4;
}

.modal-filter-option:hover {
    background: #f8f9fa;
}

.modal-filter-option input[type="checkbox"] {
    margin-top: 2px; /* Align with first line */
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Icon/Emoji - fixed width, doesn't shrink, vertically centered */
.modal-filter-option .filter-emoji {
    flex-shrink: 0;
    width: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}

/* Label text + count wrapper - can wrap naturally */
.modal-filter-option .filter-label {
    font-size: 0.95rem;
    color: #343a40;
    flex: 1;
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Count stays inline with last word */
.modal-filter-option .tool-count {
    color: #595959;
    font-size: 0.85em;
    white-space: nowrap;
}

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

.modal-filter-option.disabled input {
    pointer-events: none;
    cursor: not-allowed;
}

.filter-modal-footer {
    padding: 20px;
    background-color: #f5f5f5;
    border-top: 1px solid #ddd;
    display: flex;
    flex-direction: column;
}

/* Results preview - full width above buttons */
.results-preview {
    width: 100%;
    margin-bottom: 15px;
    padding: 8px 12px;
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

/* Different states for the preview */
.results-preview.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.results-preview.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.results-preview.neutral {
    background-color: #e2e3e5;
    color: #495057; /* Improved contrast */
    border: 1px solid #d6d8db;
}

/* Two buttons side by side - takes remaining width */
.footer-buttons {
    display: flex;
    gap: 10px;
    width: 100%;
}

.clear-all-button,
.apply-filters-button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.clear-all-button {
    background-color: #6c757d;
    color: white;
}

.clear-all-button:hover {
    background-color: #5a6268;
}

.apply-filters-button {
    background-color: #007bff;
    color: white;
}

.apply-filters-button:hover {
    background-color: #0056b3;
}

.apply-filters-button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

/* ====================================================================
   HIGH CONTRAST MODE SUPPORT
   ==================================================================== */
@media (prefers-contrast: high) {
    .reset-button:not(.has-filters) {
        background: #d1ecf1;
        color: #0c5460; /* Much darker text for high contrast */
        border-color: #bee5eb;
    }
    
    .reset-button.has-filters {
        background: #721c24;
        color: white;
        border-color: #721c24;
    }
    
    .modal-close {
        color: #212529; /* Very dark in high contrast mode */
    }
    
    .modal-filter-option .filter-label {
        color: #212529; /* Very dark in high contrast mode */
    }
    
    .results-preview.neutral {
        color: #212529; /* Very dark in high contrast mode */
    }
}

/* ====================================================================
   RESPONSIVE DESIGN
   ==================================================================== */
@media screen and (max-width: 1024px) {
    .main-content-with-sidebar {
        flex-direction: column;
    }
    
    .filter-sidebar {
        width: 100%;
    }
    
    .desktop-filters .filters {
        position: static;
        min-height: auto; /* Allow full content height */
        overflow-y: visible;
    }
}

@media screen and (max-width: 768px) {
.mobile-filter-section {
        display: block !important;
        margin: 0.5rem 0;
        padding: 0 15px; /* Match .quick-filters padding */
        visibility: visible !important;
        z-index: 10; /* Ensure above other elements */
    }
    
    .mobile-filter-button {
        display: flex !important;
        justify-content: center;
        width: 100%;
        max-width: 600px; /* Match search-input max-width */
        margin: 0 auto;
        visibility: visible !important;
        z-index: 10;
    }
    
    .desktop-filters {
        display: none; /* Hide desktop sidebar */
    }
    
    .main-content-with-sidebar {
        flex-direction: column;
    }
    
    body.modal-open {
        overflow: hidden;
    }
    
    /* Mobile-specific contrast improvements */
    .reset-button {
        color: #212529; /* Even darker on mobile for better visibility */
    }
    
    .reset-button:not(.has-filters) {
        color: #212529; /* Ensure consistent dark text on mobile */
        background: #f8f9fa; /* Slightly different background for mobile */
    }
}

@media screen and (min-width: 769px) {
    .mobile-filter-section,
    .filter-modal-overlay {
        display: none !important; /* Hide mobile filters and modal on desktop */
    }
    
    .desktop-filters {
        display: block;
    }
}

/* ====================================================================
   MOBILE SPACING IMPROVEMENTS
   ==================================================================== */

/* Reduce spacing between mobile filter button and content below on mobile */
@media screen and (max-width: 768px) {
    .mobile-filter-section {
        margin: 0.5rem 0; /* Reduced from 1rem to 0.5rem */
    }
    
    /* Reduce top margin of the main content area on mobile */
    .main-content-with-sidebar {
        margin-top: 0.5rem;
    }
    
    /* Reduce bottom margin of filter section specifically */
    .filter-sidebar {
        margin-bottom: 0.5rem;
    }
}