/* ============================================================
   ui.css —— 三端共用组件库（按钮 / 标签 / 表单 / 表格 / 弹窗 …）
   只依赖 tokens.css 的变量，不写死颜色。
   ============================================================ */

/* ================= 按钮 ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--ctl-h); padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); font-weight: 500; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: #c6cce0; }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 2px 8px rgba(61, 90, 241, .26);
}
.btn--primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn--gold { background: var(--gold); border-color: var(--gold); color: #4a3000; font-weight: 600; }
.btn--gold:hover { background: #e5a716; border-color: #e5a716; color: #4a3000; }
.btn--danger { background: #fff; border-color: #f5c6c2; color: var(--danger); }
.btn--danger:hover { background: var(--danger-bg); border-color: #efa9a2; }
.btn--ghost { background: #fff; }
.btn--plain { background: transparent; border-color: transparent; color: var(--text-2); }
.btn--plain:hover { background: var(--bg-2); border-color: transparent; color: var(--brand); }
.btn--sm { height: var(--ctl-h-sm); padding: 0 10px; font-size: 13px; border-radius: var(--radius-xs); }
.btn--lg { height: var(--ctl-h-lg); padding: 0 22px; font-size: 15px; border-radius: var(--radius); }
.btn--block { width: 100%; }
.btn--icon { width: var(--ctl-h); padding: 0; }
.btn[disabled], .btn.is-disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn.is-loading { color: transparent !important; position: relative; }
.btn.is-loading .ic { visibility: hidden; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: #fff; animation: ui-spin .7s linear infinite;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2); cursor: pointer; position: relative;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); }
.icon-btn__dot {
  position: absolute; top: 6px; right: 6px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--danger); border: 1.5px solid #fff;
}

/* ================= 标签 / 徽标 ================= */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: var(--radius-xs);
  font-size: 12px; font-weight: 500; line-height: 1;
  background: var(--bg-2); color: var(--text-2); white-space: nowrap;
}
.tag--ok { background: var(--ok-bg); color: #0b8a53; }
.tag--warn { background: var(--warn-bg); color: #b96908; }
.tag--danger { background: var(--danger-bg); color: #c93025; }
.tag--info { background: var(--info-bg); color: var(--brand-hover); }
.tag--gold { background: var(--gold-bg); color: #a5701a; }
.tag--outline { background: #fff; border: 1px solid var(--line-2); color: var(--text-2); }
.tag--lg { height: 26px; padding: 0 10px; font-size: 12.5px; }
.tag--dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .85;
}

/* ================= 表单 ================= */
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld__lb { font-size: 12.5px; color: var(--text-3); font-weight: 500; }
.fld__hint { font-size: 12px; color: var(--text-3); }
.fld__err { font-size: 12px; color: var(--danger); }

.input, .select, .textarea {
  width: 100%; min-width: 0; height: var(--ctl-h); padding: 0 11px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: #fff;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:hover, .select:hover, .textarea:hover { border-color: #c6cce0; }
.input:focus, .select:focus, .textarea:focus {
  outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint);
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.input[disabled], .select[disabled] { background: var(--bg-2); color: var(--text-3); cursor: not-allowed; }
.textarea { height: auto; min-height: 88px; padding: 9px 11px; resize: vertical; line-height: 1.6; }
.input--sm, .select--sm { height: var(--ctl-h-sm); font-size: 13px; }

/* 原生 select 去掉系统箭头，用图标库的 chevron 覆盖（跨端外观一致） */
.select { appearance: none; padding-right: 30px; cursor: pointer; }
.select-wrap { position: relative; display: block; min-width: 0; }
.select-wrap > .ic {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none; width: 15px; height: 15px;
}

.search {
  display: flex; align-items: center; gap: 8px; height: var(--ctl-h);
  padding: 0 11px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: #fff; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.search > .ic { color: var(--text-3); }
.search > input {
  flex: 1; min-width: 0; height: 100%; border: 0; background: transparent;
}
.search > input:focus { outline: 0; }
.search > input::placeholder { color: var(--text-4); }
.search--lg { height: var(--ctl-h-lg); border-radius: var(--radius); padding: 0 5px 0 14px; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; }
.radio-row { display: flex; gap: 16px; flex-wrap: wrap; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__tk {
  width: 38px; height: 22px; border-radius: 999px; background: #d3d8e8;
  position: relative; flex: 0 0 auto; transition: background var(--dur) var(--ease);
}
.switch__tk::after {
  content: ""; position: absolute; left: 2px; top: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch__tk { background: var(--ok); }
.switch input:checked + .switch__tk::after { transform: translateX(16px); }

.stepper {
  display: inline-flex; align-items: center; height: var(--ctl-h);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); overflow: hidden; background: #fff;
}
.stepper button {
  width: 34px; height: 100%; border: 0; background: #fff; color: var(--text-2);
  cursor: pointer; font-size: 16px; line-height: 1;
}
.stepper button:hover { background: var(--bg-2); color: var(--brand); }
.stepper input {
  width: 58px; height: 100%; border: 0; text-align: center;
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.stepper input:focus { outline: 0; }

.seg { display: inline-flex; padding: 3px; background: var(--bg-2); border-radius: var(--radius-sm); }
.seg__it {
  padding: 5px 12px; border: 0; border-radius: var(--radius-xs); background: transparent;
  color: var(--text-2); font-size: 13px; cursor: pointer;
}
.seg__it.is-active { background: #fff; color: var(--brand); font-weight: 600; box-shadow: var(--shadow-xs); }

/* ================= 卡片 ================= */
.card {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
}
.card__hd {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.card__hd h2, .card__hd h3 { font-size: 15px; font-weight: 600; }
.card__hd--tabs { padding: 10px 16px; }
.card__bd { padding: 16px; }
.card__bd--flush { padding: 0; }
.card__ft {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line);
}

/* ================= 表格 ================= */
.tbl { width: 100%; font-size: 13.5px; }
.tbl th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--text-2);
  font-size: 12.5px; font-weight: 600; text-align: left; white-space: nowrap;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
}
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: #fafbff; }
.tbl tbody tr.is-selected { background: var(--brand-tint); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl__scroll { overflow-x: auto; }
/* 列多的表（订单）给一个下限宽度：宁可横向滚动，也不要把列挤到换行 */
.tbl--wide { min-width: 1180px; }
/* 宽表：把最后一列（操作）钉在右侧，其余列可以左右滑动查看 */
.tbl--wide th:last-child, .tbl--wide td.td-acts {
  position: sticky; right: 0; z-index: 2;
  background: var(--surface);
  box-shadow: -10px 0 12px -12px rgba(16, 34, 74, .45);
}
.tbl--wide th:last-child { z-index: 3; }
.tbl--wide tbody tr:hover td.td-acts { background: #fafbff; }
.tbl--wide tbody tr.is-selected td.td-acts { background: var(--brand-tint); }
/* 拖拽列宽：表头右缘 6px 热区 + 拖动时的竖直参考线（照参考站 el-table border 的交互） */
.tbl--wide th { overflow: hidden; text-overflow: ellipsis; }
/* 拖窄后内容不许溢出到隔壁列：单元格裁切 + 长文本走省略号/折行 */
.tbl--wide td { overflow: hidden; }
.tbl--wide .progress { min-width: 36px; max-width: 100%; }
.cell-param { display: inline-block; max-width: 100%; color: var(--brand); }
.tbl--wide th.is-col-edge { cursor: col-resize; }
.tbl--wide th.is-col-edge::after {
  content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 2px; background: var(--brand);
}
.col-guide {
  position: fixed; top: 0; bottom: 0; width: 1px; z-index: 300;
  background: var(--brand); pointer-events: none;
}
body.is-col-resizing, body.is-col-resizing * { cursor: col-resize !important; user-select: none; }

/* ================= 订单详情页（照参考站 7 区块） ================= */
.od-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.od-cols > :nth-child(5) { grid-column: span 2; }   /* 订单分红：3 列时占 2 列，填满不留下空 */
.od-time { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; }
.od-time span { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.od-time i { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); flex: 0 0 auto; }
@media (max-width: 1200px) {
  .od-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .od-cols > :nth-child(5) { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .od-cols { grid-template-columns: 1fr; }
  .od-cols > :nth-child(5) { grid-column: auto; }
}
.tbl__acts { display: flex; gap: 4px; align-items: center; }
.tbl-id { font-family: var(--font-num); font-size: 12.5px; color: var(--text-2); }

/* ================= 窄屏：表格自动折成卡片 =================
   宽屏保留表格（密度高、好比对）；640~1024 这档照参考站的做法，**不折卡片**，
   继续用表格 + 横向滚动 + 右侧钉住的「操作」列（参考站 775px 宽就是这么显示会员列表的）。
   只有真正的手机宽度（≤640）才用 td 的 data-label 折成卡片。 */
@media (max-width: 640px) {
  /* 卡片模式忽略 JS 冻结的列宽，整表按容器宽度铺开 */
  .tbl--cards { min-width: 0 !important; width: auto !important; }
  .tbl--cards thead { display: none; }
  .tbl--cards, .tbl--cards tbody { display: block; }
  .tbl--cards tbody tr {
    position: relative; display: block; margin: 12px; padding: 12px 12px 6px;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: #fff; box-shadow: var(--shadow-xs);
  }
  .tbl--cards tbody tr:hover { background: #fff; }
  .tbl--cards tbody tr.is-selected { border-color: var(--brand); background: var(--brand-tint); }
  .tbl--cards tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 6px 0; border: 0; text-align: right; font-size: 13.5px;
  }
  .tbl--cards tbody td::before {
    content: attr(data-label); flex: 0 0 auto;
    color: var(--text-3); font-size: 12.5px; text-align: left;
  }
  .tbl--cards tbody td[data-label=""]::before,
  .tbl--cards .td-main::before,
  .tbl--cards .td-acts::before { display: none; }
  /* 勾选框挪到卡片右上角，不占一行 */
  .tbl--cards tbody td.td-ck { position: absolute; right: 10px; top: 10px; padding: 0; }
  /* 主信息（商品）整行铺开 */
  .tbl--cards tbody td.td-main { display: block; padding: 2px 30px 8px 0; text-align: left; }
  .tbl--cards tbody td.td-acts {
    justify-content: flex-end; gap: 8px; margin-top: 4px; padding-top: 10px;
    border-top: 1px solid var(--line);
  }
  .tbl--cards .cell-goods { min-width: 0; }
  /* 分类树：折叠箭头贴左上角，二级卡片缩进 + 浅底，挂在同一条树上 */
  .tbl--cards .td-caret { justify-content: flex-start; padding: 0 0 4px; }
  .tbl--cards tbody tr.tree-lv2 { margin-left: 20px; background: var(--surface-2); }
  .tbl--cards tbody tr.tree-lv2 > td { background: transparent; }
  /* 描述这类长文本在卡片里改成上下排，不要和标签挤一行 */
  .tbl--cards tbody td.td-desc { display: block; text-align: left; }
  .tbl--cards tbody td.td-desc::before { display: block; margin-bottom: 3px; }
  .tbl--cards td.td-empty { display: block; text-align: center; padding: 0; }
  /* 右上角是勾选框，第一列编号要给让出位置，不然会顶到勾选框上 */
  .tbl--cards tbody td[data-label="订单号"],
  .tbl--cards tbody td[data-label="编号"],
  .tbl--cards tbody td[data-label="商品编号"] { padding-right: 34px; }
  /* 卡片行是 flex，状态列里的进度条会跟标签挤在一行；换行让它单独占一行铺满 */
  .tbl--cards tbody td[data-label="状态"] { flex-wrap: wrap; }
  .tbl--cards tbody td .progress { flex: 1 1 100%; }
  /* 卡片模式下不需要钉住操作列（整行都是一张卡） */
  .tbl--cards th:last-child, .tbl--cards td.td-acts {
    position: static; box-shadow: none; background: transparent;
  }
}

/* 商品单元格：左图右文 */
.cell-goods { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.cell-goods__img {
  width: 38px; height: 38px; border-radius: var(--radius-xs); flex: 0 0 auto;
  background: linear-gradient(150deg, #eef1fe, #f6f7fc); object-fit: cover;
}
.cell-goods__name { font-weight: 500; line-height: 1.4; }
/* 订单列表：商品名不再截断 —— 列宽随名字长度自动延展，超过 300px 折到第二行 */
.tbl--wide .cell-goods__name {
  white-space: normal; word-break: break-word;
}
/* 冻结列宽之前（首次渲染）按最长名字撑开，量完宽度后由拖拽决定；之后统一走折行 */
.tbl--wide:not(.is-frozen) .cell-goods__name { width: max-content; max-width: 300px; }

/* ================= 分页 ================= */
.pager { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager__btn {
  min-width: 32px; height: 32px; padding: 0 9px; border: 1px solid var(--line-2);
  border-radius: var(--radius-xs); background: #fff; color: var(--text-2);
  cursor: pointer; font-variant-numeric: tabular-nums;
}
.pager__btn:hover { border-color: var(--brand); color: var(--brand); }
.pager__btn.is-active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pager__btn[disabled] { opacity: .45; cursor: not-allowed; }
.pager__info { color: var(--text-3); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ================= 页签 / 筛选 chip ================= */
.tabs { display: flex; flex-wrap: wrap; gap: 8px 18px; border-bottom: 1px solid var(--line); }
.tabs__it {
  padding: 10px 2px; border: 0; background: transparent; color: var(--text-2);
  font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs__it:hover { color: var(--brand); }
.tabs__it.is-active { color: var(--brand); border-color: var(--brand); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--radius-pill);
  background: #fff; color: var(--text-2); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.is-active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; }
.chip__n { font-variant-numeric: tabular-nums; opacity: .72; font-size: 12px; }
.chip.is-active .chip__n { opacity: .9; }

/* ================= 下拉菜单 ================= */
.dd { position: relative; }
.dd__menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 184px; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-md); display: none; z-index: 40;
}
.dd.is-open .dd__menu { display: block; animation: ui-pop .14s var(--ease); }
.dd__item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: var(--radius-xs); color: var(--text); cursor: pointer; font-size: 13.5px;
}
.dd__item:hover { background: var(--bg-2); color: var(--brand); }
.dd__item--danger:hover { background: var(--danger-bg); color: var(--danger); }
.dd__item[aria-disabled="true"] { color: var(--text-4); cursor: not-allowed; }
.dd__sep { height: 1px; margin: 5px 4px; background: var(--line); }
.dd__lb { padding: 7px 10px 4px; font-size: 11.5px; color: var(--text-3); }
@keyframes ui-pop { from { opacity: 0; transform: translateY(-4px); } }

/* ================= 弹窗 / 抽屉 ================= */
.modal { position: fixed; inset: 0; z-index: 60; display: none; }
.modal.is-open { display: block; }
.modal__mask {
  position: absolute; inset: 0; background: rgba(21, 29, 60, .45);
  animation: ui-fade .18s var(--ease);
}
.modal__box {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(660px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
  display: flex; flex-direction: column; background: #fff;
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: ui-pop .2s var(--ease); overflow: hidden;
}
.modal--wide .modal__box { width: min(940px, calc(100vw - 32px)); }
/* 小弹窗：两种写法都认（类挂在外层或挂在盒子上）——之前挂在盒子上没生效，弹窗一律 660 偏大 */
.modal--sm .modal__box, .modal__box.modal--sm { width: min(460px, calc(100vw - 32px)); }
.modal__hd {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal__hd h3 { font-size: 16px; font-weight: 600; }
.modal__hd .icon-btn { margin-left: auto; }
.modal__bd { padding: 18px 20px; overflow: auto; }
.modal__ft {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2);
}
@keyframes ui-fade { from { opacity: 0; } }

/* ================= 键值网格（详情用） ================= */
.kv {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.kv__i { background: #fff; padding: 11px 14px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kv__k { font-size: 12px; color: var(--text-3); }
.kv__v { font-size: 13.5px; font-weight: 500; word-break: break-all; }
.kv__i--full { grid-column: 1 / -1; }

/* ================= 空态 / 骨架 / 提示条 ================= */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 52px 20px; color: var(--text-3); text-align: center;
}
.empty .ic { width: 34px; height: 34px; color: var(--text-4); }
.empty b { color: var(--text-2); font-weight: 600; font-size: 14px; }

.skel {
  background: linear-gradient(90deg, #eef0f7 25%, #f6f7fb 37%, #eef0f7 63%);
  background-size: 400% 100%; animation: ui-shimmer 1.4s ease infinite; border-radius: 6px;
}
@keyframes ui-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.note {
  display: flex; align-items: flex-start; gap: 9px; padding: 11px 13px;
  border-radius: var(--radius); background: var(--info-bg); color: #2c3fae; font-size: 13px;
}
.note--warn { background: var(--warn-bg); color: #b96908; }
.note--danger { background: var(--danger-bg); color: #c93025; }
.note--ok { background: var(--ok-bg); color: #0b8a53; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%);
  z-index: 90; display: none; flex-direction: column; align-items: center; gap: 8px;
}
.toast.is-open { display: flex; }
.toast__item {
  display: flex; align-items: center; gap: 8px; padding: 9px 15px;
  background: rgba(27, 36, 64, .94); color: #fff; border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md); font-size: 13.5px; animation: ui-pop .18s var(--ease);
}
.toast__item--danger { background: rgba(201, 48, 37, .96); }

/* ================= 杂项 ================= */
.avatar {
  width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%;
  background: linear-gradient(135deg, #5c78ff, #2b45d8); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
}
.avatar--lg { width: 44px; height: 44px; font-size: 17px; }
.progress { height: 6px; border-radius: 999px; background: var(--bg-2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.progress--ok > i { background: var(--ok); }
.progress--warn > i { background: var(--warn); }
