/**
 * 自訂下拉（button + listbox）樣式，獨立檔。
 * Pill 內浮層（非選區）：--stat-vr-* 見 common.css；選區沿用本檔預設白底棕字
 *
 * 外層 .vr-select-custom__popover：fixed、陰影與圓角；內層 ul 負責捲動（利於手機觸控）。
 * 手機寬度上限 70% 由 JS 依內容計算；CSS 備援 max-width:70vw。
 */

.vr-select-custom-row {
  box-sizing: border-box;
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

/* 嵌在 pill 內：與前綴同一行、佔滿餘寬（等同 .voter-select-inner），勿用 100% 寬否則會換行 */
.voter-select-wrap .vr-select-custom-row {
  flex: 1 1 0%;
  min-width: 0;
  max-width: 100%;
  width: auto;
}

/* 外層 .voter-select-wrap* 已設 color／背景；內層與原生 select 一致透明底並繼承字色 */
.voter-select-wrap .vr-select-custom {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0;
  background: transparent;
  color: inherit;
}

.voter-select-wrap .vr-select-custom__trigger,
.voter-select-wrap .vr-select-custom__value {
  color: inherit;
}

.vr-select-custom {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  position: relative;
  min-width: 0;
  width: 100%;
  max-width: min(100%, 480px);
  padding: 8px 12px;
  border-radius: 24px;
  border: 0;
  background: #ffefd0;
  color: #8c4f00;
}

.vr-select-custom::after {
  content: "";
  position: absolute;
  right: 2px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(calc(-50% - 2px)) rotate(45deg);
  transform-origin: 50% 50%;
  pointer-events: none;
  transition: transform 0.15s ease;
}

/* 旋轉 225° 後略補垂直；整體與關閉態一併上移 2px */
.vr-select-custom--open.vr-select-custom--drop-down::after,
.vr-select-custom--open.vr-select-custom--drop-up::after {
  transform: translateY(calc(-50% + 1px)) rotate(225deg);
}

.vr-select-custom__prefix {
  flex-shrink: 0;
  color: #8c4f00;
  font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  font-style: normal;
  font-weight: 600;
  line-height: 24px;
  white-space: nowrap;
}

.vr-select-custom__combo {
  position: relative;
  flex: 1 1 0%;
  min-width: 0;
  max-width: 100%;
}

.vr-select-custom__trigger {
  box-sizing: border-box;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0 24px 0 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: #8c4f00;
  font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  font-style: normal;
  font-weight: 600;
  line-height: 24px;
  text-align: left;
}

.vr-select-custom__trigger:focus {
  outline: none;
}

.vr-select-custom__trigger:focus-visible {
  outline: 2px solid #8c4f00;
  outline-offset: 2px;
  border-radius: 4px;
}

.vr-select-custom__value {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vr-select-custom__popover {
  box-sizing: border-box;
  position: fixed;
  z-index: 3000;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: contain;
  border-radius: 16px;
  background: #fff;
  color: #8c4f00;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  border: 1px solid rgba(140, 79, 0, 0.2);
}

.vr-select-custom__popover[hidden] {
  display: none !important;
}

.vr-select-custom__list {
  box-sizing: border-box;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

@media (max-width: 767.98px) {
  .vr-select-custom__popover {
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    max-width: 70vw;
  }

  /* 手機顯示捲軸；translateZ(0) 促進獨立合成層，慣性捲動較不易與整頁互搶 */
  .vr-select-custom__list {
    scrollbar-width: thin;
    scrollbar-color: rgba(140, 79, 0, 0.45) rgba(140, 79, 0, 0.1);
    transform: translateZ(0);
  }

  .vr-select-custom__list::-webkit-scrollbar {
    width: 6px;
  }

  .vr-select-custom__list::-webkit-scrollbar-track {
    background: rgba(140, 79, 0, 0.08);
    border-radius: 3px;
  }

  .vr-select-custom__list::-webkit-scrollbar-thumb {
    background: rgba(140, 79, 0, 0.4);
    border-radius: 3px;
  }
}

/* 測量用：JS 暫加類名以取得 scrollWidth（不限斷點） */
.vr-select-custom__list.vr-select-custom__list--measure-oneline .vr-select-custom__option,
.vr-select-custom__list.vr-select-custom__list--measure-oneline .vr-select-custom__option__label,
.vr-select-custom__list.vr-select-custom__list--measure-oneline .vr-select-custom__group-label__text,
.vr-select-custom__list.vr-select-custom__list--measure-oneline .vr-select-custom__group-label--parent {
  white-space: nowrap;
}

/* statistic2026 選區浮層：僅 lg+ 列表單行；寬度由 voter-select-custom.js 依內容與視口夾住 */
@media (min-width: 992px) {
  #voter-district-jump-list {
    overflow-x: auto;
  }
  #voter-district-jump-list .vr-select-custom__option,
  #voter-district-jump-list .vr-select-custom__option__label,
  #voter-district-jump-list .vr-select-custom__group-label__text,
  #voter-district-jump-list .vr-select-custom__group-label--parent {
    white-space: nowrap;
  }
}

/* 分組列：外層 li 不佔樣式；可點父級為 button */
.vr-select-custom__group-item {
  box-sizing: border-box;
  list-style: none;
  margin: 0;
  padding: 0;
}

.vr-select-custom__group-label--parent {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 10px 12px 10px 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 22px;
  letter-spacing: 0.02em;
  color: #8c4f00;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* 有子項的父級：右側箭頭，展開／收起旋轉（與主觸發器 chevron 一致） */
.vr-select-custom__group-label--parent:not([data-vr-group="placeholder"])::after {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-1px) rotate(45deg);
  opacity: 0.85;
  transition: transform 0.15s ease;
}

.vr-select-custom__group-label--parent.vr-select-custom__group-label--expanded:not(
    [data-vr-group="placeholder"]
  )::after {
  transform: translateY(1px) rotate(225deg);
}

.vr-select-custom__group-label__text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.vr-select-custom__group-label--parent.vr-select-custom__group-label--expanded {
  color: rgba(140, 79, 0, 0.62);
}

.vr-select-custom__group-label--parent.vr-select-custom__group-label--value-selected {
  background: rgba(140, 79, 0, 0.06);
}

.vr-select-custom__group-label--parent:focus {
  outline: none;
}

.vr-select-custom__group-label--parent:focus-visible {
  outline: 2px solid #8c4f00;
  outline-offset: -2px;
}

@media (hover: hover) and (pointer: fine) {
  .vr-select-custom__group-label--parent:hover {
    background: #ffefd0;
  }
}

.vr-select-custom__option {
  margin: 0;
  padding: 10px 14px;
  cursor: pointer;
  font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 22px;
  color: #8c4f00;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* 無分組的選項（如「請選擇」）與父級左對齊；有 data-vr-group 的子項多縮進一字 */
.vr-select-custom__list > .vr-select-custom__option:not([data-vr-group]) {
  padding-left: 14px;
}

.vr-select-custom__list > .vr-select-custom__option[data-vr-group] {
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding-left: calc(14px + 1em);
}

/* 改由 .vr-select-custom__option__prefix--chevron 呈現（父級箭頭式樣 −90°） */
.vr-select-custom__list > .vr-select-custom__option[data-vr-group]::before {
  content: none;
  display: none;
}

/**
 * 手風琴子項前綴：同父級 ::after（8px、右＋底邊框），再整體旋轉 −90°（相對父級 45° 即 rotate(-45deg)）；
 * 由 voter-map.js 注入空 span。
 */
.vr-select-custom__option__prefix--chevron {
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-1px) rotate(-45deg);
  opacity: 0.85;
  pointer-events: none;
}

/* 繁體／简体（chi、sim：body.chinese）：中文字行盒與箭頭光學對齊，前綴再下移 1px */
body.chinese .vr-select-custom__option__prefix--chevron {
  transform: translateY(0) rotate(-45deg);
}

.vr-select-custom__option__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/*
 * 列表 ul 不加垂直 padding；上下留白併入首、末行元素的 padding（與原 list 6px 留白等效）
 * 寫在 padding 簡寫之後以免被覆蓋
 */
.vr-select-custom__list > li:first-child .vr-select-custom__group-label--parent,
.vr-select-custom__list > li:first-child.vr-select-custom__option {
  padding-top: calc(10px + 6px);
}

.vr-select-custom__list > li:last-child .vr-select-custom__group-label--parent,
.vr-select-custom__list > li:last-child.vr-select-custom__option {
  padding-bottom: calc(10px + 6px);
}

/* 滑鼠：懸停 / 按下；觸控列表捲動不套用 :active，改由 JS 加 --tap-press */
@media (hover: hover) and (pointer: fine) {
  .vr-select-custom__option:hover {
    background: #ffefd0;
  }

  .vr-select-custom__option:active {
    background: #ffefd0;
  }
}

/* 觸控輕點（未超過滑動閾值）時由 JS 短暫加上，捲動手勢不會加 */
.vr-select-custom__list > .vr-select-custom__option--tap-press {
  background: #ffefd0 !important;
}

.vr-select-custom__option--active {
  background: #ffefd0;
}

.vr-select-custom__option[aria-selected="true"] {
  background: rgba(140, 79, 0, 0.06);
}

@media (hover: hover) and (pointer: fine) {
  .vr-select-custom__option[aria-selected="true"]:hover,
  .vr-select-custom__option[aria-selected="true"]:active {
    background: #ffefd0;
  }
}

/* 非選區 pill：白底浮層＋各自主色（選區沿用下方元件預設棕黃） */
.voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__popover {
  background: var(--stat-vr-pop-bg, #fff);
  color: var(--stat-vr-pop-fg, #8c4f00);
  border-color: var(--stat-vr-pop-border, rgba(140, 79, 0, 0.2));
}

.voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__group-label--parent {
  color: var(--stat-vr-pop-fg, #8c4f00);
}

.voter-select-wrap:not(.voter-select-wrap-district)
  .vr-select-custom__group-label--parent.vr-select-custom__group-label--expanded {
  color: var(--stat-vr-group-expanded, rgba(140, 79, 0, 0.62));
}

.voter-select-wrap:not(.voter-select-wrap-district)
  .vr-select-custom__group-label--parent.vr-select-custom__group-label--value-selected {
  background: var(--stat-vr-group-value-bg, rgba(140, 79, 0, 0.06));
}

@media (hover: hover) and (pointer: fine) {
  .voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__group-label--parent:hover {
    background: var(--stat-vr-parent-hover, #ffefd0);
  }
}

.voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__group-label--parent:focus-visible {
  outline-color: var(--stat-vr-focus, #8c4f00);
}

.voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__option {
  color: var(--stat-vr-pop-fg, #8c4f00);
}

@media (hover: hover) and (pointer: fine) {
  .voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__option:hover {
    background: var(--stat-vr-opt-hover, #ffefd0);
  }

  .voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__option:active {
    background: var(--stat-vr-opt-active, #ffefd0);
  }
}

.voter-select-wrap:not(.voter-select-wrap-district)
  .vr-select-custom__list
  > .vr-select-custom__option--tap-press {
  background: var(--stat-vr-tap-press, #ffefd0) !important;
}

.voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__option--active {
  background: var(--stat-vr-opt-active, #ffefd0);
}

.voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__option[aria-selected="true"] {
  background: var(--stat-vr-opt-selected, rgba(140, 79, 0, 0.06));
}

@media (hover: hover) and (pointer: fine) {
  .voter-select-wrap:not(.voter-select-wrap-district)
    .vr-select-custom__option[aria-selected="true"]:hover {
    background: var(--stat-vr-opt-hover, #ffefd0);
  }

  .voter-select-wrap:not(.voter-select-wrap-district)
    .vr-select-custom__option[aria-selected="true"]:active {
    background: var(--stat-vr-opt-active, #ffefd0);
  }
}

.voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__trigger:focus-visible {
  outline-color: var(--stat-vr-focus, #8c4f00);
}

@media (max-width: 767.98px) {
  .voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__list {
    scrollbar-color: var(--stat-vr-scroll-thumb, rgba(140, 79, 0, 0.45))
      var(--stat-vr-scroll-track, rgba(140, 79, 0, 0.1));
  }

  .voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__list::-webkit-scrollbar-track {
    background: var(--stat-vr-scroll-track, rgba(140, 79, 0, 0.08));
  }

  .voter-select-wrap:not(.voter-select-wrap-district) .vr-select-custom__list::-webkit-scrollbar-thumb {
    background: var(--stat-vr-scroll-thumb, rgba(140, 79, 0, 0.4));
  }
}
