:root {
  color-scheme: light;
  --ink: #101820;
  --muted: #5c6972;
  --line: #c9d7df;
  --soft: #edf8fd;
  --brand: #14a3de;
  --brand-dark: #0b79aa;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: #eaf1f5; color: var(--ink); }
.toolbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 24px; background: rgba(255,255,255,.96); border-bottom: 1px solid #dbe7ed; box-shadow: 0 3px 14px rgba(10,65,91,.09); }
.toolbar-title { display: flex; flex-direction: column; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.toolbar strong { font-size: 15px; }
.toolbar span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.toolbar button { border: 0; border-radius: 8px; padding: 11px 26px; background: var(--brand); color: #fff; font: 700 14px inherit; cursor: pointer; }
.toolbar button:hover { background: var(--brand-dark); }
.toolbar button.secondary { border: 1px solid var(--brand); background: #fff; color: var(--brand-dark); }
.toolbar button.secondary:hover { background: var(--soft); }
.toolbar button:disabled { cursor: wait; opacity: .65; }
.sheet { width: min(210mm, calc(100% - 32px)); min-height: 297mm; margin: 24px auto 48px; padding: 17mm 16mm 15mm; background: white; box-shadow: 0 14px 45px rgba(11,58,80,.14); }
.document-header { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px; padding-bottom: 18px; border-bottom: 3px solid var(--brand); }
.brand-logo { display: block; width: 138px; height: auto; }
.document-heading { padding-left: 17px; border-left: 1px solid var(--line); }
h1 { margin: 3px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 30px; line-height: 1; }
.document-date { text-align: right; }
.document-date span, .identity-card span, .note span, .detail span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.document-date strong { font-size: 14px; }
.identity-grid { display: grid; grid-template-columns: 1.35fr 1fr 1fr; gap: 10px; margin-top: 18px; }
.identity-card { min-height: 86px; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.identity-card.patient { background: var(--soft); border-color: #b6dceb; }
.identity-card strong { display: block; font-size: 14px; line-height: 1.35; }
.identity-card small { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; }
.patient-details { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 15px 2px 0; }
.detail { min-width: 120px; max-width: 100%; }
.detail strong { font-size: 11px; }
.note { margin-top: 15px; padding: 10px 13px; border-left: 3px solid var(--brand); background: #f5f9fb; }
.note.compact { margin-top: 6px; }
.note p { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 12px; line-height: 1.45; white-space: pre-wrap; }
.services { margin-top: 20px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.section-title h2 { margin: 0; font: 700 17px Georgia, "Times New Roman", serif; }
.section-title span { color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
th, td { border: 1px solid #aebbb7; padding: 7px 9px; text-align: left; height: 30px; }
th { background: var(--soft); color: #42514e; font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
.col-num { width: 34px; }
.col-qty { width: 88px; }
.num { padding-left: 4px; padding-right: 4px; text-align: center; color: var(--muted); }
.qty { padding-left: 6px; padding-right: 6px; text-align: center; font-weight: 700; }
.course-totals { width: min(410px, 100%); margin: 9px 0 0 auto; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.course-totals > div { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.course-totals > div:last-child { border-bottom: 0; }
.course-totals span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.course-totals strong { white-space: nowrap; font-size: 13px; }
.course-totals .course-total-final { background: var(--soft); }
.course-totals .course-total-final strong, .course-totals.single strong { color: var(--brand-dark); font-size: 15px; }
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 44px; margin-top: 34px; }
.signatures div { display: grid; grid-template-columns: auto 1fr; align-items: end; gap: 9px; font-size: 11px; }
.signatures i { height: 18px; border-bottom: 1px solid #73817e; }
.signatures small { grid-column: 2; color: var(--muted); font-size: 9px; text-align: center; }
.app-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #f2f7fa; }
.status-card { width: min(480px, 100%); padding: 40px; border-radius: 14px; background: white; text-align: center; box-shadow: 0 14px 40px rgba(11,58,80,.12); }
.status-card h1 { font-size: 24px; }
.status-card p { color: var(--muted); line-height: 1.5; }
.status-card.error { border-top: 5px solid #b33e3e; }
.spinner { width: 42px; height: 42px; margin: 0 auto 22px; border: 4px solid #d9edf6; border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
.loader-card { width: min(520px, 100%); border-top: 5px solid var(--brand); }
.loader-card h1 { margin-top: 4px; }
.loader-card small { display: block; margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.loader-emblem { position: relative; display: grid; place-items: center; width: 76px; height: 76px; margin: 0 auto 18px; }
.loader-emblem > span { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--brand); color: white; font: 700 24px Georgia, serif; }
.loader-spinner { position: absolute; inset: 0; width: 76px; height: 76px; margin: 0; border-width: 3px; }
.loader-track { height: 5px; margin-top: 24px; overflow: hidden; border-radius: 999px; background: #d9edf6; }
.loader-track i { display: block; width: 38%; height: 100%; border-radius: inherit; background: var(--brand); animation: loader-slide 1.5s ease-in-out infinite; }
.loader-meta { display: flex; justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.retry-button { margin-top: 20px; border: 0; border-radius: 8px; padding: 10px 22px; background: var(--brand); color: #fff; font: 700 13px inherit; cursor: pointer; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes loader-slide { from { transform: translateX(-105%); } 50% { transform: translateX(165%); } to { transform: translateX(-105%); } }

@media (max-width: 760px) {
  .sheet { width: 100%; margin: 0; padding: 24px 18px; box-shadow: none; }
  .identity-grid { grid-template-columns: 1fr; }
  .document-header { grid-template-columns: auto 1fr; }
  .document-date { grid-column: 1 / -1; text-align: left; }
}

body.pdf-exporting { background: white; }
body.pdf-exporting .toolbar { display: none; }
body.pdf-exporting .sheet { width: 210mm; min-height: 0; margin: 0; padding: 8mm 10mm 7mm; box-shadow: none; }
body.pdf-exporting .document-header { grid-template-columns: auto 1fr auto; gap: 10px; padding-bottom: 8px; border-bottom-width: 2px; }
body.pdf-exporting .brand-logo { width: 100px; }
body.pdf-exporting .document-heading { padding-left: 10px; }
body.pdf-exporting h1 { margin-top: 1px; font-size: 23px; }
body.pdf-exporting .document-date span,
body.pdf-exporting .identity-card span,
body.pdf-exporting .note span,
body.pdf-exporting .detail span { margin-bottom: 2px; font-size: 8px; }
body.pdf-exporting .document-date { grid-column: auto; text-align: right; }
body.pdf-exporting .document-date strong { font-size: 11px; }
body.pdf-exporting .identity-grid { grid-template-columns: 1.35fr 1fr 1fr; gap: 6px; margin-top: 8px; }
body.pdf-exporting .identity-card { min-height: 58px; padding: 7px 8px; border-radius: 6px; }
body.pdf-exporting .identity-card strong { font-size: 11px; line-height: 1.2; }
body.pdf-exporting .identity-card small { margin-top: 3px; font-size: 9px; }
body.pdf-exporting .patient-details { gap: 4px 14px; margin-top: 7px; }
body.pdf-exporting .detail { min-width: 100px; }
body.pdf-exporting .detail strong { font-size: 9px; }
body.pdf-exporting .note { margin-top: 6px; padding: 5px 8px; border-left-width: 2px; }
body.pdf-exporting .note.compact { margin-top: 3px; }
body.pdf-exporting .note p { font-size: 10px; line-height: 1.2; }
body.pdf-exporting .services { margin-top: 9px; }
body.pdf-exporting .section-title { margin-bottom: 4px; }
body.pdf-exporting .section-title h2 { font-size: 14px; }
body.pdf-exporting .section-title span { font-size: 8px; }
body.pdf-exporting table { font-size: 10px; line-height: 1.15; }
body.pdf-exporting th,
body.pdf-exporting td { height: 21px; padding: 3px 5px; }
body.pdf-exporting th { font-size: 8px; }
body.pdf-exporting .empty-row { display: none; }
body.pdf-exporting .course-totals { margin-top: 5px; border-radius: 5px; }
body.pdf-exporting .course-totals > div { gap: 14px; padding: 4px 7px; }
body.pdf-exporting .course-totals span { font-size: 8px; }
body.pdf-exporting .course-totals strong { font-size: 11px; }
body.pdf-exporting .course-totals .course-total-final strong,
body.pdf-exporting .course-totals.single strong { font-size: 12px; }
body.pdf-exporting .signatures { gap: 30px; margin-top: 15px; }
body.pdf-exporting .signatures div { gap: 7px; font-size: 9px; }
body.pdf-exporting .signatures i { height: 11px; }
body.pdf-exporting .signatures small { font-size: 8px; }

@media print {
  @page { size: A4; margin: 0; }
  body { background: white; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .toolbar { display: none; }
  .sheet { width: 210mm; min-height: 0; margin: 0; padding: 8mm 10mm 7mm; box-shadow: none; }
  .document-header { grid-template-columns: auto 1fr auto; gap: 10px; padding-bottom: 8px; border-bottom-width: 2px; }
  .brand-logo { width: 100px; }
  .document-heading { padding-left: 10px; }
  h1 { margin-top: 1px; font-size: 23px; }
  .document-date span, .identity-card span, .note span, .detail span { margin-bottom: 2px; font-size: 8px; }
  .document-date { grid-column: auto; text-align: right; }
  .document-date strong { font-size: 11px; }
  .identity-grid { grid-template-columns: 1.35fr 1fr 1fr; gap: 6px; margin-top: 8px; }
  .identity-card { min-height: 58px; padding: 7px 8px; border-radius: 6px; }
  .identity-card strong { font-size: 11px; line-height: 1.2; }
  .identity-card small { margin-top: 3px; font-size: 9px; }
  .patient-details { gap: 4px 14px; margin-top: 7px; }
  .detail { min-width: 100px; }
  .detail strong { font-size: 9px; }
  .note { margin-top: 6px; padding: 5px 8px; border-left-width: 2px; }
  .note.compact { margin-top: 3px; }
  .note p { font-size: 10px; line-height: 1.2; }
  .services { margin-top: 9px; }
  .section-title { margin-bottom: 4px; }
  .section-title h2 { font-size: 14px; }
  .section-title span { font-size: 8px; }
  table { font-size: 10px; line-height: 1.15; }
  th, td { height: 21px; padding: 3px 5px; }
  th { font-size: 8px; }
  .empty-row { display: none; }
  .course-totals { margin-top: 5px; border-radius: 5px; }
  .course-totals > div { gap: 14px; padding: 4px 7px; }
  .course-totals span { font-size: 8px; }
  .course-totals strong { font-size: 11px; }
  .course-totals .course-total-final strong, .course-totals.single strong { font-size: 12px; }
  .signatures { gap: 30px; margin-top: 15px; }
  .signatures div { gap: 7px; font-size: 9px; }
  .signatures i { height: 11px; }
  .signatures small { font-size: 8px; }
  .identity-card { break-inside: avoid; }
  .services, .course-totals, .note, .signatures { break-inside: avoid; }
}
