/* ============================================
   SPIRE LIGHT — DATASETS INDEX (browse / search / filter)
   Reuses the global tokens, .post-card, .label and .btn styles so it
   stays visually identical to the rest of the site. Filters sit in a
   horizontal dropdown bar: each facet is a button that opens a small
   popover of chips, so results keep the full width and every facet is
   one click away no matter how long its option list grows. Scoped to .dx.
   ============================================ */

.dx-hero {
  padding-top: calc(var(--header-height) + var(--space-9));
  padding-bottom: var(--space-6);
}
.dx-hero .label { margin-bottom: var(--space-3); display: inline-block; }
.dx-hero h1 { margin: 0 0 var(--space-4) 0; }
.dx-hero p.lead {
  margin: 0;
  max-width: 640px;
  font-size: var(--fs-h4);
  color: var(--text-body);
  line-height: var(--lh-body);
}

/* Toolbar: a single clean search bar. Sort lives down in the results
   row, the facets in the filter bar below. */
.dx-toolbar {
  display: flex;
  align-items: stretch;
  gap: var(--space-3);
  margin-top: var(--space-6);
  max-width: 600px;
}
.dx-search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.dx-search svg {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}
.dx-search input {
  width: 100%;
  box-sizing: border-box;
  padding: var(--space-3) var(--space-4) var(--space-3) var(--space-8);
  font-family: inherit;
  font-size: var(--fs-body);
  color: var(--text-heading);
  background: var(--bg-section);
  border: 1px solid var(--border-subtle);
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.dx-search input::placeholder { color: var(--text-dim); }
.dx-search input:hover { border-color: var(--border-light); }
.dx-search input:focus {
  outline: none;
  background: var(--bg-card);
  border-color: var(--accent);
  box-shadow: var(--shadow-glow-sm);
}

.dx-sort {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-small);
  color: var(--text-muted);
}
.dx-sort select {
  font-family: inherit;
  font-size: var(--fs-small);
  color: var(--text-heading);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  padding: var(--space-3) var(--space-6) var(--space-3) var(--space-4);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
}
.dx-sort select:focus { outline: none; border-color: var(--accent); }

/* ── Horizontal filter bar: a row of dropdown facet buttons ──── */
.dx-filterbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-7);
  margin-bottom: var(--space-6);
}
.dx-filterbar:empty { display: none; }
.dx-filterbar__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.dx-facets {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.dx-facet { position: relative; }
.dx-facet__btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  padding: var(--space-3) var(--space-4);
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--text-body);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.dx-facet__btn:hover { border-color: var(--accent); color: var(--accent-bright); }
.dx-facet__chev { color: var(--text-dim); transition: transform var(--dur-fast) var(--ease-out); }
.dx-facet.is-open .dx-facet__btn {
  border-color: var(--accent);
  color: var(--accent-bright);
  box-shadow: var(--shadow-glow-sm);
}
.dx-facet.is-open .dx-facet__chev { transform: rotate(180deg); color: var(--accent-bright); }
.dx-facet.has-active .dx-facet__btn { border-color: var(--accent); color: var(--accent-bright); }
.dx-facet__badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  box-sizing: border-box;
  font-size: var(--fs-xs);
  line-height: 18px;
  text-align: center;
  color: var(--text-white);
  background: var(--accent);
}

.dx-facet__menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  z-index: 30;
  width: max-content;
  min-width: 220px;
  max-width: min(420px, calc(100vw - var(--space-6)));
  max-height: 360px;
  overflow-y: auto;
  padding: var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-card-lg);
}
.dx-facet__menu[hidden] { display: none; }
/* The rightmost facet opens its menu right-aligned so it stays on screen */
.dx-facet--right .dx-facet__menu { left: auto; right: 0; }

.dx-clear {
  margin-left: auto;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: var(--fs-xs);
  color: var(--accent-bright);
  cursor: pointer;
  display: none;
}
.dx-clear.is-visible { display: inline; }
.dx-clear:hover { text-decoration: underline; }

/* Chips inside a facet popover */
.dx-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.dx-chip {
  background: transparent;
  border: 1px solid var(--border-light);
  padding: var(--space-2) var(--space-4);
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--text-body);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}
.dx-chip:hover { border-color: var(--accent); color: var(--accent-bright); }
.dx-chip[aria-pressed="true"] {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent-bright);
  box-shadow: var(--shadow-glow-sm);
}
.dx-chip__count { color: var(--text-dim); margin-left: var(--space-1); font-weight: var(--fw-regular); }
.dx-chip[aria-pressed="true"] .dx-chip__count { color: var(--accent-bright); }

/* Results */
.dx-results__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding-bottom: var(--space-4);
  margin-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}
.dx-count { font-size: var(--fs-small); color: var(--text-muted); margin: 0; }
.dx-count strong { color: var(--text-heading); font-weight: var(--fw-semibold); }

.dx-active { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-5); }
.dx-active:empty { display: none; }
.dx-active__chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--bg-section);
  border: 1px solid var(--border-subtle);
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-3);
  font-size: var(--fs-xs);
  color: var(--text-body);
}
.dx-active__chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  font-size: 1em;
}
.dx-active__chip button:hover { color: var(--text-heading); }

/* Cards: reuse .post-card; add the spec row + meta */
.dx-card__tags { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.dx-card__tags .label { color: var(--accent-bright); }
.dx-card__lang {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin: 0;
  overflow-wrap: anywhere;
}
.dx-card__stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-1);
}
.dx-stat { display: flex; flex-direction: column; gap: var(--space-1); }
.dx-stat__value {
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  color: var(--text-heading);
}
.dx-stat__label {
  font-size: var(--fs-xs);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--text-dim);
}
.dx-card__cta {
  color: var(--text-heading);
  font-weight: var(--fw-semibold);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.post-card:hover .dx-card__cta { color: var(--accent-bright); }

.dx-empty {
  padding: var(--space-9) var(--space-6);
  text-align: center;
  border: 1px dashed var(--border-light);
  background: var(--bg-section);
}
.dx-empty h3 { margin: 0 0 var(--space-2) 0; font-size: var(--fs-h4); color: var(--text-heading); }
.dx-empty p { margin: 0 auto; max-width: 460px; color: var(--text-muted); font-size: var(--fs-small); line-height: var(--lh-body); }
.dx-empty__actions {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--space-5);
}

/* Responsive: the bar wraps on its own; on phones reclaim a little hero
   height and keep popovers within the viewport by left-anchoring and
   capping their width to the content gutter. */
@media (max-width: 600px) {
  .dx-hero { padding-top: calc(var(--header-height) + var(--space-6)); }
  .dx-toolbar { max-width: none; }
  .dx-filterbar__label { width: 100%; }
  .dx-clear { margin-left: 0; }
  .dx-facet__menu,
  .dx-facet--right .dx-facet__menu {
    left: 0;
    right: auto;
    max-width: calc(100vw - var(--space-4));
  }
}

/* Comfortable tap targets for the filter controls on touch devices. */
@media (pointer: coarse) {
  .dx-search input,
  .dx-sort select,
  .dx-facet__btn,
  .dx-chip {
    min-height: 44px;
  }
}
