/* ═══════════════════════════════════════════════════════════════════════
   shared/filter-bar.css
   Unified filter bar component used by HeadlineWatch and PriceWatch.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── FILTER WRAP ── */
.filter-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

/* ── FILTER BAR (horizontal pill row) ── */
.filter-bar {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: var(--filter-height);
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

/* ── SECTOR PILL ── */
.filter-pill {
  font-family: var(--font-sans);
  font-size: var(--type-ui);
  font-weight: 500;
  letter-spacing: var(--tracking-none);
  color: var(--color-subtext);
  appearance: none;
  background: none;
  border: 0;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  padding: 11px 8px 10px;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease;
  user-select: none;
  line-height: 1;
}

.filter-pill:hover {
  color: var(--color-primary);
}

/* "All" / "All sectors" reset pill — always primary color */
.filter-pill#sector-reset,
.filter-pill[data-sector="ALL"] {
  color: var(--color-primary);
}

/* Sector color only applies on selected + hover states.
   Inactive pills stay at --color-subtext (base rule above) for readable contrast. */
.filter-pill.is-selected[data-sector="energy"],
.filter-pill.is-selected[data-sector="chemicals"],
.filter-pill.is-partial[data-sector="energy"],
.filter-pill.is-partial[data-sector="chemicals"],
.filter-pill:hover[data-sector="energy"],
.filter-pill:hover[data-sector="chemicals"] {
  color: var(--color-energy);
}

.filter-pill.is-selected[data-sector="metals_and_mining"],
.filter-pill.is-partial[data-sector="metals_and_mining"],
.filter-pill:hover[data-sector="metals_and_mining"] {
  color: var(--color-metals);
}

.filter-pill.is-selected[data-sector="agriculture"],
.filter-pill.is-selected[data-sector="fertilizers"],
.filter-pill.is-partial[data-sector="agriculture"],
.filter-pill.is-partial[data-sector="fertilizers"],
.filter-pill:hover[data-sector="agriculture"],
.filter-pill:hover[data-sector="fertilizers"] {
  color: var(--color-agri);
}

.filter-pill.is-selected[data-sector="fertilizers_and_agricultural_chemicals"],
.filter-pill.is-partial[data-sector="fertilizers_and_agricultural_chemicals"],
.filter-pill:hover[data-sector="fertilizers_and_agricultural_chemicals"] {
  color: #c47b3a;
}

.filter-pill.is-selected[data-sector="livestock_dairy_and_seafood"],
.filter-pill.is-partial[data-sector="livestock_dairy_and_seafood"],
.filter-pill:hover[data-sector="livestock_dairy_and_seafood"] {
  color: #3d7f8d;
}

.filter-pill.is-selected[data-sector="forest_and_wood_products"],
.filter-pill.is-partial[data-sector="forest_and_wood_products"],
.filter-pill:hover[data-sector="forest_and_wood_products"] {
  color: #8a5b3d;
}

/* Selected state: show underline in current (sector) color */
.filter-pill.is-selected {
  border-bottom-color: currentColor;
}

/* Partial state: dashed underline signals incomplete selection */
.filter-pill.is-partial {
  border-bottom-color: currentColor;
  border-bottom-style: dashed;
}

.filter-pill:focus-visible {
  outline: 2px solid rgba(15, 25, 35, 0.22);
  outline-offset: 2px;
}

/* ── SECTOR PILL ROW (dynamic pills container) ── */
.sector-pill-row {
  display: inline-flex;
  align-items: center;
  gap: 24px;
  min-width: max-content;
  padding-right: 6px;
}

/* ── DIVIDER ── */
.filter-divider {
  width: 1px;
  height: 22px;
  background: var(--color-border);
  flex-shrink: 0;
  margin: 0 4px;
}

/* ── FILTER LAYER (expand/collapse subsector panel) ── */
.filter-layer {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0 28px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-4px);
  transition:
    max-height 220ms ease,
    opacity 180ms ease,
    transform 180ms ease,
    padding 220ms ease;
  border-top: 1px solid transparent;
}

.filter-layer.open {
  max-height: 520px;
  opacity: 1;
  transform: translateY(0);
  padding: 14px 28px 18px;
  border-top-color: var(--color-border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0)),
    var(--color-bg);
}

/* ── SUBSECTOR CHIP ROW ── */
.filter-chip-row {
  display: flex;
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ── SUBSECTOR CHIP ── */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: var(--type-ui);
  font-weight: 500;
  letter-spacing: var(--tracking-none);
  border: 1px solid rgba(15, 25, 35, 0.12);
  background: rgba(255, 255, 255, 0.86);
  color: var(--color-primary);
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    color 150ms ease,
    background 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.filter-chip:hover {
  color: var(--color-primary);
  border-color: rgba(15, 25, 35, 0.24);
  box-shadow: 0 2px 8px rgba(15, 25, 35, 0.05);
}

.filter-chip:focus-visible {
  outline: 2px solid rgba(15, 25, 35, 0.22);
  outline-offset: 2px;
}

/* Count badge */
.filter-chip-count {
  font-family: var(--font-mono);
  font-size: var(--type-meta);
  letter-spacing: var(--tracking-meta);
  color: var(--color-subtext);
}

/* Label inside chip */
.filter-chip-label {
  line-height: 1.2;
}

/* Selected state — uses --sector-accent for sector-colored highlight */
.filter-chip.is-selected {
  color: var(--color-primary);
  border-color: color-mix(in srgb, var(--sector-accent, var(--color-amber)) 42%, transparent);
  background: color-mix(in srgb, var(--sector-accent, var(--color-amber)) 12%, transparent);
}

/* ── SUBSECTOR GROUP (PriceWatch multi-column layout) ── */
.filter-subsector-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px 22px;
}

.filter-subsector-group {
  display: grid;
  min-width: 0;
  gap: 8px;
  align-content: start;
}

.filter-subsector-group-label {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--type-meta);
  letter-spacing: var(--tracking-kicker);
  text-transform: uppercase;
  color: var(--color-subtext);
}

/* ── CLEAR LINK ── */
.filter-layer-clear {
  appearance: none;
  border: 0;
  background: none;
  padding: 2px 4px;
  font-family: var(--font-mono);
  font-size: var(--type-meta);
  letter-spacing: var(--tracking-label);
  color: var(--color-subtext);
  cursor: pointer;
  white-space: nowrap;
  margin-left: auto;
  transition: color 150ms ease;
}

.filter-layer-clear:hover {
  color: var(--color-primary);
}

.filter-layer-clear[hidden] {
  display: none;
}

/* ── SUBSECTOR HINT (shown in "All sectors" state) ── */
.subsector-hint {
  padding: 0 28px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 220ms ease, opacity 180ms ease, padding 220ms ease;
}

.subsector-hint.open {
  max-height: 36px;
  opacity: 1;
  padding: 8px 28px 10px;
  border-top: 1px solid var(--color-border);
}

.subsector-hint-text {
  font-family: var(--font-mono);
  font-size: var(--type-meta);
  letter-spacing: var(--tracking-meta);
  color: var(--color-subtext);
}

/* ── RESPONSIVE ── */
@media (max-width: 840px) {
  .filter-wrap::after {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
    width: 24px;
    height: 52px;
    content: "";
    background: linear-gradient(90deg, rgba(240, 239, 233, 0), var(--color-bg) 82%);
    pointer-events: none;
  }

  .filter-bar {
    min-height: 52px;
    gap: 6px;
    padding: 4px 32px 4px 16px;
    flex-wrap: nowrap;
    scroll-padding-inline: 16px 32px;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
  }

  .filter-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 13px;
    border: 1px solid transparent;
    border-radius: 999px;
  }

  .filter-pill.is-selected {
    border-color: color-mix(in srgb, currentColor 38%, transparent);
    background: color-mix(in srgb, currentColor 10%, transparent);
  }

  .filter-pill.is-partial {
    border-color: color-mix(in srgb, currentColor 38%, transparent);
    border-style: dashed;
    background: color-mix(in srgb, currentColor 7%, transparent);
  }

  .filter-layer.open {
    padding: 12px 16px 16px;
    max-height: min(600px, 62dvh);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .subsector-hint.open {
    padding: 8px 16px 10px;
  }

  .filter-divider {
    margin: 0 2px;
  }

  .sector-pill-row {
    gap: 14px;
    padding-right: 12px;
  }

  .filter-subsector-groups {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .filter-chip-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 1px 24px 4px 1px;
    scroll-padding-inline: 1px 24px;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .filter-chip-row::-webkit-scrollbar {
    display: none;
  }

  .filter-chip {
    min-height: 44px;
    padding: 9px 12px;
    flex: 0 0 auto;
  }

  .filter-layer-clear {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .filter-pill,
  .filter-chip,
  .filter-layer,
  .subsector-hint {
    transition: none;
  }
}
