/* Finanças da Casa: light-blue, phone-first. One family (Inter), tabular numerals, bottom tab bar on phones. */
:root {
  color-scheme: light;
  --bg: #eef5fc;
  --surface: #ffffff;
  --surface-2: #e3eefa;
  --line: #d3e2f1;
  --ink: #0d2540;
  --ink-2: #3d5a78;
  --brand: #1a6fd6;
  --brand-ink: #ffffff;
  --brand-soft: #d9e9fb;
  --brand-deep: #0f4f9e;
  --neg: #c4282b;
  --neg-soft: #fde8e8;
  --warn: #9a5a00;
  --warn-soft: #fff1d6;
  --pos: #18794a;
  --pos-soft: #ddf3e7;
  --shadow: 0 1px 2px rgba(13, 37, 64, .06), 0 4px 14px rgba(13, 37, 64, .06);
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
}
::selection { background: var(--brand-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 8px; }
svg.i { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
h1 svg { color: var(--brand); }
#who { color: var(--ink-2); font-size: 13px; font-weight: 500; }
h2 { font-size: 15px; font-weight: 650; margin: 0 0 12px; letter-spacing: -.005em; }
h3 { font-size: 13px; font-weight: 600; margin: 18px 0 8px; color: var(--ink-2); }

/* ---------- navigation: bottom bar on phones, top tabs on wide screens ---------- */
nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(13, 37, 64, .05);
}
nav#tabs button {
  border: 0; background: none; color: var(--ink-2); font: inherit; font-size: 11px; font-weight: 550;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; padding: 6px 2px;
}
nav#tabs button.on { color: var(--brand); }
nav#tabs button.add span.dot {
  width: 48px; height: 48px; border-radius: 16px; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; margin-top: -18px; box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 40%, transparent);
  transition: transform .15s ease-out;
}
nav#tabs button.add:active span.dot { transform: scale(.94); }
nav#tabs button.add svg.i { width: 26px; height: 26px; stroke-width: 2.2; }
nav#tabs [data-tab].desk { display: none; }

#mais { display: grid; gap: 8px; }
#mais button { justify-content: flex-start; }

@media (min-width: 820px) {
  body { padding-bottom: 32px; }
  nav#tabs {
    position: sticky; top: 56px; bottom: auto; height: auto; padding: 6px 16px; display: flex; gap: 4px; overflow-x: auto;
    border-top: 0; border-bottom: 1px solid var(--line); box-shadow: none; background: var(--bg);
  }
  nav#tabs button { flex-direction: row; font-size: 14px; padding: 8px 12px; border-radius: 10px; gap: 6px; }
  nav#tabs button.on { background: var(--brand-soft); }
  nav#tabs button.add span.dot { width: 28px; height: 28px; border-radius: 9px; margin: 0; box-shadow: none; }
  nav#tabs button.add svg.i { width: 18px; height: 18px; }
  nav#tabs [data-tab].desk { display: flex; }
  nav#tabs [data-tab="mais"] { display: none; }
}

main { max-width: 980px; margin: 0 auto; padding: 4px 16px 24px; }
section { animation: in .2s ease-out; }
@keyframes in { from { opacity: .4; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { section { animation: none; } }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.muted { color: var(--ink-2); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.split { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

/* summary: one panel, not a row of equal cards */
.resumo { background: linear-gradient(160deg, var(--brand) 0%, var(--brand-deep) 100%); color: #fff; border: 0; }
.resumo .muted { color: rgba(255, 255, 255, .82); }
.resumo .big { font-size: 34px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0 2px; }
.resumo .big.neg { color: #ffd2d0; }
.resumo .bar { background: rgba(255, 255, 255, .25); }
.resumo .bar > i { background: #fff; }
.resumo dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.resumo dt { font-size: 12px; color: rgba(255, 255, 255, .78); }
.resumo dd { margin: 2px 0 0; font-weight: 650; font-size: 15px; }

/* money: negatives always red */
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }

/* ---------- lists (replace wide tables on phones) ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.list > li:last-child { border-bottom: 0; }
.list .t { font-weight: 550; min-width: 0; overflow-wrap: anywhere; }
.list .s { grid-column: 1 / -1; color: var(--ink-2); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.list .v { font-weight: 650; text-align: right; }
.list .acts { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 6px; }
.list .acts select { flex: 1; min-width: 0; }

.bar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 6px; grid-column: 1 / -1; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 4px; transition: width .3s ease-out; }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--neg); }

.tag { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-deep); white-space: nowrap; }
.tag.warn { background: var(--warn-soft); color: var(--warn); } .tag.bad { background: var(--neg-soft); color: var(--neg); } .tag.ok { background: var(--pos-soft); color: var(--pos); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 16px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--neg); }
.btn.icon { min-width: 46px; padding: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.busy { pointer-events: none; opacity: .7; }

/* 16px inputs stop iOS from zooming on focus */
input, select { font: inherit; font-size: 16px; padding: 10px 12px; min-height: 46px; max-width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); }
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input::placeholder { color: color-mix(in srgb, var(--ink-2) 75%, transparent); }
form .f { display: grid; gap: 6px; margin-bottom: 12px; } form .f > span { font-size: 13px; font-weight: 550; color: var(--ink-2); }
input.valor { font-size: 28px; font-weight: 700; text-align: right; letter-spacing: -.01em; }

.acoes { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
.acoes .btn { flex-direction: column; min-height: 96px; font-size: 14px; border-radius: 16px; background: var(--surface-2); border-color: transparent; color: var(--brand-deep); }
.acoes .btn svg.i { width: 28px; height: 28px; }
.acoes .btn.rec { background: var(--neg-soft); color: var(--neg); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.charts { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.charts canvas { max-height: 260px; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--ink-2); font-weight: 600; }
td.n, th.n { text-align: right; white-space: nowrap; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; display: none; max-width: min(92vw, 480px);
  box-shadow: 0 8px 24px rgba(13, 37, 64, .25); font-weight: 550;
}
@media (min-width: 820px) { #toast { bottom: 24px; } }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.login { max-width: 420px; margin: 24px auto; }
.lf { display: grid; gap: 12px; }
.err { color: var(--neg); font-weight: 550; }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-2); }
.empty svg.i { width: 36px; height: 36px; color: var(--brand); margin-bottom: 8px; }
.seg { display: inline-flex; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--ink-2); cursor: pointer; min-height: 38px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
