:root {
  --bg: #06070a;
  --bg-2: #090b11;
  --panel: #0c0f16;
  --panel-2: #10141d;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #e8ebf2;
  --muted: #7d8598;
  --lime: #b8ff2b;
  --lime-dim: rgba(184, 255, 43, 0.14);
  --pink: #ff3d81;
  --pink-dim: rgba(255, 61, 129, 0.14);
  --cyan: #4de1ff;
  --amber: #ffc857;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1100px 600px at 12% -10%, rgba(184, 255, 43, 0.09), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 61, 129, 0.08), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 1;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.014) 0px,
    rgba(255, 255, 255, 0.014) 1px,
    transparent 2px,
    transparent 4px
  );
  mix-blend-mode: overlay;
  opacity: 0.6;
}

a { color: var(--lime); }

.mono { font-family: var(--mono); }

/* ── login ─────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 2;
}

.login-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line-2);
  border-radius: 16px;
  padding: 32px 28px 26px;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(184, 255, 43, 0.04) inset;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--lime), transparent);
  animation: sweep 4.5s linear infinite;
}

@keyframes sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.login-card .glyph {
  font-size: 22px;
  color: var(--lime);
  text-shadow: 0 0 18px rgba(184, 255, 43, 0.7);
  margin-bottom: 6px;
}

.login-card h1 {
  font-family: var(--mono);
  font-size: 24px;
  letter-spacing: 0.12em;
  margin: 0 0 4px;
  font-weight: 700;
}

.login-card h1 span, .brand span { color: var(--pink); }

.login-card .tag {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0 0 26px;
}

label {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 6px;
}

input, select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 9px;
  padding: 11px 12px;
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { min-height: 120px; resize: vertical; line-height: 1.5; }

input:focus, select:focus, textarea:focus {
  border-color: rgba(184, 255, 43, 0.55);
  box-shadow: 0 0 0 3px rgba(184, 255, 43, 0.09);
}

.error {
  color: var(--pink);
  font-family: var(--mono);
  font-size: 12px;
  min-height: 18px;
  margin-top: 12px;
}

/* ── buttons ───────────────────────────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  padding: 8px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:hover { border-color: rgba(184, 255, 43, 0.45); color: var(--lime); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn.primary {
  background: var(--lime);
  border-color: var(--lime);
  color: #06070a;
  font-weight: 700;
}

.btn.primary:hover { background: #c9ff5c; color: #06070a; }

.btn.active {
  background: var(--lime);
  border-color: var(--lime);
  color: #06070a;
  font-weight: 700;
}

.btn.danger { border-color: rgba(255, 61, 129, 0.4); color: var(--pink); }
.btn.danger:hover { background: var(--pink-dim); border-color: var(--pink); }

.btn.ghost { color: var(--muted); }
.btn.small { padding: 5px 9px; font-size: 10.5px; }
.btn.wide { width: 100%; margin-top: 20px; padding: 12px; }

/* ── shell ─────────────────────────────────────────────────────────────── */
.app { position: relative; z-index: 2; min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 22px;
  height: 62px;
  background: rgba(6, 7, 10, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 15px;
  white-space: nowrap;
}

.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }

.nav a {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  padding: 21px 13px 19px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.nav a:hover { color: var(--text); }
.nav a.active { color: var(--lime); border-bottom-color: var(--lime); }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 14px;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.active { background: var(--lime); color: #06070a; font-weight: 700; }
.seg button.danger.active { background: var(--pink); color: #fff; }

.who {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}

.view { padding: 26px 22px 80px; max-width: 1500px; margin: 0 auto; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-head h2 {
  font-family: var(--mono);
  font-size: 17px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0;
}

.page-head .sub {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  margin-top: 5px;
}

/* ── cards / stats ─────────────────────────────────────────────────────── */
.grid { display: grid; gap: 14px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.032), rgba(255, 255, 255, 0.012));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}

.card::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(184, 255, 43, 0.35), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}

.card:hover::after { opacity: 1; }

.card .label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.card .value {
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: -0.02em;
}

.card .value.lime { color: var(--lime); }
.card .value.pink { color: var(--pink); }
.card .value.cyan { color: var(--cyan); }
.card .value.amber { color: var(--amber); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 130px;
  padding: 18px 16px 12px;
}

.chart .bar {
  flex: 1;
  min-width: 2px;
  background: linear-gradient(180deg, var(--lime), rgba(184, 255, 43, 0.22));
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: filter 0.15s;
}

.chart .bar.pink { background: linear-gradient(180deg, var(--pink), rgba(255, 61, 129, 0.2)); }
.chart .bar:hover { filter: brightness(1.35); }

/* ── tables ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

th {
  text-align: left;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.015);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
  vertical-align: middle;
}

tbody tr:hover { background: rgba(184, 255, 43, 0.035); }
tbody tr:last-child td { border-bottom: 0; }

.k { font-family: var(--mono); font-size: 12px; color: var(--text); }
.dim { color: var(--muted); }
.tiny { font-family: var(--mono); font-size: 10.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mid { vertical-align: middle; }

.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill.active { color: var(--lime); background: var(--lime-dim); border-color: rgba(184, 255, 43, 0.3); }
.pill.expired { color: var(--amber); background: rgba(255, 200, 87, 0.1); border-color: rgba(255, 200, 87, 0.3); }
.pill.banned, .pill.revoked, .pill.disabled { color: var(--pink); background: var(--pink-dim); border-color: rgba(255, 61, 129, 0.3); }
.pill.legacy { color: var(--cyan); background: rgba(77, 225, 255, 0.1); border-color: rgba(77, 225, 255, 0.3); }
.pill.pending { color: var(--amber); background: rgba(255, 200, 87, 0.08); border-color: rgba(255, 200, 87, 0.28); }
.pill.neutral { color: var(--muted); background: rgba(255, 255, 255, 0.05); border-color: var(--line-2); }

.toolbar {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar .field { display: flex; flex-direction: column; gap: 4px; }
.toolbar label { margin: 0; }
.toolbar input, .toolbar select { padding: 8px 10px; font-size: 12px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar .spacer { flex: 1; }

.pager-pages { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pager-pages .btn { padding: 4px 8px; min-width: 28px; text-align: center; }
.pager-gap { color: var(--muted); font-family: var(--mono); padding: 0 2px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.empty {
  padding: 46px 20px;
  text-align: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
}

.row-actions { display: flex; gap: 5px; justify-content: flex-end; flex-wrap: wrap; }

/* ── modal ─────────────────────────────────────────────────────────────── */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(3, 4, 6, 0.78);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal {
  width: min(640px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.8);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.modal-body { padding: 18px 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

pre {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  color: #cfe6a8;
  margin: 0;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  margin-bottom: 8px;
}

.copy-row .k { flex: 1; overflow-x: auto; white-space: nowrap; }
.copy-row .lbl {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 96px;
}

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--lime);
  border-radius: 9px;
  padding: 11px 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.18s ease-out;
}

.toast.err { border-left-color: var(--pink); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.notice {
  border: 1px solid rgba(255, 200, 87, 0.28);
  background: rgba(255, 200, 87, 0.06);
  color: #ffdd9e;
  border-radius: 9px;
  padding: 10px 13px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  margin-bottom: 14px;
}

.two-col { display: grid; grid-template-columns: 1.15fr 1fr; gap: 14px; }

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .topbar { height: auto; padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .nav { order: 3; width: 100%; }
  .nav button { padding: 10px 9px; }
  .view { padding: 18px 14px 60px; }
  .form-row { grid-template-columns: 1fr; }
}

/* row action menu (...) */
.menu {
  position: fixed;
  z-index: 70;
  min-width: 190px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.6);
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.03em;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
}

.menu button:hover { background: rgba(184, 255, 43, 0.09); color: var(--lime); }
.menu button.danger { color: rgba(255, 61, 129, 0.92); }
.menu button.danger:hover { background: rgba(255, 61, 129, 0.14); color: var(--pink); }

tbody tr.selected { background: rgba(184, 255, 43, 0.055); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

/* ── mobile bottom navigation ──────────────────────────────────────────── */
.bottom-nav { display: none; }
.more-sheet { display: none; }
.only-sm { display: none; }

.sheet-title {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 12px 8px;
}

@media (max-width: 900px) {
  .topbar .nav { display: none; }
  .hide-sm { display: none !important; }
  .only-sm { display: inline; }
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    background: rgba(6, 7, 10, 0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }

  .bottom-nav a,
  .bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.05em;
    text-decoration: none;
    cursor: pointer;
  }

  .bottom-nav .glyph { font-size: 17px; line-height: 1; }
  .bottom-nav .active { color: var(--lime); background: rgba(184, 255, 43, 0.09); }

  .more-sheet {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(3, 4, 6, 0.74);
    backdrop-filter: blur(6px);
  }

  .more-sheet .sheet-panel {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    background: var(--panel-2);
    border: 1px solid var(--line-2);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  }

  .more-sheet a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 12px;
    border-radius: 9px;
    color: var(--text);
    text-decoration: none;
    font-family: var(--mono);
    font-size: 12px;
  }

  .more-sheet a:active,
  .more-sheet a:hover { background: rgba(184, 255, 43, 0.09); color: var(--lime); }
  .more-sheet a .chev { color: var(--muted); }

  /* keep the "..." actions reachable — only on tables that have them */
  #keys-body th:last-child,
  #keys-body td:last-child,
  #devices-body th:last-child,
  #devices-body td:last-child,
  #packages-body th:last-child,
  #packages-body td:last-child {
    position: sticky;
    right: 0;
    background: var(--panel);
  }

  #keys-body th:last-child,
  #devices-body th:last-child,
  #packages-body th:last-child { background: #10141d; }

  /* dashboard recent logins: time / key / result only */
  #dash-recent th:nth-child(2),
  #dash-recent td:nth-child(2),
  #dash-recent th:nth-child(4),
  #dash-recent td:nth-child(4) { display: none; }

  #dash-recent td.k { font-size: 10.5px; overflow-wrap: anywhere; }
  #dash-recent .pill {
    font-size: 8px;
    padding: 2px 4px;
    letter-spacing: 0.04em;
    white-space: nowrap;
  }
  #dash-recent td { vertical-align: top; }

  /* copy-row / backup rows: let the value wrap instead of scrolling */
  .copy-row { flex-wrap: wrap; }
  .copy-row .lbl { min-width: auto; flex: 0 0 auto; }
  .copy-row .k { flex: 1 1 60%; white-space: normal; overflow: visible; }

  /* keys table on narrow screens: keep key / status / expiry / actions */
  #keys-body th:nth-child(3),
  #keys-body td:nth-child(3),
  #keys-body th:nth-child(5),
  #keys-body td:nth-child(5),
  #keys-body th:nth-child(6),
  #keys-body td:nth-child(6),
  #keys-body th:nth-child(7),
  #keys-body td:nth-child(7) { display: none; }

  #keys-body td.k { font-size: 11px; }
  #keys-body th,
  #keys-body td { padding: 9px 8px; }
  #keys-body .tiny { font-size: 9.5px; }
}
