/* =========================================================================
   FOLHA IMPRESSA (A4): documentos, receitas, orçamento, evoluções, prótese e ortodontia.
   Cores fixas porque o papel é sempre branco, mesmo com o app no modo escuro.
   As margens da página e os textos do navegador ficam em styles.css (@page).
   ========================================================================= */

/* O espaço entre palavras evita doses coladas ("Tomar1cápsula"). */
.doc-paper,
.print-sheet,
.controlled-rx-page {
  position: relative;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;
  min-height: 264mm;
  padding: 0 2mm;
  background: transparent;
  color: #0f172a;
  font-family: var(--font-sans);
  word-spacing: 0.12em;
}
.sheet-slot { display: contents; }
.sheet-body { position: relative; z-index: 1; font-size: 12.5px; line-height: 1.45; }

/* Cabeçalho */
.doc-header { position: relative; z-index: 1; display: flex; align-items: center; gap: 22px; border-bottom: 1px solid var(--accent); padding-bottom: 18px; margin-bottom: 20px; }
.doc-header-logo { flex: none; height: 104px; max-width: 220px; object-fit: contain; border-radius: 24px; }
.doc-header-info { flex: 1; min-width: 0; }
.doc-header-clinic { color: var(--primary); font-size: 24px; font-weight: 700; line-height: 1.15; letter-spacing: -0.022em; }
.doc-header-pro { margin-top: 6px; font-size: 13.5px; font-weight: 600; color: #334155; }
.doc-header-meta { margin-top: 4px; font-size: 11.5px; font-weight: 500; color: #64748b; }
.doc-header-badge { align-self: flex-start; flex: none; padding: 4px 12px; border: 1.2px solid var(--primary); border-radius: 999px; color: var(--primary); font-size: 11px; font-weight: 700; }

/* Título e cartão de identificação */
.doc-intro { position: relative; z-index: 1; margin-bottom: 20px; }
.doc-title { margin-bottom: 14px; color: #0f172a; font-size: 22px; font-weight: 700; line-height: 1.25; letter-spacing: -0.022em; }
.doc-subtitle { margin: -8px 0 14px; color: #475569; font-size: 13.5px; font-weight: 500; }
.doc-card { display: flex; flex-wrap: wrap; gap: 10px 34px; padding: 12px 18px; border-radius: 14px; background: rgba(var(--primary-rgb), 0.045); }
.doc-field.is-grow { flex: 1 1 240px; }
.doc-field.is-full { flex: 0 0 100%; }
.doc-field-label { display: block; margin-bottom: 2px; font-size: 10.5px; font-weight: 600; color: #64748b; }
.doc-field-value { display: block; font-size: 14px; font-weight: 600; color: #0f172a; overflow-wrap: anywhere; }

/* Texto dos documentos */
.doc-body { position: relative; z-index: 1; white-space: pre-wrap; font-size: 13.5px; line-height: 1.58; color: #0f172a; background: transparent; }

/* Fecho da folha: último trecho do texto + data + assinaturas, num bloco que não se parte.
   Ocupa o resto da folha e empurra a assinatura para o pé. */
.doc-closing { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; break-inside: avoid; }
.doc-closing .doc-footer { margin-top: auto; }
.doc-closing .sheet-evolution:first-child { padding-top: 10px; }
.doc-closing .doc-body.risus-rich-print-body .rx-use:first-child { margin-top: 20px; }
.controlled-rx-page .doc-body { flex: 1; }
.doc-footer { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: flex-end; gap: 30px; margin-top: 16px; padding-top: 56px; break-inside: avoid; }
.doc-footer-date { font-size: 13px; font-weight: 500; color: #334155; }
.doc-sign { flex: none; box-sizing: border-box; width: 290px; padding-top: 9px; border-top: 1px solid #334155; text-align: center; }
.doc-sign-name { display: block; min-height: 18px; font-size: 14.5px; font-weight: 700; color: var(--primary); }
.doc-sign-line { display: block; margin-top: 2px; font-size: 12.5px; font-weight: 500; color: #334155; }
.doc-sign-line:empty { display: none; }
.doc-sign-caption { display: block; margin-top: 2px; font-size: 11px; color: #64748b; }
.doc-footer.is-pair { display: block; padding-top: 24px; }
.doc-signs { display: flex; gap: 36px; align-items: flex-start; padding-top: 62px; }
.doc-signs .doc-sign { flex: 1; width: auto; }

/* Receita: pílula "Uso interno/externo" e medicamento com linha pontilhada */
.doc-body.risus-rich-print-body .rx-use { display: table; break-after: avoid; margin: 20px 0 12px; padding: 3px 12px; border-radius: 999px; background: rgba(var(--primary-rgb), 0.07); font-size: 11.5px; font-weight: 700; }
.doc-body.risus-rich-print-body .rx-use:first-child { margin-top: 0; }
.doc-body.risus-rich-print-body .rx-item { margin-bottom: 14px; line-height: 1.5; break-inside: avoid; }
.rx-line { display: flex; align-items: baseline; gap: 10px; font-size: 15.5px; font-weight: 600; }
.rx-name { flex: 0 1 auto; }
.rx-leader { flex: 1 1 24px; min-width: 24px; border-bottom: 1.5px dotted #b6bec9; transform: translateY(-4px); }
.rx-quantity { flex: none; max-width: 45%; text-align: right; font-size: 14px; font-weight: 500; }
.rx-how { display: block; margin-top: 4px; }

/* Folhas com muito conteúdo (orçamento, evoluções, prótese e ortodontia): cabeçalho e assinatura
   um pouco mais compactos, para caber o máximo na primeira folha */
.print-sheet .doc-header { gap: 20px; padding-bottom: 14px; margin-bottom: 16px; }
.print-sheet .doc-header-logo { height: 88px; border-radius: 20px; }
.print-sheet .doc-intro { margin-bottom: 14px; }
.print-sheet .doc-title { margin-bottom: 10px; font-size: 20px; }
.print-sheet .doc-subtitle { margin: -8px 0 10px; font-size: 12.5px; }
.print-sheet .doc-card { padding: 9px 16px; }
.print-sheet .doc-field-value { font-size: 13.5px; }
.print-sheet .doc-footer { padding-top: 46px; }
.print-sheet .doc-footer.is-pair { padding-top: 0; }
.print-sheet .doc-signs { padding-top: 56px; }

/* Tabelas, cartões e listas das folhas clínicas */
.sheet-section { margin: 16px 0 8px; break-after: avoid; color: var(--primary); font-size: 11.5px; font-weight: 700; }
.sheet-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.sheet-table th { padding: 0 8px 6px; border-bottom: 1px solid var(--accent); color: #64748b; font-size: 10.5px; font-weight: 600; text-align: left; vertical-align: bottom; }
.sheet-table td { padding: 6px 8px; border-bottom: 1px solid rgba(15, 23, 42, 0.08); color: #0f172a; vertical-align: top; }
.sheet-table tr { break-inside: avoid; }
.sheet-table.is-compact { font-size: 11.5px; }
.sheet-table .is-right { text-align: right; }
.sheet-table .is-center { text-align: center; }
.sheet-table .is-nowrap { white-space: nowrap; }
.sheet-table strong { font-weight: 600; }
.sheet-specs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 10px; }
.sheet-spec { padding: 11px 15px; border-radius: 12px; background: rgba(var(--primary-rgb), 0.045); break-inside: avoid; }
.sheet-spec.is-highlight { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; background: rgba(200, 174, 125, 0.18); }
.sheet-spec.is-highlight .doc-field-label { margin: 0; }
.sheet-checklist { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px 14px; font-size: 12.5px; }
.sheet-checklist span { display: flex; align-items: center; gap: 8px; }
.sheet-checklist span::before { content: ''; flex: none; width: 13px; height: 13px; border: 1.4px solid #94a3b8; border-radius: 4px; }
.sheet-notes { min-height: 96px; padding: 12px 15px; border: 1px solid rgba(15, 23, 42, 0.12); border-radius: 12px; white-space: pre-wrap; }
.sheet-note-card { padding: 10px 16px; border-radius: 14px; background: rgba(var(--primary-rgb), 0.045); white-space: pre-line; font-size: 12px; color: #334155; break-inside: avoid; }
.sheet-note-card .sheet-section { margin: 0 0 4px; }

/* Orçamento */
.sheet-map { margin-bottom: 14px; padding: 8px; border: 1px solid rgba(15, 23, 42, 0.1); border-radius: 14px; background: #ffffff; break-inside: avoid; }
.sheet-arch { display: flex; justify-content: center; align-items: center; gap: 2px; }
.sheet-arch + .sheet-arch { margin-top: 6px; padding-top: 6px; border-top: 1px dashed #cbd5e1; }
.sheet-tooth { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; padding: 2px 1px; }
.sheet-tooth-number { margin: 1px 0; line-height: 1.2; font-size: 10px; font-weight: 700; color: #1e293b; word-spacing: 0; }
.sheet-map-note { margin-top: 6px; text-align: center; font-size: 9.5px; font-style: italic; color: #64748b; }
.sheet-entry.is-finding { color: #be123c; font-weight: 600; }
.sheet-closing { display: flex; align-items: flex-start; gap: 14px; margin-top: 14px; }
.sheet-closing-notes { flex: 1; display: grid; gap: 8px; }
.sheet-total { flex: none; box-sizing: border-box; width: 260px; padding: 13px 18px; border-radius: 14px; background: var(--primary); color: #ffffff; break-inside: avoid; }
.sheet-total-row { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 5px; font-size: 12px; }
.sheet-total-final { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 12.5px; font-weight: 600; }
.sheet-total-row + .sheet-total-final { margin-top: 8px; padding-top: 9px; border-top: 1px solid rgba(255, 255, 255, 0.22); }
.sheet-total-final strong { color: var(--accent-light); font-size: 20px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; word-spacing: 0; }

/* Evoluções clínicas: o texto e o lacre saem exatamente como foram gravados */
.sheet-evolution { padding: 10px 0; border-bottom: 1px solid rgba(15, 23, 42, 0.1); break-inside: avoid; }
.sheet-evolution:first-child { padding-top: 0; }
.sheet-evolution-head { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; margin-bottom: 4px; break-after: avoid; }
.sheet-evolution-author { color: var(--primary); font-size: 14px; font-weight: 700; }
.sheet-evolution-date { flex: none; color: #64748b; font-size: 11.5px; font-weight: 500; }
.sheet-evolution-title { margin-bottom: 4px; color: #475569; font-size: 12px; font-weight: 600; }
.sheet-evolution .risus-rich-content { color: #0f172a; font-size: 13px; line-height: 1.5; }
.sheet-evolution .risus-rich-content p { margin: 0 0 4px; }
.sheet-evolution .risus-rich-content p.is-forensic-seal { margin: 0; color: #475569; font-family: var(--font-mono); font-size: 10px; word-spacing: 0; }

/* Receituário de Controle Especial — 2 vias oficiais (ANVISA) */
.controlled-rx-page {
  z-index: 2;
  min-height: 258mm;
  padding: 0;
}

.controlled-rx-page-break {
  page-break-after: always;
  break-after: page;
}

/* As 2 vias levam os quadros da ANVISA no pé da folha: tudo um pouco mais compacto, para a
   assinatura ficar na mesma folha dos medicamentos */
.controlled-rx-page .doc-header { gap: 18px; padding-bottom: 12px; margin-bottom: 12px; }
.controlled-rx-page .doc-header-logo { height: 76px; border-radius: 18px; }
.controlled-rx-page .doc-header-clinic { font-size: 21px; }
.controlled-rx-page .doc-intro { margin-bottom: 12px; }
.controlled-rx-page .doc-title { margin-bottom: 8px; font-size: 19px; }
.controlled-rx-page .doc-card { gap: 4px 30px; padding: 8px 16px; }
.controlled-rx-page .doc-field-value { font-size: 13px; }
.controlled-rx-page .doc-body { font-size: 13.5px; }
.controlled-rx-page .doc-body .rx-use { margin: 10px 0 6px; }
.controlled-rx-page .doc-body .rx-item { margin-bottom: 8px; line-height: 1.4; }
.controlled-rx-page .rx-line { font-size: 14.5px; }
.controlled-rx-page .doc-footer { margin: 6px 0 12px; padding-top: 36px; }

.controlled-rx-anvisa-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.85fr;
  gap: 10px;
  margin-top: auto;
}

.controlled-rx-anvisa-box {
  border: 1.2px solid #0f172a;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 10.5px;
  line-height: 1.65;
  break-inside: avoid;
  background: rgba(255, 255, 255, 0.92);
}

.controlled-rx-anvisa-title {
  text-align: center;
  font-weight: 800;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #334155;
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.controlled-rx-anvisa-line {
  white-space: nowrap;
  overflow: hidden;
}

.controlled-rx-supplier-box {
  display: flex;
  flex-direction: column;
}

.controlled-rx-supplier-space {
  flex: 1;
  min-height: 62px;
}

.controlled-rx-supplier-footer {
  text-align: center;
  border-top: 1px solid #0f172a;
  padding-top: 4px;
}

.controlled-rx-supplier-sign {
  font-weight: 700;
  font-size: 9.8px;
}

.controlled-rx-supplier-date {
  font-size: 10px;
  margin-top: 4px;
}
