/* Enhanced Global Search Component Styles */
:root {
  --search-z-index: 10000;
  --search-backdrop-z: 9998;
  --search-container-z: 9999;
  --search-primary: #00aaff;
  --search-bg-dark: rgba(18, 18, 18, 0.98);
  --search-bg-hover: rgba(255, 255, 255, 0.05);
  --search-text-primary: rgba(255, 255, 255, 0.9);
  --search-text-muted: rgba(255, 255, 255, 0.5);
  --search-border: rgba(255, 255, 255, 0.1);
  --search-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Search Container */
.global-search {
  position: fixed;
  top: 2rem;
  right: 2rem;
  z-index: var(--search-z-index);
  isolation: isolate; /* Create new stacking context */
}

/* Search Toggle Button */
.search-toggle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(26, 26, 26, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: var(--search-transition);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  position: relative;
  padding: 0;
  outline: none;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); }
  50% { box-shadow: 0 4px 20px rgba(0, 170, 255, 0.3); }
}

/* Simple tooltip - positioned to the left */
.search-toggle::after {
  content: 'Search Portfolio';
  position: absolute;
  top: 50%;
  right: calc(100% + 8px);
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: rgba(255, 255, 255, 0.8);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 400;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}

.search-toggle:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Hover preview - positioned below and to the left */
.search-preview {
  position: fixed;
  top: 5rem;
  right: 2rem;
  transform-origin: top right;
  background: rgba(18, 18, 18, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transform: translateX(20px) translateY(-5px);
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: calc(var(--search-container-z) - 1);
  width: 220px;
  margin-right: 50px; /* Offset from button */
}

.search-preview-content {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.4;
}

.search-preview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.search-preview-tag {
  font-size: 0.7rem;
  padding: 0.2rem 0.4rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.5);
}

/* Desktop hover effects */
@media (hover: hover) and (pointer: fine) {
  .search-toggle:hover {
    background: rgba(26, 26, 26, 1);
    color: rgba(255, 255, 255, 0.95);
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
    transform: scale(1.05);
  }
  
  .search-toggle:hover ~ .search-preview,
  .search-preview:hover {
    opacity: 1;
    visibility: visible;
    transform: translateX(0) translateY(0);
  }
}

/* Search Box Container - Enhanced animations */
.search-container {
  position: fixed;
  top: 5rem;
  right: 2rem;
  width: 500px; /* Increased width to show full placeholder */
  max-width: calc(100vw - 4rem); /* Responsive width */
  background: var(--search-bg-dark);
  border: 1px solid var(--search-border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(0, 170, 255, 0.1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-20px) scale(0.9);
  transition: var(--search-transition);
  z-index: var(--search-container-z);
  pointer-events: none;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  isolation: isolate; /* Create new stacking context */
  max-height: calc(100vh - 8rem); /* Prevent vertical overflow */
  overflow-y: auto; /* Allow scrolling if content is too tall */
}

.search-container.active {
  pointer-events: auto;
}

/* Show only when active with smooth animation */
.search-container.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  animation: slideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Search Input - Clean design */
.search-input-container {
  position: relative;
  padding: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  box-sizing: border-box;
}

.search-input {
  width: 100%;
  padding: 0.85rem 2.5rem;
  padding-left: 2.5rem;
  padding-right: 2.5rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: var(--search-text-primary);
  font-size: 0.95rem;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  transition: var(--search-transition);
  letter-spacing: 0.01em;
  box-sizing: border-box;
  display: block;
}

.search-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
}

.search-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
  font-weight: 400;
}

.search-icon {
  position: absolute;
  left: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.9rem;
  pointer-events: none;
  z-index: 1;
}

.search-close {
  position: absolute;
  right: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: all 0.2s ease;
  font-size: 1rem;
  z-index: 1;
}

.search-close:hover {
  color: rgba(255, 255, 255, 0.8);
}

/* Search Results */
.search-results {
  max-height: 350px; /* Reduced to ensure it fits within viewport */
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
  overflow-x: hidden; /* Prevent horizontal scrolling */
}

.search-results::-webkit-scrollbar {
  width: 6px;
}

.search-results::-webkit-scrollbar-track {
  background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.search-results::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-hover);
}

/* Search Result Items - Clean */
.search-result-item {
  padding: 0.85rem 1rem;
  margin: 0.25rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--search-transition);
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  position: relative;
  user-select: none;
  border: 1px solid transparent;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--search-bg-hover);
  border-color: rgba(0, 170, 255, 0.2);
  transform: translateX(4px);
}

.search-result-item:active {
  background: rgba(255, 255, 255, 0.08);
  transform: scale(0.99);
}

.search-result-item.highlighted {
  background: linear-gradient(90deg, rgba(0, 170, 255, 0.1) 0%, transparent 100%);
  border-color: var(--search-primary);
  box-shadow: 0 0 20px rgba(0, 170, 255, 0.1);
}

.search-result-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  font-size: 0.9rem;
  margin-top: 2px;
}

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

.search-result-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-snippet {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2; /* Standard property for compatibility */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-category {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-bottom: 4px;
}

/* Empty State - Minimal */
.search-empty {
  padding: 1.5rem;
  text-align: center;
}

.search-empty-text {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.4);
  line-height: 1.4;
}

/* Loading State */
.search-loading {
  padding: var(--spacing-lg);
  text-align: center;
  color: var(--color-text-muted);
}

.search-loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  border-top-color: var(--color-primary);
  animation: spin 1s ease-in-out infinite;
  margin-bottom: var(--spacing-sm);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Search Backdrop - Subtle overlay with blur effect */
.search-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: var(--search-backdrop-z);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, backdrop-filter 0.3s ease;
  pointer-events: none;
}

.search-backdrop.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Search Suggestions - Minimal */
.search-suggestions {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.search-suggestions-title {
  font-size: 0.7rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.search-suggestions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.search-suggestion-tag {
  padding: 0.3rem 0.6rem;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-weight: 400;
}

.search-suggestion-tag:hover {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.2);
}


/* Mobile Responsiveness */
@media screen and (max-width: 768px) {
  .global-search {
    top: 1rem;
    right: 1rem;
  }

  .search-preview {
    display: none; /* No hover preview on mobile */
  }

  .search-container {
    width: calc(100vw - 2rem);
    right: 1rem;
    left: auto;
    top: 4rem;
    max-height: calc(100vh - 6rem);
  }

  .search-toggle {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }
  
  .search-results {
    max-height: calc(100vh - 12rem);
  }
}

@media screen and (max-width: 480px) {
  .global-search {
    top: 0.75rem;
    right: 0.75rem;
  }

  .search-toggle {
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
  }

  .search-container {
    left: 0.5rem;
    right: 0.5rem;
    width: calc(100vw - 1rem);
    top: 3.5rem;
  }

  .search-results {
    max-height: calc(100vh - 10rem);
  }
  
  .search-input {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* Highlight matching text with animation */
.search-highlight {
  background: linear-gradient(90deg, rgba(0, 170, 255, 0.3), rgba(0, 170, 255, 0.1));
  color: #ffffff;
  font-weight: 600;
  border-radius: 3px;
  padding: 1px 3px;
  animation: highlight 0.5s ease;
}

@keyframes highlight {
  from { background-color: rgba(0, 170, 255, 0.5); }
  to { background: linear-gradient(90deg, rgba(0, 170, 255, 0.3), rgba(0, 170, 255, 0.1)); }
}

/* Search Result Groups */
.search-result-group {
  margin-bottom: 1rem;
}

.search-result-group-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--search-text-muted);
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--search-border);
  margin-bottom: 0.5rem;
}

/* Search Result Breadcrumb */
.search-result-breadcrumb {
  font-size: 0.65rem;
  color: var(--search-text-muted);
  margin-bottom: 2px;
  opacity: 0.7;
}

/* Search Result Action Icon */
.search-result-action {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--search-text-muted);
  opacity: 0;
  transition: var(--search-transition);
}

.search-result-item:hover .search-result-action {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* Recent Searches */
.search-recent {
  padding: 1rem;
  border-top: 1px solid var(--search-border);
}

.search-recent-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--search-text-muted);
  margin-bottom: 0.5rem;
}

.search-recent-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.search-recent-item {
  padding: 0.3rem 0.6rem;
  background: var(--search-bg-hover);
  border: 1px solid var(--search-border);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--search-text-primary);
  cursor: pointer;
  transition: var(--search-transition);
}

.search-recent-item:hover {
  background: rgba(0, 170, 255, 0.1);
  border-color: var(--search-primary);
  color: var(--search-primary);
}

/* Search Alternatives */
.search-alternatives {
  padding: 1rem;
  text-align: center;
}

.search-alternatives-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}

.search-alternative-item {
  padding: 0.4rem 0.8rem;
  background: rgba(0, 170, 255, 0.1);
  border: 1px solid var(--search-primary);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--search-primary);
  cursor: pointer;
  transition: var(--search-transition);
}

.search-alternative-item:hover {
  background: var(--search-primary);
  color: #000;
  transform: scale(1.05);
}