/**
 * Unified Student Search Component Styles
 * Modern, accessible autocomplete search
 */

.unified-student-search {
  position: relative;
  width: 100%;
  font-family: var(--font-family, 'Segoe UI', system-ui, sans-serif);
}

/* ===== Search Input ===== */
.search-input-wrapper {
  position: relative;
  width: 100%;
}

.search-input {
  width: 100%;
  height: 48px;
  padding: 12px 48px 12px 44px;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text, #1e293b);
  background: var(--card, #ffffff);
  border: 2px solid var(--border, #e2e8f0);
  border-radius: var(--border-radius, 8px);
  transition: all 0.2s ease;
  outline: none;
}

.search-input:focus {
  border-color: var(--primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-input.has-selection {
  border-color: var(--success, #10b981);
  background: rgba(16, 185, 129, 0.05);
}

.search-input.error {
  border-color: var(--error, #ef4444);
}

.search-input::placeholder {
  color: var(--text-muted, #94a3b8);
}

/* Search Icon */
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.25rem;
  pointer-events: none;
  opacity: 0.5;
}

/* Clear Button */
.clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--error, #ef4444);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: bold;
}

.clear-btn:hover {
  background: #dc2626;
  transform: translateY(-50%) scale(1.1);
}

.clear-btn:active {
  transform: translateY(-50%) scale(0.95);
}

/* Loading Indicator */
.search-loading {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner-small {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--primary, #3b82f6);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Dropdown ===== */
.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 400px;
  background: var(--card, #ffffff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--border-radius, 8px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  overflow: hidden;
  animation: dropdownSlideIn 0.2s ease;
}

@keyframes dropdownSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dropdown-content {
  max-height: 400px;
  overflow-y: auto;
}

/* Custom Scrollbar */
.dropdown-content::-webkit-scrollbar {
  width: 8px;
}

.dropdown-content::-webkit-scrollbar-track {
  background: var(--border-light, #f1f5f9);
}

.dropdown-content::-webkit-scrollbar-thumb {
  background: var(--text-muted, #94a3b8);
  border-radius: 4px;
}

.dropdown-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-light, #64748b);
}

/* ===== Dropdown Items ===== */
.dropdown-item {
  display: flex !important;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 64px;
  cursor: pointer;
  transition: all 0.15s ease;
  border-bottom: 1px solid var(--border-light, #f1f5f9);
  background: #ffffff !important; /* Force white background */
  color: #1e293b !important; /* Force dark text */
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover,
.dropdown-item.highlighted {
  background: #f8fafc !important; /* Force light background on hover */
}

.dropdown-item.highlighted {
  border-left: 3px solid var(--primary, #3b82f6);
}

/* Student Avatar */
.student-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary, #3b82f6), var(--secondary, #6366f1));
  color: white;
  font-weight: 700;
  font-size: 0.875rem;
  border-radius: 50%;
  text-transform: uppercase;
}

/* Student Info */
.student-info {
  flex: 1;
  min-width: 0;
  color: #1e293b !important; /* Force visibility */
}

.student-name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: #1e293b !important; /* Force dark text */
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.student-name mark {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6 !important; /* Force blue for highlights */
  font-weight: 700;
  padding: 0 2px;
  border-radius: 2px;
}

.student-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.student-id {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: #94a3b8 !important; /* Force muted text */
  font-family: 'Courier New', monospace;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 12px;
  white-space: nowrap;
}

.badge-year {
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary, #3b82f6);
}

.badge-homegroup {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success, #10b981);
}

.badge-house {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning, #f59e0b);
}

/* Empty State */
.dropdown-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted, #94a3b8);
}

.empty-icon {
  font-size: 3rem;
  opacity: 0.5;
  margin-bottom: 12px;
}

.dropdown-empty p {
  margin: 0 0 8px 0;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-light, #64748b);
}

.dropdown-empty small {
  font-size: 0.875rem;
  color: var(--text-muted, #94a3b8);
}

/* ===== Student Preview Card ===== */
.student-preview {
  margin-top: 16px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.preview-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: linear-gradient(135deg, 
    rgba(59, 130, 246, 0.05) 0%, 
    rgba(99, 102, 241, 0.05) 100%);
  border: 2px solid var(--primary, #3b82f6);
  border-radius: var(--border-radius, 8px);
  transition: all 0.2s ease;
}

.preview-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(59, 130, 246, 0.15);
}

.preview-avatar {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary, #3b82f6), var(--secondary, #6366f1));
  color: white;
  font-weight: 700;
  font-size: 1.25rem;
  border-radius: 50%;
  text-transform: uppercase;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.preview-details {
  flex: 1;
}

.preview-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text, #1e293b);
  margin-bottom: 8px;
}

.preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.preview-id {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
}

.id-label {
  color: var(--text-muted, #94a3b8);
  font-weight: 500;
}

.id-value {
  font-family: 'Courier New', monospace;
  font-weight: 700;
  color: var(--primary, #3b82f6);
  background: white;
  padding: 2px 8px;
  border-radius: 4px;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
  .search-input {
    height: 44px;
    padding: 10px 44px 10px 40px;
    font-size: 0.9375rem;
  }
  
  .student-avatar {
    width: 36px;
    height: 36px;
    font-size: 0.8125rem;
  }
  
  .dropdown-item {
    padding: 10px 14px;
  }
  
  .preview-card {
    padding: 14px;
  }
  
  .preview-avatar {
    width: 48px;
    height: 48px;
    font-size: 1.125rem;
  }
  
  .preview-name {
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .search-input {
    height: 40px;
    padding: 8px 40px 8px 36px;
    font-size: 0.875rem;
  }
  
  .search-icon {
    font-size: 1.125rem;
    left: 12px;
  }
  
  .student-meta {
    flex-direction: column;
    gap: 4px;
  }
  
  .preview-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
}

/* ===== Accessibility ===== */
.search-input:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.3);
  outline-offset: 2px;
}

.dropdown-item:focus-visible {
  outline: 2px solid var(--primary, #3b82f6);
  outline-offset: -2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .search-input {
    border-width: 3px;
  }
  
  .dropdown-item.highlighted {
    border-left-width: 5px;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .search-dropdown,
  .student-preview,
  .dropdown-item,
  .clear-btn {
    animation: none;
    transition: none;
  }
}

/* Ensure parent containers don't clip dropdown */
.form-group:has(.unified-student-search) {
  position: relative;
  overflow: visible !important;
  z-index: 10;
}

.unified-form-section:has(.unified-student-search) {
  overflow: visible !important;
}

/* Ensure details/accordion doesn't interfere with dropdown positioning */
details.filters-accordion {
  position: relative;
  z-index: 1;
}
