/* =========================================================================
   Report Editor — A4 print-first WYSIWYG
   Template travado + regiões editáveis. Preview muito próximo do PDF final.
   ========================================================================= */

.re-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: #2a2e35;
  display: none; flex-direction: column;
  color: #1f2328;
}
.re-overlay.re-open { display: flex; }

.re-toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: #1f232a; color: #fff;
  border-bottom: 1px solid #000;
  flex-wrap: wrap;
}
.re-toolbar h2 { font-size: 15px; margin: 0 8px 0 0; font-weight: 600; letter-spacing: .3px; }
.re-toolbar .re-spacer { flex: 1; }
.re-toolbar button {
  background: #2d6cdf; color: #fff; border: 0; padding: 7px 14px;
  border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.re-toolbar button:hover { background: #3a7bef; }
.re-toolbar button.re-secondary { background: #3a4049; }
.re-toolbar button.re-secondary:hover { background: #4a5059; }
.re-toolbar button.re-danger { background: #c7344c; }
.re-toolbar .re-zoom { display: flex; align-items: center; gap: 4px; }
.re-toolbar .re-zoom select {
  background: #2a2e35; color: #fff; border: 1px solid #3a4049;
  border-radius: 4px; padding: 5px 8px; font-size: 12px;
}
.re-toolbar .re-status {
  font-size: 12px; color: #9aa4b2; padding: 0 8px;
}
.re-toolbar .re-status.re-dirty { color: #f0b42b; }
.re-toolbar .re-status.re-saved { color: #58d68d; }

.re-main {
  flex: 1; display: flex; overflow: hidden;
}

.re-canvas-wrap {
  flex: 1; overflow: auto;
  background: #2a2e35;
  padding: 28px 20px 120px;
  scroll-behavior: smooth;
}
.re-canvas {
  margin: 0 auto;
  transform-origin: top center;
  transition: transform .15s ease;
}

.re-sidebar {
  width: 320px; background: #f4f6f9; border-left: 1px solid #d7dce4;
  overflow-y: auto; padding: 16px;
  color: #1f2328; font-size: 13px;
}
.re-sidebar h3 { margin: 0 0 12px; font-size: 14px; color: #2d6cdf; }
.re-sidebar .re-sb-empty { color: #7d8794; font-style: italic; font-size: 12px; }
.re-sidebar .re-sb-row { margin-bottom: 10px; }
.re-sidebar .re-sb-row label {
  display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: #7d8794; margin-bottom: 3px;
}
.re-sidebar .re-sb-row .re-sb-value {
  background: #fff; padding: 6px 10px; border-radius: 4px; border: 1px solid #d7dce4;
  font-size: 13px; word-break: break-word;
}
.re-sidebar .re-sb-section {
  margin-top: 16px; padding-top: 12px; border-top: 1px solid #d7dce4;
}

/* -------------------------------------------------------------------------
   A4 page — institutional frame
   ------------------------------------------------------------------------- */
.re-page {
  width: 210mm; min-height: 297mm;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
  margin-bottom: 20px;
  padding: 25mm 18mm 22mm 18mm;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 10.5pt; line-height: 1.45; color: #1a1f2e;
  position: relative;
  overflow: hidden;
  page-break-after: always;
}
.re-page.re-cover {
  padding: 0;
}

/* Page header band */
.re-page-header {
  position: absolute; top: 8mm; left: 18mm; right: 18mm;
  height: 14mm;
  border-bottom: 1.2px solid #2d6cdf;
  display: flex; align-items: flex-start; gap: 10px;
  user-select: none; pointer-events: none;
}
.re-page-header .re-hdr-logo {
  width: 22mm; height: 11mm;
  background: #2d6cdf; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 8pt; font-weight: 700; letter-spacing: .5px;
  border-radius: 2px;
}
.re-page-header .re-hdr-title {
  flex: 1; font-size: 11pt; font-weight: 700; color: #1a1f2e;
  line-height: 1.1;
}
.re-page-header .re-hdr-meta {
  font-size: 7.5pt; color: #7d8794; margin-top: 2px;
}
.re-page-header .re-hdr-page {
  text-align: right; font-size: 8pt; color: #2d6cdf; font-weight: 600;
}

/* Page footer band */
.re-page-footer {
  position: absolute; bottom: 8mm; left: 18mm; right: 18mm;
  height: 8mm;
  border-top: 1px solid #d7dce4;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 7pt; color: #7d8794;
  user-select: none; pointer-events: none;
}

.re-cover .re-page-header, .re-cover .re-page-footer { display: none; }

/* -------------------------------------------------------------------------
   Cover
   ------------------------------------------------------------------------- */
.re-cover-inner {
  display: flex; flex-direction: column; height: 100%;
}
.re-cover-band-top {
  height: 40mm; background: linear-gradient(135deg, #2d6cdf 0%, #5a4dff 100%);
  display: flex; align-items: center; padding: 0 22mm; color: #fff;
}
.re-cover-band-top .re-cover-brand {
  font-size: 22pt; font-weight: 700; letter-spacing: 1px;
}
.re-cover-body {
  flex: 1; padding: 20mm 22mm; display: flex; flex-direction: column; gap: 14mm;
}
.re-cover-title { font-size: 26pt; font-weight: 700; color: #1a1f2e; line-height: 1.15; }
.re-cover-subtitle { font-size: 14pt; color: #5a6270; margin-top: 6mm; }
.re-cover-tags { display: flex; gap: 10px; margin-top: 8mm; }
.re-cover-tag {
  padding: 6px 14px; background: #e8eef8; color: #2d6cdf; border-radius: 20px;
  font-size: 10pt; font-weight: 600;
}
.re-cover-meta-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 28px; margin-top: auto;
}
.re-cover-meta-grid .re-cover-meta-item {
  border-left: 3px solid #2d6cdf; padding: 2px 0 2px 12px;
}
.re-cover-meta-grid .re-cover-meta-label { font-size: 8pt; color: #7d8794; text-transform: uppercase; letter-spacing: .7px; }
.re-cover-meta-grid .re-cover-meta-value { font-size: 12pt; color: #1a1f2e; font-weight: 600; margin-top: 2px; }
.re-cover-footer-band {
  height: 22mm; background: #1a1f2e; color: #fff;
  display: flex; align-items: center; padding: 0 22mm; justify-content: space-between;
}
.re-cover-footer-band .re-cov-org { font-weight: 700; font-size: 12pt; }
.re-cover-footer-band .re-cov-date { font-size: 10pt; color: #9aa4b2; }

/* -------------------------------------------------------------------------
   Sections and fields
   ------------------------------------------------------------------------- */
.re-section { margin-bottom: 6mm; }
.re-section-title {
  font-size: 13pt; font-weight: 700; color: #2d6cdf;
  border-left: 3px solid #2d6cdf; padding: 2mm 3mm;
  margin: 0 0 3mm; line-height: 1.1;
}
.re-section-subtitle {
  font-size: 11pt; font-weight: 600; color: #2d6cdf; margin: 3mm 0 2mm;
}

/* Editable field visual cues */
.re-field[data-editable="true"] {
  outline: 1px dashed transparent;
  outline-offset: 2px;
  border-radius: 2px;
  transition: outline-color .12s, background-color .12s;
  cursor: text;
}
.re-field[data-editable="true"]:hover { outline-color: #a8bce6; background: #f4f8ff; }
.re-field[data-editable="true"]:focus { outline: 2px solid #2d6cdf; background: #f4f8ff; }
.re-field[data-editable="false"] { background: transparent; color: inherit; }
.re-field.re-locked { background: #fef6d5; border-left: 2px solid #f0b42b; padding-left: 4px; }

/* Metadata table */
.re-meta-table { width: 100%; border-collapse: collapse; border: 1px solid #d7dce4; }
.re-meta-table tr + tr { border-top: 1px solid #d7dce4; }
.re-meta-table th, .re-meta-table td { padding: 4px 8px; font-size: 10pt; text-align: left; vertical-align: top; }
.re-meta-table th { background: #f0f4fa; color: #2d6cdf; width: 38%; font-weight: 600; }
.re-meta-table td .re-field { min-height: 1.2em; display: block; }

/* Data tables */
.re-data-table { width: 100%; border-collapse: collapse; border: 1px solid #2d6cdf; margin-top: 2mm; }
.re-data-table thead th {
  background: #2d6cdf; color: #fff; font-size: 9pt; font-weight: 600;
  padding: 5px 6px; text-align: left; border-right: 1px solid #5a85e4;
}
.re-data-table thead th:last-child { border-right: 0; }
.re-data-table tbody td {
  font-size: 9pt; padding: 4px 6px; border-bottom: 1px solid #d7dce4;
  vertical-align: top; border-right: 1px solid #eef1f6;
}
.re-data-table tbody td:last-child { border-right: 0; }
.re-data-table tbody tr:nth-child(even) { background: #f7f9fc; }
.re-data-table tbody tr:hover { background: #e8eef8; }

/* Row action (remove) */
.re-row-actions { position: relative; }
.re-row-remove {
  border: 0; background: #c7344c; color: #fff; border-radius: 50%;
  width: 18px; height: 18px; cursor: pointer; font-size: 11px;
  line-height: 18px; padding: 0;
}
.re-row-remove:hover { background: #d94560; }

.re-table-add-row {
  margin-top: 4px; border: 1px dashed #a8bce6; background: #f4f8ff; color: #2d6cdf;
  padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 9pt; font-weight: 600;
}
.re-table-add-row:hover { background: #e8eef8; border-color: #2d6cdf; }

/* KPI cards */
.re-kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 2mm 0; }
.re-kpi-card {
  background: #f0f4fa; border-left: 3px solid #2d6cdf; padding: 6px 10px; border-radius: 2px;
}
.re-kpi-card .re-kpi-label { font-size: 8pt; color: #7d8794; text-transform: uppercase; letter-spacing: .4px; }
.re-kpi-card .re-kpi-value { font-size: 16pt; font-weight: 700; color: #1a1f2e; line-height: 1.1; margin-top: 2px; }

/* Photo grid */
.re-photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5mm; margin-top: 2mm; }
.re-photo-tile {
  border: 1px solid #d7dce4; background: #fff; border-radius: 2px; overflow: hidden;
  display: flex; flex-direction: column;
}
.re-photo-tile .re-photo-img {
  width: 100%; aspect-ratio: 3/2; object-fit: cover; background: #f0f4fa; display: block;
}
.re-photo-tile .re-photo-caption {
  padding: 4px 8px; background: #f0f4fa;
}
.re-photo-tile .re-photo-caption .re-photo-num {
  font-size: 8pt; font-weight: 700; color: #2d6cdf; display: block;
}
.re-photo-tile .re-photo-caption .re-field {
  font-size: 9pt; color: #1a1f2e; margin-top: 2px; display: block; min-height: 1.1em;
}
.re-photo-tile .re-photo-remove {
  position: absolute; top: 4px; right: 4px;
}

/* Signatures */
.re-sig-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10mm; margin: 8mm 0 0; }
.re-sig-slot {
  border-top: 1.5px solid #1a1f2e; padding-top: 3mm;
}
.re-sig-slot .re-sig-role { font-size: 9pt; font-weight: 700; color: #2d6cdf; text-transform: uppercase; letter-spacing: .5px; }
.re-sig-slot .re-sig-name { font-size: 11pt; font-weight: 600; margin-top: 6mm; }
.re-sig-slot .re-sig-title { font-size: 9pt; color: #5a6270; margin-top: 1mm; }

/* Narrative / richtext block */
.re-narrative {
  font-size: 10.5pt; line-height: 1.55; text-align: justify; color: #1a1f2e;
  white-space: pre-wrap; min-height: 1.5em;
}

/* Locked region hint */
.re-locked-region {
  position: relative;
}
.re-locked-region::after {
  content: "🔒 trecho travado pelo template";
  position: absolute; top: 2px; right: 4px; font-size: 7pt; color: #c7344c;
  opacity: 0; transition: opacity .15s;
}
.re-locked-region:hover::after { opacity: .7; }

/* Page-break hint */
.re-page-break-marker {
  margin: 12px auto; height: 1px; background: #3a4049;
  position: relative; width: 200mm;
}
.re-page-break-marker::before {
  content: "— quebra de página —";
  position: absolute; left: 50%; top: -8px; transform: translateX(-50%);
  background: #2a2e35; color: #9aa4b2; padding: 0 8px; font-size: 10px;
}

/* Drafts list inline on Relatórios tab */
.re-drafts-list {
  display: flex; flex-direction: column; gap: 6px; margin-top: 10px;
}
.re-drafts-list .re-draft-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface, #f0f4fa); padding: 8px 12px; border-radius: 6px; font-size: 13px;
}
.re-drafts-list .re-draft-item .re-draft-meta { color: #7d8794; font-size: 11px; }
.re-drafts-list .re-draft-item button { margin-left: 6px; }
