/* Search Bar Component Styles */
.search-container {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
  font-family: inherit;
}

/* Header Search Bar Styles (optimized for dark header) */
.header-search .search-container {
  max-width: 610px;
  min-width: auto;
  margin: 0;
  min-height: 40px;
  display: block;
}

/* Ensure search container is visible */
.header-search {
  display: flex;
  align-items: center;
  min-height: 40px;
}

.header-search[data-search-container] {
  min-height: 40px;
  display: flex;
  align-items: center;
}

.header-search .search-wrapper {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.header-search .search-wrapper:focus-within {
  border-color: rgba(91, 67, 234, 0.6);
  box-shadow: 0 2px 12px rgba(91, 67, 234, 0.2);
  background: rgba(255, 255, 255, 0.15);
}

.header-search .search-input {
  color: #ffffff;
  font-size: 14px;
  padding: 8px 12px;
  background: transparent;
}

.header-search .search-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.header-search .search-button {
  width: 36px;
  height: 36px;
  background: #5b43ea;
  border-radius: 8px;
  margin: 4px;
  box-shadow: 0 1px 4px rgba(91, 67, 234, 0.3);
}

.header-search .search-button:hover {
  background: #4f3bd8;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(91, 67, 234, 0.4);
}

.header-search .search-button svg {
  width: 16px;
  height: 16px;
  fill: #ffffff;
}

.header-search .search-clear {
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.7);
  margin-right: 4px;
  border-radius: 6px;
}

.header-search .search-clear:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.header-search .search-clear svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: #ffffff;
  border: 2px solid #e5e7eb;
  transition: border-color 0.2s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.search-wrapper:focus-within {
  border-color: #654BEB;
  box-shadow: 0 2px 8px rgba(101, 75, 235, 0.15);
}

.search-input {
  flex: 1;
  padding: 12px 16px;
  border: none;
  outline: none;
  font-size: 16px;
  font-weight: 400;
  color: #1f2937;
  background: transparent;
  direction: rtl;
  min-width: 0; /* allow shrink inside flex */
}

.search-input::placeholder {
  color: #9ca3af;
  font-weight: 400;
}

.search-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: none;
  background: #654BEB;
  color: white;
  border-radius: 8px;
  margin: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  flex-shrink: 0;
}

.search-button:hover {
  background: #5a3fd8;
  transform: translateY(-1px);
}

.search-button:active {
  transform: translateY(0);
}

.search-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.search-clear {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: #f3f4f6;
  color: #6b7280;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.2s ease;
  margin-right: 8px;
}

.search-clear:hover {
  background: #e5e7eb;
  color: #374151;
}

.search-clear.visible {
  display: flex;
}

.search-clear svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Search Results Dropdown */
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #393766;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0 0 12px 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  max-height: 400px;
  overflow-y: auto;
  margin-top: 4px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.search-results.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.search-result-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: rgba(91, 67, 234, 0.1);
  border-color: rgba(91, 67, 234, 0.2);
}

.search-result-item.selected {
  background: rgba(91, 67, 234, 0.15);
  border-color: rgba(91, 67, 234, 0.3);
}

.search-result-icon {
  width: 24px;
  height: 24px;
  margin-left: 12px;
  color: #c7baff;
  flex-shrink: 0;
}

.search-result-content {
  flex: 1;
  direction: rtl;
}

.search-result-title {
  font-weight: 500;
  color: #ffffff;
  margin-bottom: 2px;
  font-size: 14px;
}

.search-result-category {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.search-result-price {
  font-weight: 600;
  color: #00ff88;
  font-size: 14px;
  margin-right: auto;
}

.search-section-title {
  padding: 10px 16px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

/* Recent chips (mobile-friendly) */
.search-recent { padding: 8px 12px; }
.search-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.search-chip {
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.8);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.search-chip:hover { 
  background: rgba(91, 67, 234, 0.15); 
  border-color: rgba(91, 67, 234, 0.3);
  color: #ffffff;
}

/* Loading State */
.search-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: rgba(255, 255, 255, 0.6);
}

.search-loading svg {
  width: 20px;
  height: 20px;
  animation: spin 1s linear infinite;
  margin-left: 8px;
  fill: currentColor;
}

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

/* Empty State */
.search-empty {
  padding: 20px;
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .search-container {
    max-width: 100%;
  }
  
  .search-results {
    max-height: 300px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .search-wrapper {
    background: #1f2937;
    border-color: #374151;
  }
  
  .search-input {
    color: #f9fafb;
  }
  
  .search-input::placeholder {
    color: #9ca3af;
  }
  
  .search-results {
    background: #1f2937;
    border-color: #374151;
  }
  
  .search-result-item {
    border-bottom-color: #374151;
  }
  
  .search-result-item:hover {
    background: #374151;
  }
  
  .search-result-item.selected {
    background: #1e3a8a;
  }
  
  .search-result-title {
    color: #f9fafb;
  }
  
  .search-clear {
    background: #374151;
    color: #9ca3af;
  }
  
  .search-clear:hover {
    background: #4b5563;
    color: #d1d5db;
  }
}

/* Mobile and Tablet Styles */
@media (max-width: 700px) {
  /* Icon-only by default */
  .header-search { max-width: none; }
  .header-search .search-container { max-width: none; width: auto; }
  .header-search .search-wrapper { 
    border-radius: 10px; 
    width: auto; 
    background: transparent; 
    border-color: transparent; 
    box-shadow: none; 
  }
  .header-search .search-input { display: none; }
  .header-search .search-clear { display: none !important; }
  .search-button { width: 40px; height: 40px; margin: 3px; }
  .header-search .search-clear { width: 26px; height: 26px; margin-right: 2px; }
  .search-input { font-size: 15px; padding: 10px 10px; }
  .search-results { max-height: 70vh; }
  
  /* Widen and center dropdown under input on mobile */
  .header-search .search-results {
    position: fixed;
    left: 50%;
    right: auto;
    top: calc(var(--header-mobile-offset, 64px));
    width: min(96vw, 560px);
    max-width: 96vw;
    margin-top: -7px;
    transform: translate(-50%, -8px);
    z-index: 1100;
  }
  
  .header-search .search-results.visible {
    transform: translate(-50%, 0);
  }
  
  /* Expanded state */
  .header-search.is-open .search-wrapper { 
    position: fixed; 
    left: 50%; 
    top: calc(var(--header-mobile-offset, 64px)); 
    transform: translateX(-50%); 
    width: min(96vw, 560px); 
    background: #393767; 
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 1100;
    border-radius: 12px 12px 0 0;
  }
  
  .header-search.is-open .search-input { display: block; }
  .header-search.is-open .search-clear { display: flex; }
  .header-search.is-open .search-results { top: calc(var(--header-mobile-offset, 64px) + 52px); }
  .search-chip { font-size: 13px; padding: 8px 12px; }
}

/* Real-device mobile override: larger tap target on coarse pointers */
@media (hover: none) and (pointer: coarse) {
  .site-header .header-search .search-button { 
    width: 48px; 
    height: 48px; 
    border-radius: 12px; 
  }
  .site-header .header-search .search-button svg { 
    width: 26px; 
    height: 26px; 
  }
}

/* Tablet and larger */
@media (min-width: 769px) {
  .header-search .search-container {
    min-width: 280px;
  }
}

