:root {
  color-scheme: light;
  --bg: #f1f3f5;
  --surface: #ffffff;
  --surface-2: #f6f7f8;
  --border: #dde1e5;
  --text: #1c2228;
  --text-2: #52595f;
  --muted: #7a8086;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --grid: #e7e9ec;
  --good: #1a7f4b;
  --good-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fdf0d9;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --topbar: #1f2a33;
  --topbar-ink: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111416; --surface: #1b1f22; --surface-2: #22272b; --border: #2f353a;
    --text: #eef1f3; --text-2: #b9c0c6; --muted: #8b939a;
    --accent: #3987e5; --series-1: #3987e5; --grid: #2a2f33;
    --good: #5cc98d; --good-bg: #16301f; --warn: #f0b44c; --warn-bg: #33270f; --bad: #f28b82; --bad-bg: #3a1a18;
    --topbar: #161b1f; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111416; --surface: #1b1f22; --surface-2: #22272b; --border: #2f353a;
  --text: #eef1f3; --text-2: #b9c0c6; --muted: #8b939a;
  --accent: #3987e5; --series-1: #3987e5; --grid: #2a2f33;
  --good: #5cc98d; --good-bg: #16301f; --warn: #f0b44c; --warn-bg: #33270f; --bad: #f28b82; --bad-bg: #3a1a18;
  --topbar: #161b1f; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei UI", "Noto Sans CJK SC", system-ui, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0 0 8px; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); min-height: 1.5em; margin: 8px 0 0; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--topbar); color: var(--topbar-ink);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.brand span { font-weight: 400; opacity: .75; margin-left: 10px; font-size: 14px; }
.top-actions { display: flex; gap: 2px; }
.icon-button { background: transparent; border: 0; color: inherit; font-size: 22px; width: 40px; height: 40px; border-radius: 20px; }
.icon-button:active { background: rgba(255, 255, 255, .12); }

main { padding: 12px 12px 8px; max-width: 760px; margin: 0 auto; }
.page { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card > h2 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.login-card { margin-top: 40px; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.25; margin-top: 2px; overflow-wrap: anywhere; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile.hero { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.tile.hero .value { font-size: 34px; }
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.status.good { color: var(--good); background: var(--good-bg); }
.status.warn { color: var(--warn); background: var(--warn-bg); }
.status.bad { color: var(--bad); background: var(--bad-bg); }
.status.plain { color: var(--text-2); background: var(--surface-2); }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); opacity: .08; }
.chart .bar { fill: var(--series-1); }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .empty { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }

.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 10px; }
.hbar .name { color: var(--text-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .track { height: 14px; border-radius: 4px; background: transparent; position: relative; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.hbar .num { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text); min-width: 3ch; text-align: right; }

.searchbar { display: flex; gap: 8px; }
input[type="search"], input[type="password"], input[type="number"], input[type="text"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 13px; color: var(--text-2); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
button.primary, button.secondary, button.danger {
  border: 0; border-radius: 10px; padding: 10px 16px; min-height: 44px; font-weight: 600; white-space: nowrap;
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: #c62828; color: #fff; }
button.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
button.block { width: 100%; }
button:disabled { opacity: .5; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 14px; min-height: 36px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: transparent; padding: 4px 10px; font-size: 12.5px; min-height: 30px; }
.segmented button.active { background: var(--accent); color: var(--accent-ink); }

.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-top: 1px solid var(--border); min-width: 0; }
.list > .row:first-child { border-top: 0; }
.row.tappable { cursor: pointer; }
.row.tappable:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.row .side { text-align: right; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.row > select[data-module] { width: auto; min-width: 112px; max-width: 42%; flex: 0 1 42%; }
.rank { width: 22px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.empty-state { color: var(--muted); padding: 16px 0; text-align: center; font-size: 13px; }
.dup-group { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.dup-group.cross { border-color: var(--bad); }
.dup-group ul { margin: 6px 0 8px; padding-left: 18px; font-size: 13px; color: var(--text-2); }
.log { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--text-2); max-height: 360px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.log div { padding: 4px 0; border-top: 1px dashed var(--border); }
.log div:first-child { border-top: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { border: 0; background: transparent; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; min-height: 56px; min-width: 0; white-space: nowrap; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar .icon { width: 22px; height: 22px; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.bot-log { max-height: 260px; overflow: auto; margin-top: 12px; font-size: 12px; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--surface); color: var(--text);
  border-radius: 16px 16px 0 0; max-height: 88vh; overflow: auto; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.section-title { font-size: 13px; color: var(--muted); margin: 16px 0 6px; font-weight: 600; }
@media (max-width: 560px) { #reset-controls-card { display: none; } }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--text); color: var(--surface);
  font-size: 12.5px; padding: 6px 10px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--bad); color: #fff; }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.tier-table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tier-table th, .tier-table td { padding: 7px 4px; text-align: right; border-top: 1px solid var(--border); white-space: nowrap; }
.tier-table th { color: var(--muted); font-weight: 600; border-top: 0; }
.tier-table th:first-child, .tier-table td:first-child { text-align: left; white-space: normal; min-width: 6em; }
.tier-table tr.tiered td:first-child { font-weight: 600; }
.tier-table tr.tiered td:first-child::before { content: "● "; color: var(--accent); }

.list.items .rank { width: 64px; text-align: left; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--series-1); border-radius: 3px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
