/* Sobra — design system "Régua do mês"
   Fundo sálvia, folhas brancas, tinta quase preta; UMA cor de dado (verde-sobra) só no dinheiro
   que sobra/entra e na seleção. Previsto = tracejado; real = cheio. Ver DESIGN.md.
   Camadas: tokens (fonte única de valores) → base → layout → components → responsive.
   Telas usam os componentes; não redefinem valores fora dos tokens. */

@layer tokens, base, layout, components, responsive;

@font-face {
  font-family: "Funnel Sans";
  src: url("fonts/funnel-sans-latin.woff2") format("woff2");
  font-weight: 300 800; font-style: normal; font-display: swap;
}

@layer tokens {
  :root {
    color-scheme: light;
    --ground: #f3f5f2; --surface: #ffffff; --raised: #eef1ec; --active: #e4e9e2;
    --border: #e0e5de; --rule: #edf0eb; --control: #c7cec4; --control-strong: #868e84;
    --ink: #121512; --muted: #59615a; --faint: #69716a;
    --accent: #0a7a4f; --accent-soft: #dcefe4; --accent-ink: #064a30; --on-accent: #ffffff;
    --negative: #b3261e; --negative-soft: #fbe9e7;
    --warning: #8a4b00; --warning-soft: #fcf1d9; --warning-line: #f0d48f;
    --primary: #121512; --on-primary: #ffffff;
  --seg-dia: color-mix(in srgb, #121512 34%, #ffffff); --seg-guardar: #cfe8da;
    --hatch: repeating-linear-gradient(-45deg, var(--ink) 0 2px, transparent 2px 5px);
    --shadow-float: 0 1px 2px rgb(18 21 18 / .06), 0 12px 32px rgb(18 21 18 / .14);
    --overlay: rgb(18 21 18 / .38);

    --font: "Funnel Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px; --fs-hero: 34px;
    --r-card: 16px; --r-ctl: 12px; --r-in: 10px; --r-chip: 999px;
    --ease-out: cubic-bezier(.23, 1, .32, 1);
    --ease-in-out: cubic-bezier(.77, 0, .175, 1);
    --ease-drawer: cubic-bezier(.32, .72, 0, 1);
    --nav-h: 64px; --gutter: 16px;
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --ground: #0d0f0d; --surface: #151815; --raised: #1d211d; --active: #262b26;
    --border: #252a25; --rule: #1c201c; --control: #3d443c; --control-strong: #6b7369;
    --ink: #f1f4f0; --muted: #b0b8ae; --faint: #959d93;
    --accent: #3fcf8e; --accent-soft: #12321f; --accent-ink: #8de6bb; --on-accent: #06210f;
    --negative: #ff7b70; --negative-soft: #3a1916;
    --warning: #f2bb5c; --warning-soft: #31250e; --warning-line: #5a4417;
    --primary: #f1f4f0; --on-primary: #0d0f0d;
  --seg-dia: #6f776e; --seg-guardar: #24694a;
    --hatch: repeating-linear-gradient(-45deg, var(--ink) 0 2px, transparent 2px 5px);
    --shadow-float: 0 1px 2px rgb(0 0 0 / .4), 0 16px 40px rgb(0 0 0 / .5);
    --overlay: rgb(0 0 0 / .6);
  }
}

@layer base {
  /* ---------- base ---------- */
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body {
    font-family: var(--font); font-size: var(--fs-md); line-height: 1.45; color: var(--ink);
    background: var(--ground); min-height: 100dvh;
    -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
    font-variant-numeric: tabular-nums;
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
  }
  ::selection { background: var(--accent-soft); color: var(--accent-ink); }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { background: none; border: 0; cursor: pointer; }
  a { color: var(--ink); text-underline-offset: 3px; text-decoration-thickness: 1px; }
  b, strong { font-weight: 600; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
  .ic { flex-shrink: 0; display: block; }
  .num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
  .money .cents { font-size: max(.62em, 11px); color: var(--muted); font-weight: 500; letter-spacing: 0; }
  .pos { color: var(--accent); } .neg { color: var(--negative); }
  .muted { color: var(--muted); }
  [hidden] { display: none !important; }

  /* pressionáveis: resposta imediata ao toque (Emil: scale .97, 160ms) */
  .press, button:not(.unpress) { transition: transform 160ms var(--ease-out), background-color 160ms ease, color 160ms ease, opacity 160ms ease; }
  button:not(.unpress):active, .press:active { transform: scale(.97); }
  button:disabled { opacity: .45; cursor: default; transform: none; }
}

@layer layout {
  /* ---------- moldura ---------- */
  .shell { max-width: 560px; margin: 0 auto; padding: 0 var(--gutter); }
  header.top {
    display: flex; align-items: center; gap: 10px;
    padding: max(12px, env(safe-area-inset-top)) var(--gutter) 8px; max-width: 560px; margin: 0 auto;
  }
  .brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 18px; letter-spacing: -.01em; }
  .brand .mark { width: 28px; height: 28px; }
  .monthnav { margin-left: auto; display: flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-chip); padding: 3px; }
  .monthnav b { font-weight: 600; font-size: var(--fs-md); min-width: 92px; text-align: center; }
  .monthnav button, .iconbtn {
    width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--muted);
  }
  .iconbtn { width: 44px; height: 44px; }
  .monthnav button { position: relative; }
  .monthnav button::before { content: ""; position: absolute; inset: -6px; }
  @media (hover: hover) { .monthnav button:hover, .iconbtn:hover { background: var(--raised); color: var(--ink); } }
  main { max-width: 560px; margin: 0 auto; padding: 4px var(--gutter) 0; }
  .view { display: none; } .view.on { display: block; }
}

@layer components {
  /* ---------- títulos e blocos ---------- */
  .sec-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 28px 2px 10px; }
  .sec-h h2 { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -.005em; }
  .sec-h .aside { font-size: var(--fs-sm); color: var(--muted); }
  .sec-h .aside b { color: var(--ink); }
  .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); }
  .panel.pad { padding: 18px; }
  .hint { font-size: var(--fs-sm); color: var(--muted); line-height: 1.5; }
  .hint b { color: var(--ink); }
  .notice {
    font-size: var(--fs-sm); line-height: 1.5; color: var(--warning); background: var(--warning-soft);
    border: 1px solid var(--warning-line); border-radius: var(--r-in); padding: 10px 12px;
  }
  .lede { font-size: var(--fs-md); color: var(--muted); margin: 2px 2px 14px; line-height: 1.5; }

  /* ---------- lançamento rápido ---------- */
  .quick { display: flex; gap: 8px; margin-top: 6px; }
  .quick-in {
    flex: 1; min-width: 0; height: 52px; border-radius: var(--r-ctl); border: 1px solid var(--control-strong);
    background: var(--surface); padding: 0 14px 0 42px; font-size: 16px; outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
  }
  .quick-wrap { position: relative; flex: 1; min-width: 0; display: flex; }
  .quick-wrap .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
  .quick-in::placeholder { color: var(--faint); }
  .quick-in:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); }
  .quick-wrap.com-mic .quick-in { padding-right: 52px; }
  .mic {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px;
    border-radius: var(--r-field); color: var(--muted); display: grid; place-items: center;
    transition: background-color 160ms ease, color 160ms ease;
  }
  .mic:active { transform: translateY(-50%) scale(.97); }
  @media (hover: hover) { .mic:hover { background: var(--raised); color: var(--ink); } }
  .mic.ouvindo { background: var(--accent-soft); color: var(--accent-ink); }
  .mic.ouvindo::after {
    content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 0 0 0 var(--accent);
    animation: ouvindo 1.4s var(--ease-out) infinite;
  }
  @keyframes ouvindo { from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); } to { box-shadow: 0 0 0 10px transparent; } }
  .quick-wrap.ouvindo .quick-in { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .btn-primary {
    height: 52px; padding: 0 20px; border-radius: var(--r-ctl); background: var(--primary); color: var(--on-primary);
    font-weight: 600; font-size: var(--fs-lg); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  }
  @media (hover: hover) { .btn-primary:hover { opacity: .9; } }
  .preview {
    display: none; gap: 6px; flex-wrap: wrap; align-items: center; margin: 10px 2px 0;
    font-size: var(--fs-sm); color: var(--muted);
  }
  .preview.on { display: flex; }
  .tag {
    display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px;
    border-radius: var(--r-chip); background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  }
  .tag .ic { color: var(--muted); }
  .tag.tipo-receita { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
  .busca { position: relative; margin: 2px 0 10px; }
  .busca .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
  .busca input { width: 100%; height: 44px; border-radius: var(--r-ctl); border: 1px solid var(--control); background: var(--surface); padding: 0 14px 0 40px; font-size: 16px; outline: none; }
  .busca input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); }
  .escopo { margin: 0 4px 8px; }
  .renda-f { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
  .renda-f #rendaValor { flex: 1 1 140px; min-width: 0; }
  .renda-f #rendaDia { width: 64px; }
  .renda-f .hint { margin: 0; }
  .tag-btn { cursor: pointer; font: inherit; gap: 6px; transition: background-color 160ms ease, transform 160ms var(--ease-out); }
  .tag-btn .ic:last-child { color: var(--faint); margin-left: -2px; }
  @media (hover: hover) { .tag-btn:hover { background: var(--raised); } }
  .tag-btn:active { transform: scale(.97); }
  .tag.tipo-neutro { background: var(--raised); border-color: transparent; color: var(--muted); }
  .quick-hint { margin: 10px 2px 0; }

  /* ---------- a régua do mês (assinatura) ---------- */
  .regua { padding: 20px 18px 16px; margin-top: 16px; }
  .regua .lbl { font-size: var(--fs-md); color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
  .regua .val { font-size: var(--fs-hero); font-weight: 600; letter-spacing: -.025em; line-height: 1.1; margin: 4px 0 2px; }
  .regua .val.neg { color: var(--negative); }
  .regua .val.pos { color: var(--accent); }
  .regua .base { font-size: var(--fs-sm); color: var(--muted); }
  .barra {
    display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 16px 0 14px; gap: 2px;
    background: var(--raised);
  }
  .barra { position: relative; }
  .barra i { display: block; height: 100%; min-width: 3px; transition: flex-grow 320ms var(--ease-out); }
  .barra.sem-anim i { transition: none; }
  .barra .limite { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: var(--surface); }
  .regua .fim-renda { font-size: var(--fs-xs); color: var(--muted); margin: -8px 0 12px; }
  .seg-saiu { background: var(--ink); }
  .seg-vai { background: var(--hatch), var(--raised); }
  .seg-dia { background: var(--seg-dia); }
  .seg-guardar { background: var(--seg-guardar); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent); }
  .seg-sobra { background: var(--accent); }
  .seg-falta { background: var(--negative); }
  .legenda { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 10px 16px; }
  .legenda .it { display: grid; grid-template-columns: 12px 1fr; column-gap: 8px; row-gap: 1px; align-items: center; min-width: 0; }
  .legenda .sw { width: 12px; height: 12px; border-radius: 3px; }
  .legenda .n { font-size: var(--fs-sm); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .legenda .v { grid-column: 2; font-size: 15px; font-weight: 500; }
  .legenda .it.destaque .n { color: var(--ink); font-weight: 500; }
  .legenda .it.destaque .v { color: var(--accent); font-weight: 600; }
  .legenda .it.falta .v { color: var(--negative); font-weight: 600; }
  .regua .rodape { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 8px; }

  /* ---------- listas de linhas ---------- */
  .rows { padding: 2px 0; }
  .row {
    display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 16px;
    border-top: 1px solid var(--rule); width: 100%; text-align: left; position: relative;
  }
  .rows > .row:first-child { border-top: 0; }
  button.row, .row.tap { cursor: pointer; }
  @media (hover: hover) { button.row:hover, .row.tap:hover { background: color-mix(in srgb, var(--raised) 60%, transparent); } }
  .row .ico {
    width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
    background: var(--raised); color: var(--ink);
  }
  .row .main { flex: 1; min-width: 0; display: block; }
  .row .t, .row .s { display: block; }
  .row .t { font-size: var(--fs-lg); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.005em; }
  .row .s { font-size: var(--fs-sm); color: var(--muted); margin-top: 1px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
  .row .s .pill { margin-right: 4px; }
  .row .amt { font-size: var(--fs-lg); font-weight: 500; white-space: nowrap; text-align: right; }
  .row .amt.pos { color: var(--accent); }
  .row .amt.estorno { color: var(--accent); }
  .row .amt.neutro { color: var(--muted); font-weight: 400; } /* entre contas / investimento: só muda de lugar */
  .row .amt small { display: block; font-size: var(--fs-xs); color: var(--muted); font-weight: 400; }
  .row.previsto .ico { background: transparent; border: 1.5px dashed var(--control); color: var(--muted); }
  .row.previsto .amt { color: var(--muted); }
  .check {
    width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
    border: 1.5px solid var(--control-strong); color: var(--muted); margin-right: -6px;
  }
  @media (hover: hover) { .check:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); } }
  .row .bar { position: absolute; left: 64px; right: 16px; bottom: 8px; }
  .meter { display: block; height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }
  .row .bar { display: block; }
  .meter i { display: block; height: 100%; border-radius: 2px; background: color-mix(in srgb, var(--ink) 62%, var(--surface)); transition: width 320ms var(--ease-out); }
  .meter.fatia { height: 3px; }
  .meter.fatia i { background: var(--control); }
  .meter i.ok { background: var(--accent); } .meter i.warn { background: var(--warning); } .meter i.over { background: var(--negative); }
  .meter .limite { position: absolute; }
  .pill {
    display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: var(--r-chip);
    font-size: 11.5px; font-weight: 500; background: var(--raised); color: var(--muted); vertical-align: 1px;
  }
  .pill.pos { background: var(--accent-soft); color: var(--accent-ink); }
  .pill.neg { background: var(--negative-soft); color: var(--negative); }
  .pill.warn { background: var(--warning-soft); color: var(--warning); }
  .more { display: flex; justify-content: center; padding: 12px; font-size: var(--fs-md); font-weight: 500; color: var(--muted); border-top: 1px solid var(--rule); width: 100%; }

  /* extrato */
  .filters { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 6px -2px 4px; padding: 2px; }
  .filters::-webkit-scrollbar { display: none; }
  .chip {
    height: 40px; padding: 0 16px; border-radius: var(--r-chip); border: 1px solid var(--border); position: relative;
    background: var(--surface); color: var(--muted); font-size: var(--fs-md); font-weight: 500; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 6px;
  }
  .chip::before { content: ""; position: absolute; inset: -2px 0; }
  .chip.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
  .day-h { display: flex; justify-content: space-between; align-items: baseline; margin: 20px 4px 8px; font-size: var(--fs-sm); color: var(--muted); }
  .extrato .dia {
    position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: baseline;
    padding: 10px 16px 8px; font-size: var(--fs-sm); color: var(--muted); background: var(--surface);
    border-top: 1px solid var(--rule);
  }
  .extrato .dia:first-child { border-top: 0; border-radius: var(--r-card) var(--r-card) 0 0; }
  .extrato .dia b { color: var(--ink); font-weight: 600; }
  .extrato .row { border-top: 0; }
  .resumo { display: flex; gap: 20px; margin: 10px 4px 12px; font-size: var(--fs-sm); color: var(--muted); }
  .resumo-nota { margin: -6px 4px 12px; }
  .resumo b { display: block; font-size: var(--fs-lg); font-weight: 600; color: var(--ink); }
  .resumo .pos b { color: var(--accent); }
  .day-h b { color: var(--ink); font-weight: 600; font-size: var(--fs-md); }
  .day-h .tot { font-weight: 500; }

  /* caixinhas */
  .box { padding: 16px; margin-bottom: 12px; }
  .box .hd { display: flex; align-items: center; gap: 12px; cursor: pointer; }
  .box .hd .ico { width: 40px; height: 40px; border-radius: 12px; background: var(--raised); display: grid; place-items: center; }
  .box .nm { font-size: var(--fs-lg); font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .box .meta-t { font-size: var(--fs-sm); color: var(--muted); }
  .box .saldo { font-size: 20px; font-weight: 600; letter-spacing: -.015em; margin: 12px 0 2px; }
  .box .meter { height: 8px; border-radius: 4px; margin: 12px 0 8px; }
  .box .meter i { background: var(--accent); }
  .box .plan { font-size: var(--fs-sm); color: var(--muted); margin-top: 6px; }
  .box .acts { display: flex; gap: 8px; margin-top: 14px; }
  .btn {
    height: 44px; padding: 0 16px; border-radius: var(--r-ctl); font-weight: 600; font-size: var(--fs-md);
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--raised); color: var(--ink);
  }
  .btn.grow { flex: 1; }
  .btn.solid { background: var(--primary); color: var(--on-primary); }
  .btn.line { background: transparent; border: 1px solid var(--control-strong); }
  .btn.green { background: var(--accent-soft); color: var(--accent-ink); }
  .btn.danger { background: transparent; color: var(--negative); }
  @media (hover: hover) { .btn:hover { background: var(--active); } .btn.solid:hover { opacity: .9; background: var(--primary); } .btn.line:hover, .btn.danger:hover { background: var(--raised); } .btn.green:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent)); } }
  .addbtn {
    width: 100%; height: 52px; border: 1.5px dashed var(--control); border-radius: var(--r-card); margin-top: 12px;
    color: var(--muted); font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px;
  }
  @media (hover: hover) { .addbtn:hover { border-color: var(--ink); color: var(--ink); } }

  /* resumo de totais (caixinhas, contas) */
  .total-line { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 2px 12px; }
  .total-line .t { color: var(--muted); }
  .total-line .v { font-size: 26px; font-weight: 600; letter-spacing: -.02em; }

  /* vazio */
  .empty { border: 1px dashed var(--control); border-radius: var(--r-card); padding: 22px 18px; color: var(--muted); font-size: var(--fs-md); line-height: 1.55; }
  .empty b { color: var(--ink); }
  .empty .t { color: var(--ink); font-weight: 600; font-size: var(--fs-lg); margin-bottom: 4px; }
  .empty .ex { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
  .empty .ex button { height: 32px; padding: 0 12px; border-radius: var(--r-chip); background: var(--surface); border: 1px solid var(--border); color: var(--ink); font-size: var(--fs-sm); }

  /* ajustes */
  .set .row .ico { background: transparent; color: var(--muted); width: 28px; }
  .set .row .chev { color: var(--faint); }
  .set .row.danger .t { color: var(--negative); }
  .badge-beta { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--border); border-radius: var(--r-chip); padding: 1px 7px; margin-left: 6px; vertical-align: 2px; }

  /* ---------- complementos de componentes ---------- */
  .row[aria-disabled="true"] { opacity: .55; cursor: default; }
  .row.com-barra { padding-bottom: 20px; }
  .row .s.wrap { white-space: normal; }
  .row .iconbtn { width: 40px; height: 40px; color: var(--faint); margin-right: -8px; }
  @media (hover: hover) { .row .iconbtn:hover { color: var(--negative); background: var(--negative-soft); } }
  .row .amt small { margin-top: 1px; }
  .row .s a { color: var(--muted); }
  .warn-t { color: var(--warning); }
  .row.passo { align-items: flex-start; padding-top: 14px; padding-bottom: 14px; }
  .row.passo .ico { background: transparent; border: 1.5px dashed var(--control); color: var(--faint); }
  .row.passo.feito .ico { border: 0; background: var(--accent-soft); color: var(--accent-ink); }
  .row.passo.feito .t { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--control); }
  .row.passo .ex { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
  .row.passo .ex button {
    height: 34px; padding: 0 12px; border-radius: var(--r-chip); border: 1px solid var(--border);
    background: var(--ground); font-size: var(--fs-sm); font-weight: 500; color: var(--ink);
  }
  @media (hover: hover) { .row.passo .ex button:hover { border-color: var(--ink); } }

  /* a conta por extenso da régua */
  details.conta summary {
    cursor: pointer; font-size: var(--fs-sm); font-weight: 500; color: var(--ink); list-style: none;
    display: inline-flex; align-items: center; gap: 6px; min-height: 32px;
  }
  details.conta summary::-webkit-details-marker { display: none; }
  details.conta summary::after { content: ""; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform 200ms var(--ease-out); }
  details.conta[open] summary::after { transform: rotate(225deg) translate(-2px, 0); }
  details.conta ul { list-style: none; margin-top: 8px; font-size: var(--fs-sm); }
  details.conta li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; color: var(--muted); }
  details.conta li em { font-style: normal; color: var(--faint); }
  details.conta li.sub { padding-top: 0; font-size: var(--fs-xs); color: var(--faint); }
  details.conta li.res { border-top: 1px solid var(--rule); margin-top: 4px; padding-top: 8px; color: var(--ink); font-weight: 600; font-size: var(--fs-md); }

  /* aviso flutuante com ação */
  .toast { display: flex; align-items: center; gap: 14px; }
  .toast .tmsg { display: flex; align-items: center; gap: 8px; }
  .toast .tmsg .ic { color: var(--accent); }
  :root[data-theme="dark"] .toast .tmsg .ic { color: #0a7a4f; }
  .toast.show.acao { pointer-events: auto; }
  .toast .tacao { color: var(--on-primary); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; padding: 6px 2px; margin: -6px 0; }

  /* sugestão de guardar a sobra */
  .sugestao { margin-bottom: 12px; }
  .sugestao .sug-t { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: var(--fs-lg); margin-bottom: 4px; }
  .sugestao .sug-t .ic { color: var(--accent); }
  .sugestao .hint { margin-bottom: 14px; }
  .sugestao .btn { width: 100%; }

  /* passos de conexão do banco */
  ol.passos { padding-left: 20px; margin: 4px 0 16px; font-size: var(--fs-md); color: var(--muted); line-height: 1.55; }
  ol.passos li { margin-bottom: 6px; } ol.passos b { color: var(--ink); }
  .sheet a { color: var(--ink); }
  .hint.storage { margin: 16px 4px 0; }
  .auth-card .btn-primary { width: 100%; margin-top: 4px; }
  .auth-card .seg { margin-bottom: 16px; }
  @media (max-width: 379px) { .lbl-lancar { display: none; } .btn-primary { padding: 0 16px; } }

  /* páginas de texto (política de privacidade) */
  body.doc { max-width: 680px; margin: 0 auto; padding: max(32px, env(safe-area-inset-top)) 20px 64px; }
  .doc .voltar { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 24px; font-size: var(--fs-md); color: var(--muted); text-decoration: none; }
  .doc .voltar::before { content: ""; width: 7px; height: 7px; border-left: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); }
  .doc h1 { font-size: 28px; font-weight: 600; letter-spacing: -.02em; margin-bottom: 6px; }
  .doc .sub { color: var(--muted); font-size: var(--fs-sm); margin-bottom: 28px; }
  .doc h2 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.01em; margin: 32px 0 10px; }
  .doc p, .doc li { font-size: 15px; line-height: 1.65; color: var(--ink); margin: 0 0 10px; max-width: 68ch; }
  .doc ul { padding-left: 20px; margin: 0 0 12px; }

  /* ---------- navegação ---------- */
  nav.bottom {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(6, 1fr);
  }
  nav.bottom button {
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0 4px;
    font-size: 10.5px; letter-spacing: -.01em; font-weight: 500; color: var(--faint); border-radius: 12px; min-height: 52px; padding-inline: 1px; white-space: nowrap;
  }
  nav.bottom button.on { color: var(--ink); }
  nav.bottom button.on .ic { stroke-width: 2.25; }

  /* ---------- folhas (bottom sheets) ---------- */
  .overlay {
    position: fixed; inset: 0; z-index: 100; background: var(--overlay);
    display: none; align-items: flex-end; justify-content: center;
    opacity: 0; transition: opacity 200ms ease, display 300ms allow-discrete, overlay 300ms allow-discrete;
  }
  .overlay.show { display: flex; opacity: 1; }
  @starting-style { .overlay.show { opacity: 0; } }
  .sheet {
    background: var(--surface); width: 100%; max-width: 560px; max-height: 90dvh; overflow-y: auto;
    border-radius: 22px 22px 0 0; padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
    transform: translateY(0); transition: transform 300ms var(--ease-drawer);
    overscroll-behavior: contain;
  }
  .overlay:not(.show) .sheet { transform: translateY(100%); transition-duration: 200ms; }
  @starting-style { .overlay.show .sheet { transform: translateY(100%); } }
  .sheet::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--control); margin: 0 auto 14px; }
  .sheet h3 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.01em; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
  .sheet .hint { margin-bottom: 12px; }
  .f { margin-bottom: 14px; }
  .f > label { display: block; font-size: var(--fs-sm); color: var(--muted); font-weight: 500; margin-bottom: 6px; }
  .f input:not([type=checkbox]), .f select, .f textarea, .in {
    width: 100%; height: 48px; border-radius: var(--r-in); border: 1px solid var(--control-strong);
    background: var(--surface); padding: 0 14px; font-size: 16px; outline: none; color: var(--ink);
    transition: border-color 160ms ease, box-shadow 160ms ease;
  }
  .f textarea { height: auto; padding: 12px 14px; line-height: 1.4; }
  .f input:focus, .f select:focus, .f textarea:focus, .in:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); }
  .f input::placeholder, .f textarea::placeholder { color: var(--faint); }
  .frow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .toggle { display: flex; align-items: flex-start; gap: 10px; font-size: var(--fs-md); color: var(--ink); cursor: pointer; padding: 4px 0; line-height: 1.4; }
  .toggle input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; margin-top: 1px; }
  .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--raised); border-radius: var(--r-ctl); padding: 3px; gap: 3px; }
  .seg button { height: 44px; border-radius: 9px; font-weight: 600; color: var(--muted); }
  .seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08), 0 0 0 1px var(--border); }
  .seg button.on.rec { color: var(--accent); }
  .actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
  .actions .primary { flex: 1; height: 50px; border-radius: var(--r-ctl); background: var(--primary); color: var(--on-primary); font-weight: 600; font-size: var(--fs-lg); }
  .actions .ghost { height: 50px; padding: 0 18px; border-radius: var(--r-ctl); background: var(--raised); font-weight: 600; }
  .actions .danger { height: 50px; padding: 0 14px; color: var(--negative); font-weight: 600; }
  @media (hover: hover) { .actions .ghost:hover { background: var(--active); } .actions .danger:hover { background: var(--negative-soft); border-radius: var(--r-ctl); } }
  .acoes-dlg { flex-direction: row-reverse; } /* OK vem primeiro no HTML (Enter confirma); Cancelar fica à esquerda */
  .link-btn { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; padding: 4px 2px; }
  .actions .danger-solid { flex: 1; height: 50px; border-radius: var(--r-ctl); background: var(--negative); color: #fff; font-weight: 600; font-size: var(--fs-lg); }

  /* ---------- diálogos do app (dialogo.js): <dialog> com o visual das folhas ---------- */
  dialog.dlg {
    border: 0; padding: 22px 20px calc(18px + env(safe-area-inset-bottom)); margin: auto auto 0; width: 100%; max-width: 480px;
    max-height: 90dvh; overflow-y: auto; background: var(--surface); color: var(--ink);
    border-radius: 22px 22px 0 0; box-shadow: 0 -8px 40px rgb(0 0 0 / .18);
    transition: transform 260ms var(--ease-drawer), opacity 200ms ease, display 260ms allow-discrete, overlay 260ms allow-discrete;
  }
  dialog.dlg[open] { transform: translateY(0); opacity: 1; }
  @starting-style { dialog.dlg[open] { transform: translateY(40px); opacity: 0; } }
  dialog.dlg::backdrop { background: var(--overlay); }
  dialog.dlg h3 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.01em; margin-bottom: 12px; }
  dialog.dlg .hint { margin-bottom: 10px; line-height: 1.5; }
  .dlg-opcoes { border: 0; padding: 0; margin: 4px 0 0; display: grid; gap: 6px; }
  .dlg-op { border: 1px solid var(--border); border-radius: var(--r-ctl); padding: 10px 12px; display: flex; gap: 12px; align-items: center; }
  .dlg-op input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
  .dlg-op:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
  .ficha { display: grid; gap: 2px; margin: 4px 0 12px; }
  .ficha-l { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); font-size: var(--fs-md); }
  .ficha-l span { color: var(--muted); }
  .ficha-l b { font-weight: 600; text-align: right; }
  .erro-campo { color: var(--negative); font-size: var(--fs-sm); margin-top: 6px; min-height: 1em; }
  input[aria-invalid="true"] { border-color: var(--negative) !important; }
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .helpbody h4 { font-size: var(--fs-lg); font-weight: 600; margin: 18px 0 6px; display: flex; align-items: center; gap: 8px; }
  .helpbody p, .helpbody li { font-size: var(--fs-md); line-height: 1.55; color: var(--muted); }
  .helpbody b { color: var(--ink); }
  .helpbody ul { padding-left: 18px; }
  .helpbody .kw { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--rule); font-size: var(--fs-sm); color: var(--muted); }
  .helpbody .kw .ic { color: var(--ink); margin-top: 1px; }
  .helpbody .kw b { display: block; color: var(--ink); font-size: var(--fs-md); }

  /* ---------- toast ---------- */
  .toast {
    position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 200;
    transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
    max-width: calc(100% - 32px); width: max-content;
    background: var(--primary); color: var(--on-primary); border-radius: var(--r-ctl);
    padding: 12px 16px; font-size: var(--fs-md); font-weight: 500; box-shadow: var(--shadow-float);
    transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
  }
  .toast.show { opacity: 1; transform: translate(-50%, 0); transition-duration: 260ms; }

  /* ---------- telas de entrada e carregamento ---------- */
  .screen { position: fixed; inset: 0; z-index: 90; background: var(--ground); overflow-y: auto; }
  .screen .wrap { max-width: 420px; margin: 0 auto; padding: max(48px, env(safe-area-inset-top)) 20px 40px; }
  .auth-brand { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 650; letter-spacing: -.015em; }
  .auth-brand .mark { width: 40px; height: 40px; }
  .auth-lede { font-size: var(--fs-xl); line-height: 1.35; margin: 28px 0 8px; font-weight: 500; letter-spacing: -.01em; }
  .auth-lede span { color: var(--accent); }
  .auth-sub { color: var(--muted); margin-bottom: 24px; }
  .auth-demo { margin: 4px 0 24px; }
  .auth-demo .barra { margin: 10px 0 0; height: 10px; }
  .auth-card { padding: 18px; }
  .auth-card .btn-primary { width: 100%; }
  .linkbtn { width: 100%; padding: 12px; color: var(--muted); font-size: var(--fs-md); text-decoration: underline; text-underline-offset: 3px; }
  .load { position: fixed; inset: 0; z-index: 80; background: var(--ground); display: none; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--muted); }
  .load .mark { width: 48px; height: 48px; }
  .load .barra { width: 160px; height: 6px; margin: 0; }
  .load .barra i { animation: carregando 1.1s var(--ease-in-out) infinite alternate; background: var(--ink); flex: none; width: 40%; }
  @keyframes carregando { from { transform: translateX(-10%); } to { transform: translateX(160%); } }
  #syncBar { display: none; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--muted); margin: 12px 2px 0; }
  #syncBar .sp { width: 14px; height: 14px; border: 2px solid var(--control); border-top-color: var(--ink); border-radius: 50%; animation: gira .7s linear infinite; }
  @keyframes gira { to { transform: rotate(360deg); } }
}

@layer responsive {
  /* ---------- desktop ---------- */
  /* celular: seções de detalhe dobráveis (app.js: aplicarDobras); só o primeiro cabeçalho (.sec-dobra) dobra */
  .inv-todos { display: block; margin: 10px 2px 0; }
  .dobravel > .sec-dobra { cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .dobra-btn { all: unset; cursor: pointer; border-radius: 6px; }
  .dobra-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
  .dobra-btn::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-3px) rotate(45deg); transition: transform 160ms var(--ease-out); }
  .dobravel.fechada .dobra-btn::after { transform: translateY(-1px) rotate(-45deg); }
  .dobravel.fechada > :not(.sec-dobra) { display: none !important; }
  .dobravel.fechada > .sec-dobra { margin: 0; padding: 16px 2px; border-bottom: 1px solid var(--rule); }
  @media (prefers-reduced-motion: reduce) { .dobra-btn::after { transition: none; } }

  @media (min-width: 900px) {
    body:not(.doc):not(.ds) { padding: 0 40px 48px 272px; }
    header.top, main { max-width: 1080px; margin: 0; padding-left: 0; padding-right: 0; }
    header.top { padding-top: 28px; padding-bottom: 12px; }
    header.top .brand { display: none; }
    .monthnav { margin-left: 0; }
    #v-extrato, #v-env, #v-rec, #v-set { max-width: 760px; }
  .view-title, #v-home .view-title { display: block !important; font-size: 24px; margin: 4px 2px 16px; }
    nav.bottom {
      left: 0; top: 0; bottom: 0; right: auto; width: 232px; background: var(--ground);
      border-top: 0; border-right: 1px solid var(--border);
      display: flex; flex-direction: column; gap: 2px; padding: 24px 12px;
    }
    nav.bottom .navbrand { display: flex !important; margin: 0 10px 22px; }
    nav.bottom button { flex-direction: row; gap: 12px; padding: 0 12px; min-height: 40px; font-size: var(--fs-md); border-radius: 10px; color: var(--muted); }
    nav.bottom button.on { background: var(--active); color: var(--ink); font-weight: 600; }
    @media (hover: hover) { nav.bottom button:not(.on):hover { background: var(--raised); color: var(--ink); } }
    #v-home.on { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 0 28px; align-items: start; }
    #v-home .col-a, #v-home .col-b { min-width: 0; }
    dialog.dlg { margin: auto; border-radius: 22px; }
    .overlay { align-items: center; }
    .sheet { max-width: 480px; border-radius: 22px; padding-bottom: 22px; transform: scale(1); opacity: 1; transition: transform 200ms var(--ease-out), opacity 200ms var(--ease-out); }
    .sheet::before { display: none; }
    .overlay:not(.show) .sheet { transform: scale(.97); opacity: 0; }
    @starting-style { .overlay.show .sheet { transform: scale(.97); opacity: 0; } }
    .toast { bottom: 32px; }
    #boxList { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } #boxList .box { margin: 0; } #boxList .empty { grid-column: 1 / -1; }
  }
  .navbrand { display: none; }
  .view-title { font-size: 20px; font-weight: 600; letter-spacing: -.012em; margin: 10px 2px 6px; }
  #v-home .view-title { display: none; }
  body[data-view="set"] .monthnav { visibility: hidden; }

  /* ---------- movimento reduzido ---------- */
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
    button:active, .press:active { transform: none !important; }
  }
}
/* investimentos: Detalhado | Classes | Instituições */
.inv-visoes { margin: 0 0 6px; }
.inv-resumo { margin: 0 0 10px; }
/* conferência: aviso tocável (mesma cara do .notice) */
button.notice.conferir { display: flex; gap: 8px; align-items: flex-start; width: 100%; text-align: left; cursor: pointer; margin: 0 0 12px; font: inherit; }
/* patrimônio: total e minigráfico dos últimos meses (barras neutras; o mês atual em tinta) */
.pat { margin-bottom: 10px; }
.pat-total { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.pat-barras { display: flex; align-items: flex-end; gap: 4px; height: 56px; margin-top: 12px; }
.pat-b { flex: 1; border-radius: 3px 3px 0 0; background: var(--raised); min-height: 3px; }
.pat-b.atual { background: color-mix(in srgb, var(--ink) 62%, var(--surface)); }
.pat-meses { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted, inherit); opacity: .75; margin-top: 4px; }
.pat-b.vazio { background: none; border-bottom: 1px dashed var(--raised); }
/* fechamento do mês */
.fechamento { margin-bottom: 12px; }
.fech-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.fech-h h2 { margin: 0; font-size: 16px; }
.fech-n { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 4px; }
.fech-n span { display: flex; flex-direction: column; font-size: 13px; opacity: .85; }
.fech-n b { font-size: 17px; opacity: 1; }
/* recorrente com valor desatualizado */
.rec-sug { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.rec-sug-acoes { display: flex; gap: 12px; align-items: center; }
.assin { margin-bottom: 14px; }
.assin-tit { margin: 0 0 4px; }
.assin .hint { margin: 0 0 10px; }
.assin-subiu { color: var(--warning); font-size: var(--fs-sm); }
/* categorizar em lote: nome do grupo e a categoria escolhida lado a lado (empilha no celular) */
.cat-lote { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.cat-lote .main { flex: 1 1 180px; }
.cat-lote select { flex: 0 1 200px; min-height: 44px; font-size: 16px; }
