/* ============================================================================
   public/src/features/home/search.css
   SEARCH SYSTEM - Header Icon → Expandable Bar
   CSS variables at themes.css
   ============================================================================ */

/* ===========================
   HEADER SEARCH TRIGGER BUTTON
   =========================== */

.header-search-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  cursor: pointer;
  transition:
    background 0.2s ease,
    transform 0.2s ease,
    border-color 0.2s ease,
    opacity 0.15s ease;
  z-index: 10;
}

.header-search-btn:hover {
  background: var(--color-background-secondary);
}

.header-search-btn:focus-visible {
  outline: 2px solid white;
  outline-offset: 3px;
}

.header-search-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
}

/* Hidden while the search bar itself is expanded — independent of the
   "no exams in this context" display:none set by SearchManager, so the two
   reasons for hiding this button never fight over the same inline style.
   See openSearchBar()/closeSearchBar() in search-manager.js. */
.header-search-btn.is-bar-open {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

.header-search-icon {
  width: 16px;
  height: 16px;
  object-fit: contain;
  filter: brightness(10);
  opacity: 0.9;
}

/* ===========================
   SEARCH CONTAINER - Collapsible
   =========================== */
.search-container {
  position: absolute;
  left: 24px;
  right: 16px;
  bottom: 16px;
  overflow: visible;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 9;
}

.search-container.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.search-bar-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

/* ===========================
   SEARCH BAR - Compact Design
   =========================== */

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-surface, #ffffff);
  border: 1.5px solid var(--color-border, #e0e0e0);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  transition:
    border-color 0.25s ease,
    box-shadow 0.25s ease;
  max-width: 420px;
  min-width: 260px;
  flex-shrink: 0;
}

.search-icon {
  width: 16px;
  height: 16px;
  opacity: 0.5;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
  object-fit: contain;
}

.search-bar:focus-within .search-icon {
  opacity: 0.85;
}

/* Debounce-window feedback: while a keystroke is queued but not yet
   searched (see handleSearchInput() in search-manager.js), fade the static
   search icon out and a small spinner in, in the same slot — no layout
   shift, and no new element when idle. Cleared as soon as performSearch()
   actually runs. */
.search-bar.is-searching .search-icon {
  opacity: 0;
  position: absolute;
}

.search-spinner {
  display: none;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: var(--color-primary, #0088cc);
  border-radius: 50%;
  opacity: 0.85;
}

.search-bar.is-searching .search-spinner {
  display: block;
  animation: search-spinner-spin 0.7s linear infinite;
}

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

.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-primary, #1a1a1a);
  font-family: inherit;
  padding: 0;
  min-width: 0;
}

.search-input:placeholder-shown {
  color: var(--color-text-tertiary, #999);
  font-weight: 400;
  text-align: right;
}

.search-close,
.search-filters-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--color-text-secondary, #666);
  font-size: 1rem;
  transition:
    background 0.15s ease,
    color 0.15s ease;
  flex-shrink: 0;
  line-height: 1;
}

.search-close:hover,
.search-filters-toggle:hover {
  background: var(--color-background-secondary, #f5f5f5);
  color: var(--color-text-primary, #1a1a1a);
}

.search-close:focus-visible,
.search-filters-toggle:focus-visible {
  outline: 2px solid var(--color-primary, #0088cc);
  outline-offset: 2px;
}

/* Divider between the close/clear button and the filters toggle.
   Previously an absolutely-positioned ::after on .search-close with a
   hardcoded `left: 39px` — since .search-close has no `position`, that
   offset actually resolved against .search-bar (the nearest positioned
   ancestor), not the button itself, so the line drifted out of place
   whenever the bar's padding/gap/icon sizes changed (e.g. the 480px/768px
   breakpoints in this file). A real border on the adjacent button tracks
   the layout automatically and needs no magic number. Margin keeps it from
   touching the icons on either side. */
.search-filters-toggle {
  border-inline-start: 1px solid var(--color-border);
  margin-inline-start: 2px;
  padding-inline-start: 6px;
}

.search-close:hover {
  opacity: 1;
}

/* When there's text to clear, give the merged button a touch more presence
   so it reads as an active, meaningful action rather than a static close icon. */
.search-close.mode-clear {
  opacity: 1;
  color: var(--color-primary, #0088cc);
}

/* Two distinct icons for the merged button's two modes — an X to clear text,
   a downward chevron to collapse the whole bar — so the difference is
   visible at a glance, not just carried by aria-label/title text. Toggled by
   .mode-clear (set in updateCloseButtonMode(), search-manager.js). */
.search-close-icon {
  display: none;
}

.search-close-icon--collapse {
  display: block;
}

.search-close.mode-clear .search-close-icon--collapse {
  display: none;
}

.search-close.mode-clear .search-close-icon--clear {
  display: block;
}

.search-filters-toggle.active {
  background: var(--color-primary-light, #e8f0fe);
  color: var(--color-primary, #0088cc);
}

.filter-icon {
  width: 16px;
  height: 16px;
  display: block;
}

/* ===========================
   SEARCH FILTERS PANEL
   =========================== */
.search-filters {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(360px, 100%);
  max-height: min(70vh, 480px);
  overflow-y: auto;
  padding: 16px;
  background: var(--color-surface, #ffffff);
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  animation: slideDown 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.filter-section {
  margin-bottom: 16px;
}

.filter-section:last-of-type {
  margin-bottom: 0;
}

.filter-section h4 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-secondary, #555);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Filter Chips (Radio buttons styled as chips) */
.filter-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1.5px solid var(--color-border, #e0e0e0);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-primary, #1a1a1a);
  background: var(--color-background, #fff);
  transition: all 0.2s ease;
  user-select: none;
}

.filter-chip:hover {
  border-color: var(--color-primary, #0088cc);
  background: var(--color-primary-light, #e8f0fe);
}

.filter-chip input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.filter-chip input[type="radio"]:checked+span {
  color: var(--color-primary, #0088cc);
}

.filter-chip:has(input[type="radio"]:checked) {
  border-color: var(--color-primary, #0088cc);
  background: var(--color-primary-light, #e8f0fe);
  box-shadow: 0 0 0 2px rgba(0, 136, 204, 0.1);
}

.filter-chip:has(input[type="radio"]:focus-visible) {
  outline: 2px solid var(--color-primary, #0088cc);
  outline-offset: 2px;
}

/* Filter Select Dropdowns */
.filter-select {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--color-border, #e0e0e0);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--color-text-primary, #1a1a1a);
  background: var(--color-background, #fff);
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-select:hover {
  border-color: var(--color-primary, #0088cc);
}

.filter-select:focus {
  outline: none;
  border-color: var(--color-primary, #0088cc);
  box-shadow: 0 0 0 3px var(--color-primary-light, rgba(0, 136, 204, 0.1));
}

/* Filter Actions */
.filter-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border, #e0e0e0);
}

.btn-apply-filters,
.btn-reset-filters {
  flex: 1;
  padding: 8px 16px;
  border-radius: 10px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-apply-filters {
  background: var(--gradient-accent);
  color: white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.btn-apply-filters:hover {
  
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

.btn-reset-filters {
  background: var(--color-background-secondary, #f5f5f5);
  color: var(--color-text-primary, #1a1a1a);
}

.btn-reset-filters:hover {
  background: var(--color-border, #e0e0e0);
}

.btn-apply-filters:focus-visible,
.btn-reset-filters:focus-visible {
  outline: 2px solid var(--color-primary, #0088cc);
  outline-offset: 2px;
}

/* ===========================
   SEARCH RESULTS SUMMARY
   =========================== */
.search-results-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  background: var(--color-primary-light, #e8f0fe);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-primary, #0088cc);
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.search-results-summary #resultCount {
  font-size: 1.1rem;
  font-weight: 800;
  margin-left: 4px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  justify-content: flex-start;
  margin-right: 12px;
}

/* Filter Tags */
.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: white;
  border: 1px solid var(--color-primary, #0088cc);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary, #0088cc);
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-tag:hover {
  background: var(--color-primary, #0088cc);
  color: white;
}

.filter-tag:hover .filter-tag-remove {
  color: white;
}

.filter-tag:focus-visible {
  outline: 2px solid var(--color-primary, #0088cc);
  outline-offset: 2px;
}

.filter-tag-remove {
  font-size: 1.1rem;
  line-height: 1;
  color: var(--color-primary, #0088cc);
  transition: color 0.2s ease;
}

/* ===========================
   RESPONSIVE DESIGN
   =========================== */
@media (max-width: 768px) {
  .header-search-btn {
    width: 32px;
    height: 32px;
    bottom: 0;
    right: 12px;
    bottom: 12px;
  }

  .search-container {
    left: 12px;
    right: 12px;
    bottom: 8px;
    z-index: 11;
  }

  .search-bar-row {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .search-bar {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 5px 9px;
  }

  .search-input {
    font-size: 0.83rem;
  }

  .search-filters {
    padding: 14px;
  }

  .filter-section h4 {
    font-size: 0.75rem;
  }

  .filter-chip {
    padding: 5px 12px;
    font-size: 0.8rem;
  }

  .filter-actions {
    flex-direction: column;
  }

  .btn-apply-filters,
  .btn-reset-filters {
    width: 100%;
  }

  .search-results-summary {
    flex-direction: column;
    flex-basis: 100%;
    align-items: flex-start;
    gap: 10px;
  }

  .active-filters {
    margin-right: 0;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .search-container {
    left: 8px;
    right: 8px;
    bottom: 8px;
  }

  .search-bar {
    padding: 5px 8px;
    gap: 4px;
  }

  .search-icon {
    width: 14px;
    height: 14px;
  }

  .search-input {
    font-size: 0.82rem;
  }

  .search-close,
  .search-filters-toggle {
    width: 24px;
    height: 24px;
    font-size: 0.9rem;
  }

  .filter-icon {
    width: 14px;
    height: 14px;
  }

  .search-filters {
    top: calc(100% + 14px);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: min(60vh, 420px);
    z-index: 20;
  }

  .filter-chip {
    padding: 4px 10px;
    font-size: 0.75rem;
  }

  .filter-select {
    padding: 7px 10px;
    font-size: 0.85rem;
  }

  .btn-apply-filters,
  .btn-reset-filters {
    padding: 7px 14px;
    font-size: 0.85rem;
  }

  .search-results-summary {
    font-size: 0.85rem;
    padding: 8px 12px;
  }

  .search-results-summary #resultCount {
    font-size: 1rem;
  }

  .filter-tag {
    font-size: 0.75rem;
    padding: 2px 7px;
  }

  .header-clip::after {
    width: 100%;
    max-width: 100%;
  }

  .header {
    max-width: 100%;
  }

  .search-container {
    max-width: 100%;
  }
}

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

/* Respect reduced motion preference */
html[data-motion="reduced"] .search-container,
html[data-motion="reduced"] .search-filters,
html[data-motion="reduced"] .search-results-summary,
html[data-motion="reduced"] .search-bar,
html[data-motion="reduced"] .search-close,
html[data-motion="reduced"] .search-filters-toggle,
html[data-motion="reduced"] .filter-chip,
html[data-motion="reduced"] .filter-tag,
html[data-motion="reduced"] .btn-apply-filters,
html[data-motion="reduced"] .btn-reset-filters {
  animation: none;
  transition: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .search-bar {
    border-width: 2px;
  }

  .filter-chip {
    border-width: 2px;
  }

  .filter-tag {
    border-width: 2px;
  }
}

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

.search-bar.searching::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-primary, #0088cc);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ===========================
   DARK THEME ADJUSTMENTS
   =========================== */

[data-theme="dark"] .search-bar,
[data-theme="dark-slate"] .search-bar {
  background: var(--color-surface);
  border-color: var(--color-border);
}

[data-theme="dark"] .search-filters,
[data-theme="dark-slate"] .search-filters {
  background: var(--color-surface);
  border-color: var(--color-border);
}

[data-theme="dark"] .filter-chip,
[data-theme="dark-slate"] .filter-chip {
  background: var(--color-background);
  border-color: var(--color-border);
}

[data-theme="dark"] .filter-select,
[data-theme="dark-slate"] .filter-select {
  background: var(--color-background);
}

[data-theme="dark"] .btn-reset-filters,
[data-theme="dark-slate"] .btn-reset-filters {
  background: var(--color-surface);
}

[data-theme="dark"] .filter-tag,
[data-theme="dark-slate"] .filter-tag {
  background: var(--color-background);
}

[data-theme="dark"] .search-close,
[data-theme="dark-slate"] .search-close {
  border-color: var(--color-border);
}