/* ═════════════════════════════════════════════════════════════════════════
   AI Smart Search — ChatGPT-inspired prompt box
   Pure CSS (no Tailwind). Replicates the rounded-[28px] shadcn look:
   - soft white pill with subtle border + shadow
   - auto-growing textarea
   - icon buttons on the left row, send button on the right
   - dark mode via prefers-color-scheme
   ════════════════════════════════════════════════════════════════════════ */

.ai-search-wrap {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  direction: rtl;
  font-family: inherit;
}

.ai-search-header {
  text-align: center;
  margin-bottom: 20px;
}

/* Beta + responsibility notice shown under the prompt box.
   Matches the .ai-disclaimer design on article/tool/course pages
   (soft lavender gradient + blue pill icon + right accent). */
.ai-disclaimer {
  background: linear-gradient(135deg, #f7f9ff 0%, #fdfdff 100%);
  border: 1px solid #e4e8f4;
  border-right: 3px solid #195cff;
  border-radius: 14px;
  padding: 14px 18px;
  margin: 20px 0 0;
  font-size: 0.84rem;
  line-height: 1.65;
  color: #4a5378;
  display: flex;
  gap: 14px;
  align-items: center;
  box-shadow: 0 1px 3px rgba(25, 92, 255, 0.04);
}
.ai-disclaimer-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #eaf0ff;
  color: #195cff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.ai-disclaimer-body {
  flex: 1;
  min-width: 0;
}
.ai-disclaimer-body p {
  margin: 0;
}
.ai-disclaimer-body p + p {
  margin-top: 4px;
  color: #7b84a1;
  font-size: 0.78rem;
  line-height: 1.55;
}
.ai-disclaimer-body strong {
  color: #1a2540;
  font-weight: 700;
}
@media (max-width: 600px) {
  .ai-disclaimer {
    padding: 12px 14px;
    font-size: 0.78rem;
    gap: 10px;
  }
  .ai-disclaimer-icon {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
  }
}
.ai-search-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--dark, #1a1a2e);
  margin: 0 0 8px;
  line-height: 1.3;
}
.ai-search-header h2 .ai-gradient {
  background: linear-gradient(135deg, #195cff 0%, #7b61ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.ai-search-header p {
  font-size: 0.95rem;
  color: var(--gray, #6a6a6a);
  margin: 0;
}

/* ── Prompt box (the pill itself) ─────────────────────────────────────── */
.ai-prompt-box {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 28px;
  padding: 10px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.02),
    0 2px 10px rgba(0, 0, 0, 0.04),
    0 10px 30px rgba(25, 92, 255, 0.06);
  transition:
    box-shadow 0.2s,
    border-color 0.2s;
  cursor: text;
}
.ai-prompt-box:focus-within {
  border-color: #195cff;
  box-shadow:
    0 0 0 3px rgba(25, 92, 255, 0.12),
    0 10px 30px rgba(25, 92, 255, 0.1);
}

.ai-prompt-textarea {
  width: 100%;
  min-height: 48px;
  max-height: 200px;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  padding: 12px 14px 6px;
  font-family: inherit;
  font-size: 1rem;
  color: #111827;
  line-height: 1.5;
  direction: rtl;
}
.ai-prompt-textarea::placeholder {
  color: #9ca3af;
  transition: opacity 0.22s ease;
}
.ai-prompt-textarea.ai-placeholder-fade::placeholder {
  opacity: 0;
}
.ai-prompt-textarea:focus-visible {
  outline: none;
}

/* Custom scrollbar — matches the shared sidebar scrollbar in
   css/article-styles.css so the AI search textarea feels visually
   consistent with /article, /tool, /course sidebars. */
.ai-prompt-textarea {
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 23, 42, 0.18) transparent;
}
.ai-prompt-textarea::-webkit-scrollbar {
  width: 6px;
}
.ai-prompt-textarea::-webkit-scrollbar-track {
  background: transparent;
}
.ai-prompt-textarea::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.18);
  border-radius: 999px;
}
.ai-prompt-textarea:hover::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.32);
}

/* ── Bottom action row ────────────────────────────────────────────────── */
.ai-prompt-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 0;
}

.ai-icon-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: #374151;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
  font-family: inherit;
}
.ai-icon-btn:hover {
  background: #f3f4f6;
  color: #111827;
}
.ai-icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.ai-icon-btn svg {
  width: 22px;
  height: 22px;
}

.ai-prompt-spacer {
  flex: 1;
}

/* Pill label button (like "Tools" in ChatGPT) */
.ai-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #374151;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.ai-pill-btn:hover {
  background: #f3f4f6;
}
.ai-pill-btn svg {
  width: 16px;
  height: 16px;
}

/* Clear (X) button — appears in the actions row when textarea has text */
.ai-clear-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #6b7280;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  padding: 0;
  transition:
    background 0.15s,
    color 0.15s;
}
.ai-clear-btn:hover {
  background: #f3f4f6;
  color: #111827;
}
.ai-clear-btn:focus-visible {
  outline: 2px solid #111827;
  outline-offset: 2px;
}
.ai-clear-btn[hidden] {
  display: none;
}
.ai-clear-btn svg {
  width: 16px;
  height: 16px;
}

/* Send button — the dark primary action */
.ai-send-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #111827;
  color: #ffffff;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s,
    opacity 0.15s;
  font-family: inherit;
}
.ai-send-btn:hover:not(:disabled) {
  background: #000000;
  transform: translateY(-1px);
}
.ai-send-btn:active:not(:disabled) {
  transform: translateY(0);
}
.ai-send-btn:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}
.ai-send-btn svg {
  width: 20px;
  height: 20px;
}

/* ── Example prompts below the box ────────────────────────────────────── */
.ai-examples {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.ai-example-chip {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.82rem;
  color: #4b5563;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.ai-example-chip:hover {
  border-color: #195cff;
  color: #195cff;
  background: #f0f5ff;
  transform: translateY(-1px);
}

/* ── Loading + response area ──────────────────────────────────────────── */
.ai-response-area {
  margin-top: 24px;
  min-height: 0;
}

.ai-thinking {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  color: #6b7280;
  font-size: 0.92rem;
}
.ai-thinking-dots {
  display: inline-flex;
  gap: 4px;
}
.ai-thinking-dots span {
  width: 7px;
  height: 7px;
  background: #195cff;
  border-radius: 50%;
  animation: aiDot 1.2s infinite ease-in-out;
}
.ai-thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.ai-thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes aiDot {
  0%,
  60%,
  100% {
    transform: scale(0.7);
    opacity: 0.4;
  }
  30% {
    transform: scale(1.1);
    opacity: 1;
  }
}

.ai-response {
  background: linear-gradient(135deg, #f3f6ff 0%, #ffffff 60%);
  border: 1px solid #dbe4ff;
  border-right: 4px solid #195cff;
  border-radius: 16px;
  padding: 20px 24px;
  animation: aiFadeIn 0.35s ease-out;
}
.ai-response-label {
  font-size: 0.78rem;
  font-weight: 800;
  color: #195cff;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-response-text {
  font-size: 1rem;
  line-height: 1.7;
  color: #1a1a2e;
  margin: 0 0 18px;
}

.ai-response-matches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.ai-match-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s;
  cursor: pointer;
}
.ai-match-card:hover {
  border-color: #195cff;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(25, 92, 255, 0.12);
}
.ai-match-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-match-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #f3f4f6 center/70% no-repeat;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
}
.ai-match-name {
  font-weight: 700;
  color: #111827;
  font-size: 0.95rem;
}
.ai-match-company {
  font-size: 0.75rem;
  color: #9ca3af;
}
.ai-match-desc {
  font-size: 0.82rem;
  color: #6b7280;
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.ai-match-cta {
  margin-top: auto;
  padding-top: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #195cff;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-match-card-headline {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ai-match-logo-emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: #fff;
}
.ai-match-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #fff;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.68rem;
  font-weight: 700;
  margin-top: 3px;
  width: fit-content;
}

/* ── "Has guide" badge on top of tool cards ───────────────────────── */
.ai-match-card-recommended {
  border-color: #fbbf24;
  background: linear-gradient(135deg, #fffbeb 0%, #ffffff 40%);
}
.ai-match-guide-pill {
  position: absolute;
  top: -10px;
  right: 12px;
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  box-shadow: 0 3px 8px rgba(251, 191, 36, 0.35);
  white-space: nowrap;
  z-index: 2;
}
.ai-match-coupon-pill {
  position: absolute;
  top: -10px;
  right: 12px;
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  box-shadow: 0 3px 8px rgba(16, 185, 129, 0.35);
  white-space: nowrap;
  z-index: 2;
}
.ai-match-card {
  position: relative;
}

/* ── Show-more button ─────────────────────────────────────────────── */
.ai-show-more-btn {
  display: block;
  margin: 18px auto 6px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  padding: 10px 24px;
  font-size: 0.88rem;
  font-weight: 700;
  color: #195cff;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.ai-show-more-btn:hover {
  background: #f0f5ff;
  border-color: #195cff;
  transform: translateY(-1px);
}

.ai-extra-matches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 14px;
  animation: aiFadeIn 0.3s ease-out;
}

/* ── Filter popover (opens from the סינון button) ─────────────────── */
.ai-filter-wrap {
  position: relative;
}
.ai-filter-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  z-index: 50;
  animation: aiFadeIn 0.18s ease-out;
}
.ai-filter-popover[hidden] {
  display: none;
}
.ai-filter-popover-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #6b7280;
  padding: 4px 8px 8px;
  border-bottom: 1px solid #f3f4f6;
  margin-bottom: 6px;
}
.ai-filter-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  font-size: 0.9rem;
  color: #111827;
}
.ai-filter-option:hover {
  background: #f9fafb;
}
.ai-filter-option input[type='checkbox'] {
  margin: 0;
  width: 16px;
  height: 16px;
  accent-color: #195cff;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .ai-show-more-btn {
    background: #2a2a2a;
    border-color: #3f3f46;
    color: #93c5fd;
  }
  .ai-show-more-btn:hover {
    background: #1e3a8a;
    border-color: #60a5fa;
  }
  .ai-match-card-recommended {
    background: linear-gradient(135deg, #78350f 0%, #27272a 40%);
    border-color: #f59e0b;
  }
  .ai-filter-popover {
    background: #27272a;
    border-color: #3f3f46;
  }
  .ai-filter-option {
    color: #f3f4f6;
  }
  .ai-filter-option:hover {
    background: #3f3f46;
  }
  .ai-filter-popover-title {
    color: #a1a1aa;
    border-color: #3f3f46;
  }
}

.ai-response-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-right: 4px solid #ef4444;
  border-radius: 12px;
  padding: 14px 18px;
  color: #991b1b;
  font-size: 0.9rem;
  animation: aiFadeIn 0.25s ease-out;
}

@keyframes aiFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Login prompt (when user is not authenticated) ────────────────────── */
.ai-login-hint {
  margin-top: 16px;
  padding: 14px 18px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-right: 4px solid #f59e0b;
  border-radius: 12px;
  color: #78350f;
  font-size: 0.88rem;
  text-align: center;
}
.ai-login-hint a {
  color: #92400e;
  font-weight: 700;
  text-decoration: underline;
}

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .ai-prompt-box {
    border-radius: 24px;
  }
  .ai-prompt-textarea {
    font-size: 0.95rem;
    padding: 10px 12px 4px;
  }
  .ai-send-btn,
  .ai-icon-btn {
    width: 32px;
    height: 32px;
  }
  .ai-example-chip {
    font-size: 0.78rem;
    padding: 6px 12px;
  }
}

/* ── Dark mode (respects OS preference) ───────────────────────────────── */
@media (prefers-color-scheme: dark) {
  .ai-prompt-box {
    background: #2a2a2a;
    border-color: #3f3f46;
  }
  .ai-prompt-textarea {
    color: #f3f4f6;
  }
  .ai-prompt-textarea::placeholder {
    color: #71717a;
  }
  .ai-icon-btn {
    color: #d4d4d8;
  }
  .ai-icon-btn:hover {
    background: #3f3f46;
    color: #fff;
  }
  .ai-pill-btn {
    color: #d4d4d8;
  }
  .ai-pill-btn:hover {
    background: #3f3f46;
  }
  .ai-send-btn {
    background: #f4f4f5;
    color: #18181b;
  }
  .ai-send-btn:hover:not(:disabled) {
    background: #fff;
  }
  .ai-example-chip {
    background: #2a2a2a;
    border-color: #3f3f46;
    color: #d4d4d8;
  }
  .ai-response {
    background: linear-gradient(135deg, #1e2333 0%, #151827 60%);
    border-color: #27374d;
  }
  .ai-response-text {
    color: #e5e7eb;
  }
  .ai-match-card {
    background: #27272a;
    border-color: #3f3f46;
  }
  .ai-match-name {
    color: #fafafa;
  }
  .ai-match-desc {
    color: #a1a1aa;
  }
}
