/* ==========================================================================
   1. COMMON ELEMENTS AND BASE STYLING
   ========================================================================== */

/* Icons */
.search-icon-medium { width: 16px; height: 16px; }
.search-icon { width: 14px; height: 14px; }

/* Animation */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.container-fluid {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ==========================================================================
   2. SEARCH TRIGGER BUTTONS
   ========================================================================== */

#search-trigger, #search-trigger-header {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px 12px;
  color: inherit;
  font-size: 14px;
}

#search-trigger:hover, #search-trigger-header:hover {
  opacity: 0.8;
}

.search-trigger-container[data-trigger-position="header"] {
  position: fixed;
  top: 15px;
  right: 15px;
  z-index: 100;
  display: block;
}

/* Hide when set to none */
.search-trigger-container[data-trigger-position="none"] {
  display: none;
}

.search-trigger-button {
  background-color: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.search-trigger-button:hover {
  background-color: #e0e0e0;
  transform: scale(1.05);
}

.search-trigger-button svg {
  width: 20px;
  height: 20px;
  color: #333;
}

/* ==========================================================================
   3. SEARCH OVERLAY AND CONTAINER
   ========================================================================== */

#search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  z-index: 1000;
  display: none;
  justify-content: flex-end;
  align-items: flex-start;
  padding-top: 0;
  overflow-y: auto;
}

#search-overlay.active {
  display: flex;
}

#search-container {
  background-color: #fff;
  border-radius: 0;
  box-shadow: -5px 0 15px rgba(0, 0, 0, 0.2);
  width: 25vw;
  max-width: 25vw;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
  margin: 0;
}

#product-search {
  background-color: #fff;
}

#search-close, .search-close-button {
  background: transparent;
  border: none;
  cursor: pointer;
  color: #212b36;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001; /* Ensure it's above the overlay */
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 24px;
  width: 30px;
  height: 30px;
}

#search-close:hover, .search-close-button:hover {
  color: #000;
}

#search-close {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 24px;
  width: 30px;
  height: 30px;
}

/* ==========================================================================
   4. SEARCH LAYOUT AND FORM
   ========================================================================== */

.search-layout {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
  position: relative;
  padding: 15px 0;
}

.search-logo-container {
  position: absolute;
  left: 0;
  top: 0;  /* Changed from 50% to align top */
  transform: translateY(0); /* Remove vertical centering */
  width: auto;
  flex-shrink: 0;
  z-index: 2;
  height: 100%;
  display: flex;
  align-items: center;
}

.search-logo {
  display: block;
}

.logo-image img {
  max-height: 40px;
  width: auto;
}

.search-form-container {
  width: 100%;
  display: flex;
  justify-content: center;
}

.search-form-wrapper {
  width: 100%;
  max-width: 600px;
  position: relative;
  margin-left: 120px; /* Add space for logo */
}


.search-form {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  width: 100%;
}

#search-input, .search-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #c4cdd5;
  border-radius: 4px;
  font-size: 16px;
  outline: none;
  padding-right: 70px; /* Space for both icons */
}

/* Search button (magnifying glass icon) */
.search-button {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-submit-button {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 5px;
  cursor: pointer;
}

.search-spinner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 10;
}

.search-spinner-icon {
  width: 30px; /* Increased size for better visibility */
  height: 30px;
  animation: spin 1s linear infinite;
}

.search-clear-button {
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 5px;
  cursor: pointer;
  display: none; /* Hidden by default, shown via JS when input has value */
}

.search-right-container {
  width: 16.666%;
  display: none;
}

/* ==========================================================================
   5. SEARCH RESULTS
   ========================================================================== */

#search-results, .search-results {
  margin-top: 20px;
  /*display: grid;*/
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  background-color: #fff;
}

#search-results.list-view, .search-results.list-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-result-item {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e6e6e6;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.search-result-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.search-result-link {
  display: block;
  text-decoration: none;
  color: inherit;
  height: 100%;
}

.search-result-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.search-result-title {
  margin: 12px 0 8px;
  padding: 0 12px;
  font-size: 16px;
  font-weight: 500;
  color: #212b36;
}

.search-result-price {
  padding: 0 12px 12px;
  font-weight: 600;
  color: #212b36;
}

.search-result-price.on-sale {
  color: #bf0711;
}

.compare-price {
  text-decoration: line-through;
  color: #8c9196;
  margin-left: 5px;
}

/* List view specific styling */
#search-results.list-view .search-result-item,
.search-results.list-view .search-result-item {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 12px;
}

#search-results.list-view .search-result-image,
.search-results.list-view .search-result-image {
  width: 100px;
  height: 100px;
}

#search-results.list-view .search-result-title,
#search-results.list-view .search-result-price,
.search-results.list-view .search-result-title,
.search-results.list-view .search-result-price {
  padding: 0;
}

/* Loading state */
#search-loading {
  text-align: center;
  padding: 20px;
  background-color: #fff;
}

.loading-spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #008060;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

#banner-link {
  text-decoration: none;
  color: #1180fa;
}

#banner-link:hover {
  text-decoration: underline;
  color: #1180fa;
}

/* ==========================================================================
   6. PAGINATION
   ========================================================================== */

.search-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 24px;
  gap: 15px;
  padding: 16px 0;
  border-top: 1px solid #e6e6e6;
  background-color: #fff;
}

.pagination-button, .page-button {
  background-color: #f4f6f8;
  border: 1px solid #c4cdd5;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.pagination-button:hover:not(:disabled),
.page-button:hover:not(:disabled) {
  background-color: #dfe3e8;
}

.pagination-button:disabled,
.page-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-button.active {
  background: #f1f1f1;
}

.page-indicator {
  font-size: 14px;
  color: #637381;
}

/* ==========================================================================
   7. POPULAR SEARCHES AND SUGGESTIONS
   ========================================================================== */

/* Initial popular searches (shown before search) */
.popular-searches {
  margin: 30px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.popular-searches-label {
  margin-right: 10px;
  font-weight: 500;
  color: #333;
}

.popular-search-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-button {
  border-radius: 20px;
  padding: 8px 16px;
  background-color: #f6f6f6;
  border: 1px solid #e0e0e0;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #333;
}

.pill-button:hover {
  background-color: #e0e0e0;
}

/* Popular searches after submitting search (hidden initially) */
.search-popular {
  display: none; /* Hide by default, show with JS when search is submitted */
  flex-wrap: wrap;
  align-items: center;
  margin-top: 15px;
}

.has-search-results .popular-searches {
  display: none; /* Hide initial popular searches when showing results */
}

.has-search-results .search-popular {
  display: flex; /* Show when results are displayed */
}

.search-popular-label {
  margin-right: 10px;
  font-weight: 500;
}

.search-popular-items {
  display: flex;
  flex-wrap: wrap;
}

.search-popular-item {
  padding: 4px 12px;
  background-color: #f5f5f5;
  border-radius: 20px;
  margin: 0 5px 5px 0;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.search-popular-item:hover {
  background-color: #e5e5e5;
}

/* Suggestions styling */
.search-suggestions {
  padding-right: 15px;
}

.suggested-searches h3,
.suggested-collections h3 {
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 10px 0;
}

.suggestion-list,
.collection-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px 0;
}

.suggestion-list li,
.collection-list li {
  margin-bottom: 8px;
}

.search-suggestion-item {
  text-decoration: none;
  color: inherit;
}

/* Show more button */
.search-show-more {
  margin-top: 20px;
  text-align: center;
}

.show-more-button {
  display: inline-block;
  padding: 10px 20px;
  background: #000;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.show-more-button:hover {
  background: #333;
}

/* ==========================================================================
   8. PRODUCT SEARCH POPUP
   ========================================================================== */

.product-search-popup .search-close-button {
  position: absolute;
  top: 20px;
  right: 20px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1010; /* Higher than the popup's z-index (1000) */
  width: 30px;
  height: 30px;
  font-size: 24px;
  color: #333;
}

/* Add hover effect */
.product-search-popup .search-close-button:hover {
  color: #000;
}

/* Ensure popup has proper positioning context for absolute elements */
.product-search-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: white;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  /* Make room for the close button */
  padding: 60px 20px 20px;
}

.product-search-popup.active {
  opacity: 1;
  visibility: visible;
}

.product-search-wrapper {
  padding: 20px 0;
}

.search-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.search-title {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
}

/* ==========================================================================
   9. SEARCH RESULTS LAYOUT
   ========================================================================== */

.search-results-container {
  display: flex;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.search-sidebar {
  flex: 0 0 250px;
}

.search-products-container {
  flex: 1;
}

.search-results-heading {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 18px;
  font-weight: 600;
}

.product-results-list {
  display: flex;
  flex-direction: column;
}

.product-result-item {
  display: flex;
  gap: 15px;
  padding: 15px 0;
  border-bottom: 1px solid #eee;
  text-decoration: none;
  color: inherit;
}

.product-image {
  flex: 0 0 100px;
}

.product-image img {
  max-width: 100%;
  height: auto;
  object-fit: cover;
}

.product-details {
  flex: 1;
}

.product-title {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 500;
}

/* ==========================================================================
   10. MEDIA QUERIES
   ========================================================================== */

@media (min-width: 768px) {
  .search-logo-container,
  .search-right-container {
    display: flex;
  }
}

@media (max-width: 1200px) {
  #search-container {
    width: 33vw;
    max-width: 33vw;
  }

  #search-results,
  .search-results {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 992px) {
  #search-container {
    width: 50vw;
    max-width: 50vw;
  }

  #search-results,
  .search-results {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  #search-container {
    width: 100vw;
    max-width: 100vw;
  }

  .search-layout {
    flex-direction: column;
    padding-top: 60px; /* Make room for the absolutely positioned logo */
  }

  .search-logo-container {
    top: 0;
    transform: none;
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
  }

  #search-results,
  .search-results {
    grid-template-columns: repeat(1, 1fr);
    gap: 15px;
  }

  .search-form-wrapper {
    max-width: 100%;
  }

  .search-results-container {
    flex-direction: column;
  }

  .search-sidebar {
    flex: none;
    width: 100%;
  }

  .product-result-item {
    flex-direction: column;
  }

  .product-image {
    flex: none;
    width: 100%;
  }
}

@media (max-width: 480px) {
  #search-input, .search-input {
    padding: 10px 40px 10px 10px;
    font-size: 14px;
  }

  .search-pagination {
    flex-wrap: wrap;
  }

  .page-button {
    padding: 6px 12px;
    font-size: 12px;
  }

  .popular-search-terms {
    justify-content: center;
  }

  .pill-button {
    padding: 6px 12px;
    font-size: 12px;
  }
}
