/* ========================================
   HavocTech Armory - Mobile Optimization
   Phase 8.2 Implementation
   ======================================== */

/* ===== MOBILE-SPECIFIC VARIABLES ===== */
:root {
    --mobile-header-height: 56px;
    --mobile-bottom-nav-height: 60px;
    --touch-target-size: 44px;
    --swipe-threshold: 50px;
    /* New carousel-specific variables */
    --carousel-indicator-size-mobile: 6px;
    --carousel-indicator-size-tablet: 8px;
    --carousel-indicator-active-width-mobile: 18px;
    --carousel-indicator-active-width-tablet: 24px;
}

/* ===== BASE MOBILE IMPROVEMENTS ===== */

/* Touch-friendly tap targets */
@media (max-width: 768px) {
    /* Minimum touch target size for all interactive elements */
    button, 
    .btn, 
    a.nav-link, 
    .form-check-input,
    .product-thumbnail,
    .filter-option label {
        min-height: var(--touch-target-size);
        min-width: var(--touch-target-size);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Larger form controls */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem;
        min-height: var(--touch-target-size);
    }

    /* Enhanced buttons */
    .btn {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        font-weight: 600;
    }

    .btn-lg {
        padding: 1rem 2rem;
        font-size: 1.125rem;
    }

    /* Sticky header optimization */
    .navbar {
        position: sticky;
        top: 0;
        z-index: 1030;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    }

    /* Improved spacing */
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Mobile product cards */
    .product-card {
        margin-bottom: 1rem;
    }

    .product-card .card-img-top {
        height: 220px;
        object-fit: cover;
    }

    .product-card .product-title {
        font-size: 0.95rem;
        min-height: 40px;
    }

    .product-card .product-price {
        font-size: 1.25rem;
    }

    /* Mobile cart items */
    .cart-item {
        flex-direction: column;
        text-align: center;
    }

    .cart-item-image {
        margin: 0 auto 1rem;
        width: 120px;
        height: 120px;
    }

    /* Mobile navigation improvements */
    .navbar-toggler {
        padding: 0.5rem;
        border: none;
        min-width: var(--touch-target-size);
        min-height: var(--touch-target-size);
    }

    .navbar-nav .nav-link {
        padding: 1rem;
        font-size: 1.1rem;
    }

    .dropdown-menu {
        font-size: 1rem;
    }

    .dropdown-item {
        padding: 0.75rem 1.5rem;
    }
}

/* ===== MOBILE FILTER BOTTOM SHEET ===== */
@media (max-width: 768px) {
    /* Hide desktop sidebar on mobile */
    .filter-sidebar {
        display: none !important;
    }

    /* Mobile filter floating button */
    .mobile-filter-button {
        position: fixed;
        bottom: 80px; /* Above any bottom nav if present */
        right: 20px;
        z-index: 1020;
        width: 60px;
        height: 60px;
        border-radius: 30px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
        font-size: 1.5rem;
        display: flex !important;
        align-items: center;
        justify-content: center;
        padding: 0;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border: none;
        background: linear-gradient(135deg, var(--ht-primary) 0%, var(--ht-secondary) 100%
);
        color: white;
        cursor: pointer;
    }

    .mobile-filter-button:hover,
    .mobile-filter-button:active {
        transform: scale(1.1);
        box-shadow: 0 6px 20px rgba(46, 92, 153, 0.4);
        background: linear-gradient(135deg, var(--ht-secondary) 0%, var(--ht-primary) 100%
);
    }

    /* Active filter count badge */
    .mobile-filter-button .filter-count-badge {
        position: absolute;
        top: -5px;
        right: -5px;
        background: #dc3545;
        color: white;
        border-radius: 12px;
        padding: 0.2rem 0.5rem;
        font-size: 0.75rem;
        font-weight: 700;
        min-width: 24px;
        text-align: center;
        box-shadow: 0 2px 8px rgba(220, 53, 69, 0.4);
        animation: pulse 2s infinite;
        pointer-events: none;
    }

    @keyframes pulse {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.1); }
    }

    /* Pulse animation for filter button when filters active */
    .mobile-filter-button.has-filters {
        animation: filterPulse 2s ease-in-out infinite;
    }

    @keyframes filterPulse {
        0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); }
        50% { box-shadow: 0 4px 20px rgba(46, 92, 153, 0.6), 0 0 0 8px rgba(46, 92, 153, 0.1); }
    }

    /* Bottom sheet overlay - MUST be clickable */
    .filter-bottom-sheet-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        backdrop-filter: blur(2px);
        cursor: pointer;
    }

    .filter-bottom-sheet-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: all;
    }

    /* Bottom sheet container */
    .filter-bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-radius: 20px 20px 0 0;
        z-index: 1050;
        max-height: 90vh;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
        display: flex;
        flex-direction: column;
        visibility: hidden;
    }

    .filter-bottom-sheet.active {
        transform: translateY(0);
        visibility: visible;
    }

    /* Bottom sheet header */
    .filter-bottom-sheet-header {
        padding: 1rem 1.5rem;
        border-bottom: 1px solid #dee2e6;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
        position: relative;
        background: white;
        border-radius: 20px 20px 0 0;
    }

    .filter-bottom-sheet-header .btn-close {
        position: relative;
        z-index: 10;
        width: var(--touch-target-size);
        height: var(--touch-target-size);
        padding: 0;
        margin: 0;
        opacity: 1;
        background: transparent;
        border: none;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        color: var(--ht-dark-gray);
        transition: all 0.2s;
    }

    .filter-bottom-sheet-header .btn-close:hover,
    .filter-bottom-sheet-header .btn-close:active {
        opacity: 0.75;
        color: var(--ht-primary);
        transform: scale(1.1);
    }

    /* Swipe handle for bottom sheet */
    .filter-bottom-sheet-handle {
        width: 40px;
        height: 4px;
        background: #dee2e6;
        border-radius: 2px;
        margin: 0 auto 1rem;
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        cursor: grab;
        transition: background 0.2s;
    }

    .filter-bottom-sheet-handle:active {
        cursor: grabbing;
        background: var(--ht-primary);
    }
    
    /* Add hint animation to handle */
    @keyframes handleHint {
        0%, 100% { transform: translateX(-50%) translateY(0); }
        50% { transform: translateX(-50%) translateY(3px); }
    }
    
    .filter-bottom-sheet.active .filter-bottom-sheet-handle {
        animation: handleHint 2s ease-in-out 0.5s 2;
    }

    .filter-bottom-sheet-header h5 {
        margin-top: 0.5rem;
        margin-bottom: 0;
        font-size: 1.25rem;
        font-weight: 700;
        color: var(--ht-secondary);
    }

    /* Active filters indicator */
    .filter-bottom-sheet-header .active-filters-count {
        background: var(--ht-accent);
        color: white;
        padding: 0.25rem 0.75rem;
        border-radius: 20px;
        font-size: 0.875rem;
        font-weight: 600;
        margin-left: 0.5rem;
    }

    /* Bottom sheet content */
    .filter-bottom-sheet-content {
        overflow-y: auto;
        padding: 1.5rem;
        flex: 1;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Scrollbar styling for bottom sheet */
    .filter-bottom-sheet-content::-webkit-scrollbar {
        width: 4px;
    }

    .filter-bottom-sheet-content::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 10px;
    }

    .filter-bottom-sheet-content::-webkit-scrollbar-thumb {
        background: var(--ht-primary);
        border-radius: 10px;
    }

    /* Mobile filter sections */
    .mobile-filter-section {
        background: transparent;
        padding: 0;
        border-radius: 0;
    }

    .mobile-filter-section .filter-section {
        margin-bottom: 1.5rem;
        padding-bottom: 1.5rem;
        border-bottom: 1px solid #e9ecef;
    }

    .mobile-filter-section .filter-section:last-child {
        border-bottom: none;
    }

    .mobile-filter-section .filter-section h6 {
        font-size: 1.1rem;
        font-weight: 600;
        margin-bottom: 1rem;
        padding-bottom: 0.5rem;
        border-bottom: 2px solid var(--ht-gray);
        color: var(--ht-secondary);
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .mobile-filter-section .filter-section h6 i {
        color: var(--ht-primary);
    }

    /* Filter options in bottom sheet */
    .mobile-filter-section .filter-option {
        padding: 0.75rem 0;
        border-bottom: 1px solid #f5f5f5;
    }

    .mobile-filter-section .filter-option:last-child {
        border-bottom: none;
    }

    .mobile-filter-section .filter-option label {
        font-size: 1rem;
        cursor: pointer;
        width: 100%;
        padding-left: 0.5rem;
        display: flex;
        align-items: center;
        min-height: var(--touch-target-size);
    }

    /* Enhanced radio/checkbox styling for mobile */
    .mobile-filter-section .form-check-input {
        width: 20px;
        height: 20px;
        margin-right: 0.75rem;
        cursor: pointer;
        flex-shrink: 0;
    }

    .mobile-filter-section .form-check-input:checked {
        background-color: var(--ht-primary);
        border-color: var(--ht-primary);
    }

    /* Collapsible filter sections */
    .filter-section-collapse {
        cursor: pointer;
        user-select: none;
    }

    .filter-section-collapse::after {
        content: '\F282'; /* bi-chevron-down */
        font-family: 'bootstrap-icons';
        float: right;
        transition: transform 0.3s;
    }

    .filter-section-collapse.collapsed::after {
        transform: rotate(-90deg);
    }

    /* Bottom sheet footer */
    .filter-bottom-sheet-footer {
        padding: 1rem 1.5rem;
        border-top: 1px solid #dee2e6;
        background: white;
        flex-shrink: 0;
        display: flex;
        gap: 0.5rem;
    }

    .filter-bottom-sheet-footer .btn {
        flex: 1;
        padding: 0.75rem;
        font-weight: 600;
        font-size: 1rem;
        cursor: pointer;
    }

    .filter-bottom-sheet-footer .btn-clear {
        flex: 0.6;
        background: transparent;
        border: 2px solid var(--ht-gray);
        color: var(--ht-dark-gray);
    }

    .filter-bottom-sheet-footer .btn-clear:hover {
        background: var(--ht-light-gray);
        border-color: var(--ht-primary);
        color: var(--ht-primary);
    }

    .filter-bottom-sheet-footer .btn-apply {
        flex: 1.4;
        background: linear-gradient(135deg, var(--ht-primary) 0%, var(--ht-secondary) 100%
);
        border: none;
        color: white;
        box-shadow: 0 2px 8px rgba(46, 92, 153, 0.3);
    }

    .filter-bottom-sheet-footer .btn-apply:hover {
        background: linear-gradient(135deg, var(--ht-secondary) 0%, var(--ht-primary) 100%
);
        box-shadow: 0 4px 12px rgba(46, 92, 153, 0.4);
        transform: translateY(-2px);
    }

    /* Price range inputs in bottom sheet */
    .mobile-filter-section .filter-section .row.g-2 input {
        font-size: 1rem;
        padding: 0.75rem;
        border-radius: 8px;
    }

    /* Nested subcategory styling */
    .mobile-filter-section .ms-3 {
        margin-left: 2rem !important;
        padding-left: 1rem;
        border-left: 2px solid var(--ht-light-gray);
    }

    .mobile-filter-section .ms-3 .filter-option {
        padding: 0.5rem 0;
    }

    /* Active filter chips in header */
    .active-filter-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem 1.5rem;
        border-bottom: 1px solid #dee2e6;
        background: var(--ht-light-gray);
    }

    .filter-chip {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        background: white;
        border: 1px solid var(--ht-primary);
        color: var(--ht-primary);
        padding: 0.375rem 0.75rem;
        border-radius: 20px;
        font-size: 0.875rem;
        font-weight: 500;
    }

    .filter-chip i {
        font-size: 0.75rem;
        cursor: pointer;
    }

    .filter-chip i:hover {
        color: #dc3545;
    }
}

/* ===== TABLET FILTER OPTIMIZATIONS ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .filter-sidebar {
        position: sticky;
        top: 80px;
        max-height: calc(100vh - 100px);
        overflow-y: auto;
        padding: 1.5rem;
    }

    .mobile-filter-button {
        display: none !important;
    }
}

/* ===== HIDE MOBILE FILTER BUTTON ON DESKTOP ===== */
@media (min-width: 1025px) {
    .mobile-filter-button {
        display: none !important;
    }

    .filter-bottom-sheet,
    .filter-bottom-sheet-overlay {
        display: none !important;
    }
}

/* ===== SWIPE GESTURES FOR PRODUCT GALLERY ===== */
@media (max-width: 768px) {
    .product-detail-image {
        position: relative;
        overflow: hidden;
        touch-action: pan-y pinch-zoom;
    }

    .product-image-slider {
        display: flex;
        transition: transform 0.3s ease;
        width: 100%;
    }

    .product-image-slide {
        flex: 0 0 100%;
        width: 100%;
    }

    .product-image-slide img {
        width: 100%;
        height: auto;
        display: block;
    }

    /* Image navigation dots */
    .product-image-dots {
        display: flex;
        justify-content: center;
        gap: 8px;
        padding: 1rem 0;
    }

    .product-image-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #dee2e6;
        transition: all 0.3s;
        cursor: pointer;
    }

    .product-image-dot.active {
        width: 24px;
        border-radius: 4px;
        background: var(--ht-primary);
    }

    /* Swipe indicators */
    .swipe-indicator {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        font-size: 2rem;
        color: white;
        background: rgba(0,0,0,0.3);
        border-radius: 50%;
        width: 50px;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        transition: opacity 0.3s;
        pointer-events: none;
    }

    .swipe-indicator.left {
        left: 10px;
    }

    .swipe-indicator.right {
        right: 10px;
    }

    .product-detail-image:hover .swipe-indicator {
        opacity: 1;
    }
}

/* ===== MOBILE QUICK VIEW MODAL ===== */
@media (max-width: 768px) {
    .quick-view-modal .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .quick-view-modal .modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .quick-view-modal .modal-body {
        padding: 1.5rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .quick-view-product-image {
        height: 300px;
        object-fit: cover;
        border-radius: 8px;
        margin-bottom: 1rem;
    }

    .quick-view-content {
        padding: 1rem 0;
    }
}

/* ===== MOBILE CHECKOUT OPTIMIZATION ===== */
@media (max-width: 768px) {
    .checkout-steps {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .checkout-step {
        padding: 1.5rem;
        background: white;
        border-radius: 8px;
        border: 2px solid #dee2e6;
    }

    .checkout-step.active {
        border-color: var(--ht-primary);
    }

    .checkout-summary {
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 2px solid #dee2e6;
        padding: 1rem;
        z-index: 1010;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }

    .checkout-submit {
        width: 100%;
        padding: 1rem;
        font-size: 1.125rem;
        font-weight: 600;
    }
}

/* ===== MOBILE SEARCH OPTIMIZATION ===== */
@media (max-width: 768px) {
    .search-sort-bar {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .search-sort-bar .row {
        gap: 0.75rem;
    }

    .mobile-search-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        z-index: 1060;
        display: none;
        flex-direction: column;
    }

    .mobile-search-overlay.active {
        display: flex;
    }

    .mobile-search-header {
        padding: 1rem;
        border-bottom: 1px solid #dee2e6;
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .mobile-search-input {
        flex: 1;
        font-size: 1.125rem;
        padding: 0.75rem;
        border: none;
        outline: none;
    }

    .mobile-search-results {
        flex: 1;
        overflow-y: auto;
        padding: 1rem;
    }

    .mobile-search-result-item {
        padding: 1rem;
        border-bottom: 1px solid #f0f0f0;
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .mobile-search-result-image {
        width: 60px;
        height: 60px;
        object-fit: cover;
        border-radius: 4px;
    }
}

/* ===== PULL-TO-REFRESH INDICATOR ===== */
@media (max-width: 768px) {
    .pull-to-refresh {
        position: absolute;
        top: -60px;
        left: 0;
        right: 0;
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--ht-primary);
        font-size: 1.5rem;
        transition: all 0.3s;
        opacity: 0;
    }

    .pull-to-refresh.active {
        opacity: 1;
    }

    .pull-to-refresh i {
        animation: spin 1s linear infinite;
    }

    @keyframes spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }
}

/* ===== MOBILE BOTTOM NAVIGATION (OPTIONAL) ===== */
@media (max-width: 768px) {
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--mobile-bottom-nav-height);
        background: white;
        border-top: 1px solid #dee2e6;
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: 1020;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }

    .mobile-bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0.5rem;
        color: #6c757d;
        text-decoration: none;
        font-size: 0.75rem;
        transition: all 0.2s;
    }

    .mobile-bottom-nav-item i {
        font-size: 1.5rem;
        margin-bottom: 0.25rem;
    }

    .mobile-bottom-nav-item.active {
        color: var(--ht-primary);
    }

    .mobile-bottom-nav-badge {
        position: absolute;
        top: 8px;
        right: 50%;
        transform: translateX(10px);
        background: #dc3545;
        color: white;
        border-radius: 10px;
        padding: 0.125rem 0.4rem;
        font-size: 0.7rem;
        font-weight: 600;
    }

    /* Add padding to body when bottom nav is shown */
    body.has-bottom-nav {
        padding-bottom: var(--mobile-bottom-nav-height);
    }
}

/* ===== MOBILE PERFORMANCE OPTIMIZATIONS ===== */
@media (max-width: 768px) {
    /* Reduce animations on mobile for better performance */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Hardware acceleration */
    .product-card,
    .filter-bottom-sheet,
    .mobile-bottom-nav {
        transform: translateZ(0);
        will-change: transform;
    }

    /* Smooth scrolling */
    html {
        scroll-behavior: smooth;
    }

    /* Image lazy loading optimization */
    img[loading="lazy"] {
        background: var(--ht-light-gray);
    }
}

/* ===== LANDSCAPE MODE OPTIMIZATIONS ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .product-card .card-img-top {
        height: 180px;
    }

    .filter-bottom-sheet {
        max-height: 90vh;
    }

    .navbar {
        padding: 0.25rem 0;
    }

    .navbar-brand {
        font-size: 1.25rem;
    }
}

/* ===== TABLET OPTIMIZATIONS ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .product-card .card-img-top {
        height: 240px;
    }

    .filter-sidebar {
        position: sticky;
        top: 80px;
        max-height: calc(100vh - 100px);
        overflow-y: auto;
    }

    .container-fluid {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS FOR TOUCH ===== */
@media (max-width: 768px) {
    /* Focus states for touch */
    button:focus,
    a:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid var(--ht-primary);
        outline-offset: 2px;
    }

    /* Skip to content link */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 0;
        background: var(--ht-primary);
        color: white;
        padding: 0.5rem 1rem;
        text-decoration: none;
        z-index: 9999;
    }

    .skip-to-content:focus {
        top: 0;
    }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== ENHANCED CAROUSEL/SLIDER IMPROVEMENTS FOR MOBILE ===== */
@media (max-width: 768px) {
    /* Smaller, more refined carousel indicators */
    .carousel-indicators {
        margin-bottom: 0.5rem;
        gap: 6px;
    }

    .carousel-indicators [data-bs-target] {
        width: var(--carousel-indicator-size-mobile);
        height: var(--carousel-indicator-size-mobile);
        border-radius: 50%;
        margin: 0;
        opacity: 0.6;
        background-color: rgba(255, 255, 255, 0.7);
        border: 1px solid rgba(0, 0, 0, 0.1);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    .carousel-indicators [data-bs-target].active {
        width: var(--carousel-indicator-active-width-mobile);
        border-radius: 3px;
        opacity: 1;
        background-color: var(--ht-primary);
        border-color: var(--ht-primary);
        box-shadow: 0 2px 8px rgba(46, 92, 153, 0.4);
    }

    /* Enhanced touch feedback for indicators */
    .carousel-indicators [data-bs-target]:active {
        transform: scale(1.2);
        opacity: 0.8;
    }

    /* Better carousel control buttons for mobile */
    .carousel-control-prev,
    .carousel-control-next {
        width: 50px;
        opacity: 0.7;
        transition: all 0.3s ease;
    }

    .carousel-control-prev:hover,
    .carousel-control-next:hover {
        opacity: 1;
    }

    .carousel-control-prev-icon,
    .carousel-control-next-icon {
        width: 30px;
        height: 30px;
        background-color: rgba(0, 0, 0, 0.4);
        border-radius: 50%;
        padding: 0.5rem;
        backdrop-filter: blur(4px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    /* Hide controls on very small screens to reduce clutter */
    @media (max-width: 480px) {
        .carousel-control-prev,
        .carousel-control-next {
            width: 40px;
        }
        
        .carousel-control-prev-icon,
        .carousel-control-next-icon {
            width: 24px;
            height: 24px;
        }
    }

    /* Carousel swipe gesture enhancements */
    .carousel-inner {
        touch-action: pan-y pinch-zoom;
        cursor: grab;
    }

    .carousel-inner:active {
        cursor: grabbing;
    }

    /* Swipe direction indicators */
    .carousel-item {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Add subtle hint animation for swipeable carousel */
    @keyframes swipeHint {
        0%, 100% { transform: translateX(0); }
        50% { transform: translateX(-10px); }
    }

    .carousel-inner::after {
        content: '';
        position: absolute;
        top: 50%;
        right: 20px;
        width: 30px;
        height: 30px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        transform: translateY(-50%);
        opacity: 0;
        pointer-events: none;
        animation: swipeHint 2s ease-in-out 1s 2;
    }

    /* Smooth fade for carousel slides */
    .carousel-fade .carousel-item {
        opacity: 0;
        transition-duration: 0.4s;
        transition-property: opacity;
    }

    .carousel-fade .carousel-item.active {
        opacity: 1;
    }

    /* Hero carousel specific mobile optimizations */
    .hero-slide {
        min-height: 400px !important;
    }

    .hero-slide h1 {
        font-size: 2rem !important;
    }

    .hero-slide .lead {
        font-size: 1rem !important;
    }

    .hero-slide .btn {
        font-size: 0.95rem;
        padding: 0.6rem 1.2rem;
    }

    /* Reduce hero carousel height on very small screens */
    @media (max-width: 480px) {
        .hero-slide {
            min-height: 350px !important;
        }

        .hero-slide h1 {
            font-size: 1.75rem !important;
        }

        .hero-slide .btn-lg {
            font-size: 0.9rem;
            padding: 0.5rem 1rem;
        }
    }
}

/* ===== TABLET CAROUSEL OPTIMIZATIONS ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .carousel-indicators [data-bs-target] {
        width: var(--carousel-indicator-size-tablet);
        height: var(--carousel-indicator-size-tablet);
    }

    .carousel-indicators [data-bs-target].active {
        width: var(--carousel-indicator-active-width-tablet);
    }

    .carousel-control-prev-icon,
    .carousel-control-next-icon {
        width: 35px;
        height: 35px;
    }
}

/* ===== ENHANCED TOUCH GESTURE HANDLING ===== */
@media (max-width: 768px) {
    /* Improved touch feedback for all interactive elements */
    .carousel-item,
    .product-card,
    .category-quick-link,
    .brand-showcase-card {
        -webkit-tap-highlight-color: transparent;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }

    /* Touch ripple effect on tap */
    @keyframes touchRipple {
        0% {
            transform: scale(0);
            opacity: 0.5;
        }
        100% {
            transform: scale(2.5);
            opacity: 0;
        }
    }

    /* Active state improvements for better touch feedback */
    .btn:active,
    .card:active,
    a.category-quick-link:active,
    a.brand-showcase-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }

    /* Swipe velocity detection hints */
    .carousel-inner[data-swipe-velocity="fast"] {
        transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
    }

    .carousel-inner[data-swipe-velocity="slow"] {
        transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Prevent overscroll on carousel */
    .carousel {
        overscroll-behavior-x: contain;
    }

    /* Better momentum scrolling for iOS */
    .carousel-inner {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS FOR CAROUSEL ===== */
@media (max-width: 768px) {
    /* Larger focus states for carousel controls */
    .carousel-control-prev:focus,
    .carousel-control-next:focus {
        outline: 3px solid var(--ht-accent);
        outline-offset: 3px;
    }

    .carousel-indicators [data-bs-target]:focus {
        outline: 2px solid var(--ht-accent);
        outline-offset: 2px;
        box-shadow: 0 0 0 4px rgba(111, 185, 81, 0.3);
    }

    /* Pause carousel on focus for accessibility */
    .carousel:focus-within {
        animation-play-state: paused;
    }

    /* Screen reader only text for carousel */
    .carousel .sr-only,
    .carousel .visually-hidden {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS FOR CAROUSEL ===== */
@media (max-width: 768px) {
    /* GPU acceleration for carousel animations */
    .carousel-item,
    .carousel-control-prev-icon,
    .carousel-control-next-icon,
    .carousel-indicators [data-bs-target] {
        will-change: transform;
        transform: translateZ(0);
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    /* Reduce motion for users who prefer it */
    @media (prefers-reduced-motion: reduce) {
        .carousel-item,
        .carousel-inner,
        .carousel-indicators [data-bs-target] {
            transition-duration: 0.01ms !important;
            animation-duration: 0.01ms !important;
        }

        .carousel-inner::after {
            animation: none;
        }
    }

    /* Optimize images in carousel for mobile */
    .carousel-item img {
        max-width: 100%;
        height: auto;
        object-fit: cover;
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }

    /* Lazy loading hint for carousel images */
    .carousel-item img[loading="lazy"] {
        background: linear-gradient(90deg, var(--ht-light-gray) 25%, #f0f0f0 50%, var(--ht-light-gray) 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
    }

    @keyframes shimmer {
        0% { background-position: -100% 0; }
        100% { background-position: 100% 0; }
    }
}

/* ===== LANDSCAPE MODE CAROUSEL ADJUSTMENTS ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .hero-slide {
        min-height: 300px !important;
    }

    .carousel-indicators {
        margin-bottom: 0.25rem;
    }

    .carousel-indicators [data-bs-target] {
        width: 5px;
        height: 5px;
    }

    .carousel-indicators [data-bs-target].active {
        width: 15px;
    }
}

@media (max-width: 768px) {
    /* Ensure only one mobile filter button is visible; any duplicates beyond first hidden */
    .mobile-filter-button { position: fixed; }
    .mobile-filter-button + .mobile-filter-button { display: none !important; }

    /* Strengthen gesture reliability */
    .filter-bottom-sheet-header, .filter-bottom-sheet-handle { touch-action: none; user-select: none; }
    .filter-bottom-sheet-handle { height: 6px; }
}
