/* Base styles for the search form */
.woocommerce-product-search {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  position: relative;
  width: 100%;
  border-radius: 4px;
  overflow: hidden;
  background-color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Category dropdown styles */
.ewp-category-dropdown {
  position: relative;
  min-width: 80px;
  border-right: 1px solid #ddd;
  background-color: #f3f3f3;
}

.ewp-category-dropdown-right {
  border-right: none;
  border-left: 1px solid #ddd;
  order: 2;
}

.ewp-category-dropdown-left {
  order: 0;
}

.ewp-category-dropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  height: 100%;
  min-height: 44px;
  cursor: pointer;
  font-size: 14px;
  color: #333;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.ewp-category-dropdown-toggle i,
.ewp-category-dropdown-toggle svg {
  margin-left: 5px;
  font-size: 12px;
  transition: transform 0.2s ease;
}

.ewp-category-dropdown.active .ewp-category-dropdown-toggle i,
.ewp-category-dropdown.active .ewp-category-dropdown-toggle svg {
  transform: rotate(180deg);
}

.ewp-category-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  min-width: 180px;
  max-height: 300px;
  overflow-y: auto;
  background-color: #fff;
  border: 1px solid #ddd;
  border-top: none;
  z-index: 1001;
  display: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.ewp-category-dropdown.active .ewp-category-dropdown-menu {
  display: block;
}

.ewp-category-dropdown-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ewp-category-dropdown-menu li {
  padding: 8px 12px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.ewp-category-dropdown-menu li:hover {
  background-color: #f5f5f5;
}

.ewp-category-dropdown-menu li.selected {
  background-color: #f0f0f0;
  font-weight: bold;
}

/* Allow the search field to expand */
.woocommerce-product-search .search-field {
  flex: 1;
  min-height: 44px; /* Larger touch target for mobile */
  font-size: 16px; /* Prevent iOS zoom on focus */
  -webkit-appearance: none; /* Remove default iOS styling */
  border: none;
  padding: 0 15px;
  outline: none;
  order: 1;
}

/* Add styling for icon with text button */
.woocommerce-product-search button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: #febd69;
  cursor: pointer;
  transition: all 0.3s ease;
  min-height: 44px; /* Larger touch target for mobile */
  min-width: 44px; /* Minimum touch target size */
  padding: 0 15px;
  line-height: 1;
  order: 3;
}

/* Enhanced styling for icon buttons */
.woocommerce-product-search button i,
.woocommerce-product-search button svg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Ensure SVG icons are properly sized and colored */
.woocommerce-product-search button svg {
  width: 1.2em;
  height: 1.2em;
  vertical-align: middle;
}

/* Fix for icon spacing in icon_text mode */
.woocommerce-product-search button i + span,
.woocommerce-product-search button svg + span {
  margin-left: 8px;
}

/* Button hover effect */
.woocommerce-product-search button:hover {
  background-color: #f3a847;
}

/* Button text styling */
.woocommerce-product-search button span {
  display: inline-block;
  vertical-align: middle;
}

/* Mobile search toggle button */
.ewp-mobile-search-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 10px;
  margin-left: auto;
}

/* AJAX results container */
#ewp-ajax-results,
#ewp-mobile-ajax-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  z-index: 1000;
  max-height: 300px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  border-radius: 0 0 4px 4px;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* AJAX results list styling */
#ewp-ajax-results ul,
#ewp-mobile-ajax-results ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#ewp-ajax-results li,
#ewp-mobile-ajax-results li {
  padding: 12px; /* Larger touch targets */
  border-bottom: 1px solid #eee;
  transition: background-color 0.2s ease;
}

#ewp-ajax-results li:last-child,
#ewp-mobile-ajax-results li:last-child {
  border-bottom: none;
}

#ewp-ajax-results li a,
#ewp-mobile-ajax-results li a {
  text-decoration: none;
  color: #333;
  display: flex;
  align-items: center; /* Changed from flex-start to center for better vertical alignment */
  min-height: 44px; /* Minimum touch target size */
  padding: 8px 0; /* Add some vertical padding */
}

#ewp-ajax-results li a img,
#ewp-mobile-ajax-results li a img {
  max-width: 50px;
  margin-right: 10px;
  border-radius: 4px;
  object-fit: cover; /* Ensure consistent image display */
  height: 50px; /* Fixed height for thumbnails */
  width: 50px; /* Fixed width for thumbnails */
}

#ewp-ajax-results li a .product-info,
#ewp-mobile-ajax-results li a .product-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#ewp-ajax-results li a .product-title,
#ewp-mobile-ajax-results li a .product-title {
  font-weight: bold;
  margin-bottom: 4px; /* Small margin for price if shown */
  line-height: 1.3;
}

#ewp-ajax-results li a .product-price,
#ewp-mobile-ajax-results li a .product-price {
  font-size: 0.9em;
  color: #666;
}

/* View all results link */
.ewp-view-all-link {
  display: block;
  text-align: center;
  padding: 10px;
  background-color: #f7f7f7;
  color: #333;
  text-decoration: none;
  font-weight: bold;
  border-top: 1px solid #eee;
  transition: background-color 0.2s ease;
}

.ewp-view-all-link:hover {
  background-color: #eee;
  color: #000;
}

/* Highlight styling for search terms */
.ewp-highlight {
  background-color: #ffeb3b;
  color: #000;
  font-weight: bold;
  padding: 0 2px;
  border-radius: 2px;
}

/* Mobile overlay for fullscreen search */
.ewp-mobile-search-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.95);
  z-index: 9999;
  padding: 20px;
  flex-direction: column;
  overflow-y: auto;
}

.ewp-mobile-search-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}

.ewp-mobile-search-overlay-title {
  font-size: 18px;
  font-weight: bold;
}

.ewp-mobile-search-overlay-close {
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}

.ewp-mobile-search-overlay .woocommerce-product-search {
  margin-bottom: 15px;
}

.ewp-mobile-search-overlay #ewp-mobile-ajax-results {
  position: relative;
  max-height: none;
  flex: 1;
  border: none;
  box-shadow: none;
}

/* Loading indicator */
.ewp-loading-spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top: 2px solid #0073aa;
  border-radius: 50%;
  position: absolute;
  right: 50px;
  top: 50%;
  transform: translateY(-50%);
  animation: ewp-spin 1s linear infinite;
}

@keyframes ewp-spin {
  0% {
    transform: translateY(-50%) rotate(0deg);
  }
  100% {
    transform: translateY(-50%) rotate(360deg);
  }
}

/* Amazon-style search bar */
.ewp-amazon-style .woocommerce-product-search {
  background-color: #232f3e;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.ewp-amazon-style .ewp-category-dropdown {
  background-color: #f3f3f3;
  border-right: 1px solid #cdcdcd;
}

.ewp-amazon-style .ewp-category-dropdown-right {
  border-right: none;
  border-left: 1px solid #cdcdcd;
}

.ewp-amazon-style .ewp-category-dropdown-toggle {
  color: #333;
}

.ewp-amazon-style .search-field {
  border: none;
  background-color: #fff;
}

.ewp-amazon-style button {
  background-color: #febd69;
  color: #111;
}

.ewp-amazon-style button:hover {
  background-color: #f3a847;
}

/* Result item with keyboard focus */
.ewp-result-focus {
  background-color: #f0f0f0;
  outline: 2px solid #0073aa;
}

/* Responsive styles */
@media (max-width: 767px) {
  /* Standard mobile view */
  .woocommerce-product-search:not(.ewp-mobile-fullscreen) {
    flex-wrap: wrap;
  }

  .woocommerce-product-search:not(.ewp-mobile-fullscreen) .search-field {
    flex: 1;
    min-width: 0;
    margin-right: 8px;
  }

  /* Responsive adjustments for buttons */
  .woocommerce-product-search button {
    padding: 0 10px;
  }

  .woocommerce-product-search button i {
    font-size: 1.1em;
  }

  .woocommerce-product-search button span {
    font-size: 0.9em;
  }

  /* Category dropdown on mobile */
  .ewp-category-dropdown {
    min-width: 60px;
  }

  .ewp-category-dropdown-toggle {
    padding: 0 8px;
    font-size: 13px;
  }

  /* Fullscreen mobile search toggle */
  .ewp-mobile-search-container.ewp-fullscreen-enabled .woocommerce-product-search {
    display: none;
  }

  .ewp-mobile-search-container.ewp-fullscreen-enabled .ewp-mobile-search-toggle {
    display: flex;
  }

  /* Adjust results for better mobile viewing */
  #ewp-ajax-results li a,
  #ewp-mobile-ajax-results li a {
    flex-direction: row;
    align-items: center;
  }

  #ewp-ajax-results li a img,
  #ewp-mobile-ajax-results li a img {
    margin-bottom: 0;
    margin-right: 10px;
    max-width: 40px; /* Slightly smaller on mobile */
    height: 40px;
    width: 40px;
  }

  /* Adjust for mobile landscape */
  @media (orientation: landscape) {
    .ewp-mobile-search-overlay {
      padding: 10px;
    }
  }
}

/* Tablet styles */
@media (min-width: 768px) and (max-width: 1024px) {
  .woocommerce-product-search {
    max-width: 100%;
  }

  #ewp-ajax-results,
  #ewp-mobile-ajax-results {
    max-height: 400px;
  }
}

/* Prevent body scroll when overlay is active */
body.ewp-overlay-active {
  overflow: hidden;
}
