:root {
  --brand: #2d54da;
  --brand-dark: #1f3fb0;
  --brand-soft: #eef2fd;
  --ink: #18201d;
  --muted: #5d6763;
  --bg: #f6f7f8;
  --card: #ffffff;
  --line: #e1e5e8;
  --input-line: #c6ccd1;
  --ok: #1f7a4a;
  --warn: #9a6a00;
  --danger: #b42318;
  --radius: 12px;
  font-family: Assistant, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; }
[hidden] { display: none !important; }

.site-header {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 16px 6px; background: var(--card); border-bottom: 1px solid var(--line);
}
.logo { height: 34px; width: auto; direction: ltr; unicode-bidi: isolate; }
.top-nav { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; justify-content: center; }
.top-nav a, .link-button {
  color: var(--brand); text-decoration: none; font: inherit; background: none; border: 0; padding: 4px 0; cursor: pointer;
}
.top-nav form { margin: 0; }

main { max-width: 820px; margin: 0 auto; padding: 16px 16px 48px; }
main.narrow { max-width: 520px; }
h1 { font-size: 1.5rem; text-align: center; margin: 12px 0 18px; }
h2 { font-size: 1.1rem; margin: 0; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 14px;
}
fieldset.card { min-width: 0; }
legend { font-weight: 700; padding: 0 6px; }
.center { text-align: center; }
.muted { color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; flex: 1; min-width: 0; }
.field span { font-size: .95rem; }
input:not([type=radio]):not([type=checkbox]) {
  width: 100%; font: inherit; font-weight: 400; padding: 11px 12px; border: 1px solid var(--input-line); border-radius: 10px; background: #fff; color: var(--ink);
}
select {
  font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid var(--input-line); border-radius: 10px; background: #fff; color: var(--ink);
}
.field select { width: 100%; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
input:disabled, select:disabled { background: #f1f3f5; color: var(--muted); }
.row-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
[data-filler-row="auto"] .field input, [data-filler-row="auto"] .field select { display: none; }
input[readonly] { background: #f1f3f5; }

.field-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.toggle { display: inline-flex; border: 1px solid var(--input-line); border-radius: 10px; overflow: hidden; }
.toggle label { position: relative; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; inset: 0; }
.toggle span { display: block; padding: 10px 14px; font-weight: 600; font-size: .9rem; }
.toggle input:checked + span { background: var(--brand); color: #fff; }
.toggle input:focus-visible + span { outline: 2px solid var(--brand-dark); outline-offset: -3px; }
.card > .toggle { display: flex; width: fit-content; margin: 0 auto; }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
.actions form { margin: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 150px;
  font: inherit; font-weight: 700; padding: 11px 22px; border-radius: 10px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; color: var(--brand); }
.btn-ghost:hover { background: var(--brand-soft); }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .7; cursor: wait; }
.busy::after {
  content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert { background: #fdecea; border: 1px solid #f4b7b0; color: var(--danger); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }

.list { padding: 0; overflow: hidden; }
.row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--brand-soft); }
.row-main { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--muted); font-size: .9rem; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .85rem; font-weight: 700; background: #eef0f2; color: var(--muted); }
.badge-complete, .badge-signed { background: #e3f3ea; color: var(--ok); }
.badge-open, .badge-filled, .badge-opened { background: #fff4d6; color: var(--warn); }
.badge-cancelled, .badge-failed { background: #fdecea; color: var(--danger); }

.facts { margin: 0; display: grid; gap: 8px; }
.facts div { display: flex; gap: 10px; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; text-align: left; }
.hash { font-family: Consolas, monospace; font-size: .75rem; word-break: break-all; }
.link-box input { font-family: Consolas, monospace; font-size: .85rem; }

.signature-pad { border: 2px dashed var(--input-line); border-radius: var(--radius); background: #fff; touch-action: none; }
.signature-pad.invalid { border-color: var(--danger); }
.signature-pad canvas { display: block; width: 100%; height: auto; aspect-ratio: 3 / 1; cursor: crosshair; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; accent-color: var(--brand); }

@media (max-width: 560px) {
  .field-row { flex-direction: column; align-items: stretch; }
  .field-row .toggle { align-self: flex-start; }
  .row { grid-template-columns: 1fr auto; }
  .row-meta { grid-column: 1; grid-row: 2; }
  .btn { width: 100%; }
}

.steps { display: flex; gap: 6px; justify-content: center; list-style: none; padding: 0; margin: 0 0 6px; counter-reset: step; flex-wrap: wrap; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); font-weight: 600; }
.steps li::before { content: counter(step); display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--input-line); font-size: .8rem; }
.steps li + li::after { content: ""; }
.steps li.current { color: var(--brand); }
.steps li.current::before { background: var(--brand); color: #fff; border-color: var(--brand); }
.steps li.done::before { content: "✓"; background: var(--brand-soft); color: var(--brand); border-color: var(--brand-soft); }

.locked-value { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f1f3f5; font-weight: 700; }

.capture-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.capture {
  position: relative; display: grid; place-items: center; gap: 6px; min-height: 130px; padding: 12px;
  border: 2px dashed var(--input-line); border-radius: var(--radius); background: #fff; cursor: pointer; text-align: center; overflow: hidden;
}
.capture img { width: 100%; max-height: 120px; object-fit: contain; border-radius: 8px; }
.capture-label { font-weight: 700; }
.capture-status { font-size: .85rem; color: var(--muted); }
.capture.ok { border-style: solid; border-color: var(--ok); }
.capture.ok .capture-status { color: var(--ok); font-weight: 700; }
.capture.busy .capture-status::after { content: ""; display: inline-block; margin-inline-start: 6px; width: 10px; height: 10px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.capture.busy::after { display: none; }

.liveness { position: relative; display: grid; place-items: center; min-height: 40px; }
.liveness video { width: 100%; max-width: 420px; border-radius: var(--radius); transform: scaleX(-1); background: #000; }
.liveness-oval { position: absolute; top: 50%; left: 50%; width: 46%; max-width: 190px; aspect-ratio: 3 / 4; transform: translate(-50%, -55%); border: 3px solid rgba(255, 255, 255, .85); border-radius: 50%; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); pointer-events: none; }
.liveness-prompt { position: absolute; bottom: 10px; left: 10px; right: 10px; text-align: center; font-size: 1.15rem; font-weight: 800; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.liveness-prompt:empty { display: none; }
.liveness video[hidden] + .liveness-oval + .liveness-prompt { position: static; color: var(--ink); text-shadow: none; }
.liveness-steps { display: flex; gap: 8px; justify-content: center; list-style: none; padding: 0; margin: 0; flex-wrap: wrap; }
.liveness-steps li { padding: 4px 12px; border-radius: 999px; background: #eef0f2; color: var(--muted); font-weight: 700; font-size: .9rem; }
.liveness-steps li.done { background: #e3f3ea; color: var(--ok); }

.busy-block { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px 0; color: var(--muted); font-weight: 700; }
.busy-block::after { content: ""; width: 18px; height: 18px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.doc-pages { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.doc-page { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .06); }
.doc-end { height: 1px; }

.sig-pad { position: relative; overflow: hidden; border: 2px dashed rgba(45, 84, 218, .4); border-radius: var(--radius); background: #fff; touch-action: none; }
.sig-pad canvas { display: block; width: 100%; cursor: crosshair; touch-action: none; }
.sig-pad.locked { opacity: .5; pointer-events: none; }
.sig-pad.invalid { border-color: var(--danger); }
.sig-line { position: absolute; left: 32px; right: 32px; bottom: 26px; border-top: 1px solid rgba(225, 229, 232, .9); pointer-events: none; }
.sig-mark { position: absolute; right: 32px; bottom: 10px; font-size: 11px; font-weight: 700; color: rgba(93, 103, 99, .7); pointer-events: none; }
.sig-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 14.5px; font-weight: 500; color: var(--muted); pointer-events: none; }
.sig-pad.has-ink .sig-hint { display: none; }
.link-button:disabled { color: var(--muted); cursor: default; }

.identity-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.identity-strip a { display: grid; gap: 4px; text-align: center; color: var(--muted); font-size: .8rem; text-decoration: none; }
.identity-strip img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
