/* Searchable selects (select-search.js). The native select stays the closed
   field, so it keeps the page's own field or pill styling. While its panel is
   open the field shows the active state. The panel matches the Oppfølging
   multi select: one search field and a compact list in a floating frame. */
select[aria-expanded="true"]:not([multiple]) {
  border-color: var(--primary);
  color: var(--ink);
  background-color: var(--primary-soft);
}

.pill:has(> select[aria-expanded="true"]) {
  border-color: var(--primary);
  color: var(--ink);
  background: var(--primary-soft);
}

.select-search-panel {
  position: fixed;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-sizing: border-box;
  max-height: 340px;
  padding: 10px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.select-search-panel[hidden] {
  display: none;
}

.select-search-panel .select-search-input {
  flex: none;
  width: 100%;
  min-height: 32px;
  padding-block: 4px;
}

.select-search-list {
  display: grid;
  flex: 0 1 auto;
  align-content: start;
  gap: 2px;
  min-height: 0;
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.select-search-list [role="group"] {
  display: grid;
  gap: 2px;
}

.select-search-group {
  padding: 6px 8px 2px;
  color: var(--muted);
  font: 400 var(--fs-ui-label)/1.4 var(--font-mono);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.select-search-option {
  position: relative;
  padding: 5px 26px 5px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--ink);
  font: 400 var(--fs-ui-small)/1.4 var(--font-mono);
  overflow-wrap: anywhere;
  cursor: pointer;
}

.select-search-option.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* The current value carries a hairline check in the primary colour. */
.select-search-option[aria-selected="true"]::after {
  position: absolute;
  top: 50%;
  right: 11px;
  width: 4px;
  height: 8px;
  border: solid var(--primary);
  border-width: 0 1px 1px 0;
  content: '';
  transform: translateY(-65%) rotate(45deg);
}

.select-search-option[aria-disabled="true"] {
  color: var(--muted);
  cursor: default;
}

.select-search-list [hidden] {
  display: none;
}

.select-search-empty {
  margin: 0;
  padding: 5px 8px;
  color: var(--muted);
  font: 400 var(--fs-ui-small)/1.4 var(--font-mono);
}

@media (pointer: coarse) {
  .select-search-panel .select-search-input {
    min-height: 44px;
  }

  .select-search-option {
    display: flex;
    align-items: center;
    min-height: 44px;
  }
}

/* On a phone the panel spans the screen above its bottom edge, like the
   Oppfølging multi select. The script lifts it above the keyboard. */
@media (max-width: 720px) {
  .select-search-panel {
    top: auto;
    right: 16px;
    bottom: 16px;
    left: 16px;
    width: auto;
    max-height: calc(100dvh - 96px);
  }

  .select-search-list {
    max-height: none;
  }

  .select-search-panel .select-search-input {
    font-size: 16px;
  }
}

@media print {
  .select-search-panel {
    display: none !important;
  }
}
