/* ==========================================================================
   Browse Articles - Filter & Results Styles
   Uses base CSS variables and horizontal scroll pattern from masthead.css
   ========================================================================== */

/* ==========================================================================
   FILTERS SECTION
   ========================================================================== */

.browse-articles-filters {
  margin: 0 0 var(--space-2xl);
  padding: var(--space-xl);
  background: var(--color-bg-alt);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

/* Search Section (separate from filters) */
.search-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.filter-input--search {
  width: 100%; /* Full width of container */
}

/* Horizontal scroll container (mobile) */
.filters-scroll-container {
  position: relative;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  margin-bottom: var(--space-lg);
}

.filters-scroll-container::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Gradient fade on right edge - visual cue for horizontal scroll (like masthead) */
/* Only show in mobile horizontal scroll mode */
@media (max-width: 640px) {
  .filters-scroll-container::after {
    content: '';
    position: sticky;
    float: right; /* Position on right edge */
    right: 0;
    top: 0;
    width: 32px;
    height: 100%;
    margin-right: -32px; /* Pull outside container so it doesn't affect layout */
    background: linear-gradient(to left, var(--color-bg-alt), transparent);
    pointer-events: none; /* Allow clicks through to filters */
    opacity: 0.95;
    z-index: 1;
  }

  /* Optional: Add subtle shadow to enhance the fade effect */
  .filters-scroll-container::before {
    content: '';
    position: sticky;
    float: right; /* Position on right edge */
    right: 0;
    top: 0;
    width: 2px;
    height: 100%;
    margin-right: -2px; /* Pull outside container so it doesn't affect layout */
    background: linear-gradient(to bottom,
      transparent,
      rgba(139, 69, 19, 0.1),
      transparent);
    pointer-events: none;
    z-index: 2;
  }
}

/* Filters grid */
.filters-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-md);
  align-items: flex-end;
  width: max-content;
  min-width: 100%;
}

/* Individual filter group */
.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 160px;
  flex-shrink: 0;
  align-items: flex-start; /* Align labels to start */
}

.filter-group--checkbox {
  min-width: auto;
  flex-direction: row;
  align-items: center;
}

/* Filter labels */
.filter-label {
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-height: 20px; /* Fixed height ensures alignment across all filter groups */
  display: block;
}

.filter-label-checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
}

/* Filter inputs - inherit from base forms.css */
.filter-input,
.filter-select {
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: 1.5; /* Ensure consistent height across all inputs */
  color: var(--color-text);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-base);
  height: auto; /* Let line-height + padding determine height */
  min-height: 42px; /* Ensure minimum height for consistency */
}

.filter-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.1);
}

.filter-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Selected tags pills - full width section below filters */
.selected-tags-pills {
  display: flex;
  flex-wrap: wrap; /* Allow pills to wrap onto multiple lines */
  gap: var(--space-xs);
  padding: var(--space-md) 0;
  margin-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  width: 100%; /* Full width */
}

/* Hide empty pills container */
.selected-tags-pills:empty {
  display: none;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-primary);
  color: var(--color-bg-elevated);
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 600;
  line-height: 1;
  flex-shrink: 0; /* Prevent pills from shrinking */
  max-width: 100%; /* Prevent individual pills from overflowing */
  word-break: break-word; /* Break long tag names if needed */
  overflow-wrap: break-word;
}

.tag-pill-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: var(--radius-full);
  color: var(--color-bg-elevated);
  font-size: 14px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.tag-pill-remove:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Filter actions */
.filter-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
  flex-wrap: wrap;
}

/* Buttons use WordPress button classes - already defined in button.css */

/* ==========================================================================
   RESULTS SECTION
   ========================================================================== */

.browse-articles-results {
  margin: var(--space-2xl) 0;
}

/* Results counter */
.results-counter {
  margin-bottom: var(--space-xl);
  text-align: center;
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.results-error {
  color: var(--color-error);
}

/* Featured result container - uses existing card--featured class */
.featured-result {
  margin-bottom: var(--space-2xl);
}

/* Results grid - uses existing recommended-reading-grid class from recommended-reading.css */
#results-grid {
  /* No custom styles needed - inherits from .recommended-reading-grid */
}

.no-results {
  text-align: center;
  padding: var(--space-3xl);
  color: var(--color-text-muted);
  font-family: var(--font-sans);
}

/* Loading spinner */
.loading-spinner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-xl);
  text-align: center;
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
}

.loading-spinner.is-visible {
  display: flex;
}

.spinner-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

/* Scroll trigger (invisible) */
.scroll-trigger {
  height: 1px;
  margin-top: var(--space-xl);
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS
   ========================================================================== */

@media (max-width: 640px) {
  .browse-articles-filters {
    padding: var(--space-md);
  }

  .search-section {
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
  }

  .filter-group {
    min-width: 140px;
  }
}

@media (min-width: 641px) {
  /* On larger screens, allow filters to wrap */
  .filters-grid {
    flex-wrap: wrap;
    width: auto;
    align-items: stretch; /* Stretch all groups to same height */
  }

  .filters-scroll-container {
    overflow-x: visible;
  }

  /* Ensure filter groups fill available height for proper label alignment */
  .filter-group {
    justify-content: flex-start; /* Labels at top, inputs at bottom */
  }
}
