:root {
  --ink: #1b1f2a; --muted: #636b7c; --line: #dfe3ea; --bg: #f5f6f9; --card: #fff;
  --accent: #4338ca; --accent-ink: #fff; --danger: #b42318; --good: #0f7a4a; --warn: #a15c00;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 24px; margin: 0 0 6px; line-height: 1.25; }
h2 { font-size: 16px; margin: 26px 0 8px; }
code { font: 12px/1.4 ui-monospace, Consolas, monospace; word-break: break-all; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; }
.top nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.top nav a { text-decoration: none; }
.who { color: var(--muted); }
main { max-width: 980px; margin: 28px auto; padding: 0 20px; }
body.wide main { max-width: 1400px; margin-top: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 26px; }
.narrow { max-width: 520px; margin: 30px auto; }
.center { text-align: center; }
.empty { padding: 48px 24px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.wrap { word-break: break-all; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.actions { margin: 16px 0 4px; }
form.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; }

label { display: block; margin: 12px 0; font-weight: 600; font-size: 13px; }
label small { font-weight: 400; color: var(--muted); }
input:not([type=checkbox]):not([type=file]), textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; color: inherit; background: #fff; border: 1px solid #c3c9d4; border-radius: 6px; }
form.inline input { width: 220px; margin: 0; }
input:focus-visible, textarea:focus-visible, button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 14px; }
label.check input { margin-top: 4px; }

.btn { display: inline-block; padding: 8px 16px; font: inherit; font-weight: 600; color: var(--ink); background: #fff; border: 1px solid #c3c9d4; border-radius: 6px; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f1f2f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #372fa8; }
.btn.danger { color: var(--danger); border-color: #e3b4ae; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
button.link.danger { color: var(--danger); margin-top: 14px; font-size: 13px; }

.flash { max-width: 980px; margin: 14px auto 0; padding: 0 20px; }
.flash p { margin: 0 0 6px; padding: 10px 14px; background: #fff7e0; border: 1px solid #ecd590; border-radius: 6px; }
.notice { padding: 10px 14px; background: #eef2ff; border: 1px solid #c7d0fb; border-radius: 6px; }
blockquote { margin: 12px 0; padding: 8px 14px; border-left: 3px solid var(--line); color: var(--muted); white-space: pre-wrap; }

table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.list th, table.list td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; }
table.list tr:last-child td { border-bottom: 0; }
table.list.small td { font-size: 13px; }
table.list td.right { text-align: right; }
tr.linkrow td { padding-top: 0; font-size: 13px; }
table.kv { border-collapse: collapse; margin-top: 12px; }
table.kv th { text-align: left; padding: 4px 16px 4px 0; font-size: 13px; color: var(--muted); font-weight: 600; vertical-align: top; white-space: nowrap; }
table.kv td { padding: 4px 0; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #e8eaf0; color: #414857; white-space: nowrap; }
.pill.big { font-size: 14px; padding: 5px 14px; }
.pill.completed, .pill.signed { background: #dcf5e8; color: var(--good); }
.pill.sent, .pill.viewed { background: #e4e7ff; color: #3730a3; }
.pill.declined, .pill.voided, .pill.expired { background: #fde4e1; color: var(--danger); }

.verdict { margin: 18px 0 6px; padding: 12px 14px; border-radius: 6px; }
.verdict.good { background: #dcf5e8; color: #0b5c38; }
.verdict.warn { background: #fff1d6; color: var(--warn); }
.verdict.bad { background: #fde4e1; color: var(--danger); }

/* ---------- editor and signing pages ---------- */
.editor { display: grid; grid-template-columns: 330px 1fr; gap: 20px; align-items: start; }
.panel { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px 18px 18px; }
.panel h2 { margin-top: 18px; }
.panel p { margin: 6px 0; font-size: 13px; }
.signer { --c: var(--accent); display: flex; gap: 8px; align-items: center; padding: 8px; margin-bottom: 8px; border: 2px solid var(--line); border-radius: 8px; cursor: pointer; }
.signer.active { border-color: var(--c); background: color-mix(in srgb, var(--c) 7%, #fff); }
.signer .dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.signer .inputs { flex: 1; min-width: 0; }
.signer input { margin: 2px 0 !important; padding: 5px 8px !important; font-size: 13px !important; }
.signer .x { flex: none; width: 26px; height: 26px; border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; border-radius: 4px; }
.signer .x:hover { background: #eee; color: var(--danger); }
.palette { --c: var(--accent); display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette button { padding: 8px; font: inherit; font-size: 13px; font-weight: 600; background: #fff; border: 1px solid #c3c9d4; border-left: 5px solid var(--c); border-radius: 6px; cursor: pointer; text-align: left; }
.palette button.armed { background: var(--c); border-color: var(--c); color: #fff; }
.props { margin-top: 12px; padding: 10px 12px; background: #f6f7fa; border-radius: 8px; font-size: 13px; }
.props label { margin: 8px 0; }

.pages { min-width: 0; }
.page { position: relative; max-width: 900px; margin: 0 auto; background: #fff; box-shadow: 0 1px 4px rgba(20, 25, 40, .18); line-height: 0; user-select: none; }
.page img { width: 100%; height: auto; display: block; }
.page-no { text-align: center; font-size: 12px; color: var(--muted); margin: 6px 0 22px; }
.layer { position: absolute; inset: 0; line-height: 1.2; }
body.placing .page { cursor: crosshair; }

.field { --c: var(--accent); position: absolute; display: flex; align-items: center; justify-content: center; overflow: hidden; font-size: 12px; font-weight: 600; color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); border: 1.5px solid var(--c); border-radius: 3px; cursor: move; touch-action: none; }
.field.selected { outline: 2px solid var(--c); outline-offset: 2px; }
.field span { pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.field .grip { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; background: var(--c); border-radius: 3px 0 2px 0; cursor: nwse-resize; }

.signbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; max-width: 900px; margin: 0 auto 14px; padding: 10px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 8px rgba(20, 25, 40, .08); }
#signing > .error { max-width: 900px; margin: 0 auto 12px; }
.field.fill { cursor: default; background: #fff8d6; border-color: #caa400; color: #5d4a00; touch-action: auto; }
.field.fill.required:not(.done) { box-shadow: 0 0 0 2px rgba(202, 164, 0, .35); }
.field.fill.done { background: transparent; border-color: transparent; box-shadow: none; }
.field.fill.done:hover { border-color: #b9c0cc; }
.field.fill.pulse { animation: pulse .6s 2; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(67, 56, 202, .45); } }
.field.fill button { width: 100%; height: 100%; padding: 0; font: inherit; font-weight: 700; color: inherit; background: none; border: 0; cursor: pointer; }
.field.fill button img { width: 100%; height: 100%; object-fit: contain; object-position: left bottom; display: block; }
.field.fill input[type=text] { width: 100%; height: 100%; margin: 0; padding: 0 3px; font-size: clamp(9px, 1.25vw, 14px); border: 0; border-radius: 0; background: transparent; color: #111; }
.field.fill input[type=checkbox] { width: 100%; height: 100%; margin: 0; cursor: pointer; }

.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(20, 24, 38, .55); }
.dialog { width: 100%; max-width: 560px; background: #fff; border-radius: 12px; padding: 20px 22px; }
.dialog h2 { margin-top: 0; font-size: 18px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs button { padding: 6px 16px; font: inherit; font-weight: 600; background: #eef0f4; border: 0; border-radius: 6px; cursor: pointer; }
.tabs button.on { background: var(--accent); color: #fff; }
#pad, #typed-preview { width: 100%; height: auto; aspect-ratio: 3 / 1; border: 1px dashed #9aa2b1; border-radius: 8px; background: #fbfbfd; touch-action: none; display: block; }
#pad { cursor: crosshair; }
#typed { margin-bottom: 8px !important; }

@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .top { padding: 10px 14px; }
  main { padding: 0 10px; }
}
