/* ═══════════════════════════════════════════════════════════════════
 * Modal Filters Compact - Mobile Only
 * 
 * Problem: The .breakouts-filters container in Patterns/Breakouts/
 * Divergences modals takes ~half the screen on mobile (4 filter rows).
 * 
 * Solution: Convert to a collapsible drawer - tap "🎚️ الفلاتر" to expand.
 * Active filter summary shows when collapsed (e.g. "S • انعكاسية • شراء").
 * 
 * Same approach as the main page filters drawer (mobile_v2.css).
 * ═══════════════════════════════════════════════════════════════════ */


/* Default desktop: no changes */


/* ═══════════════════════════════════════════════════════════════════
 * Mobile (≤ 768px) - Collapse filters
 * ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    
    /* The container */
    .breakouts-filters,
    .div-filters {
        position: relative;
        padding: 8px !important;
        margin: 8px 0 !important;
        background: rgba(15, 23, 42, 0.6) !important;
        border-radius: 10px !important;
        max-height: 48px;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    /* Toggle button (rendered by JS) */
    .modal-filters-toggle {
        position: absolute;
        top: 6px;
        left: 8px;
        right: 8px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 0 12px;
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        color: white;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        font-weight: 700;
        font-size: 0.85rem;
        z-index: 5;
        font-family: inherit;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .modal-filters-toggle .mft-summary {
        opacity: 0.8;
        font-size: 0.75rem;
        font-weight: 500;
        margin-right: 4px;
        max-width: 60%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .modal-filters-toggle .mft-arrow {
        font-size: 0.7rem;
        transition: transform 0.2s ease;
        margin-right: auto;
    }
    
    /* When expanded */
    .breakouts-filters.mobile-expanded,
    .div-filters.mobile-expanded {
        max-height: 1000px;
        overflow: visible;
    }
    
    .breakouts-filters.mobile-expanded .modal-filters-toggle,
    .div-filters.mobile-expanded .modal-filters-toggle {
        background: linear-gradient(135deg, #ef4444, #dc2626);
    }
    
    .breakouts-filters.mobile-expanded .modal-filters-toggle .mft-arrow,
    .div-filters.mobile-expanded .modal-filters-toggle .mft-arrow {
        transform: rotate(180deg);
    }
    
    /* Hide groups by default; show when expanded */
    .breakouts-filters > .bf-group,
    .div-filters > .div-filter-group,
    .div-filters > [class*="filter-group"] {
        opacity: 0;
        pointer-events: none;
        max-height: 0;
        overflow: hidden;
        margin: 0;
        padding: 0;
        transition: opacity 0.2s ease;
    }
    
    .breakouts-filters.mobile-expanded > .bf-group,
    .div-filters.mobile-expanded > .div-filter-group,
    .div-filters.mobile-expanded > [class*="filter-group"] {
        opacity: 1;
        pointer-events: auto;
        max-height: 200px;
        margin-bottom: 8px;
        padding: 10px 12px;
        background: rgba(0, 0, 0, 0.25);
        border-radius: 8px;
    }
    
    /* First group: top margin to clear toggle button */
    .breakouts-filters.mobile-expanded > .bf-group:first-of-type,
    .div-filters.mobile-expanded > .div-filter-group:first-of-type {
        margin-top: 50px;
    }
    
    /* Compact buttons inside groups */
    .breakouts-filters.mobile-expanded .bf-btn,
    .div-filters.mobile-expanded .bf-btn,
    .div-filters.mobile-expanded button {
        padding: 6px 10px !important;
        font-size: 0.78rem !important;
        white-space: nowrap;
        flex: 0 0 auto;
    }
    
    .breakouts-filters.mobile-expanded .bf-label,
    .div-filters.mobile-expanded .bf-label {
        font-size: 0.78rem !important;
        color: #a78bfa !important;
        font-weight: 700;
        display: block !important;
        margin: 0 0 8px 0 !important;
        padding: 0 !important;
        flex-basis: auto !important;
        width: 100% !important;
        text-align: right;
    }
    
    /* Group layout: VERTICAL - label on top, buttons below */
    .breakouts-filters.mobile-expanded .bf-group {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0 !important;
    }
    
    /* Wrapper for buttons - inline-flex on a new line */
    .breakouts-filters.mobile-expanded .bf-group > .bf-btn:first-of-type {
        margin-top: 0;
    }
    
    /* Buttons row - flex wrap for multiple lines */
    .breakouts-filters.mobile-expanded .bf-group .bf-btn {
        display: inline-block;
        margin: 3px;
    }
    
    /* Wrap the buttons after label using a pseudo-style trick:
       set the parent to flex-wrap and label to width 100% */
    .breakouts-filters.mobile-expanded .bf-group {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 6px !important;
    }
    
    /* Label takes full first row */
    .breakouts-filters.mobile-expanded .bf-group .bf-label {
        width: 100% !important;
        margin: 0 0 6px 0 !important;
        order: -1 !important;
    }
    
    /* Buttons take natural width, wrap as needed */
    .breakouts-filters.mobile-expanded .bf-group .bf-btn {
        flex: 0 0 auto !important;
        margin: 0 !important;
    }
}
