/* RumX Search - InstantSearch.js Best Practices Implementation */

/* ========================================
   Design System Tokens
   ======================================== */

:root {
  /* RumX Brand Colors */
  --rumx-primary: #2c3e50;
  --rumx-secondary: #ac6235;
  --rumx-secondary-hover: #956140;
  
  /* Neutral Colors */
  --rumx-gray-50: #f8f9fa;
  --rumx-gray-100: #e9ecef;
  --rumx-gray-200: #dee2e6;
  --rumx-gray-300: #ced4da;
  --rumx-gray-600: #6c757d;
  --rumx-gray-900: #212529;
  
  /* Spacing Scale */
  --rumx-space-xs: 0.25rem;
  --rumx-space-sm: 0.5rem;
  --rumx-space-md: 1rem;
  --rumx-space-lg: 1.5rem;
  --rumx-space-xl: 3rem;
  
  /* Border Radius */
  --rumx-radius-sm: 0.25rem;
  --rumx-radius-md: 0.375rem;
  --rumx-radius-lg: 0.5rem;
  --rumx-radius-xl: 0.75rem;
  
  /* Shadows */
  --rumx-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --rumx-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  
  /* Typography */
  --rumx-text-sm: 0.875rem;
  --rumx-text-base: 1rem;
  --rumx-text-lg: 1.125rem;
}

/* ========================================
   Layout & Grid System
   ======================================== */

/* Responsive Hits Layout - Equal width cards */
.ais-Hits-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--rumx-space-lg);
  list-style: none;
  margin: 0;
  padding: 0;
  align-items: stretch;
}

/* Tablet: 2 columns */
@media (min-width: 768px) {
  .ais-Hits-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Large desktop: still 2 columns for better readability */
@media (min-width: 1200px) {
  .ais-Hits-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

.ais-Hits-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  /* Force strict containment to prevent content overflow affecting layout */
  contain: layout style;
  overflow: hidden;
  box-sizing: border-box;
  /* Prevent any width expansion */
  min-width: 0;
  max-width: 100%;
  flex-shrink: 0;
}

/* Ensure rum cards stretch to fill available height and respect boundaries */
.ais-Hits-item .rum-item-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  /* Critical: Contain all content within card boundaries */
  overflow: hidden !important;
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  /* Prevent any internal content from affecting card width */
  contain: layout style;
}

/* Ensure all card content respects boundaries */
.ais-Hits-item .rum-item-card * {
  box-sizing: border-box;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Mobile: single column */
@media (max-width: 767px) {
  .ais-Hits-list {
    grid-template-columns: 1fr;
    gap: var(--rumx-space-md);
  }
}

/* ========================================
   Search Box Styling
   ======================================== */

.ais-SearchBox-form {
  position: relative;
  display: flex;
  background: white;
  border: 2px solid var(--rumx-gray-200);
  border-radius: var(--rumx-radius-lg);
  transition: border-color 0.2s ease;
}

.ais-SearchBox-form:focus-within {
  border-color: var(--rumx-secondary);
  box-shadow: 0 0 0 3px rgba(172, 98, 53, 0.1);
}

.ais-SearchBox-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: var(--rumx-space-md);
  font-size: var(--rumx-text-base);
  outline: none;
}

.ais-SearchBox-input::placeholder {
  color: var(--rumx-gray-600);
}

.ais-SearchBox-submit,
.ais-SearchBox-reset {
  background: none;
  border: none;
  padding: var(--rumx-space-md);
  cursor: pointer;
  color: var(--rumx-gray-600);
  transition: color 0.2s ease;
}

.ais-SearchBox-submit:hover,
.ais-SearchBox-reset:hover {
  color: var(--rumx-secondary);
}

/* Hide submit button if not needed */
.ais-SearchBox-submit {
  display: none;
}

/* ========================================
   Sidebar & Filters
   ======================================== */

.search-sidebar {
  background: white;
  border: 1px solid var(--rumx-gray-200);
  border-radius: var(--rumx-radius-md);
  box-shadow: var(--rumx-shadow-sm);
  margin-bottom: var(--rumx-space-lg);
}

.search-sidebar-header {
  padding: var(--rumx-space-md) var(--rumx-space-lg);
  border-bottom: 1px solid var(--rumx-gray-200);
  background: var(--rumx-gray-50);
  border-radius: var(--rumx-radius-md) var(--rumx-radius-md) 0 0;
}

.search-sidebar-header h5 {
  margin: 0;
  color: var(--rumx-primary);
  font-weight: 600;
  font-size: var(--rumx-text-base);
}

.search-sidebar-section {
  padding: var(--rumx-space-lg);
  border-bottom: 1px solid var(--rumx-gray-100);
}

.search-sidebar-section:last-child {
  border-bottom: none;
}

.search-sidebar-title {
  margin: 0;
  color: var(--rumx-primary);
  font-size: var(--rumx-text-sm);
  font-weight: 600;
}

/* ========================================
   Clear All Button
   ======================================== */

#clear-all-active {
  color: var(--rumx-secondary);
  font-size: var(--rumx-text-sm);
  font-weight: 500;
  text-decoration: none;
  padding: var(--rumx-space-xs) var(--rumx-space-sm);
  border: none;
  background: none;
  border-radius: var(--rumx-radius-sm);
  transition: all 0.2s ease;
  cursor: pointer;
}

#clear-all-active:hover {
  color: var(--rumx-secondary-hover);
  background: rgba(172, 98, 53, 0.1);
  text-decoration: none;
}

/* ========================================
   Refinement Lists
   ======================================== */

.ais-RefinementList-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ais-RefinementList-item {
  margin-bottom: var(--rumx-space-sm);
}

.ais-RefinementList-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: var(--rumx-text-sm);
  color: var(--rumx-gray-900);
  transition: color 0.2s ease;
}

.ais-RefinementList-label:hover {
  color: var(--rumx-secondary);
}

.ais-RefinementList-checkbox {
  margin: 0 var(--rumx-space-sm) 0 0;
  accent-color: var(--rumx-secondary);
  width: 16px;
  height: 16px;
}

.ais-RefinementList-labelText {
  flex: 1;
  margin-right: var(--rumx-space-sm);
}

.ais-RefinementList-count {
  color: var(--rumx-gray-600);
  font-size: var(--rumx-text-sm);
  min-width: 1.5rem;
  text-align: center;
}

/* Show More button styling */
.ais-RefinementList-showMore {
  background: none;
  border: none;
  color: var(--rumx-secondary);
  cursor: pointer;
  font-size: var(--rumx-text-sm);
  font-weight: 500;
  padding-top: var(--rumx-space-sm);
  text-align: left;
  width: 100%;
  transition: all 0.2s ease;
}

.ais-RefinementList-showMore:hover {
  background: var(--rumx-gray-50);
  color: var(--rumx-secondary-hover);
}

/* Search box within refinement lists */
.ais-RefinementList .ais-SearchBox {
  padding-bottom: var(--rumx-space-md);
}

.ais-RefinementList .ais-SearchBox-form {
  position: relative;
  border: 1px solid var(--rumx-gray-300);
  border-radius: var(--rumx-radius-sm);
}

.ais-RefinementList .ais-SearchBox-input {
  width: 100%;
  padding: var(--rumx-space-sm) var(--rumx-space-md);
  border: none;
  border-radius: var(--rumx-radius-sm);
  font-size: var(--rumx-text-sm);
  background: white;
  color: var(--rumx-primary);
}

.ais-RefinementList .ais-SearchBox-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(172, 98, 53, 0.2);
}

.ais-RefinementList .ais-SearchBox-form:focus-within {
  border-color: var(--rumx-secondary);
}

/* ========================================
   Range Slider
   ======================================== */

.ais-RangeSlider .rheostat {
  background: var(--rumx-gray-200);
  border: none;
  margin: var(--rumx-space-lg) 0;
}

.ais-RangeSlider .rheostat-background {
  background: var(--rumx-gray-200);
  border: none;
}

.ais-RangeSlider .rheostat-progress {
  background: var(--rumx-secondary);
}

.ais-RangeSlider .rheostat-handle {
  background: var(--rumx-secondary);
  border: 2px solid white;
  box-shadow: var(--rumx-shadow-md);
}

/* ========================================
   Pagination
   ======================================== */

.ais-Pagination-list {
  display: flex;
  justify-content: center;
  list-style: none;
  margin: var(--rumx-space-xl) 0;
  padding: 0;
  gap: var(--rumx-space-xs);
}

.ais-Pagination-item {
  display: block;
}

.ais-Pagination-link {
  display: block;
  padding: var(--rumx-space-sm) var(--rumx-space-md);
  color: var(--rumx-gray-600);
  text-decoration: none;
  border: 1px solid var(--rumx-gray-200);
  border-radius: var(--rumx-radius-md);
  transition: all 0.2s ease;
  min-width: 2.5rem;
  text-align: center;
}

.ais-Pagination-link:hover,
.ais-Pagination-item--selected .ais-Pagination-link {
  background: var(--rumx-secondary);
  color: white;
  border-color: var(--rumx-secondary);
}

.ais-Pagination-item--disabled .ais-Pagination-link {
  color: var(--rumx-gray-300);
  cursor: not-allowed;
}

.ais-Pagination-item--disabled .ais-Pagination-link:hover {
  background: none;
  color: var(--rumx-gray-300);
  border-color: var(--rumx-gray-200);
}

/* ========================================
   Stats & Sort Layout
   ======================================== */

.ais-Stats {
  color: var(--rumx-gray-600);
  font-size: var(--rumx-text-sm);
  margin-bottom: var(--rumx-space-sm);
}

/* Desktop stats and sort alignment */
@media (min-width: 576px) {
  .d-flex.justify-content-between.align-items-start.align-items-sm-center {
    align-items: center !important;
  }
  
  .ais-Stats {
    margin-bottom: 0;
    display: flex;
    align-items: center;
  }
  
  .custom-sort-container {
    display: flex;
    align-items: center;
  }
}

/* ========================================
   Mobile Filter Toggle
   ======================================== */

.mobile-filter-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  background: white;
  border: 1px solid var(--rumx-secondary);
  border-radius: var(--rumx-radius-md);
  color: var(--rumx-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: var(--rumx-space-sm);
}

.mobile-filter-toggle:hover {
  border-color: var(--rumx-secondary);
  color: var(--rumx-secondary);
  background: rgba(172, 98, 53, 0.05);
}

.mobile-filter-toggle[aria-expanded="true"] {
  background: var(--rumx-secondary);
  border-color: var(--rumx-secondary);
  color: white;
}

.mobile-filter-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
}

.mobile-filter-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Hide the text on mobile to make it icon-only */
.mobile-filter-text {
  display: none;
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 991.98px) {
  .search-sidebar {
    margin-bottom: var(--rumx-space-lg);
  }
  
  #sidebarFilters {
    margin-top: var(--rumx-space-sm);
  }
}

/* ========================================
   Custom Inputs
   ======================================== */

.custom-input {
  width: 100%;
  padding: var(--rumx-space-xs) var(--rumx-space-sm);
  border: 1px solid var(--rumx-gray-300);
  border-radius: var(--rumx-radius-sm);
  font-size: var(--rumx-text-sm);
  line-height: 1.2;
  height: auto;
  transition: border-color 0.2s ease;
}

.custom-input:focus {
  outline: none;
  border-color: var(--rumx-secondary);
  box-shadow: 0 0 0 3px rgba(172, 98, 53, 0.1);
}

.input-group {
  display: flex;
  gap: var(--rumx-space-sm);
  margin-top: var(--rumx-space-sm);
}

.input-group .custom-input {
  flex: 1;
}

/* ========================================
   Focus & Accessibility
   ======================================== */

.ais-RefinementList-checkbox:focus {
  outline: 2px solid var(--rumx-secondary);
  outline-offset: 2px;
}

.ais-Pagination-link:focus {
  outline: 2px solid var(--rumx-secondary);
  outline-offset: 2px;
}

/* ========================================
   Loading States
   ======================================== */

.ais-SearchBox-loadingIndicator,
.ais-InfiniteHits-loadMore[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --rumx-gray-200: #000;
    --rumx-gray-300: #000;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.collapse-icon {
  margin-left: 3px;
}