:root {
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --brand: #10b981;
  --brand-dark: #059669;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid #1e293b;
  font-weight: 700;
  color: #fff;
  font-size: 1.05rem;
}
.sidebar .brand .dot {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #22d3ee);
  display: flex; align-items: center; justify-content: center; color: #06231b; font-weight: 800;
}

.nav-group { padding: 14px 0 4px; }
.nav-group .label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: #64748b; padding: 0 18px 6px;
}
.sidebar a.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; color: #cbd5e1; text-decoration: none;
  font-size: .9rem; border-left: 3px solid transparent;
}
.sidebar a.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar a.nav-item.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--brand); }
.sidebar a.nav-item .ico { width: 18px; text-align: center; }

.main { margin-left: 250px; flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar .sub { color: var(--muted); font-size: .8rem; }

.content { padding: 24px; }

/* ---------- Componentes ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.card + .card { margin-top: 18px; }

/* Cabeçalho de card — usado nas telas de posição de caixa e notas.
   Sem esta regra o título caía como h2 solto, sem espaçamento. */
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.card-head h2 { font-size: 1rem; font-weight: 700; margin: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } .sidebar { width: 72px; } .main { margin-left: 72px; } .sidebar .label, .sidebar .nav-item span.txt, .sidebar .brand span { display: none; } }

.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .k-label { font-size: .8rem; color: var(--muted); }
.kpi .k-value { font-size: 1.5rem; font-weight: 700; }
.kpi .k-foot { font-size: .75rem; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.badge-aberto { background: #fef3c7; color: #92400e; }
.badge-pago { background: #dcfce7; color: #166534; }
.badge-atraso { background: #fee2e2; color: #991b1b; }
.badge-matriz { background: #dbeafe; color: #1e40af; }
.badge-neutro { background: #e2e8f0; color: #334155; }

.text-entrada { color: var(--brand-dark); font-weight: 600; }
.text-saida { color: var(--danger); font-weight: 600; }
.text-muted { color: var(--muted); }

/* Tabelas */
table.tbl { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.tbl th, table.tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.tbl th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
table.tbl tbody tr:hover { background: #f8fafc; }
table.tbl td.num, table.tbl th.num { text-align: right; }
.tbl-scroll { overflow-x: auto; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: none; cursor: pointer;
  padding: 9px 16px; border-radius: 9px; font-size: .86rem; font-weight: 600;
  text-decoration: none; transition: .15s;
}
.btn-primary { background: var(--brand); color: #04231a; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-dark { background: var(--sidebar-bg); color: #fff; }
.btn-light { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-light:hover { background: #f1f5f9; }
.btn-danger { background: #fee2e2; color: #991b1b; }
.btn-sm { padding: 5px 10px; font-size: .78rem; border-radius: 7px; }

/* Formulários */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: .8rem; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
  width: 100%; min-width: 0; max-width: 100%;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  font-size: .88rem; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(16,185,129,.15);
}
.field-full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); } }

/* Filtros bar */
.filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }

/* Flash */
.flash { padding: 11px 16px; border-radius: 10px; margin-bottom: 14px; font-size: .88rem; }
.flash.ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.flash.erro { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* Aviso: usado em 16 chamadas de flash() e em blocos de alerta.
   Sem esta regra o aviso caía no estilo padrão e ficava invisível na página. */
.flash.aviso { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* Blocos de aviso dentro de cards e modais */
.alert { padding: 11px 14px; border-radius: 10px; font-size: .86rem; line-height: 1.5; margin-bottom: 12px; }
.alert:last-child { margin-bottom: 0; }
.alert strong { font-weight: 700; }
.alert-warn { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #7dd3fc; }

/* Login */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #0f172a, #020617); }
.auth-card { background: #fff; padding: 36px; border-radius: 18px; width: 380px; box-shadow: 0 25px 60px rgba(0,0,0,.4); }
.auth-card .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-card .logo .dot { width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #22d3ee); display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #04231a; font-size: 1.2rem; }

/* Modal simples */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.6); display: none;
  align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow-y: auto; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 720px; padding: 24px; }
.modal h3 { margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Chart helpers */
.chart-box { position: relative; height: 300px; }
.mini-chart { height: 220px; position: relative; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title h2 { font-size: 1.05rem; margin: 0; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; border-radius: 9px; text-decoration: none; color: var(--muted);
  font-size: .86rem; font-weight: 600; background: #fff; border: 1px solid var(--border); }
.tabs a.active { background: var(--sidebar-bg); color: #fff; border-color: var(--sidebar-bg); }

.empty { padding: 40px; text-align: center; color: var(--muted); }
