:root {
  --ink: #14213d;
  --muted: #60708a;
  --line: #d8e0ea;
  --soft: #f4f7fb;
  --blue: #1769e0;
  --blue-dark: #0d4eaa;
  --teal: #0e7774;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --warning: #8a4b08;
  --warning-soft: #fff7e7;
  --white: #ffffff;
  --shadow: 0 14px 40px rgba(20, 33, 61, .09);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #eef3f8; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar { min-height: 92px; padding: 20px clamp(18px, 4vw, 56px); display: flex; align-items: center; justify-content: space-between; color: white; background: linear-gradient(115deg, #10284c, #164d78 62%, #0e7774); }
.topbar h1 { margin: 2px 0 0; font-size: 28px; letter-spacing: -.03em; }
.eyebrow { margin: 0; font-size: 11px; font-weight: 800; letter-spacing: .14em; opacity: .78; }
.privacy-pill { padding: 9px 13px; border: 1px solid rgba(255,255,255,.28); border-radius: 999px; background: rgba(255,255,255,.1); font-size: 13px; font-weight: 700; }

.layout { max-width: 1460px; margin: 0 auto; padding: 28px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.layout.with-result { grid-template-columns: minmax(560px, .9fr) minmax(540px, 1.1fr); }
.workspace { min-width: 0; }
.card, .result-panel { background: var(--white); border: 1px solid rgba(25, 58, 99, .09); border-radius: 18px; box-shadow: var(--shadow); }
.card { padding: clamp(20px, 3vw, 34px); margin-bottom: 22px; }
.section-heading, .section-heading > div, .result-header, .hbys-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading > div { justify-content: flex-start; }
h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.step { display: inline-grid; place-items: center; width: 29px; height: 29px; border-radius: 9px; color: white; background: var(--blue); font-weight: 800; }
.helper, .mini-helper { color: var(--muted); }
.helper { margin: 12px 0; font-size: 14px; }
.mini-helper { margin: -2px 0 12px; font-size: 12px; }
.engine-badge { color: var(--teal); background: #e9f7f5; border-radius: 999px; padding: 7px 10px; font-size: 12px; font-weight: 750; }

textarea, input, select { width: 100%; border: 1px solid #cbd6e4; border-radius: 11px; background: white; color: var(--ink); outline: none; transition: .15s ease; }
textarea { resize: vertical; padding: 14px; line-height: 1.5; }
input, select { min-height: 45px; padding: 10px 12px; }
textarea:focus, input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23,105,224,.12); }

.preset-title { margin: 14px 0 8px; color: #42536e; font-size: 12px; font-weight: 800; }
.example-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }
.example-chip { border: 1px solid #d4deeb; background: #f7f9fc; color: #30425f; border-radius: 999px; padding: 8px 11px; font-size: 12px; }
.example-chip:hover { border-color: var(--blue); color: var(--blue); }
.primary, .secondary, .text-button, .icon-button { border: 0; border-radius: 11px; font-weight: 750; }
.primary { padding: 13px 18px; color: white; background: var(--blue); box-shadow: 0 7px 18px rgba(23,105,224,.22); }
.primary:hover { background: var(--blue-dark); }
.secondary { padding: 9px 13px; color: var(--blue); background: #eaf2ff; }
.wide { width: 100%; }
.text-button { padding: 8px; color: var(--blue); background: transparent; }
.icon-button { width: 34px; height: 34px; background: #eef2f7; font-size: 24px; color: var(--ink); }

.warning, .missing-box, .stop-banner { padding: 12px 14px; border-radius: 11px; margin: 12px 0; line-height: 1.45; font-size: 13px; }
.warning, .missing-box { color: var(--warning); background: var(--warning-soft); border: 1px solid #f1d49a; }
.stop-banner { color: var(--danger); background: var(--danger-soft); border: 1px solid #f1b7b2; font-weight: 700; }

.form-grid { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span, legend { font-size: 13px; font-weight: 800; color: #354766; }
.field small { font-weight: 500; color: var(--muted); }
.field-group { min-width: 0; margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.field-group legend { padding: 0 7px; }
.choice-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { display: block; padding: 9px 11px; border: 1px solid #ccd8e6; border-radius: 9px; color: #42536e; background: white; font-size: 12px; font-weight: 650; }
.choice input:checked + span { color: #0d4eaa; border-color: #6ea7ef; background: #eaf2ff; box-shadow: inset 0 0 0 1px #6ea7ef; }
.custom-action-row { display: flex; flex-direction: column; gap: 6px; margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line); }
.custom-action-row > span { font-size: 12px; font-weight: 800; color: #52627b; }
.custom-action-row small { color: var(--muted); font-weight: 500; }
.mini-button { align-self: flex-start; border: 1px solid #cbd8e8; border-radius: 8px; padding: 6px 9px; color: #2b527d; background: #f4f8fd; font-size: 11px; font-weight: 700; }
.mini-button:hover { border-color: var(--blue); color: var(--blue); }
.checkbox-field { justify-content: flex-end; color: #354766; font-size: 13px; font-weight: 700; }
.checkbox-field input { width: 17px; min-height: 17px; vertical-align: middle; margin-right: 6px; }
.retro-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; padding: 15px; background: var(--warning-soft); border: 1px solid #f1d49a; border-radius: 12px; }
.ai-polish-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px 14px; padding: 15px; border: 1px solid #9fd5cf; border-radius: 12px; background: #eefaf8; color: #174f4d; }
.ai-polish-card > div { display: flex; flex-direction: column; gap: 4px; }
.ai-polish-card b { font-size: 13px; }
.ai-polish-card small { color: #55716f; line-height: 1.4; }
.ai-button { grid-row: 1 / span 2; grid-column: 2; border: 0; border-radius: 10px; padding: 11px 14px; color: white; background: var(--teal); font-weight: 750; }
.ai-button:disabled { cursor: wait; opacity: .65; }
.polish-status { grid-column: 1; min-height: 17px; color: #44716e; font-size: 11px; font-weight: 700; }
.verification { padding: 13px 14px; border: 1px solid #a8c8f1; border-radius: 11px; background: #eef6ff; color: #23466f; font-size: 13px; font-weight: 700; line-height: 1.45; }
.verification input { width: 18px; min-height: 18px; margin-right: 7px; vertical-align: middle; }
.verification:has(input:disabled) { opacity: .55; }

.result-panel { position: sticky; top: 18px; align-self: start; padding: 22px; max-height: calc(100vh - 36px); overflow: auto; }
.result-header { margin-bottom: 16px; }
.document { width: 100%; max-width: 210mm; min-height: auto; aspect-ratio: 210 / 297; box-sizing: border-box; margin: 0 auto; background: white; border: 1px solid #bac5d1; padding: 6.5% 7%; color: #111; font-family: Arial, sans-serif; box-shadow: 0 8px 24px rgba(29, 45, 68, .1); }
.doc-top { display: flex; justify-content: space-between; gap: 18px; align-items: start; }
.barcode-box { width: 30mm; height: 11mm; box-sizing: border-box; border: 1px dashed #666; display: grid; place-content: center; text-align: center; font-weight: 700; font-size: 8px; line-height: 1.15; }
.barcode-box small { font-size: 6px; }
.barcode-box small { font-weight: 400; }
.doc-times { display: flex; flex-direction: column; gap: 7px; text-align: right; font-size: 11px; }
.document h3 { margin: 25px 0 21px; text-align: center; font-size: 18px; }
.doc-body { font-size: 13px; line-height: 1.58; text-align: justify; white-space: pre-wrap; }
.patient-statement { margin-top: 23px; padding: 12px; border: 1px solid #777; font-size: 11px; }
.patient-statement > p { margin: 5px 0; }
.statement-prompt { padding: 7px; background: #f3f3f3; font-style: italic; line-height: 1.4; }
.handwriting-lines { height: 35px; margin-top: 5px; background: repeating-linear-gradient(to bottom, transparent 0, transparent 16px, #888 17px); }
.read-aloud-option { margin-top: 8px !important; padding-top: 7px; border-top: 1px solid #bbb; font-size: 9px; }
.signature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 28px; font-size: 11px; }
.doc-footnote { margin: 30px 0 0; padding-top: 9px; border-top: 1px solid #aaa; font-size: 9px; color: #555; }
.document.compact { padding: 5% 6%; }
.document.compact h3 { margin: 16px 0 14px; font-size: 16px; }
.document.compact .doc-body { font-size: 11.5px; line-height: 1.42; }
.document.compact .patient-statement { margin-top: 14px; padding: 9px; }
.document.compact .signature-grid { margin-top: 18px; }
.document.extra-compact .doc-body { font-size: 10.5px; line-height: 1.32; }
.document.extra-compact .patient-statement { font-size: 9.5px; }
.document.extra-compact .handwriting-lines { height: 24px; }
.document.extra-compact .signature-grid { font-size: 9.5px; gap: 12px; margin-top: 12px; }
.result-actions { margin: 14px 0; display: flex; gap: 10px; }
.result-actions .primary { flex: 1; }
.hbys-card { padding: 17px; border-radius: 13px; background: var(--soft); border: 1px solid var(--line); }
.hbys-heading { margin-bottom: 10px; }
.hbys-heading h3 { margin: 0; font-size: 15px; }
.copy-status { display: block; min-height: 18px; padding-top: 5px; color: var(--teal); font-size: 12px; }
footer { padding: 12px 24px 28px; text-align: center; color: var(--muted); font-size: 12px; }

@media (max-width: 1050px) {
  .layout.with-result { grid-template-columns: 1fr; }
  .result-panel { position: static; max-height: none; }
}
@media (max-width: 680px) {
  .topbar { min-height: 76px; padding: 16px; }
  .topbar h1 { font-size: 23px; }
  .privacy-pill { font-size: 11px; }
  .layout { padding: 14px; }
  .card { padding: 18px; border-radius: 14px; }
  .form-grid, .retro-fields { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .ai-polish-card { grid-template-columns: 1fr; }
  .ai-button { grid-column: 1; grid-row: auto; width: 100%; }
  .doc-top { flex-direction: column; }
  .doc-times { text-align: left; }
  .signature-grid { grid-template-columns: 1fr; gap: 28px; }
}

@media print {
  body * { visibility: hidden; }
  #printDocument, #printDocument * { visibility: visible; }
  #printDocument { position: absolute; top: 0; left: 0; width: 210mm; min-height: 297mm; aspect-ratio: auto; border: 0; box-shadow: none; padding: 12mm 14mm; box-sizing: border-box; }
  @page { size: A4; margin: 0; }
}
