/* ============================================================
   filters.css — filter panel (drawer) + chips bar

   Uses the theme tokens declared in styles.css. Not every var() here has
   a fallback, so those tokens must stay declared there.
   ============================================================ */

/* ------------------------------------------------------------
   Site header actions group: filter toggle, programme selector and
   language toggle side by side on the right of the header.
   ------------------------------------------------------------ */
.site-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

/* ------------------------------------------------------------
   Toggle button (lives in the header next to the language toggle)
   ------------------------------------------------------------ */
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.35em 0.85em;
  margin-right: 0.5em;
  background: transparent;
  border: 1px solid var(--border, #ccc);
  border-radius: 4px;
  font: inherit;
  color: var(--fg-default);
  cursor: pointer;
  position: relative;
  transition: background-color 120ms ease;
}
.filter-toggle:hover { background-color: var(--bg-muted); }
.filter-toggle:focus-visible {
  outline: 2px solid var(--accent, #1f6feb);
  outline-offset: 2px;
}
.filter-toggle--active {
  background-color: var(--accent-soft);
  border-color: var(--accent, #1f6feb);
  color: var(--accent, #1f6feb);
  font-weight: 600;
}
.filter-toggle__icon { font-size: 1.1em; line-height: 1; }
.filter-toggle__badge {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 0.4em;
  background-color: var(--accent, #1f6feb);
  color: #fff;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
}

/* ------------------------------------------------------------
   Backdrop (dims the rest of the page when panel is open)
   ------------------------------------------------------------ */
.filter-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 0s 180ms;
  /* Above Leaflet controls (zoom buttons default to z-index 1000 on top of
     map panes that go up to 700). The drawer itself goes one step higher. */
  z-index: 1500;
}
.filter-backdrop--visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 180ms ease;
}

/* ------------------------------------------------------------
   Drawer panel (left side, slides in)
   ------------------------------------------------------------ */
.filter-panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 340px;
  max-width: 92vw;             /* leave a sliver of content on narrow screens */
  background: var(--bg-card);
  border-right: 1px solid var(--border, #ddd);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.06);
  transform: translateX(-100%);
  transition: transform 220ms ease;
  z-index: 1501;               /* one above the backdrop, both above Leaflet */
  display: flex;
  flex-direction: column;
  outline: none;               /* don't show default focus ring on the panel itself */
}
.filter-panel--open { transform: translateX(0); }

.filter-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1em 1.25em;
  border-bottom: 1px solid var(--border, #e5e5e5);
  flex: 0 0 auto;
}
.filter-panel__title {
  margin: 0;
  font-size: 1.1em;
  font-weight: 600;
}
.filter-panel__close {
  background: transparent;
  border: none;
  font: inherit;
  font-size: 1.6em;
  line-height: 1;
  color: var(--fg-muted, #666);
  cursor: pointer;
  padding: 0 0.3em;
  border-radius: 4px;
}
.filter-panel__close:hover { background: var(--bg-muted); }
.filter-panel__close:focus-visible {
  outline: 2px solid var(--accent, #1f6feb);
  outline-offset: 2px;
}

.filter-panel__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5em 1.25em 1.25em;
}

.filter-panel__footer {
  flex: 0 0 auto;
  padding: 0.85em 1.25em;
  border-top: 1px solid var(--border, #e5e5e5);
  background: var(--bg-muted);
}
.filter-panel__reset {
  width: 100%;
  padding: 0.55em 1em;
  background: var(--bg-card);
  border: 1px solid var(--border, #ccc);
  border-radius: 4px;
  font: inherit;
  cursor: pointer;
}
.filter-panel__reset:hover {
  background: var(--bg-muted);
  border-color: var(--fg-muted, #999);
}

/* ------------------------------------------------------------
   Filter category + group
   ------------------------------------------------------------ */
.filter-cat {
  padding: 0.75em 0 0.25em;
  border-bottom: 1px dashed var(--border, #eee);
}
.filter-cat:last-child { border-bottom: none; }
.filter-cat__title {
  margin: 0 0 0.65em;
  font-size: 0.78em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted, #666);
}

.filter-group {
  margin-bottom: 1em;
}
.filter-group:last-child { margin-bottom: 0.5em; }
.filter-group__label {
  font-size: 0.92em;
  font-weight: 600;
  margin-bottom: 0.45em;
  color: var(--fg-default);
}
.filter-group__help {
  font-size: 0.8em;
  color: var(--fg-muted, #777);
  margin: 0.35em 0 0;
  line-height: 1.4;
}

.filter-panel__note {
  font-size: 0.8em;
  color: var(--fg-muted, #777);
  margin: 0 0 1em;
  padding-bottom: 0.75em;
  border-bottom: 1px solid var(--border, #e5e5e5);
  line-height: 1.4;
  font-style: italic;
}

/* ------------------------------------------------------------
   Checkbox list control
   ------------------------------------------------------------ */
.filter-checkboxes {
  list-style: none;
  padding: 0;
  margin: 0;
}
.filter-checkboxes li {
  display: flex;
  align-items: center;
  gap: 0.55em;
  padding: 0.18em 0;
  font-size: 0.92em;
}
.filter-checkboxes input[type="checkbox"] {
  flex: 0 0 auto;
  cursor: pointer;
  margin: 0;
}
.filter-checkboxes label {
  cursor: pointer;
  flex: 1 1 auto;
}

/* ------------------------------------------------------------
   Tri-state (radio group) control
   ------------------------------------------------------------ */
.filter-tri-state {
  display: flex;
  flex-direction: column;
  gap: 0.25em;
  font-size: 0.92em;
}
.filter-tri-state__row {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.1em 0;
}
.filter-tri-state input[type="radio"] {
  margin: 0;
  flex: 0 0 auto;
}
.filter-tri-state label { cursor: pointer; flex: 1 1 auto; }

/* ------------------------------------------------------------
   Facet count badge next to each filter option: the Spanish projects that
   would match with this option on, combined with the OTHER active filters
   (leave-one-out). Empty until facets.js produces counts.
   ------------------------------------------------------------ */
.filter-count {
  flex: 0 0 auto;
  margin-left: auto;
  padding-left: 0.5em;
  font-size: 0.82em;
  color: var(--fg-muted, #888);
  font-variant-numeric: tabular-nums;     /* align thousands columns visually */
  min-width: 2em;
  text-align: right;
}

/* ------------------------------------------------------------
   Year range control
   ------------------------------------------------------------ */
.filter-year-range {
  display: flex;
  align-items: center;
  gap: 0.55em;
}
.filter-year-range__select {
  flex: 1 1 auto;
  padding: 0.3em 0.4em;
  border: 1px solid var(--border, #ccc);
  border-radius: 4px;
  font: inherit;
  background: var(--bg-card);
}
.filter-year-range__dash { color: var(--fg-muted, #777); }

/* ------------------------------------------------------------
   EC range control
   ------------------------------------------------------------ */
.filter-ec-range {
  display: flex;
  align-items: center;
  gap: 0.55em;
}
.filter-ec-range__input {
  flex: 1 1 0;
  min-width: 0;
  padding: 0.3em 0.45em;
  border: 1px solid var(--border, #ccc);
  border-radius: 4px;
  font: inherit;
  background: var(--bg-card);
}
.filter-ec-range__dash { color: var(--fg-muted, #777); }

/* ------------------------------------------------------------
   Placeholder for a filter kind not built yet ("coming soon")
   ------------------------------------------------------------ */
.filter-placeholder {
  padding: 0.45em 0.6em;
  background: var(--bg-muted);
  border: 1px dashed var(--border, #ddd);
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--fg-muted, #888);
  font-style: italic;
}

/* ------------------------------------------------------------
   Chips bar (sticky, between tabs and main content)
   ------------------------------------------------------------ */
.filter-chips-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  align-items: center;
  padding: 0.6em 1em;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border, #e5e5e5);
  position: sticky;
  top: 0;
  z-index: 100;
}
.filter-chips-bar[hidden] { display: none; }

.chip--filter {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.25em 0.4em 0.25em 0.7em;
  background: var(--bg-card);
  border: 1px solid var(--border, #d0d0d0);
  border-radius: 999px;
  font-size: 0.85em;
  line-height: 1.3;
  max-width: 100%;
}
.chip--filter .chip__label {
  font-weight: 600;
  color: var(--fg-muted, #555);
}
.chip--filter .chip__value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 24em;
}
.chip--filter .chip__remove {
  background: transparent;
  border: none;
  font: inherit;
  font-size: 1.15em;
  line-height: 1;
  padding: 0 0.25em;
  margin-left: 0.15em;
  cursor: pointer;
  color: var(--fg-muted, #777);
  border-radius: 999px;
}
.chip--filter .chip__remove:hover {
  background: var(--bg-muted);
  color: var(--fg-default);
}
.chip--filter .chip__remove:focus-visible {
  outline: 2px solid var(--accent, #1f6feb);
  outline-offset: 1px;
}

/* Action chip that clears every active filter at once. Unlike the filter
   chips it has no "×" and a quieter look. Rendered only when 3+ dimension
   chips are present (filter-chips.js). */
.chip--clear-all {
  display: inline-flex;
  align-items: center;
  padding: 0.3em 0.85em;
  background: transparent;
  border: 1px dashed var(--border, #c4c4c4);
  border-radius: 999px;
  font: inherit;
  font-size: 0.82em;
  line-height: 1.3;
  color: var(--fg-muted, #555);
  cursor: pointer;
  margin-left: 0.25em;
}
.chip--clear-all:hover {
  background: var(--bg-card);
  border-color: var(--fg-muted, #777);
  color: var(--fg-default);
}
.chip--clear-all:focus-visible {
  outline: 2px solid var(--accent, #1f6feb);
  outline-offset: 1px;
}

/* Screen-reader only label */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------
   Body lock while panel is open (prevent background scroll)
   ------------------------------------------------------------ */
body.filter-panel-open {
  overflow: hidden;
}

/* ------------------------------------------------------------
   Mobile adjustments — full-width drawer below 600px
   ------------------------------------------------------------ */
@media (max-width: 600px) {
  .filter-panel { width: 100vw; max-width: 100vw; }
  .filter-chips-bar { padding: 0.5em 0.6em; }
  .chip--filter .chip__value { max-width: 12em; }
}
