:root {
  --bg: #0d1219;
  --panel: #161d27;
  --panel-2: #1e2732;
  --line: #303c4b;
  --line-soft: #232d3a;
  --text: #eef3f8;
  --muted: #9fadbd;
  --muted-2: #6b7888;
  --signal: #3ee0b0;
  --signal-dim: rgba(62, 224, 176, 0.16);
  --warn: #e8b04b;
  --danger: #f0616b;
  --accent: #5aa9e6;

  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;

  --rail-w: 214px;
  --ledger-h: 78px;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--signal-dim); }

/* subtle console grid on the backdrop */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 46px 46px;
  opacity: 0.5;
  mask-image: radial-gradient(ellipse 80% 55% at 55% -5%, #000 10%, transparent 70%);
}

.app {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-rows: var(--ledger-h) 1fr;
  grid-template-areas: "rail ledger" "rail view";
  height: 100vh;
}

/* ---------- Rail ---------- */
.rail {
  grid-area: rail;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand-mark { color: var(--signal); font-size: 18px; }
.brand-name { font-weight: 600; letter-spacing: -0.02em; font-size: 16px; }
.brand-name em { color: var(--muted); font-style: normal; font-weight: 400; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--muted); font-weight: 500;
  transition: background 0.14s, color 0.14s;
}
.nav a .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted-2); transition: background 0.14s, box-shadow 0.14s;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); }
.nav a.active .dot { background: var(--signal); box-shadow: 0 0 8px var(--signal); }

.rail-foot { margin-top: auto; padding: 8px; }
.conn {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.conn .pulse {
  width: 7px; height: 7px; border-radius: 50%; background: var(--warn);
}
.conn.ok .pulse { background: var(--signal); box-shadow: 0 0 8px var(--signal); animation: pulse 2.4s infinite; }
.conn.down .pulse { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------- Ledger bar ---------- */
.ledger {
  grid-area: ledger;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 26px;
  padding: 0 24px;
  position: relative;
}
.ledger::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--signal), transparent);
  opacity: 0.35;
}
.ledger-block { display: flex; flex-direction: column; gap: 3px; }
.ledger-block .k {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted);
}
.ledger-block .v { font-family: var(--mono); font-size: 16px; font-weight: 500; }
.ledger-block .v.big {
  font-size: 26px; font-weight: 700; color: var(--signal);
  letter-spacing: -0.01em; line-height: 1;
  text-shadow: 0 0 22px rgba(53, 208, 165, 0.25);
}
.ledger-sep { width: 1px; height: 40px; background: var(--line); }
.ledger-strip {
  margin-left: auto; display: flex; gap: 2px; align-items: center;
  height: 34px; padding: 0 4px;
}
.ledger-strip i {
  width: 4px; border-radius: 1px; background: var(--muted-2);
  display: block;
}

.sync { margin-left: 8px; }
.sync-ic { display: inline-block; }
.sync.spinning .sync-ic { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- View ---------- */
.view { grid-area: view; overflow-y: auto; padding: 26px 28px 60px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; }
.view-head h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.view-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-weight: 500; font-size: 13px;
  transition: border-color 0.14s, background 0.14s, transform 0.05s;
}
.btn:hover { border-color: var(--muted-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--signal); border-color: var(--signal); color: #04130d; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(240, 97, 107, 0.35); background: transparent; }
.btn.danger:hover { background: rgba(240, 97, 107, 0.1); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* ---------- Cards ---------- */
.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 22px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
}
.stat .label {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted);
}
.stat .num { font-family: var(--mono); font-size: 24px; font-weight: 600; margin-top: 8px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.stat.accent .num { color: var(--signal); }

/* account grid */
.accounts-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.acct {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0; overflow: hidden; transition: border-color 0.14s, transform 0.1s;
  cursor: pointer;
}
.acct:hover { border-color: var(--muted-2); transform: translateY(-2px); }
.acct-top { display: flex; align-items: center; justify-content: space-between; padding: 15px 16px 12px; }
.acct-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.acct-avatar {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  background: var(--panel-2); border: 1px solid var(--line);
  display: grid; place-items: center; font-weight: 600; color: var(--accent);
  font-size: 14px;
}
.acct-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-email { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 8px; border-radius: 20px; border: 1px solid transparent; flex-shrink: 0;
}
.pill.ok { color: var(--signal); background: var(--signal-dim); }
.pill.warn { color: var(--warn); background: rgba(232, 176, 75, 0.12); }
.pill.error { color: var(--danger); background: rgba(240, 97, 107, 0.12); }

.acct-body { padding: 4px 16px 16px; }
.acct-balance { font-family: var(--mono); font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }
.acct-balance.dim { color: var(--muted); font-size: 15px; font-weight: 500; }
.acct-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 12px; }
.dev-line { flex: 1; }
.dev-count { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.dev-count b { color: var(--text); }
.bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--signal); border-radius: 3px; transition: width 0.4s; }
.bar.warn > i { background: var(--warn); }
.banned-tag { font-family: var(--mono); font-size: 11px; color: var(--danger); white-space: nowrap; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; }
.table th {
  text-align: left; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-size: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); }
.table tr:hover td { background: var(--panel-2); }
.table .num-cell { text-align: right; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.sig { color: var(--signal); }
.dgr { color: var(--danger); }
.wrn { color: var(--warn); }
.truncate { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.status-dot.on { background: var(--signal); box-shadow: 0 0 7px var(--signal); }
.status-dot.off { background: var(--muted-2); }
.status-dot.ban { background: var(--danger); }

/* ---------- Detail view ---------- */
.detail-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.detail-head .acct-avatar { width: 52px; height: 52px; font-size: 20px; border-radius: 12px; }
.detail-head h1 { margin: 0; font-size: 20px; }
.detail-head .sub { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-top: 3px; }
.back { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-bottom: 14px; display: inline-block; }
.back:hover { color: var(--text); }

.detail-cols { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.section-title {
  font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between;
}
.card + .card { margin-top: 16px; }

/* usage chart */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 96px; padding-top: 6px; }
.spark i {
  flex: 1; min-width: 2px; background: var(--signal-dim); border-radius: 2px 2px 0 0;
  position: relative; transition: background 0.14s;
}
.spark i:hover { background: var(--signal); }
.spark-labels { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; color: var(--muted-2); margin-top: 6px; }

.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); }

/* ---------- Forms / modal ---------- */
.modal-host { position: fixed; inset: 0; z-index: 50; place-items: center; background: rgba(4, 6, 10, 0.72); backdrop-filter: blur(3px); }
.modal-host[hidden] { display: none !important; }
.modal-host:not([hidden]) { display: grid; }
.modal { width: min(560px, 92vw); max-height: 90vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: 0 24px 60px rgba(0,0,0,0.5); }
.modal.wide { width: min(820px, 94vw); }
.remote-view {
  position: relative; width: 100%; aspect-ratio: 1000 / 720; max-height: 60vh; margin-inline: auto;
  background: #06090d; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  display: grid; place-items: center;
}
.remote-view img { width: 100%; height: 100%; object-fit: contain; display: block; cursor: default; outline: none; }
.remote-view .remote-hint {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: var(--muted); font-family: var(--mono); font-size: 12px; padding: 20px; pointer-events: none;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .desc { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 10px 12px; font-family: var(--mono); font-size: 13px; resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--signal); }
.field textarea { min-height: 120px; }
.field .hint { color: var(--muted-2); font-size: 11px; margin-top: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* auto-withdraw settings grid */
.awgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 12px; margin-top: 14px; }
.awcell { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.awcell > span { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.awgrid input, .awgrid select {
  width: 100%; box-sizing: border-box; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; color: var(--text); padding: 9px 11px; font-family: var(--mono); font-size: 13px;
}
.awgrid input:focus, .awgrid select:focus { outline: none; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-dim); }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal .dow { font-family: var(--mono); font-size: 10px; text-transform: uppercase; color: var(--muted); text-align: center; padding-bottom: 4px; }
.cal .day {
  aspect-ratio: 1; border: 1px solid var(--line-soft); border-radius: 7px; padding: 5px 6px;
  display: flex; flex-direction: column; justify-content: space-between; min-width: 0;
  background: var(--panel-2); position: relative;
}
.cal .day.empty { border: 0; background: transparent; }
.cal .day .dnum { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.cal .day .damt { font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--signal); line-height: 1.1; word-break: break-all; }
.cal .day.has { border-color: var(--signal); background: var(--signal-dim); }
.cal .day.fail { border-color: var(--danger); background: rgba(240, 97, 107, 0.1); }
.cal .day .dmark { position: absolute; top: 4px; right: 5px; width: 5px; height: 5px; border-radius: 50%; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

/* inbox */
.mail { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); align-items: flex-start; }
.mail:hover { background: var(--panel-2); }
.mail .mlabel { font-family: var(--mono); font-size: 10px; padding: 2px 7px; border-radius: 20px; background: var(--signal-dim); color: var(--signal); white-space: nowrap; flex-shrink: 0; }
.mail .mbody { min-width: 0; flex: 1; }
.mail .msub { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.mail .mfrom { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.mail .msum { color: var(--muted); font-size: 12px; margin-top: 5px; line-height: 1.5; }
.mail .mdate { font-family: var(--mono); font-size: 10px; color: var(--muted-2); white-space: nowrap; flex-shrink: 0; }
.mail.unread .msub::before { content: "●"; color: var(--signal); font-size: 9px; margin-right: 6px; vertical-align: middle; }

/* toggles */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .t-label { font-weight: 500; }
.toggle-row .t-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px; transition: 0.16s; }
.switch .track::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: 0.16s; }
.switch input:checked + .track { background: var(--signal-dim); border-color: var(--signal); }
.switch input:checked + .track::before { transform: translateX(20px); background: var(--signal); }

/* empty / loading */
.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty .big-ic { font-size: 34px; color: var(--muted-2); margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-weight: 600; }
.skeleton { background: linear-gradient(90deg, var(--panel) 25%, var(--panel-2) 50%, var(--panel) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-card { height: 168px; }

/* toasts */
.toast-host { position: fixed; bottom: 22px; right: 22px; z-index: 60; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--signal);
  border-radius: 8px; padding: 12px 16px; min-width: 240px; font-size: 13px;
  animation: slidein 0.22s ease; box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

/* misc rows */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.tag { font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "rail" "ledger" "view"; }
  .rail { flex-direction: row; align-items: center; padding: 12px; }
  .nav { flex-direction: row; margin-left: 12px; }
  .rail-foot { display: none; }
  .grid.stats { grid-template-columns: repeat(2, 1fr); }
  .detail-cols { grid-template-columns: 1fr; }
  .ledger { overflow-x: auto; }
}
