:root {
  --bg: #0a0e14;
  --bg-elev: #0f141c;
  --panel: #131a24;
  --panel-2: #182230;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #eef2f7;
  --muted: #8b98a8;
  --faint: #5c6b7c;
  --mint: #1ecb8c;
  --mint-dim: rgba(30, 203, 140, 0.14);
  --amber: #e8b84a;
  --amber-dim: rgba(232, 184, 74, 0.14);
  --rose: #f07178;
  --sky: #5ba4f5;
  --sky-dim: rgba(91, 164, 245, 0.14);
  --violet: #a78bfa;
  --violet-dim: rgba(167, 139, 250, 0.14);
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --side-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background:
    radial-gradient(900px 480px at 12% -10%, rgba(30, 203, 140, 0.08), transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(91, 164, 245, 0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--mint); }

/* .gate/.shell set display:grid — must beat UA [hidden] or login stays stacked over app */
[hidden],
.gate[hidden],
.shell[hidden],
.view[hidden],
.kpi-row[hidden] {
  display: none !important;
}
body.is-authed .gate {
  display: none !important;
}

.muted { color: var(--muted); }
.err { color: var(--rose); margin: 0.85rem 0 0; font-size: 0.9rem; }
.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

/* ── Gate ── */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.gate-shell {
  width: min(420px, 100%);
  padding: 2.25rem 2rem;
  background: linear-gradient(165deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.gate-brand {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mint);
  margin-bottom: 1rem;
}
.gate-shell h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.gate-sub {
  margin: 0.55rem 0 1.25rem;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
}
.gate-owner {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0 1.5rem;
  padding: 0.65rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text);
}
.gate-owner span {
  font-family: var(--font);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 0.2rem 0.4rem;
  background: var(--panel-2);
  border-radius: 5px;
}

/* ── Buttons ── */
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.55rem 0.95rem;
  border-radius: 9px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { border-color: rgba(255,255,255,0.22); background: #1c2634; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--mint);
  border-color: transparent;
  color: #04150e;
}
.btn-primary:hover { background: #28d998; filter: none; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.btn-lg { width: 100%; padding: 0.8rem 1rem; font-size: 0.95rem; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }

/* ── Shell ── */
.shell {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.25rem 1rem;
  background: rgba(10, 14, 20, 0.85);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.25rem 0.35rem;
}
.side-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--mint-dim);
  color: var(--mint);
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}
.side-brand strong { display: block; font-size: 0.95rem; }
.side-brand em {
  display: block;
  font-style: normal;
  font-size: 0.72rem;
  color: var(--faint);
}
.side-nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav-item {
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.7rem 0.85rem;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.9rem;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.is-on {
  background: var(--mint-dim);
  color: var(--mint);
}
.side-foot { display: flex; flex-direction: column; gap: 0.55rem; }
.side-who {
  font-size: 0.72rem;
  color: var(--faint);
  word-break: break-all;
  padding: 0 0.35rem;
  font-family: var(--mono);
}

.main {
  padding: 1.5rem 1.75rem 3rem;
  min-width: 0;
}
.main-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.main-top h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.main-sub {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}
.main-actions { display: flex; gap: 0.4rem; }

/* KPIs */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.kpi-l {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.35rem;
}
.kpi strong {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}
.search-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 200px;
  max-width: 360px;
  padding: 0.55rem 0.85rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--faint);
}
.search-wrap:focus-within {
  border-color: rgba(30, 203, 140, 0.45);
  box-shadow: 0 0 0 3px rgba(30, 203, 140, 0.1);
}
.search-wrap input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
}
.search-wrap input::placeholder { color: var(--faint); }
.toolbar-meta { color: var(--muted); font-size: 0.82rem; }

.table-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.table-wrap { overflow-x: auto; }
.table-foot {
  display: flex;
  justify-content: center;
  padding: 0.65rem;
  border-top: 1px solid var(--line);
}

.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--faint);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.data tbody tr:last-child td { border-bottom: 0; }
.data tr.row { cursor: pointer; transition: background 0.12s; }
.data tr.row:hover { background: rgba(255, 255, 255, 0.025); }
.data .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.data .user-cell strong { display: block; font-weight: 600; }
.data .user-cell .uid {
  margin-top: 0.15rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--faint);
}
.data .mono { font-family: var(--mono); font-size: 0.8rem; }
.data .stack-muted {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--faint);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--sky-dim);
  color: var(--sky);
}
.badge-free { background: rgba(92,107,124,0.2); color: var(--muted); }
.badge-fair { background: var(--amber-dim); color: var(--amber); }
.badge-pro, .badge-pro_max { background: var(--mint-dim); color: var(--mint); }
.badge-elite, .badge-family, .badge-family_elite { background: var(--violet-dim); color: var(--violet); }
.badge-paid { background: var(--mint-dim); color: var(--mint); }
.badge-created, .badge-failed, .badge-cancelled, .badge-abandoned {
  background: rgba(240,113,120,0.12); color: var(--rose);
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 0.35rem;
  background: var(--faint);
}
.status-dot.on { background: var(--mint); box-shadow: 0 0 0 3px rgba(30,203,140,0.15); }

.back-link {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0;
  margin-bottom: 1rem;
}
.back-link:hover { color: var(--mint); }
.detail-head { margin-bottom: 1.1rem; }
.detail-head h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.kv {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1.35rem;
}
.kv-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
}
.kv-item .l {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--faint);
}
.kv-item .v {
  margin-top: 0.35rem;
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  word-break: break-word;
}

.section-block { margin-top: 1.5rem; }
.section-block h3 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  font-weight: 700;
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 1.1rem 1rem 2.5rem; }
}
