:root {
  --bg: #f4f5f8; --surface: #fff; --ink: #111827; --muted: #6b7280; --line: #e3e6ec; --accent: #2f5bd3; --accent-ink: #fff;
  --accent-soft: #eef2fd; --good: #0f7a4a; --good-soft: #e7f6ee; --warn: #9a5b00; --warn-soft: #fff4e0; --bad: #b42318; --bad-soft: #fdecea;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --surface: #181c24; --ink: #e8eaf0; --muted: #9aa3b2; --line: #2a303c; --accent: #6d8ff0; --accent-soft: #1d2640;
    --good: #4cc38a; --good-soft: #13281f; --warn: #f0b155; --warn-soft: #2d2412; --bad: #f2786b; --bad-soft: #2f1715; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.55rem; line-height: 1.25; margin: .2rem 0 .8rem; }
h2 { font-size: 1.02rem; margin: 0 0 .6rem; }
code { font-size: .85em; word-break: break-all; }
.muted { color: var(--muted); } .small { font-size: .87rem; } .tiny { font-size: .78rem; }
.error { color: var(--bad); font-size: .9rem; min-height: 1em; }
.row { display: flex; align-items: center; } .gap { gap: .5rem; } .wrap { flex-wrap: wrap; } .grow { flex: 1 1 180px; } .end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: .85rem; }
.inline { display: inline; margin: 0; }
.center { text-align: center; }
ul.plain { list-style: none; padding: 0; margin: 0; } ul.plain li { padding: .25rem 0; }

header.site { display: flex; align-items: center; gap: 1.2rem; padding: .7rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.08rem; color: var(--ink); text-decoration: none; }
.top-nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.top-nav a { padding: .4rem .7rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.top-nav a.on, .top-nav a:hover { background: var(--accent-soft); color: var(--accent); }
.logout { margin-left: auto; }
.main { max-width: 980px; margin: 0 auto; padding: 1.4rem 16px 4rem; }
.main-wide { padding: 0 0 2rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.narrow { max-width: 460px; margin: 2.5rem auto; }
.flash { background: var(--good-soft); color: var(--good); border-radius: 8px; padding: .65rem .9rem; margin: 0 0 1rem; font-weight: 500; }
.flash.bad { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .92rem; }
label.check { display: block; font-weight: 400; }
label.check input { margin: 0 .45rem 0 0; vertical-align: -2px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%; min-width: 0; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.code-input { font-size: 1.5rem; letter-spacing: .3em; text-align: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .92rem; padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: .32rem .65rem; font-size: .84rem; }
.btn.big { padding: .8rem 1.4rem; font-size: 1rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; }
.danger-text { color: var(--bad); }

.pill { display: inline-block; font-size: .78rem; font-weight: 600; padding: .12rem .55rem; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill.sent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.me { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.completed { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.declined, .pill.voided { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.draft { background: var(--bg); }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .4rem; }

/* dashboard */
.dropzone { margin: 0; border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.3rem; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.busy { opacity: .7; pointer-events: none; }
.dz-inner { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.dz-inner > div:nth-child(2) { flex: 1 1 220px; }
.dz-icon { width: 46px; height: 46px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 1.3rem; }
.quick-templates { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; margin-top: .9rem; }
.chip { padding: .3rem .7rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); text-decoration: none; font-size: .86rem; font-weight: 500; }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; margin: 1.2rem 0 .6rem; }
.tabs { display: flex; gap: .2rem; flex-wrap: wrap; }
.tabs a { padding: .35rem .7rem; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: .9rem; font-weight: 500; }
.tabs a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.search input { width: 230px; max-width: 100%; }
.doc-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.doc-list li + li { border-top: 1px solid var(--line); }
.doc-row { display: flex; align-items: center; gap: 1rem; padding: .85rem 1.1rem; color: inherit; text-decoration: none; flex-wrap: wrap; }
a.doc-row:hover { background: var(--accent-soft); }
.doc-main { flex: 1 1 260px; display: flex; flex-direction: column; min-width: 0; }
.doc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; }
@media (max-width: 560px) { .doc-meta { align-items: flex-start; } }

/* document page */
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.doc-head h1 { margin-bottom: .2rem; }
.people { list-style: none; padding: 0; margin: 0; }
.people li { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; flex-wrap: wrap; }
.people li + li { border-top: 1px solid var(--line); }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c, var(--accent)); flex: none; display: inline-block; }
.trail { list-style: none; padding: 0; margin: 0; }
.trail li { display: flex; gap: .6rem; padding: .4rem 0; align-items: baseline; flex-wrap: wrap; font-size: .9rem; }
.trail .ev { width: 1.4rem; text-align: center; }
.actions details { margin-top: 1rem; }
.problems { border-color: var(--warn); background: var(--warn-soft); color: var(--ink); }
.problems ul { margin: .4rem 0 .8rem; padding-left: 1.2rem; }
.recipients-review ol { padding-left: 0; list-style: none; margin: 0 0 .6rem; }
.recipients-review ol.ordered { list-style: decimal; padding-left: 1.4rem; }
.recipients-review li { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; padding: .3rem 0; }
.recipients-review ol.ordered li { display: list-item; }
.role-row { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; display: flex; gap: .5rem; align-items: center; }
fieldset.role-row { display: block; }
fieldset.role-row legend { font-weight: 600; padding: 0 .3rem; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
@media (max-width: 640px) { .hide-sm { display: none; } }
.qr { display: flex; justify-content: center; margin: .5rem 0; } .qr svg { width: 210px; height: 210px; background: #fff; padding: 6px; border-radius: 8px; }
.steps { padding-left: 1.2rem; }
.verify { margin-top: 1rem; padding: .9rem 1rem; border-radius: 8px; }
.verify.ok { background: var(--good-soft); color: var(--good); }
.verify.bad { background: var(--bad-soft); color: var(--bad); }
.verify p { margin: .3rem 0 0; color: var(--ink); }
pre.mail { white-space: pre-wrap; font-size: .82rem; background: var(--bg); padding: .6rem; border-radius: 6px; }
.msg { margin: 0 0 1rem; padding: .7rem .9rem; border-left: 3px solid var(--accent); background: var(--accent-soft); white-space: pre-wrap; border-radius: 0 6px 6px 0; }
.disclosure { font-size: .9rem; background: var(--bg); padding: .2rem .9rem; border-radius: 8px; margin-bottom: 1rem; max-height: 300px; overflow: auto; }
.disclosure li { margin: .35rem 0; }
details.decline { margin-top: 1.2rem; }

/* the preparation screen */
.prep-top { display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 30; }
.prep-top .back { text-decoration: none; font-size: 1.3rem; color: var(--muted); }
.title-input { flex: 1 1 240px; font-size: 1.05rem; font-weight: 600; border-color: transparent; background: transparent; }
.title-input:hover { border-color: var(--line); }
.prep-actions { display: flex; gap: .5rem; margin-left: auto; align-items: center; }
#summary.warn { color: var(--warn); font-weight: 600; }
#prep-flash { margin: .6rem 1rem 0; }
.prep { display: grid; grid-template-columns: 320px 1fr; min-height: calc(100vh - 120px); }
.prep-side { border-right: 1px solid var(--line); background: var(--surface); padding: 1rem; display: flex; flex-direction: column; gap: 1.3rem; position: sticky; top: 56px; align-self: start; max-height: calc(100vh - 60px); overflow: auto; }
.prep-side h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.prep-main { position: relative; overflow: auto; padding: 1.2rem; }
@media (max-width: 860px) {
  .prep { grid-template-columns: 1fr; }
  .prep-side { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .prep-main { padding: .6rem; }
}
.signer { border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px; padding: .55rem .6rem; margin-bottom: .55rem; cursor: pointer; background: var(--surface); }
.signer.active { box-shadow: 0 0 0 2px var(--c); }
.signer-head { display: flex; align-items: center; gap: .4rem; }
.signer-head .role { border: 0; padding: .2rem .3rem; font-weight: 600; background: transparent; }
.signer-head .count { font-size: .75rem; color: var(--muted); background: var(--bg); border-radius: 999px; padding: 0 .45rem; }
.icon { background: none; border: 0; font-size: 1.1rem; color: var(--muted); cursor: pointer; padding: 0 .2rem; }
.signer-body { display: flex; flex-direction: column; gap: .35rem; margin-top: .35rem; }
.signer-body input { padding: .4rem .55rem; font-size: .9rem; }
.signer-actions { display: flex; gap: .7rem; flex-wrap: wrap; align-items: baseline; }
.signer-actions details summary { list-style: none; }
.code-box { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .35rem; }
.code-box input { flex: 1 1 120px; }
.me-line { font-size: .9rem; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.palette button { font: inherit; font-size: .86rem; text-align: left; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; }
.palette button.on, .palette button:hover { border-color: var(--accent); background: var(--accent-soft); }
.detect-status { font-size: .88rem; margin: 0 0 .6rem; color: var(--muted); }
.detect-status.ok { color: var(--good); } .detect-status.bad { color: var(--bad); }
.detect-status.busy::before { content: ""; display: inline-block; width: .8em; height: .8em; margin-right: .4em; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -.1em; }
@keyframes spin { to { transform: rotate(360deg); } }

.pages { display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.page { position: relative; width: 100%; max-width: 880px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); margin-bottom: 1rem; }
.page canvas { display: block; width: 100%; height: 100%; }
.page-num { font-size: .76rem; color: var(--muted); align-self: center; }
.pages.placing .page { cursor: crosshair; }
.field { position: absolute; border: 1.5px solid var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); border-radius: 3px; cursor: move; touch-action: none;
  display: flex; flex-direction: column; justify-content: center; padding: 0 4px; overflow: hidden; container-type: size; user-select: none; }
.field.found { border-style: dashed; }
.field.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); z-index: 5; }
.f-label { font-size: clamp(7px, 55cqh, 13px); font-weight: 700; color: var(--c); line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.f-who { font-size: clamp(6px, 30cqh, 10px); color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.1; }
.k-checkbox .f-who, .k-initial .f-who { display: none; }
.handle { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; background: var(--c); cursor: nwse-resize; border-radius: 2px 0 2px 0; }
.field-pop { position: absolute; z-index: 40; width: 280px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: .8rem; display: flex; flex-direction: column; gap: .5rem; }
.field-pop label { font-size: .82rem; }
.field-pop input, .field-pop select { padding: .35rem .5rem; font-size: .88rem; }
.pop-actions { display: flex; justify-content: space-between; }

/* the signing page */
body:has(.sign-bar) { background: #e9ebf0; }
.sign-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sign-bar.scrolled { box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.sb-left { display: flex; align-items: center; gap: .6rem; min-width: 0; flex: 1 1 260px; }
.sb-title { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-right { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
#finish.ready { animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px var(--accent-soft); } }
.sb-menu { position: relative; }
.sb-menu summary { list-style: none; }
.sb-menu .menu { position: absolute; right: 0; top: 110%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 180px; z-index: 50; }
.sb-menu .menu a { padding: .55rem .8rem; text-decoration: none; color: var(--ink); font-size: .9rem; }
.sb-menu .menu a:hover { background: var(--accent-soft); }
.sign-doc { padding: 1rem 12px 6rem; }
@media (max-width: 600px) { .sign-doc { padding: .5rem 4px 6rem; } .page { margin-bottom: .5rem; } }
.sf { position: absolute; border: 2px solid #e8a600; background: rgba(255, 214, 0, .28); border-radius: 3px; display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden; container-type: size; }
.sf .tag { font-size: clamp(7px, 50cqh, 14px); font-weight: 700; color: #8a5a00; }
.sf.filled { background: rgba(255,255,255,.4); border-color: rgba(47, 91, 211, .35); border-style: dashed; }
.sf img { max-width: 96%; max-height: 92%; }
.sf.auto { color: #14246b; font-size: clamp(7px, 60cqh, 14px); justify-content: flex-start; padding: 0 3px; cursor: default; white-space: nowrap; }
.sf.k-checkbox { font-size: clamp(8px, 80cqh, 18px); color: #14246b; font-weight: 700; }
.sf input { width: 100%; height: 100%; border: 0; background: transparent; padding: 0 3px; border-radius: 0; color: #14246b; }
.sf input:focus { outline: none; background: rgba(255,255,255,.6); }
.sf.pulse { animation: pulse 1s ease-in-out 3; box-shadow: 0 0 0 3px rgba(232, 166, 0, .6); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(232, 166, 0, .25); } }
.fixed { position: absolute; color: #14246b; font-size: clamp(7px, 1.2vw, 13px); display: flex; align-items: center; padding: 0 3px; white-space: nowrap; overflow: hidden; pointer-events: none; }

.dialog { border: 0; border-radius: 12px; padding: 1.2rem 1.3rem; width: min(560px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dialog::backdrop { background: rgba(15, 18, 24, .5); }
.init-field { flex: 0 0 90px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: .8rem 0; }
.seg button { font: inherit; padding: .4rem 1rem; border: 0; background: var(--surface); color: var(--ink); cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.previews { display: flex; gap: .6rem; flex-wrap: wrap; }
.preview { flex: 1 1 260px; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; min-height: 90px; display: flex; flex-direction: column; background: #fff; }
.preview.small-prev { flex: 0 1 140px; }
.preview img { max-height: 70px; max-width: 100%; object-fit: contain; align-self: flex-start; }
.pad-wrap { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .6rem; }
.pad { width: 100%; aspect-ratio: 900 / 260; border: 1px dashed var(--muted); border-radius: 8px; background: #fff; touch-action: none; }
.small-pad .pad { width: 180px; aspect-ratio: 360 / 200; }
.pad-wrap .link { align-self: flex-start; }

/* signature styles in the adopt dialog */
.style-list { display: flex; flex-direction: column; gap: .4rem; max-height: 46vh; overflow: auto; }
.style-opt { display: flex; align-items: center; gap: .8rem; width: 100%; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; text-align: left; font: inherit; }
.style-opt.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.style-opt .so-sig { height: 44px; max-width: 62%; object-fit: contain; }
.style-opt .so-init { height: 34px; max-width: 18%; object-fit: contain; }
.style-opt .so-label { margin-left: auto; font-size: .78rem; color: #6b7280; }

/* the AI summary */
.ai-offer { border: 1px dashed var(--line); border-radius: 8px; padding: .7rem .8rem; display: flex; flex-direction: column; gap: .45rem; align-items: flex-start; }
.ai-btn { white-space: nowrap; }
.wide-dialog { width: min(720px, calc(100vw - 24px)); max-height: 88vh; overflow: auto; }
.ai-notice { background: var(--warn-soft); border-radius: 8px; padding: .3rem .9rem; font-size: .9rem; margin-bottom: .8rem; }
.ai-notice p { margin: .5rem 0; }
.summary-box { margin-top: .8rem; width: 100%; }
.summary-box h3 { font-size: .95rem; margin: 1rem 0 .3rem; }
.ai-label { background: var(--accent-soft); color: var(--ink); border-left: 3px solid var(--accent); padding: .5rem .7rem; border-radius: 0 6px 6px 0; font-size: .86rem; margin-bottom: .6rem; }
.sum-overview { font-size: .98rem; }
.sum-list { margin: 0; padding-left: 1.1rem; }
.sum-list li { margin: .3rem 0; }
.page-refs { display: inline-flex; gap: .25rem; flex-wrap: wrap; }
.page-ref { font: inherit; font-size: .74rem; padding: 0 .4rem; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--accent); cursor: pointer; }
span.page-ref { cursor: default; color: var(--muted); }
.sum-foot { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .4rem; font-size: .78rem; color: var(--muted); }
.sum-foot p { margin: .3rem 0; }
.summary-details { margin-top: 1rem; }
