/* Mobile-first search styles */

/* Search container */
#site-search {
  position: relative;
  z-index: 100;
}

/* Search bar - mobile first */
.search-container {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e0e7ff;
  padding: 8px 4px;
  z-index: 50;
}

.search-input-wrapper {
  position: relative;
  max-width: 100%;
}

.search-input {
  width: 100%;
  height: 56px;
  padding: 16px 48px 16px 12px;
  border: 2px solid #e0e7ff;
  border-radius: 8px;
  font-size: 16px;
  background: #ffffff !important;
  color: #1e293b !important;
  outline: none;
  transition: border-color 0.2s ease;
  -webkit-text-fill-color: #1e293b !important;
  -webkit-opacity: 1 !important;
  -webkit-appearance: none;
  appearance: none;
}

/* Placeholder text styling */
.search-input::placeholder {
  color: #64748b !important;
  opacity: 1 !important;
  -webkit-text-fill-color: #64748b !important;
}

.search-input::-webkit-input-placeholder {
  color: #64748b !important;
  opacity: 1 !important;
}

.search-input::-moz-placeholder {
  color: #64748b !important;
  opacity: 1 !important;
}

.search-input:-ms-input-placeholder {
  color: #64748b !important;
  opacity: 1 !important;
}

.search-input:focus {
  border-color: #3b82f6 !important;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2) !important;
  background: #ffffff !important;
  color: #1e293b !important;
  -webkit-text-fill-color: #1e293b !important;
}

/* Mobile-specific focus improvements */
@media (max-width: 767px) {
  .search-container {
    padding: 8px 0;
  }
  
  .search-input {
    padding: 16px 48px 16px 8px;
    font-size: 15px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  
  .search-input:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.3) !important;
  }
}

/* Extra small devices - ensure full placeholder visibility */
@media (max-width: 360px) {
  .search-input {
    font-size: 14px;
  }
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #64748b;
}

.search-clear:hover {
  background: rgba(0, 0, 0, 0.05);
}

.search-input:not(:placeholder-shown) + .search-clear {
  display: flex;
}

/* Mobile suggestions - dropdown below search */
.search-suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff !important;
  border: 2px solid #e0e7ff !important;
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.search-suggestions.active {
  display: block;
}

/* Make search container relative for dropdown positioning */
.search-input-wrapper {
  position: relative;
  max-width: 100%;
  z-index: 10;
}

.search-suggestions-header {
  display: none; /* Remove header for cleaner dropdown */
}

.search-suggestions-close {
  display: none; /* Remove close button - click outside to close */
}

.search-suggestions-list {
  padding: 8px 0;
  max-height: 60vh;
  overflow-y: auto;
}

.search-suggestion {
  display: block;
  padding: 12px 16px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
  border-bottom: 1px solid #f1f5f9;
}

.search-suggestion:hover,
.search-suggestion:focus {
  background: #f8fafc !important;
  outline: none;
}

/* Enhanced mobile contrast */
@media (max-width: 767px) {
  .search-suggestion-title {
    color: #000000 !important;
    font-weight: 700;
  }
  
  .search-suggestion-type {
    color: #1e293b !important;
    font-weight: 600;
  }
  
  .search-suggestion-summary {
    color: #1e293b !important;
    font-weight: 500;
  }
}

.search-suggestion-title {
  font-weight: 600;
  color: #0f172a !important;
  margin-bottom: 4px;
}

.search-suggestion-type {
  font-size: 12px;
  color: #1e293b !important;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  font-weight: 500;
}

.search-suggestion-summary {
  font-size: 14px;
  color: #334155 !important;
  line-height: 1.4;
  font-weight: 400;
}

/* Results container */
.search-results {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  z-index: 1000;
  overflow: hidden;
}

.search-results.active {
  display: flex;
  flex-direction: column;
}

.search-results-header {
  padding: 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

.search-results-back {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  float: left;
  margin-right: 12px;
}

.search-results-back:hover {
  background: rgba(0, 0, 0, 0.05);
}

.search-results-query {
  font-weight: 600;
  color: #1e293b;
  line-height: 44px;
}

.search-results-count {
  font-size: 14px;
  color: #64748b;
  margin-top: 8px;
}

/* Hide chip containers - safeguard rule */
.chip-bar, .chips, #search-chips, .search-facets { 
  display: none !important; 
}

/* Facet chips (hidden by default) */
.search-facets {
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.search-facets::-webkit-scrollbar {
  display: none;
}

.search-facet {
  display: inline-block;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 6px 12px;
  margin-right: 8px;
  font-size: 14px;
  cursor: pointer;
  min-width: 44px;
  text-align: center;
  white-space: nowrap;
}

.search-facet:hover,
.search-facet.active {
  background: #1e40af;
  color: #ffffff;
  border-color: #1e40af;
}

/* Results list */
.search-results-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.search-result-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  transition: box-shadow 0.2s ease;
}

.search-result-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.search-result-title {
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 8px;
  text-decoration: none;
}

.search-result-title:hover {
  color: #1e40af;
}

.search-result-category {
  font-size: 12px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.search-result-summary {
  color: #475569;
  line-height: 1.5;
  margin-bottom: 12px;
}

.search-result-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.search-badge {
  font-size: 11px;
  background: #f1f5f9;
  color: #475569;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.search-badge.nhs { background: #dbeafe; color: #1e40af; }
.search-badge.council { background: #dcfce7; color: #166534; }
.search-badge.local { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.search-badge.free { background: #d1fae5; color: #065f46; }
.search-badge.digital { background: #e0e7ff; color: #3730a3; }
.search-badge.urgent { background: #fecaca; color: #991b1b; }

/* Empty state */
.search-empty {
  text-align: center;
  padding: 40px 16px;
  color: #64748b;
}

.search-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.search-empty-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #374151;
}

.search-empty-message {
  margin-bottom: 24px;
  line-height: 1.5;
}

.search-empty-link {
  color: #1e40af;
  text-decoration: none;
  font-weight: 500;
}

/* Desktop styles */
@media (min-width: 768px) {
  .search-container {
    position: static;
    background: none;
    backdrop-filter: none;
    border: none;
    padding: 0;
    display: flex;
    justify-content: center;
  }

  .search-input-wrapper {
    max-width: 500px;
    width: 100%;
  }

  .search-input {
    height: 48px;
    font-size: 16px;
  }

  /* Desktop dropdown instead of bottom sheet */
  .search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    bottom: auto;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    max-height: 400px;
    overflow-y: auto;
    margin-top: 4px;
  }

  .search-suggestions-header {
    display: none;
  }

  .search-suggestions-list {
    max-height: none;
    padding: 4px 0;
  }

  .search-suggestion {
    padding: 12px 16px;
  }

  /* Desktop results in page */
  .search-results {
    position: static;
    background: none;
    display: block;
    margin-top: 24px;
  }

  .search-results-header {
    background: none;
    border: none;
    padding: 0 0 16px 0;
  }

  .search-results-back {
    display: none;
  }

  .search-facets {
    padding: 16px 0;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    overflow: visible;
    white-space: normal;
  }

  .search-results-list {
    padding: 24px 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Force light mode for search suggestions - ALWAYS readable for healthcare info */
.search-suggestions {
  background: #ffffff !important;
  border-color: #e0e7ff !important;
}

.search-suggestions .search-suggestion {
  background: transparent !important;
}

.search-suggestions .search-suggestion:hover,
.search-suggestions .search-suggestion:focus {
  background: #f8fafc !important;
}

.search-suggestions .search-suggestion-title {
  color: #000000 !important;
  font-weight: 700 !important;
}

.search-suggestions .search-suggestion-type {
  color: #1e293b !important;
  font-weight: 600 !important;
}

.search-suggestions .search-suggestion-summary {
  color: #1e293b !important;
  font-weight: 500 !important;
}

/* Dark mode support for other elements (but NOT search suggestions) */
@media (prefers-color-scheme: dark) {
  .search-container {
    background: rgba(15, 23, 42, 0.95);
    border-color: #334155;
  }

  .search-input {
    background: #1e293b;
    color: #f1f5f9;
    border-color: #475569;
  }

  .search-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  }

  .search-results {
    background: #1e293b;
  }

  .search-results-header {
    background: #0f172a;
    border-color: #334155;
  }

  .search-result-card {
    background: #334155;
    border-color: #475569;
  }

  .search-result-title {
    color: #f1f5f9;
  }

  .search-result-summary {
    color: #cbd5e1;
  }
}

/* Safe area support */
@supports (padding: max(0px)) {
  .search-suggestions,
  .search-results {
    padding-top: max(env(safe-area-inset-top), 0);
    padding-bottom: max(env(safe-area-inset-bottom), 0);
  }
}