/* ============================================================ design tokens */
:root {
  /* surfaces — layered near-black with a faint cool tint */
  --bg:          #090b0f;
  --bg-grad:     #10141c;
  --surface:     #12161d;
  --surface-2:   #171c25;
  --surface-3:   #1e2531;
  --border:      #232b37;
  --border-2:    #2e3745;

  /* text */
  --text:        #eaf0f7;
  --dim:         #98a4b6;
  --mute:        #667085;

  /* brand + semantic */
  --accent:      #f0433d;      /* TRON red */
  --accent-2:    #ff6a5f;
  --accent-soft: rgba(240,67,61,.13);
  --ok:          #3fb87a;
  --ok-soft:     rgba(63,184,122,.14);
  --warn:        #e0a92e;
  --warn-soft:   rgba(224,169,46,.14);
  --danger:      #f0524b;
  --danger-soft: rgba(240,82,75,.13);
  --info:        #5aa2ff;
  --info-soft:   rgba(90,162,255,.13);

  --radius:   14px;
  --radius-s: 10px;
  --radius-xs: 8px;
  --shadow:   0 10px 40px -12px rgba(0,0,0,.7);
  --ring:     0 0 0 3px rgba(240,67,61,.22);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(240,67,61,.06), transparent 60%),
    radial-gradient(900px 500px at 10% -5%, #182234 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a { color: #7db9ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: .86em; }
.muted { color: var(--dim); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.hidden { display: none !important; }
.num { text-align: right; }
code {
  background: rgba(255,255,255,.055); padding: 1.5px 6px; border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em;
}

/* ================================================================= topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 13px 28px; border-bottom: 1px solid var(--border);
  background: rgba(9,11,15,.78); backdrop-filter: blur(16px) saturate(1.3);
  position: sticky; top: 0; z-index: 50; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 13px; }
.logo {
  width: 38px; height: 38px; display: grid; place-items: center; font-size: 19px;
  background: linear-gradient(140deg, var(--accent), #b32b28);
  border-radius: 11px; box-shadow: 0 4px 16px -4px rgba(240,67,61,.55);
}
.brand strong { font-size: 15px; letter-spacing: .2px; }

main { max-width: 1280px; margin: 0 auto; padding: 26px 22px 90px; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ================================================================== cards */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.card {
  background: linear-gradient(180deg, var(--surface), var(--surface));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 18px;
  box-shadow: 0 1px 0 rgba(255,255,255,.02) inset;
}
.grid .card { margin-bottom: 0; }
.card h2 { margin: 0 0 14px; font-size: 16px; letter-spacing: .2px; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head h2 { margin: 0; }

.kv {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 14px;
}
.kv:last-of-type { border-bottom: 0; }
.kv > span:first-child { color: var(--dim); }

/* =============================================================== controls */
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text);
  padding: 9px 16px; border-radius: var(--radius-s); cursor: pointer; font-size: 14px; font-weight: 500;
  transition: .14s; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover:not(:disabled) { border-color: #3d4a5e; background: var(--surface-3); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(140deg, var(--accent), #cc322d); border-color: transparent; color: #fff; box-shadow: 0 4px 14px -4px rgba(240,67,61,.5); }
.btn.primary:hover:not(:disabled) { background: linear-gradient(140deg, var(--accent-2), var(--accent)); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.danger { border-color: rgba(240,82,75,.4); color: #ff9c96; background: var(--danger-soft); }
.btn.danger:hover:not(:disabled) { background: rgba(240,82,75,.2); }
.btn.warn { border-color: rgba(224,169,46,.4); color: #f0cd82; background: var(--warn-soft); }
.btn.warn:hover:not(:disabled) { background: rgba(224,169,46,.2); }
.btn.big { padding: 12px 22px; font-size: 15px; }
.btn.tiny { padding: 6px 11px; font-size: 12.5px; border-radius: var(--radius-xs); }

.chip {
  border: 1px solid var(--border); background: transparent; color: var(--dim);
  padding: 6px 14px; border-radius: 999px; cursor: pointer; font-size: 13px; transition: .14s;
}
.chip:hover { color: var(--text); border-color: var(--border-2); }
.chip.active { background: var(--accent-soft); color: #ff9c96; border-color: rgba(240,67,61,.35); }

.field { display: block; margin-bottom: 15px; }
.field > span { display: block; color: var(--dim); font-size: 13px; margin-bottom: 7px; }
input, select {
  width: 100%; background: #0c1017; border: 1px solid var(--border); color: var(--text);
  padding: 10px 13px; border-radius: var(--radius-s); font-size: 14px; font-family: inherit; transition: .14s;
}
input::placeholder { color: var(--mute); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input.inline { padding: 7px 10px; font-size: 13px; width: 110px; }
select.inline-select {
  width: auto; min-width: 160px; padding: 8px 12px; font-size: 13px;
  background: #0c1017; border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-s);
}

.wallet-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 190px; }
.wallet-actions .charge-input { width: 92px; }
.wallet-actions .btn { padding: 6px 11px; font-size: 12px; }

/* ================================================================= events */
.events-list { max-height: 420px; overflow-y: auto; margin: -4px -6px; padding: 0 6px; }
.event-item {
  padding: 12px 14px; border-radius: var(--radius-s); font-size: 13px; line-height: 1.5;
  margin-bottom: 6px; background: var(--surface-2); border: 1px solid transparent; transition: .14s;
}
.event-item:hover { border-color: var(--border); }
.event-item.unread { background: var(--accent-soft); border-color: rgba(240,67,61,.28); }
.event-item .event-kind { font-size: 11px; text-transform: uppercase; color: var(--dim); letter-spacing: .5px; font-weight: 600; }
.event-item .event-time { float: right; color: var(--mute); font-size: 11px; margin-left: 10px; }
.event-item > div { margin-top: 5px; }
.event-item > div.muted { margin-top: 3px; }

/* ============================================================ status badge */
.status-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 10.5px; font-weight: 600; letter-spacing: .2px; }
.status-badge.active { background: var(--ok-soft); color: #6fe0a0; }
.status-badge.disconnected { background: var(--warn-soft); color: #f0cd82; }
.status-badge.revoked { background: var(--danger-soft); color: #ff9c96; }
.status-badge.blocked { background: rgba(139,152,171,.18); color: var(--dim); }

/* ============================================================= disclosure */
.disclosure {
  background: var(--accent-soft); border: 1px solid rgba(240,67,61,.26);
  border-radius: var(--radius-s); padding: 15px 17px; margin: 4px 0 16px;
}
.disclosure-title { font-weight: 600; font-size: 13px; margin-bottom: 9px; color: #ffb3ad; }
.disclosure ul { margin: 0; padding-left: 18px; font-size: 13.5px; color: #cbd5e1; }
.disclosure li { margin: 6px 0; }

.devnote {
  background: var(--warn-soft); border: 1px solid rgba(224,169,46,.3);
  border-radius: var(--radius-s); padding: 12px 16px; margin-bottom: 18px; font-size: 13.5px; color: #e8d29b;
}

/* ================================================================ status */
.status { margin-top: 14px; padding: 12px 15px; border-radius: var(--radius-s); font-size: 13.5px; word-break: break-word; }
.status.info { background: var(--info-soft); border: 1px solid rgba(90,162,255,.3); }
.status.ok { background: var(--ok-soft); border: 1px solid rgba(63,184,122,.35); }
.status.err { background: var(--danger-soft); border: 1px solid rgba(240,82,75,.35); }
.status a { color: #7db9ff; }
.status.loading { display: flex; align-items: center; gap: 11px; }
.status.loading .spinner { width: 18px; height: 18px; border-width: 2px; flex-shrink: 0; }

/* ================================================================== steps */
.steps { margin: 0; padding-left: 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 15px; }
.steps li b { display: block; font-family: ui-monospace, monospace; color: var(--accent-2); margin-bottom: 4px; }
.steps li span { color: var(--dim); font-size: 13px; }

/* ============================================================ stats (kpi) */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 13px; margin-bottom: 20px; }
.stat {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 17px;
  position: relative; overflow: hidden; transition: .16s;
}
.stat:hover { border-color: var(--border-2); transform: translateY(-2px); }
.stat::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: linear-gradient(var(--accent), transparent); opacity: .6;
}
.stat .label { color: var(--dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 500; }
.stat .value { font-size: 18px; font-weight: 650; margin-top: 6px; word-break: break-word; font-variant-numeric: tabular-nums; }
.stat .value.small { font-size: 12.5px; font-weight: 500; }

/* =============================================================== summary */
.summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px;
  background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-s);
  overflow: hidden; margin-bottom: 18px;
}
.sum-item { background: var(--surface-2); padding: 13px 16px; }
.sum-item span { display: block; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.sum-item div { font-size: 17px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }

.check { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 13px; cursor: pointer; white-space: nowrap; user-select: none; }
.check input { width: auto; }

/* ================================================================= tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius-s); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; color: var(--dim); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .5px; padding: 11px 12px;
  border-bottom: 1px solid var(--border-2); white-space: nowrap;
  background: var(--surface-2); position: sticky; top: 0;
}
thead th:first-child { border-top-left-radius: var(--radius-xs); }
thead th:last-child { border-top-right-radius: var(--radius-xs); }
td { padding: 13px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(255,255,255,.025); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2.5px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: #6fe0a0; }
.badge.err { background: var(--danger-soft); color: #ff9c96; }
.badge.pending { background: var(--warn-soft); color: #f0cd82; }
.badge.muted { background: rgba(139,152,171,.15); color: var(--dim); }

/* ============================================================= pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 16px; flex-wrap: wrap;
}
.pagination .page-info { color: var(--dim); font-size: 12.5px; }
.pager { display: flex; align-items: center; gap: 5px; }
.pager button {
  min-width: 34px; height: 34px; padding: 0 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); border-radius: var(--radius-xs);
  cursor: pointer; font-size: 13px; font-weight: 500; transition: .13s;
}
.pager button:hover:not(:disabled):not(.active) { border-color: var(--border-2); background: var(--surface-3); }
.pager button.active { background: var(--accent); border-color: transparent; color: #fff; cursor: default; }
.pager button:disabled { opacity: .35; cursor: not-allowed; }
.pager .ellipsis { color: var(--mute); padding: 0 2px; }
.page-size { display: flex; align-items: center; gap: 7px; color: var(--dim); font-size: 12.5px; }
.page-size select { width: auto; padding: 5px 8px; font-size: 12.5px; }

/* =========================================================== section nav */
.section-nav {
  display: flex; gap: 4px; padding: 5px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 20px; overflow-x: auto;
}
.section-nav button {
  border: 0; background: transparent; color: var(--dim); cursor: pointer;
  padding: 9px 18px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
  white-space: nowrap; transition: .14s; display: inline-flex; align-items: center; gap: 7px;
}
.section-nav button:hover { color: var(--text); }
.section-nav button.active { background: var(--surface-3); color: var(--text); box-shadow: 0 2px 8px -3px rgba(0,0,0,.5); }
.section-nav .nav-count {
  font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600;
}
.op-section { display: none; }
.op-section.active { display: block; animation: fade .2s ease; }

.threshold-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border);
}
.threshold-bar label { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 13.5px; }

/* ============================================================ admin panel */
.admin-info { margin-bottom: 14px; }
.admin-info .kv { padding: 8px 0; }
.admin-info code { font-size: 12px; word-break: break-all; }
.key-warn {
  background: var(--warn-soft); border: 1px solid rgba(224,169,46,.3);
  border-radius: var(--radius-s); padding: 11px 14px; font-size: 12.5px; color: #e8d29b; margin-bottom: 16px;
}
.admin-block {
  padding: 15px; border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface-2); margin-bottom: 12px; display: grid; gap: 9px;
}
.admin-block:last-child { margin-bottom: 0; }
.admin-block-title { font-size: 13px; font-weight: 600; color: var(--dim); }
.admin-block input { font-size: 13px; }

/* =========================================================== domains */
.ns-box {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: 14px 16px; margin-bottom: 14px;
}
.ns-box-title { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--dim); margin-bottom: 8px; font-weight: 600; }
.ns-list { display: grid; gap: 7px; }
.ns-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #0c1017; border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 8px 12px; font-family: ui-monospace, Menlo, monospace; font-size: 13px;
}
.ns-row button {
  border: 1px solid var(--border-2); background: var(--surface-3); color: var(--dim);
  border-radius: 6px; padding: 3px 9px; font-size: 11.5px; cursor: pointer; transition: .12s;
}
.ns-row button:hover { color: var(--text); border-color: #3d4a5e; }
.domain-add { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.domain-add input { flex: 1; min-width: 200px; }
.domain-status { display: inline-flex; align-items: center; gap: 6px; }

/* ================================================================ toasts */
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 11px; z-index: 100; max-width: 400px; }
.toast {
  position: relative; display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface-3); border: 1px solid var(--border-2);
  border-radius: 12px; padding: 14px 16px; font-size: 13.5px;
  box-shadow: var(--shadow); overflow: hidden;
  animation: toast-in .28s cubic-bezier(.2,.9,.3,1);
}
.toast.leaving { animation: toast-out .2s ease forwards; }
.toast-icon {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  font-size: 14px; font-weight: 700;
}
.toast.ok .toast-icon { background: var(--ok-soft); color: #6fe0a0; }
.toast.err .toast-icon { background: var(--danger-soft); color: #ff9c96; }
.toast.info .toast-icon { background: var(--info-soft); color: #7db9ff; }
.toast-body { flex: 1; min-width: 0; }
.toast-body .toast-title { font-weight: 600; margin-bottom: 2px; }
.toast-body a { color: #7db9ff; }
.toast-close {
  flex-shrink: 0; border: 0; background: transparent; color: var(--mute); cursor: pointer;
  font-size: 17px; line-height: 1; padding: 2px 4px; border-radius: 6px; transition: .12s;
}
.toast-close:hover { color: var(--text); background: rgba(255,255,255,.06); }
.toast .toast-bar { position: absolute; left: 0; bottom: 0; height: 2.5px; background: currentColor; opacity: .5; animation: toast-bar linear forwards; }
.toast.ok .toast-bar { color: var(--ok); }
.toast.err .toast-bar { color: var(--danger); }
.toast.info .toast-bar { color: var(--info); }
@keyframes toast-in { from { transform: translateX(24px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateX(24px); opacity: 0; } }
@keyframes toast-bar { from { width: 100%; } to { width: 0; } }

/* ============================================================ empty state */
.empty { text-align: center; padding: 44px 20px; color: var(--mute); }
.empty .empty-icon { font-size: 34px; margin-bottom: 12px; opacity: .5; }
.empty .empty-text { font-size: 14px; }

/* ================================================================ svg icons */
svg.ico { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
svg.ico.dot { vertical-align: -1px; margin-right: 3px; }

/* =============================================================== responsive */
@media (max-width: 720px) {
  main { padding: 18px 14px 80px; }
  .topbar { flex-direction: column; align-items: stretch; padding: 12px 16px; }
  .wallet-actions { min-width: 0; }
  .card { padding: 18px; }
}

/* ============================================================== modal */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(6px); }
.modal-card {
  position: relative; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.5);
  max-width: 640px; width: 100%; max-height: 85vh; overflow: hidden;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 20px 24px 12px; border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 18px; font-weight: 700; line-height: 1.3; }
.modal-sub { font-size: 12px; color: var(--mute); margin-top: 4px; font-family: var(--mono, monospace); }
.modal-close {
  background: transparent; border: 0; color: var(--mute); font-size: 24px;
  cursor: pointer; padding: 0 4px; line-height: 1; transition: color .15s;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px 24px 24px; overflow-y: auto; }

.stats-total {
  display: flex; align-items: baseline; gap: 10px;
  padding: 14px 16px; background: rgba(255,255,255,.03); border-radius: 10px; margin-bottom: 18px;
}
.stats-total .num { font-size: 28px; font-weight: 700; }
.stats-total .lbl { font-size: 13px; color: var(--mute); }

.stats-section { margin-bottom: 20px; }
.stats-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--mute); margin-bottom: 10px; }
.stats-empty { padding: 12px 4px; color: var(--mute); font-size: 13px; font-style: italic; }

.country-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 8px; transition: background .15s;
}
.country-row:hover { background: rgba(255,255,255,.03); }
.country-row .flag { font-size: 20px; line-height: 1; }
.country-row .name { flex: 1; font-size: 14px; }
.country-row .count { font-weight: 700; font-size: 14px; color: var(--accent, #ff060a); }
.country-bar { height: 3px; background: rgba(255,255,255,.05); border-radius: 2px; margin: 2px 0 6px 30px; overflow: hidden; }
.country-bar > div { height: 100%; background: var(--accent, #ff060a); border-radius: 2px; }

.visit-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,.04); font-size: 13px;
}
.visit-row:last-child { border-bottom: 0; }
.visit-row .flag { font-size: 18px; }
.visit-row .info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.visit-row .info .loc { font-weight: 500; }
.visit-row .info .meta { font-size: 11px; color: var(--mute); font-family: var(--mono, monospace); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visit-row .time { font-size: 12px; color: var(--mute); font-variant-numeric: tabular-nums; }
