/* mndok
 * Palette taken from paperwork itself: blue-black fountain-pen ink for
 * structure, ballpoint blue for actions, and the yellow "sign here" flag
 * as the one loud element. It only appears where someone signs or starts
 * the signing process.
 */

:root {
  --paper: #F5F8FC;
  --surface: #FFFFFF;
  --ink: #0F1A3D;
  --ink-2: #33405A;
  --muted: #5D6B85;
  --faint: #8A96AB;
  --rule: #DCE3EE;
  --rule-soft: #E9EEF5;
  --night: #0B1433;

  --blue: #004EEA;
  --blue-dark: #003BB5;
  --blue-wash: #EAF1FF;
  --green: #1C9A4A;
  --green-bright: #7BE321;
  --flag: #FFC93C;
  --flag-deep: #D9A70F;
  --flag-wash: rgba(255, 201, 60, 0.28);

  --ok: #1C9A4A;
  --ok-wash: #E6F6EC;
  --warn: #8A5B00;
  --warn-wash: #FFF3D1;
  --bad: #C62828;
  --bad-wash: #FDECEA;
  --brand-gradient: linear-gradient(90deg, #00176A 0%, #004EEA 22%, #17B26A 44%, #B8E021 58%, #FCA503 72%, #FD394D 86%, #A307BA 100%);

  --display: "Plus Jakarta Sans", "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --hand: Caveat, "Segoe Script", cursive;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 248px;
  --focus: 0 0 0 3px rgba(0, 78, 234, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; }

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-family: var(--display); font-weight: 800; font-size: 30px; letter-spacing: -0.02em; }
h2, h3 { font-family: var(--display); }
p { margin: 0; }
a { color: var(--blue); }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.lede { color: var(--muted); margin-top: 6px; max-width: 62ch; }
.hint { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }
.optional { font-weight: 400; color: var(--faint); }

/* ── Brand ── */
.brand { display: inline-flex; align-items: center; text-decoration: none; }
.logo img { display: block; height: 38px; width: auto; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14.5px; line-height: 1;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13.5px; }
.btn-block { width: 100%; }

.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 1px 2px rgba(0,78,234,.25); }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-flag { background: var(--flag); color: var(--ink); }
.btn-flag:hover:not(:disabled) { background: #FFBA0A; }
.btn-google { background: #fff; border-color: var(--rule); color: var(--ink); font-weight: 600; }
.btn-google:hover:not(:disabled) { border-color: var(--faint); background: #FAFBFD; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #93190F; }
.btn-quiet { background: var(--surface); border-color: var(--rule); color: var(--ink); }
.btn-quiet:hover:not(:disabled) { border-color: var(--faint); }
.btn-quiet-danger { background: transparent; border-color: var(--rule); color: var(--bad); }
.btn-quiet-danger:hover:not(:disabled) { background: var(--bad-wash); border-color: #F2B8B2; }
.btn-quiet-dark { background: transparent; border-color: rgba(255,255,255,.22); color: #fff; }
.btn-quiet-dark:hover:not(:disabled) { background: rgba(255,255,255,.08); }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); cursor: pointer; font-size: 20px; line-height: 1;
}
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn-dark { background: transparent; border-color: transparent; color: #fff; }

.text-link { display: inline-block; margin-top: 14px; font-weight: 600; font-size: 14px; }
.back-link { display: inline-block; margin-bottom: 12px; font-size: 14px; color: var(--muted); text-decoration: none; }
.back-link::before { content: "‹ "; }
.back-link:hover { color: var(--ink); }

/* ── Spinner ── */
.spinner {
  display: inline-block; width: 16px; height: 16px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite; opacity: .8;
}
.spinner-lg { width: 30px; height: 30px; border-width: 3px; color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ── */
.field { display: block; margin: 0 0 18px; border: 0; padding: 0; min-width: 0; }
.field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
input:not([type="checkbox"]):not([type="file"]), select, textarea {
  display: block; width: 100%; min-height: 42px; padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 84px; margin-top: 14px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: var(--focus); }
input::placeholder, textarea::placeholder { color: var(--faint); }
.field-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

.check { display: flex; gap: 10px; align-items: flex-start; margin: 18px 0 4px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--blue); flex: none; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 36px 20px; margin-bottom: 18px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--rule); border-radius: var(--radius); background: var(--paper); color: var(--muted);
  transition: border-color .15s, background-color .15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--blue); background: var(--blue-wash); }
.dropzone:focus-within { box-shadow: var(--focus); }
.dropzone.has-file { border-style: solid; border-color: var(--ok); background: var(--ok-wash); color: var(--ok); }
.dropzone-title { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }

.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--rule-soft); border-radius: 9px; }
.segmented button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 6px;
  font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(27,36,48,.12); }
.segmented-sm button { padding: 5px 11px; font-size: 13px; }
.segmented-tabs { margin-bottom: 20px; }

.signer-rows { display: grid; gap: 10px; margin-bottom: 12px; }
.signer-row { display: grid; grid-template-columns: 30px 1fr 1.3fr; gap: 10px; align-items: center; }
.signer-row.reorderable { grid-template-columns: 18px 30px 1fr 1.3fr auto; border-radius: var(--radius-sm); }
.signer-row.dragging { opacity: .45; }
.drag-handle { color: var(--faint); cursor: grab; display: grid; place-items: center; }
.row-tools { display: flex; gap: 4px; }
.signer-rows:not(.ordered) .drag-handle { visibility: hidden; }
.signer-rows:not(.ordered) [data-action="signer-up"], .signer-rows:not(.ordered) [data-action="signer-down"] { display: none; }
.icon-btn-sm { width: 30px; height: 30px; font-size: 16px; }
.hint-top { margin: -6px 0 12px; }
.signer-row .field { margin: 0; }
.signer-num {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--rule-soft); font-weight: 700; font-size: 13px; color: var(--ink-2);
}
.signer-num.role { width: auto; height: auto; border-radius: 0; background: none; place-items: start; font-weight: 600; font-size: 14px; }
.signer-row:has(.signer-num.role) { grid-template-columns: 120px 1fr 1.3fr; }
.auth-back { color: var(--muted); font-size: 14.5px; margin-top: 18px; display: inline-block; }
.auth-back::before { content: "‹ "; }
.check-inline { margin: 4px 0 16px; }
#dialog-text { margin-top: 14px; }
.panel-pad { padding: 24px 24px 8px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px 20px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* ── Badges, avatars, tones ── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; line-height: 1.5; white-space: nowrap; vertical-align: middle;
}
.badge-neutral { background: var(--rule-soft); color: var(--ink-2); }
.badge-info { background: var(--blue-wash); color: var(--blue-dark); }
.badge-ok { background: var(--ok-wash); color: var(--ok); }
.badge-warn { background: var(--warn-wash); color: var(--warn); }
.badge-bad { background: var(--bad-wash); color: var(--bad); }

.avatar {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%;
  background: var(--blue-wash); color: var(--blue); font-weight: 700; font-size: 13px;
}
.avatar-neutral { background: var(--rule-soft); color: var(--ink-2); }
.avatar-warn { background: var(--warn-wash); color: var(--warn); }
.avatar-ok { background: var(--ok-wash); color: var(--ok); }
.avatar-bad { background: var(--bad-wash); color: var(--bad); }

.tone-ok { --tone: var(--ok); --tone-wash: var(--ok-wash); }
.tone-warn { --tone: var(--warn); --tone-wash: var(--warn-wash); }
.tone-bad { --tone: var(--bad); --tone-wash: var(--bad-wash); }
.tone-info { --tone: var(--blue); --tone-wash: var(--blue-wash); }
.tone-neutral { --tone: var(--faint); --tone-wash: var(--rule-soft); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--tone); margin-right: 8px; vertical-align: middle; }

/* ── Toasts ── */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 300; display: grid; gap: 10px; max-width: min(420px, calc(100vw - 40px)); }
.toast {
  padding: 12px 16px; border-radius: var(--radius-sm); background: var(--ink); color: #fff;
  font-size: 14px; font-weight: 500; box-shadow: 0 8px 24px rgba(27,36,48,.22);
  border-left: 4px solid var(--blue); animation: toast-in .2s ease-out;
}
.toast-success { border-left-color: #3FB57A; }
.toast-error { border-left-color: #F0625A; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Boot & auth ── */
.view-boot { min-height: 100vh; display: grid; place-items: center; }

.view-auth { min-height: 100vh; background: #fff; }
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-intro { padding: 56px 64px; color: var(--ink-2); display: flex; flex-direction: column; justify-content: space-between; gap: 40px; position: relative;
  background: radial-gradient(600px 360px at 90% 90%, rgba(123,227,33,.16), transparent 60%), radial-gradient(600px 360px at 0% 0%, rgba(0,78,234,.12), transparent 60%), var(--paper); border-right: 1px solid var(--rule-soft); }
.auth-intro::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--brand-gradient); }
.auth-intro h1 { color: var(--ink); font-size: clamp(32px, 4vw, 48px); line-height: 1.08; max-width: 14ch; margin-top: auto; }
.auth-points { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 10px; font-weight: 500; color: var(--ink-2); }
.auth-points li { display: flex; gap: 10px; align-items: center; }
.auth-points li::before { content: ""; width: 18px; height: 18px; border-radius: 50%; flex: none; background: var(--ok-wash) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5' fill='none' stroke='%231C9A4A' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat; }
.auth-intro p { max-width: 44ch; font-size: 16.5px; margin-bottom: 8px; }
.auth-panel { background: #fff; display: grid; place-items: center; padding: 48px 24px; }
.auth-form { width: 100%; max-width: 380px; }
.auth-form h2 { font-size: 28px; font-weight: 800; margin-bottom: 22px; letter-spacing: -0.02em; }
.auth-lede { color: var(--ink-2); margin: -10px 0 20px; }
.auth-note { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--ok-wash); color: #0F5E2E; font-size: 14.5px; }
.auth-legal { margin-top: 14px; font-size: 12.5px; color: var(--faint); text-align: center; }
.oauth { margin-bottom: 4px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--faint); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.field-label-row { display: flex; justify-content: space-between; align-items: baseline; }
.field-label-row a { font-weight: 500; font-size: 13.5px; }
.auth-switch { margin-top: 20px; font-size: 14px; color: var(--muted); text-align: center; }

/* ── App shell ── */
.topbar { display: none; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 50;
  display: flex; flex-direction: column; padding: 22px 16px; gap: 8px;
  background: #fff; color: var(--ink-2); border-right: 1px solid var(--rule-soft);
}
.sidebar::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--brand-gradient); }
.sidebar-brand { padding: 6px 8px 18px; }
.sidebar-cta { margin-bottom: 18px; }
.nav-links { display: grid; gap: 2px; }
.nav-link {
  display: block; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: var(--paper); color: var(--ink); }
.nav-link.active { background: var(--blue-wash); color: var(--blue); font-weight: 600; box-shadow: inset 3px 0 0 var(--blue); }
.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--rule-soft); display: grid; gap: 12px; }
.user-chip { display: flex; gap: 10px; align-items: center; min-width: 0; color: var(--ink); font-weight: 600; font-size: 14px; }
.user-chip-text { min-width: 0; }
.user-email { font-weight: 400; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-backdrop { display: none; }

.main { margin-left: var(--sidebar); padding: 40px 48px 64px; }
.page { max-width: 1120px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 24px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 10px; color: var(--muted); font-size: 14px; }

/* ── Panels ── */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.form-panel { max-width: 720px; }
.detail-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; align-items: start; }
.detail-grid > .panel { margin-bottom: 20px; }

.empty { padding: 56px 24px; text-align: center; }
.empty h3 { font-size: 18px; margin-bottom: 8px; }
.empty p { color: var(--muted); max-width: 44ch; margin: 0 auto 20px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th {
  text-align: left; font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 12px 20px; border-bottom: 1px solid var(--rule); background: #FAFBFC; white-space: nowrap;
}
.table td { padding: 14px 20px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: #F8FAFD; }
.row-link:focus-visible { box-shadow: inset var(--focus); border-radius: 0; }
.row-muted td { color: var(--faint); }
.cell-title { font-weight: 600; color: var(--ink); overflow-wrap: break-word; }
.cell-sub { font-size: 13px; color: var(--muted); }
.cell-actions { text-align: right; }
.loading-cell { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 28px 20px !important; color: var(--muted); }
td.loading-cell { display: table-cell; text-align: center; }
td.loading-cell .spinner { margin-right: 10px; vertical-align: -3px; }

.progress { display: flex; align-items: center; gap: 10px; min-width: 130px; }
.progress-track { flex: 1; max-width: 90px; height: 6px; border-radius: 3px; background: var(--rule-soft); overflow: hidden; }
.progress-track span { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.progress-text { font-size: 13px; color: var(--muted); white-space: nowrap; }

.pager { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--rule-soft); }
.pager:empty { display: none; }
.pager-info { margin-right: auto; font-size: 13px; color: var(--muted); }

/* ── New document steps ── */
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 20px; counter-reset: step; flex-wrap: wrap; }
.steps li {
  counter-increment: step; display: flex; align-items: center; gap: 8px;
  padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--rule-soft); color: var(--muted); font-size: 14px; font-weight: 600;
}
.steps li::before {
  content: counter(step); display: grid; place-items: center; width: 24px; height: 24px;
  border-radius: 50%; background: var(--surface); font-size: 12.5px;
}
.steps li.current { background: var(--blue); color: #fff; }
.steps li.current::before { background: #fff; color: var(--blue); }
.steps li.done { background: var(--ok-wash); color: var(--ok); }
.steps li.done::before { content: "✓"; }

/* ── PDF viewer ── */
.viewer { background: #E4E8ED; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; min-width: 0; }
.viewer-bar {
  display: flex; justify-content: center; align-items: center; gap: 14px;
  padding: 8px; background: var(--surface); border-bottom: 1px solid var(--rule); font-size: 14px; font-weight: 600;
}
.viewer-stage { position: relative; display: flex; justify-content: center; padding: 16px; min-height: 420px; overflow: auto; }
.viewer-stage canvas { display: block; background: #fff; box-shadow: 0 1px 3px rgba(27,36,48,.18), 0 6px 18px rgba(27,36,48,.08); max-width: none; }
.viewer-stage.placing canvas { cursor: crosshair; }
.viewer-stage.is-loading::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border: 3px solid var(--blue); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite;
}

/* Field overlays share a colour per assignee while placing */
.c0 { --c: #1F4FD1; } .c1 { --c: #0F766E; } .c2 { --c: #7E3AF2; }
.c3 { --c: #C2410C; } .c4 { --c: #BE185D; } .c5 { --c: #475569; }

.field-box { position: absolute; display: flex; align-items: center; justify-content: center; border-radius: 4px; }
.field-box.placed {
  border: 2px dashed var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent);
  color: var(--c);
}
.field-box-label { font-size: 12.5px; font-weight: 700; padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-box.placed { cursor: move; touch-action: none; user-select: none; }
.field-box.placed.optional { border-style: dotted; }
.field-box.placed.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); z-index: 2; }
.field-box.placed .field-remove { opacity: 0; transition: opacity .12s; }
.field-box.placed:hover .field-remove, .field-box.placed.selected .field-remove { opacity: 1; }
.field-box.ft-checkbox .field-box-label { display: none; }
.fb-resize { position: absolute; right: -5px; bottom: -5px; width: 11px; height: 11px; border-radius: 2px; background: #fff; border: 2px solid var(--c); cursor: nwse-resize; opacity: 0; }
.field-box.placed.selected .fb-resize, .field-box.placed:hover .fb-resize { opacity: 1; }
.field-box.ft-checkbox .fb-resize { right: -8px; bottom: -8px; }
.field-remove {
  position: absolute; top: -11px; right: -11px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #fff; background: var(--c); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}

/* The signature flag: the one bold element */
.field-box.sign-flag {
  border: 2px solid var(--flag-deep); background: var(--flag-wash); color: var(--ink);
  cursor: pointer; padding: 0;
}
.field-box.sign-flag::before {
  content: attr(data-tab); position: absolute; right: 100%; top: 50%; transform: translateY(-50%);
  margin-right: 4px; padding: 4px 14px 4px 8px; background: var(--flag); color: var(--ink);
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
  clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 50%, calc(100% - 9px) 100%, 0 100%);
}
.field-box.sign-flag:hover { background: rgba(255, 210, 74, 0.45); }
.field-box.sign-flag.filled { background: rgba(255,255,255,.6); border-style: dashed; border-color: var(--ok); }
.field-box.sign-flag.filled::before { content: "Done"; background: var(--ok); color: #fff; }
.field-box.sign-flag img { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; }

/* Signer-side fields */
.field-input, .field-text-btn, .field-check, .field-auto {
  border: 2px solid var(--flag-deep); background: var(--flag-wash); border-radius: 3px; color: var(--ink);
}
.field-input { padding: 0 4px; min-height: 0; font-family: var(--sans); font-weight: 500; }
.field-input::placeholder { color: #8A6A00; font-weight: 600; opacity: .85; }
.field-input:focus { outline: none; background: #fff; border-color: var(--blue); box-shadow: var(--focus); }
.field-text-btn { justify-content: flex-start; padding: 0 3px; font-size: 11px; font-weight: 600; cursor: pointer; overflow: hidden; white-space: nowrap; }
.field-text-btn span { overflow: hidden; text-overflow: ellipsis; }
.field-check { padding: 0; cursor: pointer; color: var(--ink); }
.field-check svg { width: 90%; height: 90%; }
.field-auto { border-style: dashed; border-color: var(--rule); background: rgba(255,255,255,.7); color: var(--muted); font-size: 12px; justify-content: flex-start; padding: 0 4px; white-space: nowrap; overflow: hidden; }
.field-box.filled:is(.field-input, .field-text-btn, .field-check) { background: rgba(255,255,255,.75); border-color: var(--ok); border-style: dashed; }
.field-box.is-optional:not(.filled):is(.field-input, .field-text-btn, .field-check, .sign-flag) { border-style: dashed; border-color: var(--faint); background: rgba(255,255,255,.55); }
.field-box.is-optional.sign-flag::before { background: var(--rule); }
/* Text inputs on the page: beat the general input style (size and colours must match the placed box). */
.viewer-stage input.field-input { min-height: 0; height: auto; padding: 0 4px; border: 2px solid var(--flag-deep); background: var(--flag-wash); border-radius: 3px; box-shadow: none; }
.viewer-stage input.field-input.filled { background: rgba(255,255,255,.75); border-color: var(--ok); border-style: dashed; }
.viewer-stage input.field-input.is-optional:not(.filled) { border-style: dashed; border-color: var(--faint); background: rgba(255,255,255,.55); }
.viewer-stage input.field-input:focus { background: #fff; border-color: var(--blue); border-style: solid; box-shadow: var(--focus); }
.field-box.pulse { animation: pulse 1.4s ease-out 1; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(31,79,209,.55); } 100% { box-shadow: 0 0 0 14px rgba(31,79,209,0); } }

/* Signer status bar */
.sign-progress { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 220px; font-size: 14px; font-weight: 600; }
.progress-track-lg { flex: 1; max-width: 220px; height: 8px; }
.progress-track-lg span { transition: width .3s ease; }
.save-state { font-size: 13px; color: var(--muted); min-width: 110px; text-align: right; }
.save-state.save-saved::before { content: "✓ "; color: var(--ok); }
.save-state.save-error { color: var(--bad); }

/* Engagement on the document page */
.fill-progress { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13.5px; color: var(--ink-2); }
.fill-progress .progress-track { width: 110px; flex: none; }
.engagement { margin-top: 10px; }
.engagement summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--blue); width: fit-content; }
.engagement h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.eng-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; color: var(--ink-2); }
.eng-list li { display: flex; gap: 8px; align-items: flex-start; }
.eng-ico { color: var(--faint); margin-top: 2px; flex: none; }
.eng-meta { display: block; color: var(--muted); font-size: 12.5px; }

/* ── Prepare page ── */
.prep-layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.prep-side { display: grid; gap: 16px; align-content: start; }
.prep-side .panel { margin: 0; padding: 18px; }
.assignees { display: grid; gap: 8px; margin: 0 0 10px; padding: 0; list-style: none; }
.assignee-row { display: flex; gap: 6px; align-items: stretch; }
.assignee-order { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; flex: none; background: var(--c); color: #fff; font-size: 12px; font-weight: 700; margin-top: 1px; }
.assignee-move { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.palette-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--surface); font-size: 13.5px; font-weight: 600; text-align: left; cursor: pointer; }
.palette-item:hover { border-color: var(--faint); }
.palette-item.active { border-color: var(--c); background: color-mix(in srgb, var(--c) 10%, #fff); box-shadow: inset 0 0 0 1px var(--c); }
.pi-swatch { width: 14px; height: 10px; border-radius: 2px; border: 1.5px dashed var(--c); flex: none; }
.pi-checkbox .pi-swatch { width: 10px; }
.pi-signature .pi-swatch, .pi-initials .pi-swatch { background: color-mix(in srgb, var(--c) 18%, transparent); }
.assignee {
  flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 10px 12px; text-align: left;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-sm); cursor: pointer;
}
.assignee.active { border-color: var(--c); box-shadow: inset 3px 0 0 var(--c); background: color-mix(in srgb, var(--c) 6%, #fff); }
.assignee-dot { width: 12px; height: 12px; margin-top: 4px; border-radius: 3px; background: var(--c); flex: none; }
.assignee-text { display: grid; min-width: 0; flex: 1; }
.assignee-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assignee-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assignee-count { margin-top: 4px; font-size: 12.5px; font-weight: 600; color: var(--c); }
.assignee-count.is-missing { color: var(--muted); font-weight: 500; }

/* ── Detail page ── */
.signer-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; }
.signer-item { display: flex; gap: 12px; }
.signer-item-text { min-width: 0; }
.signer-state { font-size: 13.5px; font-weight: 600; color: var(--tone); margin-top: 4px; }
.order-tag {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 8px; padding: 0 5px;
  border-radius: 5px; background: var(--rule-soft); font-size: 12px; color: var(--muted); vertical-align: 1px;
}
.decline-note { margin: 8px 0 0; padding: 8px 12px; border-left: 3px solid var(--bad); background: var(--bad-wash); font-size: 14px; }

.integrity { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--tone-wash); }
.integrity-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--tone); color: #fff; }
.integrity p { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.hashes { margin: 18px 0 0; display: grid; gap: 4px; }
.hashes dt { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 8px; }
.hashes dd { margin: 0; }
.hashes code { display: block; padding: 7px 10px; background: var(--paper); border-radius: 6px; font-size: 12px; overflow-wrap: anywhere; color: var(--ink-2); }

.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { position: relative; display: flex; gap: 14px; padding-bottom: 18px; }
.tl-item:not(:last-child)::before { content: ""; position: absolute; left: 5px; top: 16px; bottom: 0; width: 2px; background: var(--rule-soft); }
.tl-dot { width: 12px; height: 12px; margin-top: 5px; border-radius: 50%; background: var(--tone); flex: none; box-shadow: 0 0 0 3px var(--surface); position: relative; }
.tl-body { min-width: 0; }
.tl-title { font-weight: 600; font-size: 14.5px; }
.tl-actor { font-weight: 400; color: var(--muted); margin-left: 8px; }
.tl-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.timeline-compact .tl-item { padding-bottom: 12px; }

/* ── Templates ── */
.tpl-list { list-style: none; margin: 0; padding: 0; }
.tpl-list:empty { display: none; }
.tpl-item { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 18px 24px; border-bottom: 1px solid var(--rule-soft); }
.tpl-item:last-child { border-bottom: 0; }
.tpl-actions { display: flex; gap: 8px; flex: none; }
.role-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; }
.role-tag { padding: 2px 9px; border-radius: 5px; background: var(--blue-wash); color: var(--blue-dark); font-size: 12.5px; font-weight: 600; }

/* ── API keys ── */
.key-reveal { border-color: var(--flag-deep); background: #FFFBEB; }
.key-reveal p { color: var(--ink-2); margin-bottom: 14px; }
.key-box { display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-sm); }
.key-box code { flex: 1; overflow-wrap: anywhere; font-size: 13px; }
.code-block {
  margin: 14px 0 0; padding: 16px 18px; background: var(--ink); color: #D8E0EA;
  border-radius: var(--radius-sm); font-family: var(--mono); font-size: 12.5px; line-height: 1.7; overflow-x: auto; white-space: pre;
}

/* ── Admin ── */
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; margin: 0 0 20px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.stat { background: var(--surface); padding: 18px 20px; }
.stat dt { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat dd { margin: 6px 0 0; font-family: var(--display); font-size: 28px; font-weight: 800; line-height: 1.1; }
.chart-box { position: relative; height: 260px; }
.chart-box-sm { height: 220px; }
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--rule-soft); }
.rank-list li:last-child { border-bottom: 0; }
.rank-count { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.admin-tab .segmented { margin-bottom: 14px; }

/* ── Signer view ── */
.view-sign, .view-verify { min-height: 100vh; }
.sign-bar {
  position: sticky; top: 0; z-index: 40; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 24px; background: rgba(255,255,255,.96); backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule-soft);
}
.sign-bar::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--brand-gradient); }
.sign-actions { display: flex; gap: 10px; }
.sign-body { max-width: 980px; margin: 0 auto; padding: 32px 20px 64px; }
.sign-intro { margin-bottom: 18px; }
.sign-intro h1 { font-size: 26px; overflow-wrap: anywhere; }
.sign-status {
  position: sticky; top: 58px; z-index: 30;
  display: flex; justify-content: space-between; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding: 12px 16px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--rule); border-left: 4px solid var(--flag); border-radius: var(--radius-sm);
}
.sign-status-text { display: grid; font-size: 14px; }
.sign-status-text span { color: var(--muted); }
.page-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--rule); background: var(--surface); font-size: 13px; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--flag-deep); background: #FFFBEB; }

.message { max-width: 520px; margin: 40px auto; padding: 40px 32px; text-align: center; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.message h1 { font-size: 26px; margin-bottom: 10px; }
.message p { color: var(--muted); margin-bottom: 20px; }
.message-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; margin-bottom: 18px; border-radius: 50%; background: var(--tone-wash); color: var(--tone); }
.message-icon svg { width: 26px; height: 26px; }

/* ── Signature modal ── */
.sig-pane { margin-top: 16px; }
.sig-pad { position: relative; height: 190px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: #FDFDFB; margin-bottom: 10px; }
.sig-pad canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; border-radius: var(--radius-sm); }
.sig-hint { position: absolute; left: 0; right: 0; top: 44%; text-align: center; color: var(--faint); font-size: 14px; pointer-events: none; }
.sig-line { position: absolute; left: 24px; right: 24px; bottom: 44px; border-bottom: 1.5px solid var(--rule); pointer-events: none; }
.sig-line::before { content: "×"; position: absolute; left: -2px; bottom: 2px; color: var(--faint); font-size: 18px; }
.sig-typed-preview {
  min-height: 110px; display: grid; place-items: center; padding: 10px;
  border: 1px solid var(--rule); border-radius: var(--radius-sm); background: #FDFDFB;
  font-family: var(--hand); font-size: 54px; line-height: 1.1; color: var(--ink); overflow-wrap: anywhere; text-align: center;
}

/* ── Modals ── */
.modal {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px;
  background: rgba(27, 36, 48, 0.55); opacity: 0; transition: opacity .18s;
}
.modal.open { opacity: 1; }
.modal-card {
  width: 100%; max-width: 480px; max-height: calc(100vh - 40px); overflow-y: auto;
  background: var(--surface); border-radius: 12px; padding: 28px; box-shadow: 0 24px 64px rgba(27,36,48,.3);
  transform: translateY(8px); transition: transform .18s;
}
.modal.open .modal-card { transform: none; }
.modal-wide { max-width: 600px; }
.modal-card h2 { font-size: 22px; font-weight: 800; margin-bottom: 12px; }
.modal-card > p { color: var(--ink-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.consent-text {
  max-height: 300px; overflow-y: auto; padding: 16px 18px; white-space: pre-wrap;
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius-sm);
  font-family: var(--serif); font-size: 15px; line-height: 1.65; color: var(--ink-2);
}

/* ── Verify ── */
.verify-body { max-width: 680px; margin: 0 auto; padding: 48px 20px; }
.verify-panel { padding: 32px; }
.verify-panel h1 { font-size: 28px; }
.verify-form { display: flex; gap: 10px; margin: 22px 0; }
.verify-form input { flex: 1; }
.verify-panel .integrity { margin-bottom: 22px; }
.verify-signers { list-style: none; margin: 0 0 12px; padding: 0; }
.verify-signers li { display: grid; grid-template-columns: 1fr auto; gap: 0 16px; padding: 10px 0; border-bottom: 1px solid var(--rule-soft); }
.verify-signers li .cell-sub:last-child { grid-column: 2; grid-row: 1 / 3; align-self: center; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .prep-layout { grid-template-columns: 1fr; }
  .prep-side { position: static; }
  .assignees { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 900px) {
  .topbar {
    position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--rule-soft);
  }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 8px 0 32px rgba(0,0,0,.25); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(27,36,48,.45); }
  .main { margin-left: 0; padding: 24px 16px 48px; }
  h1 { font-size: 25px; }
  .detail-grid { grid-template-columns: 1fr; gap: 0; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-intro { padding: 32px 24px 36px; gap: 28px; }
  .auth-intro h1 { font-size: 30px; }
  .auth-panel { padding: 32px 20px 48px; align-items: start; }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 18px; }
  .panel-flush { padding: 0; }
  .page-head { align-items: stretch; }
  .head-actions, .head-actions .btn { width: 100%; }
  .head-actions { flex-direction: column; }
  .signer-row, .signer-row:has(.signer-num.role) { grid-template-columns: 28px 1fr 36px; }
  .signer-row.reorderable { grid-template-columns: 28px 1fr auto; }
  .signer-row.reorderable .drag-handle { display: none; }
  .signer-row.reorderable .field:nth-of-type(2) { grid-column: 2; }
  .signer-row.reorderable .row-tools { grid-column: 3; grid-row: 1 / span 2; flex-direction: column; }
  .palette { grid-template-columns: 1fr 1fr 1fr; }
  .sign-status { top: 50px; }
  .save-state { min-width: 0; text-align: left; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }
  .signer-row .field:nth-of-type(2) { grid-column: 2; }
  .signer-row:has(.signer-num.role) { grid-template-columns: 1fr; }
  .signer-row .icon-btn { grid-column: 3; grid-row: 1; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .table th, .table td { padding: 12px 14px; }
  /* Document list becomes stacked cards on phones */
  .table-stack thead { display: none; }
  .table-stack tr {
    display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center;
    padding: 14px 16px; border-bottom: 1px solid var(--rule-soft);
  }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack td { display: block; padding: 0; border: 0; }
  .table-stack td:nth-child(1) { grid-column: 1 / -1; }
  .table-stack td:nth-child(4) { text-align: right; }
  .table-stack td:nth-child(3) { grid-column: 1 / -1; grid-row: 3; }
  .table-stack td.loading-cell { grid-column: 1 / -1; }
  .tpl-item { flex-direction: column; align-items: stretch; padding: 16px 18px; }
  .sign-bar { padding: 10px 14px; }
  .sign-bar .logo img { height: 30px; }
  .topbar .logo img { height: 32px; }
  .sign-body { padding: 20px 10px 48px; }
  .viewer-stage { padding: 10px; min-height: 300px; }
  .field-box.sign-flag::before { display: none; }
  .verify-form { flex-direction: column; }
  .modal-card { padding: 22px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
