/* ============================================================================
   SEARCH SYSTEM - Header Icon → Expandable Bar
   ============================================================================ */

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

.header-search-btn {
  position: absolute;
  bottom: 16px;
  right: 16px; /* RTL: left = visual right */
  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: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  transition:
    background 0.2s ease,
    transform 0.2s ease,
    border-color 0.2s ease;
  z-index: 10;
}

.header-search-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.08);
}

.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);
}

.header-search-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  filter: brightness(10); /* Make the icon white on the coloured header */
  opacity: 0.9;
}

/* ===========================
   SEARCH CONTAINER - Collapsible
   =========================== */

.search-container {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-bottom: 0;
  transition:
    max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.25s ease,
    margin-bottom 0.3s ease;
}

.search-container.is-open {
  max-height: 500px; /* large enough for filters panel */
  opacity: 1;
  margin-bottom: 20px;
  animation: none; /* override old fadeInUp */
}

/* ===========================
   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;
}

.search-bar:focus-within {
  border-color: var(--color-primary, #0088cc);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.06),
    0 0 0 3px var(--color-primary-light, rgba(0, 136, 204, 0.1));
}

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

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

.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 {
  color: var(--color-text-tertiary, #999);
  font-weight: 400;
}

.search-clear,
.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-clear:hover,
.search-close:hover,
.search-filters-toggle:hover {
  background: var(--color-background-secondary, #f5f5f5);
  color: var(--color-text-primary, #1a1a1a);
}

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

/* Divider between close and filters buttons */
.search-close {
  opacity: 0.7;
  border-left: 1px solid var(--color-border, #e0e0e0);
  border-radius: 0 6px 6px 0;
  padding-right: 2px;
  margin-right: -2px;
}

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

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

.filter-icon {
  font-size: 0.9rem;
}

/* ===========================
   SEARCH FILTERS PANEL
   =========================== */

.search-filters {
  margin-top: 12px;
  padding: 16px;
  background: var(--color-surface, #ffffff);
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  animation: slideDown 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@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 {
  transform: translateY(-1px);
  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;
  margin-top: 12px;
  padding: 10px 14px;
  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: 34px;
    height: 34px;
    bottom: 12px;
    left: 12px;
  }

  .header-search-icon {
    width: 16px;
    height: 16px;
  }

  .search-bar {
    max-width: 100%;
    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;
    align-items: flex-start;
    gap: 10px;
  }

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

@media (max-width: 480px) {
  .search-container.is-open {
    margin-bottom: 16px;
  }

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

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

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

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

  .filter-icon {
    font-size: 0.85rem;
  }

  .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;
  }
}

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

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .search-container,
  .search-filters,
  .search-results-summary,
  .search-bar,
  .search-clear,
  .search-filters-toggle,
  .filter-chip,
  .filter-tag,
  .btn-apply-filters,
  .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);
}
