:root {
  --bg: #f0f4f8;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary2: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #f59e0b;
  --income: #059669;
  --income2: #047857;
  --expense: #dc2626;
  --balance: #7c3aed;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.07);
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #2563eb 100%);
  color: white;
  padding: 32px 28px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  opacity: 0.85;
  margin: 0 0 6px;
}

.app-header h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 800;
}

.app-header p {
  max-width: 720px;
  margin: 0;
  opacity: 0.9;
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

/* ---------- Main ---------- */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

/* ---------- Navegação de Mês ---------- */
.month-navigator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow);
}

.month-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.month-display input[type="month"] {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  background: white;
  text-align: center;
}

.month-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--primary);
  border-radius: var(--radius) var(--radius) 0 0;
}

.card.income::before { background: var(--income); }
.card.expense::before { background: var(--expense); }
.card.balance::before { background: var(--balance); }
.card.danger::before { background: var(--danger); }
.card.warning::before { background: var(--warn); }

.card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
  font-weight: 800;
}

.card small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.card.danger strong { color: var(--danger); }
.card.warning strong { color: #b45309; }
.card.income strong { color: var(--income); }
.card.expense strong { color: var(--expense); }
.card.balance strong { color: var(--balance); }

/* ---------- Abas ---------- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover { background: #f1f5f9; color: var(--text); }
.tab-btn.active { background: var(--primary); color: white; }

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Panels ---------- */
.panel {
  padding: 20px;
  margin-bottom: 18px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}

/* ---------- Forms ---------- */
.expense-form, .filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.expense-form label, .filters label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: #334155;
}

.wide { grid-column: span 2; }

.form-actions {
  display: flex;
  align-items: end;
}

input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  font-size: 14px;
  background: white;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ---------- Buttons ---------- */
.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary2); }

.btn.ghost { background: #eef2ff; color: #1e3a8a; }
.btn.ghost:hover { background: #dbeafe; }

.btn.small { padding: 7px 11px; font-size: 12px; }

.file-label { position: relative; cursor: pointer; }

/* ---------- Tables ---------- */
.table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  min-width: 900px;
}

th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

tr:hover td { background: #fafafa; }

/* Badges */
.badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.Recebido, .Pago { background: #dcfce7; color: #166534; }
.Pendente, .Aberto { background: #dbeafe; color: #1d4ed8; }
.Vencido { background: #fee2e2; color: #991b1b; }
.Agendado { background: #fef3c7; color: #92400e; }
.Nao-pagar { background: #f1f5f9; color: #475569; }

/* Actions */
.actions { display: flex; gap: 5px; }

.icon-btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.icon-btn:hover { background: #f1f5f9; }

/* Cell highlights */
.desc-cell, .due-cell, .pay-cell {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.desc-cell { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }
.due-cell { background: #ffedd5; color: #9a3412; border: 1px solid #fed7aa; }
.pay-cell { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.pending-pay { background: #f1f5f9; color: #475569; border: 1px dashed #cbd5e1; }

/* ---------- Charts ---------- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.chart-panel {
  padding: 16px;
  overflow: hidden;
  min-height: 260px;
}

.wide-chart { grid-column: 1 / -1; }

.svg-chart {
  width: 100%;
  height: 205px;
  max-height: 205px;
  overflow: hidden;
}

.svg-chart svg {
  display: block;
  width: 100%;
  height: 100%;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
}

.svg-empty { font-size: 13px; fill: #94a3b8; }
.chart-value { font-size: 11px; font-weight: 700; fill: #334155; }
.chart-label { font-size: 10px; fill: #475569; }
.chart-legend { font-size: 10px; fill: #475569; font-weight: 600; }
.chart-grid { stroke: #e2e8f0; stroke-width: 1; }
.chart-line { fill: none; stroke-width: 3; vector-effect: non-scaling-stroke; }
.chart-dot { fill: #0f172a; }

/* ---------- Planejamento Anual ---------- */
.plan-table { min-width: 1000px; }
.plan-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.plan-table td, .plan-table th { padding: 10px 12px; }
.plan-table tfoot td { border-top: 2px solid var(--line); background: #f8fafc; font-weight: 700; }
.current-row { background: #eff6ff !important; }
.current-row td { border-left: 3px solid var(--primary); }
.positive { color: var(--income); }
.negative { color: var(--expense); }
.danger-text { color: var(--danger); }

/* ---------- Footer ---------- */
footer {
  text-align: center;
  color: var(--muted);
  padding: 28px 18px;
  font-size: 13px;
}

.footer-tip {
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.85;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .charts-grid { grid-template-columns: 1fr; }
  .wide-chart { grid-column: auto; }
}

@media (max-width: 980px) {
  .app-header { display: block; }
  .header-actions { justify-content: flex-start; margin-top: 16px; }
  .cards { grid-template-columns: 1fr; }
  .expense-form, .filters { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; }
  .desc-cell, .due-cell, .pay-cell { white-space: normal; }
}

/* ---------- Print ---------- */
@media print {
  .header-actions, .form-panel, .actions, .btn, .tabs, .month-navigator, footer, .icon-btn { display: none !important; }
  body { background: white; color: #000; }
  .app-header { background: white; color: #111; padding: 12px; border-bottom: 2px solid #ddd; }
  .panel, .card { box-shadow: none; border: 1px solid #ddd; }
  .cards { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .tab-content { display: block !important; }
  .chart-panel { break-inside: avoid; page-break-inside: avoid; }
  .table-wrap { overflow: visible; }
  table { min-width: auto; }
  th { background: #f0f0f0; }
  .current-row { background: #f5f5f5 !important; }
}
