/* Controle Financeiro — tema escuro (padrão do iPhone à noite) e claro */
:root {
  color-scheme: dark;
  --page: #0b0b0b; --surface: #191919; --surface-2: #222222;
  --ink: #efefef; --ink-2: #9c9c9c; --hair: rgba(255,255,255,.10);
  --grid: #303030; --axis: #474747;
  --accent: #338ced; --accent-track: #0f4a96;
  --series-1: #338ced; --ideal: #8a8a8a; --col-muted: #3b3b3b;
  --good: #53c556; --warning: #fbb315; --serious: #f18a59; --critical: #dc3c3d;
  --bad-text: #ff8a8a;
  --radius: 18px;
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --page: #f4f4f2; --surface: #ffffff; --surface-2: #f0f0ee;
    --ink: #191919; --ink-2: #666666; --hair: rgba(11,11,11,.10);
    --grid: #e7e7e7; --axis: #c2c2c2;
    --accent: #257de0; --accent-track: #cce3fd;
    --series-1: #257de0; --ideal: #9a9a9a; --col-muted: #d6d6d6;
    --good: #006c10; --bad-text: #c42b2c;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--page); color: var(--ink); }
body { font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
#app { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 96px); }
h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 10px; letter-spacing: -.01em; }
h3 { margin: 0; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.num, .tick { font-variant-numeric: tabular-nums; }
.good { color: var(--good); }
.bad { color: var(--bad-text); }
code { font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }

.carregando { padding: 40vh 0; text-align: center; color: var(--ink-2); }
.demo-pill { position: sticky; top: 4px; z-index: 5; margin: 0 auto 6px; width: fit-content; font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--hair); }

.top { display: flex; align-items: flex-start; justify-content: space-between; padding: 10px 2px 14px; }
.top p { font-size: 13px; margin-top: 2px; }
.icon-btn { background: var(--surface); border: 1px solid var(--hair); color: var(--ink); width: 38px; height: 38px; border-radius: 50%; font-size: 18px; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border: 1px solid var(--hair); position: relative; }
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card-h h2 { margin: 0; }
.vazio { text-align: center; padding: 28px 18px; }
.vazio p { margin: 6px 0 16px; }

/* hero */
.hero .eyebrow { font-size: 13px; color: var(--ink-2); }
.hero-num { font-size: 44px; font-weight: 650; letter-spacing: -.03em; margin: 2px 0 4px; }
.hero-num.neg { color: var(--bad-text); }
.small-num { font-size: 32px; margin: 4px 0; }
.sub { color: var(--ink-2); font-size: 14px; }
.sub strong { color: var(--ink); }
.meter { position: relative; height: 10px; border-radius: 99px; margin: 16px 0 8px; background: var(--accent-track); overflow: hidden; }
.meter .fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s; }
.meter.warning { background: color-mix(in srgb, var(--warning) 22%, var(--surface)); } .meter.warning .fill { background: var(--warning); }
.meter.serious { background: color-mix(in srgb, var(--serious) 22%, var(--surface)); } .meter.serious .fill { background: var(--serious); }
.meter.critical { background: color-mix(in srgb, var(--critical) 22%, var(--surface)); } .meter.critical .fill { background: var(--critical); }
.meter i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--surface); }
.meter-leg { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); }

/* alertas */
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; margin-bottom: 12px; border: 1px solid; }
.banner p { font-size: 13px; margin-top: 2px; }
.banner .b-ic { font-size: 18px; line-height: 1.2; }
.banner.warning { border-color: color-mix(in srgb, var(--warning) 55%, transparent); background: color-mix(in srgb, var(--warning) 12%, var(--surface)); }
.banner.serious { border-color: color-mix(in srgb, var(--serious) 60%, transparent); background: color-mix(in srgb, var(--serious) 14%, var(--surface)); }
.banner.critical { border-color: color-mix(in srgb, var(--critical) 65%, transparent); background: color-mix(in srgb, var(--critical) 16%, var(--surface)); }
.banner.info { border-color: var(--hair); background: var(--surface); }

/* tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--hair); border-radius: 16px; padding: 12px 13px; min-width: 0; }
.t-lab { font-size: 12px; color: var(--ink-2); }
.t-val { font-size: 19px; font-weight: 650; margin: 3px 0 2px; letter-spacing: -.01em; }
.t-sub { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.t-sub.bad { color: var(--bad-text); } .t-sub.good { color: var(--good); }

/* gráficos */
.chart { position: relative; margin: 4px -4px 6px; touch-action: pan-y; }
.chart svg { display: block; overflow: visible; }
.grid { stroke: var(--grid); stroke-width: 1; }
.axis { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--ink-2); font-size: 11px; }
.tick.strong { fill: var(--ink); font-weight: 600; }
.ref { stroke: var(--ink-2); stroke-width: 1; }
.line-real { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area-real { fill: var(--series-1); opacity: .10; }
.line-ideal { fill: none; stroke: var(--ideal); stroke-width: 2; stroke-linecap: round; }
.dot-real { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.crosshair { stroke: var(--axis); stroke-width: 1; }
.col { fill: var(--col-muted); } .col-atual { fill: var(--series-1); }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i, .tt-key { display: inline-block; width: 14px; height: 2px; border-radius: 2px; }
.k-real { background: var(--series-1); } .k-ideal { background: var(--ideal); }
.tt { display: none; position: absolute; pointer-events: none; z-index: 3; background: var(--surface-2); border: 1px solid var(--hair); border-radius: 10px; padding: 7px 9px; font-size: 12px; white-space: nowrap; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.tt-row { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tt-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* categorias */
.insight { font-size: 14px; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.cats { list-style: none; margin: 0; padding: 0; }
.cats li { padding: 8px 0; cursor: pointer; }
.cat-row { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; }
.cat-row .num { font-weight: 600; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-bottom: 4px; }
.bar div { height: 100%; background: var(--series-1); border-radius: 99px; }

/* listas */
.lista { list-style: none; margin: 0; padding: 0; }
.lista.card { padding: 4px 14px; }
.lista li { display: flex; align-items: center; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--hair); }
.lista li:last-child { border-bottom: 0; }
.lista li[data-tx], .lista li[data-fixo], .lista li[data-conexao], .lista li[data-categoria] { cursor: pointer; }
.ic { width: 36px; height: 36px; flex: none; border-radius: 11px; background: var(--surface-2); display: grid; place-items: center; font-size: 17px; }
.li-main { flex: 1; min-width: 0; }
.li-t { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.li-v .small { font-weight: 400; }
.tx.ign { opacity: .55; }
.tx.ign .li-v { text-decoration: line-through; }
.trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--ink-2); font-size: 22px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; margin-right: 4px; border: 1px solid var(--hair); }
.tag-a { background: color-mix(in srgb, var(--series-1) 18%, transparent); color: var(--ink); }
.tag-b { background: var(--surface-2); color: var(--ink-2); }
.sub-h { font-size: 13px; color: var(--ink-2); font-weight: 600; margin: 14px 0 0; text-transform: uppercase; letter-spacing: .04em; }
.dia { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 16px 4px 6px; }

/* "próximo mês" */
.conta { margin: 0; }
.conta div { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--hair); font-size: 14px; }
.conta dt { color: var(--ink-2); } .conta dd { margin: 0; font-variant-numeric: tabular-nums; }
.conta .total { border-bottom: 0; padding-top: 10px; font-weight: 650; font-size: 16px; }
.conta .total dt { color: var(--ink); }
details { margin-top: 8px; } summary { cursor: pointer; }
.mini { list-style: none; padding: 0; margin: 6px 0 0; font-size: 13px; }
.mini li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }

/* gastos: filtros */
.seg { display: flex; background: var(--surface); border: 1px solid var(--hair); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; color: var(--ink-2); padding: 8px 4px; border-radius: 9px; font: inherit; font-size: 13px; }
.seg button.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.busca { width: 100%; margin-bottom: 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin: 0 -16px 8px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--hair); background: var(--surface); color: var(--ink); border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 13px; }
.chips button.on { background: var(--ink); color: var(--page); }

/* formulários */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--surface-2); border: 1px solid var(--hair); border-radius: 11px; padding: 11px 12px; width: 100%; }
textarea { resize: vertical; font-size: 14px; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-size: 14px; }
.check input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.copy { position: relative; margin-bottom: 8px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.copy input { font-size: 13px; padding-right: 70px; }
.copy .link { position: absolute; right: 10px; bottom: 11px; }
.row { display: flex; gap: 8px; } .row .btn { flex: 1; }
.btn { font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 13px 16px; background: var(--accent); color: #fff; width: 100%; margin-top: 4px; }
.btn.sec { background: var(--surface-2); color: var(--ink); border: 1px solid var(--hair); }
.btn.danger, .link.danger { color: var(--bad-text); }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-size: 14px; padding: 0; }
.card > .link.danger { margin-top: 6px; font-size: 13px; }
select[data-papel] { width: auto; font-size: 14px; padding: 6px 8px; }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--hair); border-radius: 99px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }

/* barra de abas */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; gap: 4px; padding: 6px 10px calc(env(safe-area-inset-bottom) + 6px); background: color-mix(in srgb, var(--page) 82%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-top: 1px solid var(--hair); }
.tabbar button { flex: 1; max-width: 130px; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: none; color: var(--ink-2); font: inherit; font-size: 11px; padding: 4px 0; }
.tabbar button svg { display: block; }
.tabbar button.on { color: var(--accent); font-weight: 600; }
.fab { position: fixed; right: max(18px, calc(50% - 262px)); bottom: calc(env(safe-area-inset-bottom) + 76px); z-index: 11; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 30px; line-height: 1; box-shadow: 0 8px 24px rgba(0,0,0,.35); }

/* folhas */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0); transition: background .2s; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap.open { background: rgba(0,0,0,.5); }
.sheet { width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 18px calc(env(safe-area-inset-bottom) + 20px); transform: translateY(100%); transition: transform .22s ease-out; }
.sheet-wrap.open .sheet { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--axis); margin: 0 auto 14px; }
.sheet h2 { font-size: 19px; overflow-wrap: anywhere; }
.sheet .form { margin-top: 14px; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translate(-50%, 20px); opacity: 0; z-index: 30; background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; transition: .25s; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--critical); color: #fff; }

.login { text-align: center; padding-top: 12vh; }
.login img { border-radius: 18px; margin-bottom: 12px; }
.login h1 { margin-bottom: 4px; }
.login .form { text-align: left; margin-top: 24px; }
.halo { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
