:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #111827;
  --muted: #5b6474;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --ok: #047857;
  --ok-bg: #e7f6ef;
  --warn: #a15c00;
  --warn-bg: #fdf3e2;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --info-bg: #e8effd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --accent: #6d97ff;
    --accent-ink: #0b1020;
    --ok: #4ade9b;
    --ok-bg: #12291f;
    --warn: #f5b454;
    --warn-bg: #2d2311;
    --bad: #ff8a80;
    --bad-bg: #331616;
    --info-bg: #17223b;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* layout */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.container { max-width: 1180px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; }
@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; gap: 12px; }
  .container { padding: 16px; }
  .userbox .who { display: none; }
}

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.nowrap, th.nowrap { white-space: nowrap; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.completed, .badge.signed, .badge.delivered, .badge.done, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.pending, .badge.ready, .badge.in_progress, .badge.running, .badge.completing, .badge.registering { background: var(--info-bg); color: var(--accent); }
.badge.declined, .badge.failed, .badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.expired, .badge.cancelled, .badge.waiting, .badge.warn { background: var(--warn-bg); color: var(--warn); }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=url], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { margin-bottom: 14px; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.field .errorlist, .errorlist { color: var(--bad); margin: 4px 0 0; padding: 0; list-style: none; font-size: 13px; }
.checkbox { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters > * { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.inline { display: inline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--border); }
.alert.success { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.alert.error { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.alert.warning, .alert.info { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.secret { display: flex; gap: 8px; align-items: center; }
.secret code { flex: 1; padding: 8px 10px; background: var(--surface-2); border-radius: 6px; word-break: break-all; }
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 8px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px dashed var(--border); display: flex; gap: 12px; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 128px; }

/* login + signing page */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }
.sign-wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.sign-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .sign-grid { grid-template-columns: 1fr; } .pdf-frame { height: 60vh; } }
.pdf-frame { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.vc { font-size: 34px; font-weight: 800; letter-spacing: .18em; text-align: center; margin: 8px 0; font-variant-numeric: tabular-nums; }
.qr { display: block; margin: 8px auto; width: 220px; max-width: 100%; background: #fff; border-radius: 8px; padding: 6px; }
.step-box { text-align: center; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.signers-list { list-style: none; padding: 0; margin: 0; }
.signers-list li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.signers-list li:last-child { border-bottom: 0; }
.stack > * + * { margin-top: 10px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
