/* 
 * CSS for Filterable Cards
 * Follows the JPK theme's design system
 */

/* Component specific styles are in the filterable-components/ directory */

/* Filterable components system */
.filterable-system {
    h1, h2, h3, h4, h5, h6 {
        text-transform: uppercase;
    }
    h2 {
        font-size: clamp(1.75rem, 1.25rem + 1.25vw, 2.25rem);
    }
    /* Topics container and list */
    & .filterable-topics-container {
        margin-bottom: var(--spacing-lg);
        
        /* Topics header with inline title */
        & .topics-header {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: var(--spacing-md);
            flex-wrap: wrap;
            gap: var(--spacing-sm);
            
            & h3 {
                font-family: var(--font-heading-primary);
                text-transform: uppercase;
                margin: 0;
                font-size: 1.2rem;
            }
        }
        
        & .filterable-topics-list {
            display: flex;
            flex-wrap: wrap;
            gap: var(--spacing-sm); /* Increased gap between topic buttons */
            list-style: none;
            padding: 0;
            margin: 0;
            align-items: center;
            justify-content: center; /* Center topics on all screen sizes */
            
            & li {
                margin: 0;
                padding: 0;

                &:before {
                    display: none;
                }
            }
        }
        
        /* Responsive styles for topic navigation */
        @media screen and (max-width: 767px) { 
            & .topics-header {
                flex-direction: column;
                gap: var(--spacing-xs);
            }
            
            & .filterable-topics-list {
                gap: var(--spacing-xs);
                width: 100%;
            }
        }
    }
}

/* Mobile filter container and buttons */
.mobile-filter-container {
    display: none;
    width: 100%;
    margin-bottom: 15px;
    position: relative;
    
}

.mobile-filter-button {
    display: block;
    width: 100%;
    padding: 12px 15px;
    background-color: #f2f2f2;
    color: #000;
    border: none;
    text-align: left;
    font-family: var(--font-heading-primary);
    font-weight: bold;
    font-size: 1rem;
    text-transform: uppercase;
    cursor: pointer;
    position: relative;
    border-radius: 4px;
}

#mobile-filter-text {
    color: #000;
    font-weight: bold;
}

.mobile-filter-button .filter-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
}

/* Selected category pill styling */
.mobile-selected-pill {
    display: none;
    align-items: center;
    margin-left: 10px;
    padding: 4px 8px;
    height: auto !important;
    font-size: 0.9rem !important;
    position: relative;
    white-space: nowrap;
    border-radius: 4px !important;
    text-transform: uppercase;
    font-family: var(--font-heading-primary);
    font-weight: bold;
    vertical-align: middle;
}

.clear-filter-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #fff;
    margin-left: 6px;
}

.clear-filter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #000;
    font-size: 12px;
    line-height: 1;
    font-weight: bold;
}

/* Bottom popup style */
.mobile-filter-modal {
    display: none;
    position: fixed;
    bottom: 2rem;
    left: 0;
    width: 100%;
    z-index: 1000;
    background-color: rgba(0, 0, 0, 0.7);
    animation: slideUp 0.3s ease-out;
}

/* White bar at bottom of screen */
.mobile-filter-modal::after {
    content: '';
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 75%;
    height: 5px;
    background-color: #fff;
    border-radius: 5px 5px 0 0;
    z-index: 1001;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.mobile-filter-modal .modal-content {
    background-color: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 10px;
    box-sizing: border-box;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
}

.mobile-filter-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.mobile-filter-modal .modal-header h3 {
    margin: 0;
    font-family: var(--font-heading-primary);
    font-size: 1.2rem;
    color: #000;
    font-weight: bold;
}

.mobile-filter-modal .close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

/* Stack buttons vertically in the mobile popup */
.mobile-filter-modal .mobile-topics-list {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
}

.mobile-filter-modal .mobile-topics-list .topic-link {
    display: inline-block;
    width: auto;
    text-align: left;
}

.mobile-filter-modal .mobile-topics-list .topic-link.active {
    background-color: var(--color-yellow);
    color: #000;
}

/* Filter modal overlay */
.filter-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* Prevent body scrolling when popup is open */
body.filter-popup-open {
    overflow: hidden;
}

/* Show mobile filter on small screens */
@media screen and (max-width: 767px) {
    /* Ensure desktop filters are completely hidden */
    .topics-header,
    .filterable-topics-list,
    #filterable-topics {
        display: none !important;
    }
    
    /* Show mobile filter container */
    .mobile-filter-container {
        display: block;
    }
    
    /* Ensure proper spacing for mobile components */
    .filterable-components-container {
        margin-top: 0;
    }
}

.filterable-system {
    /* Topic links */
    & #filterable-topics {
        & a.topic-link {
            display: inline-block;
            text-decoration: none;
            padding: 7px 7px 5px; /* Match the .btn padding */
            text-transform: uppercase;
            font-family: var(--font-heading-primary);
            font-weight: bold;
            border-radius: var(--border-radius-primary);
            transition: all 0.2s ease-in-out;
            font-size: 1rem;
            line-height: 1.2;
            min-width: 44px; /* Ensure minimum width for touch target */
            text-align: center;
            letter-spacing: 0.05em;
            border: 2px solid transparent;
            
            /* Override any default button styles */
            &.btn-white {
                background-color: #ffffff;
                color: #000000;
            }
            
            &.btn-white:hover {
                background-color: transparent;
                border-color: #ffffff;
                color: #ffffff;
            }
            
            &.btn-yellow {
                background-color: var(--color-yellow);
                color: #000000;
            }
            
            &.btn-yellow:hover {
                background-color: #ffffff;
                color: #000000;
            }
            
            /* Remove pink glow on focus for this component only */
            &:focus {
                outline: none;
                box-shadow: none;
            }
        }
        
        /* Mobile-specific topic link styles */
        @media screen and (max-width: 767px) {
            & a {
                padding: 10px 15px; /* Larger touch targets on mobile */
                margin-bottom: 5px; /* Additional spacing for touch */
                font-size: 0.95rem;
            }
        }
    }
}

.filterable-system {
    /* Cards container and masonry layout */
    & .filterable-components-container {
        margin-top: var(--spacing-md);
        width: 100%;
        
        /* Main container for cards - true masonry layout with JS positioning */
        & .filterable-components {
            width: 100%;
            position: relative;
            margin-bottom: var(--spacing-lg);
            min-height: 200px; /* Minimum height to prevent layout collapse */
            /* Individual cards will be positioned absolutely via JavaScript */
            
            /* Anti-flicker during resize */
            transition: opacity 0.2s ease;
            
            /* During active resize, hide cards to prevent flickering */
            &.resizing {
                opacity: 0.2;
                transition: none; /* Disable transition during active resize */
            }
        }
        
        /* Responsive adjustments for container */
        @media screen and (max-width: 991px) {
            margin-top: var(--spacing-sm);
            
            & .filterable-components {
                margin-bottom: var(--spacing-md);
            }
        }
        
        @media screen and (max-width: 767px) {
            /* Optimize spacing on mobile */
            & .filterable-components {
                overflow: hidden; /* Prevent horizontal scrolling on mobile */
            }
        }
    }
}

.filterable-system {
    /* Base card styling */
    & .filterable-card {
        background-color: #000;
        color: #fff;
        border-radius: var(--border-radius-secondary);
        overflow: hidden;
        position: absolute; /* For masonry positioning by JS */
        display: none; /* Hidden by default, shown via JS */
        opacity: 0;
        /* top/left positioning handled by JavaScript */
        transition: 
            opacity 0.4s ease-out, 
            top 0.4s ease-out,
            box-shadow 0.3s ease;
        will-change: opacity, top; /* Performance optimization */
        
        /* No hover effects on cards as requested */
        
        /* Responsive adjustments for cards */
        @media screen and (max-width: 991px) {
            border-radius: calc(var(--border-radius-secondary) - 2px); /* Slightly smaller border radius on smaller screens */
        }
        
        @media screen and (max-width: 767px) {
            /* Mobile optimizations */
            transition: opacity 0.3s ease-out, top 0.3s ease-out; /* Faster transitions on mobile */
        }
        
        /* Mobile card click functionality */
        &.card-clickable {
            position: relative;
            cursor: pointer;
            
            &::after {
                content: '';
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                background-color: rgba(255, 255, 255, 0.05);
                opacity: 0;
                transition: opacity 0.2s ease;
                pointer-events: none;
                z-index: 1;
            }
            
            &.card-touch-active::after {
                opacity: 1;
            }
            
            /* Apply hover styles to buttons when card is clicked */
            & .btn.hover-active {
                &.btn-yellow {
                    background-color: #fff;
                    color: #000;
                }
                
                &.btn-white {
                    background-color: var(--color-yellow);
                    color: #000;
                }
                
                &.btn-outline-white {
                    background-color: #fff;
                    color: #000;
                }
                
                &.btn-outline-yellow {
                    background-color: var(--color-yellow);
                    color: #000;
                }
            }
        }
        
        & .card-content {
            height: 100%;
            width: 100%;
            padding: var(--spacing-sm);
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            position: relative;
            z-index: 1;
        }
        
        & h3 {
            font-family: var(--font-heading-primary);
            text-transform: uppercase;
            font-size: 1rem;
            margin-top: 0;
            margin-bottom: var(--spacing-xs);
            color: var(--color-yellow);
        }
        
        & .card-bg {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            z-index: 0;
        }
        
        &.card-yellow {
            background-color: var(--color-yellow);
            color: #000;
        }
        
        &.card-pink-accent {
            & h3, 
            & .highlight {
                color: var(--color-pink);
            }
        }
        
        &.single-col {
            grid-column: span 1;
        }
        
        &.double-col {
            grid-column: span 2;
        }
        
        &.visible {
            display: block;
            animation: cardEntrance 0.5s forwards;
        }
    }
}

/* Card entrance animation keyframes - enhanced for elegance */
@keyframes cardEntrance {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    60% {
        opacity: 1;
    }
    80% {
        transform: translateY(-2px) scale(1.01);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Responsive adjustments */
@media screen and (max-width: 1200px) {
    .filterable-system {
        & .filterable-components-container {
            & .filterable-components {
                grid-template-columns: repeat(3, 1fr);
                gap: var(--spacing-md);
            }
        }
    }
}

@media screen and (max-width: 992px) {
    .filterable-system {
        & .filterable-components-container {
            & .filterable-components {
                grid-template-columns: repeat(2, 1fr);
                gap: var(--spacing-sm);
            }
        }
        
        /* On tablet, single column cards remain single column */
        & .filterable-card {
            &.single-col {
                grid-column: span 1;
            }
            
            /* Double column cards span the full width on tablet */
            &.double-col {
                grid-column: span 2;
            }
        }
    }
}

@media screen and (max-width: 576px) {
    .filterable-system {
        & .filterable-components-container {
            & .filterable-components {
                grid-template-columns: 1fr;
                gap: var(--spacing-xs);
            }
        }
        
        /* On mobile, all components become full width */
        & .filterable-card {
            &.single-col,
            &.double-col {
                grid-column: span 1;
            }
        }
    }
}
