/* ========= Reset / base ========= */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Arial, sans-serif;
  background: #eceef1;
  color: #222;
}

/* ========= Toolbar (form em cima) ========= */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
  border-bottom: 1px solid #d6d9de;
  padding: 14px 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-start;
  box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}
.brand img { width: 44px; height: 44px; object-fit: contain; }
.brand h1 {
  font-size: 16px;
  margin: 0;
  color: #1f4f2a;
}
.brand small { color: #666; font-size: 12px; }

.form {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  flex: 1 1 720px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field.col2 { grid-column: span 2; }
.field.col3 { grid-column: span 3; }
.field.col4 { grid-column: span 4; }
.field.col6 { grid-column: 1 / -1; }
.field span {
  font-size: 11px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.field input, .field select {
  padding: 8px 10px;
  border: 1px solid #c8cdd4;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: #38761d;
  box-shadow: 0 0 0 2px rgba(56,118,29,.15);
}
.field input[readonly] { background: #f5f6f8; color: #1f4f2a; font-weight: 600; }

.actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.btn {
  border: 0;
  padding: 10px 16px;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn.primary { background: #1f4f2a; color: #fff; }
.btn.primary:hover:not(:disabled) { background: #2c6c3b; }
.btn.whats { background: #25d366; color: #fff; }
.btn.whats:hover:not(:disabled) { background: #1ebe5a; }

/* ========= Preview / página A4 ========= */
.preview {
  padding: 24px;
  display: flex;
  justify-content: center;
}

#contrato {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}

.a4 {
  background: #fff;
  width: 210mm;
  height: 297mm;
  padding: 18mm 20mm;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
  font-family: Arial, sans-serif;
  font-size: 10.5pt;
  line-height: 1.4;
  color: #000;
  overflow: hidden;
  position: relative;
  box-sizing: border-box;
  page-break-after: always;
  break-after: page;
}
.a4:last-child {
  page-break-after: auto;
  break-after: auto;
}

/* Container temporário para renderização do PDF (fora da tela) */
.pdf-render-host {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 210mm;
  background: #fff;
  z-index: -1;
}
.pdf-render-host .a4 {
  box-shadow: none;
  margin: 0;
}

.logo-wrap { text-align: left; margin-bottom: 4mm; }
.logo { width: 22mm; height: 22mm; object-fit: contain; }

.titulo {
  text-align: center;
  font-size: 13pt;
  margin: 0 0 5mm;
  font-weight: 700;
}

.a4 h3 {
  font-size: 11pt;
  margin: 3mm 0 1.5mm;
  font-weight: 700;
}

.a4 p { margin: 0 0 2.5mm; text-align: justify; }

.tab {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 4mm;
  table-layout: fixed;
}
.tab th, .tab td {
  border: 1px solid #c4c7c5;
  padding: 6px 8px;
  text-align: left;
  font-size: 10.5pt;
  vertical-align: middle;
}
.tab th { background: #f3f3f3; font-weight: 700; text-align: center; }
.tab td.center { text-align: center; }

.assinaturas { margin-top: 8mm; }
.assinatura-linha {
  border-bottom: 1px solid #000;
  width: 75mm;
  margin: 10mm auto 1mm;
}
.assinatura-label {
  text-align: center;
  font-weight: 700;
  font-size: 11pt;
  margin: 0;
}

.rodape-img {
  width: 80%;
  max-width: 150mm;
  margin: 8mm auto 0;
  display: block;
}

.var { color: #1f4f2a; font-weight: 600; }
.var.placeholder { color: #b3261e; }

/* ========= Impressão ========= */
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .preview { padding: 0; }
  .a4 {
    box-shadow: none;
    width: 210mm;
    min-height: 297mm;
    padding: 18mm 20mm;
  }
  @page { size: A4; margin: 0; }
}

/* ========= Responsivo ========= */
@media (max-width: 1100px) {
  .form { grid-template-columns: repeat(2, 1fr); }
  .field.col2, .field.col3, .field.col4 { grid-column: span 2; }
  .a4 {
    width: 100%;
    height: auto;
    padding: 14mm;
  }
}
