@font-face {
  font-family: 'SignScript';
  src: url('/fonts/dancing-script-latin-600-normal.woff2') format('woff2');
  font-display: block;
}
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --line: #e3e6ec;
  --primary: #1d4ed8;
  --primary-ink: #ffffff;
  --primary-soft: #e8eefc;
  --danger: #dc2626;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
.center { text-align: center; padding: 60px 16px; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 50; height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 21c3-1 4-9 7-9s1 8 4 8 3-5 5-5 2 3 3 3' stroke='white' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center/100% no-repeat; }
#nav { display: flex; align-items: center; gap: 14px; font-size: 14px; }
#nav .who { color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 80px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f8f9fb; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: #1e40af; }
.btn.danger { color: var(--danger); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--primary); padding: 0 4px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

label.field { display: block; font-size: 13px; font-weight: 600; color: #374151; }
label.field > span { display: block; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=search], input[type=number], textarea, select {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid #cfd4dc; border-radius: 8px;
  font: inherit; font-size: 14px; background: #fff; color: var(--text);
}
textarea { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.code-input { font-size: 26px !important; letter-spacing: 10px; text-align: center; height: 54px !important; font-family: ui-monospace, monospace; }

.auth { max-width: 400px; margin: 50px auto; }
.auth .card { padding: 28px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef0f4; color: #4b5563; white-space: nowrap; }
.badge.sent, .badge.active { background: #fef3c7; color: #92400e; }
.badge.completed, .badge.signed { background: #dcfce7; color: #166534; }
.badge.declined, .badge.voided { background: #fee2e2; color: #991b1b; }
.badge.draft { background: #eef0f4; color: #4b5563; }
.badge.action { background: var(--primary); color: #fff; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.list td { padding: 12px 10px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #fafbfc; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.action-list { display: grid; gap: 10px; }
.action-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid #bfd0fb; background: var(--primary-soft); border-radius: 8px; }

.dropzone { border: 2px dashed #cbd2dd; border-radius: var(--radius); padding: 40px 20px; text-align: center; background: #fafbfc; cursor: pointer; }
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- document layout (editor / signer / viewer) */
.doc-layout > * { min-width: 0; }
.doc-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
.doc-side { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page-wrap { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); max-width: 100%; }
.page-wrap canvas { display: block; width: 100%; height: auto; }
.page-wrap .overlay { position: absolute; inset: 0; }
.page-num { font-size: 12px; color: var(--muted); margin-top: -12px; }
.placing .overlay { cursor: crosshair; }

.fld { position: absolute; border: 1.5px solid var(--c, #1d4ed8); background: color-mix(in srgb, var(--c, #1d4ed8) 14%, transparent); border-radius: 4px; font-size: 11px; color: #111; display: flex; align-items: center; justify-content: center; overflow: hidden; user-select: none; }
.fld .lbl { pointer-events: none; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; color: color-mix(in srgb, var(--c) 80%, black); }
.editor .fld { cursor: move; }
.editor .fld.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); z-index: 5; }
.fld .rs { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; background: var(--c); cursor: nwse-resize; border-radius: 3px 0 3px 0; }
.fld .x { position: absolute; top: -1px; right: -1px; width: 16px; height: 16px; line-height: 14px; text-align: center; background: var(--c); color: #fff; font-size: 13px; cursor: pointer; border-radius: 0 3px 0 3px; display: none; }
.editor .fld.sel .x { display: block; }
.fld.filled { background: transparent; border-color: transparent; }
.fld.filled img { max-width: 100%; max-height: 100%; }
.fld .val { font-size: var(--fs, 12px); color: #14205a; white-space: nowrap; overflow: hidden; padding: 0 2px; width: 100%; }
.fld.mine { cursor: pointer; border-style: solid; animation: none; }
.fld.mine.todo { background: rgba(250, 204, 21, .28); border-color: #ca8a04; }
.fld.mine.todo.req::after { content: '*'; position: absolute; top: -2px; left: 3px; color: var(--danger); font-weight: 700; }
.fld.mine.done { background: rgba(22, 163, 74, .07); border: 1px dashed #16a34a; }
.fld.mine.focus { box-shadow: 0 0 0 3px rgba(29, 78, 216, .45); }
.fld input.ftext { width: 100%; height: 100%; border: 0; background: transparent; font-size: var(--fs, 12px); padding: 0 3px; color: #14205a; outline: none; }
.fld input.fcheck { width: 80%; height: 80%; margin: 0; cursor: pointer; accent-color: var(--primary); }
.fld.other { border-style: dashed; opacity: .6; }

.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette button { height: 34px; border: 1px solid var(--line); background: #fff; border-radius: 7px; font: inherit; font-size: 13px; cursor: pointer; text-align: left; padding: 0 10px; }
.palette button:hover { border-color: var(--c); }
.palette button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.rcpt { border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px; padding: 10px; display: grid; gap: 6px; background: #fff; }
.rcpt.on { box-shadow: 0 0 0 2px var(--primary-soft); border-color: var(--primary); border-left-color: var(--c); }
.rcpt .r2 { display: grid; grid-template-columns: 1fr 64px; gap: 6px; }
.rcpt input { height: 32px; font-size: 13px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }

#signbar { position: sticky; top: 56px; z-index: 40; }
.signbar { background: #fffbea; border: 1px solid #f5d77a; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; box-shadow: var(--shadow); }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.consent input { margin-top: 4px; width: 18px; height: 18px; }

.timeline { display: grid; gap: 8px; }
.tl { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.tl .num { flex: none; width: 22px; height: 22px; border-radius: 50%; background: #eef0f4; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.tl .who { font-weight: 600; font-size: 14px; }
.tl .meta { font-size: 12px; color: var(--muted); word-break: break-all; }

table.audit { width: 100%; border-collapse: collapse; font-size: 13px; }
table.audit td, table.audit th { padding: 7px 8px; border-bottom: 1px solid #f0f1f4; text-align: left; vertical-align: top; }
table.audit th { color: var(--muted); font-size: 12px; }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); max-height: 92vh; overflow: auto; }
.sigpad { border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; position: relative; touch-action: none; }
.sigpad canvas { display: block; width: 100%; height: 180px; cursor: crosshair; }
.sigpad .base { position: absolute; left: 20px; right: 20px; bottom: 40px; border-bottom: 1px solid #d5d9e0; pointer-events: none; }
.typed-preview { font-family: 'SignScript', cursive; font-size: 44px; color: #14205a; text-align: center; padding: 20px 10px; border: 1px solid #cfd4dc; border-radius: 8px; min-height: 96px; white-space: nowrap; overflow: hidden; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 14px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 90vw; }
.toast.err { background: var(--danger); }

.verify-result { border-radius: 10px; padding: 14px 16px; border: 1px solid; }
.verify-result.good { background: #f0fdf4; border-color: #86efac; }
.verify-result.bad { background: #fef2f2; border-color: #fca5a5; }
.verify-result.info { background: #eff6ff; border-color: #bfdbfe; }
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; min-width: 0; }

@media (max-width: 860px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .doc-side { position: static; max-height: none; }
  main { padding: 16px 12px 80px; }
  .hide-sm { display: none; }
  dl.kv { grid-template-columns: 1fr; }
  #nav .who { display: none; }
}

/* ---------- admin */
.admin-banner { background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.admin-banner.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .v { font-size: 24px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 12px; background: var(--primary-soft); border: 1px solid #bfd0fb; border-radius: 8px; margin-bottom: 10px; }
table.list td.chk, table.list th.chk { width: 34px; padding-right: 0; }
table.list input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.filters select { width: auto; min-width: 160px; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.nowrap { white-space: nowrap; }
