/* Palette inherited from the original spreadsheet dashboard. */
:root {
  --navy: #0b2f4a;
  --navy-2: #1f4e79;
  --green: #356854;
  --indigo: #535fc1;
  --bg: #f6f8f9;
  --surface: #ffffff;
  --line: #e3e8ec;
  --text: #1f1f1f;
  --muted: #66727c;
  --income: #2e7d32;
  --expense: #c62828;
  --balance: #1565c0;
  --orange: #fb8c00;
  --card: #8e24aa;
  --limit: #d81b60;
  --fixed: #1e88e5;
  --other: #fb8c00;
  --ok-bg: #c6efce;
  --ok-fg: #1e6b34;
  --warn-bg: #ffc7ce;
  --warn-fg: #9c0006;
  --blue-soft: #e8f1fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 47, 74, .06), 0 4px 16px rgba(11, 47, 74, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--navy-2); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; color: var(--navy); }
h2 { font-size: 1rem; color: var(--navy); }
h3 { font-size: .9rem; color: var(--navy); margin: 18px 0 8px; }
small { font-size: .8em; }

/* ---------- top bar ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; min-height: 56px; }
.brand { color: #fff; font-weight: 700; text-decoration: none; white-space: nowrap; letter-spacing: .2px; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.topbar nav a { color: #c9d6e2; text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-size: .92rem; }
.topbar nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.topbar nav a.on { color: #fff; background: rgba(255, 255, 255, .14); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 20px 16px 48px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.muted { color: var(--muted); }
.page-head .muted { margin: 4px 0 0; }
.hint { color: var(--muted); font-size: .82rem; margin: 8px 0 0; }
.hint.center { text-align: center; margin: -4px 0 14px; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }
.error { color: var(--warn-fg); margin: 0; }
.warn-text { color: var(--warn-fg) !important; }

.flash { background: var(--ok-bg); color: var(--ok-fg); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--navy);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 38px; list-style: none;
}
.btn:hover { border-color: #c7d1d9; background: #fbfcfd; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .82rem; }
.btn.danger { color: var(--expense); }
.btn::-webkit-details-marker { display: none; }
.link { font-size: .85rem; text-decoration: none; }

input, select {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid #cfd8df; border-radius: 9px; padding: 8px 10px; min-height: 40px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--blue-soft); border-color: var(--balance); }
input[data-money] { text-align: right; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; }
label.check input { width: auto; min-height: 0; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form label { flex: 1 1 120px; }
.inline-form.tight { flex-wrap: nowrap; }

.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav input { width: auto; min-width: 150px; }
.month-nav .btn { font-size: 1.2rem; padding: 4px 12px; }
.month-nav .btn.small { font-size: .82rem; }

.tabs { display: inline-flex; background: #e9eef2; border-radius: 10px; padding: 3px; }
.tabs a { text-decoration: none; color: var(--muted); padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: .9rem; }
.tabs a.on { background: #fff; color: var(--navy); box-shadow: var(--shadow); }

/* ---------- cards & KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head .muted { font-size: .8rem; }
.card-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-width: 0; border-top: 3px solid var(--navy); }
.kpi.cash { border-top-color: var(--green); background: linear-gradient(180deg, #f3f9f5, #fff 60%); }
.kpi-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi-value { font-size: 1.45rem; font-weight: 700; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { color: var(--muted); font-size: .8rem; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pos { color: var(--income) !important; }
.negc { color: var(--expense) !important; }
.accent { color: var(--balance) !important; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eef1f4; color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); }
.tag { font-size: .72rem; background: var(--blue-soft); color: var(--navy-2); padding: 0 6px; border-radius: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.chip { background: #eef1f4; border-radius: 999px; padding: 2px 10px; font-size: .82rem; }

.meter { height: 8px; background: #eef1f4; border-radius: 999px; overflow: hidden; margin: 4px 0 2px; }
.meter span { display: block; height: 100%; background: var(--card); border-radius: inherit; }
.meter.over span { background: var(--limit); }
.meter.big { height: 12px; margin-bottom: 12px; }
.meter.big span { background: var(--green); }

.cash-form summary { cursor: pointer; color: var(--green); font-size: .82rem; font-weight: 600; margin-top: 6px; }
.cash-form .inline-form { margin-top: 8px; }
.cash-form .inline-form label { flex: 1 1 100px; }

/* ---------- layout ---------- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.chart { position: relative; height: 260px; }
.chart.tall { height: 300px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.two-col.wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
section.card { margin-bottom: 16px; }

.flow-stats { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-bottom: 12px; }
.flow-stats div { display: flex; flex-direction: column; }
.flow-stats span { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.flow-stats strong { font-size: 1.15rem; color: var(--navy); }
.flow-stats small { color: var(--muted); }
.flow-stats .alert strong { color: var(--warn-fg); }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
table.grid { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.grid th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: #fff; background: var(--navy); padding: 8px 10px; font-weight: 600; white-space: nowrap; }
table.grid th:first-child { border-top-left-radius: 8px; }
table.grid th:last-child { border-top-right-radius: 8px; }
table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tbody tr:nth-child(even) td { background: #fafbfc; }
table.grid tr.sel td { background: var(--blue-soft) !important; }
table.grid tr.inactive td { opacity: .55; }
table.grid.compact td { padding: 6px 8px; }
table.grid td a { text-decoration: none; font-weight: 600; }
.num { text-align: right !important; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }

/* ---------- bars ---------- */
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.bars li { display: grid; grid-template-columns: minmax(90px, 1.1fr) 2fr auto; gap: 10px; align-items: center; font-size: .88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 10px; background: #eef1f4; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--other); }
.bar .b-cartao { background: var(--card); }
.bar .b-fixo { background: var(--fixed); }
.bar .b-outros { background: var(--other); }
.bar .b-income { background: var(--income); }

/* ---------- entries ---------- */
.entries { list-style: none; margin: 0; padding: 0; }
.entry { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.e-date { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.e-date strong { color: var(--navy); font-size: .9rem; }
.e-date small { color: var(--muted); }
.e-main { display: flex; flex-direction: column; min-width: 0; }
.e-desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.e-meta { color: var(--muted); font-size: .8rem; }
.e-amount { font-weight: 700; white-space: nowrap; }
.e-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.e-actions form { margin: 0; }
.entry.projected { background: repeating-linear-gradient(135deg, transparent 0 8px, rgba(83, 95, 193, .035) 8px 16px); }
.entry.projected .e-desc, .entry.projected .e-amount { opacity: .7; font-style: italic; }
.skipped { margin-top: 12px; }
.skipped summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.skipped-row { opacity: .6; text-decoration: line-through; }
.skipped-row .e-actions { text-decoration: none; }

.pop { position: relative; }
.pop-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(11, 47, 74, .18); padding: 12px; width: 220px; display: flex; flex-direction: column; gap: 8px; }

.repeat { border: 1px dashed #cfd8df; border-radius: 10px; padding: 8px 10px; }
.repeat-fields { display: none; margin-top: 10px; }
.repeat:has(input[name=repeat]:checked) .repeat-fields { display: block; }
.recurrence-fields { display: flex; flex-direction: column; gap: 10px; }
.recurrence-fields .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- login ---------- */
.login { min-height: 80vh; display: grid; place-items: center; }
.login .card { width: min(360px, 100%); border-top: 4px solid var(--navy); }
.login-brand { font-weight: 700; color: var(--navy); font-size: 1.2rem; margin-bottom: 16px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .charts, .two-col, .two-col.wide-left { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi.cash { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .topbar-inner { flex-direction: column; align-items: stretch; gap: 0; padding-top: 8px; }
  .topbar nav { padding-bottom: 6px; }
  .kpis, .kpis.three { grid-template-columns: minmax(0, 1fr); }
  .kpi-value { font-size: 1.3rem; }
  .page-head { align-items: stretch; }
  .month-nav input { flex: 1; min-width: 0; }
  .form .row, .recurrence-fields .row { grid-template-columns: minmax(0, 1fr); }
  .entry { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .e-actions { grid-column: 2 / -1; justify-content: flex-start; }
  .pop-body { left: 0; right: auto; }
  .chart { height: 230px; }
  .bars li { grid-template-columns: minmax(80px, 1fr) 1fr auto; }
}
