/* ============================================================
   AI Search — text + voice input + AI-ranked results
   ============================================================ */

.ai-search-wrap {
  max-width: 720px;
  margin: 32px auto 0;
  padding: 0 20px;
}

/* Sparkle label above the search */
.ai-search-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #F59C0D;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.ai-search-label .sparkle { animation: aiPulse 2.5s ease-in-out infinite; display: inline-block; }
@keyframes aiPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.15); opacity: 0.75; }
}

/* Main search box */
.ai-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 2px solid #e2e8f0;
  border-radius: 50px;
  padding: 8px 8px 8px 22px;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  transition: all 0.2s;
  position: relative;
}
.ai-search-box:focus-within {
  border-color: #F59C0D;
  box-shadow: 0 6px 30px rgba(245, 156, 13, 0.18);
}
.ai-search-box.thinking {
  border-color: #F59C0D;
}
.ai-search-box.thinking::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50px;
  padding: 2px;
  background: linear-gradient(90deg, #F59C0D, #f1f5f9, #F59C0D);
  background-size: 200% 100%;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  animation: aiShimmer 1.4s linear infinite;
  pointer-events: none;
}
@keyframes aiShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ai-search-icon { color: #94a3b8; font-size: 1.05rem; flex-shrink: 0; }
.ai-search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.96rem;
  font-family: inherit;
  color: #1e293b;
  background: transparent;
  padding: 8px 0;
}
.ai-search-input::placeholder { color: #94a3b8; }

/* Voice button */
.ai-mic-btn {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.15s;
  flex-shrink: 0;
}
.ai-mic-btn:hover { background: #fff7ed; border-color: #F59C0D; }
.ai-mic-btn.listening {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  animation: micPulse 1s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  50%      { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* Search button */
.ai-search-btn {
  background: #F59C0D;
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 0 18px;
  height: 38px;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
  flex-shrink: 0;
  letter-spacing: 0.2px;
}
.ai-search-btn:hover { background: #D4860A; }
.ai-search-btn:disabled { opacity: 0.6; cursor: not-allowed; }
@media (max-width: 520px) {
  .ai-search-btn-text { display: none; }
  .ai-search-btn { padding: 0 14px; }
}

/* Voice transcript indicator */
.voice-listening {
  text-align: center;
  margin-top: 12px;
  font-size: 0.82rem;
  color: #ef4444;
  font-weight: 600;
  display: none;
}
.voice-listening.visible { display: block; }
.voice-listening .dots::after {
  content: '';
  display: inline-block;
  animation: voiceDots 1.4s steps(4, end) infinite;
}
@keyframes voiceDots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* AI Results Section */
.ai-results { max-width: 900px; margin: 24px auto 0; padding: 0 20px; }
.ai-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}
.ai-results-title { font-size: 1.05rem; font-weight: 800; color: #162447; display: flex; align-items: center; gap: 8px; }
.ai-results-title .ai-badge {
  background: linear-gradient(135deg, #F59C0D, #ea6c00);
  color: #fff;
  font-size: 0.65rem;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  font-weight: 800;
  text-transform: uppercase;
}
.ai-results-query { font-size: 0.85rem; color: #64748b; font-style: italic; }
.ai-clear-btn {
  background: none;
  border: 1px solid #e2e8f0;
  color: #64748b;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.15s;
}
.ai-clear-btn:hover { border-color: #F59C0D; color: #F59C0D; }

/* AI Direct Answer card (Perplexity-style) */
.ai-answer {
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  border: 1.5px solid #fed7aa;
  border-radius: 14px;
  padding: 18px 22px 20px;
  margin-bottom: 22px;
  position: relative;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
html.dark .ai-answer {
  background: linear-gradient(135deg, rgba(245,156,13,0.10), rgba(245,156,13,0.04));
  border-color: rgba(245,156,13,0.30);
}
.ai-answer-avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #F59C0D, #ea6c00);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(245,156,13,0.30);
}
.ai-answer-body { flex: 1; min-width: 0; }
.ai-answer-label {
  font-size: 0.65rem;
  font-weight: 800;
  color: #9a3412;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
html.dark .ai-answer-label { color: #fb923c; }
.ai-answer-text {
  font-size: 0.95rem;
  color: #1e293b;
  line-height: 1.6;
  margin: 0;
  font-weight: 500;
}
html.dark .ai-answer-text { color: #f1f5f9; }

/* Typewriter cursor for streaming feel */
.ai-answer-text.typing::after {
  content: '▍';
  color: #F59C0D;
  margin-left: 2px;
  animation: blink 0.9s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* AI Result Cards */
.ai-result {
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 14px;
  padding: 18px 22px;
  margin-bottom: 14px;
  display: flex;
  gap: 16px;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.ai-result::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, #F59C0D, #ea6c00);
}
.ai-result:hover { transform: translateX(2px); box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08); border-color: #F59C0D; }

.ai-result-emoji {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #162447, #1E3A6E);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  flex-shrink: 0;
}

.ai-result-body { flex: 1; min-width: 0; }
.ai-result-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.ai-result-type-blog { background: #dbeafe; color: #1e40af; font-size: 0.62rem; font-weight: 800; padding: 2px 9px; border-radius: 4px; letter-spacing: 0.5px; text-transform: uppercase; }
.ai-result-type-tutorial { background: #dcfce7; color: #166534; font-size: 0.62rem; font-weight: 800; padding: 2px 9px; border-radius: 4px; letter-spacing: 0.5px; text-transform: uppercase; }
.ai-result-cat { font-size: 0.7rem; font-weight: 700; color: #F59C0D; text-transform: uppercase; letter-spacing: 0.4px; }
.ai-result-extra { font-size: 0.7rem; color: #94a3b8; }

.ai-result h3 {
  font-size: 1rem;
  font-weight: 800;
  color: #162447;
  margin: 0 0 6px;
  line-height: 1.35;
}
.ai-result-reason {
  font-size: 0.84rem;
  color: #475569;
  line-height: 1.55;
  margin: 0;
  padding-left: 24px;
  position: relative;
}
.ai-result-reason::before {
  content: '✨';
  position: absolute;
  left: 0;
  top: 0;
  font-size: 0.85rem;
}

/* Loading state */
.ai-loading {
  text-align: center;
  padding: 40px 20px;
  color: #64748b;
}
.ai-loading .spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 3px solid #fff4dc;
  border-top-color: #F59C0D;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ai-loading-text { font-size: 0.9rem; font-weight: 600; color: #475569; }
.ai-loading-sub { font-size: 0.78rem; color: #94a3b8; margin-top: 4px; }

/* Empty / Error */
.ai-empty {
  text-align: center;
  padding: 50px 20px;
}
.ai-empty .icon { font-size: 2.4rem; margin-bottom: 10px; }
.ai-empty h3 { font-size: 1.1rem; color: #162447; font-weight: 800; margin: 0 0 6px; }
.ai-empty p { font-size: 0.85rem; color: #64748b; }

/* Dark mode */
html.dark .ai-search-box { background: #1e293b; border-color: #334155; }
html.dark .ai-search-input { color: #f1f5f9; }
html.dark .ai-search-input::placeholder { color: #475569; }
html.dark .ai-mic-btn { background: #0f172a; border-color: #334155; color: #94a3b8; }
html.dark .ai-mic-btn:hover { background: #1e293b; }
html.dark .ai-results-title { color: #f1f5f9; }
html.dark .ai-result { background: #1e293b; border-color: #334155; }
html.dark .ai-result h3 { color: #f1f5f9; }
html.dark .ai-result-reason { color: #cbd5e1; }
html.dark .ai-loading-text { color: #cbd5e1; }
html.dark .ai-clear-btn { background: #1e293b; border-color: #334155; color: #94a3b8; }
html.dark .ai-empty h3 { color: #f1f5f9; }
