:root {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #121212;
  --line: #232323;
  --line-strong: #3a3a3a;
  --text: #f2f2f2;
  --muted: #8b8b8b;
  --accent: #ffffff;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--text); font-size: 13px; min-height: 18px; margin: 4px 0 0; }
.error:not(:empty)::before { content: "! "; }

.screen { min-height: 100vh; }
.centered { display: grid; place-items: center; padding: 24px; }

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

/* ---------- login ---------- */
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--accent);
  color: #000;
  font-weight: 700;
  font-size: 20px;
  display: grid;
  place-items: center;
}
.logo.small { width: 26px; height: 26px; border-radius: 7px; font-size: 13px; }

.login-card h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.login-card p { margin: 0; }

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

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }

button {
  font: inherit;
  font-size: 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  transition: opacity 0.12s ease, background 0.12s ease;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: #000; font-weight: 600; }
button.primary:hover:not(:disabled) { opacity: 0.85; }
button.ghost { background: transparent; border-color: var(--line-strong); color: var(--text); }
button.ghost:hover:not(:disabled) { border-color: var(--accent); }
button.icon { padding: 4px 10px; font-size: 18px; line-height: 1; }
button.small { padding: 6px 10px; font-size: 13px; }

/* ---------- app shell ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 7px 14px;
}
.tabs button.active { color: var(--text); border-color: var(--line-strong); }
.tabs button:hover { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.view { max-width: 1120px; margin: 0 auto; padding: 32px 24px 80px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; font-size: 14px; }

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.stat .value { font-size: 30px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 6px; }

/* ---------- tables ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.wrap { white-space: normal; }
td.actions { text-align: right; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-size: 12px;
  color: var(--muted);
}
.badge.active { border-color: var(--accent); color: var(--accent); }
.badge.expired { border-style: dashed; }
.badge.revoked { text-decoration: line-through; }

.mono { font-family: var(--mono); font-size: 12.5px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  background: var(--surface);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.secret {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.secret input { font-family: var(--mono); font-size: 12.5px; }

.note {
  border: 1px dashed var(--line-strong);
  border-radius: 9px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #000;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
}

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .topbar-right #user-email { display: none; }
  .view { padding: 20px 16px 60px; }
  .form-row { grid-template-columns: 1fr; }
}
