/**
 * Case-studies filter bar - multi-select dropdowns
 * =========================================================================
 * Styling for the checkbox dropdowns built by cs-multiselect.js. The original
 * <select> is hidden by the script, so nothing here has to fight it.
 */

.a3-cs-ms {
  position: relative;
  display: inline-block;
}

.a3-cs-ms__button {
  display: inline-flex;
  align-items: center;
  gap: 8px;

  min-height: 44px;
  padding: 10px 14px;

  background: #fff;
  border: 1px solid #e4e4e7;
  /* Square, matching the theme's buttons (global.css forces radius 0). */
  border-radius: 0 !important;

  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  color: #52525b;
  cursor: pointer;

  transition: border-color 0.2s ease, color 0.2s ease;
}

.a3-cs-ms__button:hover,
.a3-cs-ms.has-selection .a3-cs-ms__button {
  border-color: var(--primary, #ff6900);
  color: #18181b;
}

/* Count badge, as in the reference: a small pill beside the label. */
.a3-cs-ms__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary, #ff6900);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 20px;
}

.a3-cs-ms__caret {
  display: inline-flex;
  margin-left: auto;
  transition: transform 0.2s ease;
}

.a3-cs-ms__button[aria-expanded="true"] .a3-cs-ms__caret {
  transform: rotate(180deg);
}

.a3-cs-ms__panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;

  min-width: 240px;
  /* Eight rows, then scroll. A row is 38px (9 padding + 20 line + 9), so
   * 8 x 38 + the panel's own 8px top/bottom padding = 320. Anything shorter
   * than that fits with no scrollbar at all. */
  max-height: 320px;
  padding: 8px;

  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 0;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);

  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #c7c7cc transparent;

  /* Opens with a short fade + drop. `hidden` is kept as the closed state for
   * accessibility, so the panel is animated with the [hidden] attribute
   * removed first and a class driving the transition - see cs-multiselect.js.
   * transform-origin at the top keeps it hinged under the button. */
  transform-origin: top center;
  opacity: 0;
  transform: translateY(-10px) scale(0.97);
  transition:
    opacity 0.24s ease,
    transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

/* WebKit needs the parts styled explicitly - a thin track with a rounded
 * thumb, so a long list reads like the reference rather than showing the
 * platform's default chrome. */
.a3-cs-ms__panel::-webkit-scrollbar {
  width: 8px;
}

.a3-cs-ms__panel::-webkit-scrollbar-track {
  background: transparent;
}

.a3-cs-ms__panel::-webkit-scrollbar-thumb {
  background: #c7c7cc;
  border: 2px solid #fff;
  border-radius: 999px;
}

.a3-cs-ms__panel::-webkit-scrollbar-thumb:hover {
  background: #a1a1aa;
}

.a3-cs-ms__panel.is-open {
  opacity: 1;
  transform: none;
}

.a3-cs-ms__panel[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .a3-cs-ms__panel {
    transition: none;
    transform: none;
  }
}

.a3-cs-ms__option {
  display: flex;
  align-items: center;
  gap: 10px;

  padding: 9px 10px;
  border-radius: 0;

  font-size: 14px;
  line-height: 20px;
  color: #3f3f46;
  cursor: pointer;
}

.a3-cs-ms__option:hover {
  background: #f4f4f5;
}

.a3-cs-ms__option input {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--primary, #ff6900);
  cursor: pointer;
}

/* Chips for the active selection, below the bar. */
.a3-cs-chips-bar {
  background: transparent;

  /* The -30px margin below tucks this row up into .a3-cs-filters' padding,
   * and that section is position: relative - so it painted over the chips and
   * swallowed every click. Lifting the row above it restores them. */
  position: relative;
  z-index: 2;
}

/* The row reuses .a3-cs-filters__inner purely for its container width and
 * padding - reset anything visual it carries, or it reads as a second bar. */
.a3-cs-chips-bar .a3-cs-filters__inner {
  background: transparent;
  border: 0;
  box-shadow: none;
  min-height: 0;
  /* The bar's own inner has vertical padding for the filter row; the chip row
   * does not need it, and it was most of the gap under the bar. */
  padding-top: 0;
  padding-bottom: 0;
}

.a3-cs-chips-bar:has(.a3-cs-chips:empty) {
  display: none;
}

.a3-cs-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
  /* The grey bar ends at __inner's bottom (636), but .a3-cs-filters carries
   * a further 30px of padding below that, so the chips were landing 40px
   * under the visible bar. Pulled back up by that 30, leaving 12. */
  margin-top: -30px;
  padding: 12px 0 0;
}

.a3-cs-chips:empty {
  display: none;
}

/* Pill chip with a circular close badge, matching the reference. The square
 * corners elsewhere are the theme's button style; a removable token reads
 * better as a pill, and the round x is what makes it obviously dismissible. */
.a3-cs-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;

  /* !important: global.css sets `button { min-height: 56px; padding: 10px 36px }`
   * which otherwise inflates the chip to 56 tall. */
  height: 32px !important;
  min-height: 32px !important;
  padding: 0 14px !important;

  background: #e4e4e7;
  border: 0;
  border-radius: 999px !important;

  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  color: #3f3f46;
  cursor: pointer;

  transition: background-color 0.2s ease, color 0.2s ease;
}

.a3-cs-chip__x {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 14px;
  height: 14px;
  flex: 0 0 auto;

  /* No disc. A tinted circle on a grey chip just read as a blob with a faint
   * mark in it - the bare glyph is cleaner and legible at this size. */
  background: none;
  color: #71717a;

  transition: color 0.2s ease;
}

.a3-cs-chip:hover,
.a3-cs-chip:focus-visible {
  background: #d4d4d8;
  color: #18181b;
}

.a3-cs-chip:hover .a3-cs-chip__x,
.a3-cs-chip:focus-visible .a3-cs-chip__x {
  color: var(--primary, #ff6900);
}

@media (max-width: 767px) {
  .a3-cs-ms,
  .a3-cs-ms__button {
    width: 100%;
  }

  .a3-cs-ms__panel {
    min-width: 100%;
  }
}

/* =========================================================================
 * Mobile - the filter bar as a stacked panel
 *
 * Below 768 the dropdowns live inside the collapsed "Filter By" panel, so
 * they are 0-wide until it is opened. Once open they should stack full-width
 * rather than sit in a cramped row, and the panels should drop inline instead
 * of floating - an absolutely positioned menu inside a narrow scrolling panel
 * is the usual way this breaks.
 * ========================================================================= */

@media (max-width: 767px) {

  .a3-cs-filters__inner,
  /* The dropdowns live in #a3-cs-filters-groups, not directly in __inner, so
   * the stacking has to be applied there too or they stay in a cramped row. */
  #a3-cs-filters-groups,
  .a3-cs-filters__groups {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
  }

  /* .a3-cs-ms must stay a block: as a flex row it laid the panel out beside
   * the button instead of under it, once the panel went position: static. */
  .a3-cs-ms {
    display: block;
    width: 100%;
  }

  .a3-cs-ms__button {
    display: flex;
    width: 100%;
  }

  .a3-cs-ms__button {
    justify-content: space-between;
    min-height: 48px; /* comfortable tap target */
  }

  /* Inline, not absolute: a floating panel inside a narrow column gets
   * clipped or pushed off-screen. Expanding in flow keeps it readable and
   * lets the page scroll to it. */
  .a3-cs-ms__panel {
    position: static;
    min-width: 0;
    width: 100%;
    max-height: 260px;
    margin-top: 6px;
    box-shadow: none;
    border-color: #e4e4e7;

    /* The open animation stays, but without the drop - there is nothing to
     * hinge from once it is in flow. */
    transform: none;
  }

  .a3-cs-ms__panel.is-open {
    transform: none;
  }

  .a3-cs-ms__option {
    padding: 12px 10px; /* bigger rows for touch */
  }

  /* Chips wrap under the bar and stay tappable. */
  .a3-cs-chips {
    padding-top: 12px;
  }

  .a3-cs-chip {
    height: 34px !important;
    min-height: 34px !important;
  }
}

/* =========================================================================
 * Mobile - open by expanding height, not by fading
 *
 * The panel is position: static below 768, so toggling [hidden] (display:
 * none) snaps the page open in a single frame while the opacity transition
 * runs - which reads as a flicker rather than an animation.
 *
 * So on mobile the panel is never display: none. It stays in flow at
 * max-height 0 with its padding, margin and border collapsed, and expands to
 * its full box when opened. visibility keeps it out of the tab order and the
 * accessibility tree while closed, which display: none was doing before.
 * ========================================================================= */

@media (max-width: 767px) {

  .a3-cs-ms__panel[hidden] {
    display: block;
  }

  .a3-cs-ms__panel {
    max-height: 0;
    margin-top: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;

    opacity: 1;
    visibility: hidden;
    overflow: hidden;

    transition:
      max-height 0.32s cubic-bezier(0.22, 0.85, 0.28, 1),
      padding 0.32s cubic-bezier(0.22, 0.85, 0.28, 1),
      margin 0.32s cubic-bezier(0.22, 0.85, 0.28, 1),
      border-width 0.32s cubic-bezier(0.22, 0.85, 0.28, 1),
      visibility 0s linear 0.32s;
  }

  .a3-cs-ms__panel.is-open {
    max-height: 260px;
    margin-top: 6px;
    padding-top: 8px;
    padding-bottom: 8px;
    border-width: 1px;

    visibility: visible;
    overflow-y: auto;

    transition:
      max-height 0.32s cubic-bezier(0.22, 0.85, 0.28, 1),
      padding 0.32s cubic-bezier(0.22, 0.85, 0.28, 1),
      margin 0.32s cubic-bezier(0.22, 0.85, 0.28, 1),
      border-width 0.32s cubic-bezier(0.22, 0.85, 0.28, 1),
      visibility 0s linear 0s;
  }

  @media (prefers-reduced-motion: reduce) {
    .a3-cs-ms__panel {
      transition: none;
    }
  }
}
