:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --primary-dark: #1d4ed8;
  --primary-border: #93c5fd;
  --fechamento: #2563eb;
  --fechamento-soft: #eff6ff;
  --fechamento-border: #93c5fd;
  --faturas: #1d4ed8;
  --faturas-soft: #eff6ff;
  --faturas-border: #93c5fd;
  --bancos: #3b82f6;
  --bancos-soft: #f0f9ff;
  --bancos-border: #7dd3fc;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --row-alt: #f8fafc;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 1.8rem; }
.title { font-weight: 700; font-size: 1.15rem; color: #1e3a8a; }
.subtitle { font-size: 0.8rem; color: var(--muted); margin-top: -2px; }

.tabs { display: flex; gap: 8px; }
.nav-btn {
  background: #f9fafb;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
  min-width: 118px;
  transition: all .15s ease;
}
.nav-btn small { font-size: 0.7rem; opacity: 0.85; font-weight: 500; }
.nav-btn.tab-fechamento.active,
.nav-btn.tab-faturas.active,
.nav-btn.tab-bancos.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

main { padding: 20px; max-width: 1200px; margin: 0 auto; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.accent-fechamento .section-header h2,
.accent-faturas .section-header h2,
.accent-bancos .section-header h2 { color: #1e3a8a; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--primary-border);
}
.section-header h2 { font-size: 1.5rem; font-weight: 700; }
.section-desc { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: white; border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover { background: #f9fafb; border-color: #cbd5e1; }
.btn.small { padding: 6px 12px; font-size: 0.82rem; }
.btn.active-view {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-dark);
}
.btn.add-sangria {
  background: white;
  border: 1px dashed var(--primary-border);
  color: var(--primary-dark);
  width: 100%;
  margin: 8px 0 4px;
}
.btn.add-sangria:hover {
  background: var(--primary-soft);
  border-style: solid;
  border-color: var(--primary);
}

.select, .input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  background: white;
  width: 100%;
}
.select:focus, .input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.select.compact { width: auto; min-width: 140px; }
.input.compact { width: auto; min-width: 180px; }

.dia-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
}
.dia-header {
  background: linear-gradient(90deg, #eff6ff, #fff);
  padding: 16px 20px;
  font-weight: 700;
  font-size: 1.05rem;
  color: #1e3a8a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #dbeafe;
}

.caixa-table-wrap { overflow-x: auto; }
.caixa-lista {
  width: 100%;
  border-collapse: collapse;
  background: white;
  box-shadow: none;
  border-radius: 0;
}
.caixa-lista th, .caixa-lista td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.92rem;
}
.caixa-lista th {
  background: #f8fafc;
  font-weight: 700;
  font-size: 0.78rem;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #e2e8f0;
}
.caixa-lista tbody tr:nth-child(even) { background: var(--row-alt); }
.caixa-lista tbody tr:nth-child(odd) { background: #fff; }
.caixa-lista tbody tr { transition: background .15s; }
.caixa-lista tbody tr:hover { background: #eff6ff !important; }
.caixa-lista tbody tr.selected {
  background: #dbeafe !important;
  box-shadow: inset 3px 0 0 var(--primary);
}
.caixa-lista .ops { font-weight: 700; }
.caixa-lista .term { color: #374151; }
.caixa-lista .times { font-variant-numeric: tabular-nums; color: #4b5563; font-weight: 600; }

.badge-status {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid transparent;
}
.badge-status.fechado {
  background: #f1f5f9;
  color: #334155;
  border-color: #cbd5e1;
}
.badge-status.aberto {
  background: var(--ok-bg);
  color: #065f46;
  border-color: #6ee7b7;
}
.badge-status.conferir {
  background: var(--warn-bg);
  color: #92400e;
  border-color: #fcd34d;
}

.caixa-detail {
  border-top: 2px solid var(--primary);
  background: #fff;
  display: none;
}
.caixa-detail.open { display: block; }
.caixa-detail-header {
  padding: 14px 20px;
  background: var(--primary-soft);
  font-weight: 700;
  color: #1e3a8a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid #dbeafe;
}
.caixa-detail-header .meta {
  font-weight: 500;
  font-size: 0.85rem;
  color: #64748b;
}

.caixa-block { border-bottom: 1px solid #f3f4f6; }
.linha {
  display: grid;
  grid-template-columns: 1.8fr 140px 130px 1.6fr;
  gap: 10px;
  padding: 10px 20px;
  align-items: center;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9rem;
}
.linha:nth-child(even) { background: var(--row-alt); }
.linha:hover { background: #eff6ff; }
.linha.linha-sangria {
  background: #f8fafc;
  border-left: 3px solid #94a3b8;
}
.linha.linha-sangria:nth-child(even) { background: #f1f5f9; }
.linha.linha-total {
  background: #f0fdf4;
  border-left: 3px solid #34d399;
  font-weight: 600;
}
.linha.linha-div {
  background: #fef2f2;
  border-left: 3px solid #f87171;
  font-weight: 600;
}
.linha.linha-pix-cnpj {
  background: #eff6ff;
  border-left: 3px solid #60a5fa;
}
.linha.linha-pix-cnpj label { font-weight: 500; font-size: 0.92em; }
.linha label { font-weight: 600; }
.linha .valor-input { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.sangria-actions {
  padding: 4px 20px 8px;
  background: #f8fafc;
  border-bottom: 1px dashed #cbd5e1;
}

.status-OK, .status-SIM, .status-FECHOU {
  background: var(--ok-bg) !important;
  color: #065f46 !important;
  border-color: #6ee7b7 !important;
  font-weight: 700;
}
.status-Conferir {
  background: var(--warn-bg) !important;
  color: #92400e !important;
  border-color: #fcd34d !important;
  font-weight: 700;
}
.status-NÃO {
  background: var(--danger-bg) !important;
  color: #991b1b !important;
  border-color: #fca5a5 !important;
  font-weight: 700;
}
.status-select {
  border-radius: 999px;
  padding: 4px 8px;
  font-weight: 700;
  font-size: 0.8rem;
  text-align: center;
  border: 1px solid #e5e7eb;
}

.clientes-panel {
  background: #f8fafc;
  padding: 14px 20px;
  display: flex;
  gap: 28px;
  font-size: 0.9rem;
  border-top: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
}
.clientes-panel span {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
}
.clientes-panel strong { color: var(--primary-dark); font-size: 1.15rem; }
.clientes-panel .clientes-input {
  width: 88px;
  margin-top: 4px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary-dark);
  text-align: center;
  padding: 6px 8px;
}
.clientes-panel .clientes-total {
  background: #eff6ff;
}

.caixa-actions {
  padding: 10px 20px 14px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

.bank-card {
  background: white;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.bank-bb, .bank-itau { border-left: 4px solid var(--primary); }
.bank-icon { font-size: 1.8rem; }
.badge, .badge-itau {
  display: inline-block;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 4px;
  border: 1px solid var(--primary-border);
}
.banks-grid { display: grid; gap: 12px; }

.note { color: var(--muted); font-size: 0.85rem; margin-top: 12px; }

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
}
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th {
  background: #f8fafc;
  font-weight: 700;
  font-size: 0.8rem;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
#faturasContainer table tbody tr:nth-child(even) { background: var(--row-alt); }
#faturasContainer table tbody tr:hover { background: #eff6ff; }

.fatura-actions { display: flex; gap: 6px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal.hidden { display: none; }
.modal-content {
  background: white;
  border-radius: 16px;
  padding: 24px;
  width: min(480px, 92vw);
  position: relative;
  border-top: 3px solid var(--primary);
}
.close { position: absolute; right: 16px; top: 12px; background: none; border: none; font-size: 1.6rem; cursor: pointer; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e3a8a;
  color: white;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: all .25s ease;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(30, 58, 138, .25);
}
.toast.show { opacity: 1; transform: translateY(0); }

.empty-day {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 800px) {
  .linha { grid-template-columns: 1.4fr 110px 110px; }
  .linha .obs-input { display: block; grid-column: 1 / -1; width: 100%; box-sizing: border-box; }
  header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .tabs { width: 100%; overflow-x: auto; }
  .caixa-lista th:nth-child(4),
  .caixa-lista td:nth-child(4),
  .caixa-lista th:nth-child(5),
  .caixa-lista td:nth-child(5) { display: none; }
}


.filtros-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin: -8px 0 18px;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.filtro-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.filtro-item .select { min-width: 180px; text-transform: none; font-weight: 500; color: var(--text); }


/* Obs larger */
.linha {
  grid-template-columns: 1.5fr 120px 120px 1.8fr;
  align-items: start;
}
.linha .obs-input {
  min-height: 52px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.35;
  padding: 8px 10px;
}

.bot-comment-wrap {
  padding: 8px 20px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  border-left: 3px solid #64748b;
}
.btn-bot-comment {
  margin-bottom: 8px;
  border-color: #94a3b8;
  color: #334155;
}
.bot-comment-box.hidden { display: none; }
.bot-comment-box.open { display: block; }
.bot-comment-box label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}
.bot-comment-text {
  min-height: 88px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.4;
}

/* Faturas tint */
table.faturas-pendentes,
#faturasContainer table.faturas-pendentes {
  background: #fef2f2;
  border-left-color: #f87171;
}
table.faturas-pendentes th {
  background: #fee2e2;
  color: #991b1b;
}
table.faturas-pendentes tbody tr:nth-child(even) { background: #fff1f2; }
table.faturas-pendentes tbody tr:hover { background: #fecaca; }

table.faturas-recebidas,
#faturasContainer table.faturas-recebidas {
  background: #f0fdf4;
  border-left-color: #4ade80;
}
table.faturas-recebidas th {
  background: #dcfce7;
  color: #166534;
}
table.faturas-recebidas tbody tr:nth-child(even) { background: #ecfdf5; }
table.faturas-recebidas tbody tr:hover { background: #bbf7d0; }


.modal-content.modal-caixa {
  width: min(960px, 96vw);
  max-height: 90vh;
  overflow: auto;
  padding: 0 0 12px;
  border-top: 3px solid var(--primary);
}
.modal-detail-header {
  position: sticky;
  top: 0;
  z-index: 2;
  border-radius: 16px 16px 0 0;
}
.modal-caixa-block {
  padding-bottom: 8px;
}
.modal .close {
  z-index: 3;
  color: #1e3a8a;
  background: white;
  border-radius: 999px;
  width: 36px;
  height: 36px;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}

/* ===== Extratos Bancários ===== */
.accent-extratos .section-header h2 { color: #1e3a8a; }
.ext-resumo { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 14px 0; }
.ext-card { background: #fff; border: 1px solid var(--primary-border); border-left: 4px solid var(--primary); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.ext-card small { color: var(--muted); font-size: .75rem; }
.ext-card b { font-size: 1.05rem; }
.pos { color: #15803d; } .neg { color: #b91c1c; } .muted { color: var(--muted); }
.ext-caixinhas { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-bottom: 18px; }
.caixinha { background: #fff; border: 1px solid #dbeafe; border-radius: 12px; padding: 12px; cursor: pointer; box-shadow: 0 1px 3px rgba(30,58,138,.08); transition: .15s; }
.caixinha:hover { border-color: var(--primary); }
.caixinha.sel { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.cx-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.cx-head h4 { color: #1e3a8a; font-size: .95rem; }
.cx-n { background: var(--primary-soft); color: var(--primary-dark); border-radius: 999px; padding: 1px 8px; font-size: .75rem; font-weight: 600; }
.cx-line { display: flex; justify-content: space-between; font-size: .85rem; }
.cx-subs { list-style: none; margin: 6px 0 0; padding: 6px 0 0; border-top: 1px dashed #dbeafe; font-size: .78rem; }
.cx-subs li { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
.cx-subs li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ext-table-wrap { overflow-x: auto; background: #fff; border-radius: 10px; border: 1px solid #dbeafe; }
.ext-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.ext-table th { background: var(--primary-soft); color: var(--primary-dark); text-align: left; padding: 8px; position: sticky; top: 0; }
.ext-table td { padding: 6px 8px; border-top: 1px solid #eef2ff; vertical-align: top; }
.ext-table .num { text-align: right; white-space: nowrap; font-weight: 600; }
.ext-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; color: #fff; width: fit-content; }
.bk-bb { background: #eab308; color: #1e3a8a; } .bk-itau { background: #ec7000; }
.bk-ourocard { background: #1e3a8a; } .bk-itaucartao { background: #9a3412; }
#extMais { margin: 12px auto; display: block; }

/* --- cloud sync + PIN --- */
.sync-chip{margin-left:12px;font-size:12px;padding:3px 9px;border-radius:12px;background:#e8f0fe;color:#1F4E79;cursor:pointer;white-space:nowrap}
.sync-chip[data-state=ok]{background:#e6f4ea;color:#1e7e34}
.sync-chip[data-state=busy]{background:#fff4e5;color:#8a5a00}
.sync-chip[data-state=err]{background:#fde8e8;color:#b00020}
.sync-chip[data-state=off],.sync-chip[data-state=local]{background:#eee;color:#555}
#pinGate{position:fixed;inset:0;background:#1F4E79;z-index:10000;display:flex;align-items:center;justify-content:center}
#pinGate form{background:#fff;padding:28px;border-radius:14px;width:min(320px,88vw);text-align:center;display:flex;flex-direction:column;gap:10px}
#pinGate input{font-size:18px;padding:10px;border:1px solid #ccc;border-radius:8px;text-align:center}
#pinGate .pin-logo{font-size:44px}#pinGate .pin-err{color:#b00020;min-height:1em;margin:0}

/* Extratos: filtro direção + tipo */
.ext-tipo-bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:10px 0 14px}
.ext-tipo-group{display:flex;flex-wrap:wrap;align-items:center;gap:6px;padding:4px 8px;border:1px solid rgba(127,127,127,.3);border-radius:999px}
.ext-tipo-label{font-size:.75rem;font-weight:600;opacity:.7;margin-right:2px}
.ext-chip{border-radius:999px}
.ext-chip small{opacity:.65;margin-left:3px}
.ext-chip.active{background:#333;color:#fff;border-color:#333}
.ext-chip.chip-ent.active{background:#1e8e3e;border-color:#1e8e3e}
.ext-chip.chip-sai.active{background:#c5221f;border-color:#c5221f}
.obs-input{white-space:pre-wrap}
@media (max-width: 800px) {
  .linha { grid-template-columns: 1.4fr 110px 110px !important; }
  .linha .obs-input { display: block !important; grid-column: 1 / -1; width: 100%; min-height: 40px; box-sizing: border-box; }
}
.div-obs-row td{padding:6px 12px 12px;border-top:0}
.div-obs{background:#f0fdf4;border-left:3px solid #34d399;border-radius:6px;padding:8px 10px;font-size:.88rem;line-height:1.4}
.div-nao .div-obs{background:#fef2f2;border-left-color:#f87171}
.div-obs-head{display:block;font-weight:600;margin-bottom:3px}
.div-obs-text{white-space:pre-wrap;word-break:break-word}
@media (max-width: 800px){.div-obs-row td{display:table-cell !important}}
.div-obs{position:sticky;left:8px;max-width:calc(100vw - 64px);box-sizing:border-box}
/* Pagamentos de caixa, separados das faturas */
.tab-pagamentos { border-bottom: 3px solid var(--fechamento, #b87935); }
.pagamento-card, .pagamento-form { padding: 20px; margin-bottom: 16px; }
.pagamento-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; margin: 18px 0; }
.pagamento-grid label { display: flex; flex-direction: column; gap: 6px; }
.pagamento-grid .input, .pagamento-grid .select { width: 100%; box-sizing: border-box; }
.pagamento-obs { grid-column: 1 / -1; }
.pagamento-nota { white-space: pre-wrap; overflow-wrap: anywhere; }
.pagamento-form[hidden] { display: none; }
@media(max-width:600px) { .pagamento-grid { grid-template-columns: 1fr; } .pagamento-card .section-header { align-items: flex-start; } }

.nav-btn[data-tab="pagamentos"]{position:relative}
.selo-pend{position:absolute;top:6px;right:6px;width:10px;height:10px;border-radius:50%;background:#e00;box-shadow:0 0 0 2px #fff;pointer-events:none}
