/**
 * Modern Search with Algolia - Frontend Styles
 * Dropdown-style search interface with Plus Jakarta Sans font
 */

/* Main search container */
.msa-search-bar {
  font-family: 'Balto', sans-serif;
  position: relative;
  max-width: 500px;
  margin: 0 auto;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

/* Search input container */
#msa-searchbox {
  position: relative;
  margin-bottom: 0;
}

.ais-SearchBox {
  position: relative;
}

.ais-SearchBox-form {
  position: relative;
  display: flex;
  align-items: center;
  background: #fff;
  border: none;
  border-radius: 50px;
  overflow: hidden;
  transition: all 0.2s ease;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  height: 56px;
  max-width: 100%;
}

.ais-SearchBox-form:focus-within {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.ais-SearchBox-input {
  font-family: 'Balto', sans-serif;
  flex: 1;
  padding: 16px 20px;
  border: none;
  outline: none;
  font-size: 16px;
  font-weight: 400;
  color: #333;
  background: transparent;
  line-height: 1.5;
}

.ais-SearchBox-input::placeholder {
  color: #888;
  font-weight: 400;
}

.ais-SearchBox-submit {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  margin: 4px;
  margin-left: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.ais-SearchBox-submit:hover {
  background: rgba(0, 0, 0, 0.1);
  transform: scale(1.05);
}

.ais-SearchBox-reset {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin: 0 8px;
  display: none; /* Hide reset button for cleaner look */
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
  border-radius: 50%;
  opacity: 0.5;
}

.ais-SearchBox-reset:hover {
  opacity: 0.8;
}

.ais-SearchBox-submitIcon {
  width: 20px;
  height: 20px;
  fill: #666;
  max-width: 20px;
  max-height: 20px;
  flex-shrink: 0;
}

.ais-SearchBox-resetIcon {
  width: 16px;
  height: 16px;
  fill: #666;
}

.ais-SearchBox-loadingIndicator {
  position: absolute;
  right: 60px;
  top: 50%;
  transform: translateY(-50%);
}

.ais-SearchBox-loadingIcon {
  width: 20px;
  height: 20px;
  fill: #666;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Results dropdown container */
#msa-hits {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  border: 1px solid #ddd;
  max-height: 400px;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1001;
  display: none; /* Hidden by default, but can be shown */
  box-sizing: border-box;
}

/* Show dropdown when there are results or loading */
#msa-hits:not(:empty),
#msa-hits.msa-loading,
#msa-hits.msa-show {
  display: block !important;
}

.ais-Hits {
  margin: 0;
  padding: 8px 0;
}

.ais-Hits-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: block;
}

.ais-Hits-item {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 0;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid #f3f4f6;
}

.ais-Hits-item:last-child {
  border-bottom: none;
}

.ais-Hits-item:hover {
  background: #f8fafc;
}

/* Individual hit styling */
.msa-hit {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  padding: 12px 16px;
  min-height: 64px;
  border-radius: 0;
  transition: background-color 0.15s ease;
}

.msa-hit:hover {
  text-decoration: none;
  color: inherit;
  background: #f8fafc;
}

.msa-hit:focus {
  outline: none;
  background: #f0f7ff;
}

.msa-hit-image {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  overflow: hidden;
  background: #f9fafb;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e5e7eb;
}

.msa-hit-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msa-hit-image .msa-no-image {
  color: #9ca3af;
  font-size: 10px;
  text-align: center;
  font-family: 'Balto', sans-serif;
  font-weight: 500;
}

.msa-hit-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msa-hit-title {
  font-family: 'Balto', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  color: #111;
  margin: 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.msa-hit-title mark {
  background: #fef3c7;
  padding: 1px 2px;
  border-radius: 2px;
  font-weight: 700;
  color: #92400e;
}

.msa-hit-description {
  display: none; /* Hide description as requested */
}

.msa-hit-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.msa-hit-price {
  font-family: 'Balto', sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #059669;
}

.msa-hit-price .msa-regular-price {
  text-decoration: line-through;
  color: #9ca3af;
  margin-right: 4px;
  font-weight: 500;
  font-size: 12px;
}

.msa-hit-price .msa-sale-price {
  color: #dc2626;
}

.msa-hit-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.msa-badge {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.msa-badge--featured {
  background: #fef3c7;
  color: #92400e;
}

.msa-badge--sale {
  background: #fee2e2;
  color: #dc2626;
}

.msa-badge--out-of-stock {
  background: #f3f4f6;
  color: #6b7280;
}

.msa-badge--category {
  background: #ede9fe;
  color: #7c3aed;
}

.msa-hit-rating {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: #6b7280;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.msa-stars {
  display: flex;
  gap: 1px;
}

.msa-star {
  width: 10px;
  height: 10px;
  fill: #fbbf24;
}

.msa-star--empty {
  fill: #e5e7eb;
}

/* Category-specific styling */
.msa-hit--category {
  border-left: 3px solid #10b981;
  padding-left: 13px;
}

.msa-hit--category .msa-hit-title {
  color: #065f46;
}

.msa-hit--category .msa-hit-image {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.msa-category-count {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 11px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

/* Loading and empty states */
.msa-loading {
  text-align: center;
  padding: 24px 16px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
}

.msa-loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #2563eb;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: 8px;
}

.msa-no-results {
  text-align: center;
  padding: 24px 16px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  color: #6b7280;
}

.msa-no-results h3 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 15px;
  margin: 0 0 4px 0;
  color: #1f2937;
  font-weight: 600;
}

.msa-no-results p {
  margin: 0;
  font-size: 13px;
  font-weight: 400;
}

/* Pagination in dropdown */
#msa-pagination {
  display: block; /* Always visible when needed */
  margin-top: 0;
  padding: 8px 16px;
  border-top: 1px solid #f3f4f6;
  background: #fafbfc;
  border-radius: 0 0 12px 12px;
  order: 999; /* Ensure it appears at the bottom */
}

.ais-Pagination {
  text-align: center;
}

.ais-Pagination-list {
  display: inline-flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 2px;
}

.ais-Pagination-item {
  margin: 0;
}

.ais-Pagination-link {
  font-family: 'Plus Jakarta Sans', sans-serif;
  display: block;
  padding: 4px 8px;
  text-decoration: none;
  color: #6b7280;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  transition: all 0.15s ease;
  font-size: 12px;
  font-weight: 500;
  min-width: 28px;
  text-align: center;
}

.ais-Pagination-link:hover {
  background: #f3f4f6;
  color: #1f2937;
  text-decoration: none;
}

.ais-Pagination-item--selected .ais-Pagination-link {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.ais-Pagination-item--disabled .ais-Pagination-link {
  opacity: 0.4;
  cursor: not-allowed;
}

.ais-Pagination-item--disabled .ais-Pagination-link:hover {
  background: transparent;
  color: #6b7280;
}

/* Stats */
.msa-stats {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 12px;
  color: #9ca3af;
  padding: 8px 16px;
  text-align: center;
  border-bottom: 1px solid #f3f4f6;
  font-weight: 500;
}

.msa-powered-by {
  display: none; /* Hide footer as requested */
}

/* Click outside to close dropdown - DISABLED to prevent interaction issues */
.msa-search-overlay {
  display: none !important; /* Completely disable overlay */
}

/* Scrollbar styling for dropdown */
#msa-hits::-webkit-scrollbar {
  width: 8px;
  background: transparent;
}

#msa-hits::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}

#msa-hits::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

#msa-hits::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
  background-clip: padding-box;
}

/* Hide scrollbar arrows/buttons - Complete removal */
#msa-hits::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

#msa-hits::-webkit-scrollbar-button:start:decrement,
#msa-hits::-webkit-scrollbar-button:end:increment {
  display: none;
  width: 0;
  height: 0;
}

#msa-hits::-webkit-scrollbar-corner {
  background: transparent;
}

/* Elementor widget alignment support */
.elementor-widget-msa_search_widget {
  width: 100%;
}

.elementor-widget-msa_search_widget .msa-search-bar {
  max-width: 100%;
  flex-shrink: 0;
  display: inline-block;
}

/* Reset text alignment for dropdown content */
.elementor-widget-msa_search_widget #msa-hits,
.elementor-widget-msa_search_widget .msa-hit,
.elementor-widget-msa_search_widget .ais-Hits-item {
  text-align: left !important;
}

.elementor-widget-msa_search_widget .msa-hit-title,
.elementor-widget-msa_search_widget .msa-hit-price,
.elementor-widget-msa_search_widget .msa-category-count {
  text-align: left !important;
}

/* Force alignment when Elementor uses flexbox */
.elementor-widget-msa_search_widget[style*="justify-content: center"] .msa-search-bar,
.elementor-widget-msa_search_widget[style*="justify-content:center"] .msa-search-bar {
  margin-left: auto !important;
  margin-right: auto !important;
}

.elementor-widget-msa_search_widget[style*="justify-content: flex-start"] .msa-search-bar,
.elementor-widget-msa_search_widget[style*="justify-content:flex-start"] .msa-search-bar {
  margin-left: 0 !important;
  margin-right: auto !important;
}

.elementor-widget-msa_search_widget[style*="justify-content: flex-end"] .msa-search-bar,
.elementor-widget-msa_search_widget[style*="justify-content:flex-end"] .msa-search-bar {
  margin-left: auto !important;
  margin-right: 0 !important;
}

/* Responsive design */
@media (max-width: 768px) {
  .msa-search-bar {
    max-width: 100%;
    margin: 0 16px;
  }
  
  .ais-SearchBox-form {
    height: 52px;
  }
  
  .ais-SearchBox-input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 14px 18px;
  }
  
  .ais-SearchBox-submit {
    width: 44px;
    height: 44px;
    margin: 4px;
  }
  
  .ais-SearchBox-submitIcon {
    width: 18px;
    height: 18px;
  }
  
  .msa-hit {
    padding: 12px 14px;
  }
  
  .msa-hit-image {
    width: 36px;
    height: 36px;
  }
  
  .msa-hit-title {
    font-size: 13px;
  }
  
  #msa-hits {
    max-height: 60vh;
    border-radius: 12px;
  }
}

@media (max-width: 480px) {
  .ais-SearchBox-form {
    height: 48px;
  }
  
  .ais-SearchBox-input {
    padding: 12px 16px;
    font-size: 16px;
  }
  
  .ais-SearchBox-submit {
    width: 40px;
    height: 40px;
    margin: 4px;
  }
  
  .ais-SearchBox-submitIcon {
    width: 16px;
    height: 16px;
  }
  
  .msa-hit {
    padding: 10px 12px;
    min-height: 56px;
  }
  
  .msa-hit-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}

/* RTL support */
[dir="rtl"] .msa-search-bar {
  direction: rtl;
}

[dir="rtl"] .ais-SearchBox-form {
  flex-direction: row-reverse;
}

[dir="rtl"] .msa-hit {
  flex-direction: row-reverse;
}

[dir="rtl"] .msa-hit-meta {
  flex-direction: row-reverse;
}

/* Print styles */
@media print {
  .msa-search-bar {
    display: none;
  }
}

/* Focus styles for accessibility */
.msa-hit:focus {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
  background: #eff6ff;
}

/* Animation for dropdown appearance */
#msa-hits {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#msa-hits:not(:empty),
#msa-hits.msa-show {
  opacity: 1;
  transform: translateY(0);
}

/* Elementor widget specific styles */
.elementor-widget-msa_search_widget .msa-search-bar {
  max-width: 100%;
  margin: 0;
}

.elementor-widget-msa_search_widget #msa-hits,
.elementor-widget-msa_search_widget [id$="-hits"] {
  position: absolute;
  z-index: 9999;
}

.elementor-widget-msa_search_widget [id$="-pagination"] {
  order: 999;
  margin-top: auto;
}

/* Error and loading states */
.msa-loading {
  text-align: center;
  padding: 20px;
  color: #666;
  font-style: italic;
}

.msa-error {
  text-align: center;
  padding: 20px;
  color: #d63384;
  background: #f8d7da;
  border: 1px solid #f5c6cb;
  border-radius: 8px;
  margin: 10px;
}

.msa-fallback-notice {
  font-size: 12px;
  color: #666;
  margin-bottom: 5px;
  padding: 5px 10px;
  background: #fff3cd;
  border: 1px solid #ffeaa7;
  border-radius: 4px;
}

.msa-fallback-mode .ais-SearchBox {
  border-color: #ffc107;
}

/* Success states */
.msa-success {
  color: #155724;
  background: #d4edda;
  border: 1px solid #c3e6cb;
  border-radius: 4px;
  padding: 10px;
  margin: 10px 0;
}

/* Admin notices styling */
.notice.msa-notice {
  border-left-color: #0073aa;
}

.notice.msa-notice.notice-success {
  border-left-color: #46b450;
}

.notice.msa-notice.notice-error {
  border-left-color: #dc3232;
}

.notice.msa-notice p {
  margin: 0.8em 0;
  font-size: 14px;
}