@font-face {
  font-family: 'Mrs Saint Delafield';
  src: url('../assets/mrs-saint-delafield.ttf') format('truetype');
  font-display: swap;
}

:root {
  --icon-stroke: #848280;
  --paper-border: rgb(34 31 30 / 10%);
  --signature-font: 'Whisper', 'Mrs Saint Delafield', cursive;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 88px; }
body { margin: 0; color: var(--ink); background: var(--canvas); font: var(--body); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2, h3, p, dl, dd, ol { margin: 0; }
ol { padding: 0; list-style: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Icons: Phosphor, 16px, 1.3px stroke */
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 20.8; stroke-linecap: round; stroke-linejoin: round; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { min-height: 64px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.wordmark { display: block; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* Buttons, from Components > Buttons (secondary, icon + button, icon) */
.topbar .button { min-height: 34px; height: 34px; }
.button.primary:disabled { background: #dbd8d7; border-color: #d0cdcc; color: #fdfcfc; }
.button.with-icon { padding: 0 14px 0 8px; gap: 8px; }
.button.with-icon .icon { color: var(--icon-stroke); }
.button.icon-only { width: 34px; padding: 0; }
.button.icon-only svg { width: 16px; height: 16px; fill: var(--ink); }

/* Menu, from Components > Dropdown (item + left icon) */
.menu-wrap { position: relative; }
.menu { position: absolute; top: calc(100% + 4px); right: 0; z-index: 4; width: 210px; padding: 4px; display: grid; background: var(--surface); border: 1px solid var(--input-border); border-radius: 6px; box-shadow: 0 4px 7px rgb(34 31 30 / 10%); }
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 0; border-radius: 4px; background: none; color: var(--ink); text-align: left; font: var(--body); }
.menu button .icon { color: var(--muted); }
.menu button:hover, .menu button:focus-visible { background: var(--subtle); outline: none; }
.menu button:hover .icon, .menu button:focus-visible .icon { color: var(--ink); }

/* Status pill, from the Davner status families */
.status { display: inline-flex; align-items: center; gap: 6px; width: fit-content; padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--status-neutral); color: var(--ink); font: var(--label); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.status.positive { background: var(--status-positive); border-color: var(--status-positive-border); color: var(--status-positive-ink); }
.status.positive::before { background: #30a46c; }

/* Review: paper document, then status panel */
.review { width: min(100% - 48px, 1120px); margin: 0 auto; padding: 32px 0 96px; display: grid; grid-template-columns: minmax(0, 760px) 300px; justify-content: center; gap: 32px; align-items: start; }
.document { min-width: 0; }

/* Paper, from Quote tool > Document page */
.agreement { padding: 56px 71px; background: var(--surface); border: 1px solid var(--paper-border); border-radius: 4px; box-shadow: var(--shadow); }
.agreement h1 { font: var(--title); font-size: 26px; line-height: 34px; outline: none; }
.doc-label { font: var(--label); color: var(--muted); }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 28px; }
.parties > div { display: grid; gap: 2px; align-content: start; font-size: 14px; overflow-wrap: anywhere; }
.parties .doc-label { margin-bottom: 4px; }
.parties strong { font-weight: 500; }

.doc-section { margin-top: 48px; }
.doc-section > h2 { font: var(--heading); font-size: 18px; line-height: 26px; margin-bottom: 16px; }

.order-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.order-table th, .order-table td { padding: 10px 0; text-align: left; vertical-align: top; border-bottom: 1px solid var(--divider); }
.order-table th { width: 38%; padding-right: 16px; font-weight: 400; color: var(--muted); }
.order-table td { font-weight: 500; }

.terms { display: grid; gap: 28px; }
.terms h3 { font: var(--body); font-size: 15px; font-weight: 500; margin-bottom: 8px; }
.clauses { display: grid; gap: 8px; }
.clauses li { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 8px; }
.clause-number { color: var(--muted); font-size: 14px; line-height: 24px; font-variant-numeric: tabular-nums; }
.clauses p { font-size: 15px; line-height: 24px; color: #3a3736; }

.signature-blocks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 40px; }
.signature-block { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; overflow-wrap: anywhere; align-content: start; font-size: 14px; min-width: 0; }
.signature-block .doc-label { margin-bottom: 8px; }
.signature-block strong { font-weight: 500; }
.signature-line, .sign-here { height: 64px; margin-bottom: 8px; }
.signature-line { display: flex; align-items: end; border-bottom: 1px solid #bdbab9; }
.signature-line span { --signature-size: 45px; }
.signature-line span { flex: 1; min-width: 0; font-family: var(--signature-font); font-size: calc(var(--signature-size) * var(--signature-scale, 1)); line-height: 1.083; font-variant-ligatures: none; white-space: nowrap; }
.sign-here { width: 100%; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--accent-border); border-radius: 6px; background: #fdf3f2; color: var(--accent); font-weight: 500; }
.sign-here:hover { background: #fbe9e7; }

/* Order form panel, from Paper > Panel / 4, refined */
.panel { position: sticky; top: 96px; overflow: clip; background: var(--surface); border: 1px solid var(--paper-border); border-radius: 8px; box-shadow: var(--shadow); }
.panel strong { font-weight: 500; }
.panel-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 7px 20px; background: var(--canvas); border-bottom: 1px solid var(--divider); }
.panel-header h2 { font: var(--body); font-weight: 500; }
.panel-header .panel-help { display: none; }

.details { display: grid; gap: 12px; padding: 16px 20px; }
.details > div { display: flex; align-items: baseline; gap: 12px; }
.details dt { flex: none; width: 48px; font: var(--body-small); line-height: 20px; color: var(--muted); }
.details dd { display: grid; min-width: 0; overflow-wrap: anywhere; }
.details .from strong { line-height: 24px; }
.details dd .muted { font: var(--body-small); }
.details .detail-extra { display: none; }

.signers { padding: 20px; border-top: 1px solid var(--divider); }
.signers li { display: flex; gap: 12px; position: relative; }
.signers li + li { margin-top: 20px; }
.signers li:not(:last-child)::after { content: ""; position: absolute; top: 28px; bottom: -16px; left: 11.5px; width: 1px; background: var(--border); }
.signers li > div { display: grid; min-width: 0; overflow-wrap: anywhere; }
.signers strong { line-height: 24px; }
.signers .muted { font: var(--body-small); }
.signer-step { flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--subtle); color: var(--muted); font: var(--label); }
.signer-step svg { display: none; width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 24; stroke-linecap: round; stroke-linejoin: round; }
[data-state="current"] .signer-step { background: #ffcac1; color: var(--accent); }
[data-state="done"] .signer-step { background: var(--status-positive); color: var(--status-positive-ink); }
[data-state="done"] .signer-step > span { display: none; }
[data-state="done"] .signer-step svg { display: block; }

.panel-footer { display: grid; gap: 16px; padding: 20px; border-top: 1px solid var(--divider); }
.panel-note { font: var(--body-small); }
.panel-help { font: var(--body-small); color: var(--muted); }
.panel-actions { display: grid; gap: 8px; }
.panel-actions .button { width: 100%; }

/* Signed */
.signed-inner { width: min(100% - 48px, 600px); margin: 0 auto; padding: 56px 0 96px; display: grid; gap: 12px; }
.signed h1 { font: var(--title); font-size: 26px; line-height: 34px; margin-top: 8px; outline: none; }
.signed-lede { font-size: 15px; line-height: 24px; color: var(--muted); }
.signed-section { margin-top: 32px; }
.signed-section h2 { font: var(--heading); margin-bottom: 16px; }
.next-steps { display: grid; gap: 16px; counter-reset: step; }
.next-steps li { display: grid; grid-template-columns: 22px minmax(0, 1fr); column-gap: 12px; row-gap: 2px; counter-increment: step; }
.next-steps li::before { content: counter(step); grid-row: span 2; display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); font: var(--label); color: var(--muted); }
.next-steps strong { font-weight: 500; }
.next-steps span { font-size: 14px; }
.record > div { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--divider); font-size: 14px; }
.record dt { color: var(--muted); }
.record dd { font-weight: 500; overflow-wrap: anywhere; }
.record small { display: block; font: var(--body-small); margin-top: 2px; }
.record-actions { display: flex; gap: 8px; margin-top: 20px; }
.signed .panel-help { margin-top: 24px; }

/* Dialogs */
dialog { width: min(560px, calc(100% - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 0; overflow: clip; border: 1px solid rgb(34 31 30 / 15%); border-radius: 8px; background: var(--canvas); color: var(--ink); box-shadow: 0 32px 87px rgb(34 31 30 / 15%); }
dialog::backdrop { background: #221f1e66; }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }
.dialog-header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 52px; padding: 0 10px 0 24px; }
.dialog-header h2 { font: var(--heading); font-weight: 500; line-height: 20px; }
.dialog-close { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 4px; background: none; color: var(--muted); }
.dialog-close:hover { background: var(--subtle); color: var(--ink); }
.dialog-close .icon { width: 20px; height: 20px; stroke-width: 18; }
.dialog-body { display: grid; gap: 16px; padding: 8px 24px 24px; overflow-y: auto; }
.field { display: grid; gap: 8px; font: var(--label); font-size: 14px; line-height: 20px; }
.field .text-input { font: var(--body); font-size: 16px; min-height: 44px; border-radius: 6px; }
textarea.text-input { resize: vertical; min-height: 120px; }
.text-input:focus-visible { border-color: var(--accent); outline: none; }

/* Sign dialog, from Paper > Sign / E1 container */
#sign-dialog { width: min(600px, calc(100% - 32px)); }
.sign-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-height: 0; padding: 20px 24px 24px; overflow: hidden auto; }
.sign-stage { position: relative; display: flex; align-items: end; height: clamp(250px, 100dvh - 372px, 400px); padding: 0 0 32px 48px; overflow: clip; border: 1px solid #e3e0df; border-radius: 8px; background: var(--subtle); }
.sign-stage::before, .sign-stage::after { content: ""; position: absolute; pointer-events: none; transform-origin: 0 0; }
.sign-stage::before { top: 0; left: 0; width: 661.205px; height: 375.635px; background: linear-gradient(in oklab 180deg, #f0efef 8%, #f0efef80 48%, #f0efef00 100%); rotate: 4.52deg; translate: -18.096px -261.576px; }
.sign-stage::after { top: 50%; right: 0; width: 472.627px; height: 470.542px; background: linear-gradient(in oklab 90deg, #f0efef00 0%, #f0efef66 50%, #f0efef 100%); rotate: -12.2deg; translate: 286.558px calc(-50% + 3.157px); }
.sign-page { flex: none; width: 811px; padding: 24px 77px 44px; background: var(--surface); border-bottom-left-radius: 4px; outline: 1px solid rgb(0 0 0 / 8%); box-shadow: 0 6px 10px -2px rgb(34 31 30 / 5%); }
.sign-clauses { display: grid; gap: 8px; padding-bottom: 44px; font-size: 16px; line-height: 26px; color: #3f3b3a; }
.sign-clauses p { display: grid; grid-template-columns: 38px 610px; gap: 9px; }
.sign-clauses span:first-child { font-size: 14px; color: var(--muted); }
.sign-title { padding-bottom: 17px; font-size: 19px; font-weight: 600; line-height: 28px; }
.sign-block { width: 307px; }
.sign-party { font-size: 13px; font-weight: 500; line-height: 18px; color: var(--muted); }
.sign-line { position: relative; height: 74px; margin-bottom: 10px; border-bottom: 1px solid #bdbab9; }
.sign-line canvas { --ink-pad: 24px; position: absolute; top: -24px; left: -24px; width: calc(100% + 48px); height: calc(100% + 48px); pointer-events: none; }
.sign-name, .sign-date { font-size: 15px; line-height: 22px; overflow-wrap: anywhere; }
.sign-name { margin-bottom: 2px; font-weight: 500; }
.sign-date { color: var(--muted); }
#signer-name { font-weight: 500; line-height: 20px; }

.attest { position: relative; display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 16px; padding: 16px; border-radius: 8px; background: var(--subtle); cursor: pointer; }
.attest input { position: absolute; opacity: 0; width: 16px; height: 16px; margin: 0; }
.attest-box { display: grid; place-items: center; width: 16px; height: 16px; margin-top: 2px; border: 1px solid var(--input-border); border-radius: 4px; background: var(--surface); }
.attest-box svg { width: 10px; height: 10px; fill: none; stroke: #fff; stroke-width: 36; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.attest input:checked + .attest-box { background: var(--accent-border); border-color: var(--accent-border); }
.attest input:checked + .attest-box svg { opacity: 1; }
.attest input:focus-visible + .attest-box { outline: 2px solid var(--status-info-dot); outline-offset: 2px; }
.attest-text { display: grid; gap: 2px; }
.attest-text strong { font-weight: 500; font-size: 14px; line-height: 20px; }
.attest-text span { font-size: 13px; line-height: 20px; color: var(--muted); }
.form-error { font: var(--body-small); color: var(--accent); }
.dialog-actions { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: 8px; height: 64px; padding: 0 24px; border-top: 1px solid var(--border); }

/* Mobile sign bar */
.mobile-bar { display: none; }

/* Prototype controls sit outside the product UI */
.proto-bar { position: fixed; left: 16px; bottom: 16px; z-index: 4; display: flex; align-items: center; gap: 12px; padding: 6px 12px; border-radius: 999px; background: #221f1e; color: #fff; font: var(--body-small); opacity: 0.85; }
.proto-bar span { color: #bdbab9; }
.proto-bar a, .proto-bar button { padding: 0; border: 0; background: none; color: #fff; text-decoration: underline; text-underline-offset: 3px; font: inherit; }

@media (max-width: 1140px) {
  .review { grid-template-columns: minmax(0, 760px); gap: 20px; padding-top: 20px; padding-bottom: 120px; }
  /* Paper > Mobile / D, order form card: the same panel without signers and actions */
  .panel { grid-row: 1; position: static; }
  .panel-header { padding-inline: 16px; }
  .panel-header .panel-help { display: block; }
  .details { display: flex; flex-wrap: wrap; gap: 12px 24px; padding: 16px; }
  .details > div { flex: 1 1 0; flex-direction: column; align-items: stretch; gap: 2px; min-width: 120px; }
  .details > .from { min-width: 190px; }
  .details dt { width: auto; line-height: 16px; }
  .details .from strong { line-height: 20px; }
  .details .detail-extra { display: block; }
  .signers, .panel-actions, .panel-footer .panel-help { display: none; }
  .panel-footer { padding: 12px 16px; }
  .panel-footer:not(:has(.panel-note:not([hidden]))) { display: none; }
  .mobile-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  .proto-bar { bottom: 80px; }
}

/* Too narrow for paper: the document sits flat on the page */
@media (max-width: 820px) {
  body { background: var(--surface); }
  .topbar-inner { padding: 0 16px; }
  .review, .signed-inner { width: calc(100% - 32px); }
  .agreement { padding: 8px 0 0; background: none; border: 0; border-radius: 0; box-shadow: none; }
  .panel { box-shadow: none; }
}

@media (max-width: 600px) {
  .button.with-icon { width: 34px; padding: 0; justify-content: center; }
  .button.with-icon .button-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .agreement h1 { font-size: 22px; line-height: 30px; }
  .parties, .signature-blocks { grid-template-columns: minmax(0, 1fr); }
  .doc-section { margin-top: 36px; }
  .order-table th { width: 44%; }
  .record > div { grid-template-columns: 1fr; gap: 2px; }
  .details > div, .details > .from { min-width: 104px; }
  .mobile-bar .button { padding-inline: 8px; }
  .dialog-header { padding-left: 16px; }
  .dialog-body, .dialog-actions { padding-inline: 16px; }
  .sign-body { padding: 8px 16px 16px; }
  .sign-stage { height: clamp(206px, 100dvh - 372px, 346px); padding: 0 0 20px 16px; }
  .sign-stage::after { translate: 380px calc(-50% + 3.157px); }
  .sign-page { padding: 20px 20px 32px; }
  .sign-block { width: calc(100vw - 32px - 2px - 32px - 2px - 16px - 40px); }
}

@media print {
  body { background: #fff; }
  .topbar, .panel, .mobile-bar, .proto-bar, .sign-here { display: none !important; }
  .review { display: block; width: auto; padding: 0; }
  .agreement { border: 0; box-shadow: none; padding: 0; }
}
