:root {
  --bg: #0b1220;
  --bg-soft: #111a2b;
  --card: #151f33;
  --card-2: #1a2740;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eaf1ff;
  --muted: #8ba0bf;
  --ok: #38d39f;
  --warn: #f5b942;
  --bad: #ff6b6b;
  --info: #63a4ff;
  --accent: #ffce5c;
  --radius: 18px;
  --pad: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f5fb;
    --bg-soft: #e8eef8;
    --card: #ffffff;
    --card-2: #f5f8ff;
    --line: rgba(16, 36, 66, 0.10);
    --text: #10223a;
    --muted: #5b6f8c;
    --accent: #c98a00;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body { min-height: 100dvh; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 10px) 0 calc(var(--safe-bottom) + 84px);
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px var(--pad) 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 38px; height: 38px; border-radius: 11px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }
.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: 0.2px; }
.brand-text p { margin: 1px 0 0; font-size: 11px; color: var(--muted); }
.top-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }

/* ---------- 总览 ---------- */
.overview {
  margin: 4px var(--pad) 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(99, 164, 255, 0.16), rgba(56, 211, 159, 0.10));
  border: 1px solid var(--line);
}
.ov-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.ov-cell { display: flex; flex-direction: column; gap: 2px; }
.ov-num { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ov-num.ok { color: var(--ok); }
.ov-num.bad { color: var(--bad); }
.ov-label { font-size: 10px; color: var(--muted); }
.ov-foot {
  display: flex; justify-content: space-between;
  margin-top: 9px; padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 11px; color: var(--muted);
}

/* 多币种/单位汇总：不同单位不相加 */
.ov-sums {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
}
.ov-sum {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}
.ov-sum b {
  font-size: 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.ov-sum i { font-style: normal; }
.ov-sum em { font-style: normal; opacity: 0.7; }

/* ---------- 搜索 ---------- */
.search-wrap { padding: 0 var(--pad) 10px; }
.search-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.search-input:focus { border-color: var(--info); }
.search-input::placeholder { color: var(--muted); }

/* ---------- 卡片 ---------- */
.cards { display: grid; gap: 12px; padding: 0 var(--pad); }

.card {
  position: relative;
  padding: 14px 15px 13px;
  border-radius: var(--radius);
  background: linear-gradient(170deg, var(--card-2), var(--card));
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.card:active { transform: scale(0.985); }
.card:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { display: flex; align-items: center; gap: 7px; min-width: 0; }
.card-title h2 {
  margin: 0; font-size: 14px; font-weight: 620;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.dot-ok { background: var(--ok); box-shadow: 0 0 8px rgba(56, 211, 159, 0.7); }
.dot-warn { background: var(--warn); }
.dot-empty, .dot-error, .dot-auth, .dot-relay { background: var(--bad); }
.dot-idle { background: var(--muted); }

.chip {
  font-size: 10px; line-height: 1;
  padding: 4px 7px; border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.chip-ok { color: var(--ok); border-color: rgba(56, 211, 159, 0.4); background: rgba(56, 211, 159, 0.10); }
.chip-warn { color: var(--warn); border-color: rgba(245, 185, 66, 0.4); background: rgba(245, 185, 66, 0.10); }
.chip-empty { color: var(--bad); border-color: rgba(255, 107, 107, 0.4); background: rgba(255, 107, 107, 0.10); }
.chip-auth { color: var(--info); border-color: rgba(99, 164, 255, 0.4); background: rgba(99, 164, 255, 0.10); }
.chip-error, .chip-relay { color: var(--bad); border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.08); }
.chip-idle { color: var(--muted); }

.card-value {
  margin: 10px 0 4px;
  font-size: 30px;
  font-weight: 720;
  letter-spacing: -0.4px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.card-sub { margin: 0; font-size: 11px; color: var(--muted); }
.card-eta { margin: 6px 0 0; font-size: 11px; color: var(--accent); }
.card-err { margin: 8px 0 0; font-size: 11px; color: var(--bad); line-height: 1.45; }

.ring {
  --pct: 0;
  width: 44px; height: 44px; flex: 0 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--color, var(--info)) calc(var(--pct) * 1%), rgba(255, 255, 255, 0.10) 0);
}
.ring span {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--card);
  font-size: 10px; font-weight: 600;
  color: var(--muted);
}

/* ---------- 空状态 / 新手向导 ---------- */
.empty-hint {
  margin: 26px var(--pad);
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.wizard {
  margin: 6px var(--pad) 0;
  padding: 16px 16px 14px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
}
.wizard h2 { margin: 0 0 12px; font-size: 15px; font-weight: 640; }
.wizard-steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; counter-reset: step; }
.wizard-steps li {
  position: relative;
  padding-left: 30px;
  counter-increment: step;
}
.wizard-steps li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: 0;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  color: #23180a;
  background: var(--accent);
}
.wizard-steps b { display: block; font-size: 13px; font-weight: 620; margin-bottom: 3px; }
.wizard-steps span { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.wizard-steps code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}
.wizard-note { margin: 12px 0 0; font-size: 11px; color: var(--muted); line-height: 1.5; }

/* ---------- 趋势图 ---------- */
.trend {
  margin: 12px 0 4px;
  padding: 12px 12px 8px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
.trend-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; font-size: 12px; margin-bottom: 8px;
}
.trend-head .muted { font-size: 10.5px; }
.trend-rate {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trend-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 10px;
  font-size: 10.5px;
  margin-top: 4px;
}
.trend-eta { color: var(--accent); }
.spark { width: 100%; height: 52px; display: block; overflow: visible; }
.spark-area { fill: rgba(99, 164, 255, 0.16); stroke: none; }
.spark-line {
  fill: none;
  stroke: var(--info);
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.spark-dot { fill: var(--accent); stroke: none; }

/* 令牌识别提示 */
.token-detect { min-height: 0; }
.token-detect.ok { color: var(--ok); }
.token-detect.bad { color: var(--bad); }

/* 密码框 + 显示/隐藏 */
.secret-wrap { display: flex; gap: 8px; align-items: stretch; }
.secret-wrap input { flex: 1; min-width: 0; }
.secret-toggle {
  flex: 0 0 auto;
  width: 58px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.secret-toggle.on { color: var(--info); border-color: rgba(99, 164, 255, 0.5); }
.secret-toggle:active { transform: scale(0.97); }

.field-note {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* 详情页：查看已保存凭证 */
.link-btn {
  margin-top: 8px;
  padding: 4px 10px;
  font-size: 11.5px;
  color: var(--info);
  background: transparent;
  border: 1px solid rgba(99, 164, 255, 0.35);
  border-radius: 999px;
  font-family: inherit;
  cursor: pointer;
}
.link-btn:active { transform: scale(0.98); }
.key-reveal {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  word-break: break-all;
  text-align: left;
  color: var(--text);
}

/* ---------- 底部 ---------- */
.bottom-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 10px var(--pad) calc(var(--safe-bottom) + 10px);
  display: flex; justify-content: center;
  background: linear-gradient(to top, var(--bg) 55%, rgba(0, 0, 0, 0));
  pointer-events: none;
}
.fab {
  pointer-events: auto;
  width: 100%; max-width: 528px;
  height: 50px;
  border: 0; border-radius: 15px;
  background: linear-gradient(135deg, #ffce5c, #ffa63d);
  color: #23180a;
  font-size: 15px; font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: 0 8px 22px rgba(255, 166, 61, 0.32);
  cursor: pointer;
}
.fab:active { transform: scale(0.99); }

/* ---------- 抽屉 ---------- */
.sheet, .detail { position: fixed; inset: 0; z-index: 50; }
.sheet[hidden], .detail[hidden] { display: none; }
.sheet-mask, .detail-mask {
  position: absolute; inset: 0;
  background: rgba(4, 8, 16, 0.62);
  opacity: 0; transition: opacity 0.18s ease;
}
.sheet.open .sheet-mask, .detail.open .detail-mask { opacity: 1; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--bg-soft);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--line);
  transform: translateY(100%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: var(--safe-bottom);
}
.sheet.open .sheet-panel { transform: translateY(0); }
.sheet-grab { width: 38px; height: 4px; border-radius: 4px; background: var(--line); margin: 8px auto 0; }
.sheet-head, .detail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px var(--pad) 4px;
}
.sheet-head h2 { margin: 0; font-size: 15px; font-weight: 640; }
.sheet-body, .detail-body { overflow-y: auto; padding: 6px var(--pad) 18px; -webkit-overflow-scrolling: touch; }

/* ---------- 表单 ---------- */
.form-wrap { display: grid; gap: 12px; padding-top: 4px; }
.form-head { display: flex; }
.badge {
  font-size: 11px; padding: 4px 9px; border-radius: 999px;
  background: rgba(99, 164, 255, 0.14); color: var(--info);
  border: 1px solid rgba(99, 164, 255, 0.3);
}
.field { display: grid; gap: 6px; }
.field-label { font-size: 12px; color: var(--muted); }
.field-label em { color: var(--bad); font-style: normal; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-family: inherit;
  outline: none;
}
.field textarea { resize: vertical; min-height: 54px; font-size: 13px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--info); }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: 0.7; }
.field-help { font-size: 11px; color: var(--muted); line-height: 1.5; }

.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn {
  flex: 1;
  height: 46px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: linear-gradient(135deg, #ffce5c, #ffa63d); color: #23180a; border: 0; }
.btn.danger { color: var(--bad); border-color: rgba(255, 107, 107, 0.35); }
.btn.ghost { color: var(--muted); }
.btn:active { transform: scale(0.99); }
.form-msg { margin: 2px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.form-msg.good { color: var(--ok); }
.form-msg.bad { color: var(--bad); }

/* ---------- 选择类型 ---------- */
.sheet-hint { margin: 2px 0 10px; font-size: 12px; color: var(--muted); }
.pick-list { display: grid; gap: 8px; }
.pick-row {
  display: grid; gap: 3px; text-align: left;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.pick-row strong { font-size: 14px; font-weight: 620; }
.pick-row span { font-size: 11px; color: var(--muted); line-height: 1.45; }

/* ---------- 详情 ---------- */
.detail-panel {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.detail.open .detail-panel { transform: translateX(0); }
.detail-head { padding-top: calc(var(--safe-top) + 10px); border-bottom: 1px solid var(--line); }
.detail-body { padding-top: 14px; }
.detail-hero { text-align: center; padding-bottom: 8px; }
.detail-num { font-size: 34px; font-weight: 720; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.detail-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12px; }
.detail-table th, .detail-table td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.detail-table th:first-child, .detail-table td:first-child { text-align: left; }
.detail-table th { color: var(--muted); font-weight: 500; }
.raw { margin: 10px 0; font-size: 12px; color: var(--muted); }
.raw pre {
  max-height: 220px; overflow: auto;
  background: var(--card); padding: 10px; border-radius: 12px;
  font-size: 11px; line-height: 1.5; color: var(--text);
}
.detail-actions { display: flex; gap: 10px; margin-top: 14px; }
.muted { color: var(--muted); font-size: 12px; }
.small { font-size: 11px; line-height: 1.5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-bottom) + 82px);
  transform: translate(-50%, 12px);
  max-width: 86vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20, 32, 52, 0.96);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12.5px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-ok { border-color: rgba(56, 211, 159, 0.5); }
.toast-warn { border-color: rgba(245, 185, 66, 0.6); }

/* ---------- 自测页 ---------- */
.selftest-mode .overview,
.selftest-mode .cards,
.selftest-mode .wizard,
.selftest-mode .search-wrap,
.selftest-mode .bottom-bar { display: none; }
.selftest { margin: 8px var(--pad); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.selftest .t-line { padding: 3px 0; border-bottom: 1px dashed var(--line); }
.selftest .pass { color: var(--ok); }
.selftest .fail { color: var(--bad); }
.selftest h2 { font-size: 15px; }

@media (max-width: 360px) {
  .card-value { font-size: 26px; }
  .ov-num { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}