/* ============================================================
   自定义下拉（v3.89）
   为什么有它：原生 <select> 展开后的列表由操作系统绘制，改不动（老板截图里那份灰白色系统菜单
   与整站绿色主题完全不是一套）。做法是**保留原生 <select> 作为取值载体**，只把可见层换成
   button + 面板（JS 见 js/selectui.js），所以老代码里的 `.value`、`change` 监听、表单提交全都不用改。

   两种外观：
     · `data-ui-select="pill"`  → 页眉语言切换那种白药丸（.ui-select-pill）
     · `data-ui-select`（无值） → 表单字段，跟 .contact-form input 同一套圆角/边框（.ui-select-field）

   v3.90 追加后台两种：`data-ui-select="admin"`（与 admin.css 表单控件同规格）、
   `data-ui-select="admin-sm"`（表格行内小号）。后台 select 由 js/admin.js 动态生成者居多，
   组件自带 MutationObserver，新插入的带标记 select 会自动接管，后台不用到处调 enhance()。

   ⚠️ 本文件必须自带变量兜底：catalogue.html 只引 css/catalogue.css，**不引 style.css**。
   ============================================================ */

/* ---------------- 通用外壳 ---------------- */
.ui-select {
  position: relative;
  display: inline-block;
  vertical-align: middle;
}

/* 原生 select 留在 DOM 里（取值 + 表单提交 + change 事件），视觉上收成 1px 透明 */
.ui-select > select {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.ui-select-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line, #d4e7d8);
  background: var(--white, #fff);
  color: var(--ink, #17202e);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.ui-select-btn:focus-visible {
  outline: none;
  border-color: var(--blue, #0a8f47);
  box-shadow: 0 0 0 3px rgba(10, 143, 71, .12);
}
.ui-select-cur {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ui-select-caret {
  flex: 0 0 auto;
  width: 10px;
  height: 6px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%230a8f47' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat center / 10px 6px;
  transition: transform .18s ease;
}
.ui-select.is-open .ui-select-caret { transform: rotate(180deg); }
.ui-select.is-disabled { opacity: .55; }
.ui-select.is-disabled .ui-select-btn { cursor: not-allowed; }

/* ---------------- 药丸（页眉语言切换） ---------------- */
.ui-select-pill .ui-select-btn {
  border-radius: 20px;
  padding: 7px 14px 7px 14px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--blue, #0a8f47);
  gap: 10px;
}
.ui-select-pill .ui-select-btn:hover { border-color: var(--blue, #0a8f47); }
.ui-select-pill .ui-select-cur { font-weight: 700; }

/* 打印目录页：深绿工具条上的白药丸（配色与 css/catalogue.css 的 .cat-bar 一致） */
.cat-bar .ui-select-pill .ui-select-btn {
  border-color: transparent;
  border-radius: 20px;
  padding: 6px 13px 6px 13px;
  font: 700 12.5px/1.35 var(--sans, "Microsoft YaHei", Arial, sans-serif);
  color: var(--green, #0a8f47);
}
.cat-bar .ui-select-pill .ui-select-btn:hover { border-color: var(--lime, #a8f060); }
.cat-bar .ui-select-pill .ui-select-btn:focus-visible { box-shadow: 0 0 0 2px rgba(168, 240, 96, .6); }

/* ---------------- 表单字段（咨询类型） ---------------- */
.ui-select-field { display: block; width: 100%; }
.ui-select-field .ui-select-btn {
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14.5px;
  min-height: 46px;
}
.ui-select-field .ui-select-btn:hover { border-color: var(--blue, #0a8f47); }

/* ---------------- 后台（v3.90，与 css/admin.css 的表单控件同规格） ----------------
   admin  = .form-field input 那一套（1px 边线 / 圆角 8 / 10px 12px / 13.5px / 聚焦绿环）
   admin-sm = 表格里那种行内小号（.pf-inline-cat 所在 <td>），别把行高顶起来 */
.ui-select-admin .ui-select-btn {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  min-height: 40px;
}
.ui-select-admin .ui-select-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(10, 143, 71, .1);
}
.ui-select-admin-sm { max-width: 100%; }
.ui-select-admin-sm .ui-select-btn {
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 12.5px;
  min-height: 0;
  gap: 6px;
}
.ui-select-admin-sm .ui-select-caret { width: 9px; height: 5px; }
/* 后台各种「和别的控件并排」的容器里，外壳要能跟着伸长、不许撑破 */
.admin-main .ui-select { min-width: 0; }
.form-field .ui-select,
.img-pick .ui-select,
.multi-tools .ui-select,
.spec-row .ui-select { flex: 1 1 auto; min-width: 0; width: 100%; }
.media-toolbar .ui-select { flex: 0 0 auto; }
.media-toolbar .ui-select-admin .ui-select-btn { min-height: 34px; padding: 6px 11px; font-size: 13px; }

/* ---------------- 弹出面板（挂到 body，固定定位，避免被 overflow 裁掉） ---------------- */
.ui-select-menu {
  position: fixed;
  z-index: 400;
  background: var(--white, #fff);
  border: 1px solid var(--line, #d4e7d8);
  border-radius: 12px;
  box-shadow: 0 18px 44px rgba(5, 61, 28, .18);
  padding: 6px;
  max-height: 280px;
  max-width: calc(100vw - 16px);   /* 选项文字长时面板自然变宽，但不许超出屏幕 */
  overflow-y: auto;
  overscroll-behavior: contain;
  display: none;
}
.ui-select-menu.is-open { display: block; }
.ui-select-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink, #17202e);
  padding: 9px 12px;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ui-select-opt > span { overflow: hidden; text-overflow: ellipsis; }
.ui-select-opt:hover,
.ui-select-opt.is-active { background: var(--sky, #ebf7ef); color: var(--blue, #0a8f47); }
.ui-select-opt[aria-selected="true"] { color: var(--blue, #0a8f47); font-weight: 800; }
.ui-select-opt[aria-selected="true"]::after {
  content: "";
  margin-left: auto;
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Cpath d='M1.5 6.5l3 3 6-7' stroke='%230a8f47' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / 12px 12px;
}

/* 打开时按钮描边高亮，给出「它连着下面这块」的视觉暗示 */
.ui-select.is-open .ui-select-btn { border-color: var(--blue, #0a8f47); }

/* ---------------- 窄屏 ---------------- */
@media (max-width: 860px) {
  .ui-select-pill .ui-select-btn { padding: 5px 8px; font-size: 11px; max-width: 84px; }
  .cat-bar .ui-select-pill .ui-select-btn { padding: 6px 11px; font-size: 12px; max-width: none; }
}
@media (max-width: 640px) {
  .ui-select-pill .ui-select-btn { padding: 4px 6px; font-size: 10px; max-width: 74px; }
  .ui-select-pill .ui-select-caret { display: none; }
  .ui-select-menu { max-height: 60vh; }
  .ui-select-opt { font-size: 14px; padding: 11px 12px; }
}
