/* ═══════════════════════════════════════════
   Filter Bar — Dropdown-pill architecture
   ═══════════════════════════════════════════ */

.filter-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  transition: box-shadow var(--transition-normal);
}

.filter-bar.is-scrolled {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}


.filter-bar__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ── Pills row ── */
.fb-pills {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 0;
  overflow: visible;
  padding: 2px 0;
  flex-wrap: wrap;
}

/* ── Pill wrapper (contains pill + popover) ── */
.fb-pill-wrap {
  position: relative;
  flex-shrink: 0;
}

/* ── Dropdown Pill button ── */
.fb-pill {
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  padding: 0 16px !important;
  height: 40px !important;
  font-family: var(--font-family) !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  color: #374151 !important;
  background: #fff !important;
  border: 1.5px solid #d1d5db !important;
  border-radius: 10px !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  transition: all 0.15s ease !important;
  user-select: none !important;
  line-height: 1 !important;
  box-sizing: border-box !important;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04) !important;
}

.fb-pill:hover {
  border-color: var(--color-primary) !important;
  color: var(--color-primary) !important;
  background: rgba(5, 200, 158, 0.04) !important;
  box-shadow: 0 1px 3px rgba(5, 200, 158, 0.12) !important;
}

.fb-pill.is-open {
  border-color: var(--color-primary) !important;
  color: var(--color-primary) !important;
  background: rgba(5, 200, 158, 0.06) !important;
  box-shadow: 0 0 0 3px rgba(5, 200, 158, 0.1) !important;
}

.fb-pill.is-active {
  background: rgba(5, 200, 158, 0.08) !important;
  color: #047857 !important;
  border-color: var(--color-primary) !important;
  font-weight: 600 !important;
}

.fb-pill__icon {
  display: none;
  flex-shrink: 0;
}

.fb-pill__caret {
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}
.fb-pill.is-open .fb-pill__caret {
  transform: rotate(180deg);
}

/* ── Toggle chip (Tilbud) ── */
.fb-toggle {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 16px !important;
  height: 40px !important;
  font-family: var(--font-family) !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  color: #374151 !important;
  background: #fff !important;
  border: 1.5px solid #d1d5db !important;
  border-radius: 10px !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  transition: all 0.15s ease !important;
  user-select: none !important;
  line-height: 1 !important;
  box-sizing: border-box !important;
  flex-shrink: 0 !important;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04) !important;
}

.fb-toggle:hover {
  border-color: var(--color-primary) !important;
  color: var(--color-primary) !important;
  background: rgba(5, 200, 158, 0.04) !important;
  box-shadow: 0 1px 3px rgba(5, 200, 158, 0.12) !important;
}

.fb-toggle.is-active {
  background: rgba(5, 200, 158, 0.08) !important;
  color: #047857 !important;
  border-color: var(--color-primary) !important;
  font-weight: 600 !important;
  box-shadow: 0 0 0 3px rgba(5, 200, 158, 0.1) !important;
}

/* ── Divider ── */
.fb-divider {
  width: 1px;
  height: 22px;
  background: var(--color-border);
  flex-shrink: 0;
}

/* ── Reset button ── */
.fb-reset {
  font-family: var(--font-family);
  font-size: var(--text-xs);
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
  font-weight: var(--weight-medium);
  padding: var(--space-1) var(--space-2);
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--transition-normal);
  pointer-events: none;
  flex-shrink: 0;
}
.fb-reset.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.fb-reset:hover {
  text-decoration: underline;
}

/* ── Count pushes right ── */

.fb-count {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}
.fb-count strong {
  color: var(--color-primary);
  font-weight: var(--weight-semibold);
}

/* ═══════════════════════════════════════════
   Popover
   ═══════════════════════════════════════════ */

.fb-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: var(--z-dropdown);
  min-width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.fb-popover.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.fb-popover--wide {
  min-width: 260px;
}

.fb-popover--right {
  left: auto;
  right: 0;
}

.fb-popover__body {
  padding: var(--space-2) 0;
}

.fb-popover__body--scroll {
  max-height: 300px;
  overflow-y: auto;
}

/* ── Popover item (radio/checkbox row) ── */
.fb-popover__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--color-text);
  transition: background var(--transition-fast);
  user-select: none;
  line-height: 1.3;
}

.fb-popover__item:hover {
  background: rgba(5, 200, 158, 0.04);
}

.fb-popover__item--provider {
  gap: 8px;
}

/* Hide native radio/checkbox */
.fb-popover__item input[type="radio"],
.fb-popover__item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* Custom radio */
.fb-popover__radio {
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  transition: border-color var(--transition-fast);
}
.fb-popover__radio::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  transform: scale(0);
  transition: transform var(--transition-fast);
}
input[type="radio"]:checked ~ .fb-popover__radio {
  border-color: var(--color-primary);
}
input[type="radio"]:checked ~ .fb-popover__radio::after {
  transform: scale(1);
}

/* Custom checkbox */
.fb-popover__check {
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  flex-shrink: 0;
  position: relative;
  transition: all var(--transition-fast);
}
.fb-popover__check::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 5px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform var(--transition-fast);
}
input[type="checkbox"]:checked ~ .fb-popover__check {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
input[type="checkbox"]:checked ~ .fb-popover__check::after {
  transform: rotate(45deg) scale(1);
}

/* Popover text + icon */
.fb-popover__text {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.fb-popover__text svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.fb-popover__count {
  font-size: 12px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* Provider logo in popover */
.fb-popover__logo {
  width: 28px;
  height: 20px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 3px;
}

.fb-popover__empty {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--color-text-muted);
}

/* ── Mobile backdrop (added by JS) ── */
.fb-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.fb-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ═══════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════ */

@media (max-width: 768px) {
  .filter-bar__inner {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 8px;
    padding: 10px 16px;
    align-items: center;
  }

  .filter-bar__inner {
    padding: 10px 16px;
  }

  /* Single row — icons instead of labels save space */
  .fb-pills {
    flex-wrap: nowrap;
    gap: 6px;
    overflow: visible;
  }

  /* Dropdown pills stay on row 1, don't shrink */
  .fb-pill-wrap {
    position: static;
  }

  /* Hide count + reset on mobile */
  .fb-count { display: none; }
  .fb-reset { display: none !important; }

  /* Sort pill: icon only on mobile */
  .fb-sort-wrap .fb-pill__label {
    display: none !important;
  }

  /* Pills fill the full row evenly */
  .fb-pills {
    justify-content: space-between;
  }
  .fb-pill-wrap,
  .fb-toggle {
    flex: 1 1 0;
    min-width: 0;
  }
  .fb-pill {
    width: 100% !important;
    justify-content: center !important;
  }
  .fb-toggle {
    justify-content: center !important;
  }

  .fb-divider {
    display: none;
  }

  /* Show icons, hide labels on dropdown pills */
  .fb-pill__icon {
    display: block !important;
  }
  .fb-pill .fb-pill__label {
    display: none !important;
  }

  /* Active pills: keep icon, add badge via data-count attribute */
  .fb-pill.is-active .fb-pill__label {
    display: none !important;
  }
  .fb-pill.is-active .fb-pill__icon {
    display: block !important;
  }

  /* Active badge — shows count on the pill */
  .fb-pill.is-active::after {
    content: attr(data-count);
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    color: #fff;
    background: var(--color-primary);
    border-radius: 99px;
    pointer-events: none;
  }

  .fb-pill-wrap {
    position: relative;
  }

  .fb-pill,
  .fb-toggle {
    padding: 0 10px !important;
    font-size: 13px !important;
    height: 36px !important;
    flex-shrink: 0 !important;
  }

  /* Tilbud keeps its label + icon */
  .fb-toggle svg {
    display: inline-block;
  }

  /* Everything on one row */
  .fb-toggle { order: initial; }
  .fb-reset { order: initial; }
  .fb-count { order: initial; }
  .fb-sort-wrap { order: initial; }

  /* Popovers become bottom-sheet panels on mobile */
  .fb-popover {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    min-width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 60vh;
    transform: translateY(100%);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    z-index: 9999;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s ease;
  }

  .fb-popover.is-open {
    transform: translateY(0);
  }

  .fb-popover__body {
    padding: 8px 16px 24px;
  }

  .fb-popover__body--scroll {
    max-height: 50vh;
  }

  /* Bottom sheet drag handle */
  .fb-popover::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 10px auto 6px;
  }
}

@media (max-width: 480px) {
  .fb-pill,
  .fb-toggle {
    padding: 0 10px !important;
    font-size: 12px !important;
    height: 34px !important;
  }
}
