/* ============================================
   AJAX Dropdown Search - QIANMIAO Theme
   支持SKU搜索 / 下拉式卡片展示 / 响应式
   v2.1 - 下拉式优化版本
   ============================================ */

/* Search Container - Header中的搜索区域 */
.noke-search-container {
  position: relative;
  display: flex;
  align-items: center;
}

/* Search Toggle Button - 搜索图标按钮 */
.noke-search-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.2s ease;
}

.noke-search-toggle:hover {
  color: var(--primary);
}

.noke-search-toggle svg {
  width: 22px;
  height: 22px;
}

/* ============================================
   下拉搜索面板
   ============================================ */
.noke-search-dropdown {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--white);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* 搜索面板内容 */
.noke-search-dropdown-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
}

/* 搜索头部 - 包含输入框和关闭按钮 */
.noke-search-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 0;
}

/* 搜索输入框容器 */
.noke-search-input-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.noke-search-input-box svg.search-icon {
  position: absolute;
  left: 16px;
  width: 20px;
  height: 20px;
  color: var(--gray-400);
  pointer-events: none;
}

.noke-search-input {
  width: 100%;
  height: 50px;
  padding: 0 16px 0 48px;
  font-family: var(--font-primary);
  font-size: 16px;
  color: var(--text-primary);
  background: var(--gray-50);
  border: 2px solid transparent;
  border-radius: 10px;
  outline: none;
  transition: all 0.25s ease;
}

.noke-search-input:focus {
  background: var(--white);
  border-color: var(--primary);
}

.noke-search-input::placeholder {
  color: var(--gray-400);
}

/* 隐藏浏览器自带的搜索清除按钮 */
.noke-search-input::-webkit-search-cancel-button,
.noke-search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

/* Close Button - 只有一个 */
.noke-search-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: var(--gray-100);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: var(--gray-600);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.noke-search-close:hover {
  background: var(--gray-200);
  color: var(--gray-900);
}

.noke-search-close svg {
  width: 20px;
  height: 20px;
}

/* 搜索提示标签 */
.noke-search-hints {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--gray-100);
}

.noke-search-hint-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 6px;
}

.noke-search-hint-tag svg {
  width: 14px;
  height: 14px;
  color: var(--primary);
}

/* Results Body - 只显示需要的高度 */
.noke-search-body {
  max-height: 100vh;
  overflow-y: auto;
  padding: 16px 0;
  overscroll-behavior: contain;
}

.noke-search-body::-webkit-scrollbar {
  width: 6px;
}

.noke-search-body::-webkit-scrollbar-track {
  background: transparent;
}

.noke-search-body::-webkit-scrollbar-thumb {
  background: var(--gray-200);
  border-radius: 3px;
}

/* 隐藏body内容时 */
.noke-search-body:empty,
.noke-search-body-hidden {
  display: none;
}

/* Tabs bar */
.noke-search-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}

.noke-search-tabs {
  display: flex;
  gap: 4px;
}

.noke-search-tab {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.noke-search-tab:hover {
  background: var(--gray-100);
}

.noke-search-tab.active {
  color: var(--white);
  background: var(--primary);
}

.noke-search-tab .count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  margin-left: 5px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 10px;
}

.noke-search-tab.active .count {
  background: rgba(255, 255, 255, 0.25);
}

.noke-search-view-all {
  font-size: 13px;
  font-weight: 500;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.2s;
}

.noke-search-view-all:hover {
  opacity: 0.8;
}

.noke-search-view-all svg {
  width: 16px;
  height: 16px;
}

/* Section */
.noke-search-section {
  margin-bottom: 20px;
}

.noke-search-section:last-child {
  margin-bottom: 0;
}

.noke-search-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.noke-search-section-title svg {
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

/* Products Grid */
.noke-search-products-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

/* Product Card */
.noke-search-product {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: inherit;
}

.noke-search-product:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.noke-search-product-image {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  background: var(--gray-50);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.noke-search-product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.noke-search-product-image svg {
  width: 24px;
  height: 24px;
  color: var(--gray-300);
}

.noke-search-product-info {
  flex: 1;
  min-width: 0;
}

.noke-search-product-category {
  display: inline-block;
  padding: 2px 8px;
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 4px;
}

.noke-search-product-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.noke-search-product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.noke-search-product-sku {
  display: flex;
  align-items: center;
  gap: 3px;
}

.noke-search-product-sku-label {
  font-weight: 600 !important;
  font-size: 11px !important;
  color: var(--text-secondary) !important;
}

.noke-search-product-sku-value {
  color: var(--primary) !important;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace !important;
  font-size: 11px !important;
}

/* Highlight matched text */
.noke-search-highlight {
  background: linear-gradient(120deg, rgba(28, 158, 145, 0.2) 0%, rgba(28, 158, 145, 0.35) 100%);
  color: var(--primary-dark);
  padding: 1px 2px;
  border-radius: 2px;
  font-weight: 600;
}

/* Articles Grid */
.noke-search-articles-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

/* Article Card */
.noke-search-article {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: inherit;
}

.noke-search-article:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.noke-search-article-image {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  background: var(--gray-50);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.noke-search-article-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.noke-search-article-image svg {
  width: 20px;
  height: 20px;
  color: var(--gray-300);
}

.noke-search-article-info {
  flex: 1;
  min-width: 0;
}

.noke-search-article-tag {
  display: inline-block;
  padding: 2px 6px;
  margin-bottom: 3px;
  font-size: 10px;
  font-weight: 600;
  color: #7c3aed;
  background: rgba(124, 58, 237, 0.1);
  border-radius: 3px;
}

.noke-search-article-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.noke-search-article-date {
  font-size: 11px;
  color: var(--text-muted);
}

/* Loading State */
.noke-search-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.noke-search-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-100);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: noke-spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes noke-spin {
  to { transform: rotate(360deg); }
}

/* Empty State */
.noke-search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.noke-search-empty svg {
  width: 48px;
  height: 48px;
  color: var(--gray-300);
  margin-bottom: 16px;
}

.noke-search-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.noke-search-empty-text {
  font-size: 13px;
  color: var(--text-muted);
}

/* Overlay - 点击关闭 */
.noke-search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9998;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.noke-search-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* ============================================
   Mobile Styles
   ============================================ */
@media (max-width: 768px) {
  .noke-search-dropdown-inner {
    padding: 0 16px;
  }
  
  .noke-search-header {
    padding: 16px 0;
    gap: 12px;
  }
  
  .noke-search-input {
    height: 46px;
    font-size: 16px; /* Prevent iOS zoom */
    padding: 0 14px 0 44px;
  }
  
  .noke-search-input-box svg.search-icon {
    left: 14px;
    width: 18px;
    height: 18px;
  }
  
  .noke-search-close {
    width: 38px;
    height: 38px;
  }
  
  .noke-search-hints {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 0 12px;
    justify-content: center;
  }
  
  .noke-search-tabs-bar {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
  }
  
  .noke-search-tabs {
    flex: 1;
    overflow-x: auto;
    flex-wrap: nowrap;
    min-width: 0;
  }
  
  .noke-search-tab {
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
  }
  
  .noke-search-products-grid,
  .noke-search-articles-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .noke-search-product,
  .noke-search-article {
    padding: 10px;
  }
  
  .noke-search-product-image {
    width: 56px;
    height: 56px;
  }
  
  .noke-search-body {
    max-height: 50vh;
  }
}

/* Very Small Screens */
@media (max-width: 480px) {
  .noke-search-hint-tag {
    padding: 4px 8px;
    font-size: 11px;
  }
  
  .noke-search-product-title,
  .noke-search-article-title {
    font-size: 12px;
  }
}

/* Focus visible for accessibility */
.noke-search-toggle:focus-visible,
.noke-search-tab:focus-visible,
.noke-search-product:focus-visible,
.noke-search-article:focus-visible,
.noke-search-close:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Body scroll lock when search is open */
body.noke-search-open {
  overflow: hidden;
}
