:root {
  --ink: #0a0a0a;
  --ink-2: #3a3a3a;
  --ink-3: #6b6b6b;
  --line: #e2e2e2;
  --line-2: #cfcfcf;
  --paper: #ffffff;
  --wash: #f5f5f5;
  --wash-2: #ececec;
  --ok: #1a7f37;
  --wait: #9a6700;
  --bad: #c62828;
  --info: #1f5fbf;
  --r1: #2f6fdb;
  --r2: #d0661f;
  --r3: #2e9e6a;
  --r4: #8a4fd1;
  --r5: #c23b7a;
  --r6: #1d9bb0;
  --r7: #8c7a1f;
  --r8: #5b6b7f;
  --sans: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Azeret Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --radius: 2px;
  --bar: 56px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--wash); color: var(--ink); font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 26px; line-height: 1.15; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.label { font: 500 11px/1.2 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--ink-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--bar); background: var(--ink); color: #fff; display: flex; align-items: center; gap: 22px; padding: 0 20px; }
.brand { font: 600 13px/1 var(--mono); letter-spacing: 0.16em; text-transform: uppercase; text-decoration: none; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { width: 18px; height: 18px; border: 2px solid #fff; position: relative; }
.brand-mark::after { content: ''; position: absolute; left: 2px; right: 2px; bottom: 3px; height: 2px; background: #fff; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a { text-decoration: none; padding: 8px 12px; font: 500 12px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: #bdbdbd; border-radius: var(--radius); white-space: nowrap; }
.nav a:hover, .nav a.on { color: #fff; background: #222; }
.topbar .btn-light { margin-left: auto; }
.preview-chip { font: 500 10px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; border: 1px solid #555; color: #bdbdbd; padding: 5px 7px; border-radius: var(--radius); white-space: nowrap; }

main { min-height: calc(100% - var(--bar)); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 20px 80px; }
.wrap-narrow { max-width: 640px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head .sub { margin-top: 6px; color: var(--ink-3); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--paper); cursor: pointer; font: 600 12px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #262626; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--wash-2); border-color: transparent; }
.btn-light { background: transparent; color: #fff; border-color: #555; }
.btn-light:hover { border-color: #fff; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 11px; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border: 0; background: transparent; border-radius: var(--radius); cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--wash-2); color: var(--ink); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Panels and forms */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-pad { padding: 20px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.input, .select, .textarea { width: 100%; height: 40px; border: 1px solid var(--line-2); border-radius: var(--radius); padding: 0 12px; background: var(--paper); }
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ink); }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--ink); }
.hint { font-size: 13px; color: var(--ink-3); }
.error { color: var(--bad); font-size: 13px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 7px; font: 500 11px/1 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); white-space: nowrap; }
.badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.badge-ok i { background: var(--ok); }
.badge-ok { color: var(--ok); }
.badge-wait i { background: var(--wait); }
.badge-wait { color: var(--wait); }
.badge-bad i { background: var(--bad); }
.badge-bad { color: var(--bad); }
.badge-info i { background: var(--info); }
.badge-info { color: var(--info); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font: 500 11px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); padding: 12px 16px; border-bottom: 1px solid var(--line); }
.table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--wash); }
.table tr:last-child td { border-bottom: 0; }
.subject { font-weight: 600; }
.small { font-size: 13px; color: var(--ink-3); }
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); margin-bottom: 0; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 12px 16px; font: 500 12px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
.empty { padding: 56px 20px; text-align: center; color: var(--ink-3); }

/* Wizard */
.steps { display: flex; gap: 0; background: var(--paper); border-bottom: 1px solid var(--line); overflow-x: auto; }
.steps a { display: flex; align-items: center; gap: 10px; padding: 14px 18px; text-decoration: none; font: 500 12px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); border-bottom: 2px solid transparent; white-space: nowrap; }
.steps a b { width: 22px; height: 22px; display: grid; place-items: center; border: 1px solid var(--line-2); border-radius: 50%; font-weight: 600; font-size: 11px; }
.steps a.on { color: var(--ink); border-bottom-color: var(--ink); }
.steps a.on b, .steps a.done b { background: var(--ink); color: #fff; border-color: var(--ink); }
.footbar { position: sticky; bottom: 0; background: var(--paper); border-top: 1px solid var(--line); padding: 12px 20px; display: flex; justify-content: space-between; gap: 10px; z-index: 20; }

.drop { border: 1.5px dashed var(--line-2); border-radius: var(--radius); background: var(--paper); padding: 40px 20px; text-align: center; cursor: pointer; }
.drop.over { border-color: var(--ink); background: var(--wash-2); }
.drop .ic { width: 30px; height: 30px; margin-bottom: 10px; }
.doc-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.doc-row:last-child { border-bottom: 0; }
.doc-thumb { width: 38px; height: 48px; border: 1px solid var(--line-2); display: grid; place-items: center; color: var(--ink-3); flex: none; background: var(--wash); }

.rcp-row { display: grid; grid-template-columns: 6px 54px 1fr 1fr 170px 34px; gap: 10px; align-items: start; padding: 14px 16px 14px 0; border-bottom: 1px solid var(--line); }
.rcp-row:last-child { border-bottom: 0; }
.rcp-bar { align-self: stretch; }
.rcp-order { height: 40px; text-align: center; padding: 0 6px; }
.rcp-extra { grid-column: 3 / -1; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.rcp-extra .input { max-width: 220px; height: 34px; }

/* Field placement */
.prep { display: grid; grid-template-columns: 220px 1fr 240px; min-height: calc(100vh - var(--bar) - 49px - 65px); }
.prep-side { background: var(--paper); border-right: 1px solid var(--line); padding: 16px; position: sticky; top: calc(var(--bar) + 49px); align-self: start; max-height: calc(100vh - var(--bar) - 49px - 65px); overflow: auto; }
.prep-side.right { border-right: 0; border-left: 1px solid var(--line); }
.prep-canvas { padding: 24px; overflow: auto; }
.who { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 1px solid var(--line-2); background: var(--paper); border-radius: var(--radius); cursor: pointer; margin-bottom: 6px; text-align: left; }
.who.on { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--c); }
.who i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.tool { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 1px solid transparent; background: none; cursor: grab; border-radius: var(--radius); font-size: 14px; text-align: left; }
.tool:hover { background: var(--wash); }
.tool.armed { border-color: var(--ink); background: var(--wash-2); }
.tool em { font: 600 10px/1 var(--mono); width: 34px; height: 22px; display: grid; place-items: center; border: 1px solid var(--c); color: var(--c); border-radius: var(--radius); font-style: normal; text-transform: uppercase; background: color-mix(in srgb, var(--c) 10%, transparent); }
.pages { max-width: 860px; margin: 0 auto; display: grid; gap: 18px; }
.doc-label { max-width: 860px; margin: 0 auto 10px; display: flex; justify-content: space-between; }
.page { position: relative; background: var(--paper); border: 1px solid var(--line-2); width: 100%; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page-layer { position: absolute; inset: 0; }
.page-no { position: absolute; right: 8px; bottom: -18px; font: 500 10px/1 var(--mono); color: var(--ink-3); }
.armed-cursor .page-layer { cursor: crosshair; }
.fld { position: absolute; border: 1.5px solid var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font: 600 10px/1 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--c); user-select: none; touch-action: none; overflow: hidden; }
.fld.sel { outline: 2px solid var(--ink); outline-offset: 1px; }
.fld.prep-fld { cursor: move; }
.fld .rz { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; background: var(--ink); cursor: nwse-resize; }
.fld .req { position: absolute; top: 1px; right: 3px; color: var(--bad); font-size: 12px; }
.props .field { margin-bottom: 12px; }

/* Signing */
.signbar { position: sticky; top: 0; z-index: 25; background: var(--paper); border-bottom: 1px solid var(--line); }
.signbar-in { max-width: 980px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.signbar-in .grow { flex: 1; min-width: 200px; }
.progress { font: 500 11px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.consent { background: var(--ink); color: #fff; }
.consent-in { max-width: 980px; margin: 0 auto; padding: 14px 20px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.consent-in .check { flex: 1; min-width: 240px; }
.consent-in .check input { accent-color: #fff; }
.consent-in a { color: #fff; }
.sign-doc { max-width: 980px; margin: 0 auto; padding: 24px 20px 120px; position: relative; }
.sign-doc .pages { max-width: none; }
.sfld { cursor: pointer; background: color-mix(in srgb, var(--c) 12%, #fff); }
.sfld.need { animation: none; }
.sfld.done { border-style: solid; background: transparent; border-color: color-mix(in srgb, var(--c) 40%, transparent); color: var(--ink); }
.sfld.current { outline: 2px solid var(--ink); outline-offset: 2px; }
.sfld img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sfld input[type='text'] { width: 100%; height: 100%; border: 0; background: transparent; padding: 0 4px; font: 400 12px/1 var(--sans); color: var(--ink); text-transform: none; letter-spacing: 0; }
.sfld input[type='text']:focus { outline: none; background: #fff; }
.sfld .auto { font: 400 12px/1 var(--sans); text-transform: none; letter-spacing: 0; color: var(--ink-2); padding: 0 4px; white-space: nowrap; overflow: hidden; width: 100%; }
.sfld.cb { cursor: pointer; }
.sfld.cb.done::after { content: ''; width: 60%; height: 60%; background: var(--ink); clip-path: polygon(14% 52%, 0 66%, 38% 100%, 100% 20%, 86% 6%, 38% 72%); }
.tag { position: absolute; left: -96px; width: 84px; height: 30px; background: var(--ink); color: #fff; font: 600 11px/30px var(--mono); letter-spacing: 0.1em; text-transform: uppercase; text-align: center; clip-path: polygon(0 0, 82% 0, 100% 50%, 82% 100%, 0 100%); cursor: pointer; transition: top 0.25s ease; z-index: 5; }
.center-card { max-width: 520px; margin: 60px auto; padding: 32px; text-align: left; }
.center-card .ic-big { width: 44px; height: 44px; border: 2px solid var(--ink); display: grid; place-items: center; margin-bottom: 18px; }
.center-card .ic-big.ok { border-color: var(--ok); color: var(--ok); }
.center-card .ic-big.bad { border-color: var(--bad); color: var(--bad); }

/* Adopt dialog */
.modal-back { position: fixed; inset: 0; background: rgba(10, 10, 10, 0.55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--paper); width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; border-radius: var(--radius); }
.modal-wide { width: min(760px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.adopt-grid { display: grid; grid-template-columns: 1fr 130px; gap: 12px; }
.styles { display: grid; gap: 8px; margin-top: 6px; }
.style-opt { display: grid; grid-template-columns: 22px 1fr 110px; align-items: center; gap: 12px; border: 1px solid var(--line-2); border-radius: var(--radius); padding: 10px 14px; cursor: pointer; }
.style-opt.on { border-color: var(--ink); }
.style-opt .sig { font-size: 30px; line-height: 1.2; color: #0f1f59; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.style-opt .ini { font-size: 26px; color: #0f1f59; text-align: right; white-space: nowrap; }
.pad-wrap { display: grid; grid-template-columns: 1fr 160px; gap: 12px; }
.pad { width: 100%; height: 150px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--paper); touch-action: none; display: block; }
.pad-base { position: relative; }
.pad-base::after { content: ''; position: absolute; left: 14px; right: 14px; bottom: 34px; border-bottom: 1px solid var(--line-2); pointer-events: none; }
.legal { font-size: 12px; color: var(--ink-3); margin-top: 14px; }

/* Detail */
.detail-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.r-item { display: grid; grid-template-columns: 4px 1fr auto; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.r-item:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { font: 500 11px/1.6 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.hash { font: 400 11px/1.4 var(--mono); color: var(--ink-3); overflow-wrap: anywhere; }
.chain-ok { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }

/* Outbox (preview) */
.outbox { position: fixed; right: 16px; bottom: 16px; width: min(420px, calc(100vw - 32px)); max-height: min(560px, calc(100vh - 100px)); overflow: auto; z-index: 60; }
.mail { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.mail:last-child { border-bottom: 0; }
.mail .to { font: 500 11px/1.4 var(--mono); color: var(--ink-3); }

.verify-drop { padding: 56px 20px; }
.result { margin-top: 18px; }
.result-head { display: flex; gap: 14px; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--radius); font-size: 14px; z-index: 200; transition: 0.2s ease; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-bad { background: var(--bad); }
.toast-ok { background: var(--ok); }

/* Embedded mode */
body.embed { background: var(--paper); }
body.embed .topbar { display: none; }
body.embed .sign-doc { padding-bottom: 40px; }

@media (max-width: 980px) {
  .prep { grid-template-columns: 1fr; }
  .prep-side { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .prep-side.right { border-left: 0; border-top: 1px solid var(--line); }
  .tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .rcp-row { grid-template-columns: 6px 54px 1fr 34px; }
  .rcp-row .rcp-email { grid-column: 3 / 4; }
  .rcp-row .rcp-role { grid-column: 3 / 4; }
  .rcp-extra { grid-column: 3 / -1; }
  .table .hide-sm { display: none; }
  .tag { left: 0; top: -36px; }
  .sign-doc { padding-top: 48px; }
  .adopt-grid, .pad-wrap { grid-template-columns: 1fr; }
  .style-opt { grid-template-columns: 22px 1fr; }
  .style-opt .ini { display: none; }
  .kv { grid-template-columns: 1fr; }
  .topbar { gap: 12px; padding: 0 12px; }
  .brand span { display: none; }
}
