/* ========================================
   MOBILE FILTER OVERLAY
   Separate CSS file for mobile filter functionality
   With drag/swipe gesture support
   ======================================== */

@media screen and (max-width: 768px) {
  
  /* ========================================
     CATALOG VIEW SPECIFIC STYLES
     Only apply to products-by-catalog and brands-catalog views
     ======================================== */
  
  /* Specific fix for products catalog views ONLY - override grid layout */
  .view-products-by-catalog,
  .view-brands-catalog {
    display: block !important;
    grid-template-columns: 1fr !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  
  .view-products-by-catalog .view-content,
  .view-brands-catalog .view-content {
    width: 100% !important;
    max-width: 100vw !important;
    grid-column: 1 / -1 !important;
    margin: 0 !important;
    padding: 0 10px !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  /* Responsive grid container - ONLY for catalog views */
  .view-products-by-catalog .views-view-responsive-grid--horizontal,
  .view-brands-catalog .views-view-responsive-grid--horizontal {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    gap: 8px !important;
  }
  
  /* Dynamic grid columns - default 3 columns - ONLY for catalog views */
  .view-products-by-catalog .views-view-responsive-grid__item,
  .view-brands-catalog .views-view-responsive-grid__item {
    width: calc(33.33% - 6px) !important;
    max-width: calc(33.33% - 6px) !important;
    box-sizing: border-box !important;
    flex: 0 0 calc(33.33% - 6px) !important;
    height: auto !important;
  }
  
  .view-products-by-catalog .views-view-responsive-grid__item article,
  .view-brands-catalog .views-view-responsive-grid__item article {
    height: auto !important;
  }
  
  /* 1 column layout - ONLY for catalog views */
  .view-products-by-catalog.mobile-grid-1 .views-view-responsive-grid__item,
  .view-brands-catalog.mobile-grid-1 .views-view-responsive-grid__item,
  .view-products-by-catalog .mobile-grid-1 .views-view-responsive-grid__item,
  .view-brands-catalog .mobile-grid-1 .views-view-responsive-grid__item {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    margin: 0 auto !important;
  }
  
  .view-products-by-catalog.mobile-grid-1 .views-view-responsive-grid__item .images img,
  .view-brands-catalog.mobile-grid-1 .views-view-responsive-grid__item .images img,
  .view-products-by-catalog .mobile-grid-1 .views-view-responsive-grid__item .images img,
  .view-brands-catalog .mobile-grid-1 .views-view-responsive-grid__item .images img {
    min-height: 280px !important;
    object-fit: cover !important;
  }
  
  .view-products-by-catalog.mobile-grid-1 .views-view-responsive-grid--horizontal,
  .view-brands-catalog.mobile-grid-1 .views-view-responsive-grid--horizontal,
  .view-products-by-catalog .mobile-grid-1.views-view-responsive-grid--horizontal,
  .view-brands-catalog .mobile-grid-1.views-view-responsive-grid--horizontal {
    justify-content: center !important;
  }
  
  /* 2 column layout - ONLY for catalog views */
  .view-products-by-catalog.mobile-grid-2 .views-view-responsive-grid__item,
  .view-brands-catalog.mobile-grid-2 .views-view-responsive-grid__item,
  .view-products-by-catalog .mobile-grid-2 .views-view-responsive-grid__item,
  .view-brands-catalog .mobile-grid-2 .views-view-responsive-grid__item {
    width: calc(50% - 4px) !important;
    max-width: calc(50% - 4px) !important;
    flex: 0 0 calc(50% - 4px) !important;
  }
  
  .view-products-by-catalog.mobile-grid-2 .views-view-responsive-grid--horizontal,
  .view-brands-catalog.mobile-grid-2 .views-view-responsive-grid--horizontal,
  .view-products-by-catalog .mobile-grid-2.views-view-responsive-grid--horizontal,
  .view-brands-catalog .mobile-grid-2.views-view-responsive-grid--horizontal {
    justify-content: flex-start !important;
  }
  
  /* 3 column layout - ONLY for catalog views */
  .view-products-by-catalog.mobile-grid-3 .views-view-responsive-grid__item,
  .view-brands-catalog.mobile-grid-3 .views-view-responsive-grid__item,
  .view-products-by-catalog .mobile-grid-3 .views-view-responsive-grid__item,
  .view-brands-catalog .mobile-grid-3 .views-view-responsive-grid__item {
    width: calc(33.33% - 6px) !important;
    max-width: calc(33.33% - 6px) !important;
    flex: 0 0 calc(33.33% - 6px) !important;
  }
  
  /* Fix gap between images div and anchor element - ONLY for catalog views */
  .view-products-by-catalog .views-view-responsive-grid__item .images,
  .view-brands-catalog .views-view-responsive-grid__item .images {
    line-height: 0;
    font-size: 0;
  }
  
  .view-products-by-catalog .views-view-responsive-grid__item .images a,
  .view-brands-catalog .views-view-responsive-grid__item .images a {
    display: block !important;
  }
  
  /* ========================================
     END CATALOG VIEW SPECIFIC STYLES
     ======================================== */
  
  /* Grid toggle buttons */
  .mobile-grid-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    order: 2;
  }
  
  .grid-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 4px;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #999;
    transition: all 0.2s ease;
  }
  
  .grid-toggle-btn:hover {
    color: #666;
  }
  
  .grid-toggle-btn.active {
    color: #333;
    background: #f0f0f0;
  }
  
  .grid-toggle-btn svg {
    width: 18px;
    height: 18px;
  }


 

  /* Hide filters by default on mobile - prepare for slide animation */
  .view-filters {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    width: 75% !important;
    max-width: 280px !important;
    height: 100vh !important;
    height: 100dvh !important; /* Dynamic viewport height for mobile browsers */
    background: #fff !important;
    z-index: 99999 !important;
    overflow: hidden !important;
    padding: 20px 0px 80px !important;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.15) !important;
    /* Slide animation - starts off-screen */
    transform: translateX(100%) !important;
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
    visibility: hidden;
    /* Enable touch action for swipe gestures */
    touch-action: pan-y;
    will-change: transform;
    /* Always RTL direction */
    direction: rtl !important;
    text-align: right !important;
  }

  /* Show filters when active - slide in */
  .view-filters.mobile-filters-open,
  body.mobile-filter-active .view-filters {
    transform: translateX(0) !important;
    visibility: visible;
  }
  
  /* Remove transition during drag for smooth following */
  .view-filters.dragging {
    transition: none !important;
  }

  /* Filter overlay backdrop */
  .mobile-filter-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94), visibility 0.35s ease;
    will-change: opacity;
  }

  .mobile-filter-backdrop.active {
    opacity: 1;
    visibility: visible;
  }
  
  /* Remove transition during drag for smooth following */
  .mobile-filter-backdrop.dragging {
    transition: none !important;
  }

  /* Filter toggle button - icon only like cart */
  .mobile-filter-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0;
    background: transparent;
    color: #333;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0;
  }

  .mobile-filter-toggle:hover,
  .mobile-filter-toggle:active {
    color: #667eea;
  }

  .mobile-filter-toggle svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
  }
  
  /* Hide the text label */
  .mobile-filter-toggle span:not(.filter-count) {
    display: none !important;
  }

  /* Filter button container - at top of page */
  .mobile-filter-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background: #fff;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    z-index: 100;
    margin-bottom: 10px;
    direction: rtl;
  }

  /* Close button - hidden, use swipe to close */
  .mobile-filter-close {
    display: none !important;
  }

  /* Filter panel header */
  .mobile-filter-header {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 60px;
    background: #fff;
    border-bottom: 1px solid #eee;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: "Cairo", sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: #333;
    z-index: 5;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    direction: rtl;
  }
  
  .mobile-filter-header:active {
    cursor: grabbing;
  }
  
  /* Drag handle indicator */
  .mobile-filter-header .drag-handle {
    width: 40px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    margin-bottom: 8px;
    transition: background 0.2s ease;
  }
  
  .mobile-filter-header:active .drag-handle {
    background: #aaa;
  }


  .price-range-display {
    text-align: right;
    margin-right: 10%;
  }
  
  /* Style filters inside overlay */
  .view-filters.mobile-filters-open form {
    padding-bottom: 100px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #667eea #f0f0f0;
  }
  
  /* Beautiful custom scrollbar for filter form */
  .view-filters.mobile-filters-open form::-webkit-scrollbar {
    width: 5px;
  }
  
  .view-filters.mobile-filters-open form::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 10px;
  }
  
  .view-filters.mobile-filters-open form::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
  }
  
  .view-filters.mobile-filters-open form::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #5a6fd6 0%, #6a4190 100%);
  }
  
  /* Beautiful scrollbar for card-body sections */
  .view-filters.mobile-filters-open .card-body {
    scrollbar-width: thin;
    scrollbar-color: #ccc #f8f8f8;
  }
  
  .view-filters.mobile-filters-open .card-body::-webkit-scrollbar {
    width: 4px;
  }
  
  .view-filters.mobile-filters-open .card-body::-webkit-scrollbar-track {
    background: #f8f8f8;
    border-radius: 10px;
  }
  
  .view-filters.mobile-filters-open .card-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
  }
  
  .view-filters.mobile-filters-open .card-body::-webkit-scrollbar-thumb:hover {
    background: #aaa;
  }

  .view-filters.mobile-filters-open details.card {
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
  }

  .view-filters.mobile-filters-open summary.card-header,
  div[data-drupal-selector="edit-price-wrapper"] .fieldset-legend {
    padding: 4px 6px !important;
    font-size: 11px !important;
    font-weight: 600;
    background: #fff !important;
    border: none !important;
    color: #333;
    position: relative;
    transition: all 0.2s ease;
    box-shadow: none;
  }
  
  .view-filters.mobile-filters-open summary.card-header:hover {
    background: #f8f9fa !important;
    color: #667eea;
  }
  
  .view-filters.mobile-filters-open details[open] summary.card-header,div[data-drupal-selector="edit-price-wrapper"] .fieldset-legend {
    background: linear-gradient(135deg, #fff 0%, #667eea 100%) !important;
    color: #fff !important;
  }
  
  .view-filters.mobile-filters-open details[open] summary.card-header:hover {
    color: #fff !important;
  }

  summary.card-header{
    padding-right: 0 !important;
  }

  .view-filters.mobile-filters-open .card-body {
    padding: 4px 0 6px !important;
    border: none !important;
    max-height: 25vh;
    overflow-y: auto;
    margin-right: 6px;
  }
  
  
  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  .view-filters.mobile-filters-open .card {
    border: none !important;
    box-shadow: none !important;
  }
  
  /* RTL fix for filter items - checkbox on RIGHT */
  .view-filters.mobile-filters-open .form-item,
  .view-filters.mobile-filters-open .form-check,
  .view-filters.mobile-filters-open .bef-checkboxes,
  .view-filters.mobile-filters-open .bef-tree {
    direction: rtl !important;
    text-align: right !important;
  }
  
  .view-filters.mobile-filters-open .form-check,
  .view-filters.mobile-filters-open .bef-checkboxes .form-item,
  .view-filters.mobile-filters-open .form-type-checkbox {
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-start !important;
    align-items: center !important;
    gap: 4px;
  }
  
  .view-filters.mobile-filters-open .form-check-input,
  .view-filters.mobile-filters-open input[type="checkbox"] {
    margin: 0 !important;
    float: none !important;
    width: 14px !important;
    height: 14px !important;
    order: -1 !important;
    flex-shrink: 0 !important;
  }
  
  .view-filters.mobile-filters-open .form-check-label,
  .view-filters.mobile-filters-open .form-type-checkbox label,
  .view-filters.mobile-filters-open .option {
    margin: 0 !important;
    padding: 1px !important;
    font-size: 10px !important;
    order: 1 !important;
    flex-grow: 1 !important;
    text-align: right !important;
    line-height: 1.2 !important;
  }


  
  .view-filters.mobile-filters-open label {
    font-size: 15px !important;
  }

  /* Apply filters button at bottom of panel */
  .mobile-filter-apply {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 75%;
    max-width: 280px;
    padding: 15px;
    background: #fff;
    border-top: 1px solid #eee;
    z-index: 100000;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    visibility: hidden;
    direction: rtl;
  }

  .mobile-filter-apply.active,
  body.mobile-filter-active .mobile-filter-apply {
    transform: translateX(0);
    visibility: visible;
  }

  .mobile-filter-buttons {
    display: flex;
    gap: 10px;
    direction: rtl;
  }

  .mobile-filter-apply-btn {
    flex: 1;
    padding: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-family: "Cairo", sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .mobile-filter-apply-btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
  
  .mobile-filter-reset-btn {
    padding: 14px 16px;
    background: transparent;
    color: #666;
    border: 1px solid #ddd;
    border-radius: 12px;
    font-family: "Cairo", sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .mobile-filter-reset-btn:active {
    transform: scale(0.98);
    background: #f5f5f5;
  }


  /* Hide filter count badge */
  .mobile-filter-toggle .filter-count {
    display: none !important;
  }

  /* Results count text */
  .mobile-filter-results {
    font-family: "Cairo", sans-serif;
    font-size: 13px;
    color: #666;
    direction: rtl;
  }

  /* View header styling when mobile filter is active */
  .view-header.mobile-filter-header-active {
    display: flex !important;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    background: #fff;
    border-bottom: none;
    direction: rtl;
  }

  /* Filter toggle button - first (rightmost in RTL) */
  .view-header.mobile-filter-header-active .mobile-filter-toggle {
    order: 1;
    flex-shrink: 0;
  }
  
  /* Grid toggle - after filter button */
  .view-header.mobile-filter-header-active .mobile-grid-toggle {
    order: 2;
    flex-shrink: 0;
  }

  /* Products count - after grid toggle */
  .view-header.mobile-filter-header-active #products-count {
    order: 3;
    margin: 0;
    flex-shrink: 0;
    font-size: 12px;
  }
  
  /* Hide category text on mobile to save space */
  .view-header.mobile-filter-header-active #category-id-text {
    display: none !important;
  }

  /* Hide original sort inside filter panel on mobile */
  #products-sort.mobile-sort-hidden {
    display: none !important;
  }

  /* Mobile sort clone in view-header - leftmost in RTL */
  .view-header.mobile-filter-header-active #products-sort-mobile {
    order: 4;
    margin-right: auto !important; /* Push to the left in RTL */
    flex-shrink: 0;
  }
  
  .view-header.mobile-filter-header-active #products-sort-mobile .js-form-item {
    margin: 0 !important;
  }
  
  .view-header.mobile-filter-header-active #products-sort-mobile select {
    padding: 6px 10px !important;
    font-size: 12px !important;
    border-radius: 6px !important;
    border: none !important;
    max-width: 120px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  
  /* Also style in fallback container */
  .mobile-filter-container #products-sort-mobile {
    margin-right: auto !important;
  }
  
  .mobile-filter-container #products-sort-mobile .js-form-item {
    margin: 0 !important;
  }
  
  .mobile-filter-container #products-sort-mobile select {
    padding: 6px 10px !important;
    font-size: 12px !important;
    border-radius: 6px !important;
    border: none !important;
    max-width: 120px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  /* Body scroll lock when filter is open */
  body.mobile-filter-active {
    overflow: hidden !important;
  }

  /* Hide the view header when it would be empty */
  .view-header:empty {
    display: none;
  }
}

/* Desktop - ensure filter toggle and grid toggle are hidden */
@media screen and (min-width: 769px) {
  .mobile-filter-toggle,
  .mobile-grid-toggle,
  .mobile-filter-container,
  .mobile-filter-backdrop,
  .mobile-filter-close,
  .mobile-filter-header,
  .mobile-filter-apply {
    display: none !important;
  }
}

