:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-2: #14b8a6;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --info-bg: #e0f2fe;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 14px;
  --font: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #111a2c; --surface-2: #0f1727; --line: #1f2b40; --text: #e2e8f0; --muted: #94a3b8;
    --accent: #2dd4bf; --accent-2: #14b8a6; --accent-ink: #04201c;
    --ok: #4ade80; --ok-bg: #052e1a; --warn: #fbbf24; --warn-bg: #3a2a05; --err: #f87171; --err-bg: #3b0d0d; --info-bg: #0c2a3d;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #111a2c; --surface-2: #0f1727; --line: #1f2b40; --text: #e2e8f0; --muted: #94a3b8;
  --accent: #2dd4bf; --accent-2: #14b8a6; --accent-ink: #04201c;
  --ok: #4ade80; --ok-bg: #052e1a; --warn: #fbbf24; --warn-bg: #3a2a05; --err: #f87171; --err-bg: #3b0d0d; --info-bg: #0c2a3d;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }

/* layout */
.app { display: grid; grid-template-columns: 200px 1fr; grid-template-rows: 56px 1fr; height: 100vh; height: 100dvh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-status { display: flex; align-items: center; gap: 8px; }
.nav { background: var(--surface); border-right: 1px solid var(--line); padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.main { overflow-y: auto; padding: 24px; }
.page { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 52px 1fr 62px; }
  .nav { grid-row: 3; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 4px; overflow-x: auto; gap: 0;
    padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .nav a { flex: 1 1 0; min-width: 44px; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 10px; justify-content: center; white-space: nowrap; }
  .nav a svg { width: 22px; height: 22px; }
  .main { padding: 16px; }
  .topbar { padding: 0 12px; }
}

/* connection pill */
.conn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; max-width: 46vw; }
.conn span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.conn.on .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.conn.busy .dot { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.badge { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); font-weight: 600; white-space: nowrap; }

/* cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h2 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h3 { margin: 16px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.warn .v { color: var(--warn); } .stat.err .v { color: var(--err); } .stat.ok .v { color: var(--ok); }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 140px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 9px 12px; min-height: 40px; }
input[type=range] { accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea { font-family: var(--mono); font-size: 13px; min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.big-input { font-size: 34px !important; font-weight: 700; padding: 10px 14px !important; font-variant-numeric: tabular-nums; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.btn.danger.solid { background: var(--err); color: #fff; border-color: var(--err); }
.btn.lg { min-height: 56px; font-size: 18px; padding: 10px 22px; border-radius: 12px; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.presets .btn { min-height: 48px; font-size: 17px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--surface-2); font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; background: var(--surface-2); }
td input[type=number] { min-height: 34px; padding: 4px 8px; width: 96px; }

/* pills */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.err { background: var(--err-bg); color: var(--err); border-color: transparent; }
.pill.info { background: var(--info-bg); border-color: transparent; }

/* transaction panel */
.tx-panel { display: grid; gap: 14px; }
.tx-amounts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tx-amounts .stat .v { font-size: 34px; }
@media (max-width: 560px) { .tx-amounts .stat .v { font-size: 24px; } }
.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.result { border-radius: var(--radius); padding: 20px; display: flex; gap: 16px; align-items: center; }
.result.ok { background: var(--ok-bg); } .result.warn { background: var(--warn-bg); } .result.err { background: var(--err-bg); }
.result .icon { font-size: 40px; line-height: 1; }
.result h2 { margin: 0; font-size: 22px; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--info-bg); font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.err { background: var(--err-bg); color: var(--err); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-all; }
pre.json { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 12px/1.5 var(--mono);
  overflow: auto; max-height: 360px; margin: 0; white-space: pre-wrap; word-break: break-all; }
.empty { text-align: center; padding: 32px; color: var(--muted); }

/* console */
.log { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; font: 12px/1.6 var(--mono); height: 52vh; overflow: auto; padding: 8px 10px; }
.log div { white-space: pre-wrap; word-break: break-all; }
.log .tx { color: var(--accent); } .log .rx { color: var(--text); } .log .ev { color: var(--warn); } .log .log-l { color: var(--muted); }

/* toasts & dialog */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
@media (max-width: 760px) { .toasts { bottom: 76px; left: 16px; } }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: in .2s; }
.toast.err { background: var(--err); color: #fff; } .toast.ok { background: var(--ok); color: #fff; } .toast.warn { background: var(--warn); color: #fff; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }
.dlg { border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); width: min(640px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(15, 23, 42, .45); }
.dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 17px; }
.dlg-body { padding: 16px 20px; max-height: 70vh; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.dlg-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; }

/* 展示站 */
.demo-tag { flex: none; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-decoration: none;
  background: var(--warn-bg); color: var(--warn); }
