/* ============================================================
   IDESPA · Gerador de Relatório Físico-Financeiro
   ============================================================ */
:root {
  --green: #2db52a;
  --green-2: #40cc40;
  --green-soft: #e8f7e6;
  --green-line: #bfe6bb;
  --navy: #10295a;
  --navy-2: #1d3b78;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f8f3;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 41, 90, .06), 0 8px 24px rgba(16, 41, 90, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
}
/* folhas decorativas do fundo (assets/fundo) */
body::before, body::after {
  content: "";
  position: fixed;
  z-index: -1;
  pointer-events: none;
  background: url("../assets/fundo/folha-idespa.svg") no-repeat center / contain;
  opacity: .08;
}
body::before { width: 520px; height: 520px; top: -180px; left: -200px; }
body::after  { width: 420px; height: 420px; bottom: -160px; right: -140px; transform: scaleX(-1); }

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { height: 40px; }
.brand strong { display: block; color: var(--navy); font-size: 16px; }
.brand span { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; transition: .15s;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: #249b22; }
.btn.primary:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--navy); }
.btn.ghost:hover { border-color: var(--green); color: var(--green); }
.btn.add { background: var(--green-soft); color: #1d7d1b; border: 1px dashed var(--green); width: 100%; justify-content: center; }
.btn.add:hover { background: #d9f2d6; }
.btn.icon { padding: 6px 10px; background: transparent; color: #b91c1c; border-color: #fecaca; }
.btn.icon:hover { background: #fef2f2; }

/* ---------------- Layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(360px, 520px) 1fr;
  gap: 24px;
  padding: 24px;
  align-items: start;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .topbar { flex-direction: column; align-items: stretch; padding: 12px 16px; }
}

/* ---------------- Formulário ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 16px; font-size: 16px; color: var(--navy);
}
.card h3 { margin: 20px 0 10px; font-size: 13px; color: var(--navy-2); text-transform: uppercase; letter-spacing: .04em; }
.step {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--green); color: #fff; font-size: 13px;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.col-2 { grid-column: span 2; }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr; } .col-2 { grid-column: span 1; } }

label, legend { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="date"], textarea {
  font: inherit; font-size: 14px; color: var(--ink);
  padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fffef2;              /* amarelo suave = campo editável */
  transition: .15s;
  width: 100%;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(45,181,42,.15); background: #fff; }
input.money { text-align: right; font-variant-numeric: tabular-nums; }
input[readonly] { background: #f3f4f6; color: var(--navy); font-weight: 700; }

fieldset.radios { border: 0; padding: 0; margin: 0; display: flex; flex-direction: row; gap: 16px; align-items: center; flex-wrap: wrap; }
fieldset.radios legend { margin-bottom: 6px; width: 100%; }
label.radio { flex-direction: row; align-items: center; gap: 6px; font-size: 14px; color: var(--ink); font-weight: 500; cursor: pointer; }
label.radio input { accent-color: var(--green); width: 16px; height: 16px; }
label.file input { font-size: 12px; font-weight: 400; }

.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.rows { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.row-item {
  border: 1px solid var(--line); border-left: 4px solid var(--green);
  border-radius: 10px; padding: 12px; background: #fcfdfc;
}
.row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.row-head b { color: var(--navy); font-size: 13px; }

/* ---------------- Pré-visualização ---------------- */
.preview { position: sticky; top: 88px; max-height: calc(100vh - 110px); overflow: auto; padding-bottom: 8px; }
@media (max-width: 1100px) { .preview { position: static; max-height: none; } }
.preview-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .06em; }

.paper {
  position: relative;
  width: 210mm; min-height: 297mm;
  margin: 0 auto;
  padding: 12mm 10mm 22mm;
  background: #fff;
  box-shadow: 0 10px 40px rgba(16,41,90,.15);
  border-radius: 4px;
  overflow: hidden;
}
.watermark {
  position: absolute; left: 50%; top: 50%;
  width: 120mm; transform: translate(-50%, -50%);
  opacity: .06; pointer-events: none; z-index: 0;
}
.paper-footer {
  position: absolute; left: 10mm; right: 10mm; bottom: 8mm;
  border-top: 2px solid var(--green);
  padding-top: 6px;
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 9px; color: var(--muted);
}

/* ============================================================
   DOCUMENTO (o que vai para o PDF) — largura útil de A4: 190mm
   ============================================================ */
.doc { position: relative; z-index: 1; width: 190mm; font-size: 10.5px; color: #111827; }

.doc-header {
  display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center;
  padding: 10px 14px;
  border-radius: 10px 10px 0 0;
  background: linear-gradient(120deg, #f2fbf1 0%, #e3f5e1 60%, #d3efcf 100%);
  border: 1px solid var(--green-line);
  border-bottom: 0;
  position: relative; overflow: hidden;
}
.doc-header::after { /* faixa de cor */
  content: ""; position: absolute; right: -40px; top: -40px;
  width: 160px; height: 160px; border-radius: 0 100% 0 100%;
  background: linear-gradient(135deg, var(--green-2), var(--green)); opacity: .18;
}
.doc-header img { height: 58px; display: block; }
.doc-header .inst { line-height: 1.45; color: var(--navy); }
.doc-header .inst strong { font-size: 11.5px; display: block; margin-bottom: 2px; letter-spacing: .01em; }
.doc-header .inst span { font-size: 9px; display: block; }

.doc-title {
  background: var(--navy);
  color: #fff; text-align: center;
  font-weight: 800; font-size: 13px; letter-spacing: .06em;
  padding: 9px 10px;
}
.doc-title small { display: block; font-size: 8.5px; font-weight: 500; letter-spacing: .12em; opacity: .75; margin-top: 2px; }

.doc table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.doc th, .doc td { border: 1px solid #cbd5d1; padding: 6px 8px; vertical-align: middle; }

.info td { height: 44px; }
.info .lbl { font-weight: 700; color: var(--navy); background: #f7faf7; font-size: 10px; text-transform: uppercase; letter-spacing: .03em; }
.info .val { text-align: center; font-weight: 700; color: #111827; }
.info .side { text-align: center; font-weight: 700; font-size: 10px; color: var(--navy); background: #fbfdfb; }
.info .side em { font-style: normal; color: #111827; display: block; margin-top: 2px; }
.check {
  display: inline-grid; place-items: center;
  width: 15px; height: 15px; border: 1.5px solid var(--navy); border-radius: 3px;
  font-size: 10px; line-height: 1; vertical-align: middle; margin: 0 2px;
}
.check.on { background: var(--green); border-color: var(--green); color: #fff; }

.section-title {
  background: var(--green); color: #fff;
  text-align: center; font-weight: 800; letter-spacing: .08em; font-size: 11px;
  padding: 7px !important;
  border-color: var(--green) !important;
}
.doc thead th, .cols th {
  background: #eef7ed; color: var(--navy); font-weight: 700; font-size: 10px; text-align: center;
}
.fisica td { text-align: center; }
.fisica td.meta { text-align: left; }
.fisica td.num { font-weight: 800; color: var(--navy); }
.fisica tr:nth-child(even) td { background: rgba(238, 247, 237, .45); }
.fisica tr.total td { background: #e3f5e1; font-weight: 800; color: #0f3d0e; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  font-size: 9.5px; font-weight: 700; line-height: 1.3;
  background: #e5e7eb; color: #374151;
}
.badge.ok   { background: #dcfce7; color: #166534; }
.badge.up   { background: #dbeafe; color: #1e3a8a; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.bad  { background: #fee2e2; color: #991b1b; }

.fin td { text-align: center; font-variant-numeric: tabular-nums; }
.fin tr.total td { background: #eef2fb; font-weight: 800; color: var(--navy); }

.spacer td { height: 10px; border-left-color: transparent; border-right-color: transparent; padding: 0; }

.local-data td { text-align: right; padding: 10px 12px; font-size: 11px; }
.sig td { text-align: center; vertical-align: bottom; padding: 8px 10px 10px; }
.sig .role { font-size: 9.5px; color: var(--muted); background: #f7faf7; padding: 5px; vertical-align: middle; }
.sig .area { height: 78px; display: flex; align-items: flex-end; justify-content: center; }
.sig .area img { max-height: 60px; max-width: 70%; }
.sig .line { border-top: 1px solid #111827; width: 75%; margin: 0 auto; padding-top: 4px; }
.sig .name { font-weight: 800; font-size: 10.5px; text-transform: uppercase; }
.sig .sub  { font-size: 9.5px; font-weight: 600; color: #374151; }

.avoid-break { page-break-inside: avoid; break-inside: avoid; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* evita borda dupla entre tabelas consecutivas */
.doc table { margin-top: -1px; }

/* botão voltar ao início */
.back {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line); color: var(--navy); background: #fff;
  text-decoration: none; transition: .15s;
}
.back:hover { border-color: var(--green); color: var(--green); }

/* ============================================================
   Anexo I · Relação de documentos (checklist Sim/Não)
   ============================================================ */
.btn.sm { padding: 5px 12px; font-size: 13px; }
.bulk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.bulk .hint { margin: 0; }

.item-check .row-head b { font-weight: 600; line-height: 1.35; }
.item-ctrl { display: flex; gap: 10px; align-items: center; }
.item-ctrl input[type="text"] { flex: 1; min-width: 0; }
@media (max-width: 520px) { .item-ctrl { flex-direction: column; align-items: stretch; } }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.seg-opt { position: relative; flex-direction: row; gap: 0; cursor: pointer; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span { display: block; padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--muted); background: #fff; transition: .15s; }
.seg-opt + .seg-opt span { border-left: 1px solid var(--line); }
.seg-opt input:focus-visible + span { box-shadow: inset 0 0 0 2px var(--green); }
.seg-opt.sim input:checked + span { background: var(--green); color: #fff; }
.seg-opt.nao input:checked + span { background: #dc2626; color: #fff; }
.seg-opt input[value=""]:checked + span { background: #f3f4f6; color: var(--navy); }

.checklist .cols th:first-child { text-align: left; }
.checklist td { font-size: 9.5px; }
.checklist td.esp { font-weight: 600; color: #111827; line-height: 1.35; }
.checklist td.esp .n { color: var(--navy); font-weight: 800; }
.checklist td.esp .detalhe { font-weight: 400; font-size: 7.5px; line-height: 1.35; margin-top: 4px; color: #374151; text-align: justify; }
.checklist td.mark { text-align: center; }
.checklist td.obs { font-size: 9.5px; }
.checklist tr:nth-child(odd) td { background: rgba(238, 247, 237, .45); }
.checklist tr.spacer td, .checklist tr.cols th { background: none; }
.checklist tr.cols th { background: #eef7ed; }

/* ============================================================
   Componentes de formulário compartilhados (listas, conferências)
   ============================================================ */
select {
  font: inherit; font-size: 14px; color: var(--ink);
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: #fffef2; width: 100%;
}
select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(45,181,42,.15); }
.grid.grid-3 { grid-template-columns: repeat(3, 1fr); align-items: end; }
.col-3 { grid-column: span 3; }
@media (max-width: 520px) { .grid.grid-3 { grid-template-columns: 1fr; } .col-3 { grid-column: span 1; } }

.row-actions { display: inline-flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.btn.mini { padding: 4px 9px; font-size: 12px; background: #fff; border-color: var(--line); color: var(--navy); }
.btn.mini:hover:not(:disabled) { border-color: var(--green); color: var(--green); }
.btn.mini:disabled { opacity: .35; cursor: default; }
.btn.mini.danger { color: #b91c1c; border-color: #fecaca; }
.btn.mini.danger:hover { background: #fef2f2; color: #b91c1c; border-color: #fca5a5; }
.btn.add.sm { padding: 6px 12px; font-size: 13px; margin-top: 8px; }
.tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 6px; border-radius: 999px; background: #dbeafe; color: #1e3a8a; margin-left: 6px; }

.calc { margin-top: 10px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.calc b { color: var(--navy); }
.calc .ok, .doc-status .ok { color: #166534; font-weight: 600; }
.calc .warn, .doc-status .warn { color: #b45309; font-weight: 600; }
.doc-status { font-weight: 500; }
.calc.total-geral { padding: 10px 12px; border-radius: 10px; background: var(--green-soft); color: #1f2937; font-size: 13px; }

/* Itens da NF (Relação de Pagamentos) */
details.nf-itens { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
details.nf-itens summary { cursor: pointer; font-size: 12px; font-weight: 700; color: var(--navy-2); text-transform: uppercase; letter-spacing: .04em; }
.nf-item { display: grid; grid-template-columns: 1fr 30px; gap: 6px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.nf-item > input { padding: 7px 9px; font-size: 13px; }
.nf-nums { grid-column: 1 / -1; display: grid; grid-template-columns: .8fr 1.1fr .8fr 1.3fr 1.3fr; gap: 6px; }
.nf-nums label { font-size: 10.5px; gap: 3px; }
.nf-nums input { padding: 6px 7px; font-size: 12.5px; }
.nf-item .btn.mini { justify-content: center; padding: 4px 0; }
@media (max-width: 520px) { .nf-nums { grid-template-columns: 1fr 1fr; } }

/* Grupos recolhíveis (Mapa Comparativo) */
details.grupo-form { border: 1px solid var(--line); border-radius: 10px; background: #fff; }
details.grupo-form > summary {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 12px 14px; cursor: pointer; list-style: none;
  border-left: 4px solid var(--green); border-radius: 10px;
}
details.grupo-form > summary::-webkit-details-marker { display: none; }
details.grupo-form > summary::before { content: "▸"; color: var(--green); font-weight: 800; }
details.grupo-form[open] > summary::before { content: "▾"; }
details.grupo-form[open] > summary { border-bottom-left-radius: 0; border-bottom: 1px solid var(--line); }
.g-titulo { flex: 1; font-weight: 700; font-size: 13px; color: var(--navy); }
.g-resumo { font-size: 12px; color: var(--muted); white-space: nowrap; }
.grupo-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.grupo-body > .row-head { align-items: flex-end; gap: 12px; margin: 0; }
.g-label { flex: 1; }

/* ============================================================
   Papel A4 paisagem (usar com baixarPdf(..., { orientacao: "landscape" }))
   ============================================================ */
.paper.landscape { width: 297mm; min-height: 210mm; }
.paper.landscape .doc { width: 277mm; }

/* ============================================================
   Tabelas dos documentos financeiros
   ============================================================ */
.doc td.l { text-align: left; }
.doc td.r { text-align: right; }
.doc td.c { text-align: center; }
/* "R$" à esquerda e valor à direita, como na formatação contábil do Excel */
.doc td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc td.num .rs { float: left; color: #4b5563; }
.legenda td { font-size: 9px; color: #374151; padding: 4px 8px; background: #fbfdfb; }

/* Relação de Pagamentos */
.pagamentos td, .pagamentos th { font-size: 8.5px; text-align: center; vertical-align: middle; }
.pagamentos .cols th { font-size: 8.5px; }
.pagamentos td.desc { text-align: left; font-size: 7.5px; line-height: 1.35; vertical-align: top; }
.pagamentos td.valor { text-align: right; font-weight: 700; white-space: nowrap; }
.pagamentos tr.total td { background: #e3f5e1; font-weight: 800; color: #0f3d0e; font-size: 9.5px; }
.doc table.nf-mini { margin: 5px 0 0; }
.nf-mini th, .nf-mini td { font-size: 7px !important; padding: 2px 4px !important; border-color: #dde5e1 !important; text-align: center; }
.nf-mini th { background: #f3f8f2; color: var(--navy); font-weight: 700; }
.nf-mini td.l { text-align: left; }
.nf-mini td.r { text-align: right; white-space: nowrap; }
.nf-mini tr.t td { font-weight: 800; background: #f3f8f2; }

/* Conciliação Bancária */
.conc td, .conc th { font-size: 9.5px; text-align: center; }
.conc tr.banco td { font-weight: 700; color: var(--navy); }
.conc tr.total td { background: #eef2fb; font-weight: 800; color: var(--navy); }
.conc tr.spacer td { height: 8px; }

/* Balancete Financeiro */
.balancete td, .balancete th { font-size: 9.5px; text-align: center; }
.balancete tr.sub td { background: #fbfdfb; font-size: 9.5px; color: #374151; }
.balancete tr.total td { background: #e3f5e1; font-weight: 800; color: #0f3d0e; }

/* Mapa Comparativo */
.mapa th, .mapa td { font-size: 7.2px; padding: 3px 4px; text-align: center; }
.mapa .cols th { font-size: 7.2px; }
.mapa th.forn { font-size: 8px; letter-spacing: .04em; }
.mapa td.desc { text-align: left; line-height: 1.3; }
.mapa tr.grupo td { background: #cfeccb; color: #0f3d0e; font-weight: 800; text-align: left; font-size: 8px; padding: 4px 6px; }
.mapa td.min { font-weight: 800; color: #166534; background: #ecfdf0; }
.mapa .media { background: #f3f6fb; }
.mapa tr.total td { background: #e3f5e1; font-weight: 800; color: #0f3d0e; font-size: 7.6px; }
.mapa tr.total td.media { background: #dfe7f5; color: var(--navy); }
