/* ==========================================================================
   支付宝流水分析系统 — 样式表
   纯静态、完全离线（无外部字体 / 图片 / CDN / url() 外链）

   设计系统
     · 间距刻度：4 / 8 / 12 / 16 / 24 / 32（--s1 … --s6）
     · 圆角：卡片 14，控件 9，胶囊 999
     · 强调色：主色 = 蓝（--accent）；危险 / 警示 = 红（--red）
       语义色仅在数据含义处使用：绿 = 收入 / 成功，琥珀 = 「待扫码确认」瞬时状态
     · 阴影只有两级：卡片几乎无阴影，浮层用 --shadow-lg
   目录：变量 / 基础 / 顶栏 / 步骤条 / 卡片 / 表单 / 徽章 / 二维码 /
         折叠面板 / 概览卡 / 图表 / 明细表 / toast / 弹窗 / 页脚 / 响应式
   ========================================================================== */

/* ------------------------------------------------------------------ 变量 */
:root {
  /* 间距刻度 */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  /* 深色主题（默认） */
  --bg: #0c1017;
  --bg-soft: #111823;
  --panel: #141c26;
  --panel-2: #1a2330;
  --border: #28323f;
  --border-soft: #202a36;

  --text: #e9eef5;
  --text-dim: #a7b3c2;
  --text-mute: #808da1;

  --accent: #4d8dfd;
  --accent-soft: rgba(77, 141, 253, 0.14);
  --accent-line: rgba(77, 141, 253, 0.45);

  --green: #35c26b;
  --green-soft: rgba(53, 194, 107, 0.13);
  --red: #f2555a;
  --red-soft: rgba(242, 85, 90, 0.13);
  --orange: #e0a23c;
  --orange-soft: rgba(224, 162, 60, 0.13);
  --gray: #8b98a9;
  --gray-soft: rgba(139, 152, 169, 0.13);

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.5);

  --radius: 14px;
  --radius-sm: 9px;

  --qr: 264px;
  --chart-h: 250px;
  --chart-h-wide: 340px;

  --sans: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Cascadia Mono", monospace;
}

html[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-soft: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --border: #dbe1ea;
  --border-soft: #e7ecf3;

  --text: #16202e;
  --text-dim: #4e5b6c;
  --text-mute: #66707f;

  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.09);
  --accent-line: rgba(37, 99, 235, 0.38);

  --green: #128a43;
  --green-soft: rgba(18, 138, 67, 0.1);
  --red: #cf2f38;
  --red-soft: rgba(207, 47, 56, 0.1);
  --orange: #a96a06;
  --orange-soft: rgba(169, 106, 6, 0.1);
  --gray: #6b7787;
  --gray-soft: rgba(107, 119, 135, 0.1);

  --shadow: 0 1px 2px rgba(20, 35, 60, 0.06);
  --shadow-lg: 0 18px 44px rgba(20, 35, 60, 0.18);
}

/* ------------------------------------------------------------------ 基础 */
*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.35; }

p { margin: 0; }

ol, ul { margin: 0; padding: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .mono {
  font-family: var(--mono);
  font-size: 0.9em;
}
code {
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--text-dim);
}

.hint { font-size: 12px; color: var(--text-mute); }
.mute { color: var(--text-mute); }
.small { font-size: 12px; }
.spacer { margin-left: auto; }

.wrap {
  width: min(1240px, 100% - 32px);
  margin: 0 auto;
  padding: var(--s5) 0 var(--s6);
}

/* ------------------------------------------------------------------ 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
}
@supports (backdrop-filter: blur(8px)) {
  .topbar {
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(8px);
  }
}

.topbar-inner {
  width: min(1240px, 100% - 32px);
  margin: 0 auto;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  padding: var(--s2) 0;
}

.brand { display: flex; align-items: center; gap: var(--s3); min-width: 0; }

.logo {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.brand-text { min-width: 0; }
.brand h1 { font-size: 16px; }
.brand .sub { font-size: 12px; color: var(--text-mute); }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gray); }
.pill.ok .dot { background: var(--green); }
.pill.warn .dot { background: var(--orange); }
.pill.bad .dot { background: var(--red); }
.pill.ok { border-color: color-mix(in srgb, var(--green) 40%, var(--border)); }
.pill.warn { border-color: color-mix(in srgb, var(--orange) 40%, var(--border)); }
.pill.bad { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }

/* ------------------------------------------------------------------ 按钮 */
.btn {
  appearance: none;
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent-line); color: var(--text); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #fff); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger {
  background: var(--red-soft);
  border-color: color-mix(in srgb, var(--red) 40%, var(--border));
  color: var(--red);
}
.btn.danger:hover:not(:disabled) { border-color: var(--red); }
.btn.sm { padding: 5px 11px; font-size: 12px; }
.btn.current { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}
.btn-row.center { justify-content: center; }

/* ------------------------------------------------------------------ 步骤条 */
.steps {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s3);
  margin: 0 0 var(--s4);
}

.step {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  min-width: 0;
  transition: border-color .15s ease, background .15s ease;
}
.step:hover { border-color: var(--border); }

.step .idx {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-soft);
  color: var(--text-mute);
  font-size: 12px;
  font-weight: 700;
}

.step .txt { min-width: 0; }
.step .txt b {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step .txt span { font-size: 12px; color: var(--text-mute); }

/* 当前步骤：展开 */
.step.active {
  border-color: var(--accent-line);
  background: linear-gradient(180deg, var(--accent-soft), transparent 72%), var(--panel);
}
.step.active .idx { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.active .txt b { color: var(--text); }

/* 已完成步骤：折叠成一行摘要 */
.step.done .idx { background: var(--green-soft); border-color: transparent; color: var(--green); font-size: 0; }
.step.done .idx::before { content: "✓"; font-size: 13px; }
.step.done .txt b { color: var(--text-dim); }
.step.done .txt span { display: none; }

/* ------------------------------------------------------------------ 卡片 */
.card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin-bottom: var(--s4);
  overflow: hidden;
  scroll-margin-top: 76px;
}
.card:last-of-type { margin-bottom: var(--s5); }

/* 未解锁（步骤 1 未完成）：弱化但不隐藏，兜底导入仍可用 */
.card.locked { background: var(--bg-soft); }
.card.locked .card-head { border-bottom-color: var(--border-soft); }
.card.locked .card-body { opacity: .82; }

.card-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--border-soft);
}
.card-head h2 { font-size: 15px; }

.card-body { padding: var(--s5); }

.section-title {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  flex-wrap: wrap;
  margin: var(--s5) 0 var(--s3);
}
.section-title h3 { font-size: 14px; }

.note {
  margin-bottom: var(--s4);
  font-size: 12.5px;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------ 表单 */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s3);
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 12px; font-weight: 500; color: var(--text-dim); }

input:not([type="checkbox"]):not([type="file"]),
select,
textarea {
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:not([type="checkbox"]):not([type="file"]):hover,
select:hover,
textarea:hover { border-color: var(--text-mute); }
input:not([type="checkbox"]):not([type="file"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { cursor: pointer; }
textarea {
  min-height: 130px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
}
input[type="checkbox"] { accent-color: var(--accent); }

input[type="file"] {
  width: 100%;
  padding: 7px 8px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-soft);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 12px;
  margin-right: var(--s2);
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.quick-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-top: var(--s4);
}
.quick-ranges { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-ranges .btn { border-radius: 999px; padding: 4px 13px; font-size: 12px; }

/* ------------------------------------------------------------------ 徽章 / 提示 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.pending { color: var(--accent); background: var(--accent-soft); }
.badge.scanned { color: var(--orange); background: var(--orange-soft); }
.badge.confirmed { color: var(--green); background: var(--green-soft); }
.badge.expired,
.badge.canceled { color: var(--text-mute); background: var(--gray-soft); }
.badge.error { color: var(--red); background: var(--red-soft); }
.badge.income { color: var(--green); background: var(--green-soft); }
.badge.expense { color: var(--red); background: var(--red-soft); }
.badge.neutral { color: var(--text-mute); background: var(--gray-soft); }

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  margin-top: var(--s4);
  padding: 10px var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 12.5px;
}
.alert.error { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); background: var(--red-soft); color: var(--text); }
.alert.warn { border-color: color-mix(in srgb, var(--orange) 40%, var(--border)); background: var(--orange-soft); color: var(--text); }
.alert.ok { border-color: color-mix(in srgb, var(--green) 40%, var(--border)); background: var(--green-soft); color: var(--text); }
.alert .ic { flex: 0 0 auto; font-weight: 700; line-height: 1.5; }
.alert > div { min-width: 0; }

.loading-box {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-top: var(--s4);
  padding: 12px var(--s4) 15px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
}
/* 不确定进度条：等待期间始终有“在动”的视觉反馈 */
.loading-box::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 36%;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  animation: loading-bar 1.25s ease-in-out infinite;
}
@keyframes loading-bar {
  0% { left: -36%; }
  100% { left: 100%; }
}
.spinner {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 等待期间：按钮呈现“处理中”禁用态 + 行内转圈（纯 CSS，无需 JS 配合） */
#card-login:has(#qr-loading:not([hidden])) #btn-create,
#card-login:has(#qr-loading:not([hidden])) #btn-refresh,
#card-bills:has(#fetch-loading:not([hidden])) #btn-fetch,
#card-bills:has(#fetch-loading:not([hidden])) #btn-import {
  pointer-events: none;
  cursor: progress;
  opacity: .75;
}
#card-login:has(#qr-loading:not([hidden])) #btn-create,
#card-login:has(#qr-loading:not([hidden])) #btn-refresh { font-size: 0; }
#card-login:has(#qr-loading:not([hidden])) #btn-create::before,
#card-login:has(#qr-loading:not([hidden])) #btn-refresh::before,
#card-bills:has(#fetch-loading:not([hidden])) #btn-fetch::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
#card-login:has(#qr-loading:not([hidden])) #btn-create::after { content: "获取中…"; font-size: 13px; }
#card-login:has(#qr-loading:not([hidden])) #btn-refresh::after { content: "刷新中…"; font-size: 12px; }

/* 等待时二维码区域给骨架感（扫光 + 高亮描边），避免看起来像卡死。
   仅作用于空态骨架；已经显示二维码时（例如刷新）不遮挡可扫的图形。 */
#card-login:has(#qr-loading:not([hidden])) .qr-frame.blank {
  border-color: var(--accent-line);
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--panel-2));
}
#card-login:has(#qr-loading:not([hidden])) .qr-frame.blank::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 18%, var(--accent-soft) 50%, transparent 82%);
  animation: qr-sweep 1.5s ease-in-out infinite;
}
@keyframes qr-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
#card-login:has(#qr-loading:not([hidden])) .qr-empty { opacity: .5; }

.scanned-callout { font-weight: 600; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* ------------------------------------------------------------------ 二维码（步骤 1 焦点） */
.qr-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s4);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  text-align: center;
}

.qr-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s3);
  width: 100%;
}

/* 白底 + 内边距，保证二维码静区可见 */
.qr-frame {
  position: relative;
  padding: 18px;
  border-radius: 20px;
  background: #ffffff;
  line-height: 0;
  box-shadow: 0 10px 30px rgba(2, 8, 20, .28);
}
.qr-frame img {
  display: block;
  width: var(--qr);
  height: var(--qr);
  border-radius: 6px;
  image-rendering: pixelated;
}
.qr-frame.blank {
  width: calc(var(--qr) + 36px);
  height: calc(var(--qr) + 36px);
  display: grid;
  place-items: center;
  padding: var(--s4);
  border: 1px dashed var(--border);
  background: var(--panel-2);
  box-shadow: none;
  overflow: hidden;
  color: var(--text-mute);
  font-size: 12.5px;
  line-height: 1.7;
}
.qr-frame.loading::after {
  content: "二维码加载中…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: rgba(255, 255, 255, .86);
  color: #3a4552;
  font-size: 12.5px;
}

/* 空态：明确告诉用户“点这里开始”，而不是一片空白 */
.qr-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  width: 100%;
  line-height: 1.7;
  text-align: center;
}
.qr-empty-icon { color: var(--text-mute); opacity: .6; }
.qr-empty-title { font-size: 13.5px; font-weight: 600; color: var(--text-dim); }
.qr-empty-hint { font-size: 12px; }

/* 步骤 1 的等待提示：占满二维码区域宽度，足够醒目 */
#qr-loading { width: 100%; text-align: left; }

.qr-status {
  min-height: 24px;
  font-size: 14.5px;
  color: var(--text);
}
.qr-times {
  display: flex;
  justify-content: center;
  gap: 6px var(--s4);
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}
#qr-account { display: flex; justify-content: center; }

.uuid-chip {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  max-width: 420px;
  padding: 5px 6px 5px var(--s3);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--bg-soft);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-mute);
}
.uuid-chip .val {
  flex: 1;
  min-width: 0;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.uuid-chip button {
  font: inherit;
  cursor: pointer;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-dim);
}
.uuid-chip button:hover { color: var(--text); border-color: var(--accent-line); }

.privacy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-mute);
}
.privacy b { font-weight: 600; color: var(--text-dim); }

/* ------------------------------------------------------------------ 折叠面板 */
details.collapse {
  width: 100%;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  overflow: hidden;
  text-align: left;
}
details.collapse > summary {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 10px var(--s4);
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
details.collapse > summary::-webkit-details-marker { display: none; }
details.collapse > summary::before {
  content: "";
  width: 0;
  height: 0;
  flex: 0 0 auto;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  opacity: .65;
  transition: transform .15s ease;
}
details.collapse[open] > summary::before { transform: rotate(90deg); }
details.collapse > summary:hover { color: var(--text); }
details.collapse > summary .hint { font-weight: 400; }

.collapse-body {
  padding: var(--s4);
  border-top: 1px solid var(--border-soft);
  background: var(--panel);
}
.collapse-body > * + * { margin-top: var(--s4); }

.howto {
  display: grid;
  gap: 6px;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-dim);
}
.howto li::marker { color: var(--text-mute); }

/* ------------------------------------------------------------------ 概览卡片 */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s3);
}
.stat-card {
  padding: var(--s4);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel-2);
  min-width: 0;
}
.stat-card .k { font-size: 12px; color: var(--text-mute); }
.stat-card .v {
  margin-top: 6px;
  font-size: clamp(19px, 1.7vw, 22px);
  font-weight: 700;
  letter-spacing: -.2px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat-card .x { margin-top: 2px; font-size: 11.5px; color: var(--text-mute); font-variant-numeric: tabular-nums; }
.v.pos { color: var(--green); }
.v.neg { color: var(--red); }
.v.zero { color: var(--text); }

/* ------------------------------------------------------------------ 图表 */
.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s4);
}
.chart-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--s4) var(--s4) var(--s3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.chart-card.wide { grid-column: 1 / -1; }

.chart-head {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  flex-wrap: wrap;
  margin-bottom: var(--s3);
}
.chart-head h4 { font-size: 13.5px; }

/* 固定高度：SVG 注入前后布局不跳；同一行里若另一张卡更高，则本卡图表区随之长高 */
.chart-box { width: 100%; height: var(--chart-h); flex: 1 1 auto; }
.chart-card.wide .chart-box { height: var(--chart-h-wide); }
.chart-box.donut { height: 280px; }
.chart-box.tall { height: var(--chart-h-wide); }
.chart-box svg { display: block; width: 100%; height: 100%; overflow: visible; }

.chart-empty {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 120px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-mute);
  font-size: 12.5px;
}

/* SVG 内部元素 */
.grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; }
.axis-line { stroke: var(--border); stroke-width: 1.2; }
.axis-label,
.axis-title { fill: var(--text-mute); font-size: 11px; font-family: var(--sans); }
.bar-income { fill: var(--green); }
.bar-expense { fill: var(--red); }
.bar-neutral { fill: var(--gray); }
.bar-other { fill: var(--accent); }
.bar,
.donut-slice { transition: opacity .12s ease; }
.bar:hover,
.donut-slice:hover { opacity: .78; }
.donut-center-title { fill: var(--text-mute); font-size: 12px; font-family: var(--sans); }
.donut-center-value { fill: var(--text); font-size: 19px; font-weight: 700; font-family: var(--sans); }
.line-path { fill: none; stroke: var(--accent); stroke-width: 2; }
.line-dot { fill: var(--accent); }

.legend {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--s3);
  max-height: 200px;
  overflow: auto;
}
.legend .item {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--s2);
  padding: 3px var(--s1);
  border-radius: 6px;
  font-size: 12px;
}
.legend .item:hover { background: var(--bg-soft); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.legend .amt { color: var(--text); font-variant-numeric: tabular-nums; }
.legend .pc { min-width: 44px; text-align: right; color: var(--text-mute); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ 明细表 */
.toolbar {
  display: flex;
  align-items: flex-end;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-bottom: var(--s3);
}
.toolbar .field { flex: 1 1 180px; max-width: 280px; }
.toolbar .field.grow { flex: 2 1 240px; max-width: 380px; }
.toolbar .field.narrow { flex: 0 1 120px; max-width: 140px; }
.toolbar-end { align-self: flex-end; }

.table-wrap {
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
}

table.bills {
  width: 100%;
  min-width: 960px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
table.bills th,
table.bills td {
  padding: 10px var(--s3);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-soft);
}
table.bills thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
table.bills thead th.sortable { cursor: pointer; user-select: none; }
table.bills thead th.sortable:hover { color: var(--text); }
table.bills thead th .arrow { margin-left: 4px; color: var(--accent); font-size: 10px; }
table.bills th.ta-r,
table.bills td.num { text-align: right; }
table.bills tbody tr:hover td { background: var(--bg-soft); }
table.bills tbody tr:last-child td { border-bottom: 0; }

table.bills td.num {
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.bills td.time {
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
}
table.bills td.cp { max-width: 200px; }
table.bills td.sub { max-width: 240px; color: var(--text-dim); }
table.bills td.order { max-width: 170px; font-family: var(--mono); font-size: 11px; color: var(--text-mute); }
table.bills td.cp .ell,
table.bills td.sub .ell,
table.bills td.order .ell {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amt-in { color: var(--green); }
.amt-out { color: var(--red); }
.amt-nu { color: var(--text-dim); }

.empty {
  padding: 48px var(--s5);
  text-align: center;
  color: var(--text-mute);
}
.empty .big { margin-bottom: 6px; font-size: 26px; }

.pager {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  margin-top: var(--s3);
}
.pager .info { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.pager .pages { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.pager .pages .btn { min-width: 32px; padding: 4px 8px; font-size: 12px; }

/* ------------------------------------------------------------------ 会话列表 */
.sessions { display: grid; gap: var(--s2); }
.session-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  padding: var(--s3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-size: 12.5px;
}
.session-item.current { border-color: var(--accent-line); background: var(--accent-soft); }
.session-item .grow { flex: 1 1 200px; min-width: 0; }
.session-item .u {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item .tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--gray-soft);
  color: var(--text-dim);
  font-size: 11px;
}
.session-item .tag.on { background: var(--green-soft); color: var(--green); }
.session-item .tag.off { color: var(--text-mute); }

/* ------------------------------------------------------------------ toast */
.toast-host {
  position: fixed;
  right: var(--s4);
  bottom: var(--s4);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: 10px var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  pointer-events: auto;
  animation: toast-in .18s ease;
}
.toast .ic { flex: 0 0 auto; font-weight: 700; }
.toast .tx { min-width: 0; word-break: break-word; }
.toast .x {
  margin-left: auto;
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--text-mute);
  font: inherit;
  cursor: pointer;
}
.toast.success { border-color: color-mix(in srgb, var(--green) 45%, var(--border)); }
.toast.success .ic { color: var(--green); }
.toast.error { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }
.toast.error .ic { color: var(--red); }
.toast.warn { border-color: color-mix(in srgb, var(--orange) 45%, var(--border)); }
.toast.warn .ic { color: var(--orange); }
.toast.info .ic { color: var(--accent); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------------ 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: var(--s5);
  background: rgba(4, 8, 16, .58);
}
@supports (backdrop-filter: blur(3px)) {
  .modal { backdrop-filter: blur(3px); }
}

.modal-card {
  width: min(720px, 100%);
  max-height: min(86vh, 820px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 { font-size: 14px; }
.modal-scroll { flex: 1; min-height: 0; overflow: auto; }
.modal-body { padding: var(--s4) var(--s4) var(--s2); }

.modal-section {
  padding: var(--s4);
  border-top: 1px solid var(--border-soft);
}
.modal-section-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  margin-bottom: var(--s3);
}
.modal-section-head h4 { font-size: 13px; }
.modal-section .alert { margin-top: var(--s3); }

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--s3);
  margin-bottom: var(--s4);
}
.kv {
  min-width: 0;
  padding: 9px var(--s3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.kv .k { font-size: 11.5px; color: var(--text-mute); }
.kv .v { font-size: 13px; font-weight: 600; word-break: break-all; }
.kv .v.ok { color: var(--green); }
.kv .v.bad { color: var(--red); }
.kv .v.warn { color: var(--orange); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-dim);
  font-size: 11.5px;
}
.chip.ok { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, var(--border)); }
.chip.bad { color: var(--text-mute); }

pre.raw {
  margin: 0;
  padding: var(--s3);
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ------------------------------------------------------------------ 页脚 */
.footnote {
  margin-top: var(--s5);
  text-align: center;
  font-size: 12px;
  color: var(--text-mute);
}

/* ------------------------------------------------------------------ 响应式 */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .chart-card.wide { grid-column: auto; }
  /* 窄屏仍为确定高度（不跳动），只是随宽度收缩，避免图形被“邮政信箱”式留白 */
  .chart-box { height: clamp(190px, 42vw, 260px); }
  .chart-card.wide .chart-box,
  .chart-box.tall { height: clamp(190px, 40vw, 280px); }
  .chart-box.donut { height: clamp(230px, 58vw, 290px); }

  /* 步骤条横向滚动 */
  .steps {
    display: flex;
    gap: var(--s2);
    overflow-x: auto;
    padding-bottom: var(--s2);
    scroll-snap-type: x proximity;
  }
  .step { flex: 0 0 226px; scroll-snap-align: start; }

  .card-head,
  .card-body { padding: var(--s4); }
  .toolbar .field,
  .toolbar .field.grow,
  .toolbar .field.narrow { flex: 1 1 100%; max-width: none; }
  .toolbar-end { width: 100%; }
  .toolbar-end .btn { width: 100%; }
  .modal { padding: var(--s3); }
}

@media (max-width: 560px) {
  .wrap,
  .topbar-inner { width: calc(100% - 24px); }
  .brand .sub { display: none; }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .card-head h2 { font-size: 14px; }
  .qr-frame { padding: 14px; border-radius: 16px; }
  .qr-frame.blank { width: calc(var(--qr) + 28px); height: calc(var(--qr) + 28px); }
  .qr-frame.loading::after { border-radius: 16px; }
  .toast-host { left: var(--s3); right: var(--s3); max-width: none; }
}

@media (max-width: 420px) {
  :root { --qr: 200px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
