/* Mobile Styles */
@media (max-width: 768px) {
    .container {
        padding: 0 15px 2rem;
    }

    /* Back Arrow Mobile */
    .back-arrow {
        top: 15px;
        left: 15px;
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    /* Header */
    .header {
        padding: 0.75rem 0;
    }

    .header-content {
        justify-content: flex-end;
    }

    .filters-button {
        padding: 0.45rem 0.9rem;
        font-size: 0.7125rem;
    }

    .filters-dropdown {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(360px, calc(100vw - 24px));
        max-height: 60vh;
    }

    .cart-warning {
        font-size: 0.75rem;
        padding: 0.65rem 0.9rem;
    }

    /* Estado inicial mientras carga: oculto */
    .filters-list {
    max-height: 220px;
    visibility: hidden;
    }

    /* Cuando el body tenga la clase agregada por el script, se muestra */
    body.css-ready .filters-list {
    visibility: visible;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    /* Hero Section */
    .hero {
        padding: 1rem 0;
        margin-bottom: 2rem;
    }

    .hero-title {
        font-size: 2rem;
        margin-bottom: 0.75rem;
    }

    .hero-subtitle {
        font-size: 1rem;
        margin-bottom: 2rem;
    }

    /* Search */
    .search-box input {
        padding: 1rem 1.25rem;
        font-size: 1rem;
    }

    .search-box-small input {
        padding: 0.875rem 1rem;
        font-size: 0.875rem;
    }

    /* Search Results */
    .search-results {
        width: 100%;
        margin-left: 0;
        max-height: 300px;
    }

    .search-result-item, .result-item {
        padding: 0.875rem 1rem;
    }

    .product-name {
        font-size: 0.875rem;
        text-align: left;
    }

    .product-price {
        font-size: 0.75rem;
        font-weight: bold;
    }

    .add-button, .add-btn {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }

    .qty-btn {
        width: 24px;
        height: 24px;
        font-size: 0.875rem;
    }

    .qty-display {
        font-size: 0.875rem;
        min-width: 18px;
    }

    /* Cart Sidebar - Mobile Floating Bottom Sheet */
    .cart-sidebar {
        width: 100%;
        height: 70vh;
        max-height: 600px;
        bottom: -100vh; /* Ensure completely hidden initially */
        right: auto;
        left: 0;
        top: auto;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -10px 30px var(--shadow-strong);
        transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1002 !important; /* Higher than overlay */
        pointer-events: auto !important; /* Ensure touch events work */
        -webkit-transform: translateZ(0) !important; /* Force hardware acceleration */
        transform: translateZ(0) !important;
        /* Additional iOS optimizations to prevent blur */
        -webkit-backface-visibility: hidden !important;
        backface-visibility: hidden !important;
        will-change: transform !important;
        opacity: 1 !important;
        filter: none !important;
        -webkit-filter: none !important;
    }

    .cart-sidebar.open {
        bottom: 0;
        right: auto;
        pointer-events: auto !important;
        z-index: 1002 !important;
        /* Ensure all child elements are interactive */
    }
    
    /* Ensure all cart content is interactive when open */
    .cart-sidebar.open * {
        pointer-events: auto !important;
    }

    /* Floating Cart Handle Bar */
    .cart-sidebar::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--surface-handle);
        border-radius: 2px;
        z-index: 10;
    }

    /* Fix Cart Header Layout for Floating Design */
    .cart-header {
        flex-direction: column;
        align-items: stretch;
        padding: 1.5rem 1rem 1rem;
        gap: 1rem;
        border-radius: 20px 20px 0 0;
        position: relative;
    }

    .cart-header h3 {
        text-align: center;
        margin-bottom: 0;
        order: 1;
        margin-top: 0.5rem; /* Space for handle bar */
    }

    .cart-close {
        display: none;
        position: absolute;
        top: 1.5rem;
        right: 1rem;
        order: 3;
        z-index: 20;
        background: var(--surface-card-inverse-soft);
        border-radius: 50%;
        width: 32px;
        height: 32px;
        align-items: center;
        justify-content: center;
        color: var(--surface-panel);
    }

    /* Reorganize List Actions for Floating Cart */
    .list-actions {
        order: 2;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        margin-top: 0.5rem;
    }

    .download-list-btn, .upload-list-btn, .list-actions .empty-cart-btn {
        padding: 0.5rem;
        font-size: 0.75rem;
        height: auto;
        min-height: 40px;
        border-radius: 8px;
    }

    /* Mobile Cart Toggle */
    .mobile-cart-toggle {
        display: flex !important;
        bottom: calc(4.5rem + env(safe-area-inset-bottom, 0));
        right: 1.5rem;
        width: 56px;
        height: 56px;
        z-index: 99999 !important;
    }

    .footer-social {
        margin-bottom: 1rem;
        margin-top: 0;
    }

    .social-link {
        width: 36px;
        height: 36px;
    }

    .cart-icon {
        font-size: 1.25rem;
    }

    .cart-count {
        width: 20px;
        height: 20px;
        font-size: 0.625rem;
        top: -3px;
        right: -3px;
    }

    /* Compare Button - Integrated in Floating Cart */
    .cart-sidebar .compare-button {
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        border-radius: 0;
        padding: 1.25rem;
        font-size: 1.125rem;
        z-index: 10;
        box-shadow: 0 -2px 10px var(--shadow-subtle);
        min-height: 44px;
        background: var(--success-primary);
    }

    .cart-footer {
        padding: 1rem;
        padding-bottom: 0;
        background: var(--surface-card-inverse);
        border-top: 1px solid var(--border-subtle);
        position: relative;
        border-radius: 0 0 20px 20px;
    }

    /* Cart content scrolling in floating design */
    .cart-items {
        padding: 1rem;
        padding-bottom: 1rem;
        max-height: calc(70vh - 200px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
    }

    /* Product List Section */
    .search-and-list {
        flex-direction: column;
        gap: 1rem;
    }

    /* CTA Button */
    .cta-button {
        padding: 1rem 1.5rem;
        font-size: 1rem;
    }

    /* Cart Items */
    .cart-item {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .cart-item-name {
        font-size: 0.8125rem;
    }

    .cart-item-price {
        font-size: 0.6875rem;
    }

    .quantity-btn {
        width: 24px;
        height: 24px;
        font-size: 0.875rem;
    }

    .quantity-input {
        width: 35px;
        font-size: 0.8125rem;
    }

    .remove-btn {
        width: 24px;
        height: 24px;
        font-size: 0.875rem;
    }

    /* Comparison Page */
    .winner-card {
        padding: 1.5rem;
        margin: 0 -15px;
        border-radius: 0;
    }

    .winner-name {
        font-size: 1.5rem;
    }

    .price-amount {
        font-size: 2.25rem;
    }

    .savings-amount {
        font-size: 1.25rem;
    }

    .view-list-button {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    /* Comparison Grid - Mobile Horizontal Layout */
    .comparison-grid {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0 1rem;
    }

    .comparison-row {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .comparison-row-top,
    .comparison-row-bottom {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        max-width: 100%;
    }

    .comparison-card {
        background: var(--surface-card-muted) !important;
        border: 2px solid var(--border-subtle) !important;
        border-radius: 12px !important;
        padding: 0.75rem !important;
        
        height: 65px !important; /* Further reduced height for more compact layout */
        min-height: 65px !important; /* Override components.css min-height */
        max-height: 65px !important; /* Force exact height */
        display: flex !important;
        flex-direction: row !important; /* Horizontal layout */
        align-items: center !important;
        justify-content: flex-start !important; /* Changed from space-between to prevent expansion */
        box-shadow: 0 2px 8px var(--shadow-subtle) !important;
        position: relative;
        width: 100% !important;
        gap: 0.75rem !important;
        overflow: hidden !important; /* Prevent content overflow */
    }

    .comparison-card.winner {
        background: var(--success-surface-faint) !important;
        border-color: var(--success-primary) !important;
        box-shadow: 0 4px 12px var(--success-border-soft) !important;
    }

    .comparison-card .supermarket-logo {
        width: 45px !important;
        height: 35px !important;
        margin: 0 !important;
        margin-left: 1.7rem !important;
        object-fit: contain;
        border-radius: 6px;
        padding: 0.2rem;
        flex-shrink: 0 !important;
    }

    .comparison-card .supermarket-name {
        display: none !important; /* Hide name in horizontal layout to save space */
    }

    .comparison-card .total-price {
        font-size: 1.15rem !important;
        font-weight: 700 !important;
        color: var(--success-primary) !important;
        margin: 0 !important;
        flex-shrink: 0 !important;
        min-width: 75px !important;

    }

    .comparison-card .product-availability {
        font-size: 0.8rem !important;
        color: var(--text-tertiary) !important;
        margin: 0 !important;
        flex: 1 !important;
        text-align: left !important;
        line-height: 1.2 !important;
    }

    .comparison-card .penalty-count {
        color: var(--danger-border) !important;
        font-weight: 500 !important;
        font-size: 0.7rem !important;
        display: block !important;
        margin-top: 0.2rem !important;
    }

    /* Payment Methods Button - Mobile Horizontal Layout */
    .payment-methods-btn {
        position: static !important; /* Changed from absolute to static for horizontal layout */
        width: 30px !important;
        height: 30px !important;
        border-radius: 50% !important;
        border: none !important;
        background: var(--surface-neutral) !important;
        color: var(--text-tertiary) !important;
        font-size: 0.8rem !important;
        cursor: pointer !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        transition: all 0.2s ease !important;
        box-shadow: 0 1px 3px var(--shadow-subtle) !important;
        z-index: 10 !important;
        flex-shrink: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .comparison-card.winner .payment-methods-btn {
        background: var(--success-surface-softer) !important;
        color: var(--success-primary) !important;
    }

    .payment-methods-btn:hover {
        transform: scale(1.05) !important;
        box-shadow: 0 2px 6px var(--shadow-soft) !important;
    }

    /* Shopping List Page */
    .supermarket-header {
        flex-direction: column;
        gap: 1.5rem;
        text-align: center;
        padding: 1.5rem;
    }

    .supermarket-info {
        flex-direction: column;
        gap: 1rem;
    }

    .supermarket-name {
        font-size: 1.5rem;
    }

    .list-actions {
        flex-direction: column;
        width: 100%;
    }

    .print-button, .back-button {
        justify-content: center;
        padding: 0.875rem 1rem;
    }

    /* Shopping List Section */
    .shopping-list-section {
        padding: 1.5rem;
    }

    .list-summary {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .summary-item {
        padding: 0.75rem;
    }

    .summary-value {
        font-size: 1.25rem;
    }

    .summary-item.total .summary-value {
        font-size: 1.5rem;
    }

    /* Product Items */
    .product-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.875rem;
    }

    .product-details {
        width: 100%;
    }

    .product-quantity {
        align-self: flex-end;
        margin-right: 0;
        background: var(--brand-primary);
        color: var(--text-on-inverse);
        padding: 0.25rem 0.5rem;
        border-radius: 4px;
        font-size: 0.875rem;
    }

    /* Footer Actions */
    .footer-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .new-comparison-button, .share-button {
        padding: 0.875rem 1.5rem;
    }

    /* Cart Summary Section */
    .summary-stats {
        flex-direction: column;
        gap: 1rem;
    }

    /* Unavailable Products */
    .unavailable-products {
        padding: 1rem;
    }

    .unavailable-products li {
        font-size: 0.875rem;
    }

    .unavailable-note {
        font-size: 0.8125rem;
    }
}

/* Small Mobile Styles */
@media (max-width: 480px) {
    .hero-title {
        font-size: 1.75rem;
    }

    .hero-subtitle {
        font-size: 0.9375rem;
    }

    .search-box input {
        padding: 0.875rem 1rem;
        font-size: 0.9375rem;
    }

    .winner-card {
        padding: 1.25rem;
    }

    .winner-name {
        font-size: 1.25rem;
    }

    .price-amount {
        font-size: 2rem;
    }

    .comparison-card {
        padding: 1rem;
    }

    .supermarket-header {
        padding: 1.25rem;
    }

    .shopping-list-section {
        padding: 1.25rem;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        padding: 0.5rem 0;
        margin-bottom: 1.5rem;
    }

    .hero-title {
        font-size: 1.75rem;
        margin-bottom: 0.5rem;
    }

    .hero-subtitle {
        font-size: 0.9375rem;
        margin-bottom: 1.5rem;
    }

    .winner-card {
        padding: 1.25rem;
    }

    /* Floating cart in landscape */
    .cart-sidebar {
        height: 80vh;
        max-height: 500px;
        bottom: -80vh;
    }

    .cart-sidebar.open {
        bottom: 0;
    }
}

/* Touch Improvements */
@media (hover: none) and (pointer: coarse) {
    .search-result-item {
        padding: 1rem 1.25rem;
    }

    .add-button {
        width: 36px;
        height: 36px;
        font-size: 1.125rem;
    }

    .quantity-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .remove-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .cart-close {
        padding: 0.5rem;
        font-size: 1.75rem;
    }

    .comparison-card {
        padding: 1.5rem;
    }

}

/* iOS Specific Optimizations */
@media (max-width: 768px) {
    /* Prevent zoom on input focus */
    input[type="text"], input[type="number"], textarea, select {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }

    /* Better touch targets for all interactive elements */
    button, .add-btn, .qty-btn, .remove-btn, .cart-close, .mobile-cart-toggle {
        min-height: 8px;
        min-width: 8px;
        touch-action: manipulation; /* Prevents double-tap zoom */
    }

    /* Smooth scrolling for iOS */
    .cart-items, .search-results, .modal-body {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Safe area support for iPhone X and newer */
    .cart-sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .compare-button {
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
    }

    .mobile-cart-toggle {
        bottom: 4rem;
    }

    /* Prevent text selection on buttons */
    button, .add-btn, .qty-btn, .remove-btn, .comparison-card {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Better focus states for accessibility */
    button:focus, .add-btn:focus, .qty-btn:focus {
        outline: 2px solid var(--brand-primary);
        outline-offset: 2px;
    }

    /* Improve overlay behavior */
    .overlay {
        -webkit-backdrop-filter: blur(4px) !important;
        backdrop-filter: blur(4px) !important;
        z-index: 1000 !important; /* Lower than cart */
        pointer-events: auto !important;
        background: var(--overlay-dim) !important;
        /* Prevent overlay from blocking cart interactions */
        touch-action: manipulation !important;
    }
    
    .overlay.show {
        pointer-events: auto !important;
        display: block !important;
    }
    
    /* Critical: Prevent overlay from intercepting cart touches */
    .overlay.show ~ .cart-sidebar.open,
    .overlay.show + .cart-sidebar.open {
        pointer-events: auto !important;
        z-index: 1002 !important;
        /* Override any overlay interference */
        position: fixed !important;
    }
    
    /* Ensure overlay only closes when clicking outside cart area */
    .overlay.show {
        /* Create exclusion zone for cart */
        clip-path: polygon(0% 0%, 0% 100%, 100% 100%, 100% 30%, 0% 30%);
    }

    /* Fix for iOS Safari bottom bar - Floating Cart */
    .cart-sidebar {
        height: 70vh;
        max-height: 600px;
        height: -webkit-fill-available;
        max-height: min(600px, -webkit-fill-available);
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .supermarket-logo, .winner-logo {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* iPhone specific fixes */
@supports (-webkit-touch-callout: none) {
    /* This targets iOS Safari specifically */
    .cart-sidebar {
        height: -webkit-fill-available;
    }
    
    .compare-button {
        position: -webkit-sticky;
        position: sticky;
        bottom: 0;
    }
    
    /* Fix for iOS keyboard pushing content */
    .search-box input:focus {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
}




