:root {
  color-scheme: light;
  --ink: #172526;
  --muted: #667575;
  --line: #cfd9d6;
  --soft: #eef5f2;
  --green: #18755d;
  --green-dark: #115743;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: #e8eeec; 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 #dbe3e0; box-shadow: 0 3px 14px rgba(19,42,36,.08); }
.toolbar div { display: flex; flex-direction: column; }
.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(--green); color: #fff; font: 700 14px inherit; cursor: pointer; }
.toolbar button:hover { background: var(--green-dark); }
.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(20,40,34,.14); }
.document-header { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; padding-bottom: 18px; border-bottom: 3px solid var(--green); }
.brand-mark { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--green); color: #fff; font: 800 28px Georgia, serif; }
.eyebrow { color: var(--green); font-weight: 700; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
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: #b9d0c9; }
.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(--green); background: #f7f9f8; }
.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; }
.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: #f3f7f5; }
.status-card { width: min(480px, 100%); padding: 40px; border-radius: 14px; background: white; text-align: center; box-shadow: 0 14px 40px rgba(20,40,34,.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 #dceae5; border-top-color: var(--green); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@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; }
}

@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: 297mm; margin: 0; padding: 14mm 14mm 12mm; box-shadow: none; }
  .identity-card { break-inside: avoid; }
  .services, .note, .signatures { break-inside: avoid; }
}
