* { box-sizing: border-box; }
:root {
  --bg: #0f172a; --panel: #111827; --card: #1e293b; --text: #e5e7eb;
  --muted: #94a3b8; --line: #1f2937; --accent: #38bdf8; --navbar:#0b1220;
  --ok:#34d399; --bad:#f87171; --warn:#fcd34d;
}
html, body { height: 100%; margin: 0; }
body { font-family: -apple-system, Segoe UI, Roboto, "Noto Sans", sans-serif; background: var(--bg); color: var(--text); }

.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--navbar);
}
.brand { font-weight: 700; letter-spacing: .3px; }
.meta { display: flex; gap: 8px; align-items: center; }
.who { color: var(--muted); font-size: 13px; margin-right: 8px; }
.main { flex: 1; padding: 18px 20px; }

.btn {
  background: transparent; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04283a; border: none; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { color: var(--muted); }
.btn.danger { color: var(--bad); border-color: #7f1d1d; }
.btn.danger:hover { border-color: var(--bad); }
.btn.mini { padding: 4px 8px; font-size: 12px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; min-width: 900px; font-size: 14px; }
thead th {
  background: #0b1220; text-align: left; font-weight: 700; color: var(--text);
  padding: 10px 12px; white-space: nowrap; border-bottom: 1px solid var(--line);
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:nth-child(even) { background: rgba(255,255,255,0.03); }
tbody tr.inactive { opacity: .5; }
.key { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); }
.bal-low { color: var(--warn); font-weight: 700; }
.bal-zero { color: var(--bad); font-weight: 700; }
.pill { padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.pill.on { color: var(--ok); border-color: #14532d; }
.pill.off { color: var(--bad); border-color: #7f1d1d; }
.actions { display: flex; gap: 6px; }

.input {
  width: 100%; background: #0b1220; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; font-size: 14px; outline: none;
}
.input:focus { border-color: var(--accent); }
label.fld { display: block; margin: 10px 0 4px; font-size: 12px; color: var(--muted); }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 24px; display: flex; flex-direction: column; gap: 10px;
}
.login-brand { font-size: 20px; font-weight: 700; text-align: center; }
.login-sub { color: var(--muted); font-size: 13px; text-align: center; margin-bottom: 6px; }
.login-error { color: var(--bad); font-size: 13px; min-height: 16px; text-align: center; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; }
.modal-card {
  width: 440px; max-width: 92vw; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 20px; max-height: 88vh; overflow-y: auto;
}
.modal-title { font-weight: 700; font-size: 16px; margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.keybox {
  background: #0b1220; border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; color: var(--accent);
}
.note { color: var(--muted); font-size: 12px; margin-top: 8px; line-height: 1.5; }
.ledger { margin-top: 10px; font-size: 12px; }
.ledger .row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid var(--line); }

/* transactions table (ledger modal) — the modal widens only when it holds one */
.modal-card:has(.ledger-table) { width: 860px; }
.ledger-wrap { margin-top: 10px; overflow-x: auto; }
.ledger-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ledger-table th, .ledger-table td {
  padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top;
}
.ledger-table thead th {
  position: sticky; top: 0; background: var(--panel);
  font-weight: 600; color: var(--muted); white-space: nowrap;
}
.ledger-table tbody tr:hover { background: rgba(255, 255, 255, .03); }
.ledger-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger-table .nowrap { white-space: nowrap; color: var(--muted); }
/* Long topic titles truncate rather than stretching the table; full text is in
   the title attribute. */
.ledger-table .detail {
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ledger-table .credit { color: var(--ok); }
.ledger-table .debit { color: #fca5a5; }
.ledger-table .tok-split { color: var(--muted); font-size: 11px; }
.ledger-table tfoot td {
  padding-top: 8px; font-weight: 600; border-bottom: none; color: var(--muted);
}
.ledger-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.copied { color: var(--ok) !important; }
