/**
 * Search Component Styles
 * Apple-inspired search with dropdown results and highlighting
 */

/* Search container */
.universal-search {
  position: relative;
  max-width: 100%;
  width: 280px;
  margin: 0 auto;
}

/* Search input */
.search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 42px 10px 44px;
  border-radius: 8px;
  border: 1px solid var(--border-color, rgba(0, 0, 0, 0.12));
  background-color: var(--bg-color, #fff);
  color: var(--text-color, #333);
  font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
  -webkit-appearance: none;
  line-height: 1.3;
}

.search-input:focus {
  background-color: var(--info-bg, #fff);
  border-color: var(--accent-color, #007aff);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.12);
}

/* Search icon */
.search-icon-container {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* Allow clicks to pass through to the input */
}

.search-icon {
  color: var(--text-secondary, #6b7280);
  font-size: 14px;
  pointer-events: none; /* Ensure icon doesn't capture clicks */
}

/* Clear button */
.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary, #6b7280);
  color: #fff;
  font-size: 12px;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-input:valid ~ .search-clear,
.search-input:focus ~ .search-clear {
  opacity: 0.7;
}

/* Search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  max-height: 300px;
  overflow-y: auto;
  background: var(--info-bg, #fff);
  border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
  z-index: 1000;
  display: none;
  padding: 8px 0;
}

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

/* Search result items */
.search-result-item {
  padding: 10px 12px;
  margin: 0 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.search-result-item:hover {
  background-color: rgba(0, 102, 204, 0.08);
}

.search-result-title {
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-color, #333);
  font-size: 14px;
}

.search-result-context {
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  line-height: 1.4;
  /* Truncate to 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* When there are no results */
.search-no-results {
  padding: 20px 15px;
  text-align: center;
  color: var(--text-secondary, #6b7280);
  font-size: 14px;
}

/* Fullscreen search for mobile */
.search-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--info-bg, #fff);
  z-index: 1000;
  display: none;
  padding: 20px;
  box-sizing: border-box;
  /* Start hidden and off-screen for slide-down animation */
  transform: translateY(-100%);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.2s linear;
}

.search-fullscreen.active {
  display: block;
  /* Animate into view */
  transform: translateY(0);
  opacity: 1;
}

.search-close-fullscreen {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  background: var(--bg-color, #f5f5f7);
  border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary, #6b7280);
}

.search-fullscreen-input {
  position: relative;
  max-width: 600px;
  margin: 50px auto 20px;
}

.search-fullscreen-results {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
  box-shadow: none;
  border: 1px solid var(--border-color, rgba(142, 142, 147, 0.2));
  border-radius: 8px;
}

/* Highlight for search matches */
.search-highlight {
  background-color: rgba(255, 204, 0, 0.3);
  border-radius: 2px;
  padding: 0 2px;
  margin: 0 -2px;
  font-weight: bold;
  position: relative;
  z-index: 5;
}

/* Fuzzy match highlights - slightly different styling */
.search-highlight.fuzzy-match {
  background-color: rgba(255, 149, 0, 0.25);
  border: 1px solid rgba(255, 149, 0, 0.4);
  font-weight: normal;
  font-style: italic;
}

/* Animation for the target indicator */
@keyframes target-pulse {
  0% { 
    transform: scale(1); 
    border-color: rgba(255, 204, 0, 0.8);
    box-shadow: 0 0 15px rgba(255, 204, 0, 0.6);
  }
  50% { 
    transform: scale(1.03); 
    border-color: rgba(255, 165, 0, 0.9);
    box-shadow: 0 0 25px rgba(255, 165, 0, 0.8);
  }
  100% { 
    transform: scale(1); 
    border-color: rgba(255, 204, 0, 0.8);
    box-shadow: 0 0 15px rgba(255, 204, 0, 0.6);
  }
}

/* Target indicator for scrolled content */
.search-target-indicator {
  position: absolute;
  z-index: 99999;
  pointer-events: none;
  border: 3px solid rgba(255, 204, 0, 0.8);
  border-radius: 4px;
  box-shadow: 0 0 15px rgba(255, 204, 0, 0.6);
  animation: target-pulse 1.5s infinite;
  transition: all 0.2s ease-out;
}

/* Animation for highlights on the page */
@keyframes search-highlight-pulse {
  0%, 100% {
    background-color: rgba(255, 204, 0, 0.3);
  }
  50% {
    background-color: rgba(255, 204, 0, 0.5);
  }
}

/* Dark Mode Support */
body.dark .search-input {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  color: #f0f0f0;
}

body.dark .search-input:focus {
  background-color: rgba(255, 255, 255, 0.08);
  border-color: var(--accent-color, #2997ff);
  box-shadow: 0 0 0 3px rgba(41, 151, 255, 0.16);
}

body.dark .search-results,
body.dark .search-fullscreen {
  background-color: var(--info-bg, #1c1c1e);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

body.dark .search-result-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

body.dark .search-result-title {
  color: #f0f0f0;
}

body.dark .search-icon,
body.dark .search-clear,
body.dark .search-result-context,
body.dark .search-no-results,
body.dark .search-close-fullscreen {
  color: #8E8E93;
}

body.dark .search-highlight {
  background-color: rgba(255, 204, 0, 0.25);
}

body.dark .search-highlight.fuzzy-match {
  background-color: rgba(255, 149, 0, 0.35);
  border: 1px solid rgba(255, 149, 0, 0.5);
  color: #000;
}

/* Highlighted text in search results */
.search-result-title .search-highlight,
.search-result-context .search-highlight {
  background-color: rgba(255, 204, 0, 0.5);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: bold;
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
  .universal-search {
    width: 200px;
  }
  
  .search-input {
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

@media (max-width: 480px) {
  .universal-search {
    width: 160px;
  }
}

/* Combined Search and Menu Component (Apple.com style) */
.universal-search-menu {
  position: relative;
  display: flex;
  align-items: center;
  margin-left: auto;
}

.search-trigger {
  appearance: none;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background-color: var(--info-bg, rgba(142, 142, 147, 0.12));
  border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
  box-shadow: 0 1px 4px var(--shadow-color, rgba(0, 0, 0, 0.08));
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.search-trigger:hover {
  background-color: var(--bg-color, rgba(142, 142, 147, 0.08));
  border-color: var(--accent-color, #007aff);
  box-shadow: 0 2px 8px rgba(0, 102, 204, 0.16);
}

.search-trigger:focus-visible {
  outline: 2px solid var(--accent-color, #007aff);
  outline-offset: 3px;
}

.search-trigger .search-icon {
  position: static;
  transform: none;
  font-size: 16px;
}

.search-menu-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: min(420px, calc(100vw - 32px));
  background: var(--info-bg, #fff);
  border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
  padding: 12px;
  display: none;
  z-index: 1000;
}

.search-menu-panel.active {
  display: block;
  animation: fadeIn 0.25s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.search-section {
  margin-bottom: 12px;
}

.search-wrapper {
  position: relative;
  margin-bottom: 10px;
}

.search-wrapper .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #8E8E93;
  font-size: 14px;
}

.menu-section {
  border-top: 1px solid var(--border-color, rgba(142, 142, 147, 0.2));
  padding: 8px 0;
  display: none; /* Hide by default */
}

/* Only show menu section when search panel is active */
.search-menu-panel.active .menu-section {
  display: block;
}

/* Also hide fullscreen menu section by default */
.fullscreen-menu-section {
  display: none;
}

.search-fullscreen.active .fullscreen-menu-section {
  display: block;
}

.menu-section a {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  color: var(--text-color, #333);
  text-decoration: none;
  font-weight: 500;
  border-radius: 6px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.menu-section a.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-section a.nav-link i {
  width: 20px;
  text-align: center;
  font-size: 16px;
}

.menu-section a:hover {
  background: rgba(0, 102, 204, 0.08);
  color: var(--accent-color, #007bff);
}

/* Search results inside the combined dropdown */
.search-menu-panel .search-results {
  position: static;
  box-shadow: none;
  border: 1px solid var(--border-color, rgba(142, 142, 147, 0.12));
  margin-top: 8px;
  max-height: 200px;
}

/* Dark mode support */
body.dark .search-trigger {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}

body.dark .search-trigger:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: var(--accent-color, #2997ff);
}

body.dark .search-menu-panel {
  background: var(--info-bg, #1c1c1e);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

body.dark .menu-section {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

body.dark .menu-section a {
  color: #f0f0f0;
}

body.dark .menu-section a:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Mobile responsive styles */
@media (max-width: 600px) {
  /* Fullscreen slide-down mobile search */
  .search-menu-panel {
    position: fixed !important;
    inset: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    max-height: none !important;
    overflow-y: auto !important;
    transform: translateY(-100%) !important;
    opacity: 0 !important;
    transition: transform 0.35s cubic-bezier(0.23, 1, 0.32, 1) !important;
    z-index: 2000 !important;
  }
  .search-menu-panel.active {
    transform: translateY(0) !important;
    opacity: 1 !important;
  }
  .search-results {
    position: relative;
    width: 100%;
    max-height: 50vh;
  }
  .search-wrapper {
    width: 100%;
  }
  .search-input {
    width: 100%;
    box-sizing: border-box;
  }
  header#header {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
}

/* Search backdrop overlay for handling clicks outside dropdown */
.search-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: transparent;
  z-index: 999; /* Just below the dropdown but above other content */
  display: none;
}

/* Ensure search menu panel is above the backdrop */
.search-menu-panel.active {
  display: block;
  animation: fadeIn 0.25s cubic-bezier(0.165, 0.84, 0.44, 1);
  z-index: 1000; /* Ensure it's above the backdrop */
}

/* Mobile fullscreen slide-down override */
@media (max-width: 600px) {
  /* Hide the dropdown panel and use fullscreen overlay */
  .search-menu-panel {
    display: none !important;
  }
  .search-fullscreen {
    display: block !important;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.23,1,0.32,1), opacity 0.2s linear;
    z-index: 2000 !important;
  }
  .search-fullscreen.active {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Page Preview Popup Styles */
.page-preview-popup {
  position: fixed;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  z-index: 1001;
  width: 320px;
  max-width: calc(100vw - 20px);
  max-height: 400px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
  pointer-events: none;
}

.page-preview-popup.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.preview-content {
  padding: 0;
  overflow: hidden;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 12px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background: #f8f9fa;
  border-radius: 12px 12px 0 0;
}

.preview-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #1d1d1f;
  line-height: 1.2;
}

.preview-close {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #86868b;
  font-size: 14px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.preview-close:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #1d1d1f;
}

.preview-body {
  padding: 16px 20px;
}

.preview-body p {
  margin: 0 0 12px 0;
  font-size: 14px;
  line-height: 1.4;
  color: #424245;
}

.preview-features ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.preview-features li {
  font-size: 13px;
  color: #86868b;
  margin-bottom: 4px;
  padding-left: 12px;
  position: relative;
  line-height: 1.3;
}

.preview-features li:before {
  content: '•';
  position: absolute;
  left: 0;
  color: #007aff;
  font-weight: bold;
}

.preview-footer {
  padding: 12px 20px 16px 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: #f8f9fa;
  border-radius: 0 0 12px 12px;
}

.preview-visit-btn {
  display: inline-block;
  background: #007aff;
  color: white;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
}

.preview-visit-btn:hover {
  background: #0056b3;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

/* Dark mode support for preview popup */
body.dark .page-preview-popup {
  background: #1c1c1e;
  border-color: rgba(255, 255, 255, 0.1);
}

body.dark .preview-header {
  background: #2c2c2e;
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

body.dark .preview-header h3 {
  color: #f2f2f7;
}

body.dark .preview-close {
  color: #8e8e93;
}

body.dark .preview-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #f2f2f7;
}

body.dark .preview-body p {
  color: #e5e5ea;
}

body.dark .preview-features li {
  color: #8e8e93;
}

body.dark .preview-footer {
  background: #2c2c2e;
  border-top-color: rgba(255, 255, 255, 0.1);
}

/* Mobile responsiveness for preview popup */
@media (max-width: 768px) {
  .page-preview-popup {
    width: 280px;
    max-height: 350px;
  }
  
  .preview-header,
  .preview-body,
  .preview-footer {
    padding-left: 16px;
    padding-right: 16px;
  }
  
  .preview-header h3 {
    font-size: 15px;
  }
  
  .preview-body p {
    font-size: 13px;
  }
  
  .preview-features li {
    font-size: 12px;
  }
} 
