/* USDT Watcher — design tokens */
:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --border-strong: #cfcdc6;
  --text: #121211;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3efea;
  --in: #2a78d6;
  --in-soft: #e5effb;
  --out: #eb6834;
  --out-soft: #fdece4;
  --good: #0c7a0c;
  --good-soft: #e6f3e6;
  --warn: #9a6400;
  --warn-soft: #fbf1dc;
  --bad: #c03030;
  --bad-soft: #fae7e7;
  --tron: #c63b3b;
  --eth: #5b6fd8;
  --bsc: #b98500;
  --grid: #e8e7e2;
  --shadow: 0 1px 2px rgba(20, 20, 18, .06), 0 1px 1px rgba(20, 20, 18, .04);
  --radius: 10px;
  --radius-sm: 6px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --border-strong: #3d3d39;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #92918a;
    --accent: #3fae90;
    --accent-ink: #0d1f1a;
    --accent-soft: #1b2e28;
    --in: #3987e5;
    --in-soft: #172536;
    --out: #d95926;
    --out-soft: #33201a;
    --good: #4cc04c;
    --good-soft: #1a2b1a;
    --warn: #e8a530;
    --warn-soft: #2f2615;
    --bad: #ec6b6b;
    --bad-soft: #351c1c;
    --tron: #ec6b6b;
    --eth: #8f9df0;
    --bsc: #e0b23a;
    --grid: #2a2a27;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2e2e2b;
  --border-strong: #3d3d39;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #92918a;
  --accent: #3fae90;
  --accent-ink: #0d1f1a;
  --accent-soft: #1b2e28;
  --in: #3987e5;
  --in-soft: #172536;
  --out: #d95926;
  --out-soft: #33201a;
  --good: #4cc04c;
  --good-soft: #1a2b1a;
  --warn: #e8a530;
  --warn-soft: #2f2615;
  --bad: #ec6b6b;
  --bad-soft: #351c1c;
  --tron: #ec6b6b;
  --eth: #8f9df0;
  --bsc: #e0b23a;
  --grid: #2a2a27;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; font-weight: 700; font-size: 15px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 15px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.sidebar-foot form { margin: 0; }
.main { min-width: 0; padding: 24px 28px 48px; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- surfaces */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card + .card { margin-top: 16px; }
.grid > .card, .stack > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: grid; gap: 16px; }

/* ---------- KPI */
.kpi { padding: 16px 18px; }
.kpi-label { color: var(--text-2); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--text-3); margin-left: 4px; letter-spacing: 0; }
.kpi-sub { margin-top: 4px; color: var(--text-2); font-size: 12.5px; display: flex; gap: 12px; flex-wrap: wrap; }
.flow { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-in { background: var(--in); }
.dot-out { background: var(--out); }

.period-tabs { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.period-tabs button {
  border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 12.5px; font-weight: 500;
  padding: 5px 10px; border-radius: 6px; cursor: pointer;
}
.period-tabs button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
td.right, th.right { text-align: right; }
tr:last-child td { border-bottom: 0; }
.empty { text-align: center; padding: 40px 16px; color: var(--text-2); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ---------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; line-height: 18px;
}
.net { background: var(--surface-2); color: var(--text-2); }
.net::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: currentColor; }
.net-TRON::before { background: var(--tron); }
.net-ETH::before { background: var(--eth); }
.net-BSC::before { background: var(--bsc); }
.dir-IN { background: var(--in-soft); color: var(--in); }
.dir-OUT { background: var(--out-soft); color: var(--out); }
.st-ok, .st-sent { background: var(--good-soft); color: var(--good); }
.st-warn, .st-pending { background: var(--warn-soft); color: var(--warn); }
.st-down, .st-failed, .st-error { background: var(--bad-soft); color: var(--bad); }
.st-off { background: var(--surface-2); color: var(--text-3); }
.amount-in { color: var(--text); }
.amount-out { color: var(--text); }
.sign-in { color: var(--in); font-weight: 700; }
.sign-out { color: var(--out); font-weight: 700; }

/* ---------- forms */
label { font-weight: 500; font-size: 13px; color: var(--text-2); display: block; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; min-height: 36px;
}
textarea { min-height: 120px; font-family: var(--mono); font-size: 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field { margin-bottom: 14px; }
.field .help { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; color: var(--text); margin-bottom: 10px; cursor: pointer; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.check span small { display: block; color: var(--text-3); font-weight: 400; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; align-items: end; }
.filters .field { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: 13px;
  padding: 7px 14px; min-height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.btn svg { width: 16px; height: 16px; }
.inline-form { display: inline; margin: 0; }

/* ---------- alerts */
.flash { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid; font-weight: 500; }
.flash-ok { background: var(--good-soft); color: var(--good); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.flash-error { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.flash-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.callout { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); font-size: 13px; }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
.callout.bad { background: var(--bad-soft); color: var(--bad); }
.test-result { font-size: 12.5px; font-weight: 600; margin-left: 8px; }
.test-result.ok { color: var(--good); }
.test-result.error { color: var(--bad); }
.htmx-request .spinner { display: inline-block; }
.spinner { display: none; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- chart */
.chart-box { position: relative; height: 280px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- wallet cards */
.wallet-list { display: grid; gap: 10px; }
.wallet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.wallet-row:last-child { border-bottom: 0; }
.wallet-name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.addr { font-family: var(--mono); font-size: 12px; color: var(--text-3); word-break: break-all; }

.note-form { display: flex; gap: 6px; min-width: 180px; }
.note-form input { min-height: 30px; padding: 4px 8px; font-size: 12.5px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 12px; flex-wrap: wrap; }
.totals { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.totals b { color: var(--text); }

/* ---------- login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth .brand { padding: 0 0 20px; }

details { position: relative; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.popover {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(340px, 86vw);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: 16px;
}
.plain-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.group-head { display: flex; align-items: center; gap: 10px; margin: 22px 0 8px; }
.group-head h2 { margin: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.checks .check { margin: 0; font-size: 12.5px; }
.target-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.target-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
details.danger summary { cursor: pointer; color: var(--bad); font-weight: 600; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }
.qr { background: #fff; padding: 8px; border-radius: 8px; width: 200px; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 10px 16px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0; }
  .nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; gap: 4px; padding-bottom: 2px; }
  .nav a { padding: 6px 10px; white-space: nowrap; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; }
  .sidebar-foot .who { display: none; }
  .main { padding: 18px 16px 40px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .kv { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
  .kpi-value { font-size: 22px; }
}
@media (forced-colors: active) {
  .badge, .btn { border: 1px solid CanvasText; }
}
