/**
 * SmartSearch AI - Search Widget Stylesheet
 *
 * Production-quality, theme-agnostic CSS for the SmartSearch AI widget.
 * Prefix: ssai- (SmartSearch AI)
 *
 * Features:
 * - Clean, semantic markup styling
 * - Full keyboard navigation support
 * - Mobile-responsive (breakpoint: 600px)
 * - Accessibility-compliant focus states
 * - Smooth transitions and animations
 * - Z-index strategy for dropdowns
 */

/* ============================================================================
   BASE RESET & CONTAINER
   ============================================================================ */

.ssai-search-wrapper {
  max-width: 680px;
  margin: 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #1f2937;
  box-sizing: border-box;
}

.ssai-search-wrapper * {
  box-sizing: border-box;
}

/* ============================================================================
   SEARCH ROW: FLEX LAYOUT FOR INPUTS + BUTTON
   ============================================================================ */

.ssai-search-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 16px;
}

/* ============================================================================
   INPUT CONTAINERS & STYLING
   ============================================================================ */

.ssai-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.ssai-search-input,
.ssai-location-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border: 2px solid #d1d5db;
  border-radius: 8px;
  background-color: #ffffff;
  color: #1f2937;
  transition: all 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.ssai-search-input:hover,
.ssai-location-input:hover {
  border-color: #9ca3af;
}

.ssai-search-input:focus,
.ssai-location-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Support for icon in search input */
.ssai-has-icon .ssai-search-input {
  padding-left: 40px;
}

/* Search icon - absolutely positioned */
.ssai-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: #9ca3af;
  pointer-events: none;
  flex-shrink: 0;
}

/* ============================================================================
   SEARCH BUTTON
   ============================================================================ */

.ssai-search-btn {
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 500;
  background-color: #2563eb;
  color: #ffffff;
  border: 2px solid #2563eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  align-self: flex-start;
}

.ssai-search-btn:hover {
  background-color: #1d4ed8;
  border-color: #1d4ed8;
}

.ssai-search-btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.ssai-search-btn:active {
  transform: translateY(1px);
}

/* ============================================================================
   SUGGESTIONS DROPDOWN
   ============================================================================ */

/* Theme override: take full control of .search-results-live when SSAI is active */
.search-results-live.ssai-dropdown-active {
  position: absolute !important;
  top: 100% !important;
  left: 0 !important;
  right: 0 !important;
  background: #ffffff !important;
  padding: 4px 0 !important;
  border-radius: 0 0 8px 8px !important;
  max-height: 380px !important;
  overflow: hidden !important;
  overflow-y: auto !important;
  z-index: 9999 !important;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.06) !important;
  border: 1px solid #dfe1e5 !important;
  border-top: none !important;
  display: none;
}

.search-results-live.ssai-dropdown-active.visible {
  display: block !important;
}

/* Plugin shortcode mode */
.ssai-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: #ffffff;
  border: 1px solid #dfe1e5;
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 380px;
  overflow-y: auto;
  z-index: 9999;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.06);
  display: none;
  margin-top: 0;
  padding: 4px 0;
}

.ssai-suggestions.visible {
  display: block;
}

/* Individual suggestion item — Google-style compact row */
.ssai-suggestion-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background-color 0.08s ease;
}

.ssai-suggestion-item:hover {
  background-color: #f1f3f4;
}

.ssai-suggestion-item.selected {
  background-color: #f1f3f4;
}

/* Search icon in suggestion row */
.ssai-sg-icon {
  width: 16px;
  height: 16px;
  color: #9aa0a6;
  flex-shrink: 0;
}

/* Text wrapper — name + context on one line */
.ssai-sg-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  line-height: 1.4;
  color: #202124;
}

.ssai-sg-name {
  font-weight: 400;
}

.ssai-sg-name strong {
  font-weight: 700;
  color: #202124;
}

.ssai-sg-context {
  color: #70757a;
  font-size: 13px;
}

/* ============================================================================
   RESULTS CONTAINER
   ============================================================================ */

.ssai-results {
  margin-top: 32px;
}

/* ============================================================================
   LOADING STATE
   ============================================================================ */

.ssai-loading {
  text-align: center;
  padding: 48px 16px;
  color: #6b7280;
}

.ssai-loading::before {
  content: '';
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: ssai-spin 0.8s linear infinite;
  margin-bottom: 16px;
  margin-right: 12px;
  vertical-align: middle;
}

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

/* ============================================================================
   INTERPRETED / INTENT BANNER
   ============================================================================ */

.ssai-interpreted {
  background-color: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
  color: #1e40af;
  font-size: 14px;
  line-height: 1.6;
}

/* ============================================================================
   MATCHED SERVICES
   ============================================================================ */

.ssai-matched-services {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.ssai-service-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  background-color: #dbeafe;
  color: #1e40af;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

/* ============================================================================
   POSTS / RESULTS GRID
   ============================================================================ */

.ssai-posts {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Individual post card */
.ssai-post-item {
  display: flex;
  gap: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  background-color: #ffffff;
  transition: all 0.2s ease;
}

.ssai-post-item:hover {
  border-color: #2563eb;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

/* Post thumbnail */
.ssai-post-item img {
  width: 140px;
  height: 140px;
  object-fit: cover;
  flex-shrink: 0;
}

/* Post content wrapper */
.ssai-post-item > div {
  padding: 12px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

/* Post title */
.ssai-post-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  text-decoration: none;
  display: block;
  margin-bottom: 8px;
  transition: color 0.2s ease;
  line-height: 1.4;
}

.ssai-post-title:hover {
  color: #2563eb;
  text-decoration: underline;
}

/* Post excerpt */
.ssai-post-excerpt {
  font-size: 14px;
  color: #6b7280;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
}

/* ============================================================================
   POWERED BY
   ============================================================================ */

.ssai-powered-by {
  text-align: center;
  margin-top: 24px;
  font-size: 12px;
  color: #9ca3af;
  font-style: italic;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 600px) {
  .ssai-search-row {
    flex-direction: column;
    gap: 10px;
  }

  .ssai-input-wrap {
    min-width: 100%;
  }

  .ssai-search-btn {
    width: 100%;
    align-self: stretch;
  }

  .ssai-search-input,
  .ssai-location-input {
    font-size: 16px; /* prevents mobile zoom on focus */
  }

  .ssai-post-item {
    flex-direction: column;
  }

  .ssai-post-item img {
    width: 100%;
    height: 200px;
  }

  .ssai-post-item > div {
    padding: 12px;
  }

  .ssai-suggestions,
  .search-results-live.ssai-dropdown-active {
    max-height: 300px !important;
  }
}

/* ============================================================================
   UTILITY & HIDDEN STATES
   ============================================================================ */

.ssai-hidden {
  display: none !important;
}

.ssai-no-results {
  text-align: center;
  padding: 40px 16px;
  color: #6b7280;
}

/* ============================================================================
   SCROLLBAR STYLING (WEBKIT BROWSERS)
   ============================================================================ */

.ssai-suggestions::-webkit-scrollbar,
.search-results-live.ssai-dropdown-active::-webkit-scrollbar {
  width: 6px;
}

.ssai-suggestions::-webkit-scrollbar-track,
.search-results-live.ssai-dropdown-active::-webkit-scrollbar-track {
  background: transparent;
}

.ssai-suggestions::-webkit-scrollbar-thumb,
.search-results-live.ssai-dropdown-active::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 3px;
}

.ssai-suggestions::-webkit-scrollbar-thumb:hover,
.search-results-live.ssai-dropdown-active::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

/* ============================================================================
   CLICKABLE SERVICE CHIPS (USED IN BANNERS & RESULTS)
   ============================================================================ */

.ssai-chip-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
}

.ssai-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: #2563eb;
  background-color: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.ssai-chip:hover {
  background-color: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}

/* ============================================================================
   "DID YOU MEAN?" — NOT USED IN DROPDOWN ANYMORE (kept for results banners)
   ============================================================================ */

.ssai-did-you-mean {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background-color: #fffbeb;
  border-bottom: 1px solid #fde68a;
}

.ssai-dym-label {
  font-size: 13px;
  font-weight: 600;
  color: #92400e;
  margin-right: 4px;
}

.ssai-did-you-mean .ssai-chip {
  background-color: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}

.ssai-did-you-mean .ssai-chip:hover {
  background-color: #f59e0b;
  color: #ffffff;
  border-color: #f59e0b;
}

/* ============================================================================
   QUERY → MATCH BANNER (RESULTS VIEW)
   ============================================================================ */

.ssai-query-banner {
  background-color: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}

.ssai-query-banner .ssai-chip-bar {
  padding: 8px 0 0 0;
}

.ssai-banner-query {
  font-size: 14px;
  color: #334155;
  line-height: 1.5;
}

.ssai-banner-query strong {
  color: #0f172a;
}

/* ============================================================================
   SEARCH PAGE BANNER (INJECTED ON search.php)
   ============================================================================ */

.ssai-page-banner {
  background-color: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
}

.ssai-page-banner .ssai-chip-bar {
  padding: 8px 0 0 0;
}

.ssai-page-banner .ssai-banner-query {
  font-size: 15px;
}

/* ============================================================================
   EMPTY STATE WITH EXAMPLE QUERIES
   ============================================================================ */

.ssai-empty-help {
  padding: 0;
}

.ssai-empty-title {
  padding: 10px 16px 2px;
  font-size: 13px;
  font-weight: 400;
  color: #70757a;
}

.ssai-empty-subtitle {
  padding: 0 16px 6px;
  font-size: 13px;
  color: #9aa0a6;
}

/* Example row — matches suggestion row style exactly */
.ssai-example-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background-color 0.08s ease;
  text-decoration: none;
  color: #202124;
  font-size: 15px;
}

.ssai-example-row:hover {
  background-color: #f1f3f4;
  text-decoration: none;
  color: #202124;
}

.ssai-example-row .ssai-sg-icon {
  color: #9aa0a6;
}

.ssai-example-row .ssai-sg-name {
  font-weight: 400;
  color: #5f6368;
  font-style: italic;
}

/* Legacy chip-based example links (kept for results page) */
.ssai-example-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.ssai-example-link {
  display: inline-block;
  padding: 6px 14px;
  font-size: 13px;
  color: #2563eb;
  background-color: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  text-decoration: none;
  transition: all 0.15s ease;
  cursor: pointer;
}

.ssai-example-link:hover {
  background-color: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}

/* ============================================================================
   RESPONSIVE ADDITIONS
   ============================================================================ */

@media (max-width: 600px) {
  .ssai-chip-bar {
    gap: 6px;
    padding: 8px 12px;
  }

  .ssai-chip {
    font-size: 12px;
    padding: 5px 10px;
  }

  .ssai-page-banner {
    margin: 0 -12px 16px;
    border-radius: 0;
  }

  .ssai-example-list {
    gap: 6px;
  }
}
