/* ==========================================================================
   components.css — 可复用组件
   所有组件只引用 tokens 层的变量，不写死颜色与尺寸。
   组件之间不互相依赖，可以按任意顺序在页面里组合。
   ========================================================================== */

@layer components {

/* ==========================================================================
   1. 卡片 / 面板
   ========================================================================== */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card--flush { border: none; background: transparent; }
.card--pad { padding: var(--space-5); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.card-head--plain { border-bottom: none; padding-bottom: 0; }

.card-head-text { min-width: 0; }
.card-head-text h3 {
  font-size: var(--text-md);
  font-weight: var(--weight-semi);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.card-head-text p {
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.card-head-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.card-body { padding: var(--space-5); }
.card-body--tight { padding: var(--space-4); }
.card-body--flush { padding: 0; }

.card-foot {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
}

/* 可折叠卡片 */
.card-head[data-collapsible] { cursor: pointer; user-select: none; }
.card-head[data-collapsible]:hover { background: var(--color-surface-2); }
.collapse-caret {
  width: 16px; height: 16px; flex: none;
  color: var(--color-text-subtle);
  transition: transform var(--dur-base) var(--ease-out);
}
.card.is-collapsed .collapse-caret { transform: rotate(-90deg); }
.card.is-collapsed .card-body,
.card.is-collapsed .card-foot { display: none; }

/* ==========================================================================
   2. 按钮
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-h);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.btn svg { width: 16px; height: 16px; flex: none; stroke-width: 1.8; }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

/* --- 主要 --- */
.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-invert);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:active { transform: translateY(0.5px); }

/* --- 次要（描边）--- */
.btn-outline {
  background: var(--color-surface);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-soft); }

/* --- 幽灵（无边框）--- */
.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover { background: var(--color-surface-sunken); color: var(--color-text); }

/* --- 语义色 --- */
.btn-success { background: var(--success-500); color: #fff; }
.btn-success:hover { background: var(--success-600); }
.btn-danger { background: var(--danger-500); color: #fff; }
.btn-danger:hover { background: var(--danger-600); }
.btn-danger-soft { background: var(--danger-50); color: var(--danger-600); }
.btn-danger-soft:hover { background: var(--danger-100); }
.btn-gold { background: var(--gold-400); color: #3a2a00; }
.btn-gold:hover { background: var(--gold-500); }

/* --- 尺寸 --- */
.btn-sm { height: var(--control-h-sm); padding: 0 var(--space-3); font-size: var(--text-sm); gap: 4px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: var(--control-h-lg); padding: 0 var(--space-6); font-size: var(--text-md); }
.btn-block { width: 100%; }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: var(--control-h-sm); }

/* --- 按钮组（连体按钮）--- */
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; border-color: var(--color-border-strong); }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.btn-group .btn:hover, .btn-group .btn.is-active { z-index: 1; position: relative; }
.btn-group .btn.is-active {
  background: var(--color-primary-soft);
  border-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: var(--weight-semi);
}

/* ==========================================================================
   3. 表单
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }

.field-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}
.field-label .req { color: var(--danger-500); }
.field-label .tag-auto { margin-left: auto; }

.field-hint {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  line-height: var(--leading-snug);
}
.field-error {
  font-size: var(--text-xs);
  color: var(--danger-600);
  line-height: var(--leading-snug);
}

.input,
.select,
.textarea {
  width: 100%;
  height: var(--control-h);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-base);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
.textarea { height: auto; min-height: 76px; padding: var(--space-2) var(--space-3); line-height: var(--leading-snug); }

.input:hover, .select:hover, .textarea:hover { border-color: var(--color-text-subtle); }

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.input::placeholder, .textarea::placeholder { color: var(--color-text-subtle); }

.input[readonly], .input:disabled, .select:disabled, .textarea:disabled {
  background: var(--color-surface-sunken);
  color: var(--color-text-muted);
  cursor: not-allowed;
  border-color: var(--color-border);
}
/* 自动计算字段：视觉上区分"系统填的"和"我填的" */
.input[data-auto="true"] {
  background: var(--color-primary-soft);
  border-color: var(--brand-200);
  color: var(--brand-800);
  font-weight: var(--weight-medium);
}

.input-lg, .select-lg { height: var(--control-h-lg); padding: 0 var(--space-4); font-size: var(--text-md); }
.input-sm, .select-sm { height: var(--control-h-sm); font-size: var(--text-sm); padding: 0 var(--space-2); }

/* select 自绘箭头（各浏览器默认箭头差异太大） */
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237c8494' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 16px;
}
html[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa1ad' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* 输入前缀/后缀（¥、天） */
.input-affix { position: relative; display: flex; align-items: center; }
.input-affix .input { padding-left: 26px; }
.input-affix .affix {
  position: absolute;
  left: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
  pointer-events: none;
}
.input-affix .affix--suffix { left: auto; right: var(--space-3); }
.input-affix .input--has-suffix { padding-left: var(--space-3); padding-right: 32px; }

/* 输入组：输入框 + 按钮贴在一起 */
.input-group { display: flex; gap: var(--space-2); align-items: stretch; }
.input-group .input { flex: 1; min-width: 0; }
.input-group .btn { flex: none; }

/* 带图标的搜索框 */
.search-box { position: relative; display: flex; align-items: center; min-width: 0; }
.search-box svg {
  position: absolute;
  left: var(--space-3);
  width: 16px; height: 16px;
  color: var(--color-text-subtle);
  pointer-events: none;
}
.search-box .input { padding-left: 36px; }
.search-box .search-clear {
  position: absolute;
  right: var(--space-2);
  display: grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  color: var(--color-text-subtle);
}
.search-box .search-clear:hover { background: var(--color-surface-sunken); color: var(--color-text); }
.search-box .search-clear svg { position: static; width: 14px; height: 14px; }

/* 复选框 / 单选框 */
.check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-base);
  cursor: pointer;
  user-select: none;
  min-height: 24px;
}
.check input[type="checkbox"],
.check input[type="radio"] {
  width: 16px; height: 16px;
  flex: none;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* 开关 */
.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  width: 40px; height: 22px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  transition: background-color var(--dur-base) var(--ease-out);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur-base) var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--color-primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--shadow-focus); }

/* 分段控件（替代单选按钮组） */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
}
.segmented button {
  height: 28px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.segmented button:hover { color: var(--color-text); }
.segmented button[aria-pressed="true"],
.segmented button.is-active {
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: var(--weight-semi);
  box-shadow: var(--shadow-xs);
}

/* 表单栅格 */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr));
  gap: var(--space-4);
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-full { grid-column: 1 / -1; }

.form-section + .form-section {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px dashed var(--color-border);
}
.form-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

/* 筛选栏 */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: var(--space-3);
  align-items: end;
}
.filter-bar .filter-search { grid-column: span 2; }
.filter-bar .filter-actions { display: flex; gap: var(--space-2); align-items: center; }

@media (max-width: 767px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: span 1; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar .filter-search { grid-column: span 2; }
  /* 移动端表单控件加大到触控安全高度 */
  .input, .select { height: var(--control-h-lg); }
}

/* ==========================================================================
   4. 徽章 / 状态
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.5;
  white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }

.badge-neutral { background: var(--color-surface-sunken); color: var(--color-text-muted); }
.badge-primary { background: var(--color-primary-soft); color: var(--brand-700); }
.badge-success { background: var(--success-50); color: var(--success-700); }
.badge-warning { background: var(--warning-50); color: var(--warning-700); }
.badge-danger  { background: var(--danger-50);  color: var(--danger-700); }
.badge-gold    { background: var(--gold-50);    color: var(--gold-700); }

.badge-dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* 金额文本 */
.amount { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.amount-pos { color: var(--color-pos); }
.amount-neg { color: var(--color-neg); }
.amount-muted { color: var(--color-text-subtle); }
.amount-strong { font-weight: var(--weight-semi); }

/* 数值单位后缀 */
.unit { font-size: 0.85em; color: var(--color-text-subtle); font-weight: var(--weight-normal); margin-left: 1px; }

/* ==========================================================================
   5. 指标卡片
   ========================================================================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
  gap: var(--space-3);
}

.stat {
  position: relative;
  padding: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  min-width: 0;
}
.stat--accent { border-color: var(--brand-200); background: linear-gradient(180deg, var(--brand-50), var(--color-surface)); }
.stat--gold { border-color: var(--gold-200); background: linear-gradient(180deg, var(--gold-50), var(--color-surface)); }

.stat-top {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-icon {
  width: 28px; height: 28px;
  flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  color: var(--color-text-muted);
}
.stat-icon svg { width: 15px; height: 15px; stroke-width: 1.8; }
.stat-icon[data-tone="primary"] { background: var(--brand-50); color: var(--brand-600); }
.stat-icon[data-tone="success"] { background: var(--success-50); color: var(--success-600); }
.stat-icon[data-tone="warning"] { background: var(--warning-50); color: var(--warning-600); }
.stat-icon[data-tone="danger"]  { background: var(--danger-50);  color: var(--danger-600); }
.stat-icon[data-tone="gold"]    { background: var(--gold-50);    color: var(--gold-600); }

.stat-icon--lg { width: 36px; height: 36px; border-radius: var(--radius-lg); }
.stat-icon--lg svg { width: 18px; height: 18px; }

.stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  word-break: break-all;
}
.stat-value--sm { font-size: var(--text-lg); }
.stat-sub {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
}

/* 卡片右上角跳转链接 */
.stat-link {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  color: var(--color-text-subtle);
}
.stat-link:hover { color: var(--color-primary); }
.stat-link svg { width: 15px; height: 15px; }

/* ==========================================================================
   6. 表格
   核心用法：<div class="table-wrap"><table class="table">…</table></div>
   移动端由 .table--stack 转为"每条记录一张卡"（见下方 view 层说明）
   ========================================================================== */

.table-wrap {
  width: 100%;
  overflow: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  font-size: var(--text-sm);
  border-collapse: separate;
  border-spacing: 0;
  min-width: 640px;
}
.table--auto { min-width: 0; }

.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: var(--space-3);
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  color: var(--color-text-muted);
  white-space: nowrap;
  text-align: left;
}

.table tbody td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color var(--dur-fast) var(--ease-out); }
.table tbody tr:hover { background: var(--color-surface-2); }

/* 密集模式 */
.table--dense thead th { padding: var(--space-2) var(--space-3); }
.table--dense tbody td { padding: var(--space-2) var(--space-3); }

/* 合计行 */
.table tfoot td {
  padding: var(--space-3);
  background: var(--color-surface-sunken);
  border-top: 1px solid var(--color-border);
  font-weight: var(--weight-semi);
  position: sticky;
  bottom: 0;
}

/* 列对齐与截断 */
.table .col-num { text-align: right; }
.table .col-center { text-align: center; }
.table .col-actions { text-align: right; white-space: nowrap; }
.table .truncate {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 首列吸左（横向滚动时保持参照物） */
.table--sticky-first td:first-child,
.table--sticky-first th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--color-surface);
  box-shadow: 1px 0 0 var(--color-border);
}
.table--sticky-first thead th:first-child { z-index: 3; background: var(--color-surface-2); }
.table--sticky-first tbody tr:hover td:first-child { background: var(--color-surface-2); }

/* 表格上方的工具条 */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.table-toolbar-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* 行内可编辑单元格 */
.cell-edit {
  width: 100%;
  height: var(--control-h-sm);
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: var(--text-sm);
  color: inherit;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.cell-edit:hover { border-color: var(--color-border-strong); background: var(--color-surface); }
.cell-edit:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: var(--shadow-focus);
}

/* ==========================================================================
   7. 移动端表格 → 卡片列表
   同一份列定义同时生成 table 与 card 两种结构，用 CSS 切换显示。
   这样"哪些字段重要"只在一处定义，不会出现两套数据渲染逻辑不同步。
   ========================================================================== */

.record-cards { display: none; }

@media (max-width: 767px) {
  .table-wrap--stackable { display: none; }
  .record-cards { display: flex; flex-direction: column; }

  .record-card {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-2) var(--space-3);
  }
  .record-card:last-child { border-bottom: none; }

  .record-card-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
  .record-card-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    font-weight: var(--weight-semi);
    font-size: var(--text-base);
  }
  .record-card-meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    font-size: var(--text-xs);
    color: var(--color-text-muted);
  }
  .record-card-side {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }
  .record-card-amount {
    font-size: var(--text-md);
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
  }
  .record-card-extra {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    padding-top: var(--space-2);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
  }
  .record-card-extra dl { display: flex; gap: 4px; margin: 0; }
  .record-card-extra dt { color: var(--color-text-subtle); }
  .record-card-extra dd { margin: 0; font-variant-numeric: tabular-nums; }
  .record-card-actions { grid-column: 1 / -1; display: flex; gap: var(--space-2); }
}

/* ==========================================================================
   8. 空状态 / 加载 / 骨架
   ========================================================================== */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-5);
  text-align: center;
}
.empty-icon {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: var(--radius-xl);
  background: var(--color-surface-sunken);
  color: var(--color-text-subtle);
}
.empty-icon svg { width: 24px; height: 24px; stroke-width: 1.6; }
.empty-title { font-size: var(--text-base); font-weight: var(--weight-semi); }
.empty-desc { font-size: var(--text-sm); color: var(--color-text-muted); max-width: 42ch; }
.empty--sm { padding: var(--space-8) var(--space-4); }

.loading-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.spinner {
  width: 18px; height: 18px;
  flex: none;
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner--sm { width: 14px; height: 14px; border-width: 2px; }
.spinner--lg { width: 26px; height: 26px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg,
    var(--color-surface-sunken) 25%,
    var(--color-surface-2) 37%,
    var(--color-surface-sunken) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: skeleton-shine 1.4s ease infinite;
}
@keyframes skeleton-shine {
  from { background-position: 100% 50%; }
  to   { background-position: 0 50%; }
}
.skeleton-text { height: 12px; margin: 6px 0; }

/* ==========================================================================
   9. 弹窗 / 抽屉
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(16, 24, 40, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal-overlay.is-open { display: flex; animation: fade-in var(--dur-fast) var(--ease-out); }

.modal {
  width: min(680px, 100%);
  max-height: min(86vh, 86dvh);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modal-in var(--dur-base) var(--ease-out);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.modal--sm { width: min(440px, 100%); }
.modal--lg { width: min(880px, 100%); }
.modal--xl { width: min(1120px, 100%); }

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex: none;
}
.modal-head-text { flex: 1; min-width: 0; }
.modal-title { font-size: var(--text-lg); font-weight: var(--weight-semi); }
.modal-desc { margin-top: 2px; font-size: var(--text-sm); color: var(--color-text-muted); }

.modal-close {
  flex: none;
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  color: var(--color-text-subtle);
}
.modal-close:hover { background: var(--color-surface-sunken); color: var(--color-text); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-5);
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
  flex: none;
}
.modal-foot .modal-foot-left { margin-right: auto; }

@media (max-width: 767px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: sheet-in var(--dur-slow) var(--ease-out);
  }
  @keyframes sheet-in {
    from { transform: translateY(100%); }
    to   { transform: none; }
  }
  /* 移动端底部弹层：为 Home 指示条留白 */
  .modal-foot { padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px)); }
}

/* ==========================================================================
   10. 提示消息（Toast）
   ========================================================================== */

.toast-region {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-3));
  right: var(--space-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  max-width: min(380px, calc(100vw - var(--space-6)));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  pointer-events: auto;
  animation: toast-in var(--dur-base) var(--ease-out);
}
.toast.is-leaving { animation: toast-out var(--dur-fast) var(--ease-in-out) forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px); }
}

.toast-icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.toast-icon svg { width: 18px; height: 18px; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: var(--weight-semi); }
.toast-text { color: var(--color-text-muted); }
.toast-text:first-child { color: inherit; }

.toast-close {
  flex: none;
  display: grid; place-items: center;
  width: 20px; height: 20px;
  margin: -2px -4px 0 0;
  border-radius: var(--radius-sm);
  color: var(--color-text-subtle);
}
.toast-close:hover { background: var(--color-surface-sunken); }
.toast-close svg { width: 14px; height: 14px; }

.toast[data-type="success"] { border-color: var(--success-100); }
.toast[data-type="success"] .toast-icon { color: var(--success-500); }
.toast[data-type="error"] { border-color: var(--danger-100); }
.toast[data-type="error"] .toast-icon { color: var(--danger-500); }
.toast[data-type="warning"] { border-color: var(--warning-100); }
.toast[data-type="warning"] .toast-icon { color: var(--warning-500); }
.toast[data-type="info"] .toast-icon { color: var(--color-primary); }

@media (max-width: 767px) {
  .toast-region {
    top: auto;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--space-3));
    left: var(--space-3);
    right: var(--space-3);
    max-width: none;
  }
  .toast { animation: toast-up var(--dur-base) var(--ease-out); }
  @keyframes toast-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
  }
  .toast.is-leaving { animation: toast-out-up var(--dur-fast) var(--ease-in-out) forwards; }
  @keyframes toast-out-up { to { opacity: 0; transform: translateY(12px); } }
}

/* ==========================================================================
   11. 标签页 / 分段导航
   ========================================================================== */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out);
}
.tab:hover { color: var(--color-text); text-decoration: none; }
.tab[aria-selected="true"],
.tab.is-active { color: var(--color-primary); font-weight: var(--weight-semi); }
.tab[aria-selected="true"]::after,
.tab.is-active::after {
  content: "";
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--color-primary);
}

/* 药丸式标签（用于账号切换等场景） */
.chip-row {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-1);
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: all var(--dur-fast) var(--ease-out);
}
.chip:hover { border-color: var(--color-primary); color: var(--color-primary); }
.chip.is-active,
.chip[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.chip-count {
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--color-surface-sunken);
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
}
.chip.is-active .chip-count { background: rgba(255,255,255,0.25); color: #fff; }

/* ==========================================================================
   12. 进度条 / 倒计时条
   ========================================================================== */

.bar {
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--color-surface-sunken);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  transition: width var(--dur-slow) var(--ease-out);
}
.bar-fill[data-tone="success"] { background: var(--success-500); }
.bar-fill[data-tone="warning"] { background: var(--warning-500); }
.bar-fill[data-tone="danger"]  { background: var(--danger-500); }
.bar-fill[data-tone="gold"]    { background: var(--gold-400); }

/* ==========================================================================
   13. 键值列表（详情展示）
   ========================================================================== */

.kv {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  align-items: baseline;
}
.kv dt {
  color: var(--color-text-subtle);
  white-space: nowrap;
}
.kv dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}
.kv--wide { grid-template-columns: minmax(0, 1fr); gap: var(--space-1); }
.kv--wide dt { margin-top: var(--space-2); }

/* 可复制文本 */
.copy-line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.copy-line .copy-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   14. 二维码
   ========================================================================== */

.qr-frame {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.qr-frame canvas,
.qr-frame img,
.qr-frame svg {
  width: 100%;
  height: auto;
  max-width: 260px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.qr-holder { display: flex; justify-content: center; }

/* 扫码窗 */
.scan-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #0d1014;
}
.scan-stage video {
  width: 100%; height: 100%;
  object-fit: cover;
}
.scan-reticle {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(62%, 220px);
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 100vmax rgba(13, 16, 20, 0.45);
  pointer-events: none;
}
.scan-reticle::before,
.scan-reticle::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid var(--brand-400);
  border-radius: var(--radius-lg);
  clip-path: polygon(
    0 0, 32% 0, 32% 12%, 12% 12%, 12% 32%, 0 32%,
    0 100%, 32% 100%, 32% 88%, 12% 88%, 12% 68%, 0 68%,
    100% 0, 68% 0, 68% 12%, 88% 12%, 88% 32%, 100% 32%,
    100% 100%, 68% 100%, 68% 88%, 88% 88%, 88% 68%, 100% 68%);
}
.scan-hint {
  position: absolute;
  left: 0; right: 0;
  bottom: var(--space-4);
  text-align: center;
  color: #fff;
  font-size: var(--text-sm);
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

/* 表单里的图片选择/上传区 */
.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  border: 1.5px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.file-drop:hover, .file-drop.is-over { border-color: var(--color-primary); background: var(--color-primary-soft); color: var(--color-primary); }
.file-drop svg { width: 22px; height: 22px; }

/* ==========================================================================
   15. 会员卡
   ========================================================================== */

.member-card {
  /*
   * 会员卡是一张"实体的金卡"，浅色/深色主题下都应保持金色。
   * 做法不是把颜色写死到每个子元素，而是在卡片作用域内重新声明
   * 金色与状态色阶——CSS 变量沿级联生效，卡片内的徽章、卡号块
   * 会自动使用这份浅色值，不受全局暗色主题影响。
   */
  --gold-50:  #fff9e6;
  --gold-100: #fff1c2;
  --gold-200: #ffe487;
  --gold-300: #ffd24d;
  --gold-600: #a87400;
  --gold-700: #7a5300;

  position: relative;
  border-radius: var(--radius-xl);
  overflow: hidden;
  color: #2a1f00;
  background:
    radial-gradient(120% 140% at 100% 0%, var(--gold-200) 0%, transparent 55%),
    linear-gradient(135deg, var(--gold-100) 0%, var(--gold-50) 55%, #fffdf5 100%);
  border: 1px solid var(--gold-200);
  box-shadow: var(--shadow-sm);
}
.member-card[data-status="expired"],
.member-card[data-status="disabled"] {
  background: linear-gradient(135deg, var(--gray-100) 0%, var(--gray-50) 100%);
  border-color: var(--color-border);
  color: var(--color-text);
}
.member-card[data-status="pending"] {
  background: linear-gradient(135deg, var(--brand-50) 0%, #fff 100%);
  border-color: var(--brand-200);
  color: var(--color-text);
}

.member-card-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-3);
}
.member-card-brand {
  flex: 1;
  min-width: 0;
}
.member-card-brand .title {
  font-size: var(--text-2xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.75;
  font-weight: var(--weight-semi);
}
.member-card-brand .sub {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  letter-spacing: 0.01em;
}

.member-card-body {
  display: flex;
  gap: var(--space-5);
  padding: 0 var(--space-5) var(--space-5);
  align-items: flex-start;
  flex-wrap: wrap;
}
.member-card-info { flex: 1; min-width: 190px; display: flex; flex-direction: column; gap: var(--space-3); }
.member-card-name {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.member-card-code {
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: var(--weight-semi);
  letter-spacing: 0.1em;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.06);
  display: inline-block;
}
.member-card[data-status="expired"] .member-card-code,
.member-card[data-status="disabled"] .member-card-code { background: var(--color-surface-sunken); }

.member-card-qr { flex: none; margin-left: auto; }
.member-card-qr .qr-frame { padding: var(--space-2); border-radius: var(--radius-md); border-color: rgba(0,0,0,0.08); }

.member-card-days {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
}
.member-card-days .num {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.member-card-days .unit { font-size: var(--text-sm); opacity: 0.8; }

.member-card-foot {
  padding: var(--space-3) var(--space-5);
  background: rgba(0, 0, 0, 0.04);
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* 会员卡在手机上的竖排 */
@media (max-width: 560px) {
  .member-card-body { flex-direction: column; }
  .member-card-qr { margin-left: 0; align-self: center; }
}

/* ==========================================================================
   16. 提示条 / 横幅
   ========================================================================== */

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}
.banner svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.banner-body { flex: 1; min-width: 0; }
.banner-title { font-weight: var(--weight-semi); }
.banner-desc { color: var(--color-text-muted); font-size: var(--text-xs); margin-top: 2px; }

.banner[data-tone="info"] { background: var(--info-50); border-color: var(--brand-200); }
.banner[data-tone="info"] > svg { color: var(--brand-600); }
.banner[data-tone="success"] { background: var(--success-50); border-color: var(--success-100); }
.banner[data-tone="success"] > svg { color: var(--success-600); }
.banner[data-tone="warning"] { background: var(--warning-50); border-color: var(--warning-100); }
.banner[data-tone="warning"] > svg { color: var(--warning-600); }
.banner[data-tone="danger"] { background: var(--danger-50); border-color: var(--danger-100); }
.banner[data-tone="danger"] > svg { color: var(--danger-600); }
.banner[data-tone="gold"] { background: var(--gold-50); border-color: var(--gold-200); }
.banner[data-tone="gold"] > svg { color: var(--gold-600); }

/* ==========================================================================
   17. 下拉菜单
   ========================================================================== */

.menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: var(--z-drawer);
  min-width: 180px;
  padding: var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  animation: menu-in var(--dur-fast) var(--ease-out);
}
@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
.menu[hidden] { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  text-align: left;
}
.menu-item:hover { background: var(--color-surface-sunken); text-decoration: none; }
.menu-item svg { width: 16px; height: 16px; color: var(--color-text-muted); flex: none; }
.menu-item[data-tone="danger"] { color: var(--danger-600); }
.menu-item[data-tone="danger"] svg { color: var(--danger-500); }
.menu-sep { height: 1px; margin: var(--space-1) 0; background: var(--color-border); }
.menu-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--text-2xs);
  color: var(--color-text-subtle);
  font-weight: var(--weight-semi);
  letter-spacing: 0.05em;
}

/* ==========================================================================
   18. 图表容器
   ========================================================================== */

.chart-box { position: relative; width: 100%; }
.chart-box--sm { height: 200px; }
.chart-box--md { height: 260px; }
.chart-box--lg { height: 320px; }
.chart-box canvas { width: 100% !important; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
}
.chart-legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.chart-legend-swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex: none;
}

/* ==========================================================================
   19. 危险操作确认
   ========================================================================== */

.confirm-icon {
  width: 42px; height: 42px;
  margin: 0 auto var(--space-3);
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--danger-50);
  color: var(--danger-600);
}
.confirm-icon svg { width: 21px; height: 21px; }
.confirm-icon[data-tone="warning"] { background: var(--warning-50); color: var(--warning-600); }

/* ==========================================================================
   20. 工具类（放在最后一层，便于局部覆盖）
   ========================================================================== */

.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }
.text-pos { color: var(--color-pos); }
.text-neg { color: var(--color-neg); }
.text-gold { color: var(--gold-600); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-lg { font-size: var(--text-lg); }
.fw-medium { font-weight: var(--weight-medium); }
.fw-semi { font-weight: var(--weight-semi); }
.fw-bold { font-weight: var(--weight-bold); }
.font-mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.w-full { width: 100%; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.hidden { display: none !important; }
.mono-num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

} /* end @layer components */
