:root {
  --navy: #17325c;
  --navy-2: #22457a;
  --green: #2f8f5b;
  --green-dark: #24724a;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --line: #dbe1e9;
  --text: #1b2635;
  --muted: #5b6778;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn: #8a4b00;
  --warn-bg: #fff4e0;
  --ok-bg: #e8f5ee;
  --info-bg: #e9f0fa;
  --focus: #3b82f6;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--navy-2); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .5rem; color: var(--navy); }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; color: var(--navy); }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; word-break: break-all; }

/* ---------- top bar ---------- */
.devbar { background: #b42318; color: #fff; text-align: center; font-weight: 600; padding: .35rem; font-size: .85rem; }
.topbar { background: var(--navy); color: #fff; }
.topbar .inner { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.25rem; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; text-decoration: none; letter-spacing: .01em; }
.brand span { color: #8fd3ad; }
.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a { color: #d6e0ee; text-decoration: none; padding: .35rem .7rem; border-radius: 6px; font-size: .92rem; }
.nav a:hover, .nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.who { display: flex; align-items: center; gap: .75rem; font-size: .85rem; color: #d6e0ee; }
.who form { margin: 0; }
.linkbtn { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }

.page { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel.tight { padding: 0; overflow: hidden; }
.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- flashes & notices ---------- */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.flash.success { background: var(--ok-bg); border-color: #bfe3cf; }
.flash.error { background: var(--danger-bg); border-color: #f5c2bc; color: #7a1a12; }
.flash.info { background: var(--info-bg); border-color: #c8d8ef; }
.notice { background: var(--warn-bg); border: 1px solid #f3d29a; color: var(--warn); padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem 1.1rem; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 42px; }
.btn:hover { border-color: #b9c3d0; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f0c4bf; }
.btn.block { width: 100%; }
.btn.sm { padding: .3rem .7rem; min-height: 32px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

/* ---------- forms ---------- */
.field { margin-bottom: 1rem; }
.field label, .label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field .hint { color: var(--muted); font-size: .85rem; margin: .25rem 0 0; }
.field .err { color: var(--danger); font-size: .88rem; margin: .3rem 0 0; font-weight: 600; }
.field.bad input, .field.bad select, .field.bad textarea { border-color: var(--danger); }
input[type=text], input[type=email], input[type=number], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid #c4ccd7; border-radius: 6px; font: inherit; background: #fff; color: var(--text); min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input[type=file] { padding: .45rem; }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline input, .inline select { width: auto; flex: 1 1 160px; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: .15rem; flex: none; accent-color: var(--green); }

/* ---------- tables ---------- */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: .6rem .9rem; border-bottom: 1px solid var(--line); background: #f8fafc; }
table.list td { padding: .7rem .9rem; border-bottom: 1px solid #edf0f4; vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.rowlink { cursor: pointer; }
table.list tr.rowlink:hover td { background: #f7f9fc; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
@media (max-width: 720px) {
  table.list.stack thead { display: none; }
  table.list.stack tr { display: block; border-bottom: 1px solid var(--line); padding: .5rem 0; }
  table.list.stack td { display: block; border: 0; padding: .15rem .9rem; }
}

/* ---------- tabs & status ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 0; padding: 0 .5rem; flex-wrap: wrap; background: #f8fafc; }
.tabs a { padding: .7rem .9rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--navy); border-color: var(--green); }
.count { display: inline-block; min-width: 1.4rem; padding: 0 .4rem; border-radius: 999px; background: #e3e8ef; font-size: .75rem; text-align: center; margin-left: .3rem; }
.tabs a.on .count.alert, .count.alert { background: var(--green); color: #fff; }
.status { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e3e8ef; color: #334155; white-space: nowrap; }
.status.sent, .status.opened { background: var(--info-bg); color: #1e4a8a; }
.status.completed { background: var(--warn-bg); color: var(--warn); }
.status.archived, .status.purged { background: var(--ok-bg); color: #1d6b43; }
.status.cancelled, .status.expired { background: #eef0f3; color: #5b6778; }
.searchbar { display: flex; gap: .5rem; padding: .9rem; border-bottom: 1px solid var(--line); }
.searchbar input { max-width: 360px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: .7rem .9rem; border-top: 1px solid var(--line); font-size: .9rem; }

/* ---------- detail ---------- */
dl.facts { display: grid; grid-template-columns: 11rem 1fr; gap: .45rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
@media (max-width: 560px) { dl.facts { grid-template-columns: 1fr; } dl.facts dd { margin-bottom: .4rem; } }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .55rem 0; border-bottom: 1px solid #edf0f4; display: grid; grid-template-columns: 11.5rem 1fr; gap: .75rem; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-size: .85rem; }
@media (max-width: 560px) { .timeline li { grid-template-columns: 1fr; gap: 0; } }

/* ---------- login ---------- */
.center-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--navy); }
.login-card { background: #fff; border-radius: 12px; padding: 2rem; width: 100%; max-width: 400px; text-align: center; }
.login-card h1 { margin-bottom: .25rem; }

/* ---------- mapping editor ---------- */
.map-layout { display: grid; grid-template-columns: minmax(320px, 430px) 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 980px) { .map-layout { grid-template-columns: 1fr; } }
.map-side { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; }
.map-row { display: grid; grid-template-columns: 1fr; gap: .2rem; margin-bottom: .7rem; }
.map-row label { font-weight: 600; font-size: .88rem; }
.map-row.missing select { border-color: var(--danger); }
.placebar { display: flex; flex-direction: column; gap: .4rem; }
.placebar .check { padding: .35rem .5rem; border-radius: 6px; }
.placebar .check.on { background: var(--info-bg); }
.pagewrap { position: relative; display: inline-block; max-width: 100%; border: 1px solid var(--line); background: #fff; touch-action: none; user-select: none; }
.pagewrap img { display: block; max-width: 100%; height: auto; pointer-events: none; }
.box { position: absolute; border: 2px solid; pointer-events: none; }
.box span { position: absolute; top: -1.35rem; left: -2px; font-size: .72rem; color: #fff; padding: 0 .35rem; border-radius: 3px; white-space: nowrap; }

/* ---------- signer ---------- */
.s-body { background: var(--bg); }
.s-top { background: var(--navy); color: #fff; padding: .85rem 1rem; }
.s-top .inner { max-width: 640px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.s-top .org { font-weight: 700; }
.s-top .secure { font-size: .8rem; color: #c9d6e8; }
.s-main { max-width: 640px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.s-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 1.4rem; }
@media (max-width: 480px) { .s-main { padding: .75rem .6rem 2rem; } .s-card { padding: 1.1rem; border-radius: 10px; } }
.s-card h1 { font-size: 1.35rem; }
.lede { font-size: 1.02rem; }
.code-input { font-size: 1.6rem !important; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; max-width: 14rem; margin: 0 auto; display: block; }
.progress { display: flex; gap: .3rem; margin: 0 0 1.1rem; }
.progress i { flex: 1; height: 5px; border-radius: 3px; background: #dfe5ec; }
.progress i.on { background: var(--green); }
.stepcount { color: var(--muted); font-size: .85rem; margin-bottom: .2rem; }
.step-nav { display: flex; gap: .6rem; margin-top: 1.25rem; }
.step-nav .btn { flex: 1; }
.radios { display: flex; flex-direction: column; gap: .45rem; }
.radios .check { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .8rem; align-items: center; }
.radios .check:has(input:checked) { border-color: var(--green); background: var(--ok-bg); }
.radios .check input { margin-top: 0; }
.sub { margin: .6rem 0 0 .4rem; padding-left: .9rem; border-left: 3px solid var(--line); }
details.more { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; margin-bottom: 1rem; }
details.more summary { cursor: pointer; font-weight: 600; }
details.more[open] summary { margin-bottom: .7rem; }
.review { margin: 0; display: grid; grid-template-columns: 9.5rem 1fr; gap: .45rem .8rem; }
.review dt { color: var(--muted); }
.review dd { margin: 0; word-break: break-word; }
@media (max-width: 420px) { .review { grid-template-columns: 1fr; } .review dd { margin-bottom: .45rem; } }
.cert { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: .9rem 1rem; font-size: .92rem; line-height: 1.55; max-height: 22rem; overflow: auto; }
.declare { font-weight: 600; margin: .9rem 0; }
.bw { background: var(--warn-bg); border: 1px solid #f3d29a; border-radius: 8px; padding: .75rem .8rem; margin-bottom: 1rem; }
.sigtabs { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: .6rem; }
.sigtabs button { flex: 1; padding: .6rem; border: 0; background: #f8fafc; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); min-height: 44px; }
.sigtabs button.on { background: var(--navy); color: #fff; }
.sigpad { position: relative; border: 2px dashed #b8c2cf; border-radius: 8px; background: #fff; touch-action: none; }
.sigpad canvas { display: block; width: 100%; height: 170px; cursor: crosshair; }
.sigpad .line { position: absolute; left: 8%; right: 8%; bottom: 38px; border-bottom: 1px solid #c4ccd7; pointer-events: none; }
.sigpad .ph { position: absolute; left: 0; right: 0; top: 40%; text-align: center; color: #a0aab6; pointer-events: none; }
.typed-preview { font-family: "Signature", cursive; font-size: 2.4rem; color: #17325c; min-height: 4.2rem; border: 2px dashed #b8c2cf; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 .5rem; overflow: hidden; white-space: nowrap; }
@font-face { font-family: "Signature"; src: url("../fonts/DancingScript.ttf") format("truetype"); font-display: block; }
.done-mark { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-bg); color: var(--green); display: flex; align-items: center; justify-content: center; font-size: 2rem; margin: 0 auto 1rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 1.25rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.cert p { margin: 0 0 .6rem; }
.cert p:last-child { margin-bottom: 0; }
.cert.struck p.item2 { text-decoration: line-through; color: #6b7280; }
.sigpad + .actions { margin-top: .4rem; }
.stepgroup { border-top: 1px solid var(--line); padding: .7rem 0; }
.stepgroup:first-of-type { border-top: 0; }
.stepno { font-weight: 700; color: var(--navy); font-size: .85rem; white-space: nowrap; }
.fieldlist { list-style: none; margin: .4rem 0 .6rem; padding: 0; }
.fieldlist li { padding: .35rem 0; border-bottom: 1px dashed #e5e9ef; display: flex; flex-wrap: wrap; gap: .1rem .5rem; align-items: baseline; }
.fieldlist li a { font-weight: 600; }
.ok-text { color: #1d6b43; }
.err-text { color: var(--danger); font-weight: 600; }
.tight-list { margin: .3rem 0 0; padding-left: 1.2rem; }
.box.opt { border: 1px solid #7c3aed; background: rgba(124,58,237,.08); pointer-events: auto; cursor: pointer; }
.box.opt span { background: #7c3aed; }
.box.fld { border: 1.5px solid #2563eb; background: rgba(37,99,235,.08); pointer-events: auto; cursor: pointer; }
.box.fld span { background: #2563eb; }
.box.sig { border: 2px solid #2f8f5b; background: rgba(47,143,91,.12); pointer-events: auto; cursor: pointer; }
.box.sig span { background: #2f8f5b; }
.box.strk { border: 2px solid #c2410c; background: rgba(194,65,12,.10); pointer-events: auto; cursor: pointer; }
.box.strk span { background: #c2410c; }
.box.draft { border: 2px dashed #111; background: rgba(0,0,0,.05); }
.box span { opacity: 0; transition: opacity .1s; }
.box:hover span, .box.sel span { opacity: 1; }
.box.sel { outline: 2px solid #f59e0b; }
.optrow { display: grid; grid-template-columns: 1fr 1.4fr 1.6fr; gap: .4rem; margin-bottom: .4rem; }
@media (max-width: 700px) { .optrow { grid-template-columns: 1fr; } }
.readonly-val { padding: .55rem .7rem; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; }
.pageimg { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; margin-bottom: .8rem; background: #fff; }
.saved-note { font-size: .85rem; color: #1d6b43; margin: .2rem 0 .3rem; }
.cert p.struck-p { text-decoration: line-through; color: #6b7280; }
.field-note { margin-top: -.6rem; }
.center { text-align: center; } .btn.danger { color: var(--danger); }
.filters { flex-wrap: wrap; align-items: center; }
.filters input[type=date] { width: auto; min-height: 40px; }
.filters select { width: auto; max-width: 220px; }
ol.signers { padding-left: 1.2rem; margin: 0; }
ol.signers li { margin-bottom: .6rem; }
.steps-list li { margin-bottom: .5rem; }
.inline-form { display: inline; }

/* ---------- visual editor ---------- */
.page.wide { max-width: 1500px; }
.ed-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.ed-head h1 { margin: 0; }
#notes { margin-bottom: .6rem; }
.ed-tools { position: sticky; top: 0; z-index: 30; display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; margin-bottom: 1rem; }
.ed-tools .tool { padding: .35rem .7rem; min-height: 34px; border-radius: 6px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: .88rem; cursor: pointer; }
.ed-tools .tool.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.ed-tools .sep { width: 1px; height: 24px; background: var(--line); margin: 0 .2rem; }
.ed-tools .hint { margin-left: auto; color: var(--muted); font-size: .82rem; }
.ed-layout { display: grid; grid-template-columns: 360px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 1000px) { .ed-layout { grid-template-columns: 1fr; } }
.ed-side { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; padding: 0; }
.ed-tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); background: #f8fafc; }
.ed-tabs button { flex: 1; border: 0; background: none; padding: .6rem .3rem; font: inherit; font-size: .85rem; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.ed-tabs button.on { color: var(--navy); border-color: var(--green); }
.ed-tabs .badge { display: inline-block; min-width: 1.2rem; border-radius: 999px; background: var(--danger); color: #fff; font-size: .7rem; padding: 0 .3rem; margin-left: .2rem; }
#sidepanel { padding: 1rem; }
#sidepanel h3 { margin-top: .6rem; }
#sidepanel .field { margin-bottom: .75rem; }
#sidepanel .row { display: flex; gap: .4rem; align-items: center; }
#sidepanel .row > * { flex: 1; }
.flist { list-style: none; padding: 0; margin: 0 0 .8rem; }
.flist li { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .4rem; border-radius: 6px; cursor: pointer; align-items: baseline; }
.flist li:hover { background: #f1f5f9; }
.flist li .t { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.flist li.unplaced .t { color: var(--warn); }
.problem { display: flex; gap: .5rem; justify-content: space-between; align-items: flex-start; padding: .5rem 0; border-bottom: 1px solid #eef1f5; font-size: .9rem; }
.ready { background: var(--ok-bg); border: 1px solid #bfe3cf; border-radius: 8px; padding: .8rem; }
.role-row { border: 1px solid var(--line); border-radius: 8px; padding: .6rem; margin-bottom: .6rem; }
.swatch { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; vertical-align: middle; margin-right: .3rem; }
.opt-row { display: flex; gap: .3rem; align-items: center; margin-bottom: .3rem; }
.opt-row input { flex: 1; min-height: 36px; padding: .3rem .5rem; }
.ed-pages { display: flex; flex-direction: column; gap: 1rem; }
.ed-page { position: relative; background: #fff; border: 1px solid var(--line); box-shadow: 0 1px 3px rgba(0,0,0,.06); user-select: none; touch-action: none; }
.ed-page img { display: block; width: 100%; height: auto; pointer-events: none; }
.ed-page.placing { cursor: crosshair; }
.ed-page .pno { position: absolute; top: -1.3rem; left: 0; font-size: .75rem; color: var(--muted); }
.fbox { position: absolute; border: 1.5px solid var(--c, #2563eb); background: color-mix(in srgb, var(--c, #2563eb) 12%, transparent); border-radius: 2px; cursor: pointer; overflow: visible; }
.fbox.acro { border-style: dashed; }
.fbox.sel { outline: 2px solid #f59e0b; outline-offset: 1px; z-index: 5; }
.fbox .lbl { position: absolute; left: 2px; top: 50%; transform: translateY(-50%); font-size: 10px; line-height: 1; color: #0f172a; white-space: nowrap; overflow: hidden; max-width: calc(100% - 4px); pointer-events: none; text-shadow: 0 0 2px #fff; }
.fbox.tiny .lbl { left: 110%; max-width: none; background: rgba(255,255,255,.85); padding: 1px 2px; }
.fbox .grip { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; background: #f59e0b; border-radius: 2px; cursor: nwse-resize; display: none; }
.fbox.sel.movable .grip { display: block; }
.fbox.movable.sel { cursor: move; }
.ghost { position: absolute; border: 2px dashed #111; background: rgba(0,0,0,.05); pointer-events: none; }
