:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #17181a;
  --muted: #7b7f86;
  --line: #e7e7e3;
  --soft: #f1f1ee;
  --accent: #2f5bd3;
  --green: #1f8a5b;
  --red: #c4372f;
  --amber: #b7791f;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --panel: #18191c; --ink: #ececec; --muted: #8d9199;
    --line: #2a2c30; --soft: #202226; --accent: #7a9bff; --green: #46c08a;
    --red: #ff6b61; --amber: #e0a43c;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
input, select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.brand { font-weight: 700; letter-spacing: -0.02em; font-size: 17px; }
.brand span { color: var(--muted); font-weight: 500; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.icon-btn {
  border: none; background: transparent; cursor: pointer; font-size: 16px; color: var(--muted);
  padding: 2px 6px; border-radius: 6px;
}
.icon-btn:hover { background: var(--soft); color: var(--ink); }

.login { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  display: grid; gap: 12px; width: 300px; padding: 28px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px;
}
.error { color: var(--red); min-height: 1em; font-size: 13px; }

.topbar {
  display: flex; align-items: center; gap: 24px; padding: 14px 24px;
  border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5;
}
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: none; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.tabs button.active { background: var(--soft); color: var(--ink); font-weight: 600; }
.sync { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.dot.busy { background: var(--amber); animation: pulse 1s infinite; }
.dot.err { background: var(--red); }
@keyframes pulse { 50% { opacity: 0.3; } }

.balances { display: flex; gap: 12px; padding: 16px 24px 0; flex-wrap: wrap; }
.bal {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; min-width: 170px;
}
.bal.total { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.bal .label { font-size: 12px; color: var(--muted); }
.bal.total .label { color: inherit; opacity: 0.7; }
.bal .value { font-size: 18px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.bal .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bal .warn { color: var(--red); font-size: 12px; }

main { padding: 16px 24px 48px; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar-right { margin-left: auto; display: flex; gap: 8px; }
#search { width: 340px; }
.segmented { display: flex; background: var(--soft); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: none; background: none; padding: 5px 11px; border-radius: 7px; cursor: pointer; color: var(--muted);
}
.segmented button.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.ops { width: 100%; border-collapse: collapse; }
.ops th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 9px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.ops td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ops tr:last-child td { border-bottom: none; }
.ops tr.dim td { opacity: 0.55; }
.ops tr.danger td { background: color-mix(in srgb, var(--red) 7%, transparent); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt { font-weight: 600; }
.amt.in { color: var(--green); }
.amt.out { color: var(--red); }
.amt.neutral { color: var(--muted); }
.usd { font-size: 12px; color: var(--muted); }
.date { white-space: nowrap; color: var(--muted); font-size: 13px; }
.hash { display: flex; align-items: center; gap: 2px; margin-top: 3px; }
.hash a { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; color: var(--accent); text-decoration: none; }
.hash a:hover { text-decoration: underline; }
.hash .copy { font-size: 12px; padding: 0 4px; }
.chain { font-size: 12px; white-space: nowrap; }
.chain i { font-style: normal; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; }
.chain .tron { background: #e5312f; } .chain .ethereum { background: #6b7bd8; } .chain .solana { background: #19c39b; } .chain .bsc { background: #f0b90b; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap;
  background: var(--soft); color: var(--muted); border: none; cursor: pointer;
}
.pill.income { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.pill.expense { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.pill.swap, .pill.internal { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); }
.pill.network_fee, .pill.energy { background: color-mix(in srgb, var(--amber) 15%, transparent); color: var(--amber); }
.kind-select { font-size: 12px; padding: 2px 4px; }

.cp input { width: 170px; padding: 4px 7px; }
.addr { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; color: var(--muted); margin-top: 3px; cursor: copy; }
.contract { font-size: 11.5px; color: var(--accent); }
.flag { font-size: 12px; color: var(--muted); margin-top: 3px; max-width: 280px; }
.flag.danger { color: var(--red); font-weight: 600; }
.cat select { max-width: 170px; padding: 4px 6px; }
.suggest {
  display: inline-flex; gap: 4px; align-items: center; margin-top: 4px; font-size: 12px;
  background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent);
  border-radius: 6px; padding: 2px 4px 2px 8px;
}
.suggest button { border: none; background: none; cursor: pointer; color: inherit; padding: 0 4px; font-size: 13px; }
.suggest button:hover { color: var(--ink); }
.desc input { width: 100%; min-width: 180px; border-color: transparent; background: transparent; padding: 4px 6px; }
.desc input:hover, .desc input:focus { border-color: var(--line); background: var(--panel); }
.link { font-size: 12px; color: var(--accent); margin-top: 3px; }
.link button { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 12px; text-decoration: underline; }
.more { text-align: center; margin-top: 14px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.period-nav { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; color: var(--muted); }
.delta.good { color: var(--green); } .delta.bad { color: var(--red); }
.kpi .breakdown { font-size: 12px; color: var(--muted); line-height: 1.6; }
.report-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .report-grid { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 14px; }
.alerts { display: grid; gap: 8px; margin-bottom: 16px; }
.alert { border-radius: 9px; padding: 10px 14px; border: 1px solid var(--line); background: var(--panel); }
.alert b { display: block; font-size: 13px; }
.alert span { font-size: 13px; color: var(--muted); }
.alert.danger { border-color: var(--red); } .alert.danger b { color: var(--red); }
.alert.warn b { color: var(--amber); }
.cat-row { display: grid; grid-template-columns: 1fr 110px 90px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.cat-row:last-child { border-bottom: none; }
.cat-name { display: flex; align-items: center; gap: 8px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.bar { height: 4px; background: var(--soft); border-radius: 2px; margin-top: 4px; }
.bar div { height: 100%; border-radius: 2px; }
.muted { color: var(--muted); font-size: 13px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .settings-grid { grid-template-columns: 1fr; } }
.list-row { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row input[type=text] { flex: 1; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input[name=address] { flex: 1; min-width: 200px; }
.people-new { margin-bottom: 16px; }
.people-new p { margin: 0 0 4px; line-height: 1.5; max-width: 900px; }
.people-new input[type=text] { min-width: 220px; }
.cp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 12px; }
@media (max-width: 600px) { .cp-grid { grid-template-columns: 1fr; } }
.cp-card { display: grid; gap: 10px; align-content: start; }
.cp-head { display: flex; gap: 8px; }
.cp-name { flex: 1; font-weight: 600; }
.cp-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cp-fields label { display: grid; gap: 4px; font-size: 12px; }
.cp-sub { font-size: 12px; margin-bottom: -6px; }
.addr-row { display: flex; align-items: center; gap: 8px; }
.addr-row .addr { margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cp-card .inline-form { margin-top: 0; }
.addr-input { flex: 1; min-width: 200px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 9px; font-size: 13px; z-index: 20;
}
.danger-btn:hover { color: var(--red); }
