:root {
  --apac-blue: #0b4f8a;
  --apac-blue-dark: #083862;
  --apac-blue-soft: #e8f2fb;
  --apac-gray: #5b6773;
  --apac-border: #d7e2ee;
  --apac-bg: #f3f6fa;
  --apac-card: #ffffff;
  --apac-danger: #b42318;
  --apac-success: #067647;
  --apac-shadow: 0 10px 30px rgba(11, 79, 138, 0.08);
  --sidebar-width: 250px;
}

* {
  box-sizing: border-box;
}

body.app-shell {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at top right, rgba(11, 79, 138, 0.12), transparent 30%),
    linear-gradient(180deg, #eef4fa 0%, var(--apac-bg) 40%, #e9eef5 100%);
  color: #1f2933;
  min-height: 100vh;
}

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--apac-blue) 0%, var(--apac-blue-dark) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  box-shadow: 8px 0 24px rgba(8, 56, 98, 0.18);
}

.sidebar-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 1.25rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
}

.sidebar-brand strong {
  display: block;
  font-size: 1rem;
  line-height: 1.2;
}

.sidebar-brand small {
  opacity: 0.8;
  font-size: 0.78rem;
}

.sidebar-nav {
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.sidebar-label {
  margin: 0 0 0.45rem 0.55rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.7;
  font-weight: 700;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: rgba(255, 255, 255, 0.92);
  text-decoration: none;
  padding: 0.72rem 0.85rem;
  border-radius: 12px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-link i {
  font-size: 1.1rem;
  width: 1.2rem;
  text-align: center;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-link.active {
  background: #fff;
  color: var(--apac-blue-dark);
}

.sidebar-footer {
  padding: 1rem 1.1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  opacity: 0.75;
}

.app-main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1.25rem 1.5rem 0.5rem;
}

.app-topbar h1 {
  font-size: clamp(1.2rem, 2vw, 1.65rem);
  margin: 0;
  color: var(--apac-blue-dark);
  font-weight: 700;
}

.app-topbar p {
  margin: 0.25rem 0 0;
  color: var(--apac-gray);
  font-size: 0.92rem;
}

.sidebar-toggle {
  display: none;
  margin-top: 0.15rem;
}

.app-content {
  padding: 0.75rem 1.5rem 5rem;
  width: 100%;
  max-width: 1200px;
}

.app-backdrop {
  display: none;
}

.stat-card {
  background: #fff;
  border: 1px solid #d9e3ef;
  border-radius: 14px;
  padding: 1rem 1.1rem;
  box-shadow: var(--apac-shadow);
}

.stat-label {
  color: var(--apac-gray);
  font-size: 0.85rem;
  font-weight: 600;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--apac-blue-dark);
  line-height: 1.2;
}

.privacy-banner {
  background: #fff8e6;
  border: 1px solid #f5d78e;
  color: #7a5b00;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin: 1rem 0 1.25rem;
  font-size: 0.92rem;
}

.nav-pills .nav-link {
  color: var(--apac-blue);
  border: 1px solid #c9d8e8;
  background: #fff;
  margin: 0 0.25rem 0.5rem 0;
  border-radius: 999px;
  font-size: 0.9rem;
}

.nav-pills .nav-link.active {
  background: var(--apac-blue);
  border-color: var(--apac-blue);
  color: #fff;
}

.section-card {
  background: var(--apac-card);
  border: 1px solid #d9e3ef;
  border-radius: 16px;
  box-shadow: var(--apac-shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.section-card h2 {
  font-size: 1.1rem;
  color: var(--apac-blue-dark);
  margin: 0 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-card h2 .badge-step {
  background: var(--apac-blue-soft);
  color: var(--apac-blue);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 700;
}

.form-label {
  font-weight: 600;
  color: #334155;
  font-size: 0.9rem;
}

.required::after {
  content: " *";
  color: var(--apac-danger);
}

.form-control,
.form-select {
  border-radius: 10px;
  border-color: #c9d6e5;
  min-height: 42px;
}

.form-control:focus,
.form-select:focus {
  border-color: #7fb0de;
  box-shadow: 0 0 0 0.2rem rgba(11, 79, 138, 0.15);
}

textarea.form-control {
  min-height: 110px;
}

.field-hint {
  color: var(--apac-gray);
  font-size: 0.78rem;
}

.is-invalid {
  border-color: var(--apac-danger) !important;
}

.action-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid #d7e2ee;
  padding: 0.85rem 1.5rem;
  margin-left: calc(-1.5rem);
  margin-right: calc(-1.5rem);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.06);
}

.action-bar .container {
  max-width: none;
  padding: 0;
  width: 100%;
}

.btn-apac {
  background: var(--apac-blue);
  border-color: var(--apac-blue);
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
}

.btn-apac:hover,
.btn-apac:focus {
  background: var(--apac-blue-dark);
  border-color: var(--apac-blue-dark);
  color: #fff;
}

.btn-outline-apac {
  border-color: var(--apac-blue);
  color: var(--apac-blue);
  border-radius: 10px;
  font-weight: 600;
}

.btn-outline-apac:hover {
  background: var(--apac-blue-soft);
  color: var(--apac-blue-dark);
}

.preview-frame {
  width: 100%;
  min-height: 75vh;
  border: 1px solid #cfdceb;
  border-radius: 12px;
  background: #fff;
}

.modal-apac .modal-header {
  background: var(--apac-blue);
  color: #fff;
}

.modal-apac .btn-close {
  filter: invert(1);
}

/* ===== Modal principal estilo formulário APAC ===== */
.modal-apac-sheet .modal-dialog,
.modal-apac-sheet.modal {
  --bs-modal-border-radius: 0;
}

.apac-sheet {
  background: #d9e2ec;
  border: 0;
  border-radius: 0;
  opacity: 1;
}

.modal-apac-sheet .modal-content.apac-sheet {
  background: #d9e2ec;
}

.apac-sheet-topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 1.25rem;
  background: linear-gradient(135deg, #0b4f8a 0%, #062f54 100%);
  color: #fff;
  border-bottom: 3px solid #041e37;
}

.apac-sheet-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.apac-sheet-cross {
  width: 42px;
  height: 42px;
  border: 2px solid #fff;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
}

.apac-sheet-brand strong {
  display: block;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

.apac-sheet-brand small {
  opacity: 0.85;
  font-size: 0.78rem;
}

.apac-sheet-title-box {
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.08);
  padding: 0.45rem 0.85rem;
  text-align: center;
}

.apac-sheet-title-box h5 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.apac-sheet-title-box span {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  opacity: 0.92;
  margin-top: 0.15rem;
}

.apac-sheet-body {
  background:
    linear-gradient(180deg, #e8eef5 0%, #d7e0ea 100%);
  padding: 1rem 1.25rem 1.5rem !important;
}

.apac-official-form {
  max-width: 980px;
  margin: 0 auto;
  background: #fff;
  border: 1.5px solid #111;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  padding: 0;
}

.apac-block {
  border-bottom: 1px solid #111;
}

.apac-block:last-child {
  border-bottom: 0;
}

.apac-block-head {
  background: #111;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.38rem 0.55rem;
  text-align: center;
  line-height: 1.25;
}

.apac-block-head span {
  display: inline-grid;
  place-items: center;
  min-width: 1.4rem;
  height: 1.4rem;
  border: 1px solid rgba(255, 255, 255, 0.55);
  font-size: 0.78rem;
}

.apac-block-body {
  padding: 0.95rem 1rem 1.1rem;
  background: #fff;
}

/* Grade papel oficial */
.apac-grid-row {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid #111;
}

.apac-grid-row:last-child {
  border-bottom: 0;
}

.apac-cell {
  border-right: 1px solid #111;
  padding: 0.2rem 0.35rem 0.35rem;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 48px;
}

.apac-cell:last-child {
  border-right: 0;
}

.apac-cell-grow { flex: 1 1 0; }
.apac-cell-full { flex: 1 1 100%; border-right: 0; }
.apac-cell-cnes { flex: 0 0 140px; }
.apac-cell-pront { flex: 0 0 150px; }
.apac-cell-cns { flex: 1 1 280px; }
.apac-cell-nasc { flex: 0 0 140px; }
.apac-cell-sexo { flex: 0 0 160px; }
.apac-cell-raca { flex: 0 0 120px; }
.apac-cell-ddd { flex: 0 0 70px; }
.apac-cell-tel { flex: 0 0 180px; }
.apac-cell-mun { flex: 1 1 240px; }
.apac-cell-ibge { flex: 0 0 140px; }
.apac-cell-uf { flex: 0 0 70px; }
.apac-cell-cep { flex: 0 0 140px; }
.apac-cell-proc-cod { flex: 0 0 190px; }
.apac-cell-qtd { flex: 0 0 80px; }
.apac-cell-diag { flex: 1 1 280px; }
.apac-cell-cid { flex: 0 0 140px; }
.apac-cell-date { flex: 0 0 150px; }
.apac-cell-stamp { flex: 0 0 180px; }
.apac-cell-stamp-wide { flex: 1 1 220px; }
.apac-cell-doctype { flex: 0 0 140px; }
.apac-cell-orgao { flex: 0 0 150px; }
.apac-cell-apacnum { flex: 0 0 180px; }
.apac-cell-valid { flex: 0 0 240px; }
.apac-cell-cpf { flex: 0 0 190px; }
.apac-cell-hint small { line-height: 1.3; padding-top: 0.2rem; }

.apac-paciente-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  min-height: 30px;
}
.apac-paciente-status .badge { font-size: 0.72rem; font-weight: 600; }

/* ===== Folha APAC no modal = mesma grade do PDF (pdf-builder.php) ===== */
.apac-form-wrap { max-width: 1000px; margin: 0 auto; }

/* ---------- Documento ao lado da folha (Carregar PDF) ---------- */
.apac-sheet-body { position: relative; }
.apac-sheet-body.has-doc {
  overflow: hidden;
  padding: 0 !important;
  display: flex;
}
.apac-split.has-doc {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  width: 100%;
}
.apac-split.has-doc .apac-split-form {
  order: 1;
  flex: 0 0 var(--apac-split-form, 55%);
  min-width: 0;
  overflow: auto;
  padding: 0.9rem;
}
/* A folha mantém a largura oficial; o JS aplica zoom para caber, sem refluir os campos */
.apac-split.has-doc .apac-form-wrap { width: 1000px; max-width: none; }
.apac-split-divider {
  order: 2;
  flex: 0 0 8px;
  cursor: col-resize;
  background: #b8c6d6;
  position: relative;
  touch-action: none;
}
.apac-split-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 2px;
  width: 4px;
  height: 42px;
  margin-top: -21px;
  border-radius: 2px;
  background: repeating-linear-gradient(180deg, #5b6f86 0 3px, transparent 3px 6px);
}
.apac-split-divider:hover,
.apac-split-divider:focus-visible,
.apac-split.resizing .apac-split-divider { background: #0b4f8a; outline: none; }
.apac-split.resizing { cursor: col-resize; user-select: none; }
.apac-split.resizing iframe { pointer-events: none; }

.apac-doc {
  order: 3;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #525659;
}
.apac-split.doc-left .apac-doc { order: 1; }
.apac-split.doc-left .apac-split-form { order: 3; }
.apac-doc-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  background: #fff;
  border-bottom: 2px solid #0b4f8a;
  color: #0b4f8a;
}
.apac-doc-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.85rem;
}
.apac-doc-bar { flex-wrap: wrap; row-gap: 0.3rem; }
.apac-doc-queue { flex: 1 1 220px; min-width: 0; display: flex; align-items: center; gap: 0.25rem; }
.apac-doc-queue .btn { padding: 0.15rem 0.45rem; border: 1px solid #cfdceb; }
.apac-doc-select { flex: 1 1 auto; min-width: 0; font-weight: 700; color: #0b4f8a; font-size: 0.8rem; padding-top: 0.15rem; padding-bottom: 0.15rem; }
.apac-doc-status { font-size: 0.7rem; white-space: nowrap; }
.apac-doc-tools { display: flex; gap: 0.25rem; }
.apac-doc-tools .btn { padding: 0.15rem 0.45rem; border: 1px solid #cfdceb; }
.apac-doc-zoom { align-items: center; padding-right: 0.35rem; margin-right: 0.15rem; border-right: 1px solid #cfdceb; }
.apac-doc-zoom[hidden] { display: none; }
.apac-doc-zoom-label { min-width: 3.4rem; font-size: 0.75rem; font-weight: 700; }
.apac-doc-pages { font-size: 0.72rem; color: #5b6f86; white-space: nowrap; margin-left: 0.25rem; }
.apac-doc-view { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 12px; }
.apac-doc-view iframe { display: block; width: 100%; height: 100%; border: 0; background: #525659; }
.apac-doc-img { display: block; max-width: none; width: 100%; height: auto; margin: 0; background: #fff; }
.apac-img-page { display: inline-block; max-width: 100%; }
.apac-doc-loading { color: #fff; padding: 1rem; display: flex; gap: 0.5rem; align-items: center; }
.apac-pdf-page {
  position: relative;
  margin: 0 auto 12px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  touch-action: none;
}
.apac-pdf-page canvas { display: block; }

/* Seleção de linha para a Gemini */
.apac-ai-rubber {
  position: absolute;
  z-index: 5;
  border: 2px solid #0b4f8a;
  background: rgba(11, 79, 138, 0.18);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7);
  pointer-events: none;
}
.apac-ai-rubber.invalid {
  border-color: #b42318;
  background: rgba(180, 35, 24, 0.15);
}
.apac-ai-marks {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
.apac-ai-mark {
  position: absolute;
  pointer-events: auto;
  border: 1.5px solid #1f6f43;
  background: rgba(31, 111, 67, 0.14);
  border-radius: 3px;
  padding: 0;
  cursor: pointer;
  display: block;
}
.apac-ai-mark-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  display: grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 999px;
  background: #1f6f43;
  color: #fff;
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  border: 2px solid #fff;
  pointer-events: none;
}
.apac-ai-mark:hover,
.apac-ai-mark:focus-visible {
  background: rgba(31, 111, 67, 0.28);
  outline: 2px solid #1f6f43;
  outline-offset: 1px;
  z-index: 21;
}
#geminiResultModal {
  z-index: 2100 !important;
}
.modal-backdrop.apac-gemini-backdrop {
  z-index: 2090 !important;
}
.apac-ai-preview img {
  display: block;
  max-width: 100%;
  max-height: 120px;
  margin: 0 auto;
  border: 1px solid #cfdceb;
  border-radius: 6px;
  background: #fff;
}

/* Ícone flutuante Colar (após Copiar da IA) */
.apac-paste-fab {
  position: fixed;
  z-index: 2000;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  border: 0;
  border-radius: 999px;
  background: #1f6f43;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(15, 50, 30, 0.35);
  cursor: pointer;
  animation: apac-paste-pop 0.18s ease-out;
}
.apac-paste-fab:hover,
.apac-paste-fab:focus-visible {
  background: #185734;
  color: #fff;
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.apac-paste-fab i { font-size: 0.95rem; }
@keyframes apac-paste-pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.apac-doc-view { cursor: crosshair; }
.apac-doc-view .apac-ai-mark { cursor: pointer; }

/* Camada de texto do pdf.js (permite selecionar e copiar texto do laudo) */
.apac-pdf-page .textLayer {
  position: absolute;
  text-align: initial;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  letter-spacing: normal;
  word-spacing: normal;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
  z-index: 0;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}
.apac-pdf-page .textLayer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  user-select: text;
}
.apac-pdf-page .textLayer > :not(.markedContent),
.apac-pdf-page .textLayer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1;
  --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.apac-pdf-page .textLayer .markedContent { display: contents; }
.apac-pdf-page .textLayer ::selection { background: rgba(0, 90, 255, 0.3); color: transparent; }
.apac-pdf-page .textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  cursor: default;
  user-select: none;
}

.apac-doc-drop {
  position: absolute;
  inset: 0.6rem;
  z-index: 40;
  display: grid;
  place-items: center;
  border: 3px dashed #0b4f8a;
  border-radius: 14px;
  background: rgba(232, 240, 250, 0.92);
  pointer-events: none;
  text-align: center;
  color: #0b4f8a;
}
.apac-doc-drop[hidden] { display: none; }
.apac-doc-drop i { display: block; font-size: 2.6rem; }
.apac-doc-drop strong { display: block; font-size: 1.15rem; }
.apac-doc-drop small { color: #36506b; }

@media (max-width: 900px) {
  .apac-split.has-doc { flex-direction: column; }
  .apac-split.has-doc .apac-split-form { flex: 1 1 auto; }
  .apac-split.has-doc .apac-doc { order: 0; flex: 0 0 45%; }
  .apac-split-divider { display: none; }
}
.apac-paper {
  background: #fff;
  border: 1.5px solid #555;
  border-radius: 4px 4px 16px 16px;
  padding: 10px 12px 18px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}
.ap-topo img { display: block; width: 100%; height: auto; }

.ap-bar {
  background: #1e1e1e;
  color: #fff;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 0.32rem 0.5rem;
  margin: 12px 0 2px;
}

.ap-row { display: flex; margin-top: 14px; }

.ap-box {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  min-height: 46px;
  border: 1px solid #7a7a7a;
  background: #fff;
  padding: 10px 6px 4px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.ap-legend {
  position: absolute;
  top: -0.6em;
  left: min(48px, 10%);
  max-width: calc(100% - 10px);
  margin: 0;
  padding: 0 4px;
  background: #fff;
  color: #2b2b2b;
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ap-c .ap-legend { left: 50%; transform: translateX(-50%); }
.ap-r .ap-legend { left: auto; right: 6px; }
.ap-l0 .ap-legend { left: 3px; }
.ap-l3 .ap-legend { left: min(14px, 4%); }
.ap-l7 .ap-legend { left: min(36px, 4%); }
.ap-in .ap-legend,
.ap-inr .ap-legend { position: static; transform: none; padding: 0; margin-bottom: 2px; max-width: 100%; }
.ap-inr .ap-legend { text-align: right; }
.ap-in, .ap-inr { padding-top: 6px; }

.apac-paper .form-control {
  border: 0;
  border-bottom: 1px dashed #b7c2cf;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  min-height: 28px;
  padding: 2px 3px;
  font-size: 0.88rem;
  font-weight: 600;
}
.apac-paper .form-control::placeholder { font-size: 0.8rem; font-weight: 400; }
.apac-paper .form-control:focus { border-bottom-color: #0b4f8a; background: #f5f9ff; }
.apac-paper .apac-boxes { letter-spacing: 0.12em; }

.ap-check { display: flex; align-items: center; justify-content: space-around; gap: 6px; min-height: 28px; flex-wrap: wrap; }
.ap-check-opt { display: inline-flex; align-items: center; gap: 3px; font-size: 0.8rem; color: #333; margin: 0; cursor: pointer; white-space: nowrap; }
.ap-check-opt input { margin: 0; }

.ap-phone { display: flex; gap: 0; }
.ap-phone-ddd { flex: 0 0 20%; border-right: 1px solid #7a7a7a; padding-right: 4px; }
.ap-phone-num { flex: 1 1 auto; padding-left: 4px; }
.ap-sub { display: block; text-align: center; font-size: 0.55rem; color: #444; line-height: 1; }
.ap-box-phone { padding-top: 8px; }

.ap-box-area { justify-content: flex-start; padding-top: 12px; }
.ap-area { min-height: 70px; resize: vertical; border: 0 !important; border-bottom: 1px dashed #b7c2cf !important; }
.ap-inner-label { font-size: 0.62rem; font-weight: 600; color: #2b2b2b; margin: 8px 0 0 min(36px, 4%); text-transform: uppercase; }

.ap-grid { display: grid; row-gap: 14px; margin-top: 14px; }
/* colunas em mm do PDF — SOLICITAÇÃO: 11,9|51,3|104,6·105,2|133,7·134,3|196,5 */
.ap-grid-sol {
  grid-template-columns: minmax(0, 39.4fr) minmax(0, 53.3fr) minmax(0, 0.6fr) minmax(0, 28.5fr) minmax(0, 0.6fr) minmax(0, 62.2fr);
}
/* AUTORIZAÇÃO: 11,9|41,3|51,1|100,0·100,6|132,0·134,3|196,5 */
.ap-grid-aut {
  grid-template-columns: minmax(0, 29.4fr) minmax(0, 9.8fr) minmax(0, 48.9fr) minmax(0, 0.6fr) minmax(0, 31.4fr) minmax(0, 2.3fr) minmax(0, 62.2fr);
}
.ap-box-stamp { justify-content: stretch; }
.ap-stamp {
  flex: 1;
  min-height: 60px;
  border: 1px dashed #b7c2cf;
  background: #fafafa;
  color: #8a96a3;
  font-size: 0.7rem;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 4px;
}
.ap-valid { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px; }
.ap-valid span { font-size: 0.78rem; color: #555; }

@media (max-width: 760px) {
  .ap-row { flex-wrap: wrap; margin-top: 0; }
  .ap-row .ap-box { width: 100% !important; margin-left: 0 !important; margin-top: 14px; }
  .ap-grid { grid-template-columns: 1fr; }
  .ap-grid .ap-box { grid-column: 1 !important; grid-row: auto !important; }
}

/* Modais de paciente com a mesma grade da folha APAC */
.apac-official-form-modal {
  max-width: none;
  box-shadow: none;
}
@media (min-width: 700px) {
  .apac-official-form-modal .apac-grid-row { flex-wrap: nowrap; }
  .apac-official-form-modal .apac-cell { flex-shrink: 1; min-width: 0; }
  .apac-official-form-modal .apac-cell-sexo { flex-shrink: 0; }
}
.modal-body.apac-sheet-body { padding: 0.9rem !important; }
.modal-paciente-sheet { max-width: min(1000px, 96vw); }

/* SOLICITAÇÃO — carimbo alto à direita (oficial) */
.apac-sol-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 180px;
  grid-template-areas:
    "nome data stamp"
    "doc  docnum stamp";
}

.apac-sol-nome { grid-area: nome; }
.apac-sol-data { grid-area: data; }
.apac-sol-stamp { grid-area: stamp; min-height: 110px; border-right: 0; }
.apac-sol-doc { grid-area: doc; }
.apac-sol-docnum { grid-area: docnum; border-right: 0; }

/* AUTORIZAÇÃO — carimbo alto à direita; nº da APAC na linha de baixo */
.apac-aut-grid {
  display: grid;
  grid-template-columns: 1.45fr 0.7fr 1fr;
  grid-template-areas:
    "nome  orgao stamp"
    "doc   docnum stamp"
    "data  num   valid";
}

.apac-aut-nome { grid-area: nome; }
.apac-aut-orgao { grid-area: orgao; }
.apac-aut-num { grid-area: num; }
.apac-aut-num .apac-cell-input {
  letter-spacing: 0.08em;
  text-align: center;
}
.apac-aut-doc { grid-area: doc; flex: 0 0 auto; max-width: none; }
.apac-aut-docnum { grid-area: docnum; }
.apac-aut-data { grid-area: data; max-width: none; }
.apac-aut-stamp {
  grid-area: stamp;
  min-height: 120px;
  border-right: 0;
}
.apac-aut-stamp .apac-stamp-box {
  flex: 1;
  min-height: 72px;
}
.apac-aut-valid { grid-area: valid; border-right: 0; }

.apac-cell-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #1f2933;
  margin: 0 0 0.15rem;
  line-height: 1.2;
}

.apac-cell-input,
.apac-official-form .form-control,
.apac-official-form .form-select {
  border-radius: 0 !important;
  border: 0 !important;
  border-bottom: 1px dashed #94a3b8 !important;
  min-height: 30px;
  padding: 0.15rem 0.2rem;
  background: transparent;
  box-shadow: none !important;
  font-size: 0.92rem;
  font-weight: 600;
}

.apac-official-form textarea.form-control {
  min-height: 72px;
  border: 1px solid #cbd5e1 !important;
  resize: vertical;
}

.apac-cell-input:focus,
.apac-official-form .form-control:focus,
.apac-official-form .form-select:focus {
  border-bottom-color: #0b4f8a !important;
  background: #f8fbff;
}

.apac-boxes {
  font-family: "Consolas", "Courier New", monospace;
  letter-spacing: 0.12em;
}

.apac-sexo {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 30px;
  padding-top: 0.15rem;
}

.apac-stamp-box {
  flex: 1;
  min-height: 42px;
  border: 1px dashed #94a3b8;
  display: grid;
  place-items: center;
  color: #64748b;
  font-size: 0.72rem;
  text-align: center;
  padding: 0.35rem;
  background: #fafafa;
}

.apac-valid-pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.35rem;
  align-items: center;
}

.apac-valid-pair span {
  font-size: 0.75rem;
  color: #64748b;
}

.apac-cell-area {
  min-height: 110px;
}

.apac-official-form .form-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #334155;
  margin-bottom: 0.25rem;
}

@media (max-width: 900px) {
  .apac-cell,
  .apac-cell-cnes,
  .apac-cell-pront,
  .apac-cell-cns,
  .apac-cell-nasc,
  .apac-cell-sexo,
  .apac-cell-raca,
  .apac-cell-ddd,
  .apac-cell-tel,
  .apac-cell-mun,
  .apac-cell-ibge,
  .apac-cell-uf,
  .apac-cell-cep,
  .apac-cell-proc-cod,
  .apac-cell-qtd,
  .apac-cell-diag,
  .apac-cell-cid,
  .apac-cell-date,
  .apac-cell-stamp,
  .apac-cell-doctype,
  .apac-cell-orgao,
  .apac-cell-apacnum,
  .apac-cell-valid {
    flex: 1 1 100%;
    border-right: 0;
    border-bottom: 1px solid #e2e8f0;
  }

  .apac-sol-grid,
  .apac-aut-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "nome"
      "data"
      "stamp"
      "doc"
      "docnum";
  }

  .apac-aut-grid {
    grid-template-areas:
      "nome"
      "orgao"
      "num"
      "doc"
      "docnum"
      "data"
      "stamp"
      "valid";
  }
}

.apac-sheet-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  background: #fff;
  border-top: 2px solid #0b4f8a;
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.preview-frame-full {
  min-height: calc(100vh - 140px);
  border: 0;
  border-radius: 0;
}

@media (max-width: 768px) {
  .apac-sheet-topbar {
    grid-template-columns: 1fr auto;
  }

  .apac-sheet-brand {
    grid-column: 1 / 2;
  }

  .apac-sheet-title-box {
    grid-column: 1 / -1;
    order: 3;
  }
}

.toast-container {
  z-index: 1080;
}

.char-counter.over {
  color: var(--apac-danger);
  font-weight: 700;
}

.autocomplete-wrap {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  background: #fff;
  border: 1px solid #cfdceb;
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  max-height: 260px;
  overflow: auto;
}

.autocomplete-item {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border-bottom: 1px solid #edf2f7;
  color: #1f2933;
}

.autocomplete-item:last-child {
  border-bottom: 0;
}

.autocomplete-item.active {
  background: var(--apac-blue-soft);
  box-shadow: inset 3px 0 0 var(--apac-blue);
}

.autocomplete-item.continue.active { background: #e8f5ee; box-shadow: inset 3px 0 0 #1f6f43; }

.autocomplete-item:hover {
  background: var(--apac-blue-soft);
}

.autocomplete-item small {
  color: var(--apac-gray);
}

.autocomplete-item.create {
  color: var(--apac-blue);
  font-weight: 700;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
}

.autocomplete-list { min-width: min(360px, 90vw); max-height: 320px; }

.autocomplete-empty {
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  color: var(--apac-gray);
  border-bottom: 1px solid #edf2f7;
}

.autocomplete-actions {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f7fafd;
  border-top: 1px solid #cfdceb;
}

.autocomplete-actions .autocomplete-item {
  border-bottom: 0;
  font-size: 0.82rem;
  justify-content: center;
}

.autocomplete-actions .autocomplete-item + .autocomplete-item { border-left: 1px solid #cfdceb; }

.autocomplete-item.continue {
  color: #1f6f43;
  font-weight: 700;
  flex-direction: column;
  align-items: flex-start;
}

.autocomplete-item.continue small { font-weight: 400; font-size: 0.7rem; }
.autocomplete-item.continue:hover { background: #e8f5ee; }

.apac-status-select { width: auto; min-width: 130px; }

.apac-form-scroll {
  display: flex;
  flex-direction: column;
  gap: 0;
}

#apacFormModal .modal-body {
  overflow-y: auto;
}

@media (max-width: 992px) {
  .app-sidebar {
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  body.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .app-main {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .app-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1035;
  }

  .app-backdrop[hidden] {
    display: none !important;
  }

  .app-content {
    padding: 0.5rem 1rem 5rem;
  }

  .action-bar {
    margin-left: -1rem;
    margin-right: -1rem;
    padding: 0.85rem 1rem;
  }
}

@media (max-width: 768px) {
  .action-bar .btn {
    width: 100%;
    margin-bottom: 0.4rem;
  }

  .section-card {
    padding: 1rem;
  }
}
