/* Modern Search Styles */
#h-searchbar {
  position: relative;
  flex: 1;
  max-width: 500px;
  margin: 0 20px;
}

.search-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 44px 0 44px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 400;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
}

.search-input:focus {
  outline: none;
  border-color: #8b5cf6;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.search-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 20px;
  transition: color 0.3s ease;
  z-index: 5;
}

.search-input:focus + .search-icon {
  color: #8b5cf6;
}

.search-clear {
  position: absolute;
  right: 44px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.search-clear:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
}

.search-loader {
  position: absolute;
  right: 44px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
}

.loader-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #8b5cf6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.search-btn {
  height: 44px;
  padding: 0 20px;
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  border: none;
  border-radius: 12px;
  font-weight: 600;
  transition: all 0.3s ease;
  white-space: nowrap;
  z-index: 10;
  position: relative;
}

.search-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

/* Suggestion Panel */
.suggestion-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: rgba(23, 23, 23, 0.98);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  margin-top: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.suggestion-panel.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.suggestion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.02);
}

.suggestion-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.suggestion-count {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 8px;
  border-radius: 6px;
}

.suggestion-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
}

.suggestion-list::-webkit-scrollbar {
  width: 6px;
}

.suggestion-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.suggestion-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.suggestion-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.suggestion-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
}

.suggestion-item:last-child {
  margin-bottom: 0;
}

.suggestion-poster {
  width: 50px;
  height: 70px;
  margin-right: 16px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.suggestion-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.suggestion-item:hover .suggestion-poster img {
  transform: scale(1.05);
}

.suggestion-details {
  flex: 1;
  min-width: 0;
}

.suggestion-title {
  font-weight: 600;
  color: #fff;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
  line-height: 1.3;
}

.suggestion-alt {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.suggestion-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  flex-wrap: wrap;
}

.suggestion-type {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  color: #fff;
  font-size: 10px;
}

.suggestion-aired {
  font-style: italic;
}

/* Empty and Error States */
.suggestion-empty,
.suggestion-error {
  padding: 40px 20px;
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
}

.suggestion-empty i,
.suggestion-error i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.suggestion-empty h4,
.suggestion-error h4 {
  margin: 0 0 8px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 16px;
}

.suggestion-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.02);
}

.search-tips {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  justify-content: center;
}

.search-tips i {
  color: #8b5cf6;
}

/* Skeleton Loading */
.suggestion-skeleton {
  display: flex;
  align-items: center;
  padding: 12px;
}

.skeleton-poster {
  width: 50px;
  height: 70px;
  margin-right: 16px;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(255,255,255,0.1) 25%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.1) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

.skeleton-details {
  flex: 1;
}

.skeleton-title {
  height: 16px;
  background: linear-gradient(90deg, rgba(255,255,255,0.1) 25%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.1) 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  margin-bottom: 8px;
  animation: loading 1.5s infinite;
  width: 70%;
}

.skeleton-meta {
  height: 12px;
  background: linear-gradient(90deg, rgba(255,255,255,0.1) 25%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.1) 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: loading 1.5s infinite;
  width: 50%;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ===== MOBILE FIXES ===== */
@media (max-width: 768px) {
  #h-searchbar {
    margin: 0 10px;
    max-width: none;
    position: relative;
  }
  
  .search-form {
    flex-direction: row;
    gap: 8px;
    position: relative;
    z-index: 1002; /* Higher z-index */
  }
  
  .search-input-wrapper {
    width: 100%;
    position: relative;
  }
  
  .search-input {
    height: 44px;
    font-size: 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    z-index: 1003; /* Ensure input is above everything */
    position: relative;
  }
  
  .search-btn {
    height: 44px;
    padding: 0 16px;
    min-width: auto;
    flex-shrink: 0;
    z-index: 1003;
  }
  
  .search-btn span {
    display: none;
  }
  
  .search-btn i {
    margin: 0;
    font-size: 20px;
  }
  
  /* FIXED: Mobile suggestion panel positioning */
  .suggestion-panel {
    position: fixed;
    top: 80px !important; /* Below header + some margin */
    left: 10px !important;
    right: 10px !important;
    bottom: auto !important;
    margin-top: 0;
    max-height: calc(100vh - 120px); /* Dynamic height */
    z-index: 1001; /* Below input but above other content */
    border-radius: 12px;
    background: rgba(23, 23, 23, 0.98);
    backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    overflow: hidden;
  }
  
  .suggestion-list {
    max-height: calc(100vh - 200px); /* Account for header and footer */
    padding: 4px;
  }
  
  /* Mobile-specific suggestion items */
  .suggestion-item {
    padding: 14px 12px;
    margin-bottom: 4px;
  }
  
  .suggestion-poster {
    width: 45px;
    height: 63px;
    margin-right: 12px;
  }
  
  .suggestion-title {
    font-size: 15px;
  }
  
  .suggestion-alt {
    font-size: 13px;
  }
  
  .suggestion-meta {
    font-size: 12px;
    gap: 8px;
  }
  
  .suggestion-header {
    padding: 14px 16px 10px;
  }
  
  .suggestion-footer {
    padding: 10px 16px;
  }
  
  /* Ensure header doesn't interfere */
  header.fixed {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  /* Ensure main content has proper spacing */
  .main-content {
    margin-top: 70px;
  }
}

/* Extra Small Mobile Devices */
@media (max-width: 480px) {
  #h-searchbar {
    margin: 0 8px;
  }
  
  .search-form {
    gap: 6px;
  }
  
  .search-input {
    height: 42px;
    padding: 0 42px 0 42px;
    font-size: 16px;
  }
  
  .search-icon {
    left: 14px;
    font-size: 18px;
  }
  
  .search-clear {
    right: 42px;
    padding: 3px;
  }
  
  .search-loader {
    right: 42px;
  }
  
  .search-btn {
    height: 42px;
    width: 42px;
    padding: 0;
    border-radius: 10px;
  }
  
  .suggestion-panel {
    top: 75px !important;
    left: 8px !important;
    right: 8px !important;
    max-height: calc(100vh - 100px);
  }
  
  .suggestion-item {
    padding: 12px 10px;
  }
  
  .suggestion-poster {
    width: 40px;
    height: 56px;
    margin-right: 10px;
  }
  
  .suggestion-title {
    font-size: 14px;
  }
  
  .suggestion-alt {
    font-size: 12px;
  }
  
  .suggestion-meta {
    font-size: 11px;
  }
}

/* Mobile backdrop for suggestions */
.suggestion-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 999; /* Below suggestions but above other content */
  backdrop-filter: blur(5px);
}

.suggestion-backdrop.show {
  display: block;
}

/* Fix for iOS Safari */
@supports (-webkit-touch-callout: none) {
  .search-input {
    font-size: 16px;
  }
  
  .suggestion-panel {
    -webkit-overflow-scrolling: touch;
  }
}

/* Fix for mobile keyboard */
@media (max-height: 600px) {
  .suggestion-panel {
    max-height: 50vh;
  }
  
  .suggestion-list {
    max-height: calc(50vh - 120px);
  }
}

/* Ensure input is always accessible and above suggestions */
.search-input {
  position: relative;
  z-index: 1003 !important; /* Critical: Ensure input is above suggestions */
}

/* Prevent body scroll when suggestions are open on mobile */
body.suggestions-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Focus states for accessibility */
.search-input:focus-visible {
  outline: 2px solid #8b5cf6;
  outline-offset: 2px;
}

.suggestion-item:focus-visible {
  outline: 2px solid #8b5cf6;
  outline-offset: -2px;
  border-radius: 8px;
}

/* Dark theme variations */
@media (prefers-color-scheme: dark) {
  .search-input {
    background: rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.15);
  }
  
  .suggestion-panel {
    background: rgba(10, 10, 10, 0.98);
  }
}

/* Animation for search clear button */
.search-clear {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .search-input,
  .suggestion-item,
  .search-btn,
  .suggestion-panel {
    transition: none;
  }
  
  .loader-spinner {
    animation: none;
  }
  
  .skeleton-poster,
  .skeleton-title,
  .skeleton-meta {
    animation: none;
  }
}

/* Critical fix: Ensure search form elements have proper z-index stacking */
#h-searchbar .inner {
  position: relative;
  z-index: 1002;
}

.search-input-wrapper {
  z-index: 1003;
}

/* Fix for very small screens */
@media (max-width: 360px) {
  .search-form {
    gap: 4px;
  }
  
  .search-btn {
    width: 40px;
    height: 40px;
  }
  
  .search-input {
    height: 40px;
    padding: 0 40px 0 40px;
    font-size: 14px;
  }
  
  .suggestion-panel {
    left: 6px !important;
    right: 6px !important;
  }
}

/* Ensure the search container doesn't affect layout */
#h-searchbar {
  min-height: 44px;
}

/* Fix for Android Chrome */
@media (max-width: 768px) and (orientation: landscape) {
  .suggestion-panel {
    max-height: 60vh;
  }
  
  .suggestion-list {
    max-height: calc(60vh - 120px);
  }
}

/* Important: Reset any conflicting styles from external CSS */
#h-searchbar * {
  box-sizing: border-box;
}

.suggestion-panel {
  box-sizing: border-box !important;
}

/* Force the suggestion panel to stay within bounds */
.suggestion-panel {
  max-width: 100vw;
  overflow: hidden;
}

/* Fix for input focus on mobile */
.search-input:focus {
  transform: none !important;
}