/* ============================================================ base */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --line: #e2dfd8;
  --text: #1d1c1a;
  --muted: #7a776f;
  --faint: #b9b5ab;
  --accent: #1d1c1a;
  --on-accent: #ffffff;

  --t-entrada: #2f9e5b;
  --t-saida: #e0533d;
  --t-diario: #c8417e;
  --t-economia: #8fae1b;
  --t-cartao: #6d4fd8;

  --g2: #9fdc9a;  --g2-t: #14401b;
  --g1: #c9f0d2;  --g1-t: #1e4d2b;
  --y:  #fbe7b8;  --y-t:  #5a4210;
  --r1: #f8c9cf;  --r1-t: #6b1d28;
  --r2: #ec6a78;  --r2-t: #3f0610;

  --radius: 14px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1d1d1b; --surface-2: #262624; --line: #33322f;
  --text: #f1efe9; --muted: #9b978d; --faint: #5b5852; --accent: #f1efe9; --on-accent: #141413;
  --g2: #2f6b37; --g2-t: #e2f7e1; --g1: #234a2c; --g1-t: #cfeedd;
  --y: #5a4718; --y-t: #fbe9bf; --r1: #5c2a31; --r1-t: #fbd5da; --r2: #a7283a; --r2-t: #fff0f2;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --surface: #1d1d1b; --surface-2: #262624; --line: #33322f;
    --text: #f1efe9; --muted: #9b978d; --faint: #5b5852; --accent: #f1efe9; --on-accent: #141413;
    --g2: #2f6b37; --g2-t: #e2f7e1; --g1: #234a2c; --g1-t: #cfeedd;
    --y: #5a4718; --y-t: #fbe9bf; --r1: #5c2a31; --r1-t: #fbd5da; --r2: #a7283a; --r2-t: #fff0f2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hidden { display: none !important; }

/* tons do saldo */
.tone-g2 { background: var(--g2); color: var(--g2-t); }
.tone-g1 { background: var(--g1); color: var(--g1-t); }
.tone-y  { background: var(--y);  color: var(--y-t); }
.tone-r1 { background: var(--r1); color: var(--r1-t); }
.tone-r2 { background: var(--r2); color: var(--r2-t); }

/* ícone de tipo */
.dot { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  font-size: 11px; font-weight: 700; color: #fff; flex: none; }
.dot.entrada { background: var(--t-entrada); } .dot.saida { background: var(--t-saida); }
.dot.diario { background: var(--t-diario); } .dot.economia { background: var(--t-economia); }
.dot.cartao { background: var(--t-cartao); } .dot.todas { background: var(--muted); }
.dot.off { background: transparent; border: 1.5px solid var(--line); }
.dot.ghost { background: transparent; border: 1.5px dashed var(--t-diario); color: var(--t-diario); }

/* ============================================================ layout */
.shell { display: flex; min-height: 100dvh; }
.side { display: none; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 14px 10px;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.topbar .grow { flex: 1; }
.period { display: flex; align-items: center; gap: 2px; }
.period .label { font-weight: 650; min-width: 84px; text-align: center; font-size: 17px; }
.iconbtn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; }
.iconbtn:hover { background: var(--surface-2); }
.iconbtn:disabled { opacity: 0.3; }
.todaybtn { width: 34px; height: 36px; border-radius: 8px; border: 1.5px solid var(--text);
  display: flex; flex-direction: column; overflow: hidden; font-size: 13px; font-weight: 700; }
.todaybtn::before { content: ""; height: 7px; background: var(--t-saida); }
.todaybtn span { flex: 1; display: grid; place-items: center; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }

.content { flex: 1; padding: 0 14px calc(90px + var(--safe-b)); }

/* barra inferior (celular) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b));
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 4px 0; }
.tabbar button.on { color: var(--text); font-weight: 600; }
.tabbar .add { justify-self: center; width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }

/* ============================================================ quadro de saldos (celular) */
.gridhead { position: sticky; top: calc(58px + var(--safe-t)); z-index: 4; background: var(--bg);
  display: grid; grid-template-columns: 34px 1fr 1fr; align-items: center; gap: 8px;
  padding: 6px 0 8px; font-size: 13px; color: var(--muted); }
.gridhead .right { text-align: right; padding-right: 10px; }
.filterchip { justify-self: start; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px 5px 6px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line);
  color: var(--text); font-weight: 550; }

.rows { border-radius: var(--radius); overflow: hidden; background: var(--surface);
  border: 1px solid var(--line); touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.row { display: grid; grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr); align-items: stretch; min-height: 42px;
  border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .d { display: grid; place-items: center; font-size: 13px; color: var(--muted); font-weight: 600; }
.row.we .d { background: var(--surface-2); }
.row.today .d { background: var(--text); color: var(--bg); }
.row.past .v { opacity: 0.75; }
.row .v { display: flex; align-items: center; gap: 8px; padding: 0 10px; justify-content: space-between; }
.row .v .amt.zero { color: var(--faint); }
.row .b { display: flex; align-items: center; justify-content: flex-end; padding: 0 10px; font-weight: 600; font-size: 14px; }
.row.today { box-shadow: inset 0 2px 0 var(--text); }
.row.press { filter: brightness(0.94); }

/* modo "todas": bloco por dia */
.dayblock { display: grid; grid-template-columns: 34px minmax(0, 1.55fr) minmax(0, 1fr); border-top: 1px solid var(--line); }
.dayblock:first-child { border-top: 0; }
.dayblock .d { display: grid; place-items: start center; padding-top: 12px; font-size: 13px; color: var(--muted); font-weight: 600; }
.dayblock.today .d { background: var(--text); color: var(--bg); }
.dayblock.we .d { background: var(--surface-2); }
.dayblock .dlist { padding: 6px 0; min-height: 42px; }
.dayblock .it { display: flex; align-items: center; gap: 8px; padding: 4px 10px; font-size: 14px; }
.dayblock .it .desc { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.dayblock .b { display: flex; justify-content: flex-end; padding: 12px 8px; font-weight: 600; font-size: 13px; }
.dayblock .empty { padding: 12px 10px; color: var(--faint); font-size: 13px; }

.monthsum { margin: 12px 2px 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.monthsum span { display: inline-flex; align-items: center; gap: 6px; }
.swipehint { text-align: center; color: var(--faint); font-size: 12px; margin-top: 10px; }

/* ============================================================ horizonte */
.hz { display: grid; gap: 8px; }
.hzcol { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.hzcol h3 { margin: 0; font-size: 13px; text-align: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-weight: 650; }
.hzcol h3.cur { background: var(--text); color: var(--bg); }
.hzcell { display: grid; grid-template-columns: 24px 1fr; font-size: 12.5px; border-top: 1px solid var(--line); min-height: 26px; }
.hzcell:nth-child(2) { border-top: 0; }
.hzcell .d { display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.hzcell .b { display: flex; align-items: center; justify-content: flex-end; padding: 0 6px; font-weight: 600; }
.hzcell.today .d { background: var(--text); color: var(--bg); }
.hzcell.blank .b { background: transparent; }

/* ============================================================ cartões de informação */
.cards { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.wide { grid-column: 1 / -1; }
.card h4 { margin: 0 0 4px; font-size: 14px; font-weight: 650; }
.card .formula { display: flex; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; }
.card .formula .dot { width: 16px; height: 16px; font-size: 9px; }
.card .big { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.card .big.neg { color: var(--t-saida); }
.card .note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.bar { height: 8px; border-radius: 9px; background: var(--surface-2); overflow: hidden; margin: 6px 0 2px; }
.bar i { display: block; height: 100%; background: var(--t-economia); }

.sectiontitle { font-size: 13px; color: var(--muted); margin: 22px 2px 8px; font-weight: 550; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.li { display: flex; align-items: center; gap: 10px; padding: 13px 14px; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.li:first-child { border-top: 0; }
button.li:hover { background: var(--surface-2); }
.li .grow { flex: 1; min-width: 0; }
.li .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.li .chev { color: var(--faint); }
.li.danger { color: var(--t-saida); }
.emptybox { padding: 30px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* ============================================================ sheets e diálogos */
#overlay { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.35); opacity: 0; transition: opacity .18s; pointer-events: auto; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; transform: translateY(100%);
  transition: transform .22s cubic-bezier(.2,.8,.2,1); pointer-events: auto; padding-bottom: var(--safe-b); }
.open .scrim { opacity: 1; }
.open .sheet { transform: none; }
.sheet .grab { width: 38px; height: 5px; border-radius: 9px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet header { display: flex; align-items: center; gap: 6px; padding: 10px 12px 8px 16px; flex: none; }
.sheet header h2 { font-size: 18px; margin: 0; flex: 1; font-weight: 650; }
.sheet .body { overflow: auto; padding: 0 16px 16px; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet .foot { padding: 10px 16px 14px; flex: none; }

.dialog { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -46%); opacity: 0;
  width: min(360px, calc(100% - 40px)); background: var(--surface); border-radius: 18px; padding: 20px;
  pointer-events: auto; transition: all .18s; }
.open .dialog { transform: translate(-50%, -50%); opacity: 1; }
.dialog h3 { margin: 0 0 6px; font-size: 17px; }
.dialog p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.dialog .stack { display: grid; gap: 8px; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 48px;
  border-radius: 12px; font-weight: 650; background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--t-saida); border: 1px solid color-mix(in srgb, var(--t-saida) 50%, transparent); }
.btn.t-entrada { background: var(--t-entrada); color: #fff; } .btn.t-saida { background: var(--t-saida); color: #fff; }
.btn.t-diario { background: var(--t-diario); color: #fff; } .btn.t-economia { background: var(--t-economia); color: #1b2400; }
.btn.t-cartao { background: var(--t-cartao); color: #fff; }
.btn:disabled { opacity: .5; }
.btn.small { height: 38px; width: auto; padding: 0 14px; font-size: 14px; }

/* formulário */
.amount { display: flex; align-items: baseline; gap: 6px; padding: 6px 0 14px; border-bottom: 1px solid var(--line); }
.amount span { font-size: 22px; font-weight: 600; color: var(--muted); }
.amount input { border: 0; outline: 0; background: none; font-size: 34px; font-weight: 700; width: 100%; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.types { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 14px 0 6px; }
.types button { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11.5px; padding: 8px 2px;
  border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.types button.on { border-color: var(--text); color: var(--text); font-weight: 650; background: var(--surface-2); }
.field { display: flex; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line); }
.field > svg { color: var(--muted); flex: none; }
.field input, .field select { flex: 1; border: 0; background: none; outline: 0; min-height: 50px; min-width: 0; }
.field select { appearance: none; -webkit-appearance: none; text-align: right; padding-right: 2px; }
.field input[type="date"] { text-align: right; }
.field .lab { flex: 1; color: var(--muted); }
.field .val { width: 96px; text-align: right; }
.tagpick { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.chip { padding: 6px 11px; border-radius: 99px; border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.add { border-style: dashed; }
.hint { font-size: 12.5px; color: var(--muted); padding: 10px 0 0; line-height: 1.4; }

/* detalhe */
.detail .kind { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.detail .title { font-size: 22px; font-weight: 700; margin: 8px 0 2px; }
.detail .amt { font-size: 18px; font-weight: 600; }
.detail dl { margin: 16px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; font-size: 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; text-align: right; }

/* lista do dia */
.dayitems .li { padding: 12px 2px; }
.forecastnote { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); margin: 6px 0 10px; line-height: 1.45; }
.forecastnote b { color: var(--text); }
.daynav { display: flex; align-items: center; gap: 2px; }
.daynav .label { min-width: 64px; text-align: center; font-weight: 650; }
select.inline { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: 14px; }

/* toast */
#toast { position: fixed; left: 50%; top: calc(12px + var(--safe-t)); transform: translate(-50%, -20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 80;
  transition: all .2s; pointer-events: none; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--t-saida); color: #fff; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(340px, 100%); display: grid; gap: 14px; }
.login h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: -0.02em; }
.login input { height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; outline: 0; }
.login .err { color: var(--t-saida); font-size: 14px; min-height: 20px; }

/* ============================================================ desktop */
@media (min-width: 900px) {
  body { font-size: 14px; }
  .side {
    display: flex; flex-direction: column; gap: 2px; width: 210px; flex: none; padding: 18px 12px;
    border-right: 1px solid var(--line); position: sticky; top: 0; height: 100dvh; background: var(--surface);
  }
  .side .brand { font-weight: 750; font-size: 17px; padding: 4px 10px 18px; letter-spacing: -0.02em; }
  .side button { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--muted); text-align: left; }
  .side button:hover { background: var(--surface-2); color: var(--text); }
  .side button.on { background: var(--surface-2); color: var(--text); font-weight: 650; }
  .side hr { border: 0; border-top: 1px solid var(--line); margin: 10px 4px; width: auto; }
  .side svg.i { width: 19px; height: 19px; }
  .tabbar { display: none; }
  .topbar { padding: 16px 28px; border-bottom: 1px solid var(--line); }
  .content { padding: 20px 28px 60px; }
  .content.narrow { max-width: 760px; }
  .cards { grid-template-columns: repeat(4, 1fr); }
  .cards .card.wide { grid-column: span 2; }
  #toast { top: auto; bottom: 28px; transform: translate(-50%, 20px); }

  /* sheet vira gaveta lateral */
  .sheet { left: auto; top: 0; width: 440px; max-height: none; border-radius: 0; transform: translateX(100%);
    border-left: 1px solid var(--line); }
  .open .sheet { transform: none; }
  .sheet .grab { display: none; }
  .sheet.center { left: 50%; top: 50%; bottom: auto; width: 480px; max-height: 88dvh; border-radius: 18px;
    transform: translate(-50%, -46%); opacity: 0; transition: all .18s; border: 0; }
  .open .sheet.center { transform: translate(-50%, -50%); opacity: 1; }

  /* quadro anual */
  .months { display: grid; gap: 22px; }
  .mtable { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
  .mtable h3 { margin: 0; font-size: 15px; padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 650; display: flex; justify-content: space-between; }
  .mtable h3 .muted { font-weight: 450; font-size: 13px; }
  table.grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
  table.grid th { font-size: 12.5px; font-weight: 550; color: var(--muted); text-align: right; padding: 8px 12px; border-bottom: 1px solid var(--line);
    background: var(--surface); cursor: pointer; user-select: none; }
  table.grid th:first-child { text-align: center; width: 52px; cursor: default; }
  table.grid th.col-saldo { width: 150px; cursor: default; }
  table.grid th .h { display: inline-flex; align-items: center; gap: 6px; }
  table.grid th.collapsed { width: 44px; }
  table.grid th.collapsed .h span { display: none; }
  table.grid td { text-align: right; padding: 0 12px; height: 34px; border-top: 1px solid var(--line); font-size: 13.5px; }
  table.grid td:first-child { text-align: center; color: var(--muted); font-weight: 600; font-size: 12.5px; }
  table.grid td.cell { cursor: pointer; }
  table.grid td.cell:hover { background: var(--surface-2); }
  table.grid td.zero { color: var(--faint); }
  table.grid td.fc { color: var(--t-diario); }
  table.grid td.collapsed { font-size: 0; padding: 0; }
  table.grid tr.we td:first-child { background: var(--surface-2); }
  table.grid tr.past td.cell { opacity: 0.72; }
  table.grid tr.today td { border-top: 2px solid var(--text); }
  table.grid tr.today td:first-child { background: var(--text); color: var(--bg); }
  table.grid td.bal { font-weight: 650; }
  table.grid tr.total td { font-weight: 650; background: var(--surface-2); height: 38px; }
  .hz { grid-template-columns: repeat(6, 1fr) !important; }
}
@media (min-width: 900px) and (max-width: 1180px) {
  .hz { grid-template-columns: repeat(4, 1fr) !important; }
}
