:root {
  --teal: #00898a;
  --teal-dark: #00626a;
  --teal-soft: #e6f4f4;
  --cyan: #23cdcd;
  --navy: #0c1c2a;
  --ink: #142433;
  --muted: #667085;
  --line: #dde4ea;
  --line-soft: #eaeff3;
  --soft: #f6f9fa;
  --paper: #ffffff;
  --warn: #f8ae41;
  --danger: #b42318;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 34, 48, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 34, 48, 0.08);
  --shadow-lg: 0 18px 48px rgba(12, 28, 42, 0.14);

  --preview-zoom: 0.7;
}

* {
  box-sizing: border-box;
}

/* O atributo hidden precisa vencer os display: grid/flex declarados abaixo
   (senão a tela de login continua visível por cima do app após entrar). */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: #eef2f5;
  color: var(--ink);
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

button,
input,
textarea,
select {
  font: inherit;
}

/* ------------------------------------------------------------------ botões */
button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, color 0.15s;
  box-shadow: var(--shadow-sm);
}

button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
  box-shadow: 0 2px 8px rgba(0, 137, 138, 0.28);
}

button.primary:hover {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
  color: #fff;
}

button.block {
  width: 100%;
  padding: 12px;
}

button.link {
  border: 0;
  box-shadow: none;
  background: none;
  padding: 2px 4px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
}

button.link:hover {
  color: var(--teal-dark);
}

button.mini {
  padding: 5px 9px;
  font-size: 12px;
  box-shadow: none;
}

button.mini.danger {
  color: var(--danger);
  border-color: #f0cfcb;
  background: #fff6f5;
}

button.mini.danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ------------------------------------------------------------------- modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-fundo {
  position: absolute;
  inset: 0;
  background: rgba(12, 28, 42, 0.55);
  backdrop-filter: blur(3px);
  animation: modal-fade 0.18s ease-out;
}

.modal-caixa {
  position: relative;
  width: min(100%, 440px);
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 26px 60px rgba(4, 16, 26, 0.4);
  animation: modal-subir 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-fade {
  from { opacity: 0; }
}

@keyframes modal-subir {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
}

.modal-icone {
  width: 50px;
  height: 50px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 800;
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.modal[data-tom="perigo"] .modal-icone {
  background: #fef3f2;
  color: var(--danger);
}

.modal[data-tom="aviso"] .modal-icone {
  background: #fffaeb;
  color: #b54708;
}

.modal[data-tom="ok"] .modal-icone {
  background: #ecfdf3;
  color: #087443;
}

.modal-caixa h2 {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.3;
  color: var(--navy);
}

.modal-caixa p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
}

.modal-caixa label {
  margin: 18px 0 0;
  text-align: left;
}

.modal-acoes {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.modal-acoes button {
  flex: 1;
  padding: 11px;
}

/* Trava o fundo enquanto o modal está aberto */
body.com-modal {
  overflow: hidden;
}

/* ------------------------------------------------------------------- login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 12% -10%, rgba(35, 205, 205, 0.22), transparent 60%),
    linear-gradient(140deg, #0d2230, var(--navy));
}

.login-card {
  width: min(100%, 400px);
  background: #fff;
  border-radius: 14px;
  padding: 34px 30px 30px;
  box-shadow: 0 30px 70px rgba(4, 16, 26, 0.45);
}

.login-logo {
  width: 152px;
  height: auto;
  display: block;
  margin-bottom: 22px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 21px;
  color: var(--navy);
}

.login-sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.login-erro {
  margin: 0 0 14px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: #fef3f2;
  border: 1px solid #f4c9c4;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  flex-shrink: 0;
}

.brand-logo {
  width: 132px;
  height: auto;
  display: block;
}

.brand-text {
  padding-left: 13px;
  border-left: 1px solid var(--line);
}

.brand-text strong,
.brand-text span {
  display: block;
}

.brand-text strong {
  font-size: 14px;
  color: var(--navy);
}

.brand-text span {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 1px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.btn-group {
  display: flex;
}

.btn-group button {
  border-radius: 0;
  margin-left: -1px;
  box-shadow: none;
}

.btn-group button:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  margin-left: 0;
}

.btn-group button:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.btn-group button:hover {
  position: relative;
  z-index: 1;
}

.doc-picker {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.doc-picker select {
  width: auto;
  min-width: 190px;
  max-width: 260px;
  padding: 8px 10px;
  font-weight: 600;
}

/* Indicador de salvamento — o usuário nunca clica em "Salvar", então
   este selo é a única evidência de que o servidor recebeu a alteração. */
.save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}

.save-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.save-status[data-state="saved"] {
  color: #087443;
  background: #ecfdf3;
  border-color: #c6ecd7;
}

.save-status[data-state="dirty"] {
  color: #b54708;
  background: #fffaeb;
  border-color: #f5dfa8;
}

.save-status[data-state="saving"] {
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-color: #b9e0e0;
}

.save-status[data-state="error"] {
  color: var(--danger);
  background: #fef3f2;
  border-color: #f4c9c4;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}

/* ------------------------------------------------------ painel de clientes */
.painel {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 60px;
}

.painel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.painel-head h1 {
  margin: 0;
  font-size: 26px;
  color: var(--navy);
  letter-spacing: -0.02em;
}

.painel-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.busca {
  margin: 0;
  min-width: 300px;
}

.busca input {
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.painel-lista {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.tabela-clientes {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 13px;
}

.tabela-clientes thead th {
  background: var(--soft);
  color: var(--muted);
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
}

.tabela-clientes tbody tr {
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background 0.12s;
}

.tabela-clientes tbody tr:last-child {
  border-bottom: 0;
}

.tabela-clientes tbody tr:hover {
  background: var(--teal-soft);
}

.tabela-clientes td {
  border: 0;
  padding: 13px 16px;
  vertical-align: middle;
  color: var(--ink);
}

.tabela-clientes td strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
}

.tabela-clientes td small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

.tabela-clientes .rev {
  display: inline-block;
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--teal-soft);
  border: 1px solid #b9e0e0;
  color: var(--teal-dark);
  font-size: 11.5px;
  font-weight: 800;
  text-align: center;
}

/* Sempre visíveis: escondê-las no hover deixa a linha parecendo sem ações. */
.tabela-clientes .acoes {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.painel-vazio {
  padding: 70px 24px;
  text-align: center;
}

.painel-vazio h2 {
  margin: 0 0 6px;
  font-size: 17px;
  color: var(--navy);
}

.painel-vazio p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
}

/* Em telas estreitas a tabela rola em vez de espremer as colunas. */
@media (max-width: 860px) {
  .painel-lista {
    overflow-x: auto;
  }

  .tabela-clientes {
    min-width: 720px;
  }

  .tabela-clientes .acoes {
    opacity: 1;
  }
}

/* ---------------------------------------------------- ficha do cliente */
.ficha {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.ficha-grid {
  display: grid;
  grid-template-columns: minmax(460px, 1fr) minmax(320px, 420px);
  gap: 20px;
  align-items: start;
}

.ficha-docs {
  display: grid;
  gap: 16px;
}

.bloco-docs,
.bloco-gerar {
  padding: 20px;
}

.bloco-docs h2,
.bloco-gerar h2 {
  margin: 0 0 14px;
  font-size: 15px;
  color: var(--navy);
}

.docs-lista {
  display: grid;
  gap: 8px;
}

.doc-linha {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--soft);
}

.doc-tipo {
  flex-shrink: 0;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.doc-info {
  flex: 1;
  min-width: 0;
}

.doc-info strong {
  display: block;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-info small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

.doc-acoes {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}

/* Cards dos tipos de documento. PCMSO e LTCAT ficam desabilitados
   até os geradores existirem — melhor mostrar o roadmap do que esconder. */
.tipos-doc {
  display: grid;
  gap: 9px;
}

/* Separador das fases do ciclo do cliente (proposta/contrato × técnicos) */
.fase {
  display: block;
  margin: 4px 0 2px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fase:not(:first-child) {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.tipo-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}

.tipo-card:hover:not(:disabled) {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.tipo-card strong {
  display: block;
  font-size: 14px;
  color: var(--navy);
}

.tipo-card small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 400;
}

.tipo-card:disabled {
  opacity: 1;
  background: var(--soft);
  color: var(--muted);
  cursor: not-allowed;
}

.tipo-card:disabled strong {
  color: var(--muted);
}

.em-breve {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #f2f4f7;
  border: 1px solid #e2e6ea;
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

.sem-doc {
  color: var(--muted);
  font-style: italic;
}

.doc-titulo {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.danger-btn {
  color: var(--danger);
  border-color: #f0cfcb;
  background: #fff6f5;
}

.danger-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

@media (max-width: 1100px) {
  .ficha-grid {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------------- workspace */
.workspace {
  display: grid;
  /* Sidebar larga: o formulário é onde o trabalho acontece.
     A folha A4 da prévia encolhe via --preview-zoom. */
  grid-template-columns: minmax(460px, 620px) minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  align-items: start;
}

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.editor {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 108px);
  overflow: auto;
  overscroll-behavior: contain;
}

/* --------------------------------------------------------------------- abas */
.tabs {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  background: var(--soft);
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
}

.tab {
  flex: 1 1 auto;
  min-width: 90px;
  border: 0;
  border-right: 1px solid var(--line-soft);
  border-radius: 0;
  padding: 13px 8px;
  color: var(--muted);
  background: transparent;
  box-shadow: none;
  font-size: 12.5px;
}

.tab:last-child {
  border-right: 0;
}

.tab:hover {
  background: #fff;
  color: var(--teal-dark);
}

.tab.active {
  background: #fff;
  color: var(--teal-dark);
  box-shadow: inset 0 -3px 0 var(--teal);
  font-weight: 700;
}

.tab-panel {
  display: none;
  padding: 22px;
}

.tab-panel.active {
  display: block;
}

.tab-panel h2,
.section-head h2 {
  margin: 0 0 16px;
  font-size: 17px;
  color: var(--navy);
  letter-spacing: -0.01em;
}

.hint {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-left: 3px solid var(--cyan);
  background: var(--teal-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: #35525c;
  font-size: 12px;
  line-height: 1.45;
}

/* ---------------------------------------------------------------- campos */
label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: #344054;
  font-size: 12.5px;
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  font-weight: 400;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  outline: 0;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 137, 138, 0.13);
}

textarea {
  min-height: 76px;
  resize: vertical;
  line-height: 1.45;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ------------------------------------------------------- coleções (rows) */
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
}

.count {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.rows {
  display: grid;
  gap: 9px;
}

.vazio {
  margin: 0;
  padding: 26px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* Cada registro é um <details>: fechado por padrão, para uma lista
   longa (30 riscos) caber na tela. */
.row-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.row-card:hover {
  border-color: #c3d0d9;
}

.row-card[open] {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 137, 138, 0.09);
}

.row-card summary {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  cursor: pointer;
  list-style: none;
  background: var(--soft);
  user-select: none;
}

.row-card summary::-webkit-details-marker {
  display: none;
}

.row-card[open] summary {
  background: var(--teal-soft);
  border-bottom: 1px solid var(--line-soft);
}

.row-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.row-card[open] .row-num {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.row-text {
  flex: 1;
  min-width: 0;
}

.row-text strong,
.row-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-text strong {
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
}

.row-text small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

/* Seta do accordion */
.row-card summary::after {
  content: "";
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  margin: -4px 4px 0;
  transition: transform 0.18s;
}

.row-card[open] summary::after {
  transform: rotate(-135deg);
  margin-top: 2px;
  border-color: var(--teal-dark);
}

.row-body {
  padding: 16px 13px 13px;
}

.row-body label:last-of-type {
  margin-bottom: 14px;
}

/* ------------------------------------------------------- aba de textos */
.grupo-textos {
  margin-bottom: 18px;
}

.grupo-textos h3 {
  margin: 0 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.grupo-textos .row-card {
  margin-bottom: 8px;
}

.texto-corpo {
  font-family: "SF Mono", "Consolas", "Menlo", monospace;
  font-size: 12px;
  line-height: 1.55;
  resize: vertical;
}

.texto-acoes {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

.hint code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #fff;
  border: 1px solid #cfe6e6;
  font-size: 11px;
  color: var(--teal-dark);
}

.badge-custom {
  color: #b54708;
  background: #fffaeb;
  border-color: #f5dfa8;
}

/* Selo de nível de risco / status, visível com a linha fechada */
.badge {
  flex-shrink: 0;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
}

.badge.risk-low {
  color: #087443;
  background: #ecfdf3;
  border-color: #c6ecd7;
}

.badge.risk-tol {
  color: #4b7a12;
  background: #f4faea;
  border-color: #d9ebbd;
}

.badge.risk-med {
  color: #b54708;
  background: #fffaeb;
  border-color: #f5dfa8;
}

.badge.risk-high {
  color: #b42318;
  background: #fef3f2;
  border-color: #f4c9c4;
}

.badge.risk-crit {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.badge.risk-none,
.badge.status-planejado {
  color: var(--muted);
  background: #f2f4f7;
  border-color: #e2e6ea;
}

.badge.status-em-andamento {
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-color: #b9e0e0;
}

.badge.status-concluído,
.badge.status-concluido {
  color: #087443;
  background: #ecfdf3;
  border-color: #c6ecd7;
}

.badge.status-atrasado {
  color: var(--danger);
  background: #fef3f2;
  border-color: #f4c9c4;
}

/* ----------------------------------------------------------------- prévia */
.preview-wrap {
  min-width: 0;
}

.preview-actions {
  position: sticky;
  top: 88px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 9px 13px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.preview-title {
  flex: 1;
  color: var(--muted);
  font-weight: 700;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.zoom {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.zoom button {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
}

.zoom button:hover {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

#zoomLabel {
  min-width: 42px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.document {
  width: max-content;
  margin: 0 auto 40px;
}

/* A folha tem 210mm fixos; encolhe a prévia para caber na coluna. */
@media screen {
  .document {
    zoom: var(--preview-zoom);
  }
}

/* Bancada: onde o paginador monta e MEDE as folhas antes de exibi-las.
   Fica fora da tela e sem zoom, para as medidas serem as reais da A4. */
#bancada {
  position: absolute;
  top: 0;
  left: -20000px;
  width: 210mm;
  zoom: 1;
  visibility: hidden;
  pointer-events: none;
}

/* 292mm (e não 297mm) é o mesmo orçamento usado pelo paginador em JS:
   deixa folga até a borda do papel para o rodapé nunca tombar de página. */
.page {
  width: 210mm;
  min-height: 292mm;
  margin: 0 auto 18px;
  padding: 17mm 16mm 16mm;
  background: var(--paper);
  box-shadow: var(--shadow-lg);
  border-radius: 2px;
  position: relative;
  overflow: visible;
  display: flex;
  flex-direction: column;
}

/* Empurra o rodapé para a base da folha, independente do conteúdo. */
.page-corpo {
  flex: 1;
}

.cover-page {
  display: grid;
  align-content: space-between;
  background: linear-gradient(130deg, rgba(0, 137, 138, 0.96), rgba(12, 28, 42, 0.98));
  color: #fff;
  overflow: hidden;
}

.cover-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.cover-page > *:not(.cover-bg) {
  position: relative;
  z-index: 1;
}

.cover-rule {
  width: 82px;
  height: 5px;
  background: var(--cyan);
  margin-bottom: 28px;
}

.cover-title {
  font-size: 42px;
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.01em;
  max-width: 640px;
}

.cover-subtitle {
  margin-top: 20px;
  font-size: 15px;
  line-height: 1.5;
  max-width: 620px;
  color: rgba(255, 255, 255, 0.86);
}

.cover-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 36px;
}

.cover-meta div {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px;
}

.cover-meta span,
.doc-meta span {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.74;
}

.cover-meta strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
}

.mdmed-sign {
  display: grid;
  grid-template-columns: minmax(230px, 300px) 1px minmax(340px, 1fr);
  align-items: center;
  gap: 24px;
  font-weight: 800;
  max-width: 760px;
}

.cover-logo {
  width: 100%;
  max-width: 330px;
  height: auto;
  display: block;
}

.cover-divider {
  width: 1px;
  height: 76px;
  background: rgba(255, 255, 255, 0.34);
}

.cover-contact {
  display: grid;
  gap: 7px;
  color: rgba(255, 255, 255, 0.92);
}

.cover-contact strong {
  display: block;
  font-size: 15px;
  line-height: 1.25;
  white-space: nowrap;
}

.cover-contact span {
  display: block;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.78);
}

.cover-contact .contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding-top: 2px;
  font-size: 13px;
  line-height: 1.35;
  font-weight: 700;
  color: #fff;
}

.cover-contact .contact-row span {
  color: #fff;
  font-size: inherit;
  font-weight: inherit;
}

.header-logo {
  width: 138px;
  height: auto;
  display: block;
  margin-bottom: 4px;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 10px;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--teal);
}

.doc-header strong {
  color: var(--teal-dark);
  font-size: 18px;
}

.doc-header span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.doc-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  font-size: 11px;
  text-align: right;
}

.doc-meta strong {
  font-size: 11px;
  color: var(--ink);
}

.page h1 {
  margin: 0 0 16px;
  color: var(--teal-dark);
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.page h2 {
  margin: 18px 0 8px;
  color: var(--teal-dark);
  font-size: 16px;
  line-height: 1.25;
}

.page h3 {
  margin: 13px 0 6px;
  color: var(--navy);
  font-size: 13px;
}

.page p,
.page li {
  font-size: 11.5px;
  line-height: 1.48;
}

.page p {
  margin: 0 0 8px;
}

.page ul,
.page ol {
  margin: 6px 0 10px 18px;
  padding: 0;
}

/* Compacto de propósito: a seção 1 tem 20 campos e precisa caber
   numa única A4, senão o rodapé transborda para uma página extra. */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin: 6px 0 10px;
}

.info {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  min-height: 0;
}

.info span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 1px;
}

.info strong {
  display: block;
  font-size: 11px;
  line-height: 1.3;
}

.note {
  border-left: 4px solid var(--warn);
  background: #fff8eb;
  padding: 10px 12px;
  margin: 10px 0;
}

.note.law {
  border-left-color: #b54708;
  background: #fdf3ea;
}

.toc {
  columns: 2;
  column-gap: 24px;
  padding-left: 0;
  list-style: none;
}

.toc li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px dotted #b7c1ca;
  margin-bottom: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 13px;
  font-size: 10px;
  page-break-inside: auto;
}

th {
  background: var(--teal-dark);
  color: #fff;
  text-align: left;
}

th,
td {
  border: 1px solid #cfd8df;
  padding: 6px;
  vertical-align: top;
}

tr {
  page-break-inside: avoid;
}

/* Cores do nível de risco dentro do documento impresso */
td.risk-low {
  color: #087443;
  font-weight: 800;
}

td.risk-tol {
  color: #4b7a12;
  font-weight: 800;
}

td.risk-med {
  color: #b54708;
  font-weight: 800;
}

td.risk-high {
  color: #b42318;
  font-weight: 800;
}

td.risk-crit {
  color: #fff;
  background: var(--danger);
  font-weight: 800;
}

td.risk-none {
  color: var(--muted);
  font-weight: 700;
}

table.inventory {
  font-size: 8.5px;
}

table.inventory th,
table.inventory td {
  padding: 4px;
}

thead {
  display: table-header-group;
}

.signature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 34px;
  margin-top: 42px;
}

.signature {
  border-top: 1px solid var(--ink);
  padding-top: 8px;
  text-align: center;
  font-size: 11px;
}

.footer {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
  color: var(--muted);
  font-size: 8.5px;
  line-height: 1.35;
}

.footer > span:first-child {
  padding-top: 10px;
}

.footer strong {
  color: var(--teal-dark);
}

.footer-page {
  white-space: nowrap;
  color: var(--teal-dark);
  font-weight: 700;
}

/* -------------------------------------------------------------- responsivo */
@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .editor {
    position: static;
    max-height: none;
  }

  .preview-actions {
    position: static;
  }

  .document {
    zoom: 1;
    width: 100%;
  }

  .page {
    width: 100%;
    min-height: auto;
  }
}

/* ---------------------------------------------------------------- impressão */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: #fff;
  }

  .topbar,
  .editor,
  .preview-actions,
  .login-screen {
    display: none !important;
  }

  .workspace {
    display: block;
    padding: 0;
  }

  .document {
    zoom: 1; /* o PDF sai em escala real, independente do zoom da tela */
    width: 100%;
    margin: 0;
  }

  /* A folha NÃO pode ter os 297mm exatos da A4: 297mm dá ≈1122,52px, e o
     arredondamento de sub-pixel joga o rodapé (último item do flex, colado na
     borda inferior) para uma página extra em branco. A folga evita isso. */
  #bancada {
    display: none !important;
  }

  .page {
    width: 210mm;
    min-height: 292mm; /* mesmo orçamento do paginador; a folga evita que o
                          rodapé tombe para uma folha extra em branco */
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    page-break-after: always;
    break-after: page;
  }

  .page:last-child {
    page-break-after: auto;
    break-after: auto;
  }
}

@page {
  size: A4;
  margin: 0;
}
