/* ── Design tokens ───────────────────────────────────────────────
   A control-room ledger, not a generic dark dashboard: warm brass
   for the accent (keys, seals, activation — the whole point of this
   tool) against a cool near-black, with a monospace register
   reserved for anything that is data (codes, tokens, dates) rather
   than prose. */
:root {
  --bg: #0a0d12;
  --surface: #12161d;
  --surface-2: #1a1f28;
  --surface-3: #212734;
  --line: #242a34;
  --line-soft: #1c212a;

  --ink: #edf0f5;
  --ink-muted: #8b93a3;
  --ink-faint: #545c6a;

  --brass: #d6a253;
  --brass-strong: #c4903f;
  --brass-soft: rgba(214, 162, 83, 0.14);
  --brass-ink: #241a0a;

  --ok: #3ecf8e;
  --ok-soft: rgba(62, 207, 142, 0.13);
  --danger: #ef5f6a;
  --danger-soft: rgba(239, 95, 106, 0.13);
  --warn: #e0a83a;
  --warn-soft: rgba(224, 168, 58, 0.13);
  --info: #5b9dee;
  --info-soft: rgba(91, 157, 238, 0.12);

  --font-body: "Cairo", "Segoe UI", Tahoma, sans-serif;
  --font-data: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow-lift: 0 10px 30px -12px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 520px at 85% -10%, rgba(214, 162, 83, 0.06), transparent 60%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body.centered { display: flex; align-items: center; justify-content: center; }

a { color: var(--brass); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-weight: 800; letter-spacing: -0.01em; color: var(--ink); margin: 0; }
h2 { font-size: 21px; }
h3 { font-size: 16px; }

.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.mono { font-family: var(--font-data); direction: ltr; unicode-bidi: isolate; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
}

/* ── Login ───────────────────────────────────────────────────── */
.login-shell {
  position: relative;
  width: min(400px, 92vw);
}
.login-shell::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: calc(var(--radius-lg) + 1px);
  background: linear-gradient(160deg, rgba(214, 162, 83, 0.35), transparent 45%);
  z-index: 0;
}
.login-card {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-lift);
}
.login-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.login-mark .seal {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(155deg, var(--brass), var(--brass-strong));
  display: flex; align-items: center; justify-content: center;
  color: var(--brass-ink); flex-shrink: 0;
  box-shadow: 0 6px 16px -6px rgba(214, 162, 83, 0.55);
}
.login-card h1 { font-size: 19px; }
.login-card .muted { font-size: 12.5px; margin-top: -8px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-muted);
}

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px var(--brass-soft);
}
input::placeholder { color: var(--ink-faint); }

button {
  background: var(--brass);
  color: var(--brass-ink);
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 13.5px;
  cursor: pointer;
  font-family: inherit;
  transition: background 120ms ease, transform 120ms ease;
}
button:hover { background: var(--brass-strong); }
button:active { transform: translateY(1px); }
button.secondary { background: var(--surface-3); color: var(--ink); border: 1px solid var(--line); font-weight: 700; }
button.secondary:hover { background: var(--surface-2); border-color: var(--brass); }
button.danger { background: var(--danger); color: #2a0d10; }
button.danger:hover { background: #e14a56; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.error-text {
  color: var(--danger);
  font-size: 12.5px;
  background: var(--danger-soft);
  border: 1px solid rgba(239, 95, 106, 0.3);
  border-radius: 8px;
  padding: 8px 10px;
}

/* ── App shell ───────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}
.sidebar .brand .seal {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(155deg, var(--brass), var(--brass-strong));
  display: flex; align-items: center; justify-content: center; color: var(--brass-ink);
}
.sidebar .brand .brand-text { display: flex; flex-direction: column; gap: 1px; }
.sidebar .brand .brand-text strong { font-size: 14px; font-weight: 800; color: var(--ink); }
.sidebar .brand .brand-text span { font-size: 10.5px; color: var(--ink-faint); }

.nav-section-label {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  padding: 12px 12px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink-muted);
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  border-inline-start: 2px solid transparent;
  margin-inline-start: -2px;
}
.nav-link svg { flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-link.active {
  background: var(--brass-soft);
  color: var(--brass);
  border-inline-start-color: var(--brass);
}
.nav-link.active svg { opacity: 1; }
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line-soft); }

main { padding: 28px 32px; max-width: 1180px; }

.page-eyebrow {
  font-size: 11px;
  font-weight: 800;
  color: var(--brass);
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.page-eyebrow::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--brass); }
.page-head { margin-bottom: 20px; }
.page-head .sub { margin-top: 4px; font-size: 13px; }

/* ── Stat tiles ──────────────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 22px; }
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-tile .n { font-size: 22px; font-weight: 800; font-family: var(--font-data); }
.stat-tile .l { font-size: 11.5px; color: var(--ink-faint); font-weight: 700; margin-top: 2px; }

/* ── Tables ──────────────────────────────────────────────────── */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
th, td { text-align: start; padding: 11px 10px; }
thead th {
  color: var(--ink-faint);
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}
tbody tr { border-bottom: 1px solid var(--line-soft); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
tbody td:first-child, thead th:first-child { border-radius: 8px 0 0 8px; }
tbody td:last-child, thead th:last-child { border-radius: 0 8px 8px 0; }

.table-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 6px 14px; overflow-x: auto; }

/* ── Status seals (icon + label, not just a color pill) ─────── */
.seal-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  border: 1px solid transparent;
}
.seal-chip svg { flex-shrink: 0; }
.seal-chip.ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(62, 207, 142, 0.25); }
.seal-chip.danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(239, 95, 106, 0.25); }
.seal-chip.warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(224, 168, 58, 0.25); }
.seal-chip.muted { background: var(--surface-3); color: var(--ink-muted); border-color: var(--line); }

/* legacy alias kept for any un-migrated spots */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.muted { background: var(--surface-3); color: var(--ink-muted); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input[type="search"] { min-width: 260px; }
.spacer { flex: 1; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 8, 11, 0.72);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow-y: auto; z-index: 50;
}
.modal {
  width: min(560px, 100%);
  display: flex; flex-direction: column; gap: 13px;
  box-shadow: var(--shadow-lift);
  border-color: var(--line);
}
.modal.modal-wide { width: min(780px, 100%); }
.wide-modal { width: 100%; }
.modal h3 { margin: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--line-soft); }

.detail-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 9px 2px; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--ink-faint); font-weight: 700; font-size: 12.5px; }
.detail-row .v { font-weight: 700; text-align: end; }

.tier-group { margin-top: 10px; }
.tier-group + .tier-group { margin-top: 12px; }
.tier-group-label {
  font-size: 11px; font-weight: 800; color: var(--ink-faint);
  margin-bottom: 6px; display: flex; align-items: center; gap: 6px;
}
.tier-group-label .dot { width: 6px; height: 6px; border-radius: 50%; }
.tier-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tier-chip {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--ink-muted); border: 1px solid var(--line);
}

.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; max-height: 260px; overflow-y: auto; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.chip-grid label { flex-direction: row; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink); }
.chip-grid input { width: auto; }

.form-section-label {
  color: var(--brass);
  font-size: 11.5px;
  font-weight: 800;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}
.upgrade-head { align-items: end; }
.upgrade-count { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-bottom: 2px; font-size: 12px; }
.upgrade-features { grid-template-columns: repeat(2, minmax(230px, 1fr)); max-height: 330px; }
.upgrade-tier-title {
  grid-column: 1 / -1;
  color: var(--brass);
  font-size: 11px;
  font-weight: 800;
  padding: 8px 2px 3px;
  border-bottom: 1px solid var(--line-soft);
}
.upgrade-tier-title:first-child { padding-top: 0; }
.upgrade-features label { justify-content: flex-start; }
.upgrade-features label .faint { margin-inline-start: auto; font-size: 10px; }
.upgrade-features label.feature-owned { color: var(--ink-muted); }

.token-box {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 11px; font-family: var(--font-data); font-size: 11.5px; word-break: break-all;
  max-height: 140px; overflow-y: auto; direction: ltr; text-align: left; color: var(--ink-muted);
}

.empty {
  color: var(--ink-faint);
  padding: 40px 24px;
  text-align: center;
  font-size: 13.5px;
}
.section-title { display: flex; align-items: center; gap: 10px; margin: 26px 0 10px; }
.section-title h3 { margin: 0; }
.section-title .count { font-size: 12px; color: var(--ink-faint); font-weight: 700; }

/* ── Referral programme ─────────────────────────────────────── */
.referral-summary {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 22px;
  margin-top: 14px;
}
.referral-link-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 7px; }
.referral-code {
  display: inline-flex;
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--font-data);
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--brass);
  background: var(--brass-soft);
  border: 1px dashed rgba(214, 162, 83, .45);
  border-radius: 8px;
  padding: 7px 11px;
}
.inline-check { flex-direction: row; align-items: center; color: var(--ink); }
.inline-check input { width: auto; }
.info-note {
  color: var(--info);
  background: var(--info-soft);
  border: 1px solid rgba(91, 157, 238, .24);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12.5px;
}
.commission-callout {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 15px;
  background: var(--brass-soft);
  border: 1px solid rgba(214, 162, 83, .25);
  border-radius: 9px;
}
.commission-callout strong { color: var(--brass); font-family: var(--font-data); font-size: 17px; }
.public-referral { width: min(540px, 92vw); text-align: center; }
.public-referral h1 { font-size: 24px; margin: 8px 0 12px; }
.public-referral .referral-code { font-size: 20px; margin: 12px 0; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; border-inline-start: 0; border-bottom: 1px solid var(--line); }
  .sidebar-foot { margin-top: 12px; }
  main { padding: 22px 16px; }
  .grid-2, .grid-3, .referral-summary { grid-template-columns: 1fr; }
  .upgrade-features { grid-template-columns: 1fr; }
  .toolbar input[type="search"] { min-width: 100%; }
}
