:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #15191e;
  --muted: #5b6573;
  --line: #dfe3e8;
  --accent: #0b7a5f;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3ee;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1215;
    --surface: #171b20;
    --surface-2: #1f252c;
    --text: #e8ecf0;
    --muted: #9aa5b1;
    --line: #2b333c;
    --accent: #3fc79f;
    --accent-ink: #062018;
    --accent-soft: #143429;
    --danger: #ff7b6e;
    --danger-soft: #3a1a17;
    --warn: #f3c25b;
    --warn-soft: #362a10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
code, .mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 0.9em; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 640px; }
header.top { border-bottom: 1px solid var(--line); background: var(--surface); }
header.top .wrap { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text); text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.spacer { flex: 1; }
footer { border-top: 1px solid var(--line); margin-top: 56px; padding: 24px 0 40px; color: var(--muted); font-size: 0.875rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 0.875rem; }
.btn[aria-disabled='true'], .btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

.hero { padding: 64px 0 40px; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 640px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h3 { display: flex; align-items: center; gap: 8px; }
section { margin-top: 40px; }
ol.steps { padding-left: 1.2em; }
ol.steps li { margin-bottom: 0.5em; }

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 180px; }

.keybox { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; word-break: break-all; min-height: 110px; background: var(--surface-2); }
.notice { border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.notice.ok { background: var(--accent-soft); }
.notice.err { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
[hidden] { display: none !important; }

/* admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 20px 0; overflow-x: auto; }
.tabs button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 10px 14px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected='true'] { color: var(--text); border-bottom-color: var(--accent); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 20px; }
.stat b { display: block; font-size: 1.6rem; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input { flex: 1 1 220px; }
.toolbar select { flex: 0 0 150px; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 0.9rem; }
.table th { background: var(--surface-2); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.table td.actions-cell { white-space: nowrap; text-align: right; }
.scroll { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge.active { background: var(--accent-soft); color: var(--accent); }
.badge.revoked { background: var(--danger-soft); color: var(--danger); }
.badge.expired { background: var(--warn-soft); color: var(--warn); }
.login { max-width: 400px; margin: 72px auto; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 0.9rem; max-width: calc(100vw - 32px); }

@media (max-width: 640px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .table td { border: 0; padding: 4px 12px; }
  .table td.actions-cell { text-align: left; }
}
.stack > * + * { margin-top: 16px; }
.login .alt { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.btn.wide { width: 100%; }
