:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --pink: #ff4d8d;
  --green: #2ecc71;
  --amber: #f5a623;
  --blue: #4aa3ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

h1 { margin: 0 0 12px; font-size: 18px; font-weight: 650; }

.muted { color: var(--muted); font-weight: 400; }
.center { text-align: center; }

.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.pill {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
}

.token {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.token input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 8px;
  width: 280px;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--blue); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: rgba(74,163,255,.18); border-color: var(--blue); color: var(--blue); }
button.primary:hover { background: rgba(74,163,255,.28); }

/* ---- onboarding (batch-add) panel ---- */
.add-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.add-panel.hidden { display: none; }
.add-grid { display: flex; flex-wrap: wrap; gap: 12px 18px; }
.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.fld-wide { flex: 1 1 100%; }
.fld-check { flex-direction: row; align-items: center; gap: 7px; align-self: flex-end; color: var(--text); }
.fld input[type="text"], .fld input[type="number"], .fld textarea {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 6px 9px; font-size: 13px;
}
.fld textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.fld input[type="text"] { min-width: 240px; }
.fld input[type="number"] { width: 120px; }
.add-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.add-result { margin-top: 12px; }
.add-result:empty { display: none; }
.add-result table { width: auto; min-width: 60%; }
.add-result th, .add-result td { padding: 5px 10px; font-size: 12px; }
.add-result .pill-sm { font-size: 11px; padding: 1px 7px; border-radius: 4px; }
.pill-sm.created { background: rgba(46,204,113,.15); color: var(--green); }
.pill-sm.skipped { background: rgba(245,166,35,.15); color: var(--amber); }
.pill-sm.exists { background: rgba(139,147,163,.15); color: var(--muted); }
.pill-sm.noeoa { background: rgba(255,77,141,.15); color: var(--pink); }
.add-err { color: #ffb3cd; }

/* ---- account stats (funnel + segmented bars + flag chips) ---- */
.stats {
  display: grid;
  grid-template-columns: minmax(300px, 1.1fr) minmax(320px, 1.4fr);
  gap: 16px 28px;
  margin-bottom: 16px;
  align-items: start;
}
@media (max-width: 880px) { .stats { grid-template-columns: 1fr; } }
.stat-block { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.stat-gtitle { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat-block .segbars { margin-bottom: 4px; }

/* Funnel: one clickable row per stage = label + decaying bar + count + % + drop. */
.funnel { display: flex; flex-direction: column; gap: 3px; }
.fn-row {
  display: grid;
  grid-template-columns: 64px 1fr 38px 38px 40px;
  align-items: center; gap: 8px;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  padding: 3px 6px; cursor: pointer; text-align: left; width: 100%;
  font-variant-numeric: tabular-nums;
}
.fn-row:hover { background: var(--panel); border-color: var(--line); }
.fn-row.active { background: rgba(74,163,255,.12); border-color: var(--blue); }
.fn-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.fn-row.active .fn-label { color: var(--text); }
.fn-track { height: 14px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.fn-fill { display: block; height: 100%; background: rgba(74,163,255,.55); border-radius: 4px; }
.fn-num { text-align: right; color: var(--text); font-weight: 650; font-size: 12px; }
.fn-pct { text-align: right; color: var(--muted); font-size: 11px; }
.fn-drop { text-align: right; color: var(--pink); font-size: 11px; }

/* Segmented proportion bar: each mutually-exclusive slice as a clickable segment,
   widths summing to 100%. A legend below carries the same slices as clickable
   pills (so a sliver too thin to click in the bar is still reachable). */
.segbar { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.seg-title { font-size: 11px; color: var(--muted); }
.seg-track { display: flex; height: 18px; border-radius: 5px; overflow: hidden; background: var(--panel-2); border: 1px solid var(--line); }
.seg {
  border: none; padding: 0; cursor: pointer; min-width: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  border-right: 1px solid rgba(15,17,21,.5);
}
.seg:last-child { border-right: none; }
.seg-cap { font-size: 10px; color: #0f1115; font-weight: 600; white-space: nowrap; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; }
.seg-good { background: var(--green); }
.seg-bad  { background: var(--pink); }
.seg-muted { background: #5a6273; }
.seg-muted .seg-cap { color: var(--text); }
.seg.active { outline: 2px solid var(--blue); outline-offset: -2px; }
/* Legend pills under a segmented bar. */
.seg-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.seg-leg {
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; border: 1px solid transparent; border-radius: 5px;
  padding: 1px 6px; cursor: pointer; font-size: 11px; color: var(--muted);
}
.seg-leg:hover { border-color: var(--line); }
.seg-leg.active { border-color: var(--blue); color: var(--text); }
.seg-leg b { color: var(--text); font-variant-numeric: tabular-nums; }
.seg-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.seg-good .seg-dot { background: var(--green); }
.seg-bad  .seg-dot { background: var(--pink); }
.seg-muted .seg-dot { background: #5a6273; }

/* Independent flag chips. */
.stat-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.stat-chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer;
}
.stat-chip:hover { border-color: var(--blue); }
.stat-chip.active { background: rgba(74,163,255,.18); border-color: var(--blue); color: var(--text); }
.stat-chip .stat-num { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-chip .stat-pct { font-size: 10px; color: var(--muted); }
.stat-chip.active .stat-pct { color: var(--blue); }

/* Banner shown above the grid while a stat filter is active. */
.filter-banner {
  margin-bottom: 12px; padding: 8px 14px; font-size: 13px; color: var(--muted);
  background: rgba(74,163,255,.10); border: 1px solid var(--blue); border-radius: 8px;
}
.filter-banner[hidden] { display: none; }
.filter-banner strong { color: var(--text); }
.filter-banner button {
  margin-left: 10px; font-size: 12px; padding: 2px 9px;
  background: transparent; border-color: var(--blue); color: var(--blue);
}

/* Editable ADS-binding cell: dashed affordance like the vol target. */
.ads-edit { display: inline-flex; gap: 5px; align-items: center; }
.ads-val { cursor: pointer; border-bottom: 1px dashed var(--line); }
.ads-val:hover { color: var(--blue); border-bottom-color: var(--blue); }
.ads-val.none { color: #555; font-style: italic; }
.ads-edit input { width: 110px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 5px; padding: 3px 6px; font-size: 12px; }

main { padding: 16px 24px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; }
tbody tr:hover { background: var(--panel); }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.addr { color: var(--muted); cursor: copy; }
.addr.none { color: #555; font-style: italic; }

/* Identity column: username on top, referrer (who invited) dimmed below. */
.identity { white-space: nowrap; }
.identity .uname { color: var(--text); }
.identity .ref-line { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); }
.identity .ref-line.none { color: #555; }

.disabled td { opacity: .45; }

.tag { font-size: 11px; padding: 1px 7px; border-radius: 4px; }
.tag.on { background: rgba(46,204,113,.15); color: var(--green); }
.tag.off { background: rgba(139,147,163,.15); color: var(--muted); }

/* Vol. cell: left-align so the left→right fill reads naturally (overrides .num). */
td.vol { white-space: nowrap; text-align: left; }

/* Vol. amount with the progress bar AS its background fill. The fill is an
   absolutely-positioned layer growing left→right; the amount text sits on top. */
.vol-fill-box {
  position: relative;
  display: inline-block;
  min-width: 200px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  overflow: hidden;
}
.vol-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: rgba(74,163,255,.28);     /* blue fill (in progress) */
  border-radius: 6px 0 0 6px;
  z-index: 0;
}
.vol-fill-box.done .vol-fill { background: rgba(46,204,113,.30); } /* green when reached */
.vol-main { position: relative; z-index: 1; white-space: nowrap; }
.vol-val { color: var(--text); }
.vol-sep { color: var(--muted); margin: 0 4px; }
.vol-pct { margin-left: 8px; font-size: 11px; color: var(--muted); }
.vol-fill-box.done .vol-pct { color: var(--green); }

/* 磨损 line under Vol. (grid) and under each day (detail). Dim + spaced. */
.loss-line { margin-top: 5px; font-size: 11px; color: var(--muted); display: flex; gap: 4px 12px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.loss-line .loss-lbl { opacity: .7; }
.loss-line .loss-seg { color: var(--cream, #b8c0cc); white-space: nowrap; }
/* BNB figure: hint (dotted underline + help cursor) that hovering shows the
   reference price used to convert gas → USD. Works in both the grid loss-line
   and the detail-drawer history loss text. */
.bnb-seg { text-decoration: underline dotted; text-underline-offset: 2px; cursor: help; }
.target-edit { display: inline-flex; gap: 4px; align-items: center; }
.vol-target { color: var(--muted); cursor: pointer; border-bottom: 1px dashed var(--line); }
.vol-target:hover { color: var(--blue); border-bottom-color: var(--blue); }
.target-edit input { width: 84px; text-align: right; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 5px; padding: 3px 6px; }

.stale { color: var(--amber); }
.today-row td { background: rgba(74,163,255,.07); }

/* Balance line shown under each address (EOA / Cloud). Segments spaced out with
   their own gaps so the three tokens don't read as one cramped string. */
.bal-line { margin-top: 5px; font-variant-numeric: tabular-nums; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.bal-line.muted { color: var(--muted); font-size: 12px; }
.bal-seg { font-size: 12px; white-space: nowrap; }
.bal-num { color: var(--text); }
.bal-sym { color: var(--muted); font-size: 11px; }
.bal-line.stale .bal-num, .bal-line.stale .bal-sym { color: var(--amber); }
/* Addresses are block-level inside their cell now (address on top, balance below). */
td .addr.full { display: inline-block; }

/* Proxy cell: scheme://user:pass@host:port with the MIDDLE masked (both ends
   visible). The masked form is short, so no ellipsis truncation is needed; the eye
   toggle reveals the full value in place. */
.proxy-val { display: inline-block; vertical-align: bottom; }

/* Eye toggle next to the proxy: reveal/hide the full value. Lit blue when shown. */
.eye-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 4px; padding: 0 5px; font-size: 12px; line-height: 18px;
  cursor: pointer; flex: none;
}
.eye-btn:hover { border-color: var(--blue); color: var(--blue); }
.eye-btn.on { color: var(--blue); border-color: var(--blue); }

/* Address + copy button on one line. */
.addr-row { display: inline-flex; align-items: center; gap: 6px; }
.copy-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 4px; padding: 0 5px; font-size: 12px; line-height: 18px;
  cursor: pointer; flex: none;
}
.copy-btn:hover { border-color: var(--blue); color: var(--blue); }
.copy-btn:active { color: var(--green); border-color: var(--green); }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 16px 20px; overflow-y: auto; z-index: 20;
  box-shadow: -8px 0 24px rgba(0,0,0,.4);
}
.drawer.hidden { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.drawer-head button { font-size: 18px; line-height: 1; padding: 2px 9px; }

.hist { width: 100%; border-collapse: collapse; margin-top: 8px; }
.hist th, .hist td { padding: 6px 8px; font-size: 12px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 8px; z-index: 30; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.err { border-color: var(--pink); color: #ffb3cd; }

/* ---- login overlay ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15,17,21,.92);
}
.login-overlay.hidden { display: none; }
.login-card {
  width: 320px; max-width: 92vw;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 26px 24px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.login-card h2 { margin: 0; font-size: 18px; font-weight: 650; }
.login-sub { margin: -6px 0 6px; font-size: 13px; }
.login-fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.login-fld input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font-size: 14px;
}
.login-fld input:focus { outline: none; border-color: var(--blue); }
.login-submit { margin-top: 6px; padding: 9px; font-size: 14px; }
.login-err { margin: 0; font-size: 12px; color: #ffb3cd; }
.login-err[hidden] { display: none; }
.login-adv { margin-top: 4px; font-size: 12px; color: var(--muted); }
.login-adv summary { cursor: pointer; }
.login-adv .login-fld { margin-top: 10px; }
.login-adv button { margin-top: 8px; width: 100%; }

/* User chip in the header (username · scope) + logout/users buttons. */
.user-chip { color: var(--text); }
.user-chip .uc-scope { color: var(--muted); margin-left: 6px; font-size: 11px; }
.user-chip .uc-admin { color: var(--amber); margin-left: 6px; font-size: 11px; }

/* Users admin panel: reuse .add-panel styling; result table cells. */
#usersResult table { width: auto; min-width: 60%; }
#usersResult th, #usersResult td { padding: 6px 10px; font-size: 12px; }
.u-scope { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.u-actions { display: inline-flex; gap: 6px; }
.u-actions button { font-size: 11px; padding: 2px 8px; }
.u-actions button.danger { border-color: var(--pink); color: #ffb3cd; }
.u-actions button.danger:hover { background: rgba(255,77,141,.12); }
.pill-sm.admin { background: rgba(245,166,35,.15); color: var(--amber); }
