:root {
  --navy: #102a4c;
  --navy-deep: #0b1f39;
  --gold: #b1842f;
  --gold-soft: #fff8e7;
  --ink: #151922;
  --muted: #667085;
  --line: #d9dee7;
  --paper: #fff;
  --surface: #edf1f5;
}
* { box-sizing: border-box; }
html { color-scheme: light; background: var(--surface); scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at top, #f9fafb 0, var(--surface) 68%); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; line-height: 1.45; }
button, input, textarea, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.skip-link { position: fixed; left: 16px; top: -60px; z-index: 1000; padding: 10px 14px; border-radius: 8px; color: #fff; background: var(--navy); text-decoration: none; }
.skip-link:focus { top: 12px; }
.page-toolbar { position: sticky; z-index: 50; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 14px max(18px, calc((100vw - 1180px)/2)); border-bottom: 1px solid rgba(16,42,76,.12); background: rgba(255,255,255,.94); box-shadow: 0 10px 34px rgba(16,42,76,.07); backdrop-filter: blur(16px); }
.toolbar-brand strong, .toolbar-brand span { display: block; }
.toolbar-brand strong { color: var(--navy); font-size: .92rem; }
.toolbar-brand span { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.toolbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.tool-button { min-height: 39px; display: inline-flex; align-items: center; justify-content: center; padding: 0 13px; border: 1px solid var(--navy); border-radius: 9px; color: var(--navy); background: #fff; font-size: .75rem; font-weight: 800; text-decoration: none; cursor: pointer; }
.tool-button:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(16,42,76,.1); }
.tool-button-primary { color: #fff; background: var(--navy); }
.tool-button-gold { color: var(--navy-deep); border-color: #d3b064; background: var(--gold-soft); }
.tool-button-muted { border-color: #cfd5de; color: #475467; }
.receipt-shell { width: min(100%, 230mm); margin: 28px auto 52px; padding: 0 10mm; }
.receipt-document { position: relative; width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto; padding: 12mm 13mm 10mm; border: 1px solid #cbd3df; background: var(--paper); box-shadow: 0 28px 80px rgba(16,42,76,.18); overflow: hidden; }
.receipt-document::before { content: ""; position: absolute; inset: 0 0 auto; height: 5px; background: linear-gradient(90deg, var(--gold) 0 23%, var(--navy) 23% 100%); }
.document-header { display: grid; grid-template-columns: 1fr 31mm; gap: 8mm; align-items: start; padding-bottom: 5mm; border-bottom: 1px solid var(--line); }
.document-kicker { color: var(--gold); font-size: 8.5px; font-weight: 900; letter-spacing: .15em; text-transform: uppercase; }
.document-header h1 { margin: 3mm 0 4mm; color: var(--navy-deep); font-family: Georgia, "Times New Roman", serif; font-size: 20px; line-height: 1.18; letter-spacing: -.02em; }
.document-number { display: inline-flex; flex-wrap: wrap; gap: 5px 9px; padding: 2.2mm 3mm; border: 1px solid #d5b875; border-radius: 6px; background: var(--gold-soft); font-size: 9px; }
.document-number span { color: #765b22; font-weight: 700; }
.document-number strong { color: var(--navy); letter-spacing: .03em; }
.document-qr { padding: 2mm; border: 1px solid var(--line); border-radius: 8px; text-align: center; background: #fff; }
.document-qr img { display: block; width: 100%; height: auto; }
.document-qr span { display: block; margin-top: 1mm; color: var(--muted); font-size: 7px; font-weight: 700; }
.status-banner { display: grid; grid-template-columns: 37mm 1fr; gap: 5mm; align-items: center; margin: 4mm 0; padding: 3.5mm 4mm; border: 1px solid #d6bb7d; border-left: 4px solid var(--gold); border-radius: 7px; background: linear-gradient(90deg, #fff9ea, #fffdf8); }
.status-banner span, .status-banner strong { display: block; }
.status-banner span { color: #806528; font-size: 7.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.status-banner strong { margin-top: 1px; color: var(--navy); font-size: 15px; }
.status-banner p { margin: 0; color: #4a4e57; font-size: 9px; font-weight: 650; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.summary-grid > div { min-height: 18mm; padding: 2.8mm 3mm; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summary-grid > div:nth-child(3n) { border-right: 0; }
.summary-grid > div:nth-last-child(-n+3) { border-bottom: 0; }
.summary-grid span, .summary-grid strong, .summary-grid small { display: block; }
.summary-grid span { color: var(--muted); font-size: 7.2px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.summary-grid strong { margin-top: 1.3mm; color: var(--navy-deep); font-size: 9px; line-height: 1.25; }
.summary-grid small { margin-top: 1px; color: #765b22; font-size: 7.5px; font-style: italic; }
.editable-section, .terms-section, .transfer-section, .agreement-section { margin-top: 4mm; }
.section-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 2.2mm; }
.section-title-row h2, .terms-section h2 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: 12px; }
.section-title-row > span, .section-title-row small { color: var(--muted); font-size: 7.3px; }
.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2.1mm 4mm; }
.field { display: block; min-width: 0; }
.field-wide { grid-column: auto; }
.field-full { grid-column: 1 / -1; }
.field > span, .signature-field > span { display: block; margin-bottom: .5mm; color: #475467; font-size: 7.2px; font-weight: 750; }
.field input, .field textarea, .signature-field input { width: 100%; min-height: 7mm; padding: 1mm 1.5mm; border: 0; border-bottom: 1px solid #9ba8ba; border-radius: 0; outline: none; color: var(--ink); background: #fbfcfd; font-size: 8.5px; }
.field textarea { min-height: 10mm; resize: vertical; }
.field input:focus, .field textarea:focus, .signature-field input:focus { border-bottom-color: var(--gold); box-shadow: inset 0 -1px 0 var(--gold); }
::placeholder { color: #9aa3b0; opacity: 1; }
.terms-section { padding: 3mm 4mm; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; }
.terms-section ol { columns: 2; column-gap: 7mm; margin: 2mm 0 0; padding-left: 4.5mm; }
.terms-section li { break-inside: avoid; margin: 0 0 1.5mm; padding-left: 1mm; color: #3f4752; font-size: 7.5px; line-height: 1.34; }
.transfer-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 2.5mm 3mm; border: 1px dashed #b7c0cd; border-radius: 7px; background: #fbfcfd; }
.upload-button, .link-button { border: 0; color: var(--navy); background: transparent; font-size: 7.8px; font-weight: 800; cursor: pointer; }
.upload-button { padding: 1.5mm 2.5mm; border: 1px solid #bac4d0; border-radius: 5px; background: #fff; }
.link-button:disabled { color: #a5acb6; cursor: not-allowed; }
.file-note { color: var(--muted); font-size: 7.2px; }
.transfer-preview[hidden] { display: none !important; }
.transfer-preview { display: grid; grid-template-columns: 37mm 1fr; gap: 4mm; align-items: center; margin: 2mm 0 0; padding: 2mm; border: 1px solid var(--line); border-radius: 7px; }
.transfer-preview img { display: block; width: 37mm; max-height: 25mm; object-fit: contain; background: #f2f4f7; }
.transfer-preview figcaption { color: var(--muted); font-size: 7.2px; }
.agreement-text { margin: 0 0 3mm; padding: 2.8mm 4mm; border-left: 3px solid var(--navy); color: #3e4652; background: #f6f8fb; font-size: 8px; font-style: italic; }
.signature-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6mm; }
.signature-card { position: relative; padding: 3mm; border: 1px solid var(--line); border-radius: 8px; break-inside: avoid; }
.signature-heading span, .signature-heading strong { display: block; }
.signature-heading span { color: var(--gold); font-size: 7.2px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.signature-heading strong { margin-top: .6mm; color: var(--navy); font-size: 8.5px; }
.signature-pad-wrap { position: relative; height: 24mm; margin: 2mm 0 1mm; border: 1px dashed #a9b3c0; border-radius: 5px; background: linear-gradient(#fff, #fbfcfd); overflow: hidden; touch-action: none; }
.signature-pad { position: relative; z-index: 2; display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.signature-placeholder { position: absolute; z-index: 1; left: 0; right: 0; bottom: 2mm; color: #a4acb7; text-align: center; font-size: 7px; pointer-events: none; }
.signature-pad-wrap.has-signature .signature-placeholder { opacity: 0; }
.clear-signature { padding: 0; border: 0; color: #6b7280; background: transparent; font-size: 7px; font-weight: 750; cursor: pointer; }
.signature-field { display: grid; grid-template-columns: 26mm 1fr; align-items: center; gap: 2mm; margin-top: 1.4mm; }
.signature-field > span { margin: 0; }
.signature-field input { min-height: 6mm; font-size: 8px; }
.document-footer { display: grid; grid-template-columns: 1fr auto; gap: 6mm; align-items: end; margin-top: 3mm; padding-top: 2.5mm; border-top: 1px solid var(--line); color: var(--muted); font-size: 6.7px; }
.document-footer p { margin: 0; max-width: 145mm; }
.document-footer div { text-align: right; }
.document-footer span, .document-footer strong { display: block; }
.document-footer strong { margin-top: 1mm; color: var(--navy); font-size: 7px; }
.toast { position: fixed; z-index: 200; right: 18px; bottom: 18px; max-width: 340px; padding: 12px 15px; border-radius: 9px; color: #fff; background: var(--navy-deep); box-shadow: 0 16px 38px rgba(11,31,57,.25); font-size: .8rem; }
:focus-visible { outline: 3px solid rgba(177,132,47,.4); outline-offset: 2px; }

@media (max-width: 980px) {
  .page-toolbar { position: static; align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; justify-content: flex-start; }
  .receipt-shell { padding: 0 12px; }
}
@media (max-width: 720px) {
  .page-toolbar { padding: 13px 12px; }
  .toolbar-actions { display: grid; grid-template-columns: repeat(2, 1fr); }
  .tool-button { width: 100%; }
  .receipt-shell { margin-top: 14px; }
  .receipt-document { min-height: 0; padding: 22px 16px; }
  .document-header { grid-template-columns: 1fr 84px; gap: 14px; }
  .document-header h1 { font-size: 16px; }
  .status-banner { grid-template-columns: 1fr; gap: 5px; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-grid > div { border-right: 0; border-bottom: 1px solid var(--line) !important; }
  .summary-grid > div:last-child { border-bottom: 0 !important; }
  .field-grid, .signature-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
  .terms-section ol { columns: 1; }
  .document-footer { grid-template-columns: 1fr; }
  .document-footer div { text-align: left; }
}

@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { width: 210mm; min-height: 297mm; background: #fff !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  body { margin: 0; }
  .page-toolbar, .skip-link, .toast, .no-print, .transfer-controls { display: none !important; }
  .receipt-shell { width: 210mm; margin: 0; padding: 0; }
  .receipt-document { width: 210mm; max-width: none; min-height: 297mm; margin: 0; padding: 8mm 10mm 7mm; border: 0; box-shadow: none; overflow: visible; }
  .receipt-document::before { height: 4px; }
  .document-header { grid-template-columns: 1fr 27mm; gap: 6mm; padding-bottom: 3.5mm; }
  .document-header h1 { margin: 2mm 0 3mm; font-size: 17px; }
  .document-number { padding: 1.5mm 2mm; }
  .status-banner { margin: 3mm 0; padding: 2.5mm 3mm; }
  .summary-grid > div { min-height: 15.5mm; padding: 2.2mm 2.5mm; }
  .editable-section, .terms-section, .transfer-section, .agreement-section { margin-top: 3mm; }
  .field-grid { gap: 1.4mm 3.5mm; }
  .field input, .field textarea, .signature-field input { min-height: 5.7mm; padding: .5mm 1mm; background: #fff; }
  .field textarea { min-height: 7mm; }
  .terms-section { padding: 2.2mm 3mm; }
  .terms-section ol { margin-top: 1.3mm; }
  .terms-section li { margin-bottom: 1mm; font-size: 7.1px; line-height: 1.28; }
  .transfer-section:not(:has(.transfer-preview:not([hidden]))) .transfer-controls { display: none !important; }
  .transfer-section:not(:has(.transfer-preview:not([hidden]))) { display: none !important; }
  .transfer-preview { grid-template-columns: 30mm 1fr; margin-top: 1mm; padding: 1.5mm; }
  .transfer-preview img { width: 30mm; max-height: 20mm; }
  .agreement-text { margin-bottom: 2mm; padding: 2mm 3mm; }
  .signature-grid { gap: 4mm; }
  .signature-card { padding: 2mm; }
  .signature-pad-wrap { height: 20mm; margin: 1.3mm 0 .7mm; }
  .signature-field { margin-top: .8mm; }
  .document-footer { margin-top: 2mm; padding-top: 1.8mm; }
  section, .signature-card, .terms-section, .document-footer { break-inside: avoid; page-break-inside: avoid; }
}

@media print {
  body:has(.transfer-preview:not([hidden])) .receipt-document { padding-top: 6mm; padding-bottom: 5mm; }
  body:has(.transfer-preview:not([hidden])) .document-header { padding-bottom: 2.5mm; }
  body:has(.transfer-preview:not([hidden])) .document-header h1 { margin: 1.4mm 0 2mm; font-size: 16px; }
  body:has(.transfer-preview:not([hidden])) .status-banner { margin: 2mm 0; padding: 2mm 3mm; }
  body:has(.transfer-preview:not([hidden])) .summary-grid > div { min-height: 14mm; padding: 1.8mm 2.3mm; }
  body:has(.transfer-preview:not([hidden])) .editable-section,
  body:has(.transfer-preview:not([hidden])) .terms-section,
  body:has(.transfer-preview:not([hidden])) .transfer-section,
  body:has(.transfer-preview:not([hidden])) .agreement-section { margin-top: 2mm; }
  body:has(.transfer-preview:not([hidden])) .field-grid { gap: 1mm 3mm; }
  body:has(.transfer-preview:not([hidden])) .field input,
  body:has(.transfer-preview:not([hidden])) .field textarea,
  body:has(.transfer-preview:not([hidden])) .signature-field input { min-height: 5mm; }
  body:has(.transfer-preview:not([hidden])) .field textarea { min-height: 6mm; }
  body:has(.transfer-preview:not([hidden])) .terms-section { padding: 1.7mm 2.5mm; }
  body:has(.transfer-preview:not([hidden])) .terms-section li { margin-bottom: .7mm; font-size: 6.8px; line-height: 1.23; }
  body:has(.transfer-preview:not([hidden])) .transfer-preview { grid-template-columns: 27mm 1fr; gap: 2.5mm; margin-top: .7mm; padding: 1mm; }
  body:has(.transfer-preview:not([hidden])) .transfer-preview img { width: 27mm; max-height: 14mm; }
  body:has(.transfer-preview:not([hidden])) .agreement-text { margin-bottom: 1.4mm; padding: 1.6mm 2.5mm; font-size: 7.3px; }
  body:has(.transfer-preview:not([hidden])) .signature-card { padding: 1.5mm; }
  body:has(.transfer-preview:not([hidden])) .signature-pad-wrap { height: 15mm; margin: 1mm 0 .5mm; }
  body:has(.transfer-preview:not([hidden])) .signature-field { margin-top: .5mm; }
  body:has(.transfer-preview:not([hidden])) .document-footer { margin-top: 1.3mm; padding-top: 1.2mm; }
}

/* Cloudflare server workflow */
.server-panel { width: min(1180px, calc(100% - 28px)); margin: 22px auto 0; padding: 20px; border: 1px solid #d8dee8; border-radius: 14px; background: #fff; box-shadow: 0 14px 40px rgba(11,31,57,.08); }
.server-panel-heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.server-panel-heading h2 { margin: 4px 0 6px; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.12rem, 2vw, 1.5rem); }
.server-panel-heading p { max-width: 850px; margin: 0; color: #5c6675; font-size: .88rem; line-height: 1.55; }
.server-kicker { color: var(--gold); font-size: .7rem; font-weight: 900; letter-spacing: .15em; text-transform: uppercase; }
.mode-badge { flex: 0 0 auto; padding: 7px 11px; border: 1px solid #ccd4df; border-radius: 999px; color: var(--navy); background: #f7f9fc; font-size: .74rem; font-weight: 850; }
.mode-badge.is-owner { color: #fff; border-color: var(--navy); background: var(--navy); }
.mode-badge.is-recipient { color: #694e16; border-color: #e4ca8f; background: #fff7df; }
.server-grid { display: grid; grid-template-columns: minmax(260px, .85fr) minmax(320px, 1.15fr); gap: 18px; margin-top: 18px; }
.server-field > span { display: block; margin-bottom: 6px; color: #344054; font-size: .78rem; font-weight: 800; }
.server-field input { width: 100%; min-height: 43px; padding: 10px 12px; border: 1px solid #c9d1dc; border-radius: 8px; color: #182230; background: #fff; font-size: .9rem; }
.server-field small, .share-row small { display: block; margin-top: 6px; color: #697386; font-size: .72rem; line-height: 1.45; }
.server-security { min-width: 0; padding: 13px; border: 1px solid #e0e5ec; border-radius: 10px; background: #fafbfc; }
.consent-row { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; color: #4c5666; font-size: .75rem; line-height: 1.45; }
.consent-row input { margin-top: 2px; accent-color: var(--navy); }
.server-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.server-button { min-height: 40px; padding: 9px 14px; border: 1px solid #bfc8d4; border-radius: 8px; color: var(--navy); background: #fff; font-size: .78rem; font-weight: 850; cursor: pointer; }
.server-button:hover { background: #f7f9fc; }
.server-button:disabled { opacity: .55; cursor: wait; }
.server-button-primary { color: #fff; border-color: var(--navy); background: var(--navy); }
.server-button-primary:hover { background: #183b67; }
.server-button-danger { color: #9f1d22; border-color: #e0b3b5; }
.share-box { display: grid; gap: 12px; margin-top: 16px; padding: 14px; border: 1px solid #d6dee8; border-radius: 10px; background: #f8fafc; }
.share-row label { display: block; margin-bottom: 5px; color: #344054; font-size: .75rem; font-weight: 850; }
.share-row > div { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.share-row input { min-width: 0; padding: 9px 10px; border: 1px solid #c7d0dc; border-radius: 7px; color: #253247; background: #fff; font-size: .76rem; }
.share-row button { padding: 8px 12px; border: 0; border-radius: 7px; color: #fff; background: var(--navy); font-size: .75rem; font-weight: 850; cursor: pointer; }
.server-status { margin: 14px 0 0; padding: 10px 12px; border-left: 3px solid var(--gold); color: #455064; background: #fffaf0; font-size: .78rem; line-height: 1.5; }
.server-status.is-error { border-left-color: #b4232a; color: #8d1b20; background: #fff4f4; }
.server-status.is-success { border-left-color: #237a4b; color: #17643c; background: #f0fbf5; }
.privacy-note { margin: 10px 0 0; color: #70798a; font-size: .7rem; line-height: 1.45; }
.privacy-note code { padding: 1px 4px; border-radius: 4px; color: #344054; background: #edf1f6; }
.receipt-document.is-loading { opacity: .55; pointer-events: none; }
.receipt-document input[readonly], .receipt-document textarea[readonly] { color: #475467; background: #f3f5f8; cursor: default; }
.signature-card.is-locked .signature-pad { cursor: default; }
.signature-card.is-locked .signature-pad-wrap { background: #f7f8fa; }
.document-footer small { display: block; margin-top: .7mm; color: #697386; font-size: 6.2px; }

@media (max-width: 760px) {
  .server-panel { width: calc(100% - 24px); padding: 16px 13px; }
  .server-panel-heading { flex-direction: column; gap: 10px; }
  .server-grid { grid-template-columns: 1fr; }
  .server-actions { display: grid; grid-template-columns: 1fr; }
  .server-button { width: 100%; }
  .share-row > div { grid-template-columns: 1fr; }
  .share-row button { width: 100%; }
}

@media print {
  .server-panel { display: none !important; }
}

[hidden] { display: none !important; }
