/**
 * 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
   ============================================================================ */

.ssai-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 9999;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: none;
  margin-top: 8px;
}

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

/* Category label inside suggestions */
.ssai-category-label {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b7280;
  background-color: #f9fafb;
  margin-top: 0;
  margin-bottom: 4px;
  position: sticky;
  top: 0;
}

.ssai-category-label:first-child {
  margin-top: 0;
}

/* Individual suggestion item */
.ssai-suggestion-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.15s ease;
}

.ssai-suggestion-item:last-child {
  border-bottom: none;
}

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

.ssai-suggestion-item.selected {
  background-color: #eff6ff;
  border-left: 3px solid #2563eb;
  padding-left: 13px;
}

/* Matched text highlighting in suggestion name */
.ssai-suggestion-name strong {
  color: #2563eb;
  font-weight: 600;
}

/* Intent phrase shown in suggestions */
.ssai-suggestion-intent {
  font-style: italic;
  font-size: 14px;
  color: #6b7280;
  margin-top: 4px;
  display: block;
}

/* ============================================================================
   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 {
    max-height: 300px;
  }
}

/* ============================================================================
   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 {
  width: 8px;
}

.ssai-suggestions::-webkit-scrollbar-track {
  background: transparent;
}

.ssai-suggestions::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.ssai-suggestions::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}
