:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --ink: #111113;
  --mut: #86868b;
  --line: #ebebe7;
  --soft: #f0f0ec;
  --pos: #0e9f6e;
  --neg: #e5484d;
  --warn: #d97706;
  --acc: #111113;
  --on-acc: #ffffff;
  --r: 16px;
  --tab: 60px;
  --max: 560px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0c;
    --card: #151517;
    --ink: #f4f4f2;
    --mut: #8e8e93;
    --line: #242427;
    --soft: #1d1d20;
    --pos: #34d399;
    --neg: #ff6b6b;
    --warn: #f59e0b;
    --acc: #f4f4f2;
    --on-acc: #0b0b0c;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
body.lock { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.mut { color: var(--mut); }
.hide { display: none !important; }

/* ---------- layout ---------- */
.view {
  max-width: var(--max);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(var(--tab) + env(safe-area-inset-bottom) + 28px);
  min-height: 100vh;
}
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.title { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; margin: 0; }
.sub { color: var(--mut); font-size: 13px; }

.monthnav { display: flex; align-items: center; gap: 2px; }
.monthnav button { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; color: var(--mut); }
.monthnav button:active { background: var(--soft); }
.monthnav span { min-width: 112px; text-align: center; font-weight: 600; font-size: 15px; }

h2.sec { font-size: 13px; font-weight: 600; color: var(--mut); text-transform: uppercase; letter-spacing: .06em; margin: 26px 4px 8px; display: flex; justify-content: space-between; align-items: baseline; }
h2.sec a { text-transform: none; letter-spacing: 0; font-weight: 500; }

.card { background: var(--card); border-radius: var(--r); padding: 14px 16px; border: 1px solid var(--line); }
.card + .card { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .card + .card { margin-top: 0; }
.stat small { display: block; color: var(--mut); font-size: 12px; margin-bottom: 2px; }
.stat b { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.stat em { display: block; font-style: normal; font-size: 12px; color: var(--mut); margin-top: 2px; }

.hero { padding: 8px 4px 18px; }
.hero small { color: var(--mut); font-size: 13px; }
.hero h1 { margin: 2px 0 2px; font-size: 42px; line-height: 1.1; font-weight: 700; letter-spacing: -0.04em; }
.hero p { margin: 0; color: var(--mut); font-size: 13px; }

/* ---------- listas ---------- */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; }
.item + .item { border-top: 1px solid var(--line); }
button.item:active, .item.tap:active { background: var(--soft); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 12.5px; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .v { font-weight: 600; white-space: nowrap; }
.item .badge { font-size: 11px; color: var(--mut); border: 1px solid var(--line); border-radius: 99px; padding: 0 6px; margin-left: 6px; font-weight: 500; }
.item .late { color: var(--neg); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.check {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 1.6px solid var(--mut); display: grid; place-items: center; color: transparent;
}
.check.on { background: var(--pos); border-color: var(--pos); color: #fff; }
.check svg { width: 15px; height: 15px; }

.dayhead { font-size: 12.5px; font-weight: 600; color: var(--mut); padding: 14px 4px 6px; }
.daygroup .list { margin-bottom: 2px; }

.empty { text-align: center; color: var(--mut); padding: 28px 12px; font-size: 14px; }

/* ---------- barras ---------- */
.bars .bar { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 7px 0; font-size: 14px; }
.bars .track { grid-column: 1 / -1; height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bars .fill { height: 100%; border-radius: 99px; }
.hist { display: flex; align-items: flex-end; gap: 10px; height: 110px; padding-top: 6px; }
.hist .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.hist .pair { display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; flex: 1; }
.hist .pair i { display: block; width: 38%; max-width: 16px; border-radius: 4px 4px 0 0; min-height: 2px; }
.hist .i { background: var(--pos); opacity: .85; }
.hist .e { background: var(--neg); opacity: .85; }
.hist .col span { font-size: 11px; color: var(--mut); }
.hist .col.cur span { color: var(--ink); font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--mut); margin-top: 10px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }

/* ---------- controles ---------- */
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 9px; font-size: 14px; font-weight: 550; color: var(--mut); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.type button.on[data-type="expense"] { color: var(--neg); }
.seg.type button.on[data-type="income"] { color: var(--pos); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 500; color: var(--mut); }
.chip.on { background: var(--acc); color: var(--on-acc); border-color: var(--acc); }

.search { position: relative; margin-bottom: 10px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--mut); }
.search input { padding-left: 38px; }

input, select, textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 16px; outline: none; appearance: none; -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--mut); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
input[type="date"] { min-height: 46px; }
textarea { resize: none; min-height: 70px; }
label.f { display: block; margin-top: 14px; }
label.f > span { display: block; font-size: 12.5px; color: var(--mut); margin: 0 2px 5px; font-weight: 500; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; background: var(--acc); color: var(--on-acc); font-weight: 600; font-size: 16px; text-align: center; }
.btn:active { opacity: .85; }
.btn[disabled] { opacity: .5; }
.btn.ghost { background: var(--soft); color: var(--ink); }
.btn.danger { background: transparent; color: var(--neg); }
.btn + .btn { margin-top: 8px; }
.link { color: var(--ink); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); background: var(--card); border-radius: 12px; margin-top: 14px; }
.switch input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line); position: relative; flex: none; padding: 0; border: 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked { background: var(--pos); }
.switch input:checked::after { transform: translateX(20px); }

.amount { font-size: 38px; font-weight: 700; text-align: center; letter-spacing: -0.03em; border: 0; background: transparent; padding: 14px 0 6px; }
.amount:focus { border: 0; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--ink); }

/* ---------- gráfico fluxo ---------- */
.chart { width: 100%; height: 130px; }
.chart path.line { fill: none; stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart path.area { fill: var(--ink); opacity: .07; }
.chart line.zero { stroke: var(--neg); stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; opacity: .7; }
.chart .low { fill: var(--neg); }
.chartlabels { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--mut); margin-top: 4px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .in { max-width: var(--max); margin: 0 auto; height: var(--tab); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.tabbar button { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 550; color: var(--mut); }
.tabbar button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--ink); }
.tabbar .add { justify-content: center; }
.tabbar .add i { width: 48px; height: 48px; border-radius: 50%; background: var(--acc); color: var(--on-acc); display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.22); }
.tabbar .add i svg { stroke: var(--on-acc); width: 24px; height: 24px; }
.tabbar .add:active i { transform: scale(.94); }

/* ---------- sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 40; opacity: 0; transition: opacity .2s; }
.backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; margin: 0 auto; max-width: var(--max);
  background: var(--bg); border-radius: 22px 22px 0 0; max-height: 92vh; max-height: 92dvh;
  display: flex; flex-direction: column; transform: translateY(100%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
}
.sheet.show { transform: none; }
.sheet .grab { width: 38px; height: 5px; border-radius: 99px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 4px; flex: none; }
.sheet header h3 { margin: 0; font-size: 17px; font-weight: 650; }
.sheet header button { width: 32px; height: 32px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; color: var(--mut); }
.sheet .scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px calc(env(safe-area-inset-bottom) + 20px); }
.sheet .actions { margin-top: 20px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--neg); color: #fff; }

/* ---------- login ---------- */
.auth { max-width: 400px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px); }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 22px; }
.auth h1 { font-size: 30px; letter-spacing: -0.03em; margin: 0 0 4px; }
.auth p { color: var(--mut); margin: 0 0 18px; }
.auth .err { color: var(--neg); font-size: 14px; margin-top: 12px; min-height: 20px; }
.auth .btn { margin-top: 18px; }

.loading { display: grid; place-items: center; min-height: 60vh; color: var(--mut); }

@media (min-width: 700px) {
  .sheet { bottom: 50%; transform: translateY(calc(50% + 100vh)); border-radius: 22px; max-height: 86vh; }
  .sheet.show { transform: translateY(50%); }
}
