/**
 * =====================================================
 * FRESHBOX ADAPTIVE UI FRAMEWORK
 * Site-wide responsive components for mobile-first UX
 * =====================================================
 * 
 * Breakpoints:
 * - Mobile:  < 768px
 * - Tablet:  768px - 1023px  
 * - Desktop: >= 1024px
 * 
 * Components:
 * - Mobile bottom filter bar
 * - Bottom sheet modals
 * - Cart FAB (mobile-only)
 * - Responsive search bar
 * - Adaptive navigation
 * 
 * Author: FreshBox Development Team
 * Date: November 2, 2025
 * =====================================================
 */

/* =====================================================
   1. CSS VARIABLES (Design Tokens)
   ===================================================== */
:root {
    /* Colors */
    --fresh-green: #4A7C59;
    --fresh-green-dark: #3d6548;
    --fresh-green-light: #5a9369;
    --fresh-orange: #FF9F5A;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Z-index layers */
    --z-bottom-bar: 40;
    --z-modal-overlay: 50;
    --z-modal-sheet: 51;
    --z-fab: 45;
    --z-header: 60;
    
    /* Transitions */
    --transition-fast: 0.2s ease-out;
    --transition-normal: 0.3s ease-out;
    --transition-slow: 0.5s ease-out;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
    --shadow-top: 0 -4px 12px rgba(0,0,0,0.1);
    
    /* Border radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    /* Touch targets (minimum 44px) */
    --touch-target: 44px;
}

/* =====================================================
   2. MOBILE BOTTOM FILTER BAR
   ===================================================== */

.mobile-bottom-filter-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-bottom-bar);
    
    display: none; /* Hidden by default, shown on mobile */
    background: white;
    border-top: 1px solid #e5e7eb;
    box-shadow: var(--shadow-top);
    
    padding: var(--spacing-sm) var(--spacing-md);
    padding-bottom: calc(var(--spacing-sm) + env(safe-area-inset-bottom)); /* iOS safe area */
}

.mobile-bottom-filter-bar .filter-bar-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
    max-width: 600px;
    margin: 0 auto;
}

.filter-bar-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    
    min-height: var(--touch-target);
    padding: var(--spacing-sm) var(--spacing-md);
    
    background: var(--fresh-green);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    
    font-size: 14px;
    font-weight: 600;
    
    cursor: pointer;
    transition: all var(--transition-fast);
    
    position: relative;
}

.filter-bar-button:hover {
    background: var(--fresh-green-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.filter-bar-button:active {
    transform: translateY(0);
}

.filter-bar-button i {
    font-size: 18px;
}

.filter-bar-button .filter-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    
    background: #ef4444;
    color: white;
    
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    
    border-radius: var(--radius-full);
    
    font-size: 11px;
    font-weight: 700;
    
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =====================================================
   3. BOTTOM SHEET MODAL SYSTEM
   ===================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-modal-overlay);
    
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-modal-sheet);
    
    background: white;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    
    max-height: 85vh;
    height: 75vh;
    
    transform: translateY(100%);
    transition: transform var(--transition-normal);
    
    display: flex;
    flex-direction: column;
    
    overflow: hidden;
}

.modal-overlay.open .modal-sheet {
    transform: translateY(0);
}

/* Modal Header */
.modal-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    padding: var(--spacing-lg) var(--spacing-lg) var(--spacing-md);
    border-bottom: 1px solid #e5e7eb;
    
    flex-shrink: 0;
}

.modal-sheet-header h3 {
    font-size: 20px;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}

.modal-close {
    width: var(--touch-target);
    height: var(--touch-target);
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    background: #f3f4f6;
    border: none;
    border-radius: var(--radius-full);
    
    font-size: 24px;
    color: #6b7280;
    
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: #e5e7eb;
    color: #1f2937;
}

/* Modal Body */
.modal-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
    -webkit-overflow-scrolling: touch;
}

/* Modal Footer */
.modal-sheet-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid #e5e7eb;
    
    display: flex;
    gap: var(--spacing-md);
    
    flex-shrink: 0;
    background: white;
}

.modal-sheet-footer button {
    flex: 1;
    min-height: var(--touch-target);
    padding: var(--spacing-md);
    
    border-radius: var(--radius-md);
    border: none;
    
    font-size: 16px;
    font-weight: 600;
    
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-sheet-footer .btn-primary {
    background: var(--fresh-green);
    color: white;
}

.modal-sheet-footer .btn-primary:hover {
    background: var(--fresh-green-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.modal-sheet-footer .btn-secondary {
    background: white;
    color: var(--fresh-green);
    border: 2px solid var(--fresh-green);
}

.modal-sheet-footer .btn-secondary:hover {
    background: #f0fdf4;
}

/* =====================================================
   4. CART FAB (Mobile Only)
   ===================================================== */

.cart-fab {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom)); /* Above bottom bar */
    right: var(--spacing-lg);
    z-index: var(--z-fab);
    
    display: none; /* Hidden by default, shown on mobile */
    
    width: 64px;
    height: 64px;
    
    background: linear-gradient(135deg, var(--fresh-green) 0%, var(--fresh-green-dark) 100%);
    border-radius: var(--radius-full);
    
    box-shadow: var(--shadow-lg);
    
    align-items: center;
    justify-content: center;
    
    cursor: pointer;
    transition: all var(--transition-normal);
    
    border: none;
    color: white;
}

.cart-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(74, 124, 89, 0.4);
}

.cart-fab:active {
    transform: scale(1.05);
}

.cart-fab i {
    font-size: 24px;
}

.cart-fab .cart-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    
    background: #ef4444;
    color: white;
    
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    
    border-radius: var(--radius-full);
    border: 3px solid white;
    
    font-size: 12px;
    font-weight: 700;
    
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Pulse animation for cart FAB */
.cart-fab::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    
    border-radius: var(--radius-full);
    border: 2px solid var(--fresh-green);
    
    opacity: 0;
    animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }
    100% {
        transform: scale(1.3);
        opacity: 0;
    }
}

/* =====================================================
   5. CART QUICK PREVIEW
   ===================================================== */

.cart-quick-preview {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-modal-sheet);
    
    background: white;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    
    max-height: 60vh;
    
    transform: translateY(100%);
    transition: transform var(--transition-normal);
    
    box-shadow: var(--shadow-top);
    
    display: flex;
    flex-direction: column;
    
    overflow: hidden;
}

.cart-quick-preview.open {
    transform: translateY(0);
}

.cart-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    padding: var(--spacing-lg);
    border-bottom: 1px solid #e5e7eb;
}

.cart-preview-header h4 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
}

.cart-preview-items {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    -webkit-overflow-scrolling: touch;
}

.cart-item-mini {
    display: flex;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border-bottom: 1px solid #f3f4f6;
}

.cart-item-mini img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.cart-item-mini .item-details {
    flex: 1;
}

.cart-item-mini .item-name {
    font-weight: 600;
    font-size: 14px;
    margin: 0 0 4px;
}

.cart-item-mini .item-price {
    font-size: 13px;
    color: #6b7280;
    margin: 0;
}

.cart-preview-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.cart-total {
    font-size: 18px;
    font-weight: 700;
    text-align: right;
    margin-bottom: var(--spacing-md);
}

.cart-preview-footer .btn-primary,
.cart-preview-footer .btn-secondary {
    width: 100%;
    min-height: var(--touch-target);
    padding: var(--spacing-md);
    
    border-radius: var(--radius-md);
    
    font-size: 16px;
    font-weight: 600;
    
    cursor: pointer;
    transition: all var(--transition-fast);
    
    margin-bottom: var(--spacing-sm);
}

.cart-preview-footer .btn-primary {
    background: var(--fresh-green);
    color: white;
    border: none;
}

.cart-preview-footer .btn-secondary {
    background: white;
    color: var(--fresh-green);
    border: 2px solid var(--fresh-green);
}

/* =====================================================
   6. MOBILE SEARCH BAR (Woolworths-style)
   ===================================================== */

.search-bar-mobile {
    display: none; /* Hidden by default, shown on mobile */
    
    align-items: center;
    gap: var(--spacing-sm);
    
    background: #f3f4f6;
    border-radius: var(--radius-full);
    padding: var(--spacing-sm) var(--spacing-md);
    
    flex: 1;
    margin: 0 var(--spacing-sm);
    
    transition: all var(--transition-fast);
}

.search-bar-mobile:focus-within {
    background: white;
    box-shadow: 0 0 0 2px var(--fresh-green);
}

.search-bar-mobile i {
    color: #9ca3af;
    font-size: 16px;
}

.search-bar-mobile input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    
    font-size: 14px;
    color: #1f2937;
}

.search-bar-mobile input::placeholder {
    color: #9ca3af;
}

/* =====================================================
   7. RESPONSIVE VISIBILITY UTILITIES
   ===================================================== */

/* Hide on mobile */
.hide-mobile {
    display: block;
}

/* Hide on tablet */
.hide-tablet {
    display: block;
}

/* Hide on desktop */
.hide-desktop {
    display: block;
}

/* Show only on mobile */
.show-mobile-only {
    display: none;
}

/* Show only on tablet */
.show-tablet-only {
    display: none;
}

/* Show only on desktop */
.show-desktop-only {
    display: none;
}

/* =====================================================
   8. MEDIA QUERIES - MOBILE (<768px)
   ===================================================== */

@media (max-width: 767px) {
    /* Show mobile components */
    .mobile-bottom-filter-bar {
        display: block;
    }
    
    .cart-fab {
        display: flex;
    }
    
    .search-bar-mobile {
        display: flex;
    }
    
    /* Hide desktop components */
    .sidebar-filters {
        display: none !important;
    }
    
    .hide-mobile {
        display: none !important;
    }
    
    .show-mobile-only {
        display: block !important;
    }
    
    /* Horizontal categories - hide on smallest screens */
    @media (max-width: 480px) {
        .horizontal-category-nav {
            display: none !important;
        }
    }
    
    /* Add bottom padding to content (for bottom bar) */
    .main-content {
        padding-bottom: 80px;
    }
    
    /* Product grid - 2 columns */
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* =====================================================
   9. MEDIA QUERIES - TABLET (768px - 1023px)
   ===================================================== */

@media (min-width: 768px) and (max-width: 1023px) {
    /* Show horizontal categories */
    .horizontal-category-nav {
        display: flex !important;
    }
    
    /* Show mobile bottom bar on tablet (CRITICAL FIX) */
    .mobile-bottom-filter-bar {
        display: block !important;
    }
    
    /* Hide FAB on tablet (cart in header is sufficient) */
    .cart-fab {
        display: none !important;
    }
    
    /* Hide desktop sidebar */
    .sidebar-filters {
        display: none !important;
    }
    
    .hide-tablet {
        display: none !important;
    }
    
    .show-tablet-only {
        display: block !important;
    }
    
    /* Modal adjustments for tablet */
    .modal-sheet {
        height: 60vh;
        max-width: 600px;
        margin: 0 auto;
        left: 50%;
        transform: translateX(-50%) translateY(100%);
    }
    
    .modal-overlay.open .modal-sheet {
        transform: translateX(-50%) translateY(0);
    }
    
    /* Product grid - 3 columns */
    .products-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* =====================================================
   10. MEDIA QUERIES - DESKTOP (>=1024px)
   ===================================================== */

@media (min-width: 1024px) {
    /* Show desktop components */
    .horizontal-category-nav {
        display: flex !important;
    }
    
    .sidebar-filters {
        display: block !important;
    }
    
    /* Hide mobile/tablet components */
    .mobile-bottom-filter-bar {
        display: none !important;
    }
    
    .cart-fab {
        display: none !important;
    }
    
    .search-bar-mobile {
        display: none !important;
    }
    
    .hide-desktop {
        display: none !important;
    }
    
    .show-desktop-only {
        display: block !important;
    }
    
    /* Product grid - 4 columns */
    .products-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* =====================================================
   11. ACCESSIBILITY
   ===================================================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 3px solid var(--fresh-green);
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* =====================================================
   12. PRINT STYLES
   ===================================================== */

@media print {
    .mobile-bottom-filter-bar,
    .cart-fab,
    .modal-overlay,
    .search-bar-mobile {
        display: none !important;
    }
}
