:root {
  --blue: #2457F5;
  --blue-dark: #1A44C8;
  --blue-soft: #E6ECFF;
  --ink: #111827;
  --muted: #6B7280;
  --line: #E5E7EB;
  --paper: #F7F5F0;
  --white: #FFFFFF;
  --green: #15803D;
  --green-soft: #DCFCE7;
  --amber: #B45309;
  --amber-soft: #FEF3C7;
  --red: #B91C1C;
  --red-soft: #FEE2E2;
  --s1: #2457F5; --s2: #0F9D8A; --s3: #C2410C; --s4: #7C3AED; --s5: #BE185D; --s6: #0369A1;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
p { margin: 0 0 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 8px; padding: 10px 16px; font-weight: 600; background: var(--white); color: var(--ink); border-color: var(--line); transition: background .15s, border-color .15s; }
.btn:hover { background: #F3F4F6; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--blue); color: var(--white); border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 6px; }
.btn-block { width: 100%; justify-content: center; }
.input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--white); outline: none; }
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.input-sm { padding: 7px 10px; font-size: 13px; border-radius: 6px; }
label.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; background: var(--white); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .logo img { height: 32px; display: block; }
.topbar .right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 32px 24px; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #F3F4F6; color: var(--muted); }
.pill.draft { background: #F3F4F6; color: var(--muted); }
.pill.sent, .pill.waiting { background: var(--amber-soft); color: var(--amber); }
.pill.completed, .pill.signed { background: var(--green-soft); color: var(--green); }
.pill.voided { background: var(--red-soft); color: var(--red); }
.pill.pending { background: #F3F4F6; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--red); font-size: 13px; margin-top: 8px; }
.ok { color: var(--green); font-size: 13px; margin-top: 8px; }
.notice { background: var(--amber-soft); color: var(--amber); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin: 12px 0; word-break: break-all; }
.notice a { color: inherit; font-weight: 600; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); }
table.list td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.row:hover td { background: #FAFAFA; cursor: pointer; }
.drop { border: 2px dashed #CBD5E1; border-radius: 12px; padding: 32px; text-align: center; background: var(--white); transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--blue); background: var(--blue-soft); }
.drop input[type=file] { display: none; }

.editor { display: grid; grid-template-columns: 1fr 340px; min-height: calc(100vh - 61px); }
.pages { padding: 24px; overflow: auto; background: #E9E7E1; }
.page-wrap { position: relative; margin: 0 auto 20px; background: var(--white); box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 8px 24px rgba(0,0,0,.06); }
.page-wrap canvas { display: block; width: 100%; height: auto; }
.page-wrap .overlay { position: absolute; inset: 0; }
.page-wrap .overlay.placing { cursor: crosshair; }
.side { background: var(--white); border-left: 1px solid var(--line); padding: 20px; overflow: auto; position: sticky; top: 61px; height: calc(100vh - 61px); }
.side section { margin-bottom: 24px; }
.side h3 { margin-bottom: 10px; }
.signer-row { display: grid; grid-template-columns: 10px 1fr 1fr 24px; gap: 6px; align-items: center; margin-bottom: 6px; }
.signer-row .dot { width: 10px; height: 10px; border-radius: 50%; }
.signer-row button { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 0; }
.signer-row button:hover { color: var(--red); }
.palette { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.palette .btn { justify-content: center; }
.palette .btn.active { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }
.fld { position: absolute; border: 1.5px solid var(--c, var(--blue)); background: color-mix(in srgb, var(--c, var(--blue)) 14%, transparent); border-radius: 3px; font-size: 11px; font-weight: 600; color: var(--c, var(--blue)); display: flex; align-items: flex-end; padding: 2px 4px; overflow: hidden; white-space: nowrap; user-select: none; }
.fld.editable { cursor: move; }
.fld.selected { box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--c, var(--blue)); z-index: 2; }
.fld.unassigned { --c: #9CA3AF; border-style: dashed; }
.fld .rs { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; background: var(--c, var(--blue)); cursor: nwse-resize; border-radius: 2px 0 0 0; }
.fld img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: left bottom; }
.fld .val { position: absolute; inset: 0; display: flex; align-items: flex-end; padding: 0 4px 2px; color: var(--ink); font-weight: 500; font-family: Helvetica, Arial, sans-serif; }
.fld.mine { cursor: pointer; animation: pulse 1.6s ease-in-out infinite; }
.fld.mine.done { animation: none; background: color-mix(in srgb, var(--c, var(--blue)) 6%, transparent); }
.fld.other { pointer-events: none; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c, var(--blue)) 40%, transparent);} 50% { box-shadow: 0 0 0 5px transparent; } }
.field-props .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.events { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.events li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.events li span:last-child { color: var(--muted); white-space: nowrap; }
.signers-status { list-style: none; margin: 0; padding: 0; }
.signers-status li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.signers-status li .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.signers-status li .who { flex: 1; min-width: 0; }
.signers-status li .who div:last-child { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--white); border-radius: 14px; padding: 20px; width: 560px; max-width: 100%; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 8px 12px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); }
.sigpad { border: 1px solid var(--line); border-radius: 10px; background: #FAFAFA; position: relative; }
.sigpad canvas { display: block; width: 100%; height: 200px; touch-action: none; }
.sigpad .base { position: absolute; left: 24px; right: 24px; bottom: 44px; border-top: 1px solid #CBD5E1; pointer-events: none; }
.typed { font-family: "Caveat", "Segoe Script", "Brush Script MT", cursive; font-size: 44px; padding: 20px; min-height: 120px; border: 1px solid var(--line); border-radius: 10px; background: #FAFAFA; display: flex; align-items: center; }
.modal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }

.signbar { position: sticky; bottom: 0; background: var(--white); border-top: 1px solid var(--line); padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; z-index: 20; }
.signbar label { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.progress { font-size: 13px; color: var(--muted); }
.center { max-width: 480px; margin: 48px auto; padding: 0 24px; }
.code-input { font-size: 28px; letter-spacing: 10px; text-align: center; font-family: Menlo, Consolas, monospace; }
.hero { max-width: 520px; margin: 72px auto 0; padding: 0 24px; }
.hero h1 { font-size: 40px; margin: 28px 0 12px; letter-spacing: -0.02em; }
.hero p.lead { font-size: 18px; color: var(--muted); margin-bottom: 28px; }
@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); }
}
