/* ═══════════════════════════════════════════════════════════════════════════
   ui-select — one dropdown language for every page
   ---------------------------------------------------------------------------
   The native <select> stays in the DOM and keeps its value, its events and the
   geometry its page gives it. This file only unifies the *closed* control
   (caret, spacing, hover/focus/open states) and dresses the custom popup that
   ui-select.js renders in place of the OS listbox.

   Load this stylesheet AFTER the page stylesheet: several rules deliberately
   tie on specificity with per-page select rules and win on source order.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --uisel-radius: 12px;
  --uisel-menu-bg: var(--surface, #fff);
  --uisel-menu-line: var(--line, #e6e6e1);
  --uisel-menu-shadow:
    0 1px 1px rgba(20, 20, 18, .04),
    0 4px 12px rgba(20, 20, 18, .06),
    0 22px 48px rgba(20, 20, 18, .14);
  --uisel-hover: rgba(20, 20, 18, .055);
  --uisel-active: rgba(20, 20, 18, .085);
  --uisel-scroll-thumb: rgba(20, 20, 18, .2);
  --uisel-caret: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.75L6 7.75L9 4.75' fill='none' stroke='%238c8c86' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

[data-theme="dark"] {
  --uisel-menu-shadow:
    0 1px 1px rgba(0, 0, 0, .3),
    0 4px 12px rgba(0, 0, 0, .34),
    0 24px 56px rgba(0, 0, 0, .5);
  --uisel-hover: rgba(255, 255, 255, .07);
  --uisel-active: rgba(255, 255, 255, .11);
  --uisel-scroll-thumb: rgba(255, 255, 255, .22);
  --uisel-caret: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.75L6 7.75L9 4.75' fill='none' stroke='%23a0a099' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ── the closed control ─────────────────────────────────────────────────── */
/* Doubled attribute so this outranks page rules such as
   `.template-route-row .kselect` without resorting to !important.            */
select[data-uiselect][data-uiselect] {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: var(--uisel-caret);
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 12px;
  cursor: pointer;
  text-overflow: ellipsis;
  transition-property: border-color, box-shadow, background-color, color;
  transition-duration: 160ms;
  transition-timing-function: cubic-bezier(.4, 0, .2, 1);
}

select[data-uiselect][data-uiselect]:disabled {
  opacity: .55;
  cursor: not-allowed;
}

select[data-uiselect][data-uiselect]:hover:not(:disabled) {
  border-color: var(--line-2, #d5d5ce);
}

select[data-uiselect][data-uiselect]:focus-visible {
  outline: none;
  border-color: var(--ink, #161614);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(22, 22, 20, .12));
}

/* while the custom popup is open the control reads as pressed */
select[data-uiselect].uiselect-open[data-uiselect] {
  border-color: var(--ink, #161614);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(22, 22, 20, .12));
}

/* ── the popup ──────────────────────────────────────────────────────────── */
.uiselect-menu {
  position: fixed;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  min-width: 168px;
  max-width: min(420px, calc(100vw - 20px));
  padding: 5px;
  border: 1px solid var(--uisel-menu-line);
  border-radius: var(--uisel-radius);
  background: var(--uisel-menu-bg);
  box-shadow: var(--uisel-menu-shadow);
  font-family: var(--sans, system-ui, sans-serif);
  opacity: 0;
  transform: translateY(-4px) scale(.985);
  transform-origin: top center;
  transition: opacity 130ms cubic-bezier(.4, 0, .2, 1), transform 130ms cubic-bezier(.2, .8, .2, 1);
  overscroll-behavior: contain;
}

.uiselect-menu.uiselect-up {
  transform-origin: bottom center;
  transform: translateY(4px) scale(.985);
}

.uiselect-menu.uiselect-in {
  opacity: 1;
  transform: none;
}

/* search ------------------------------------------------------------------ */
/* the hairline keeps scrolled options from colliding with the field */
.uiselect-search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 1px 1px 4px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line, #e6e6e1);
}

.uiselect-search svg {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--faint, #8c8c86);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.uiselect-search input {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 31px;
  border: 1px solid var(--line, #e6e6e1);
  border-radius: calc(var(--uisel-radius) - 5px);
  background: var(--surface-2, #f7f7f5);
  color: var(--ink, #161614);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
}

.uiselect-search input::placeholder {
  color: var(--faint, #8c8c86);
}

.uiselect-search input:focus {
  border-color: var(--line-2, #d5d5ce);
  background: var(--surface, #fff);
}

/* list -------------------------------------------------------------------- */
.uiselect-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--uisel-scroll-thumb) transparent;
  outline: none;
}

.uiselect-list::-webkit-scrollbar {
  width: 9px;
}

.uiselect-list::-webkit-scrollbar-track {
  background: transparent;
}

.uiselect-list::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--uisel-scroll-thumb);
  background-clip: content-box;
}

.uiselect-group {
  padding: 9px 10px 5px;
  color: var(--faint, #8c8c86);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.uiselect-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: calc(var(--uisel-radius) - 5px);
  color: var(--ink, #161614);
  font-size: 13px;
  font-weight: 450;
  line-height: 1.35;
  cursor: pointer;
  user-select: none;
}

/* `display: flex` above would otherwise beat the UA rule for [hidden] */
.uiselect-option[hidden] {
  display: none;
}

.uiselect-option-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.uiselect-check {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

.uiselect-option.is-active {
  background: var(--uisel-hover);
}

.uiselect-option.is-selected {
  font-weight: 600;
}

.uiselect-option.is-selected .uiselect-check {
  opacity: 1;
}

.uiselect-option.is-selected.is-active {
  background: var(--uisel-active);
}

.uiselect-option.is-disabled {
  opacity: .4;
  cursor: not-allowed;
}

.uiselect-empty {
  padding: 14px 10px;
  color: var(--faint, #8c8c86);
  font-size: 12.5px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .uiselect-menu {
    transition: none;
    transform: none;
  }
}
