/**
 * Mobile Search Styles for Flatsome Child Theme
 * 
 * FEATURES:
 * - Responsive mobile-first design
 * - Touch-friendly interactions
 * - Smooth animations
 * - Vietnamese text support
 * - Anti-zoom on mobile inputs
 * - Accessibility-focused
 */

/* ================================
   SEARCH FORM CONTAINER
   ================================ */

.search-container {
  background-color: #f9fafb;
}
.search-form-container {
  position: relative;
  flex: 1;
  max-width: 100%;
  margin-bottom: 0px;
}

.search-form {
  position: relative;
  width: 100%;
  margin-bottom: 0px;
}

/* ================================
   SEARCH INPUT FIELD
   ================================ */

input[type="search"].search-field {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem 0 0 0.5rem;
  background-color: #ffffff;
  color: #1f2937;
  font-size: 1rem;
  line-height: 1.5;
  outline: none;
  transition: all 0.2s ease-in-out;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  margin-bottom: 0px;
  height: auto;
  box-shadow: none;
}

input[type="search"].search-field:focus {
  border-color: var(--primary-color);
  box-shadow: none;
  outline: none;
}

input[type="search"].search-field::placeholder {
  color: #9ca3af;
  opacity: 1;
}

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

button[type="submit"].search-submit {
  padding: 0.75rem 1rem;
  background-color: var(--primary-color);
  color: #ffffff;
  border: 1px solid var(--primary-color);
  border-radius: 0 0.5rem 0.5rem 0;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  margin: 0px;
}

button[type="submit"].search-submit:hover {
  background-color: #651014;
  border-color: #651014;
}

button[type="submit"].search-submit:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(123, 17, 19, 0.2);
}

button[type="submit"].search-submit svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* ================================
   SEARCH RESULTS DROPDOWN
   ================================ */

.live-search-results,
[id*="live-search-input"][id*="-results"],
[id*="mobile-search-input"][id*="-results"],
[id*="desktop-search-input"][id*="-results"] {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
  margin-top: 0.25rem;
  max-height: 24rem;
  overflow-y: auto;
  z-index: 50;
  opacity: 1;
  transform: translateY(0);
  transition: all 0.2s ease-in-out;
}

.live-search-results.hidden,
[id*="live-search-input"][id*="-results"].hidden,
[id*="mobile-search-input"][id*="-results"].hidden,
[id*="desktop-search-input"][id*="-results"].hidden {
  opacity: 0;
  transform: translateY(-0.5rem);
  visibility: hidden;
  display: none;
}

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

.loading {
  padding: 1rem;
  text-align: center;
  color: #6b7280;
}

.loading.hidden {
  display: none;
}

/* Loading spinner animation */
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

.loading .animate-spin {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid #e5e7eb;
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.5rem;
}

/* ================================
   NO RESULTS STATE
   ================================ */

.no-results {
  padding: 2rem 1rem;
  text-align: center;
  color: #6b7280;
  font-size: 0.875rem;
}

.no-results.hidden {
  display: none;
}

/* ================================
   SEARCH RESULT ITEMS
   ================================ */

.results {
  padding: 0;
}

.search-result-item,
.results > div {
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.2s ease-in-out;
}

.search-result-item:last-child,
.results > div:last-child {
  border-bottom: none;
}

.search-result-item a,
.results a {
  display: block;
  padding: 0.75rem;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s ease-in-out;
}

.search-result-item:hover,
.results > div:hover {
  background-color: #f9fafb;
}

.search-result-item:hover a,
.results > div:hover a {
  color: var(--primary-color);
}

/* ================================
   RESULT ITEM LAYOUT
   ================================ */

.search-result-content {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.search-result-thumbnail {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.375rem;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  background-color: #f9fafb;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-result-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-result-thumbnail svg {
  width: 1rem;
  height: 1rem;
  color: #9ca3af;
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #1f2937;
  line-height: 1.25;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.search-result-date {
  font-size: 0.75rem;
  color: #6b7280;
}

.search-result-category,
.search-result-source {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-weight: 500;
}

.search-result-category {
  background-color: rgba(123, 17, 19, 0.1);
  color: var(--primary-color);
}

.search-result-source {
  background-color: #f3f4f6;
  color: #374151;
}

/* ================================
   SEARCH HIGHLIGHTING
   ================================ */

mark,
.highlight {
  background: linear-gradient(120deg, #fef3c7 0%, #fde68a 100%);
  color: #92400e;
  padding: 0.125rem 0.25rem;
  border-radius: 0.125rem;
  font-weight: 600;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.search-result-item:hover mark,
.results > div:hover mark {
  background: linear-gradient(120deg, #fbbf24 0%, #f59e0b 100%);
  color: #78350f;
}

/* ================================
   MOBILE SEARCH TOGGLE
   ================================ */

.mobile-search-toggle {
  all: unset;
  color: #000;
  border: none;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  margin: 0px;
  font-size: 16px;
  line-height: normal;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 11px;
}

.mobile-search-toggle:hover {
  color: #1f2937;
  background-color: #f3f4f6;
}

.mobile-search-toggle:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(123, 17, 19, 0.2);
}

.mobile-search-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
}

.mobile-search-toggle i {
  font-size: 16px;
  display: inline-block;
  font-style: normal !important;
  font-family: "Font Awesome 5 Pro", "Font Awesome 5 Free", "Font Awesome 6 Pro",
    "Font Awesome 6 Free" !important;
  font-weight: 900 !important;
}

.mobile-search-toggle .fas {
  font-weight: 900 !important;
}

.mobile-search-toggle .fa-search:before {
  content: "\f002" !important;
}

.mobile-search-toggle svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

/* ================================
   MOBILE SEARCH OVERLAY
   ================================ */

#mobile-search {
  width: 100%;
  padding: 1rem 0px;
  transition: all 0.3s ease-in-out;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

#mobile-search.show {
  transform: translateY(0);
}

/* Make sure it sticks with header */
.header.stuck #mobile-search {
  position: sticky;
  top: 100%;
  z-index: 999;
}

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

/* Mobile devices (up to 640px) */
@media (max-width: 640px) {
  .search-field {
    padding: 0.625rem 0.75rem;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  .search-submit {
    padding: 0.625rem 0.75rem;
    min-width: 2.75rem;
  }

  .search-submit svg {
    width: 1rem;
    height: 1rem;
  }

  .search-result-content {
    gap: 0.5rem;
  }

  .search-result-thumbnail {
    width: 2rem;
    height: 2rem;
  }

  .search-result-title {
    font-size: 0.8125rem;
  }

  .search-result-meta {
    gap: 0.375rem;
  }

  .search-result-category,
  .search-result-source {
    font-size: 0.6875rem;
    padding: 0.0625rem 0.375rem;
  }
}

/* Desktop devices (1024px and up) */
@media (min-width: 1024px) {
  .search-field {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
  }

  .search-submit {
    padding: 0.875rem 1.5rem;
  }

  .search-submit svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .search-result-title {
    font-size: 0.9375rem;
  }
}

/* ================================
   TOUCH DEVICE OPTIMIZATIONS
   ================================ */

.touch-device .search-result-item a,
.touch-device .results a {
  padding: 1rem 0.75rem;
  min-height: 2.75rem;
}

.touch-device .search-submit {
  min-width: 3.5rem;
  min-height: 3rem;
}

.touch-device .mobile-search-toggle {
  min-width: 16px;
  min-height: 16px;
}

/* ================================
   ACCESSIBILITY IMPROVEMENTS
   ================================ */

/* Focus styles for keyboard navigation */
.search-field:focus-visible,
.search-submit:focus-visible,
.mobile-search-toggle:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.search-result-item a:focus-visible,
.results a:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: -2px;
}

/* ================================
   UTILITY CLASSES
   ================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none;
}

.flex {
  display: flex;
}

.flex-1 {
  flex: 1 1 0%;
}

.flex-shrink-0 {
  flex-shrink: 0;
}

.items-start {
  align-items: flex-start;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}
