/* ==========================================================================
   通用组件：按钮、表单、徽标、卡片、表格、进度、空状态、代码块等
   ========================================================================== */

/* ---------- 按钮 ---------- */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-line: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--btn-line); border-radius: var(--radius-sm);
  background: var(--btn-bg); color: var(--btn-fg);
  font-size: var(--fs-sm); font-weight: 550; line-height: 1; white-space: nowrap;
  user-select: none; text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .06s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active:not([disabled]) { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-line: transparent;
  box-shadow: 0 1px 2px rgba(67, 71, 232, .4), inset 0 1px 0 rgba(255, 255, 255, .16);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-soft { --btn-bg: var(--accent-soft); --btn-fg: var(--accent-text); --btn-line: transparent; }
.btn-soft:hover { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
.btn-danger { --btn-fg: var(--bad); --btn-line: var(--bad-line); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-danger-solid { --btn-bg: var(--bad); --btn-fg: #fff; --btn-line: transparent; }
.btn-danger-solid:hover { background: color-mix(in srgb, var(--bad) 88%, #000); }
.btn-ghost { --btn-bg: transparent; --btn-line: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: var(--fs-xs); border-radius: 7px; gap: 5px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: var(--fs-md); border-radius: 10px; }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon.btn-sm svg { width: 15px; height: 15px; }
.btn .spinner { width: 14px; height: 14px; }
.btn-group { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; opacity: .75;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 表单 ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.field-label .optional { margin-left: 6px; font-weight: 400; color: var(--text-3); }
.field-hint { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.55; }
.field-error { font-size: var(--fs-xs); color: var(--bad); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 560px) { .field-row { grid-template-columns: minmax(0, 1fr); } }

.input, .select, .textarea {
  width: 100%; min-width: 0; height: 36px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-md); line-height: 1.4;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.input.mono, .mono { font-family: var(--font-mono); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2376809a' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 16px;
}
.input-sm, .select-sm { height: 30px; font-size: var(--fs-sm); }
.input-group { position: relative; display: block; }
.input-group .input { padding-right: 42px; }
.input-addon { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.search { position: relative; display: block; min-width: 0; }
.search svg { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 36px; }
@media (max-width: 720px) {
  .input, .select, .textarea { font-size: 16px; }
  .input-sm, .select-sm { font-size: 16px; }
}

/* 选项卡片（单选） */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.choice-body {
  display: grid; gap: 4px; padding: 14px 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-md); background: var(--surface);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.choice:hover .choice-body { border-color: var(--text-3); }
.choice input:checked + .choice-body { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.choice input:focus-visible + .choice-body { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice input:disabled + .choice-body { opacity: .55; cursor: not-allowed; }
.choice-title { font-weight: 600; }
.choice-price { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.02em; }
.choice-sub { font-size: var(--fs-xs); color: var(--text-2); }

/* 开关 */
.switch {
  position: relative; flex: none; width: 36px; height: 20px; padding: 0;
  border: 0; border-radius: 999px; background: var(--line-strong);
  transition: background .18s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .18s var(--ease);
}
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.switch[disabled] { opacity: .45; cursor: not-allowed; }

/* 分段控件 */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-3); max-width: 100%; overflow-x: auto; }
.segmented button {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 550; white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented button svg { width: 15px; height: 15px; }
.segmented .count { padding: 0 6px; border-radius: 999px; background: var(--surface-3); color: var(--text-3); font-size: 14px; line-height: 17px; }

/* 标签页 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 14px;
  border: 0; background: transparent; color: var(--text-2); font-weight: 550; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent-text); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; background: var(--accent); }
.tab .count { padding: 0 7px; border-radius: 999px; background: var(--surface-3); color: var(--text-3); font-size: 14px; line-height: 18px; }

/* 筛选胶囊 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--text-3); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-text); }
.chip .count { color: var(--text-3); font-size: 14px; }
.chip[aria-pressed="true"] .count { color: inherit; opacity: .8; }

/* ---------- 徽标 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2);
  font-size: var(--fs-xs); font-weight: 550; line-height: 1; white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-outline { background: transparent; border: 1px solid var(--line-strong); }
.badge-mono { font-family: var(--font-mono); font-weight: 500; }
.badge-sm { height: 19px; padding: 0 7px; font-size: 14px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.status-dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.status-dot.off { background: var(--line-strong); }

/* ---------- 卡片 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 12px; padding: 18px 20px 0; }
.card-title { flex: 1; min-width: 0; }
.card-title h2, .card-title h3 { font-size: var(--fs-lg); }
.card-title p { margin-top: 3px; color: var(--text-3); font-size: var(--fs-sm); line-height: 1.5; }
.card-body { padding: 16px 20px 20px; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); color: var(--text-2); font-size: var(--fs-sm); }
.card-flush .card-body { padding: 0; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card.is-interactive { transition: border-color .15s, box-shadow .15s, transform .15s; }
.card.is-interactive:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }

/* 提示条 */
.callout {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--info-line); border-radius: var(--radius-md);
  background: var(--info-soft); color: var(--text); font-size: var(--fs-sm); line-height: 1.6;
}
.callout > svg { width: 18px; height: 18px; margin-top: 2px; color: var(--info); }
.callout-body { flex: 1; min-width: 0; }
.callout strong { font-weight: 650; }
.callout-ok { border-color: var(--ok-line); background: var(--ok-soft); } .callout-ok > svg { color: var(--ok); }
.callout-warn { border-color: var(--warn-line); background: var(--warn-soft); } .callout-warn > svg { color: var(--warn); }
.callout-bad { border-color: var(--bad-line); background: var(--bad-soft); } .callout-bad > svg { color: var(--bad); }
.callout-accent { border-color: var(--accent-line); background: var(--accent-soft); } .callout-accent > svg { color: var(--accent-text); }

/* ---------- 表格 ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
.card > .table-wrap { border-radius: inherit; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  position: sticky; top: 0; z-index: 1;
  padding: 10px 16px; background: var(--surface-2); color: var(--text-3);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .02em; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table .cell-main { display: grid; gap: 2px; min-width: 0; }
.table .cell-main strong { font-weight: 600; }
.table .cell-main small { color: var(--text-3); font-size: var(--fs-xs); }
.table .actions { text-align: right; white-space: nowrap; }

/* ---------- 进度 / 用量 ---------- */
.bar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .5s var(--ease); }
.bar.ok > span { background: var(--ok); }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }
.bar-lg { height: 10px; }

/* ---------- 空状态 / 骨架 ---------- */
.empty { display: grid; justify-items: center; gap: 8px; padding: 40px 20px; text-align: center; color: var(--text-2); }
.empty-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-3); margin-bottom: 4px; }
.empty-icon svg { width: 24px; height: 24px; }
.empty h3 { font-size: var(--fs-lg); color: var(--text); }
.empty p { max-width: 420px; font-size: var(--fs-sm); line-height: 1.65; color: var(--text-3); }
.empty .btn { margin-top: 8px; }
.empty.compact { padding: 24px 16px; }

.skeleton { border-radius: 8px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 220% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
.skeleton-line { height: 14px; margin: 10px 0; }
.skeleton-block { height: 120px; }

/* ---------- 代码 ---------- */
.codeblock { border: 1px solid var(--code-line); border-radius: var(--radius-md); background: var(--code-bg); color: var(--code-fg); overflow: hidden; }
.codeblock-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--code-line); color: #8d94b8; font-size: var(--fs-xs); }
.codeblock pre { margin: 0; padding: 14px 16px; overflow: auto; font-size: 14px; line-height: 1.7; tab-size: 2; white-space: pre; }
.codeblock .btn { --btn-bg: transparent; --btn-fg: #aab0d0; --btn-line: transparent; }
.codeblock .btn:hover { background: rgba(255, 255, 255, .08); --btn-fg: #fff; }
.copy-field { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px 4px 4px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
.copy-field code { flex: 1; min-width: 0; padding: 0; background: transparent; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 弹出层 ---------- */
.popover {
  position: fixed; z-index: 70; min-width: 280px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-md);
  background: var(--surface); box-shadow: var(--shadow-lg); overflow: hidden;
  animation: pop-in .14s var(--ease);
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- 杂项 ---------- */
.monogram {
  --vendor: var(--accent);
  flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: color-mix(in srgb, var(--vendor) 14%, var(--surface)); color: var(--vendor);
  border: 1px solid color-mix(in srgb, var(--vendor) 28%, transparent);
  font-size: 14px; font-weight: 700; letter-spacing: -.02em;
}
.monogram.sm { width: 28px; height: 28px; border-radius: 8px; font-size: 14px; }
.monogram.lg { width: 44px; height: 44px; border-radius: 12px; font-size: 15px; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.small { font-size: var(--fs-xs); }
.right { margin-left: auto; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.row.nowrap { flex-wrap: nowrap; }
.divider { height: 1px; background: var(--line); border: 0; margin: 4px 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; font-size: var(--fs-sm); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; text-align: right; font-weight: 550; min-width: 0; }
details.fold > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 550; font-size: var(--fs-sm); padding: 4px 0; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin-right: 4px; }
details.fold[open] > summary::before { transform: rotate(45deg); }

.codeblock pre{font-size:14px}.codeblock pre code{padding:0;border-radius:0;background:transparent;color:inherit;font-size:inherit}.codeblock .btn{color:#c1c7e0}.codeblock .btn:hover{color:white}
