:root {
  --bg: #07090d;
  --surface: #0d1117;
  --surface-2: #151b25;
  --surface-3: #1c2333;
  --border: #212936;
  --border-hover: #303a4d;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --muted: #64748b;
  --accent: #26a17b;
  --accent-hover: #2fbf91;
  --accent-muted: rgba(38,161,123,.12);
  --accent-border: rgba(38,161,123,.3);
  --warn: #f59e0b;
  --warn-muted: rgba(245,158,11,.1);
  --warn-border: rgba(245,158,11,.3);
  --err: #ef4444;
  --err-muted: rgba(239,68,68,.08);
  --err-border: rgba(239,68,68,.35);
  --blue: #3b82f6;
  --blue-muted: rgba(59,130,246,.1);
  --blue-border: rgba(59,130,246,.3);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', SFMono-Regular, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); min-height: 100vh;
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent-hover); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent); text-decoration: underline; }

code { font-family: var(--mono); }

/* ── Auth pages ─────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px;
}
.auth-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; letter-spacing: -.02em; }
.auth-card .sub { color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; line-height: 1.5; }

/* ── Layout ─────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 12px; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px 20px; margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.sidebar .brand .logo {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #1a7a5c);
  font-weight: 700; color: #fff; font-size: 15px;
  box-shadow: 0 2px 8px rgba(38,161,123,.25);
}
.sidebar .brand b { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }

.sidebar a.nav {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 13.5px; font-weight: 500;
  transition: all .15s ease;
}
.sidebar a.nav svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .6; transition: opacity .15s; }
.sidebar a.nav:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar a.nav:hover svg { opacity: .85; }
.sidebar a.nav.active { background: var(--accent-muted); color: var(--accent-hover); }
.sidebar a.nav.active svg { opacity: 1; }

.sidebar .spacer { flex: 1; }
.sidebar .admin-identity {
  padding: 12px; font-size: 12px; color: var(--muted);
  overflow-wrap: anywhere; border-top: 1px solid var(--border); margin-top: 8px;
  display: flex; align-items: center; gap: 8px;
}
.sidebar .admin-identity svg { width: 14px; height: 14px; flex-shrink: 0; opacity: .5; }

/* Main */
.main { flex: 1; padding: 32px 40px; max-width: 1200px; }
.main h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-bottom: 20px; }
.main h2 { font-size: 15px; font-weight: 600; margin: 24px 0 14px; color: var(--text-secondary); letter-spacing: -.01em; }

/* ── Stats ──────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; transition: border-color .2s;
}
.stat:hover { border-color: var(--border-hover); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat .value small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ── Panels ─────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
}
.panel-heading { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.panel-heading h2 { margin: 0 0 4px; }
.panel-heading p { font-size: 12.5px; }

/* ── Gas wallet ─────────────────────────────────── */
.gas-address {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center;
  gap: 10px; margin-bottom: 14px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.gas-address span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 500; }
.gas-address code { overflow-wrap: anywhere; color: var(--accent-hover); font-size: 12.5px; }
.gas-address .wallet-address-qr { grid-column: 1 / -1; text-align: center; padding-top: 8px; }

.gas-networks { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.gas-network {
  padding: 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); transition: border-color .2s;
}
.gas-network:hover { border-color: var(--border-hover); }
.gas-network.low { border-color: var(--warn-border); }
.gas-network.sufficient { border-color: var(--accent-border); }
.gas-network.stale, .gas-network.unavailable { border-color: var(--border); }
.gas-network-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.gas-network-head strong { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.gas-network-head div > span { color: var(--muted); font-size: 12px; }
.gas-state {
  padding: 3px 10px; border-radius: 999px; text-transform: capitalize;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.gas-state.low { color: var(--warn); background: var(--warn-muted); border-color: var(--warn-border); }
.gas-state.sufficient { color: var(--accent-hover); background: var(--accent-muted); border-color: var(--accent-border); }
.gas-state.stale, .gas-state.unavailable { color: var(--muted); }
.gas-network dl { display: grid; gap: 8px; }
.gas-network dl div { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.gas-network dt { color: var(--muted); }
.gas-network dd { font-weight: 600; text-align: right; }
.gas-network .top-up { color: var(--warn); padding-top: 8px; border-top: 1px solid var(--border); margin-top: 4px; }
.gas-network time { display: block; margin-top: 10px; color: var(--muted); font-size: 11px; }
.gas-message, .gas-loading, .gas-unavailable { color: var(--muted); font-size: 12.5px; }
.gas-loading, .gas-unavailable { padding: 18px; text-align: center; }

/* ── Tables ─────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
td {
  padding: 12px; border-bottom: 1px solid rgba(33,41,54,.6);
  vertical-align: middle; font-size: 13.5px;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(21,27,37,.5); }
tr:last-child td { border-bottom: none; }
td code { font-size: 12px; color: var(--text-secondary); }
.empty { color: var(--muted); padding: 28px; text-align: center; font-size: 13.5px; }

/* ── Alert banner ───────────────────────────────── */
.alert-banner {
  background: var(--err-muted); border: 1px solid var(--err-border);
  color: var(--err); border-radius: var(--radius); padding: 14px 18px;
  margin-bottom: 20px; font-size: 13.5px;
}
.alert-banner strong { display: block; margin-bottom: 6px; font-size: 14px; }
.alert-banner ul { margin: 0 0 8px; padding-left: 18px; }
.alert-banner li { margin: 3px 0; }
.alert-banner a { color: var(--err); font-weight: 600; }

/* ── Badges ─────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px; font-size: 11.5px;
  border: 1px solid var(--border); color: var(--muted); font-weight: 500;
}
.badge.awaiting_payment { color: var(--warn); border-color: var(--warn-border); background: var(--warn-muted); }
.badge.detected, .badge.funding, .badge.sweeping { color: var(--blue); border-color: var(--blue-border); background: var(--blue-muted); }
.badge.paid, .badge.overpaid, .badge.confirmed, .badge.delivered, .badge.completed, .badge.active, .badge.ok {
  color: var(--accent-hover); border-color: var(--accent-border); background: var(--accent-muted);
}
.badge.expired, .badge.underpaid, .badge.orphaned, .badge.failed, .badge.revoked, .badge.disabled, .badge.alert {
  color: var(--err); border-color: var(--err-border); background: var(--err-muted);
}
.badge.pending, .badge.error { color: var(--warn); border-color: var(--warn-border); background: var(--warn-muted); }

/* ── Forms ──────────────────────────────────────── */
label { display: block; font-size: 12.5px; color: var(--text-secondary); margin: 14px 0 6px; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], textarea, select {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 14px; font-family: var(--font);
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover { border-color: var(--border-hover); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
input::placeholder { color: var(--muted); }

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff; border: none;
  padding: 10px 18px; border-radius: var(--radius-sm); font-size: 13.5px;
  cursor: pointer; font-weight: 600; font-family: var(--font);
  transition: all .15s ease; white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(38,161,123,.25); }
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--surface-3); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--surface-2); border-color: var(--border-hover); box-shadow: none; }
.btn.danger {
  background: transparent; color: var(--err);
  border: 1px solid var(--err-border); padding: 7px 14px; font-size: 12.5px;
}
.btn.danger:hover { background: var(--err-muted); border-color: var(--err); box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: 12px; }
.form-row { margin-top: 18px; }
.error-msg { color: var(--err); font-size: 13px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 8px; line-height: 1.6; }

/* ── Secret reveal ──────────────────────────────── */
.secret-box {
  background: var(--accent-muted); border: 1px solid var(--accent-border);
  border-radius: var(--radius); padding: 16px; margin-top: 14px;
}
.secret-box code { word-break: break-all; font-size: 13px; color: var(--accent-hover); }
.secret-box .note { color: var(--warn); font-size: 12.5px; margin-top: 10px; }
.secret-copy { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.secret-copy code { flex: 1; min-width: 0; }

/* ── Utilities ──────────────────────────────────── */
.row { display: flex; gap: 12px; align-items: end; }
.row > div { flex: 1; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.full-width { width: 100%; }
.setup-card { max-width: 620px; }
.success-msg { color: var(--accent-hover); margin: 12px 0; line-height: 1.5; }
.mnemonic {
  display: block; margin-top: 10px; padding: 14px; line-height: 1.8;
  white-space: normal; background: var(--surface-2); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 14px; letter-spacing: .02em;
}
.wallet-mode { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin-top: 16px; }
.wallet-mode legend { color: var(--muted); font-size: 13px; padding: 0 6px; }
.wallet-mode label { color: var(--text); }
.setup-addresses, .wallet-addresses { display: grid; gap: 14px; margin-top: 16px; }
.setup-addresses div, .wallet-addresses div {
  display: grid; gap: 6px; padding: 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.setup-addresses dt, .wallet-addresses dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 500; }
.setup-addresses code, .wallet-addresses code { overflow-wrap: anywhere; font-size: 13px; }

.wallet-address-card {
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start;
  padding: 16px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.wallet-address-info dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 500; margin-bottom: 6px; }
.wallet-address-info dd { margin: 0; }
.wallet-address-info code { overflow-wrap: anywhere; font-size: 13px; color: var(--text-secondary); }
.wallet-address-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wallet-address-qr {
  background: #fff; border-radius: var(--radius-sm); padding: 6px;
  display: grid; place-items: center; flex-shrink: 0;
}
.wallet-address-qr img { display: block; width: 120px; height: 120px; }

/* ── Slot grid ──────────────────────────────────── */
.slot-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.slot-card {
  display: grid; gap: 8px; padding: 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); transition: all .2s ease;
}
.slot-card:hover { border-color: var(--accent); background: var(--surface-3); text-decoration: none; }
.slot-card small { color: var(--muted); overflow-wrap: anywhere; font-family: var(--mono); font-size: 11.5px; }

/* ── Page heading ───────────────────────────────── */
.page-heading { display: flex; align-items: start; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.page-heading h1 { margin: 8px 0 4px; }
.page-heading code { color: var(--muted); font-size: 12px; }
.page-heading a { font-size: 13px; color: var(--muted); font-weight: 500; }
.page-heading a:hover { color: var(--accent-hover); }
.small-value { font-size: 13px !important; overflow-wrap: anywhere; }

/* ── Network indicator dot ──────────────────────── */
.network-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.network-dot.bsc { background: #f0b90b; }
.network-dot.polygon { background: #8247e5; }
.network-dot.unknown { background: var(--muted); }

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 720px) {
  .shell { display: block; }
  .sidebar { width: 100%; min-height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar .spacer { display: none; }
  .main { padding: 20px 16px; }
  .gas-address { grid-template-columns: 1fr; }
  .panel { overflow-x: auto; }
  .page-heading { flex-direction: column; }
  .wallet-address-card { grid-template-columns: 1fr; }
  .wallet-address-actions { align-items: flex-start; }
}
