:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e5ea;
  --accent: #1d4ed8;
  --accent-soft: #e8eefc;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --danger: #b91c1c;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.noscroll { overflow: hidden; }
h1 { font-size: 20px; line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 650; }
a { color: var(--accent); text-decoration: none; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; }
.error { color: var(--danger); font-size: 13px; min-height: 0; }
.error:empty { display: none; }
.loading { color: var(--muted); padding: 32px 16px; text-align: center; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: 50px; padding: 0 16px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
.brand .logo { display: inline-flex; width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: #fff; align-items: center; justify-content: center; }
.brand.big { font-size: 20px; margin-bottom: 2px; }
.brand.big .logo { width: 32px; height: 32px; }
.doc-title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; padding-left: 10px; border-left: 1px solid var(--line); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: 6px;
  border: 1px solid #d4d7de; background: #fff; color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: #f7f8fa; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1e40af; }
.btn.primary:disabled:hover { background: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f2f4; color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.done { background: var(--ok-soft); border-color: #b7e0c3; color: var(--ok); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 44px; font-size: 15px; padding: 0 20px; }
.btn.block { display: flex; width: 100%; }
.linkbtn { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 2px 0; }
.iconbtn { width: 28px; height: 28px; border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; border-radius: 6px; flex: none; }
.iconbtn:hover { background: #f1f2f4; color: var(--danger); }
.iconbtn-space { width: 28px; flex: none; }
.input {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid #d4d7de; border-radius: 6px; background: #fff;
  font: inherit; color: var(--text);
}
.input:focus { outline: 2px solid rgba(29, 78, 216, .25); border-color: var(--accent); }
.input.sm { height: 28px; font-size: 13px; }
.input.link { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; color: #374151; background: #fafbfc; }
select.input { padding-right: 6px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-top: 4px; }
.check input { width: 16px; height: 16px; margin: 0; }

/* ---------- admin layout ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 18px 16px 48px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; }
.card.pad { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 12px; }
.head h1 + .muted { margin-top: 3px; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.back:hover { color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.notice { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13.5px; }
.notice.ok { background: var(--ok-soft); color: #14532d; border: 1px solid #c3e6cd; }
.notice.error { background: #fdecec; color: var(--danger); border: 1px solid #f5c2c2; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 330px; padding: 24px; display: flex; flex-direction: column; gap: 10px; }
.login p { margin: 0 0 6px; }

.list .row { display: flex; align-items: center; gap: 14px; padding: 11px 14px; border-bottom: 1px solid var(--line); color: inherit; }
.list .row:last-child { border-bottom: 0; }
.list .row:hover { background: #fafbfc; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; max-width: 45%; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #f1f2f4; color: #4b5563; white-space: nowrap; }
.chip.signed { background: var(--ok-soft); color: #14532d; }
.chev { color: #9ca3af; display: inline-flex; }
.empty { padding: 30px 16px; text-align: center; }
.empty p { margin: 0 0 8px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.wait { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: #eef0f3; color: var(--muted); }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.wait { background: #f1f2f4; color: var(--muted); }
.pill.seen { background: var(--accent-soft); color: var(--accent); }

.srow { padding: 11px 14px; border-bottom: 1px solid var(--line); }
.srow:last-child { border-bottom: 0; }
.sname { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.linkline { display: flex; gap: 6px; margin-top: 8px; }
.linkline .input { height: 28px; }
.events { list-style: none; margin: 0; padding: 6px 14px 10px; }
.events li { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.events li:last-child { border-bottom: 0; }
.events .when { color: var(--muted); min-width: 220px; font-variant-numeric: tabular-nums; }

.form { display: flex; flex-direction: column; gap: 8px; max-width: 640px; }
.label { font-weight: 600; font-size: 13px; margin-top: 8px; }
.label:first-child { margin-top: 0; }
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 96px; padding: 16px; border: 1.5px dashed #c8ccd4; border-radius: 8px; background: #fafbfc;
  cursor: pointer; text-align: center;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.has { border-style: solid; border-color: #b7e0c3; background: var(--ok-soft); }
.signer-edit { display: flex; flex-direction: column; gap: 6px; }
.srow-edit { display: flex; align-items: center; gap: 6px; }
.srow-edit .input:nth-of-type(1) { flex: 1.3; }
.srow-edit .input:nth-of-type(2) { flex: 1; }
.form > .btn.sm { align-self: flex-start; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

/* ---------- editor ---------- */
.admin .wrap:has(.editor) { max-width: 1280px; }
.editor { display: grid; grid-template-columns: 270px 1fr; gap: 16px; align-items: start; }
.side { position: sticky; top: 64px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: calc(100vh - 80px); overflow: auto; }
.side-sec { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 7px; }
.side-sec:last-child { border-bottom: 0; }
.side-title { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.side-title.mt { margin-top: 4px; }
.who { display: flex; flex-direction: column; gap: 4px; }
.who-btn { display: flex; align-items: center; gap: 8px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font: inherit; cursor: pointer; text-align: left; }
.who-btn.on { border-color: var(--c); box-shadow: inset 3px 0 0 var(--c); background: #fafbff; font-weight: 600; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.tools:has(> :only-child) { grid-template-columns: 1fr; }
.tool { padding: 7px 8px; border: 1px solid color-mix(in srgb, var(--c) 45%, white); border-radius: 6px; background: color-mix(in srgb, var(--c) 7%, white); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; text-align: left; }
.tool:hover { background: color-mix(in srgb, var(--c) 14%, white); }
.tool.on { background: var(--c); color: #fff; border-color: var(--c); }
.hint { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.hint.live { color: var(--accent); font-weight: 600; }
.row-inline { display: flex; align-items: center; gap: 8px; }
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.checklist li::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.checklist li.ok::before { background: #16a34a; }
.checklist li.todo { color: var(--warn); }
.checklist li.todo::before { background: #f59e0b; }
.actions-col { gap: 8px; }

.editor-main { min-width: 0; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.page { position: relative; width: 100%; max-width: 900px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 4px 14px rgba(0,0,0,.06); container-type: inline-size; }
.page-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.overlay { position: absolute; inset: 0; }
.overlay.placing { cursor: crosshair; background: rgba(29, 78, 216, .03); }

.efield {
  position: absolute; border: 1.5px solid var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
  border-radius: 3px; cursor: move; touch-action: none; user-select: none;
  font-size: clamp(8px, 1.45cqw, 12px); color: color-mix(in srgb, var(--c) 80%, black);
  display: flex; align-items: center; padding: 0 4px; overflow: visible;
}
.efield.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); z-index: 2; }
.efield .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; pointer-events: none; }
.efield .lbl em { font-style: normal; font-weight: 400; opacity: .85; }
.efield .x {
  position: absolute; top: -9px; right: -9px; width: 18px; height: 18px; border-radius: 50%;
  border: 0; background: var(--c); color: #fff; font-size: 13px; line-height: 18px; padding: 0; cursor: pointer; display: none;
}
.efield.sel .x, .efield:hover .x { display: block; }
.efield .rs { position: absolute; right: -5px; bottom: -5px; width: 11px; height: 11px; background: #fff; border: 1.5px solid var(--c); border-radius: 2px; cursor: nwse-resize; }

/* ---------- signer page ---------- */
.sign-main { max-width: 940px; margin: 0 auto; padding: 16px 12px 60px; }
.center-card { max-width: 520px; margin: 28px auto; padding: 24px 22px; }
.center-card h1 { margin: 2px 0 8px; }
.eyebrow { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.lead { font-size: 15px; color: #374151; margin: 0 0 16px; }
.lead.small { font-size: 14px; }
.label-sm { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.signer-list { list-style: none; margin: 0 0 18px; padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.signer-list li { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.signer-list li:last-child { border-bottom: 0; }
.signer-list .nm { font-weight: 600; }
.signer-list .you { font-weight: 400; color: var(--muted); }
.signer-list .role { color: var(--muted); font-size: 13px; }
.signer-list .pill { margin-left: auto; }
.consent { display: flex; gap: 10px; align-items: flex-start; padding: 12px; background: #f8f9fb; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 14px; cursor: pointer; font-size: 13.5px; color: #374151; }
.consent input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; }
.fine { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.bigcheck { width: 54px; height: 54px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }

.signbar {
  position: sticky; top: 50px; z-index: 15;
  display: flex; align-items: center; gap: 8px;
  margin: -16px -12px 16px; padding: 9px 12px;
  background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.progress { font-size: 13.5px; font-weight: 600; color: #374151; }
.btn.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(29,78,216,.45); } 50% { box-shadow: 0 0 0 7px rgba(29,78,216,0); } }

.sfield {
  position: absolute; display: flex; align-items: center; padding: 0 3px; border-radius: 3px;
  font-size: clamp(7px, 1.7cqw, 15px); overflow: hidden; font-family: Helvetica, Arial, sans-serif;
}
.sfield.other { border: 1px dashed #b6bcc6; background: rgba(241, 242, 244, .55); color: #8a919c; font-size: clamp(6px, 1.25cqw, 11px); font-family: inherit; }
.sfield.other span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sfield.mine { border: 1.5px solid #f59e0b; background: rgba(254, 243, 199, .85); color: #0f1c4d; }
.sfield.sig { cursor: pointer; justify-content: center; font: inherit; font-size: clamp(9px, 1.9cqw, 15px); padding: 0; }
.sfield.sig .tag { font-weight: 700; color: #92400e; letter-spacing: .01em; }
.sfield.sig:hover { background: rgba(253, 230, 138, .95); }
.sfield.sig.filled { background: rgba(236, 253, 243, .5); border-color: #86d5a4; justify-content: flex-start; align-items: flex-end; }
.sfield.sig img { width: 100%; height: 100%; object-fit: contain; object-position: left bottom; }
.sfield.auto { background: rgba(236, 253, 243, .6); border-color: #86d5a4; }
.sfield.text { padding: 0; }
.val { white-space: nowrap; overflow: hidden; }
.val-input { width: 100%; height: 100%; border: 0; background: transparent; font: inherit; color: inherit; padding: 0 3px; }
.val-input:focus { outline: 2px solid #f59e0b; }
.sfield.flash { animation: flash .9s ease-in-out 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 5px rgba(245, 158, 11, .5); } }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 100; max-width: calc(100% - 32px); background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(17, 24, 39, .45); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 24px); overflow: auto; background: #fff; border-radius: 12px; padding: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 12px; }
.modal .fine { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { border: 0; background: none; font: inherit; font-weight: 600; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.pane { display: flex; flex-direction: column; gap: 8px; }
.sigpad { position: relative; height: 190px; border: 1px solid #d4d7de; border-radius: 8px; background: #fcfcfd; }
.pad-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; z-index: 2; }
.pad-line { position: absolute; left: 22px; right: 22px; bottom: 44px; border-bottom: 1px solid #c8ccd4; }
.pad-hint { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; color: #a0a6b1; font-size: 13px; }
.sigpad.has-ink .pad-hint { display: none; }
.pad-tools { display: flex; justify-content: flex-end; }
.font-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.font-opt { height: 74px; border: 1px solid #d4d7de; border-radius: 8px; background: #fff; cursor: pointer; overflow: hidden; padding: 0 10px; color: #0f1c4d; }
.font-opt span { font-size: 30px; white-space: nowrap; display: block; overflow: hidden; text-overflow: ellipsis; }
.font-opt.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(29,78,216,.25); }

@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .chips { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .doc-title { display: none; }
  .signbar .progress { font-size: 12.5px; }
  .signbar .btn { padding: 0 10px; }
  .center-card { margin: 12px auto; padding: 20px 16px; }
  .font-grid { grid-template-columns: 1fr; }
  .font-opt { height: 60px; }
  .events .when { min-width: 0; width: 100%; }
  .linkline { flex-wrap: wrap; }
  .linkline .input { flex-basis: 100%; }
}

/* ---------- log in / create account ---------- */
.login .brand.big { justify-content: center; }
.tagline { text-align: center; color: var(--muted); font-size: 13.5px; margin: 2px 0 6px; }
.auth-tabs { display: flex; border: 1px solid var(--line); border-radius: 7px; padding: 3px; gap: 3px; margin-bottom: 4px; }
.auth-tab { flex: 1; text-align: center; padding: 6px 0; border-radius: 5px; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.auth-tab.on { background: var(--accent-soft); color: var(--accent); }
.login { max-width: 360px; }
.form h2 { margin-bottom: 2px; }

.btn.icon { padding: 0 7px; }
.btn.icon svg { display: block; }
