/* Layout: casca de app. Barra inferior no celular, trilho lateral no computador. */
:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface2: #eef1f6; --line: #dde2ea;
  --fg: #151b26; --fg2: #566074; --fg3: #8a94a6;
  --accent: #2b59d9; --accent-fg: #ffffff; --accent-soft: #e5ecff;
  --pos: #178a5c; --pos-soft: #e1f4ea; --neg: #c8363f; --neg-soft: #fbe6e7; --warn: #b7791f; --warn-soft: #fbf0d9;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .05);
  --r: 12px; --r-sm: 8px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  --gutter: 16px; --nav-h: 62px; --rail-w: 224px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e131b; --surface: #161d28; --surface2: #1d2634; --line: #2a3445;
    --fg: #e8edf5; --fg2: #a3aec2; --fg3: #6f7b90;
    --accent: #7ea2ff; --accent-fg: #0b1220; --accent-soft: #1d2a4a;
    --pos: #4cc38a; --pos-soft: #14301f; --neg: #ff7a82; --neg-soft: #3a1a1e; --warn: #e6b457; --warn-soft: #34290f;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e131b; --surface: #161d28; --surface2: #1d2634; --line: #2a3445;
  --fg: #e8edf5; --fg2: #a3aec2; --fg3: #6f7b90;
  --accent: #7ea2ff; --accent-fg: #0b1220; --accent-soft: #1d2a4a;
  --pos: #4cc38a; --pos-soft: #14301f; --neg: #ff7a82; --neg-soft: #3a1a1e; --warn: #e6b457; --warn-soft: #34290f;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
.bottom:empty, .rail:empty { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); } .mut { color: var(--fg2); } .mut3 { color: var(--fg3); }

/* Casca */
.shell { min-height: 100vh; }
.rail { display: none; }
.main { padding: 0 max(var(--gutter), env(safe-area-inset-right, 0px)) calc(var(--nav-h) + 24px + env(safe-area-inset-bottom, 0px)) max(var(--gutter), env(safe-area-inset-left, 0px)); max-width: 1080px; margin: 0 auto; }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); display: flex; align-items: center; gap: 10px; padding: 12px 0 10px; }
.topbar h1 { font: 700 19px/1.2 var(--font-num); margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding: 6px max(8px, env(safe-area-inset-left, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)); }
.bottom a, .rail a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; font-weight: 600; color: var(--fg3); text-decoration: none; border-radius: 10px; }
.bottom a svg, .rail a svg { width: 22px; height: 22px; }
.bottom a[aria-current="page"], .rail a[aria-current="page"] { color: var(--accent); }
.fab { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom, 0px)); z-index: 25; display: inline-flex; align-items: center; gap: 6px; padding: 12px 18px; border: 0; border-radius: 999px; background: var(--accent); color: var(--accent-fg); font-weight: 700; box-shadow: 0 6px 20px rgba(30, 60, 160, .35); }
.fab svg { width: 18px; height: 18px; }
@media (min-width: 900px) {
  .bottom { display: none; }
  .shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .rail { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface); }
  .rail .brand { font: 700 17px/1.2 var(--font-num); padding: 4px 10px 18px; }
  .rail .brand small { display: block; font: 500 12px var(--font); color: var(--fg3); margin-top: 2px; }
  .rail a { flex: none; flex-direction: row; gap: 12px; padding: 10px 12px; font-size: 14px; }
  .rail a:hover { background: var(--surface2); }
  .rail a[aria-current="page"] { background: var(--accent-soft); }
  .main { padding: 0 28px 48px; width: 100%; }
  .fab { right: 32px; bottom: 28px; }
}

body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 40; background: var(--bg); }

/* Blocos */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card > .hd { display: flex; align-items: center; gap: 8px; padding: 12px 14px 0; font: 700 13px var(--font); color: var(--fg2); text-transform: uppercase; letter-spacing: .05em; }
.card > .hd .sp { flex: 1; }
.card > .bd { padding: 12px 14px 14px; }
.card.flush > .bd { padding: 6px 0 4px; }
.stack { display: grid; gap: 14px; margin-top: 6px; }
.grid2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
.grid3 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.grid2 > *, .stack > * { min-width: 0; }
.sec { font: 700 12px var(--font); text-transform: uppercase; letter-spacing: .08em; color: var(--fg3); margin: 10px 2px -4px; display: flex; align-items: center; gap: 8px; }
.sec .sp { flex: 1; }
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .l { font-size: 12px; color: var(--fg2); font-weight: 600; }
.kpi .v { font: 700 22px/1.2 var(--font-num); margin-top: 2px; overflow-wrap: anywhere; }
.kpi .s { font-size: 12px; color: var(--fg3); margin-top: 2px; }
.kpis3 { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis3 .kpi { padding: 10px 12px; } .kpis3 .kpi .v { font-size: 17px; }
@media (min-width: 700px) { .kpis3 .kpi .v { font-size: 22px; } }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border-radius: var(--r); font-size: 13px; background: var(--surface2); border: 1px solid var(--line); }
.alert.warn { background: var(--warn-soft); border-color: transparent; } .alert.bad { background: var(--neg-soft); border-color: transparent; } .alert.ok { background: var(--pos-soft); border-color: transparent; }
.alert .grow { flex: 1; min-width: 0; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* Listas */
.row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-width: 0; }
.row + .row { border-top: 1px solid var(--line); }
.row.click { cursor: pointer; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid transparent; }
.row.click:hover { background: var(--surface2); }
.row .main-t { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 12px; color: var(--fg3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font: 600 14px var(--font-num); white-space: nowrap; text-align: right; }
.row.paid .t { text-decoration: line-through; color: var(--fg3); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.day-h { display: flex; justify-content: space-between; padding: 14px 14px 4px; font-size: 12px; font-weight: 700; color: var(--fg2); text-transform: uppercase; letter-spacing: .05em; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface2); color: var(--fg2); white-space: nowrap; }
.chip.ok { background: var(--pos-soft); color: var(--pos); } .chip.bad { background: var(--neg-soft); color: var(--neg); } .chip.warn { background: var(--warn-soft); color: var(--warn); } .chip.acc { background: var(--accent-soft); color: var(--accent); }
.check { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--line); background: none; display: grid; place-items: center; color: transparent; padding: 0; }
.check.on { background: var(--pos); border-color: var(--pos); color: #fff; }
.check svg { width: 14px; height: 14px; }
.empty { padding: 26px 16px; text-align: center; color: var(--fg2); }
.empty b { display: block; color: var(--fg); margin-bottom: 4px; }
.bar { height: 8px; border-radius: 99px; background: var(--surface2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--neg); }

/* Controles */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 13px; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); } .btn.pri:hover { filter: brightness(1.08); color: var(--accent-fg); }
.btn.dng { color: var(--neg); } .btn.dng:hover { border-color: var(--neg); }
.btn.sm { padding: 4px 10px; font-size: 12px; } .btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }
.iconbtn { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.iconbtn svg { width: 17px; height: 17px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: inline-flex; background: var(--surface2); border-radius: 10px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--fg2); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.monthnav { display: flex; align-items: center; gap: 6px; }
.monthnav .lbl { font: 600 14px var(--font-num); min-width: 128px; text-align: center; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--fg2); }
.field input, .field select, .field textarea, .inp { width: 100%; padding: 9px 11px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); min-height: 40px; }
.field input:focus, .field select:focus, .inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form .full { grid-column: 1 / -1; }
.inline { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline .field { flex: 1 1 120px; }
.filters { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 700px) { .filters { grid-template-columns: 2fr repeat(3, 1fr); } }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
.tbl th:first-child, .tbl td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.tbl th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--fg2); }
.tbl tr.cur td { background: var(--accent-soft); }
.scroll-x { overflow-x: auto; max-width: 100%; }
.chart { position: relative; height: 260px; } .chart.tall { height: 320px; }
.seg-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface2); }
.seg-bar > i { display: block; height: 100%; }
.amort-sl { display: flex; align-items: center; gap: 10px; }
.amort-sl input[type=range] { flex: 1; accent-color: var(--accent); }
details.fold { border-top: 1px solid var(--line); }
details.fold > summary { padding: 11px 14px; cursor: pointer; font-weight: 600; color: var(--fg2); list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: '▸ '; } details.fold[open] > summary::before { content: '▾ '; }
.months12 { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); padding: 0 14px 14px; }

/* Modal e avisos */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(8, 12, 20, .55); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px var(--gutter) calc(18px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -8px 40px rgba(0, 0, 0, .3); }
.modal h2 { margin: 0 0 14px; font: 700 18px var(--font-num); }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@media (min-width: 700px) { .overlay { align-items: center; } .modal { border-radius: 16px; padding: 22px; } }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 78px + env(safe-area-inset-bottom, 0px)); z-index: 120; display: grid; gap: 8px; justify-items: center; padding: 0 var(--gutter); pointer-events: none; }
@media (min-width: 900px) { #toasts { bottom: 90px; } }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 460px; padding: 10px 14px; border-radius: 12px; background: var(--fg); color: var(--bg); font-size: 13px; font-weight: 500; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); }
.toast.erro { background: var(--neg); color: #fff; }
.toast button { border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }
.badge-demo { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); font-size: 11px; font-weight: 700; }
.drop { border: 2px dashed var(--line); border-radius: var(--r); padding: 22px; text-align: center; color: var(--fg2); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.hide-mobile { display: none; } @media (min-width: 700px) { .hide-mobile { display: initial; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
