/* Shared visual contract for static/js/block/search-select.js. */

:where(.block-search-select) {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  color: var(--foreground, var(--text-primary));
  font: inherit;
}

:where(.block-search-select__field) {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

:where(.block-search-select__input) {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: var(--control-h-m);
  border: 1px solid var(--input, var(--border-default));
  border-radius: var(--radius-md, 10px);
  background: var(--background, var(--bg-paper));
  padding: 0 var(--space-10, 40px) 0 var(--space-3, 12px);
  color: var(--foreground, var(--text-primary));
  font: inherit;
  line-height: var(--lh-body);
  appearance: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

:where(.block-search-select__input:hover:not(:disabled)) {
  border-color: var(--muted-foreground, var(--text-muted));
}

:where(.block-search-select__input:focus-visible) {
  border-color: var(--ring, var(--primary));
  outline: 2px solid var(--ring, var(--primary));
  outline-offset: 2px;
}

:where(.block-search-select__input:disabled) {
  background: var(--surface, var(--background, #ffffff));
  background: color-mix(in srgb, var(--foreground, #0f0f0f) 6%, var(--background, #ffffff));
  color: var(--muted-foreground, var(--text-muted));
  cursor: not-allowed;
  opacity: 1;
}

:where(.block-search-select__icon) {
  position: absolute;
  top: 50%;
  right: var(--space-3, 12px);
  display: inline-flex;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  color: var(--muted-foreground, var(--text-muted));
  font-size: 20px;
  line-height: 1;
  pointer-events: none;
  transform: translateY(-50%);
  transition: transform 120ms ease, color 120ms ease;
}

:where(.block-search-select__input[aria-expanded="true"] + .block-search-select__icon) {
  color: var(--foreground, var(--text-primary));
  transform: translateY(-50%) rotate(180deg);
}

:where(.block-search-select__icon svg) {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:where(.block-search-select__popover) {
  z-index: var(--z-popover, 1000);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border, var(--border-default));
  border-radius: var(--radius-md, 10px);
  background: var(--card, var(--background, #ffffff));
  color: var(--card-foreground, var(--foreground, #0f0f0f));
  box-shadow: var(--shadow-lg, 0 16px 36px rgba(17, 17, 17, 0.14));
  scrollbar-gutter: stable;
}

:where(.block-search-select__menu) {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--space-1, 4px);
  width: 100%;
  max-height: 100%;
  margin: 0;
  padding: var(--space-1, 4px);
  background: transparent;
}

/* The popover owns the scroll viewport. Horizon's base menu clips overflow;
   leaving that clipping on the inner flex list hides later options. */
.block-search-select__popover .hz-menu {
  max-height: none;
  overflow: visible;
}

.block-search-select__popover [role="option"],
.block-search-select__menu > [role="option"] {
  flex: 0 0 auto;
}

.block-search-select__menu.hz-menu--floating {
  max-height: var(--block-search-select-height, 320px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.block-search-select__popover .block-search-select__menu.hz-menu--floating {
  max-height: none;
  overflow: visible;
}

:where(.block-search-select__option) {
  box-sizing: border-box;
  position: relative;
  width: 100%;
  min-height: var(--control-h-m);
  justify-content: flex-start;
  border: 0;
  border-radius: var(--radius-sm, 7px);
  background: transparent;
  padding: var(--space-2, 8px) var(--space-9, 36px) var(--space-2, 8px) var(--space-3, 12px);
  color: inherit;
  text-align: left;
  font: inherit;
  line-height: var(--lh-body);
  overflow-wrap: anywhere;
  cursor: pointer;
}

:where(.block-search-select__option:hover:not(:disabled),
  .block-search-select__option.is-focused) {
  outline: 0;
  background: var(--hover-overlay, rgba(15, 23, 42, 0.06));
  color: var(--foreground, var(--text-primary, #0f0f0f));
}

/* attach() also enhances existing page-owned options that intentionally keep
   their local component class. Keep active-descendant focus visible there too. */
:where(.block-search-select__popover [role="option"].is-focused,
  .block-search-select__menu [role="option"].is-focused) {
  outline: 0;
  background: var(--hover-overlay, rgba(15, 23, 42, 0.06));
  color: var(--foreground, var(--text-primary, #0f0f0f));
}

:where(.block-search-select__option[aria-selected="true"],
  .block-search-select__option.is-active) {
  background: var(--surface, var(--background, #ffffff));
  background: color-mix(in srgb, var(--primary, #0074ff) 10%, var(--background, #ffffff));
  color: var(--foreground, var(--text-primary, #0f0f0f));
  font-weight: 700;
}

:where(.block-search-select__option[aria-selected="true"]:hover:not(:disabled),
  .block-search-select__option[aria-selected="true"].is-focused,
  .block-search-select__option.is-active:hover:not(:disabled),
  .block-search-select__option.is-active.is-focused) {
  background: color-mix(in srgb, var(--primary, #0074ff) 16%, var(--background, #ffffff));
  color: var(--foreground, var(--text-primary, #0f0f0f));
}

:where(.block-search-select__option[aria-selected="true"]::after,
  .block-search-select__option.is-active::after) {
  content: "";
  position: absolute;
  top: 50%;
  right: var(--space-3, 12px);
  width: 6px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-62%) rotate(45deg);
}

:where(.block-search-select__option:focus-visible) {
  outline: 2px solid var(--ring, var(--primary));
  outline-offset: -2px;
}

:where(.block-search-select__option:disabled) {
  color: var(--muted-foreground, var(--text-muted));
  cursor: not-allowed;
  opacity: 0.62;
}

:where(.block-search-select__menu .hz-menu-placeholder) {
  padding: var(--space-3, 12px);
  color: var(--muted-foreground, var(--text-muted));
  text-align: center;
  font-size: var(--fs-sm);
}

@media (max-width: 640px) {
  :where(.block-search-select__popover) {
    max-width: calc(100vw - var(--space-4, 16px));
  }

  :where(.block-search-select__option) {
    min-height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :where(.block-search-select__input, .block-search-select__icon) {
    transition: none;
  }
}

@media (forced-colors: active) {
  :where(.block-search-select__input, .block-search-select__popover) {
    border-color: CanvasText;
  }

  :where(.block-search-select__option[aria-selected="true"]::after,
    .block-search-select__option.is-active::after) {
    border-color: HighlightText;
  }

  :where(.block-search-select__option[aria-selected="true"],
    .block-search-select__option.is-active) {
    background: Highlight;
    color: HighlightText;
  }
}
