/* ============================================================
 * candycake_cart · cc-select 自研下拉组件样式
 *
 * 目标：替代 bootstrap-select（.selectpicker）的视觉，统一走糖糕绿设计 token，
 *       支持 option.data-content（图片 / SVG / HTML）透传，无侵入替换。
 *
 * 结构（由 cc-select.js progressive enhance 后生成）：
 *   .cc-select
 *   ├── select.cc-select__native  （原生 <select>，aria-hidden + 视觉隐藏，保留 form 提交语义）
 *   ├── button.cc-select__trigger （点击切换菜单）
 *   │   ├── .cc-select__trigger-content  （含图标 / 文字 / data-content HTML）
 *   │   └── .cc-select__chevron
 *   └── .cc-select__menu (role=listbox)
 *       └── .cc-select__option (role=option)[.is-selected][.is-active][.is-disabled]
 *           └── .cc-select__option-content
 * ============================================================ */

/* ---------- 容器 ---------- */
.cc-select {
  position: relative;
  display: inline-flex;
  width: 100%;
  min-width: 0;
  vertical-align: middle;
}

/* 原生 select 视觉隐藏但保留焦点/读屏可达 + form 提交 */
.cc-select__native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  /* 重置浏览器默认尺寸，避免撑高容器 */
  padding: 0;
  margin: 0;
  border: 0;
}

/* ---------- 触发按钮 ---------- */
.cc-select__trigger {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 6px 14px;
  background: #fff;
  border: 1px solid rgba(var(--cc-brand-rgb), .16);
  border-radius: var(--cc-radius-sm);
  color: var(--cc-text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.cc-select__trigger:hover:not(:disabled) {
  border-color: rgba(var(--cc-brand-rgb), .34);
}

.cc-select__trigger:focus,
.cc-select__trigger:focus-visible {
  outline: none;
  border-color: var(--cc-brand);
  box-shadow: 0 0 0 4px rgba(var(--cc-brand-rgb), .12);
}

/* 打开状态 */
.cc-select.is-open .cc-select__trigger {
  border-color: var(--cc-brand);
  box-shadow: 0 0 0 4px rgba(var(--cc-brand-rgb), .12);
}

/* 触发按钮内容区（容纳 data-content 渲染的 HTML） */
.cc-select__trigger-content {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cc-select__trigger-content img,
.cc-select__trigger-content svg {
  flex: 0 0 auto;
  max-height: 20px;
}

/* placeholder 状态 */
.cc-select__trigger.is-empty .cc-select__trigger-content {
  color: var(--cc-muted);
}

/* chevron */
.cc-select__chevron {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--cc-muted);
  font-size: 18px;
  line-height: 1;
  transition: transform .18s ease, color .18s ease;
}

.cc-select.is-open .cc-select__chevron {
  transform: rotate(180deg);
  color: var(--cc-brand-dark);
}

/* 禁用 */
.cc-select.is-disabled .cc-select__trigger,
.cc-select__trigger:disabled {
  cursor: not-allowed;
  background: #f8fafc;
  color: var(--cc-muted);
  border-color: var(--cc-border);
  box-shadow: none;
}

.cc-select.is-disabled .cc-select__chevron {
  color: var(--cc-border);
}

/* 错误态（兼容 .is-invalid / .has-error 包裹） */
.cc-select.is-invalid .cc-select__trigger,
.is-invalid .cc-select__trigger,
.has-error .cc-select__trigger,
.was-validated select.cc-select__native:invalid + .cc-select__trigger {
  border-color: var(--cc-danger);
}

.cc-select.is-invalid .cc-select__trigger:focus,
.is-invalid .cc-select__trigger:focus {
  box-shadow: 0 0 0 4px rgba(220, 38, 38, .14);
}

/* ---------- 下拉菜单 ---------- */
.cc-select__menu {
  position: absolute;
  z-index: 1050;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 100%;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius-sm);
  box-shadow: var(--cc-shadow-soft, 0 10px 28px rgba(15, 95, 71, .08));
  opacity: 0;
  transform: translateY(-4px) scale(.985);
  transform-origin: top center;
  transition: opacity .14s ease, transform .14s ease;
  pointer-events: none;
}

.cc-select.is-open .cc-select__menu {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* 向上展开 */
.cc-select.is-dropup .cc-select__menu {
  top: auto;
  bottom: calc(100% + 6px);
  transform-origin: bottom center;
  transform: translateY(4px) scale(.985);
}

.cc-select.is-dropup.is-open .cc-select__menu {
  transform: translateY(0) scale(1);
}

/* 滚动条美化 */
.cc-select__menu::-webkit-scrollbar { width: 6px; }
.cc-select__menu::-webkit-scrollbar-track { background: transparent; }
.cc-select__menu::-webkit-scrollbar-thumb {
  background: rgba(var(--cc-brand-rgb), .18);
  border-radius: 3px;
}
.cc-select__menu::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--cc-brand-rgb), .32);
}

/* ---------- 选项 ---------- */
.cc-select__option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--cc-text);
  cursor: pointer;
  user-select: none;
  transition: background .14s ease, color .14s ease;
}

.cc-select__option + .cc-select__option {
  margin-top: 2px;
}

.cc-select__option-content {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cc-select__option-content img,
.cc-select__option-content svg {
  flex: 0 0 auto;
  max-height: 20px;
}

/* 右侧勾选标记 */
.cc-select__option-check {
  flex: 0 0 auto;
  display: none;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  color: var(--cc-brand);
  font-size: 16px;
  line-height: 1;
}

.cc-select__option.is-selected .cc-select__option-check {
  display: inline-flex;
}

/* 高亮（键盘 / 鼠标 hover） */
.cc-select__option:hover:not(.is-disabled),
.cc-select__option.is-active:not(.is-disabled) {
  background: var(--cc-brand-bg);
  color: var(--cc-brand-dark);
}

/* 已选 */
.cc-select__option.is-selected {
  background: var(--cc-brand-soft);
  color: var(--cc-brand-dark);
  font-weight: 700;
}

.cc-select__option.is-selected:hover,
.cc-select__option.is-selected.is-active {
  background: rgba(var(--cc-brand-rgb), .18);
}

/* 禁用 */
.cc-select__option.is-disabled {
  color: var(--cc-muted);
  cursor: not-allowed;
  opacity: .65;
}

/* 分组标题（<optgroup label="..."> → 渲染为只读 header） */
.cc-select__group-label {
  padding: 8px 12px 4px;
  font-size: 12px;
  font-weight: 800;
  color: var(--cc-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.cc-select__group-label + .cc-select__option {
  margin-top: 0;
}

/* 分隔线（<option disabled value=""> 单独空值兜底） */
.cc-select__divider {
  height: 1px;
  margin: 6px 8px;
  background: var(--cc-border);
}

/* 空态 */
.cc-select__empty {
  padding: 18px 12px;
  text-align: center;
  color: var(--cc-muted);
  font-size: 13px;
}

/* ---------- 尺寸变体 ---------- */
.cc-select--sm .cc-select__trigger {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}

.cc-select--lg .cc-select__trigger {
  min-height: 48px;
  padding: 10px 16px;
  font-size: 15px;
}

/* ---------- 行内尺寸（Bootstrap col 兼容） ---------- */
.cc-select.form-control {
  padding: 0;
  border: 0;
  height: auto;
  background: transparent;
  box-shadow: none;
}

.cc-select.form-control .cc-select__trigger {
  width: 100%;
}

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .cc-select__menu {
    max-height: 60vh;
  }
}
