/* One stylesheet, no build step, no framework.
   Dark by default with a light override, because a panel that lives on a
   second monitor at 2am should not be a flashlight. */

:root {
  --bg: #12141a;
  --surface: #1a1d26;
  --surface-2: #222633;
  --border: #2e3444;
  --text: #e4e7ee;
  --muted: #949cb0;
  --accent: #6aa9ff;
  --accent-dim: #2b4a7d;
  --ok: #4ec98a;
  --warn: #e8b64c;
  --danger: #f0685f;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --radius: 8px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --border: #d8dce4;
    --text: #1b1f27;
    --muted: #5c6675;
    --accent: #1c62d0;
    --accent-dim: #cbdcf7;
    --ok: #14804a;
    --warn: #8a5a00;
    --danger: #b3261e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

code, pre, .mono { font-family: var(--mono); font-size: 13px; }

/* ── chrome ───────────────────────────────────────────────────────────── */

header.top {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header.top .brand {
  font-weight: 600;
  padding: 14px 0;
  color: var(--text);
  white-space: nowrap;
}
header.top .brand small { color: var(--muted); font-weight: 400; }

nav.main { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
nav.main a {
  padding: 15px 12px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
nav.main a:hover { color: var(--text); text-decoration: none; }
nav.main a.active { color: var(--text); border-bottom-color: var(--accent); }

.who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.who form { display: inline; }

main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 32px 0 12px; }
h3 { font-size: 14px; margin: 20px 0 8px; text-transform: uppercase;
     letter-spacing: .06em; color: var(--muted); }
.subtitle { color: var(--muted); margin: 0 0 24px; }

/* ── cards and grids ──────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat { text-align: left; }
.stat .value { font-size: 30px; font-weight: 600; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ── tables ───────────────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.empty { color: var(--muted); padding: 28px; text-align: center; }

/* ── forms ────────────────────────────────────────────────────────────── */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 16px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

input[type=text], input[type=password], input[type=number], input[type=email],
input[type=url], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 18px;
}
legend { padding: 0 8px; color: var(--muted); font-size: 12px;
         text-transform: uppercase; letter-spacing: .06em; }

.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.checks label {
  display: flex; align-items: center; gap: 7px;
  color: var(--text); font-size: 14px; margin: 0; cursor: pointer;
}
.checks input { margin: 0; }

.row { display: flex; gap: 12px; align-items: flex-end; }
.row > * { flex: 1; }
.row > .shrink { flex: 0 0 auto; }

/* ── buttons ──────────────────────────────────────────────────────────── */

button, .btn {
  display: inline-block;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.1); text-decoration: none; }

.btn.secondary, button.secondary {
  background: var(--surface-2); color: var(--text); border-color: var(--border);
}
.btn.danger, button.danger { background: var(--danger); }
.btn.small, button.small { padding: 5px 10px; font-size: 13px; }
.btn.link, button.link {
  background: none; border: none; color: var(--accent); padding: 0;
}

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 20px; }

/* ── badges and notices ───────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.danger { color: var(--danger); border-color: currentColor; }
.badge.accent { color: var(--accent); border-color: currentColor; }

.notice {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 18px;
}
.notice.ok { border-color: var(--ok); }
.notice.warn { border-color: var(--warn); }
.notice.danger { border-color: var(--danger); }
.notice p:first-child { margin-top: 0; }
.notice p:last-child { margin-bottom: 0; }
.notice ul { margin: 8px 0 0; padding-left: 20px; }

/* ── code blocks ──────────────────────────────────────────────────────── */

pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 12px;
  white-space: pre;
}
.copy-block { position: relative; }
.copy-block button {
  position: absolute; top: 8px; right: 8px;
  padding: 3px 9px; font-size: 12px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.copy-block button:hover { color: var(--text); }

.fingerprint {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  color: var(--text);
}

.kv { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: 8px 20px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; word-break: break-word; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs a, .tabs button {
  background: none; border: none; color: var(--muted);
  padding: 9px 14px; border-bottom: 2px solid transparent; cursor: pointer;
}
.tabs a.active, .tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

/* ── narrow pages (login, setup) ──────────────────────────────────────── */

.narrow { max-width: 460px; margin: 60px auto; padding: 0 20px; }
.narrow.wide { max-width: 640px; }
.narrow h1 { text-align: center; margin-bottom: 6px; }
.narrow .subtitle { text-align: center; }

@media (max-width: 720px) {
  header.top { flex-wrap: wrap; gap: 8px; padding: 0 14px; }
  main { padding: 20px 14px 60px; }
  .row { flex-direction: column; align-items: stretch; }
}

/* ── additions used by the issuance, enrolment and admin pages ─────────── */

/* A quieter button for secondary actions inside a card. */
.btn.ghost, button.ghost {
  background: none;
  color: var(--muted);
  border-color: var(--border);
}
.btn.ghost:hover, button.ghost:hover { color: var(--text); filter: none; }
button.ghost.danger, .btn.ghost.danger { color: var(--danger); background: none; }

/* Checkbox and radio labels, whether or not they sit inside .checks. */
label.check {
  display: flex; align-items: center; gap: 7px;
  color: var(--text); font-size: 14px; margin: 0; cursor: pointer;
}
label.check input { margin: 0; width: auto; }

/* Hints outside a .field — the same size and colour, just not nested. */
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.card > .hint { margin-bottom: 0; }

/* A form that has to sit inside a table cell next to other controls. */
form.inline { display: inline; }
form.inline select { width: auto; }

/* Repeatable SAN and extension rows. The template row is [hidden]; app.js
   clones it, so its layout has to match a real row exactly. */
.repeat-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.repeat-row input { flex: 1; }
.repeat-row select { flex: 0 0 auto; width: auto; }
.repeat-row button { flex: 0 0 auto; padding: 6px 10px; line-height: 1; }
.repeat-row[hidden] { display: none; }

/* Lists that are structure, not bullets. */
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 5px 0; border-bottom: 1px solid var(--border); }
ul.plain li:last-child { border-bottom: none; }

/* QR codes are rendered as scaled-up PNGs, so keep the pixels square and put
   them on white — a dark background makes them unscannable. */
.qr {
  width: 220px; height: 220px;
  image-rendering: pixelated;
  background: #fff; padding: 10px; border-radius: 8px;
}
