/* Stripe 支付服务 v1 · 管理后台样式
   颜色、圆角、间距、阴影、动效都在 :root 变量里；深色模式跟随系统。 */

/* ================================================================ tokens */
:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --surface-3: #e8eaee;
  --overlay: rgba(15, 17, 21, .38);
  --border: #e3e5ea;
  --border-strong: #c9cdd6;

  --text: #16181d;
  --text-2: #5a5f6b;
  --text-3: #6b707a;

  --primary: #2f5bd3;
  --primary-hover: #2a52c2;
  --primary-active: #2448ab;
  --primary-soft: #eaf0fd;
  --primary-soft-2: #dbe5fb;
  --link: #2a52c2;
  --on-primary: #ffffff;

  --success: #16794a;
  --success-soft: #e6f4ec;
  --warning: #93590a;
  --warning-soft: #fbf1df;
  --danger: #c0322f;
  --danger-hover: #a82a27;
  --danger-soft: #fcebea;
  --neutral-soft: #eef0f3;

  --toast-bg: #1d2026;
  --toast-text: #f3f4f6;

  /* 图表：分类色按业务创建顺序固定分配（已用 dataviz 校验器验证） */
  --chart-1: #2a78d6;
  --chart-2: #eb6834;
  --chart-3: #1baf7a;
  --chart-4: #eda100;
  --chart-5: #e87ba4;
  --chart-6: #008300;
  --chart-7: #6250d6;
  --chart-muted: #a3a8b2;
  --chart-other: #cdd1d8;
  --chart-bar: #8d929c;
  --grid: #eceef2;
  --axis: #c9cdd6;

  --ring: 0 0 0 3px rgba(47, 91, 211, .28);
  --ring-danger: 0 0 0 3px rgba(192, 50, 47, .22);
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .05);
  --shadow-pop: 0 12px 32px rgba(17, 24, 39, .13), 0 2px 8px rgba(17, 24, 39, .06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
          "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-xl: 22px;

  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  --dur-1: 120ms;
  --dur-2: 180ms;
  --dur-3: 260ms;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);

  --sidebar-w: 224px;
  --rail-w: 64px;
  --topbar-h: 56px;
  --gutter: 24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1013;
    --surface: #17191d;
    --surface-2: #1e2025;
    --surface-3: #262930;
    --overlay: rgba(0, 0, 0, .55);
    --border: #2a2d34;
    --border-strong: #3b3f48;

    --text: #eceef2;
    --text-2: #a7acb7;
    --text-3: #7d838f;

    --primary: #4466d8;
    --primary-hover: #4f71e2;
    --primary-active: #3c5cc6;
    --primary-soft: #1f2a4a;
    --primary-soft-2: #273561;
    --link: #8eaaff;

    --success: #4fc785;
    --success-soft: #18301f;
    --warning: #e7ab4c;
    --warning-soft: #33281a;
    --danger: #f27a72;
    --danger-hover: #f48d86;
    --danger-soft: #3a1f1e;
    --neutral-soft: #24272d;

    --toast-bg: #2a2e36;
    --toast-text: #eceef2;

    --chart-1: #3987e5;
    --chart-2: #d95926;
    --chart-3: #199e70;
    --chart-4: #c98500;
    --chart-5: #d55181;
    --chart-6: #008300;
    --chart-7: #9085e9;
    --chart-muted: #5f6570;
    --chart-other: #444953;
    --chart-bar: #7f8592;
    --grid: #24272d;
    --axis: #3b3f48;

    --ring: 0 0 0 3px rgba(110, 145, 255, .38);
    --ring-danger: 0 0 0 3px rgba(242, 122, 114, .3);
    --shadow-sm: none;
    --shadow-pop: 0 16px 40px rgba(0, 0, 0, .5);
  }
}

/* ================================================================ reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-base)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, p, dl, dd, figure { margin: 0; }
h1, h2, h3, h4 { font-weight: 600; line-height: 1.3; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }
@media (hover: hover) { a:hover { text-decoration: underline; text-underline-offset: 2px; } }
svg { flex: none; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--r-xs); }
::selection { background: var(--primary-soft-2); }
[hidden] { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

.mono { font-family: var(--mono); font-size: .92em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ================================================================ shell */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden auto;
  padding: 12px 10px calc(12px + env(safe-area-inset-bottom));
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 6px;
  margin-bottom: 14px;
  color: var(--text);
}
.brand-mark { width: 26px; height: 26px; border-radius: 7px; }
.brand-name { font-weight: 600; font-size: var(--fs-base); line-height: 1.2; }
.brand-name small { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-weight: 500;
  text-decoration: none;
  transition: background-color var(--dur-1), color var(--dur-1);
}
.nav a svg { width: 18px; height: 18px; }
@media (hover: hover) { .nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; } }
.nav a:active { background: var(--surface-3); }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--link); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; }
.env-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: var(--fs-xs);
  line-height: 1.4;
}
.env-note.danger { background: var(--danger-soft); color: var(--danger); }
.env-note svg { width: 16px; height: 16px; }
.collapse-btn { align-self: flex-start; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: var(--fs-md); font-weight: 600; min-width: 0; }
.topbar .menu-btn { display: none; margin-left: -6px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 var(--gutter) calc(32px + env(safe-area-inset-bottom));
  scroll-padding-top: 72px;
}

/* 管理员会话：视口最上方一条主色细线 */
.admin-strip {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--primary);
  z-index: 90;
  transform-origin: left center;
  animation: strip-in var(--dur-3) var(--ease-out);
  pointer-events: none;
}
@keyframes strip-in { from { transform: scaleX(0); } }

/* 会话徽标（右上角） */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: background-color var(--dur-2), color var(--dur-2), border-color var(--dur-2);
}
.chip svg { width: 16px; height: 16px; }
.chip .lvl { color: var(--text); font-weight: 500; }
.chip .sep { width: 1px; height: 12px; background: var(--border-strong); }
@media (hover: hover) { .chip:hover { background: var(--surface-2); } }
.chip.is-admin { background: var(--primary-soft); border-color: transparent; color: var(--link); }
.chip.is-admin .lvl { color: var(--link); }
.chip.is-admin .sep { background: currentColor; opacity: .35; }
.chip.is-ending { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.chip.is-ending .lvl { color: var(--warning); }

.mode-badge { display: inline-flex; }

/* 平板 / 窄窗口：侧栏收成图标栏；桌面可手动折叠 */
@media (min-width: 768px) and (max-width: 1199px) {
  .shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .shell .sidebar { padding-inline: 10px; align-items: center; }
  .shell .brand-name, .shell .nav .label, .shell .env-note .label, .shell .collapse-btn { display: none; }
  .shell .nav a { width: 40px; justify-content: center; padding: 0; }
  .shell .env-note { padding: 8px; justify-content: center; }
}
@media (min-width: 1200px) {
  .shell.is-collapsed { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .shell.is-collapsed .sidebar { align-items: center; }
  .shell.is-collapsed .brand-name, .shell.is-collapsed .nav .label, .shell.is-collapsed .env-note .label { display: none; }
  .shell.is-collapsed .nav a { width: 40px; justify-content: center; padding: 0; }
  .shell.is-collapsed .env-note { padding: 8px; justify-content: center; }
  .shell.is-collapsed .collapse-btn { align-self: center; }
  .shell.is-collapsed .collapse-btn svg { transform: scaleX(-1); }
}

/* 手机：单列，导航进抽屉 */
.scrim { display: none; }
@media (max-width: 767px) {
  :root { --gutter: 16px; --topbar-h: 52px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 80;
    width: min(288px, 86vw);
    transform: translateX(-102%);
    transition: transform var(--dur-3) var(--ease-out);
    box-shadow: var(--shadow-pop);
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .shell.nav-open .sidebar { transform: none; }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 79;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-3);
  }
  .shell.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .sidebar .collapse-btn { display: none; }
  .shell { display: block; height: auto; min-height: 100dvh; }
  .main { display: block; }
  .topbar { position: sticky; top: 0; z-index: 40; padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); gap: 6px; }
  .content { overflow: visible; min-height: 0; }
  .toolbar { top: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .topbar .menu-btn { display: inline-flex; }
  .chip .when-wide { display: none; }
  .elevate-btn .label { display: none; }
  .elevate-btn { width: 32px; padding: 0; }
  .mode-badge { display: none; }
}

/* ================================================================ buttons */
.btn {
  --spin: currentColor;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
  transition: background-color var(--dur-1), border-color var(--dur-1), color var(--dur-1), transform var(--dur-1), box-shadow var(--dur-1), opacity var(--dur-1);
}
.btn svg { width: 16px; height: 16px; }
@media (hover: hover) { .btn:hover { background: var(--surface-2); text-decoration: none; } }
.btn:active { transform: scale(.97); background: var(--surface-3); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); --spin: var(--on-primary); }
@media (hover: hover) { .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); } }
.btn-primary:active { background: var(--primary-active); border-color: var(--primary-active); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; --spin: #fff; }
@media (hover: hover) { .btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); } }
.btn-danger:active { background: var(--danger-hover); }
.btn-danger:focus-visible { box-shadow: var(--ring-danger); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-2); }
@media (hover: hover) { .btn-quiet:hover { background: var(--surface-2); color: var(--text); } }
.btn-quiet.danger { color: var(--danger); }
.btn-link { border: 0; background: none; height: auto; padding: 0; color: var(--link); font-weight: 500; }
@media (hover: hover) { .btn-link:hover { background: none; text-decoration: underline; text-underline-offset: 2px; } }
.btn-link:active { background: none; }
.btn-sm { height: 28px; padding: 0 10px; font-size: var(--fs-xs); }
.btn-lg { height: 40px; padding: 0 16px; font-size: var(--fs-base); border-radius: var(--r-md); }
.btn-icon { width: 32px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-block { width: 100%; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--spin);
  border-right-color: transparent;
  animation: spin .7s linear infinite;
}
.btn.is-done { color: var(--success); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================ form controls */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field { margin-top: 14px; }
.label { font-size: var(--fs-sm); font-weight: 500; color: var(--text); }
.label .optional { font-weight: 400; color: var(--text-3); margin-left: 6px; font-size: var(--fs-xs); }
.hint { font-size: var(--fs-xs); color: var(--text-2); line-height: 1.45; }
.error-text { font-size: var(--fs-xs); color: var(--danger); line-height: 1.45; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-row + .field, .field + .field-row, .field-row + .field-row { margin-top: 14px; }
.field-row .field + .field { margin-top: 0; }

.input, .textarea, .select-trigger {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
  -webkit-appearance: none;
  appearance: none;
}
.textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: 1; }
.input:focus, .textarea:focus, .select-trigger:focus-visible { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .input-group[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled { background: var(--surface-2); color: var(--text-2); }
.input-group:has(.input:disabled) { background: var(--surface-2); color: var(--text-2); }
.select-trigger:disabled { background: var(--surface-2); color: var(--text-2); cursor: not-allowed; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }
input:-webkit-autofill, input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px var(--surface) inset;
  transition: background-color 99999s;
}

.input-group {
  display: flex;
  align-items: center;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
.input-group:focus-within { border-color: var(--primary); box-shadow: var(--ring); }
.input-group .affix { padding: 0 2px 0 10px; color: var(--text-3); white-space: nowrap; }
.input-group .affix.end { padding: 0 10px 0 2px; }
.input-group .input { border: 0; box-shadow: none !important; height: 100%; background: transparent; }

.search {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}
.search > svg { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 32px; padding-right: 30px; }
.search .clear { position: absolute; right: 4px; width: 26px; height: 26px; }

.select-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  padding: 0 8px 0 10px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.select-trigger .val { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.select-trigger .ph { color: var(--text-3); }
.select-trigger > svg { width: 16px; height: 16px; color: var(--text-3); transition: transform var(--dur-2) var(--ease-out); }
.select-trigger[aria-expanded="true"] > svg { transform: rotate(180deg); }
@media (hover: hover) { .select-trigger:hover { border-color: var(--text-3); } }
.select-trigger.is-set { border-color: var(--primary); color: var(--link); background: var(--primary-soft); }
.select-trigger.is-set > svg { color: var(--link); }
.field .select-trigger { width: 100%; }
.field .select-trigger.is-set { border-color: var(--border-strong); color: var(--text); background: var(--surface); }
.field .select-trigger.is-set > svg { color: var(--text-3); }

.seg {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.seg button {
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--dur-1), color var(--dur-1), box-shadow var(--dur-1);
}
@media (hover: hover) { .seg button:hover { color: var(--text); } }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.seg button:focus-visible { outline: none; box-shadow: var(--ring); }
.seg.sm button { height: 24px; padding: 0 10px; font-size: var(--fs-xs); }
.field .seg { align-self: flex-start; }

.switch {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background-color var(--dur-2);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform var(--dur-2) var(--ease-out);
}
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.switch:focus-visible { outline: none; box-shadow: var(--ring); }
.switch:disabled { opacity: .5; cursor: not-allowed; }
.switch.is-busy::after { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* 6 位动态码输入：一个真实输入框 + 6 个显示格 */
.code { position: relative; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.code input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  font-size: 16px;
  border: 0;
  caret-color: transparent;
  z-index: 1;
}
.code .cell {
  display: grid;
  place-items: center;
  height: 52px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 22px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
.code.is-focused .cell.is-active { border-color: var(--primary); box-shadow: var(--ring); }
.code.is-focused .cell.is-active:empty::after {
  content: "";
  width: 1.5px;
  height: 22px;
  background: var(--text);
  animation: blink 1s steps(1) infinite;
}
.code.is-error .cell { border-color: var(--danger); }
.code.is-error { animation: shake .3s var(--ease-out); }
.code.is-disabled .cell { background: var(--surface-2); color: var(--text-3); }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ================================================================ badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}
.badge svg { width: 12px; height: 12px; }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--primary-soft); color: var(--link); }
.badge.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); }
.badge.sq { border-radius: var(--r-xs); height: 20px; padding: 0 6px; }

.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; }

/* ================================================================ cards & sections */
.page { display: flex; flex-direction: column; gap: 16px; }
.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.card-h {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 12px 16px 0;
}
.card-h h2, .card-h h3 { font-size: var(--fs-base); font-weight: 600; white-space: nowrap; }
@media (max-width: 767px) { .card-h .card-sub { display: none; } }
.card-h .actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.card-b { padding: 12px 16px 16px; }
.card-sub { color: var(--text-2); font-size: var(--fs-xs); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; }
@media (max-width: 1099px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* 吸顶工具条 */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 calc(var(--gutter) * -1);
  padding: 16px var(--gutter) 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.toolbar .spacer { flex: 1 1 auto; }
.toolbar .search { width: 280px; }
.toolbar .when-narrow { display: none; }
.toolbar .meta { color: var(--text-3); font-size: var(--fs-xs); white-space: nowrap; }
@media (max-width: 767px) {
  .toolbar { flex-wrap: nowrap; padding-top: 12px; }
  .toolbar .search { flex: 1 1 auto; width: auto; }
  .toolbar .when-wide { display: none; }
  .toolbar .when-narrow { display: inline-flex; }
  .toolbar.wrap { flex-wrap: wrap; }
  .toolbar .meta { display: none; }
}
.filter-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 11px;
  font-weight: 600;
}

.tabs-wrap { padding-top: 16px; margin-bottom: -16px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
}
@media (hover: hover) { .tabs a:hover { color: var(--text); text-decoration: none; } }
.tabs a[aria-selected="true"] { color: var(--text); }
.tabs a[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--primary);
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.notice svg { width: 16px; height: 16px; margin-top: 2px; }
.notice.warn { background: var(--warning-soft); color: var(--warning); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.notice.info { background: var(--primary-soft); color: var(--link); }
.notice .grow { color: inherit; }
.notice .btn-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ================================================================ money */
.money { white-space: nowrap; font-variant-numeric: tabular-nums; }
.money .cur { color: var(--text-3); margin-right: 1px; font-weight: 400; }
.money .dec { color: var(--text-3); }
.money.neg .int, .money.neg .cur, .money.neg .dec { color: var(--danger); }
.money.big { font-variant-numeric: proportional-nums; }
.money.big .cur { font-size: .58em; margin-right: 3px; vertical-align: .32em; }
.money.big .dec { font-size: .58em; vertical-align: .32em; margin-left: 1px; }

/* ================================================================ KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-label { display: flex; align-items: center; gap: 4px; color: var(--text-2); font-size: var(--fs-sm); }
.kpi-value { margin-top: 6px; font-size: 26px; font-weight: 600; line-height: 1.15; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value .unit { font-size: .58em; font-weight: 500; color: var(--text-3); margin-left: 2px; }
.kpi-delta { margin-top: 4px; display: flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; }
.kpi-delta svg { width: 12px; height: 12px; }
@media (max-width: 767px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpis > :first-child { grid-column: 1 / -1; }
  .kpi { padding: 12px 14px 14px; }
  .kpi-value { font-size: 22px; margin-top: 4px; }
  .kpi-delta { white-space: normal; flex-wrap: wrap; }
}
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 500; font-variant-numeric: tabular-nums; }
.delta.good { color: var(--success); }
.delta.bad { color: var(--danger); }
.delta.flat { color: var(--text-2); }
.info-btn { display: inline-grid; place-items: center; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--text-3); }
.info-btn svg { width: 14px; height: 14px; }
@media (hover: hover) { .info-btn:hover { color: var(--text); } }

/* ================================================================ charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart:focus-visible { outline: none; }
.chart:focus-visible .plot-frame { stroke: var(--primary); }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .peak { fill: var(--text-2); font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums; }
.chart .col { transition: opacity var(--dur-1); }
.chart.has-hover .col { opacity: .45; }
.chart.has-hover .col.is-hover { opacity: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .plot-frame { fill: none; stroke: transparent; }
.chart.is-refreshing, .is-refreshing { opacity: .55; transition: opacity var(--dur-2); }
.s-1 { fill: var(--chart-1); background: var(--chart-1); }
.s-2 { fill: var(--chart-2); background: var(--chart-2); }
.s-3 { fill: var(--chart-3); background: var(--chart-3); }
.s-4 { fill: var(--chart-4); background: var(--chart-4); }
.s-5 { fill: var(--chart-5); background: var(--chart-5); }
.s-6 { fill: var(--chart-6); background: var(--chart-6); }
.s-7 { fill: var(--chart-7); background: var(--chart-7); }
.s-muted { fill: var(--chart-muted); background: var(--chart-muted); }
.s-other { fill: var(--chart-other); background: var(--chart-other); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-xs); color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }

.tip {
  position: absolute;
  z-index: 10;
  min-width: 168px;
  max-width: 260px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-xs);
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--dur-1), transform var(--dur-1);
}
.tip.is-on { opacity: 1; transform: none; }
.tip-title { color: var(--text-2); margin-bottom: 6px; }
.tip-total { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.tip-total strong, .tip-row strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tip-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; gap: 6px; line-height: 1.7; color: var(--text-2); }
.tip-row .key { width: 10px; height: 2px; border-radius: 2px; }

.hbars { display: flex; flex-direction: column; gap: 16px; padding-top: 4px; }
.hbar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; }
.hbar-row .name { color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-row .sub { margin-left: 8px; color: var(--text-3); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.hbar-track { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; background: var(--chart-bar); transform-origin: left; animation: grow-x var(--dur-3) var(--ease-out); }
@keyframes grow-x { from { transform: scaleX(0); } }

.share { display: block; height: 4px; margin-top: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.share > i { display: block; height: 100%; border-radius: 999px; background: var(--chart-bar); }
.tbl .r .share { margin-left: auto; max-width: 140px; }

/* ================================================================ tables → cards */
.tbl-wrap { container-type: inline-size; min-width: 0; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.tbl th {
  position: sticky;
  top: var(--th-top, 0px);
  z-index: 2;
  padding: 9px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th:first-child, .tbl td:first-child { padding-left: 16px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 16px; }
.tbl .r { text-align: right; }
.tbl .c-fit { width: 1%; white-space: nowrap; }
.tbl .cell-2 { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.tbl .cell-2 > :last-child { color: var(--text-3); font-size: var(--fs-xs); }
.tbl .trunc { max-width: 1px; }
.tbl .trunc > :not(.cell-2) { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl .cell-2 > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl tr.is-link { cursor: pointer; }
.tbl tr.is-link:focus-visible { outline: none; }
.tbl tr.is-link:focus-visible td { background: var(--primary-soft); }
@media (hover: hover) { .tbl tr.is-link:hover td { background: var(--surface-2); } }
.tbl tr.is-new td { animation: flash 1.6s var(--ease-out); }
@keyframes flash { from { background: var(--primary-soft-2); } }
.tbl .chev { display: block; color: var(--text-3); width: 16px; height: 16px; transition: transform var(--dur-2) var(--ease-out); }
.tbl-foot { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px; border-top: 1px solid var(--border); color: var(--text-3); font-size: var(--fs-xs); }
.card > .tbl-wrap .tbl th { background: var(--surface); }
.card > .tbl-wrap:first-child .tbl th:first-child { border-top-left-radius: var(--r-lg); }
.card > .tbl-wrap:first-child .tbl th:last-child { border-top-right-radius: var(--r-lg); }

/* 窄容器：表格变成卡片 */
@container (max-width: 700px) {
  .tbl, .tbl tbody { display: block; }
  .tbl thead { display: none; }
  .tbl tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
  }
  .tbl tr:last-child { border-bottom: 0; }
  .tbl td, .tbl td:first-child, .tbl td:last-child { display: block; padding: 0; border: 0; min-width: 0; text-align: left; }
  .tbl .trunc { max-width: none; }
  .tbl td.r { text-align: left; }
  .tbl td.k-b { text-align: right; }
  .tbl .k-hide, .tbl td.k-hide, .tbl td.k-hide:last-child, .tbl td.k-hide:first-child { display: none; }
  .tbl .k-a { grid-column: 1; grid-row: 1; }
  .tbl .k-b { grid-column: 2; grid-row: 1; justify-self: end; text-align: right; }
  .tbl .k-c { grid-column: 1 / -1; grid-row: 2; }
  .tbl .k-d { grid-column: 1; grid-row: 3; color: var(--text-3); font-size: var(--fs-xs); }
  .tbl .k-e { grid-column: 2; grid-row: 3; justify-self: end; }
  .tbl .k-f { grid-column: 1 / -1; grid-row: 4; }
  .tbl .cell-2 { flex-direction: row; flex-wrap: wrap; gap: 0 6px; }
  .tbl .k-strong { font-weight: 600; }
  .tbl .chev { display: none; }
  @media (hover: hover) { .tbl tr.is-link:hover { background: var(--surface-2); } .tbl tr.is-link:hover td { background: none; } }
  .tbl tr.is-link:focus-visible { background: var(--primary-soft); }
  .dlg .tbl tr { padding-inline: 0; }
}
.k-only { display: none; }
@container (max-width: 700px) { .k-only { display: inline; } .k-no { display: none; } }

/* ================================================================ description list & ids */
.dl { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px 16px; font-size: var(--fs-sm); }
.dl dt { color: var(--text-2); }
.dl dd { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 420px) { .dl { grid-template-columns: 88px minmax(0, 1fr); } }

.idv { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; min-width: 0; vertical-align: middle; }
.idv .t { font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy-btn { display: inline-grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: var(--r-xs); background: none; color: var(--text-3); transition: color var(--dur-1), background-color var(--dur-1); }
.copy-btn svg { width: 14px; height: 14px; }
@media (hover: hover) { .copy-btn:hover { color: var(--text); background: var(--surface-2); } }
.copy-btn.is-done { color: var(--success); }

.section { display: flex; flex-direction: column; gap: 10px; padding: 16px 0; border-top: 1px solid var(--border); }
.section:first-child { border-top: 0; padding-top: 4px; }
.section > h3 { font-size: var(--fs-sm); font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.section > h3 .actions { margin-left: auto; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; font-size: var(--fs-sm); }
.timeline .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); transform: translateY(-1px); }
.timeline .dot.ok { background: var(--success); }
.timeline .dot.warn { background: var(--warning); }
.timeline .dot.danger { background: var(--danger); }
.timeline .dot.info { background: var(--primary); }
.timeline time { color: var(--text-3); font-size: var(--fs-xs); white-space: nowrap; font-variant-numeric: tabular-nums; }
.timeline .sub { color: var(--text-2); font-size: var(--fs-xs); }

/* Stripe 权限检查列表 */
.perm-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 16px; }
.perm-list li { display: grid; grid-template-columns: 16px minmax(0, 1fr); column-gap: 8px; align-items: start; font-size: var(--fs-sm); line-height: 1.45; }
.perm-list li svg { width: 16px; height: 16px; margin-top: 2px; grid-row: 1 / span 2; }
.perm-list li.ok svg { color: var(--success); }
.perm-list li.bad svg { color: var(--danger); }
.perm-list li.warn svg { color: var(--warning); }
.perm-list .name { color: var(--text); font-weight: 500; }
.perm-list .purpose { color: var(--text-2); font-size: var(--fs-xs); }
.perm-list li.bad .purpose { color: var(--danger); }

/* 复选框（自绘，跟主色走） */
.cb {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  transition: background-color var(--dur-1), border-color var(--dur-1);
}
.cb::after {
  content: "";
  width: 9px;
  height: 5px;
  border: 2px solid var(--on-primary);
  border-top: 0;
  border-right: 0;
  transform: rotate(-45deg) translate(1px, -1px);
  opacity: 0;
  transition: opacity var(--dur-1);
}
.cb:checked { background: var(--primary); border-color: var(--primary); }
.cb:checked::after { opacity: 1; }
.cb:focus-visible { outline: none; box-shadow: var(--ring); }
.cb-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.5; cursor: pointer; }
@media (hover: hover) { .cb-row:hover { background: var(--surface-2); } }
.env-note a { color: inherit; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }

/* ================================================================ popover, menu, listbox */
.pop {
  position: fixed;
  z-index: 120;
  min-width: 180px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: min(360px, 60vh);
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  transform-origin: top left;
  animation: pop-in var(--dur-2) var(--ease-out);
}
.pop.up { transform-origin: bottom left; animation-name: pop-in-up; }
.pop.is-closing { animation: fade-out var(--dur-1) var(--ease-in) forwards; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
@keyframes pop-in-up { from { opacity: 0; transform: translateY(4px) scale(.98); } }
@keyframes fade-out { to { opacity: 0; } }
.opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text);
  text-align: left;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.opt > svg { width: 16px; height: 16px; color: var(--text-2); }
.opt .check { color: var(--primary); visibility: hidden; margin-left: auto; }
.opt[aria-selected="true"] .check { visibility: visible; }
.opt[aria-selected="true"] { font-weight: 500; }
.opt.is-active, .opt:focus-visible { background: var(--surface-2); outline: none; }
@media (hover: hover) { .opt:hover { background: var(--surface-2); } }
.opt.danger { color: var(--danger); }
.opt.danger > svg { color: var(--danger); }
.opt:disabled { color: var(--text-3); cursor: not-allowed; }
.pop-sep { height: 1px; margin: 4px -4px; background: var(--border); }
.pop-head { padding: 8px 8px 6px; font-size: var(--fs-xs); color: var(--text-2); line-height: 1.5; }
.pop-head strong { display: block; color: var(--text); font-size: var(--fs-sm); font-weight: 600; }
.pop-text { padding: 8px 10px; font-size: var(--fs-sm); color: var(--text-2); line-height: 1.55; max-width: 280px; }

/* ================================================================ dialogs, drawers, sheets */
dialog.dlg {
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  max-width: none;
  max-height: min(88dvh, 820px);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
dialog.dlg[open] { display: flex; flex-direction: column; animation: dlg-in var(--dur-3) var(--ease-out); }
dialog.dlg::backdrop { background: var(--overlay); animation: fade-in var(--dur-2) ease-out; }
dialog.dlg.is-closing { animation: dlg-out var(--dur-2) var(--ease-in) forwards; }
dialog.dlg.is-closing::backdrop { animation: fade-out var(--dur-2) var(--ease-in) forwards; }
dialog.dlg.wide { width: min(640px, calc(100vw - 32px)); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes dlg-out { to { opacity: 0; transform: translateY(4px) scale(.99); } }
@keyframes fade-in { from { opacity: 0; } }

.dlg-h { flex: none; display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 4px; }
.dlg-h .titles { flex: 1 1 auto; min-width: 0; }
.dlg-title { font-size: var(--fs-lg); font-weight: 600; line-height: 1.35; }
.dlg-desc { margin-top: 4px; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.55; }
.dlg-close { margin: -4px -8px 0 0; }
.dlg-b { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 12px 20px 18px; }
.dlg-f {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.dlg-f .left { margin-right: auto; color: var(--text-3); font-size: var(--fs-xs); }

dialog.dlg.drawer {
  margin: 0 0 0 auto;
  width: min(560px, 100vw);
  height: 100dvh;
  max-height: 100dvh;
  border-width: 0 0 0 1px;
  border-radius: 0;
}
dialog.dlg.drawer[open] { animation: drawer-in var(--dur-3) var(--ease-out); }
dialog.dlg.drawer.is-closing { animation: drawer-out var(--dur-2) var(--ease-in) forwards; }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes drawer-out { to { transform: translateX(24px); opacity: 0; } }
.drawer .dlg-h { padding-top: calc(18px + env(safe-area-inset-top)); border-bottom: 1px solid var(--border); padding-bottom: 14px; }
.drawer .dlg-b { padding-top: 16px; }

@media (max-width: 639px) {
  dialog.dlg:not(.drawer), dialog.dlg.wide:not(.drawer) {
    margin: auto 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    border-width: 1px 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  dialog.dlg:not(.drawer)[open] { animation: sheet-in var(--dur-3) var(--ease-out); }
  dialog.dlg:not(.drawer).is-closing { animation: sheet-out var(--dur-2) var(--ease-in) forwards; }
  dialog.dlg:not(.drawer) .dlg-h::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 36px;
    height: 4px;
    margin-left: -18px;
    border-radius: 4px;
    background: var(--border-strong);
  }
  dialog.dlg .dlg-f .btn { flex: 1 1 0; height: 40px; }
  dialog.dlg .dlg-f .left { display: none; }
  dialog.dlg.drawer { width: 100%; border-width: 0; }
}
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }

.result { display: flex; flex-direction: column; gap: 12px; }
.result-head { display: flex; align-items: center; gap: 10px; }
.result-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--success-soft); color: var(--success); }
.result-icon svg { width: 18px; height: 18px; }
.secret {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.secret code { flex: 1 1 auto; min-width: 0; font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }

/* ================================================================ toasts */
.toasts {
  position: fixed;
  z-index: 200;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 420px;
  padding: 10px 10px 10px 14px;
  border-radius: var(--r-md);
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
  line-height: 1.45;
  animation: toast-in var(--dur-3) var(--ease-out);
}
.toast > svg { width: 16px; height: 16px; }
.toast.ok > svg { color: #5dd08f; }
.toast.error > svg { color: #ff8a80; }
.toast .msg { flex: 1 1 auto; min-width: 0; }
.toast .act { flex: none; height: 28px; padding: 0 10px; border: 0; border-radius: var(--r-sm); background: rgba(255, 255, 255, .12); color: inherit; font-weight: 500; font-size: var(--fs-xs); }
@media (hover: hover) { .toast .act:hover { background: rgba(255, 255, 255, .2); } }
.toast .x { flex: none; width: 24px; height: 24px; padding: 0; border: 0; background: none; color: inherit; opacity: .6; display: grid; place-items: center; }
.toast .x svg { width: 14px; height: 14px; }
.toast.is-leaving { animation: toast-out var(--dur-2) var(--ease-in) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }
@media (max-width: 767px) {
  .toasts { left: 12px; right: 12px; align-items: stretch; }
  .toast { max-width: none; }
}

/* ================================================================ skeleton, empty, misc */
.sk {
  display: block;
  height: 12px;
  border-radius: var(--r-xs);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.sk + .sk { margin-top: 8px; }
.sk.h-lg { height: 26px; width: 60%; }
.sk.w-40 { width: 40%; }
.sk.w-70 { width: 70%; }
.sk-rows { display: flex; flex-direction: column; }
.sk-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.sk-row:last-child { border-bottom: 0; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 40px 16px; text-align: center; color: var(--text-2); }
.empty > svg { width: 28px; height: 28px; color: var(--text-3); margin-bottom: 4px; }
.empty h3 { font-size: var(--fs-base); font-weight: 600; color: var(--text); }
.empty p { font-size: var(--fs-sm); max-width: 360px; }
.empty .btn { margin-top: 8px; }

.err-block { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 32px 16px; text-align: center; color: var(--text-2); }

.kv-inline { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--text-2); font-size: var(--fs-xs); }
.kv-inline strong { color: var(--text); font-weight: 500; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.between { justify-content: space-between; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 1099px) { .settings-grid { grid-template-columns: minmax(0, 1fr); } }
.setting { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 16px; align-items: start; }
.setting + .setting { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.setting .desc { color: var(--text-2); font-size: var(--fs-xs); margin-top: 2px; line-height: 1.5; }
@media (max-width: 520px) { .setting { grid-template-columns: minmax(0, 1fr); gap: 8px; } }

.savebar {
  position: sticky;
  bottom: 12px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  animation: toast-in var(--dur-3) var(--ease-out);
}
.savebar .msg { flex: 1 1 auto; color: var(--text-2); font-size: var(--fs-sm); }

.log-detail { margin: 0; padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2); font-family: var(--mono); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-2); }

/* ================================================================ standalone pages (login, pay result, error) */
.solo {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.solo-card {
  width: min(400px, 100%);
  padding: 28px 28px 24px;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.solo-card .brand { margin-bottom: 22px; padding: 0; }
.solo-card h1 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.01em; }
.solo-card .lead { margin-top: 6px; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.6; }
.solo-card form { margin-top: 22px; display: flex; flex-direction: column; gap: 14px; }
.solo-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--text-3); font-size: var(--fs-xs); line-height: 1.6; }
.login-status { min-height: 20px; font-size: var(--fs-sm); line-height: 1.5; }
.login-status.error { color: var(--danger); }
.login-status.ok { color: var(--success); }
.dlg .login-status:empty { display: none; }
@media (max-width: 480px) {
  .solo { place-items: start center; padding-top: 12vh; }
  .solo-card { border: 0; background: transparent; box-shadow: none; padding: 8px 4px; }
}

.pay-card { text-align: center; }
.pay-card .state-icon { display: grid; place-items: center; width: 52px; height: 52px; margin: 4px auto 16px; border-radius: 50%; background: var(--success-soft); color: var(--success); }
.pay-card .state-icon svg { width: 26px; height: 26px; }
.pay-card .state-icon.wait { background: var(--primary-soft); color: var(--link); }
.pay-card .state-icon.neutral { background: var(--surface-2); color: var(--text-2); }
.pay-card h1 { font-size: var(--fs-xl); }
.pay-card .en { margin-top: 2px; color: var(--text-3); font-size: var(--fs-sm); }
.pay-card .amount { margin-top: 18px; font-size: 32px; font-weight: 600; }
.pay-card .desc { margin-top: 4px; color: var(--text-2); }
.pay-card .note { margin-top: 20px; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.6; }

/* ================================================================ reduced motion */
/* 只保留淡入淡出，去掉位移和缩放 */
@media (prefers-reduced-motion: reduce) {
  @keyframes dlg-in { from { opacity: 0; } }
  @keyframes dlg-out { to { opacity: 0; } }
  @keyframes drawer-in { from { opacity: 0; } }
  @keyframes drawer-out { to { opacity: 0; } }
  @keyframes sheet-in { from { opacity: 0; } }
  @keyframes sheet-out { to { opacity: 0; } }
  @keyframes pop-in { from { opacity: 0; } }
  @keyframes pop-in-up { from { opacity: 0; } }
  @keyframes toast-in { from { opacity: 0; } }
  @keyframes toast-out { to { opacity: 0; } }
  @keyframes strip-in { from { opacity: 0; } }
  @keyframes grow-x { from { opacity: 0; } }
  @keyframes shake { from { opacity: 1; } }
  .sk { animation: none; }
  .btn:active { transform: none; }
  .sidebar, .switch::after, .select-trigger > svg, .tip { transition-property: opacity, background-color, color; }
}

@media (forced-colors: active) {
  .badge, .chip, .btn, .card { border: 1px solid CanvasText; }
  .admin-strip { background: Highlight; }
}
