/* Admin filter panel */
.filter-panel {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.filter-panel.hidden {
    transform: translateY(-100%);
}

/* Filter group layout */
.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.5rem;
    align-items: center;
    /* Vertical alignment fix */
}

.filter-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #f5f5f5;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.filter-item.active {
    background: #e0f2fe;
}

.filter-item[data-state="forced"] {
    background: #c8e6c9;
}

.filter-item[data-state="discarded"] {
    background: #ffcdd2;
}

.filter-subgroup {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem;
    background: #f8f8f8;
    border-radius: 8px;
}

.filter-label {
    font-weight: 500;
    margin-right: 0.5rem;
    color: #666;
}

.filter-item[data-filter^="rarity"] {
    padding: 0.3rem 0.8rem;
    /* background: #e8e8e8; */
}

.filter-item[data-filter^="rarity"][data-state^="neutral"] {
    background: #e8e8e8;
}

.filter-item[data-filter^="rarity"] .filter-toggle {
    width: 20px;
    height: 20px;
    font-size: 0.9rem;
}

.filter-toggle {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #fff;
}

/* Search input alignment */
.filter-dropdown {
    position: relative;
    display: flex;
    align-items: center;
    height: 40px;
    /* Match class filter height */
}

.filter-search {
    height: 40px;
    padding: 0 12px;
    border-radius: 20px;
    border: 1px solid #444;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    margin-left: auto;
    /* Push to right side */
}

.filter-search-wrapper {
    margin-right: auto;
    padding: 0 8px;
}

.filter-options {
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    max-height: 300px;
    overflow-y: auto;
    z-index: 11;
    display: none;
}

.filter-options.active {
    display: block;
}

.filter-option {
    padding: 0.5rem 1rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.selected-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
}

/* Mobile specific styles */
@media (max-width: 768px) {
    .filter-panel {
        top: -1px;
        /* Prevent 1px gap */
    }

    .filter-group {
        flex-direction: column;
    }

    .filter-search {
        width: 100%;
    }
}

/* Class filters container */
.class-filter-container {
    display: flex;
    gap: 8px;
    padding: 4px 16px;
    /* Add side padding */
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
    min-height: 48px;
    margin: 0 -8px;
    /* Compensate for padding */
}

/* Scrollbar styling */
.class-filter-container::-webkit-scrollbar {
    height: 3px;
    background: transparent;
}

.class-filter-container::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 2px;
}

/* Class filter items */
.class-filter-item {
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    overflow: hidden;
    /* Keep content within bounds */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4px;
    /* Add internal spacing */
}

/* Class icon sizing fix */
.class-icon {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    padding: 0;
    /* Remove previous padding */
    filter: invert(1);
    object-fit: contain;
    position: static;
    /* Remove absolute positioning */
}

/* Filter states */
.class-filter-item[data-state="forced"] {
    background: rgba(76, 175, 80, 0.9);
    /* Solid green background */
    border-color: #4CAF50;
}

/* Hover effects with safe space */
.class-filter-item:hover {
    transform: scale(1.15);
    z-index: 2;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    margin: 0 4px;
    /* Prevent cropping */
}

.class-filter-scroll-wrapper {
    position: relative;
    padding-bottom: 4px;
    /* Space for scrollbar */
}

@media (max-width: 768px) {

    /* Main filter panel alignment */
    .filter-group {
        align-items: flex-start;
        padding: 0.5rem 1rem;
        gap: 0.75rem;
    }

    /* Filter subgroups (rarity/class) */
    .filter-subgroup {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        padding: 0;
        background: none;
    }

    /* Filter group labels */
    .filter-label {
        margin: 0 0 0.25rem 0;
        font-size: 0.9em;
        color: #444;
    }

    .filter-subgroup .filter-label {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Rarity filter row */
    .filter-subgroup:has(.filter-item[data-filter^="rarity"]) {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Rarity filter items */
    .filter-item[data-filter^="rarity"] {
        padding: 0.25rem 0.8rem;
        font-size: 0.9em;
        gap: 0.25rem;
    }

    /* Hide toggle circles on mobile for rarity */
    .filter-item[data-filter^="rarity"] .filter-toggle {
        display: none;
    }

    /* Force single line without scroll */
    .class-filter-scroll-wrapper {
        overflow: hidden;
        padding-right: 32px;
    }

    .class-filter-container {
        padding: 4px 0;
        margin: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 4px;
        /* Compensate for negative margin */
        width: calc(100% + 16px);
        margin-right: -8px;
        padding-right: 8px;
    }

    /* Class filter items */
    .class-filter-item {
        width: calc(12.5% - 5px);
        margin-right: 1px;
        /* 8 items per row accounting for gap */
        height: auto;
        min-width: 32px;
        /* Minimum size */
        aspect-ratio: 1;
        /* Maintain square shape */
        flex-shrink: 1;
        /* Allow shrinking */
        padding: 2px;
    }

    /* Disable hover effects on mobile */
    .class-filter-item:hover {
        transform: none !important;
        margin: 0 !important;
        box-shadow: none !important;
    }

    /* Adjust class icon sizing */
    .class-icon {
        max-width: 24px;
        max-height: 24px;
    }

    /* Search filter adjustments */
    .filter-search-wrapper {
        width: 100%;
        padding: 0;
    }

    .filter-search {
        width: 100%;
        margin: 0;
        height: 36px;
    }

    /* Horizontal layout for rarity filters */
    .filter-subgroup:has(.filter-item[data-filter^="rarity"]) {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    /* State colors for rarity filters */
    .filter-item[data-filter^="rarity"][data-state="forced"] {
        background: #c8e6c9 !important;
    }

    .filter-item[data-filter^="rarity"][data-state="discarded"] {
        background: #ffcdd2 !important;
    }

    /* Indexed filter alignment */
    .filter-item[data-filter="indexed"] {
        margin-right: auto;
    }
}

.mastery-filter-group {
    display: flex;
    gap: 1px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.mastery-filter-item {
    /* mirror .class-filter-item basics */
    padding: 6px 8px !important;
    border-radius: 0 !important;
    width: 40px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

/* Hover states */
.mastery-filter:not([data-active="true"]):hover {
    background: rgba(255, 255, 255, 0.1);
}

.mastery-filter-item.filter-forced {
    background: rgba(76, 175, 80, 0.9);
    border-color: #4CAF50;
}

.mastery-filter-item.filter-neutral {
    background: rgba(255, 255, 255, 0.1);
    border-color: transparent;
}

.mastery-filter-item.filter-discarded {
    background: rgba(175, 76, 80, 0.9);
    border-color: transparent;
}