/**
 * Unified Search Styles
 * Consolidated styles for all search components across the site
 * 
 * @package LeanPress
 */

/* Base search component */
.search-component {
  position: relative;
  display: flex;
  align-items: center;
}

/* Search form */
.search-form {
  display: flex;
  align-items: center;
  height: 100%;
  width: 100%;
}

/* Base search input styling */
.search-input {
  box-sizing: border-box;
  height: 44px; /* Increased from 2.45rem for better touch target */
  padding: 0.5rem 44px 0.5rem 1.2rem; /* Right padding matches button width */
  border: 1px solid var(--c-border);
  border-radius: 0.5rem;
  background-color: var(--c-bg);
  color: var(--c-fg);
  font-size: 1rem;
  width: 100%;
  transition: all 0.3s ease;
  line-height: 1.2;
  min-height: 44px; /* Ensures minimum touch target height */
}

.search-input:focus {
  outline: none;
  border-color: var(--c-accent);
}

/* Override browser's default blue autofill background */
input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 30px white inset !important;
  -webkit-text-fill-color: var(--c-fg) !important;
}

/* Hide the browser's clear button (X) */
.search-input::-webkit-search-cancel-button,
.custom-search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

/* Base search submit button */
.search-submit {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  background: transparent;
  border: none;
  color: var(--c-fg-light);
  cursor: pointer;
  width: 44px; /* Fixed width for touch target */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.3s ease;
  z-index: 1; /* Ensure button is above input */
}

.search-input:focus + .search-submit,
.custom-search:not(:placeholder-shown) + .search-submit {
  color: var(--c-accent);
}

.search-submit:hover {
  color: var(--c-accent);
}

/* Search pill variation - matched with filter-btn styling */
.search-pill {
  position: relative;
  display: flex;
  align-items: center;
}

.search-pill .search-input {
  width: 180px;
  transition: width 0.3s ease, background-color 0.3s ease;
  padding: 0.6rem 1.2rem; /* Match filter-btn padding from blog.css */
  border: 1px solid var(--c-border);
  border-radius: 0.5rem; /* Match filter-btn border-radius from blog.css */
  font-size: 1rem; /* Match filter-btn font-size from blog.css */
  line-height: 1.5;
  background-color: var(--c-bg); /* Match filter-btn background from blog.css */
}

.search-pill .search-input:focus {
  width: 220px;
  border-color: var(--c-accent); /* Match filter-btn active border color from blog.css */
  background-color: var(--c-bg-alt); /* Match filter-btn hover background from blog.css */
  outline: none;
}

/* Header search variation */
.header-search {
  position: relative;
  display: flex;
  align-items: center;
}

/* Search toggle button */
.search-toggle {
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.3s ease, opacity 0.2s ease, visibility 0.2s ease;
}

.search-toggle:hover,
.header-search.active .search-toggle {
  color: var(--c-accent);
}

/* Header search form - initially hidden */
.header-search .search-component {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  overflow: hidden;
  opacity: 0;
  transition: width 0.3s ease, opacity 0.3s ease;
  z-index: 101;
}

/* Active state for search form */
.header-search.active .search-component {
  width: 160px;
  opacity: 1;
  right: 5px;
}

.header-search.active .search-toggle {
  opacity: 0;
  visibility: hidden;
}

/* Header search input styling */
.header-search .search-input {
  color: #ffffff;
  background-color: rgba(39, 45, 44, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-search .search-input:focus {
  background-color: rgba(39, 45, 44, 1);
  box-shadow: 0 4px 12px rgba(39, 197, 111, 0.2);
}

/* Search Results Page */
.search-header {
  margin-bottom: 2rem;
  text-align: center;
}

.search-title {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
  color: var(--c-fg);
}

.search-title span {
  color: var(--c-accent);
}

.search-form-container {
  max-width: 500px;
  margin: 0 auto;
}

.search-form-container .search-form {
  display: flex;
  position: relative;
}

.search-form-container .search-field {
  flex-grow: 1;
  padding: 0.75rem 1rem;
  padding-right: 3rem;
  border: 1px solid var(--c-border);
  border-radius: 2rem;
  font-size: 1rem;
  background-color: var(--c-bg);
  color: var(--c-fg);
}

.search-form-container .search-field:focus {
  outline: none;
  border-color: var(--c-accent);
}

.search-form-container .search-submit {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--c-fg-light);
  cursor: pointer;
  padding: 0.5rem;
}

.search-form-container .search-submit:hover {
  color: var(--c-accent);
}

.no-results {
  text-align: center;
  padding: 3rem 1rem;
  max-width: 600px;
  margin: 0 auto;
}

.no-results h2 {
  margin-bottom: 1rem;
  color: var(--c-fg);
  font-size: 1.75rem;
}

.no-results p {
  margin-bottom: 2rem;
  color: var(--c-fg-light);
  font-size: 1.1rem;
}

/* No results search variation */
.search-again {
  margin-top: 2rem;
  display: flex;
  justify-content: center;
}

.search-again .search-input {
  width: 350px;
  height: 3.2rem;
  border-color: var(--c-accent);
  font-size: 1.1rem;
  padding: 0.6rem 3rem 0.6rem 1.5rem;
}

.search-again .search-input:focus {
  box-shadow: 0 2px 8px rgba(39, 197, 111, 0.2);
}

.search-again .search-submit {
  color: var(--c-accent);
  right: 12px;
  font-size: 1.2rem;
}

/* Responsive styles */
@media (max-width: 480px) {
  /* Mobile search styling - full width overlay */
  .header-search {
    position: static; /* Reset to allow proper positioning of child elements */
  }

  .header-search.active .search-toggle {
    opacity: 1;
    visibility: visible;
  }
  
  .header-search .search-component {
    position: fixed;
    top: var(--nav-header-height);
    left: 0;
    right: 0;
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    transform: translateY(-100%);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    box-sizing: border-box;
  }

  .header-search.active .search-component {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  
  /* Full width form and input */
  .header-search .search-form {
    width: 100%;
    display: flex;
  }
  
  .header-search .search-input {
    width: 100%;
    flex-grow: 1;
    padding-right: 1rem; /* Add right padding to fix spacing issue */
  }
  
  /* Override any other styles that might be limiting width */
  .header-search.active .search-component,
  .header-search.active .search-form,
  .header-search.active .search-input {
    width: 100% !important;
    max-width: none !important;
    left: 0 !important;
  }
  
  /* Fix search icon positioning in mobile search box */
  .header-search.active .search-submit {
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--c-accent);
  }
}
