/* The PDF canvas and exported text keep their own embedded font. */
@font-face {
  font-family: FormularSans;
  src: url('./fonts/NotoSans-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* Agency interface: system Arial regular/bold, independent of PDF metrics. */
:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  color: #17382a;
  background: #f1f6f2;
  font-synthesis: none;
  --green: #009b31;
  --dark-green: #007a2f;
  --ink: #17382a;
  --muted: #50645b;
  --line: #d5e1d9;
  --pale: #e9f3eb;
  --paper: #fff;
  --viewport-height: 100dvh;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
}
* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
body { margin: 0; min-width: 280px; font-size: 16px; line-height: 1.5; }
button, input, textarea, select { font: inherit; }
button, a, summary { touch-action: manipulation; }
button, [role='button'], summary { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
a { color: #006d2d; text-underline-offset: 3px; }
input, textarea, select { font-size: 16px; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, summary:focus-visible, [tabindex]:focus-visible { outline: 3px solid #165fd7; outline-offset: 3px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, p { margin: 0; }
h1, h2, strong { font-weight: 700; }
h1, h2 { letter-spacing: -.025em; }
h1 { font-size: clamp(32px, 4vw, 48px); line-height: 1.08; }
h2 { font-size: 26px; line-height: 1.2; }
p { line-height: 1.55; }
[hidden] { display: none !important; }
.skip-link { position: absolute; z-index: 400; top: 8px; left: 8px; background: #fff; padding: 14px; transform: translateY(-160%); }
.skip-link:focus { transform: none; }

/* Compact, familiar agency header. */
.site-header { min-height: 84px; display: flex; align-items: center; gap: 24px; padding: calc(10px + env(safe-area-inset-top, 0px)) max(24px, calc((100vw - 1160px) / 2), env(safe-area-inset-left, 0px)) 10px; border-bottom: 1px solid var(--line); background: #fff; }
.brand { display: flex; align-items: center; min-height: 44px; }
.brand img { display: block; width: 160px; height: 56px; object-fit: cover; object-position: center; }
.service-label { font-size: 14px; color: var(--muted); border-left: 1px solid var(--line); padding-left: 24px; }
.help-link { margin-left: auto; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; min-width: 44px; padding: 0 12px; border-radius: 8px; text-decoration: none; font-size: 16px; font-weight: 700; }
.help-link svg { width: 20px; height: 20px; }
main { width: min(100%, 1208px); margin: auto; padding: 0 24px; }
.eyebrow { display: block; color: #006d2d; font-size: 14px; line-height: 1.4; font-weight: 700; }
.site-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 auto; padding: 16px max(24px, calc((100vw - 1160px) / 2), env(safe-area-inset-left, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)); background: #fff; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.site-footer nav { display: flex; gap: 20px; }
.site-footer a { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; color: var(--muted); }

/* Controls share real touch targets and restrained pointer feedback. */
.button { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 48px; min-width: 44px; border: 1px solid transparent; border-radius: 8px; padding: 12px 18px; font-size: 16px; font-weight: 700; line-height: 1.35; text-align: center; text-decoration: none; box-shadow: none; }
.primary { color: #fff; background: var(--dark-green); }
.primary span[aria-hidden] { font-size: 20px; line-height: 1; }
.secondary { color: #006d2d; background: #fff; border-color: #b4c9bb; }
.subtle { color: var(--ink); background: #fff; border-color: var(--line); }
.danger { color: #962c22; background: #fff8f6; border-color: #d8a9a0; }
.square-button { display: inline-flex; justify-content: center; align-items: center; min-width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font-size: 26px; line-height: 1; }
.button, .square-button, .tool, .zoom-label, .help-link, .inline-link, .field-list-item, #saved-signatures button { transition: transform 120ms var(--ease-out); }
.button:active:not(:disabled), .square-button:active:not(:disabled), .tool:active:not(:disabled), .zoom-label:active:not(:disabled), .help-link:active, .inline-link:active, .field-list-item:active, #saved-signatures button:active { transform: scale(.98); }
.small-note { font-size: 14px; line-height: 1.5; color: var(--muted); }
.inline-link { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; padding: 4px 0; border: 0; background: transparent; color: #006d2d; font: inherit; text-decoration: underline; text-underline-offset: 3px; }
.notice { margin-top: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #f1f6f2; color: var(--ink); font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.notice.error { color: #8b291d; background: #fff0ec; border-color: #d8a9a0; }
.notice.success { color: #185d27; background: #e8f5e9; border-color: #b3d6b5; }
.notice a { color: inherit; }

/* Entry: one useful action, three consistent steps, early delivery status. */
.start-view { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr); align-items: center; gap: 72px; padding: 48px 0 52px; }
.intro h1 { margin: 12px 0 18px; }
.intro-copy { color: var(--muted); font-size: 18px; max-width: 540px; }
.upload-card { display: flex; flex-direction: column; align-items: center; margin-top: 24px; padding: 22px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.upload-card.drag-over { outline: 2px solid var(--dark-green); outline-offset: -2px; background: var(--pale); }
.upload-card .primary { width: 100%; }
.upload-meta { margin-top: 12px; font-size: 14px; color: var(--muted); text-align: center; }
.drop-hint { margin-top: 4px; font-size: 14px; color: var(--muted); text-align: center; }
.local-note { display: flex; gap: 10px; align-items: flex-start; margin-top: 18px; color: var(--muted); font-size: 14px; }
.local-note svg { flex: 0 0 21px; height: 23px; margin-top: 1px; color: #006d2d; }
.entry-readiness { min-height: 66px; margin-top: 12px; padding-left: 31px; font-size: 14px; color: var(--muted); }
.steps-card { padding-left: 34px; border-left: 1px solid var(--line); }
.steps-title { color: var(--ink); font-size: 22px; }
.steps-list { display: grid; gap: 26px; list-style: none; margin: 28px 0; padding: 0; }
.steps-list li { display: flex; align-items: flex-start; gap: 14px; }
.step-number { display: flex; align-items: center; justify-content: center; flex: 0 0 30px; height: 30px; border-radius: 8px; background: var(--pale); color: #006d2d; font-size: 16px; font-weight: 700; }
.steps-list strong { display: block; margin: 2px 0 4px; font-size: 16px; line-height: 1.35; }
.steps-list li div > span { display: block; color: var(--muted); font-size: 14px; line-height: 1.5; }
.agent-note { padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.agent-note a { display: inline-flex; align-items: center; min-height: 44px; }

/* Document workspace: navigation, PDF and tools occupy separate layout space. */
.document-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 24px 0 20px; }
.document-heading > div { min-width: 0; }
.document-heading h1 { margin: 5px 0 6px; font-size: 30px; line-height: 1.15; }
.document-heading p { color: var(--muted); font-size: 14px; }
.filename { max-width: 75ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-heading > .button { flex-shrink: 0; font-size: 14px; }
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 282px; gap: 0; align-items: start; margin-bottom: 32px; border: 1px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden; }
.document-workspace, .review-document { min-width: 0; background: #e6ede8; }
.document-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0 8px; min-height: 54px; padding: 4px 8px; background: #fff; border-bottom: 1px solid var(--line); }
.page-controls, .zoom-controls { display: flex; align-items: center; gap: 0; }
.page-label { display: flex; gap: 3px; align-items: center; white-space: nowrap; font-size: 14px; }
.page-label select { min-height: 44px; min-width: 44px; max-width: 64px; border: 0; border-radius: 4px; padding: 6px 2px; color: var(--ink); background: #fff; }
.zoom-label { min-height: 44px; min-width: 54px; width: 54px; padding: 4px; white-space: pre-line; line-height: 1.1; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: 14px; font-variant-numeric: tabular-nums; }
.paper-scroll, .review-paper-scroll { position: relative; height: clamp(360px, 67dvh, 850px); overflow: auto; padding: 15px; scrollbar-gutter: stable; }
.paper { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 2px 8px #17382a15; user-select: none; -webkit-user-select: none; }
.paper canvas { display: block; }
.canvas-caption { padding: 10px 14px; border-top: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 14px; line-height: 1.4; }
.editor-sidebar { min-width: 0; padding: 20px 16px; border-left: 1px solid var(--line); background: #fff; }
.sidebar-intro { margin-bottom: 18px; }
.sidebar-intro h2 { margin-bottom: 8px; font-size: 22px; }
.sidebar-intro p { font-size: 14px; color: var(--muted); }
.tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 44px; min-height: 74px; padding: 10px 5px; border: 1px solid #b4c9bb; border-radius: 8px; background: #fff; color: var(--ink); font-size: 14px; line-height: 1.2; }
.tool-icon { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; flex-shrink: 0; font-size: 24px; line-height: 1; }
.tool[aria-pressed='true'] { border-color: var(--dark-green); outline: 1px solid var(--dark-green); outline-offset: -2px; background: var(--pale); color: #006d2d; }
.selected-panel { margin-top: 14px; padding: 12px; border: 1px solid #b4c9bb; border-radius: 8px; background: #f1f6f2; }
.selected-panel > strong { display: block; font-size: 14px; }
.selected-panel .small-note { margin-top: 8px; }
.selection-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.selection-buttons .button { min-height: 44px; padding: 8px 10px; font-size: 14px; }
.field-list-button { width: 100%; margin-top: 12px; font-size: 14px; }
.edit-next { margin-top: 18px; }
.edit-next .primary { width: 100%; padding: 12px; font-size: 16px; }

/* PDF overlays: absolute geometry and font metrics are not UI styling. */
.field-layer, .addition-layer { position: absolute; inset: 0; pointer-events: none; }
.field-button { position: absolute; min-width: 44px; min-height: 44px; border: 0; border-radius: 2px; padding: 0; background: transparent; color: #173428; pointer-events: auto; overflow: visible; text-align: left; font-size: 11px; line-height: 1.2; cursor: text; }
.field-button .field-preview { display: block; width: 100%; height: 100%; padding: 0; border: 1px solid #6c8d74; border-radius: 2px; background: #f2fbf0; font-family: FormularSans, sans-serif; font-weight: 400; white-space: pre-wrap; overflow: hidden; pointer-events: none; }
.field-button.readonly { cursor: default; }
.field-button.readonly .field-preview { border: 1px dashed #8c9990; background: #fafbf9; }
.field-button .field-preview.field-warning { border: 2px solid #a84314; background: #fff2e6; }
.field-button.bool-field { font-size: 14px; cursor: pointer; }
.field-button.bool-field .field-preview { display: flex; align-items: center; justify-content: center; font-size: min(18px, 100%); }
.field-button:focus-visible { z-index: 9; outline-offset: 1px; }
.addition { position: absolute; min-width: 44px; min-height: 44px; border: 0; border-radius: 2px; padding: 0; background: transparent; color: #111; pointer-events: auto; text-align: left; transform-origin: 0 0; overflow: visible; cursor: pointer; touch-action: pan-y pinch-zoom; }
/* Only an explicitly selected annotation owns the next drag gesture. */
.addition.selected { cursor: grab; touch-action: none; }
.addition.dragging { cursor: grabbing; }
.overlay-visual { position: absolute; display: block; pointer-events: none; }
.addition.selected .overlay-visual { outline: 2px solid #006d2d; outline-offset: 3px; background: #009b3109; }
.addition img { display: block; width: 100%; height: 100%; pointer-events: none; }
.addition-text { display: block; color: #141f19; font-family: FormularSans, sans-serif; font-weight: 400; line-height: 1.3; white-space: pre; pointer-events: none; }
.addition-mark { width: 100%; height: 100%; stroke: #152a20; stroke-width: 2; pointer-events: none; }

/* Review renders the exported PDF, with its own navigation and zoom. */
.review-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; gap: 24px; padding-bottom: 32px; }
.review-document { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.review-paper-scroll canvas { display: block; margin: auto; background: #fff; box-shadow: 0 2px 8px #17382a15; }
.file-facts { display: flex; justify-content: space-between; gap: 14px; padding: 12px 14px; border-top: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 14px; }
.file-facts strong { min-width: 0; overflow-wrap: anywhere; font-weight: 400; }
.file-facts > span { flex-shrink: 0; white-space: nowrap; }
.send-panel { padding: 22px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.send-panel h2 { margin: 8px 0 20px; font-size: 26px; }
.recipient-label { padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.recipient-label strong { display: block; margin-top: 3px; color: var(--ink); font-size: 16px; overflow-wrap: anywhere; }
.contact-details { margin: 10px 0 4px; }
.contact-details summary { min-height: 44px; padding: 11px 0; font-size: 14px; cursor: pointer; }
.contact-details summary span { color: var(--muted); }
.form-fields { display: grid; gap: 14px; padding: 10px 0; }
.form-fields label, #text-input-container label { display: grid; min-width: 0; gap: 8px; color: var(--muted); font-size: 14px; }
input[type='text'], input[type='email'], textarea, #text-input-container select { width: 100%; min-height: 48px; padding: 12px; border: 1px solid #7c8c80; border-radius: 8px; background: #fff; color: var(--ink); line-height: 1.4; }
textarea { min-height: 90px; resize: vertical; }
.review-confirm { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 0; font-size: 16px; line-height: 1.4; cursor: pointer; }
.review-confirm input { width: 22px; height: 22px; margin: 0; flex-shrink: 0; accent-color: var(--dark-green); }
.review-actions { display: grid; gap: 10px; margin-top: 16px; }
.review-actions .button { width: 100%; }
.send-help { margin-top: 12px; }
.send-help a { display: inline-flex; align-items: center; min-height: 44px; }
.privacy-small { margin-top: 16px; color: var(--muted); font-size: 14px; line-height: 1.55; }

/* Native dialogs keep focus, viewport and keyboard handling in the browser. */
.sheet { width: 100%; max-width: min(550px, calc(100vw - 32px)); max-height: calc(var(--viewport-height) - 32px); padding: 24px; overflow: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); box-shadow: 0 16px 60px #17382a24; opacity: 1; transform: translateY(0); }
.sheet::backdrop { background: #17382a80; }
.sheet[open]:not(.keyboard-open) { transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out); }
@starting-style { .sheet[open]:not(.keyboard-open) { opacity: 0; transform: translateY(6px); } }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dialog-heading > div { min-width: 0; }
.dialog-heading h2 { font-size: 26px; overflow-wrap: anywhere; }
.dialog-heading .eyebrow { margin-bottom: 5px; }
.dialog-heading .square-button { flex-shrink: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 4px; }
.dialog-actions .button { flex: 1; max-width: 220px; }
.size-label { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--muted); font-size: 14px; }
.size-label select { min-width: 70px; min-height: 44px; padding: 8px; border: 1px solid #7c8c80; border-radius: 8px; background: #fff; color: var(--ink); }
.signature-sheet { max-width: min(700px, calc(100vw - 32px)); }
.signature-canvas-wrap { position: relative; width: 100%; height: 230px; overflow: hidden; border: 1px solid #7c8c80; border-radius: 8px; background: #f8fbf8; }
.signature-canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; touch-action: none; }
.signature-guide { position: absolute; bottom: 46px; left: 24px; right: 24px; border-top: 1px dashed #a4b6a5; pointer-events: none; }
.signature-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #50645b; font-size: 18px; font-style: italic; pointer-events: none; }
.signature-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 12px 0; }
.signature-footer .button { flex-shrink: 0; font-size: 14px; }
.signature-footer > .small-note { max-width: 240px; text-align: right; }
.signature-saved { margin-bottom: 14px; color: var(--muted); font-size: 14px; }
#saved-signatures { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
#saved-signatures button { width: 112px; height: 56px; padding: 5px; border: 1px solid #b4c9bb; border-radius: 8px; background: #fff; }
#saved-signatures img { display: block; width: 100%; height: 100%; object-fit: contain; }
.check-options { display: flex; gap: 12px; }
.check-options .button { flex: 1; }
.check-options .button span { font-size: 24px; }
.compact-sheet > .small-note { margin-top: 16px; }
.field-list-item { width: 100%; min-height: 60px; margin-top: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #f1f6f2; color: var(--ink); text-align: left; }
.field-list-item strong { display: block; font-size: 16px; overflow-wrap: anywhere; }
.field-list-item span { display: block; margin-top: 4px; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
#privacy-dialog > p { margin: 14px 0; font-size: 16px; }
#privacy-dialog > .button { margin-top: 10px; }
.choice-list { display: grid; gap: 8px; }
#text-input-container .choice-label { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); font-size: 16px; }
.choice-label input { width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--dark-green); }

/* Work-in-progress feedback does not move the document underneath. */
.busy-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: #f1f6f2e6; }
.busy-card { max-width: 440px; padding: 28px; border: 1px solid var(--line); border-radius: 12px; background: #fff; text-align: center; }
.busy-card strong { display: block; margin-top: 14px; font-size: 18px; }
.busy-card p { margin-top: 8px; color: var(--muted); font-size: 14px; }
.spinner { display: inline-block; width: 28px; height: 28px; border: 2px solid #c5dbcd; border-top-color: var(--dark-green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; z-index: 300; width: max-content; max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 14px; line-height: 1.5; transform: translateX(-50%); }

/* Personal links use the same document workspace and agency vocabulary. */
.customer-view { max-width: 820px; margin: 0 auto; padding: 40px 0 48px; }
.customer-card { padding: 32px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.customer-card h1 { margin: 14px 0 18px; font-size: clamp(30px, 4vw, 40px); overflow-wrap: anywhere; }
.customer-card .intro-copy { max-width: none; }
.customer-facts { display: grid; gap: 16px; margin: 24px 0; padding: 20px 0; border-block: 1px solid var(--line); }
.customer-facts > div { display: grid; grid-template-columns: minmax(130px, .7fr) minmax(0, 1.3fr); gap: 12px; align-items: baseline; }
.customer-facts dt { color: var(--muted); font-size: 14px; }
.customer-facts dd { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.customer-message { margin-bottom: 20px; padding-left: 16px; border-left: 3px solid var(--dark-green); white-space: pre-wrap; overflow-wrap: anywhere; }
.customer-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 22px 0; }
.customer-help { display: inline-flex; align-items: center; min-height: 44px; margin-top: 14px; font-size: 16px; }
.customer-context { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.customer-context > div { display: grid; min-width: 0; gap: 4px; }
.customer-context strong { font-size: 16px; overflow-wrap: anywhere; }
.customer-context span { color: var(--muted); font-size: 14px; }
.customer-context button { flex-shrink: 0; font-size: 14px; }
.customer-card .notice { margin-block: 18px; }

/* Hover is an enhancement for precise pointers; touch always gets press feedback. */
@media (hover: hover) and (pointer: fine) {
  .primary:hover:not(:disabled) { background: #006426; }
  .secondary:hover:not(:disabled), .subtle:hover:not(:disabled), .tool:hover:not(:disabled), .square-button:hover:not(:disabled), .zoom-label:hover, .help-link:hover, .field-list-item:hover { background: var(--pale); }
  .field-button:hover .field-preview { background: #e7f5e3; }
  .addition:hover .overlay-visual { outline: 1px dashed #006d2d; }
  .addition.selected:hover .overlay-visual { outline: 2px solid #006d2d; }
}

/* Tablets retain a large document area; tools move into a compact reserved row. */
@media (max-width: 960px) {
  .start-view { gap: 36px; }
  .steps-card { padding-left: 24px; }
  .editor-layout { grid-template-columns: minmax(0, 1fr); }
  .editor-sidebar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 12px 16px; padding: 12px 16px 16px; border-left: 0; border-top: 1px solid var(--line); }
  .sidebar-intro { display: none; }
  .tools { grid-column: 1 / -1; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tool { flex-direction: row; min-height: 48px; padding: 9px 8px; }
  .selected-panel { grid-column: 1 / -1; margin-top: 0; }
  .field-list-button, .edit-next { margin-top: 0; }
  .field-list-button { width: auto; }
  .edit-next .primary { padding-inline: 16px; }
  .paper-scroll { height: clamp(340px, 60dvh, 740px); }
  .review-layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
  .review-layout .document-controls { justify-content: center; }
  .send-panel { padding: 18px; }
}

/* Phones use normal flow, not an overlay dock. Low viewports can always scroll. */
@media (max-width: 700px), (max-width: 960px) and (max-height: 550px) {
  .site-header { min-height: 64px; gap: 12px; padding: calc(8px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); }
  .brand img { width: 142px; height: 48px; }
  .service-label { display: none; }
  .help-link { padding-inline: 8px; }
  main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .start-view { display: block; padding: 26px 0 30px; }
  .intro h1 { margin: 10px 0 14px; font-size: 36px; }
  .intro-copy { font-size: 17px; }
  .upload-card { margin-top: 20px; padding: 16px; }
  .drop-hint { display: none; }
  .local-note { margin-top: 16px; }
  .entry-readiness { min-height: 66px; }
  .steps-card { margin-top: 20px; padding: 20px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .steps-title { font-size: 22px; }
  .steps-list { gap: 16px; margin: 18px 0 20px; }
  .steps-list strong { font-size: 16px; margin-top: 2px; }
  .agent-note { padding-top: 14px; }
  .site-footer { display: block; padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
  .site-footer nav { gap: 22px; margin-top: 4px; }
  .document-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 0; }
  .document-heading h1 { font-size: 22px; }
  .document-heading > .button { min-height: 44px; padding: 10px 12px; }
  body:has(#editor-view:not([hidden])) { display: flex; flex-direction: column; height: 100dvh; }
  body:has(#editor-view:not([hidden])) .site-header { flex: 0 0 auto; }
  body:has(#editor-view:not([hidden])) main { display: flex; flex: 1 0 0; flex-direction: column; min-height: 0; }
  body:has(#editor-view:not([hidden])) .site-footer { display: none; }
  .editor-view { display: flex; flex: 1; flex-direction: column; min-height: 0; }
  .editor-view .document-heading, .customer-context { flex: 0 0 auto; }
  .editor-layout { flex: 1 0 0; align-items: stretch; grid-template-rows: minmax(min-content, 1fr) auto; min-height: min-content; margin: 0 -16px; border-left: 0; border-right: 0; border-radius: 0; }
  .document-workspace { display: grid; grid-template-rows: auto minmax(220px, 1fr) auto; min-height: 0; }
  .document-controls { padding: 4px; column-gap: 0; justify-content: space-between; }
  .paper-scroll { height: auto; min-height: 220px; contain: size; }
  .canvas-caption { padding: 6px 14px; }
  .editor-sidebar { grid-template-columns: minmax(0, 1fr) auto; padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px)); gap: 6px; }
  .tool { flex-direction: column; gap: 4px; padding: 7px 2px; min-height: 62px; }
  .field-list-button { width: auto; min-height: 44px; padding: 8px 0; border-color: transparent; justify-self: start; text-decoration: underline; text-underline-offset: 3px; }
  .edit-next { width: 100%; }
  .edit-next .primary { min-height: 48px; }
  .selection-buttons .button { padding: 8px 4px; }
  .selected-panel { padding: 8px; }
  .selected-panel .small-note { display: none; }
  .review-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; padding-bottom: 24px; }
  .review-layout .document-controls { justify-content: space-between; }
  .review-paper-scroll { height: clamp(300px, 56dvh, 680px); }
  .send-panel { padding: 20px; }
  .send-panel h2 { margin-bottom: 16px; }
  .sheet { width: 100%; max-width: 100%; max-height: calc(var(--viewport-height) - 12px); margin: auto 0 0; bottom: var(--keyboard-offset, 0px); padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px)); border-radius: 12px 12px 0 0; }
  .dialog-actions .button { max-width: none; }
  .signature-sheet { max-width: 100%; }
  .signature-footer { gap: 12px; }
  .signature-footer > .small-note { max-width: 190px; }
  .customer-view { padding: 24px 0 32px; }
  .customer-card { padding: 24px 20px; }
  .customer-facts > div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .customer-actions { flex-direction: column; }
  .customer-actions .button { width: 100%; }
  .customer-context { flex-wrap: wrap; gap: 8px; }
}
@media (max-width: 370px) {
  .tools { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .tool { flex-direction: row; min-height: 44px; padding: 8px; }
  .field-list-button { justify-self: start; width: auto; padding: 8px 0; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; }
  .selection-buttons { gap: 6px; }
  .intro h1 { font-size: 32px; }
  .page-word { display: none; }
  .document-controls, .review-layout .document-controls { justify-content: space-between; column-gap: 0; }
  .signature-footer { align-items: flex-start; }
  .signature-footer > .small-note { max-width: 140px; }
  .sheet { padding-inline: 16px; }
  .signature-canvas-wrap { height: 200px; }
  .send-panel { padding: 16px; }
}
@media (orientation: landscape) and (max-height: 550px) {
  .review-paper-scroll { height: 62dvh; min-height: 240px; }
  .signature-canvas-wrap { height: 140px; }
  .signature-sheet { padding-top: 14px; }
  .signature-sheet .dialog-heading { margin-bottom: 10px; }
  .signature-sheet .dialog-actions { margin-top: 12px; }
}
/* Keyboard interactions remain immediate; reduced motion removes movement. */
html[data-input-mode='keyboard'] :is(.button, .square-button, .tool, .zoom-label, .help-link, .inline-link, .field-list-item, #saved-signatures button, .sheet) { transition: none; }
html[data-input-mode='keyboard'] :is(.button, .square-button, .tool, .zoom-label, .help-link, .inline-link, .field-list-item, #saved-signatures button):active { transform: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .button:active:not(:disabled), .square-button:active:not(:disabled), .tool:active:not(:disabled), .zoom-label:active:not(:disabled), .help-link:active, .inline-link:active, .field-list-item:active, #saved-signatures button:active { transform: none; }
  .spinner { border-right-color: var(--dark-green); }
}
