:root {
  --bg: #f5f6f8; --card: #fff; --txt: #1d2330; --muted: #677085; --line: #e2e5eb;
  --pri: #1f5eb8; --pri-2: #e8f0fb; --ok: #1d7a46; --ok-2: #e5f4ec; --warn: #9a6200; --warn-2: #fdf3dd;
  --bad: #b3261e; --bad-2: #fbe9e7; --almeida: #1f5eb8; --martins: #7a3fb0;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--txt); }
header { background: #16223a; color: #fff; padding: 10px 18px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
header h1 { font-size: 16px; margin: 0 12px 0 0; font-weight: 600; }
header label { font-size: 12px; opacity: .85; display: flex; gap: 6px; align-items: center; }
header input, header select { background: #24324f; color: #fff; border: 1px solid #3a4a6b; border-radius: 6px; padding: 4px 8px; }
nav { display: flex; gap: 2px; flex-wrap: wrap; background: #fff; border-bottom: 1px solid var(--line); padding: 0 12px; position: sticky; top: 48px; z-index: 9; }
nav button { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font: inherit; }
nav button.ativo { color: var(--pri); border-bottom-color: var(--pri); font-weight: 600; }
nav .badge { margin-left: 4px; }
main { padding: 16px 18px 60px; max-width: 1600px; margin: 0 auto; }
h2 { font-size: 18px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.kpi b { display: block; font-size: 18px; }
.kpi span { font-size: 12px; color: var(--muted); }
.barra { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.barra .esp { flex: 1; }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 11px; cursor: pointer; color: var(--txt); }
button:hover { border-color: var(--pri); }
button.pri { background: var(--pri); color: #fff; border-color: var(--pri); }
button.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
button.perigo { color: var(--bad); }
button.grande { font-size: 16px; padding: 10px 20px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px; background: #fff; color: var(--txt); }
textarea { width: 100%; min-height: 80px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 5px 7px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f0f2f6; position: sticky; top: 0; font-weight: 600; font-size: 12px; white-space: nowrap; cursor: pointer; }
td.n, th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr:hover td { background: #fafbfd; }
.tabela { max-height: 70vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; background: var(--pri-2); color: var(--pri); white-space: nowrap; }
.b-ok { background: var(--ok-2); color: var(--ok); } .b-warn { background: var(--warn-2); color: var(--warn); } .b-bad { background: var(--bad-2); color: var(--bad); }
.b-cinza { background: #eceef2; color: var(--muted); }
.cart-almeida { border-left: 4px solid var(--almeida); } .cart-martins { border-left: 4px solid var(--martins); }
.tag-almeida { background: #e8f0fb; color: var(--almeida); } .tag-martins { background: #f2eafa; color: var(--martins); }
.muted { color: var(--muted); font-size: 12px; }
.aviso { background: var(--warn-2); border: 1px solid #f0d9a4; border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.erro { background: var(--bad-2); border: 1px solid #f2c4bf; border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.alerta-gigante { background: #b3261e; color: #fff; border-radius: 12px; padding: 18px 22px; margin: 6px 0 16px; box-shadow: 0 6px 24px rgba(179, 38, 30, .35); }
.alerta-gigante .ag-titulo { font-size: 26px; font-weight: 800; letter-spacing: .02em; line-height: 1.2; }
.alerta-gigante .ag-sub { font-size: 14px; opacity: .95; margin-top: 6px; }
.alerta-gigante ul { margin: 10px 0 4px; padding-left: 20px; font-size: 15px; }
.alerta-gigante li { margin: 4px 0; }
.alerta-gigante button { margin-top: 10px; background: #fff; color: #b3261e; border: none; font-weight: 700; }
tr.dia-ruim td { background: #fbe9e7; }
.okbox { background: var(--ok-2); border: 1px solid #bfe3cd; border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.motivos { font-size: 11px; color: var(--muted); margin-top: 2px; }
.drop { border: 2px dashed #b7c3d8; border-radius: 10px; padding: 24px; text-align: center; background: #fbfcfe; cursor: pointer; }
.drop.over { background: var(--pri-2); border-color: var(--pri); }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; }
.form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.form label.largo { grid-column: 1 / -1; }
.form input, .form select, .form textarea { color: var(--txt); font-size: 14px; }
#modal { position: fixed; inset: 0; background: rgba(15, 20, 35, .45); display: none; align-items: flex-start; justify-content: center; z-index: 50; overflow: auto; padding: 40px 12px; }
#modal.aberto { display: flex; }
#modal .caixa { background: #fff; border-radius: 12px; padding: 18px 20px; width: min(920px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
#modal .acoes { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
#toast { position: fixed; bottom: 18px; right: 18px; z-index: 60; display: flex; flex-direction: column; gap: 6px; }
#toast div { background: #16223a; color: #fff; padding: 9px 14px; border-radius: 8px; max-width: 460px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast div.e { background: var(--bad); }
.linha-editor select, .linha-editor input { font-size: 12px; padding: 2px 4px; max-width: 170px; }
details summary { cursor: pointer; color: var(--pri); }
#impressao { display: none; }

/* ---------- impressão / PDF ---------- */
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  body { background: #fff; font-size: 11px; }
  header, nav, main, #modal, #toast { display: none !important; }
  #impressao { display: block; }
}
.pdf h1 { font-size: 18px; margin: 0; }
.pdf .cab { display: flex; justify-content: space-between; border-bottom: 2px solid #16223a; padding-bottom: 6px; margin-bottom: 10px; }
/* sem break-inside:avoid na seção inteira: bloco maior que a página empurrava tudo para a pág. 2 e deixava a 1 em branco */
.pdf .secao { border: 1px solid #ccd2dc; border-radius: 6px; padding: 8px 10px; margin: 10px 0; }
.pdf .secao h2, .pdf tr { break-inside: avoid; }
.pdf .secao h2 { font-size: 14px; margin: 0 0 6px; }
.pdf table { font-size: 10.5px; }
.pdf th { background: #eef1f5; position: static; }
.pdf .resumo td { font-size: 12px; }
.pdf .resumo tr.total td { font-weight: 700; border-top: 2px solid #16223a; font-size: 13px; }
.pdf .rodape { margin-top: 12px; font-size: 10px; color: #555; }
.pdf ul { margin: 4px 0; padding-left: 18px; }
