/* ── Option list always stacks ── */

/* OverlayScrollbars turns .select-options into its host and forces the host to
   flex-direction:row (to lay out viewport + scrollbars). That row overrides our
   Tailwind `flex-col`, so whenever the OS-injected block viewport wrapper is
   absent — e.g. after an Idiomorph re-render destroys/re-creates OS — the options
   become direct flex-row children and render side-by-side. Force column
   unconditionally: OS scrollbars are position:absolute (out of flow), so the
   single in-flow viewport stacks identically with column or row. */
.select-options {
  flex-direction: column !important;
}

/* ── Keyboard-highlighted option ── */

/* select_controller.js (_paintActive) marks the option the arrow keys point at. Unlayered on
   purpose: it must beat the option's own background utilities (see CLAUDE.md, the @layer rule). */
.select-options [data-select-active] {
  background-color: rgba(215, 223, 242, 0.4);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px #283B75;
}

.select-options [data-select-active][aria-selected="true"] {
  background-color: rgba(215, 223, 242, 0.6);
}

/* ── Group divider ── */

/* An option whose `data` carries `group-end` (Form:Select shape #2) closes a group: a line under it
   separates e.g. the popular dialing codes from the alphabetical rest. A pseudo-element, not a border,
   so the option's own rounded hover/selected background is left intact. Hidden while the search box
   filters (`data-filtered`, select_controller.js) — a filtered list has no groups. */
.select-options [data-group-end] {
  position: relative;
  margin-bottom: 9px;
}

.select-options [data-group-end]::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -5px;
  height: 1px;
  /* The control-border grey: the sheet header's #E5E7EB is invisible at 1px on a white panel. */
  background: #A6ACBB;
}

[data-filtered] .select-options [data-group-end] {
  margin-bottom: 0;
}

[data-filtered] .select-options [data-group-end]::after {
  display: none;
}

/* ── Select mobile backdrop ── */

.select-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--z-sheet-backdrop);
  animation: select-fade-in 0.2s ease;
}

@keyframes select-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* The body is already overflow:hidden (base.html.twig), so locking IT does nothing — the real
   scroller is <main data-scroll-root>. Reach it from the body class so the marker stays the
   controller's only contract. See assets/js/scroll_lock.js. */
body.select-mobile-open main[data-scroll-root] {
  overflow: hidden;
}

/* ── Mobile bottom sheet ── */

@media (max-width: 639px) {
  .select-sheet {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
    padding: 0 0 calc(16px + env(safe-area-inset-bottom)) !important;
    box-sizing: border-box !important;
    z-index: var(--z-sheet) !important;
    /* No fixed height: a 2-option select used to get ~400px of empty sheet. The option list has
       its own scroller (.select-options), so the sheet can simply grow to its content and cap.
       dvh, not vh: the shell is 100dvh, and the two disagree exactly when the iOS toolbar
       collapses. */
    max-height: 60dvh !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    animation: select-slide-up 0.25s ease-out;
  }

  @keyframes select-slide-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  .select-sheet-handle {
    width: 40px;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    margin: 12px auto 0;
  }

  .select-sheet-header {
    flex-shrink: 0;
    padding: 8px 16px 12px;
    border-bottom: 1px solid #e5e7eb;
  }

  .select-sheet-title {
    font-size: 15px;
    font-weight: 600;
    color: #191A1C;
    margin-top: 10px;
  }

  .select-sheet-body {
    flex: 1;
    overflow: hidden;
    min-height: 0;
  }

  .select-sheet .select-options {
    max-height: none !important;
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .select-sheet [data-select-target="option"] {
    min-height: 48px;
    padding: 14px 12px;
    /* 16px: below it iOS zooms the page on focus of any control in the same form. */
    font-size: 16px;
  }

  /* The sheet itself has no side padding (the header and the option list bring their own). */
  .select-sheet [data-select-target="search"] {
    flex-shrink: 0;
    width: auto;
    margin: 12px 16px 4px;
  }

  .select-sheet [data-select-target="emptyState"] {
    padding: 8px 24px;
  }
}
