/* Palette inherited from the original spreadsheet dashboard. */
:root {
  --navy: #0b2f4a;
  --navy-2: #1f4e79;
  --green: #356854;
  --indigo: #535fc1;
  --bg: #f6f8f9;
  --surface: #ffffff;
  --line: #e3e8ec;
  --text: #1f1f1f;
  --muted: #66727c;
  --income: #2e7d32;
  --expense: #c62828;
  --balance: #1565c0;
  --orange: #fb8c00;
  --card: #8e24aa;
  --limit: #d81b60;
  --fixed: #1e88e5;
  --other: #fb8c00;
  --forecast: #78909c;
  --ok-bg: #c6efce;
  --ok-fg: #1e6b34;
  --warn-bg: #ffc7ce;
  --warn-fg: #9c0006;
  --blue-soft: #e8f1fb;
  /* semantic tokens: the dark theme redefines these */
  --heading: var(--navy);
  --link: var(--navy-2);
  --chrome: var(--navy);
  --accent: var(--navy);
  --primary: var(--navy);
  --primary-hover: var(--navy-2);
  --input-bg: #ffffff;
  --input-line: #cfd8df;
  --hover-bg: #fbfcfd;
  --hover-line: #c7d1d9;
  --soft: #eef1f4;
  --tabs-bg: #e9eef2;
  --tab-on: #ffffff;
  --zebra: #fafbfc;
  --tfoot: #f3f6f8;
  --pop-bg: #ffffff;
  --cash-tint: #f3f9f5;
  --tag-fg: var(--navy-2);
  --chart-grid: #e3e8ec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 47, 74, .06), 0 4px 16px rgba(11, 47, 74, .05);
}

/* ---------- dark theme: follows the system unless the user picked one ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1418;
  --surface: #171e24;
  --line: #2a343d;
  --text: #e3e8ec;
  --muted: #9aa7b2;
  --income: #66bb6a;
  --expense: #ef6461;
  --balance: #64b5f6;
  --card: #ba68c8;
  --limit: #f06292;
  --fixed: #42a5f5;
  --other: #ffa726;
  --ok-bg: #1d3a28;
  --ok-fg: #a5dcb4;
  --warn-bg: #46232a;
  --warn-fg: #ff9ea8;
  --blue-soft: #1d3247;
  --heading: #dce8f3;
  --link: #8cbbea;
  --chrome: #0b2233;
  --accent: #4f8cc9;
  --primary: #2f6ea5;
  --primary-hover: #3b80bd;
  --input-bg: #10161b;
  --input-line: #36424c;
  --hover-bg: #1e2830;
  --hover-line: #3e4b56;
  --soft: #242e37;
  --tabs-bg: #1c252d;
  --tab-on: #2b3641;
  --zebra: #1a2128;
  --tfoot: #1d252c;
  --pop-bg: #1d252c;
  --cash-tint: #16271e;
  --tag-fg: #a3c9ee;
  --chart-grid: #2a343d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0f1418;
    --surface: #171e24;
    --line: #2a343d;
    --text: #e3e8ec;
    --muted: #9aa7b2;
    --income: #66bb6a;
    --expense: #ef6461;
    --balance: #64b5f6;
    --card: #ba68c8;
    --limit: #f06292;
    --fixed: #42a5f5;
    --other: #ffa726;
    --ok-bg: #1d3a28;
    --ok-fg: #a5dcb4;
    --warn-bg: #46232a;
    --warn-fg: #ff9ea8;
    --blue-soft: #1d3247;
    --heading: #dce8f3;
    --link: #8cbbea;
    --chrome: #0b2233;
    --accent: #4f8cc9;
    --primary: #2f6ea5;
    --primary-hover: #3b80bd;
    --input-bg: #10161b;
    --input-line: #36424c;
    --hover-bg: #1e2830;
    --hover-line: #3e4b56;
    --soft: #242e37;
    --tabs-bg: #1c252d;
    --tab-on: #2b3641;
    --zebra: #1a2128;
    --tfoot: #1d252c;
    --pop-bg: #1d252c;
    --cash-tint: #16271e;
    --tag-fg: #a3c9ee;
    --chart-grid: #2a343d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="light"] { color-scheme: light; }

/* ---------- extra themes (palettes after popular terminal color schemes); list in theme.js ---------- */
:root[data-theme="rosa"] { /* Rosa claro */
  color-scheme: light;
  --bg: #fdf4f7;
  --surface: #ffffff;
  --line: #f3d9e3;
  --text: #2b1a22;
  --muted: #8a6474;
  --income: #2e7d32;
  --expense: #c62828;
  --balance: #d81b60;
  --card: #8e24aa;
  --limit: #5e35b1;
  --fixed: #1e88e5;
  --other: #fb8c00;
  --ok-bg: #d7f2dc;
  --ok-fg: #1e6b34;
  --warn-bg: #ffd6dd;
  --warn-fg: #9c0006;
  --blue-soft: #fde4ee;
  --heading: #880e4f;
  --link: #ad1457;
  --chrome: #880e4f;
  --accent: #c2185b;
  --primary: #c2185b;
  --primary-hover: #ad1457;
  --input-bg: #ffffff;
  --input-line: #ecc5d4;
  --hover-bg: #fff8fb;
  --hover-line: #e6b3c7;
  --soft: #fbe9f0;
  --tabs-bg: #f8e1ea;
  --tab-on: #ffffff;
  --zebra: #fffafc;
  --tfoot: #fcf0f5;
  --pop-bg: #ffffff;
  --cash-tint: #f6faf6;
  --tag-fg: #ad1457;
  --chart-grid: #f3d9e3;
  --shadow: 0 1px 2px rgba(136, 14, 79, .06), 0 4px 16px rgba(136, 14, 79, .06);
}
:root[data-theme="rose-pine"] { /* Rosé Pine (rosa escuro) */
  color-scheme: dark;
  --bg: #191724;
  --surface: #1f1d2e;
  --line: #312e47;
  --text: #e0def4;
  --muted: #908caa;
  --income: #9ccfd8;
  --expense: #eb6f92;
  --balance: #ebbcba;
  --card: #c4a7e7;
  --limit: #f6c177;
  --fixed: #3e8fb0;
  --other: #ea9a97;
  --ok-bg: #1f3a3d;
  --ok-fg: #9ccfd8;
  --warn-bg: #3e1f2e;
  --warn-fg: #eb6f92;
  --blue-soft: #2a2740;
  --heading: #ebbcba;
  --link: #c4a7e7;
  --chrome: #13111e;
  --accent: #eb6f92;
  --primary: #b4637a;
  --primary-hover: #c4728a;
  --input-bg: #16141f;
  --input-line: #403d52;
  --hover-bg: #26233a;
  --hover-line: #524f67;
  --soft: #26233a;
  --tabs-bg: #21202e;
  --tab-on: #393552;
  --zebra: #1c1a29;
  --tfoot: #232136;
  --pop-bg: #26233a;
  --cash-tint: #1b2a2e;
  --tag-fg: #ebbcba;
  --chart-grid: #312e47;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .4);
}
:root[data-theme="dracula"] { /* Dracula */
  color-scheme: dark;
  --bg: #21222c;
  --surface: #282a36;
  --line: #3b3d4f;
  --text: #f8f8f2;
  --muted: #9aa3c7;
  --income: #50fa7b;
  --expense: #ff5555;
  --balance: #8be9fd;
  --card: #bd93f9;
  --limit: #ff79c6;
  --fixed: #62a8f4;
  --other: #ffb86c;
  --ok-bg: #1f3a2a;
  --ok-fg: #50fa7b;
  --warn-bg: #4a2130;
  --warn-fg: #ff8080;
  --blue-soft: #303a55;
  --heading: #bd93f9;
  --link: #ff79c6;
  --chrome: #191a21;
  --accent: #bd93f9;
  --primary: #7c5cc4;
  --primary-hover: #8f6fd6;
  --input-bg: #1e1f29;
  --input-line: #44475a;
  --hover-bg: #303241;
  --hover-line: #565970;
  --soft: #343746;
  --tabs-bg: #2b2d3a;
  --tab-on: #44475a;
  --zebra: #252733;
  --tfoot: #2c2e3b;
  --pop-bg: #2f3141;
  --cash-tint: #1f2e27;
  --tag-fg: #ff79c6;
  --chart-grid: #3b3d4f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .4);
}
:root[data-theme="nord"] { /* Nord */
  color-scheme: dark;
  --bg: #2e3440;
  --surface: #3b4252;
  --line: #4c566a;
  --text: #eceff4;
  --muted: #a7b1c2;
  --income: #a3be8c;
  --expense: #bf616a;
  --balance: #88c0d0;
  --card: #b48ead;
  --limit: #ebcb8b;
  --fixed: #81a1c1;
  --other: #d08770;
  --ok-bg: #3b4a3f;
  --ok-fg: #a3be8c;
  --warn-bg: #4a3438;
  --warn-fg: #e5a2a8;
  --blue-soft: #3e4a5e;
  --heading: #88c0d0;
  --link: #8fbcbb;
  --chrome: #242933;
  --accent: #88c0d0;
  --primary: #5e81ac;
  --primary-hover: #6d91bd;
  --input-bg: #2b303b;
  --input-line: #4c566a;
  --hover-bg: #434c5e;
  --hover-line: #5b6680;
  --soft: #434c5e;
  --tabs-bg: #353c4a;
  --tab-on: #4c566a;
  --zebra: #383e4c;
  --tfoot: #3f4757;
  --pop-bg: #434c5e;
  --cash-tint: #34403b;
  --tag-fg: #8fbcbb;
  --chart-grid: #4c566a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
}
:root[data-theme="gruvbox"] { /* Gruvbox */
  color-scheme: dark;
  --bg: #1d2021;
  --surface: #282828;
  --line: #3c3836;
  --text: #ebdbb2;
  --muted: #a89984;
  --income: #b8bb26;
  --expense: #fb4934;
  --balance: #83a598;
  --card: #d3869b;
  --limit: #fabd2f;
  --fixed: #8ec07c;
  --other: #fe8019;
  --ok-bg: #32361a;
  --ok-fg: #b8bb26;
  --warn-bg: #43211c;
  --warn-fg: #fb4934;
  --blue-soft: #2e3a36;
  --heading: #fabd2f;
  --link: #83a598;
  --chrome: #32302f;
  --accent: #d79921;
  --primary: #b57614;
  --primary-hover: #d79921;
  --input-bg: #1d2021;
  --input-line: #504945;
  --hover-bg: #32302f;
  --hover-line: #665c54;
  --soft: #3c3836;
  --tabs-bg: #32302f;
  --tab-on: #504945;
  --zebra: #2c2a29;
  --tfoot: #32302f;
  --pop-bg: #32302f;
  --cash-tint: #262b1c;
  --tag-fg: #8ec07c;
  --chart-grid: #3c3836;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .4);
}
:root[data-theme="tokyo-night"] { /* Tokyo Night */
  color-scheme: dark;
  --bg: #16161e;
  --surface: #1a1b26;
  --line: #292e42;
  --text: #c0caf5;
  --muted: #8b93b8;
  --income: #9ece6a;
  --expense: #f7768e;
  --balance: #7aa2f7;
  --card: #bb9af7;
  --limit: #e0af68;
  --fixed: #7dcfff;
  --other: #ff9e64;
  --ok-bg: #1f2d24;
  --ok-fg: #9ece6a;
  --warn-bg: #3a1f2a;
  --warn-fg: #f7768e;
  --blue-soft: #24304f;
  --heading: #7aa2f7;
  --link: #7dcfff;
  --chrome: #101014;
  --accent: #7aa2f7;
  --primary: #3d59a1;
  --primary-hover: #4c6bbf;
  --input-bg: #13131a;
  --input-line: #3b4261;
  --hover-bg: #222436;
  --hover-line: #414868;
  --soft: #24283b;
  --tabs-bg: #1f2030;
  --tab-on: #2f334d;
  --zebra: #1d1e2b;
  --tfoot: #202232;
  --pop-bg: #24283b;
  --cash-tint: #1a2620;
  --tag-fg: #bb9af7;
  --chart-grid: #292e42;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .4);
}
:root[data-theme="catppuccin"] { /* Catppuccin Mocha */
  color-scheme: dark;
  --bg: #181825;
  --surface: #1e1e2e;
  --line: #313244;
  --text: #cdd6f4;
  --muted: #a6adc8;
  --income: #a6e3a1;
  --expense: #f38ba8;
  --balance: #89b4fa;
  --card: #cba6f7;
  --limit: #f5c2e7;
  --fixed: #74c7ec;
  --other: #fab387;
  --ok-bg: #23352b;
  --ok-fg: #a6e3a1;
  --warn-bg: #3d2232;
  --warn-fg: #f38ba8;
  --blue-soft: #2a3350;
  --heading: #b4befe;
  --link: #89b4fa;
  --chrome: #11111b;
  --accent: #cba6f7;
  --primary: #8839ef;
  --primary-hover: #9a55f0;
  --input-bg: #11111b;
  --input-line: #45475a;
  --hover-bg: #2a2b3c;
  --hover-line: #585b70;
  --soft: #313244;
  --tabs-bg: #252536;
  --tab-on: #45475a;
  --zebra: #1b1b2a;
  --tfoot: #232334;
  --pop-bg: #313244;
  --cash-tint: #1c2a24;
  --tag-fg: #f5c2e7;
  --chart-grid: #313244;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .4);
}
:root[data-theme="solarized"] { /* Solarized claro */
  color-scheme: light;
  --bg: #eee8d5;
  --surface: #fdf6e3;
  --line: #e0d9c3;
  --text: #073642;
  --muted: #657b83;
  --income: #859900;
  --expense: #dc322f;
  --balance: #268bd2;
  --card: #6c71c4;
  --limit: #d33682;
  --fixed: #2aa198;
  --other: #cb4b16;
  --ok-bg: #e3ecc0;
  --ok-fg: #5b6b00;
  --warn-bg: #f6d5ca;
  --warn-fg: #a32321;
  --blue-soft: #dce9f0;
  --heading: #073642;
  --link: #268bd2;
  --chrome: #073642;
  --accent: #268bd2;
  --primary: #268bd2;
  --primary-hover: #1a75b5;
  --input-bg: #fffbf0;
  --input-line: #d6cfb8;
  --hover-bg: #f7f0dc;
  --hover-line: #cfc6ab;
  --soft: #eee8d5;
  --tabs-bg: #e6dfc8;
  --tab-on: #fdf6e3;
  --zebra: #f8f1de;
  --tfoot: #f3ecd8;
  --pop-bg: #fdf6e3;
  --cash-tint: #f1f2dc;
  --tag-fg: #268bd2;
  --chart-grid: #e6dfc8;
  --shadow: 0 1px 2px rgba(7, 54, 66, .06), 0 4px 16px rgba(7, 54, 66, .06);
}
:root[data-theme="preto"] { /* Preto (AMOLED) */
  color-scheme: dark;
  --bg: #000000;
  --surface: #0b0b0b;
  --line: #222222;
  --text: #e8e8e8;
  --muted: #9a9a9a;
  --income: #66bb6a;
  --expense: #ef5350;
  --balance: #64b5f6;
  --card: #ba68c8;
  --limit: #f06292;
  --fixed: #42a5f5;
  --other: #ffa726;
  --ok-bg: #0f2416;
  --ok-fg: #a5dcb4;
  --warn-bg: #2a1014;
  --warn-fg: #ff9ea8;
  --blue-soft: #0f1e2e;
  --heading: #ffffff;
  --link: #8cbbea;
  --chrome: #000000;
  --accent: #4f8cc9;
  --primary: #2f6ea5;
  --primary-hover: #3b80bd;
  --input-bg: #000000;
  --input-line: #333333;
  --hover-bg: #151515;
  --hover-line: #3a3a3a;
  --soft: #161616;
  --tabs-bg: #111111;
  --tab-on: #262626;
  --zebra: #080808;
  --tfoot: #121212;
  --pop-bg: #141414;
  --cash-tint: #0a170f;
  --tag-fg: #a3c9ee;
  --chart-grid: #222222;
  --shadow: none;
}
:root[data-theme="terminal"] { /* Terminal (fósforo) */
  color-scheme: dark;
  --bg: #0a0f0a;
  --surface: #0d140d;
  --line: #1f3a1f;
  --text: #9cff9c;
  --muted: #5fb86f;
  --income: #33ff66;
  --expense: #ff5f5f;
  --balance: #5fd7ff;
  --card: #d787ff;
  --limit: #ffaf00;
  --fixed: #00d7af;
  --other: #ffd75f;
  --ok-bg: #0f2a14;
  --ok-fg: #33ff66;
  --warn-bg: #2a0f0f;
  --warn-fg: #ff6b6b;
  --blue-soft: #0f2a1a;
  --heading: #33ff66;
  --link: #5fff87;
  --chrome: #050805;
  --accent: #33ff66;
  --primary: #1f7a35;
  --primary-hover: #279443;
  --input-bg: #050805;
  --input-line: #2a5a2a;
  --hover-bg: #122012;
  --hover-line: #3a7a3a;
  --soft: #142214;
  --tabs-bg: #0f1a0f;
  --tab-on: #1f3a1f;
  --zebra: #0b120b;
  --tfoot: #101a10;
  --pop-bg: #0f180f;
  --cash-tint: #0d1a0f;
  --tag-fg: #5fff87;
  --chart-grid: #1a2e1a;
  --shadow: none;
}
:root[data-theme="preto"] .topbar { border-bottom: 1px solid var(--line); }
:root[data-theme="terminal"] { --radius: 4px; }
:root[data-theme="terminal"] body { font-family: ui-monospace, "SF Mono", Menlo, "JetBrains Mono", Consolas, monospace; font-size: 14px; text-shadow: 0 0 2px rgba(51, 255, 102, .2); }
:root[data-theme="terminal"] .topbar { border-bottom: 1px solid var(--line); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--link); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; color: var(--heading); }
h2 { font-size: 1rem; color: var(--heading); }
h3 { font-size: .9rem; color: var(--heading); margin: 18px 0 8px; }
small { font-size: .8em; }

/* ---------- top bar ---------- */
.topbar { background: var(--chrome); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; min-height: 56px; }
.brand { color: #fff; font-weight: 700; text-decoration: none; white-space: nowrap; letter-spacing: .2px; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.topbar nav a { color: #c9d6e2; text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-size: .92rem; }
.topbar nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.topbar nav a.on { color: #fff; background: rgba(255, 255, 255, .14); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 20px 16px 48px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.muted { color: var(--muted); }
.page-head .muted { margin: 4px 0 0; }
.hint { color: var(--muted); font-size: .82rem; margin: 8px 0 0; }
.hint.center { text-align: center; margin: -4px 0 14px; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }
.error { color: var(--warn-fg); margin: 0; }
.warn-text { color: var(--warn-fg) !important; }

.flash { background: var(--ok-bg); color: var(--ok-fg); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.notice { background: var(--surface-2, var(--surface)); border: 1px solid var(--line, #d9dee3); border-left: 4px solid var(--warn, #eda100); padding: 10px 14px; border-radius: 10px; margin: 0 0 16px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--heading);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 38px; list-style: none;
}
.btn:hover { border-color: var(--hover-line); background: var(--hover-bg); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .82rem; }
.btn.danger { color: var(--expense); }
.btn::-webkit-details-marker { display: none; }
.link { font-size: .85rem; text-decoration: none; }

input, select {
  font: inherit; color: inherit; background: var(--input-bg);
  border: 1px solid var(--input-line); border-radius: 9px; padding: 8px 10px; min-height: 40px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--blue-soft); border-color: var(--balance); }
input[data-money] { text-align: right; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; }
label.check input { width: auto; min-height: 0; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form label { flex: 1 1 120px; }
.inline-form.tight { flex-wrap: nowrap; }

.month-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.month-nav .mn-step { font-size: 1.3rem; line-height: 1; padding: 8px 12px; }
.month-nav .btn.small { font-size: .82rem; }
.mn-current { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 11.5em; padding: 5px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--blue-soft); cursor: pointer; line-height: 1.15; }
.mn-current:hover { border-color: var(--hover-line); }
.mn-current:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.mn-label { font-size: 1.12rem; font-weight: 700; color: var(--heading); white-space: nowrap; }
.mn-sub { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.mn-current.now { background: var(--surface); border-color: var(--accent); }
.mn-current.now .mn-sub { color: var(--accent); }
.mn-current input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; border: 0; padding: 0; }

.tabs { display: inline-flex; background: var(--tabs-bg); border-radius: 10px; padding: 3px; }
.tabs a { text-decoration: none; color: var(--muted); padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: .9rem; }
.tabs a.on { background: var(--tab-on); color: var(--heading); box-shadow: var(--shadow); }

/* ---------- cards & KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head .muted { font-size: .8rem; }
.card-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-width: 0; border-top: 3px solid var(--accent); }
.kpi.cash { border-top-color: var(--green); background: linear-gradient(180deg, var(--cash-tint), var(--surface) 60%); }
.kpi-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi-value { font-size: 1.45rem; font-weight: 700; color: var(--heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { color: var(--muted); font-size: .8rem; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pos { color: var(--income) !important; }
.negc { color: var(--expense) !important; }
.accent { color: var(--balance) !important; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); }
.tag { font-size: .72rem; background: var(--blue-soft); color: var(--tag-fg); padding: 0 6px; border-radius: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.chip { background: var(--soft); border-radius: 999px; padding: 2px 10px; font-size: .82rem; }

.meter { height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden; margin: 4px 0 2px; }
.meter span { display: block; height: 100%; background: var(--card); border-radius: inherit; }
.meter.over span { background: var(--limit); }
.meter.big { height: 12px; margin-bottom: 12px; }
.meter.big span { background: var(--green); }

.cash-form summary { cursor: pointer; color: var(--green); font-size: .82rem; font-weight: 600; margin-top: 6px; }
.cash-form .inline-form { margin-top: 8px; }
.cash-form .inline-form label { flex: 1 1 100px; }

/* ---------- layout ---------- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.chart { position: relative; height: 260px; }
.chart.tall { height: 300px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.two-col.wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
section.card { margin-bottom: 16px; }

.flow-stats { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-bottom: 12px; }
.flow-stats div { display: flex; flex-direction: column; }
.flow-stats span { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.flow-stats strong { font-size: 1.15rem; color: var(--heading); }
.flow-stats small { color: var(--muted); }
.flow-stats .alert strong { color: var(--warn-fg); }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
table.grid { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.grid th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: #fff; background: var(--chrome); padding: 8px 10px; font-weight: 600; white-space: nowrap; }
table.grid th:first-child { border-top-left-radius: 8px; }
table.grid th:last-child { border-top-right-radius: 8px; }
table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tbody tr:nth-child(even) td { background: var(--zebra); }
table.grid tr.sel td { background: var(--blue-soft) !important; }
table.grid tr.inactive td { opacity: .55; }
table.grid tr.past td { color: var(--muted); }
[hidden] { display: none !important; }

/* flow card filters: segmented buttons, big enough to tap */
.flow-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.forecast-box { border: 1px solid var(--line, #e3e8ec); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.forecast-box.on { border-color: var(--forecast); }
.forecast-box .hint { margin: 6px 0 0; }
.forecast-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.forecast-head form { margin: 0; }
.forecast-lead { margin: 0; flex: 1 1 420px; line-height: 1.5; }
.forecast-how summary { cursor: pointer; margin-top: 8px; font-size: .9em; color: var(--muted); }
.forecast-months { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.forecast-months li { display: flex; flex-direction: column; padding: 6px 10px; border-radius: 8px; background: var(--chart-grid, #e3e8ec); font-size: .85em; }
.forecast-months li span { color: var(--muted); }
.forecast-months li.avg { background: none; border: 1px solid var(--forecast); }
.flow-table td.forecast { color: var(--forecast); }
.seg { display: inline-flex; background: var(--tabs-bg); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .86rem;
  padding: 7px 12px; border-radius: 8px; cursor: pointer; min-height: 36px; }
.seg button.on { background: var(--tab-on); color: var(--heading); box-shadow: var(--shadow); }
table.grid tfoot td { border-top: 2px solid var(--line); background: var(--tfoot); }
table.grid.compact td { padding: 6px 8px; }
table.grid td a { text-decoration: none; font-weight: 600; }
.num { text-align: right !important; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }

/* ---------- bars ---------- */
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.bars li { display: grid; grid-template-columns: minmax(90px, 1.1fr) 2fr auto; gap: 10px; align-items: center; font-size: .88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars.share li { grid-template-columns: minmax(90px, 1fr) 2fr 10.5em; }
.bars.share .num { text-align: right; }
.bar { height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--other); }
.bar .b-cartao { background: var(--card); }
.bar .b-fixo { background: var(--fixed); }
.bar .b-outros { background: var(--other); }
.bar .b-income { background: var(--income); }

/* ---------- entries ---------- */
.entries { list-style: none; margin: 0; padding: 0; }
.entry { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.e-date { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.e-date strong { color: var(--heading); font-size: .9rem; }
.e-date small { color: var(--muted); }
.e-main { display: flex; flex-direction: column; min-width: 0; }
.e-desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.e-meta { color: var(--muted); font-size: .8rem; }
.e-amount { font-weight: 700; white-space: nowrap; }
.e-orig { display: block; font-weight: 400; font-size: .75rem; color: var(--muted); }
[data-fx-field][hidden] { display: none; }
.fx-note { font-size: .8rem; margin: 0 0 .75rem; }
.e-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.e-actions form { margin: 0; }
.entry.projected { background: repeating-linear-gradient(135deg, transparent 0 8px, rgba(83, 95, 193, .035) 8px 16px); }
.entry.projected .e-desc, .entry.projected .e-amount { opacity: .7; font-style: italic; }
.skipped { margin-top: 12px; }
.skipped summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.skipped-row { opacity: .6; text-decoration: line-through; }
.skipped-row .e-actions { text-decoration: none; }

.pop { position: relative; }
.pop-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; background: var(--pop-bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(11, 47, 74, .18); padding: 12px; width: 220px; display: flex; flex-direction: column; gap: 8px; }

.repeat { border: 1px dashed var(--input-line); border-radius: 10px; padding: 8px 10px; }
.split-card { margin-bottom: 16px; }
.split-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--soft); }
.split-bar span { display: block; height: 100%; }
.split-legend { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-top: 12px; }
.split-legend div { display: flex; align-items: baseline; gap: 6px; }
.split-legend .dot { width: 10px; height: 10px; border-radius: 3px; align-self: center; }
.b-cartao { background: var(--card); }
.b-fixo { background: var(--fixed); }
.b-outros { background: var(--other); }
.loan-fields { display: flex; flex-direction: column; gap: 10px; }
form:has(select[data-loan-system] option[value=none]:checked) .loan-fields { display: none; }
.edit-debt { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.repeat-fields { display: none; margin-top: 10px; }
.repeat:has(input[name=repeat]:checked) .repeat-fields { display: block; }
.recurrence-fields { display: flex; flex-direction: column; gap: 10px; }
.recurrence-fields .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- login ---------- */
.login { min-height: 80vh; display: grid; place-items: center; }
.login .card { width: min(360px, 100%); border-top: 4px solid var(--accent); }
.login-brand { font-weight: 700; color: var(--heading); font-size: 1.2rem; margin-bottom: 16px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .charts, .two-col, .two-col.wide-left { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi.cash { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .who-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
  .who img + .who-name, .who .avatar-fallback + .who-name { display: none; }
  /* summary cards two per row, compact */
  .kpis, .kpis.three { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpis.three .kpi:last-child { grid-column: 1 / -1; }
  .kpi { padding: 10px 12px; }
  .kpi-label { font-size: .7rem; }
  .kpi-value { font-size: 1.12rem; }
  .kpi-sub { font-size: .72rem; }
  .page-head { align-items: stretch; }
  .month-nav { width: 100%; }
  .month-nav .mn-current { flex: 1; min-width: 0; }
  .month-nav .mn-today { order: 1; flex-basis: 100%; }
  .form .row, .recurrence-fields .row { grid-template-columns: minmax(0, 1fr); }
  /* one line per entry: tap the description to edit, ✕ stays inline;
     projected entries keep Confirmar/Pular on a second line */
  .entry { grid-template-columns: 44px minmax(0, 1fr) auto auto; gap: 8px; }
  .e-actions .edit-btn { display: none; }
  .fatura-row .e-actions { display: none; } /* the title already opens the statement */
  .view-tabs { display: flex; width: 100%; }
  .analysis-btn { width: 100%; justify-content: center; }
  .view-tabs a { flex: 1; text-align: center; padding: 7px 4px; }
  .entry.projected .e-actions, .skipped-row .e-actions { grid-column: 2 / -1; justify-content: flex-start; }
  .pop-body { left: 0; right: auto; }
  .chart { height: 230px; }
  .chart.tall { height: 240px; }
  .card-head { flex-direction: column; gap: 2px; }
  .flow-filters, .seg { width: 100%; }
  .seg button { flex: 1; }
  .flow-table .opt { display: none; }
  .flow-table td, .flow-table th { padding: 7px 6px; font-size: .8rem; }
  .flow-table td small { display: block; }
  .flow-table .pill { padding: 1px 6px; }
  .bars li { grid-template-columns: minmax(80px, 1fr) 1fr auto; }
}

/* Receitas / Gastos: yearly per-category chart + composition bar */
.cat-charts { margin-bottom: 16px; }
.cat-charts .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.year-table { margin: 8px 0 4px; }
.year-table summary { cursor: pointer; color: var(--muted); font-size: .86rem; }
.year-table td .dot { margin-right: 4px; vertical-align: -1px; }
.comp-head { margin-top: 20px; flex-wrap: wrap; gap: 8px; }
.comp-head h3 { margin: 0; }
.comp-bar { display: flex; gap: 2px; height: 36px; border-radius: 6px; overflow: hidden; }
.comp-bar span { display: flex; align-items: center; justify-content: center; min-width: 2px; flex-basis: 0;
  color: #fff; font-size: .78rem; font-weight: 600; text-shadow: 0 1px 1px rgba(0, 0, 0, .35); white-space: nowrap; overflow: hidden; }
.comp-bar .empty { margin: auto; }
.comp-legend { list-style: none; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 24px; }
.comp-legend li { display: grid; grid-template-columns: 10px 1fr auto 3.5em; align-items: baseline; gap: 8px; font-size: .9rem; }
.comp-legend .dot { align-self: center; }
.comp-legend small { text-align: right; }
.comp-legend .comp-total { border-top: 1px solid var(--line); padding-top: 4px; }

/* Conectar ao Claude */
.copy-row { display: flex; gap: 8px; margin-top: 12px; }
.copy-row input { flex: 1; min-width: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.mcp-help { margin-top: 10px; font-size: .88rem; }
.mcp-help summary { cursor: pointer; color: var(--muted); }
.mcp-help ol { padding-left: 18px; margin: 8px 0 0; }
.mcp-help li { margin-bottom: 6px; }
.mcp-help code { font-size: .78rem; background: var(--soft); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

/* Sugestões de recorrência (parcelas de financiamento novo) */
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px; border-radius: 999px;
  background: #eb6834; color: #fff; font-size: .72rem; font-weight: 700; line-height: 18px; text-align: center; }
.suggestions { border-left: 4px solid #eb6834; margin-bottom: 16px; }
.suggestion { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 12px 0; border-top: 1px solid var(--soft); }
.suggestion:first-of-type { border-top: 0; }
.sug-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sug-actions { display: flex; gap: 8px; }

/* ---------- signed-in user / Google login ---------- */
.who { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: inherit; opacity: .9; margin-left: auto; white-space: nowrap; }
.who img { width: 24px; height: 24px; border-radius: 50%; }
.btn.block { display: block; width: 100%; text-align: center; margin-bottom: 8px; }

/* legal pages */
.legal { max-width: 760px; margin: 0 auto; line-height: 1.55; }
.legal h2 { margin-top: 1.4em; font-size: 1.05rem; }
.legal-links { text-align: center; font-size: .85rem; color: var(--muted); padding-top: 0; }
.legal-links a { color: inherit; }

/* theme toggle */
.theme-toggle { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: 6px 8px; border-radius: 8px; line-height: 1; }
.topbar .theme-toggle { color: #c9d6e2; font-size: 1rem; }
.topbar .theme-toggle:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.legal-links .theme-toggle { color: var(--muted); font-size: .85rem; padding: 0 4px; text-decoration: underline; }
.theme-menu { position: relative; }
.theme-menu > summary { list-style: none; }
.theme-menu > summary::-webkit-details-marker { display: none; }
.topbar .theme-menu[open] > summary { color: #fff; background: rgba(255, 255, 255, .12); }
.legal-links .theme-menu { display: inline-block; }
.theme-menu.up .menu-panel { top: auto; bottom: calc(100% + 8px); right: auto; left: 50%; transform: translateX(-50%); }
.theme-panel { min-width: 230px; max-height: min(70vh, 520px); overflow-y: auto; font-size: .92rem; text-align: left; text-shadow: none; }
.theme-option { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; white-space: nowrap; }
.theme-option:hover, .theme-option:focus-visible { background: var(--soft); outline: none; }
.theme-option[aria-checked="true"] { font-weight: 600; }
.theme-option[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); }
.theme-swatch { flex: none; display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; width: 34px; height: 18px; padding: 0 3px;
  border-radius: 5px; border: 1px solid var(--line); }
.theme-swatch i { width: 8px; height: 8px; border-radius: 50%; }
.theme-swatch.auto { background: linear-gradient(135deg, #f6f8f9 50%, #0f1418 50%); }

/* Gastos/Receitas: entries first, charts on the "Análise" tab */
.section-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 0 0 16px; }
.analysis-btn { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; border: 1px solid var(--accent); color: var(--accent); background: var(--surface); border-radius: 999px; padding: 7px 16px; text-decoration: none; }
.analysis-btn:hover { background: var(--blue-soft); }
.analysis-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.analysis-btn.on:hover { background: var(--primary-hover); }
.month-analysis { margin-bottom: 16px; }
.month-analysis > .card { margin-bottom: 0; }
.month-analysis:not(.two-col) > .card + .card { margin-top: 16px; }

.e-link { color: inherit; text-decoration: none; }
.e-link:hover { text-decoration: underline; }

/* guide ("Como usar") */
.guide { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.guide-hero { padding: 8px 0 4px; }
.guide-hero .lead { font-size: 1.05rem; color: var(--muted); margin: 8px 0 14px; max-width: 640px; }
.guide section.card, .guide-sec { margin: 0; line-height: 1.55; }
.guide-sec h2 { margin-bottom: 10px; }
.guide-sec h3 { margin-top: 16px; }
.guide-sec ol, .guide-sec ul { padding-left: 1.3em; margin: 6px 0; }
.guide-sec li { margin: 6px 0; }
.guide-mcp { border-left: 4px solid var(--accent); }
.guide-example { background: var(--soft); border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.guide-example summary { cursor: pointer; font-weight: 600; }
.guide-example code { font-size: .82rem; word-break: break-all; }
.guide-asks li { font-style: italic; }
.guide-tabs { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; margin: 0; }
.guide-tabs dt { font-weight: 700; color: var(--heading); }
.guide-tabs dd { margin: 0; }
.welcome { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-left: 4px solid var(--accent); }
.welcome p { margin: 6px 0 0; color: var(--muted); }
.login-pitch { color: var(--muted); font-size: .9rem; margin: -8px 0 14px; }
@media (max-width: 560px) {
  .guide-tabs { grid-template-columns: 1fr; gap: 2px; }
  .guide-tabs dd { margin-bottom: 8px; }
  .welcome { flex-direction: column; align-items: stretch; }
}
.welcome .btn { white-space: nowrap; flex-shrink: 0; }

/* profile menu (top-right): avatar + name + ▾ opens a menu */
.profile-menu { position: relative; margin-left: auto; }
.profile-menu > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 5px 8px 5px 5px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .22); color: #fff;
  user-select: none; }
.profile-menu > summary::-webkit-details-marker { display: none; }
.profile-menu > summary:hover, .profile-menu[open] > summary, .profile-menu > summary.on { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .4); }
.profile-menu > summary:focus-visible { outline: 2px solid #8cbbea; outline-offset: 2px; }
.profile-menu .chev { font-size: .75rem; opacity: .85; transition: transform .15s; }
.profile-menu[open] .chev { transform: rotate(180deg); }
.profile-menu img, .avatar-fallback { width: 26px; height: 26px; border-radius: 50%; }
.avatar-fallback { display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-weight: 700; font-size: .8rem; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; min-width: 240px; background: var(--pop-bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .22); padding: 6px; display: flex; flex-direction: column; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; min-width: 0; }
.menu-head span { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; }
.menu-panel a, .menu-panel .menu-logout { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font: inherit; font-size: .92rem; background: none; border: 0; width: 100%; text-align: left; cursor: pointer; }
.menu-panel a small { color: var(--muted); font-size: .75rem; }
.menu-panel a:hover, .menu-panel a:focus-visible, .menu-panel .menu-logout:hover, .menu-panel .menu-logout:focus-visible { background: var(--soft); outline: none; }
.menu-panel hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu-panel form { margin: 0; }
.menu-logout { color: var(--expense) !important; }
.profile-tabs { flex-wrap: wrap; }
.account-id { display: flex; align-items: center; gap: 12px; }
.account-id img, .account-id .avatar-fallback { width: 48px; height: 48px; font-size: 1.2rem; }
.account-id div { display: flex; flex-direction: column; min-width: 0; }
.mcp-help-card ol { padding-left: 1.2em; }
.mcp-help-card code { font-size: .78rem; word-break: break-all; background: var(--soft); padding: 1px 5px; border-radius: 4px; }
@media (max-width: 560px) {
  .profile-menu > summary { padding: 3px 6px 3px 3px; }
  .menu-panel { position: fixed; left: 8px; right: 8px; top: 52px; min-width: 0; }
}

/* tablets and phones: brand + theme + profile on one row, the nav scrolls below */
@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; gap: 0 8px; min-height: 0; padding-top: 8px; }
  .brand { flex: 1; }
  .topbar nav { order: 3; flex-basis: 100%; padding-bottom: 6px; margin: 0 -16px; padding-left: 12px; padding-right: 24px;
    -webkit-mask-image: linear-gradient(to right, #000 88%, transparent); mask-image: linear-gradient(to right, #000 88%, transparent); }
  .topbar nav a { padding: 7px 10px; }
  .profile-menu { margin-left: 0; }
}
/* menu items: label on top, hint below */
.menu-panel a { flex-direction: column; align-items: flex-start; gap: 1px; }
.menu-panel a .badge { margin-left: 0; }
.menu-panel a.menu-row { flex-direction: row; align-items: center; justify-content: space-between; }

.cat-pick { display: inline-flex; vertical-align: middle; }
.cat-pick select { padding: 2px 6px; font-size: .8rem; min-width: 0; width: auto; }

/* fatura: filter bar stays under the top bar while scrolling the purchases
   (--sticky-top is the top bar height, set by statement.js) */
.purchase-filter { position: sticky; top: var(--sticky-top, 56px); z-index: 5; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); padding: 10px 0; margin: 0 0 4px; border-bottom: 1px solid var(--line); }
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row input[type="search"] { flex: 1 1 auto; min-width: 0; }
.filter-row select { width: auto; flex: 0 0 auto; }
.filter-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 1px 0;
  -webkit-mask-image: linear-gradient(to right, #000 92%, transparent); mask-image: linear-gradient(to right, #000 92%, transparent); }
.filter-chips::-webkit-scrollbar { display: none; }
.fchip { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--soft); color: var(--text); text-decoration: none; font-size: .85rem; white-space: nowrap; }
.fchip small { color: var(--muted); }
.fchip:hover { border-color: var(--card); }
.fchip.on { background: var(--card); border-color: var(--card); color: #fff; font-weight: 600; }
.fchip.on small { color: rgba(255, 255, 255, .85); }
.filter-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0; font-size: .85rem; color: var(--muted); }
.filter-label { color: var(--text); }
.filter-clear { margin-left: auto; min-height: 26px; padding: 2px 8px; }
#compras { scroll-margin-top: calc(var(--sticky-top, 56px) + 8px); }
.to-top { position: fixed; right: 16px; bottom: 16px; z-index: 20; padding: 8px 14px; border-radius: 999px;
  background: var(--card); color: #fff; text-decoration: none; font-size: .85rem; font-weight: 600; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }
.to-top[hidden] { display: none; }
.cat-pick { max-width: 100%; }
.cat-pick select { max-width: 100%; text-overflow: ellipsis; }
.bar-filter { display: contents; color: inherit; text-decoration: none; cursor: pointer; }
.bars li:has(.bar-filter):hover .bar-label, .bar-filter.on .bar-label { color: var(--card); font-weight: 600; }
.bars li:has(.bar-filter.on) .bar { outline: 2px solid var(--card); outline-offset: 1px; }

/* "Ocultar valores" (privacy.js): amounts from the brl helper are
   <span class="money"><span>R$ …</span></span>; the inner value is hidden and a
   fixed mask shown, so the layout and color stay and nothing leaks in a print. */
.money-toggle { display: inline-flex; align-items: center; }
.money-toggle .eye-off, .hide-money .money-toggle .eye-open { display: none; }
.hide-money .money-toggle .eye-off { display: inline; }
.hide-money .money > * { display: none; }
.hide-money .money::after { content: "R$ •••••"; white-space: nowrap; }
.hide-money input[data-money] { -webkit-text-security: disc; }
@supports not (-webkit-text-security: disc) {
  .hide-money input[data-money] { color: transparent; text-shadow: 0 0 8px var(--text); }
}

/* "Seus dados e segurança" (/seguranca), on top of the guide styles */
.trust-summary { list-style: none; padding: 0; margin: 4px 0 14px; display: grid; gap: 8px; grid-template-columns: repeat(2, 1fr); }
@media (max-width: 640px) { .trust-summary { grid-template-columns: 1fr; } }
.trust-summary li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; line-height: 1.45; }
.trust-summary li::before { content: "✓"; color: var(--income); font-weight: 700; margin-right: 6px; }
.trust-inactive { border-left: 4px solid var(--orange); }
.trust-ack { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; border-left: 4px solid var(--accent); }
.trust-ack p { margin: 0; flex: 1 1 320px; }
.trust-meta { text-align: center; font-size: .85rem; }

/* ---------- Início: orçamento em destaque ---------- */
.budget-hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 16px; }
.budget-hero .card { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.budget-big { font-size: 2.1rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.budget-hero .over { border-color: var(--warn, #c62828); }
.budget-empty { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.kpis.kpis-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.kpi-label .link.small, .link.small { font-size: .8rem; padding: 0; margin-left: 6px; background: none; border: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* blocos recolhidos */
details.more-details > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; gap: 8px; align-items: baseline; }
details.more-details > summary::-webkit-details-marker { display: none; }
details.more-details > summary::before { content: "▸"; color: var(--muted); }
details.more-details[open] > summary::before { content: "▾"; }
details.more-details[open] > summary { margin-bottom: 12px; }

/* menu "Mais" na barra */
.topbar nav { overflow: visible; align-items: center; } /* 4 items now; the "Mais" menu must not be clipped */
.nav-more { position: relative; }
.nav-more > summary { list-style: none; cursor: pointer; color: #c9d6e2; padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-size: .92rem; display: flex; align-items: center; gap: 4px; }
.nav-more > summary::-webkit-details-marker { display: none; }
.nav-more > summary:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.nav-more > summary.on, .nav-more[open] > summary { color: #fff; background: rgba(255, 255, 255, .14); }
.nav-more .chev { font-size: .7rem; opacity: .8; }
.nav-more .menu-panel { left: 0; right: auto; min-width: 180px; }
.topbar nav .nav-more .menu-panel a { display: block; color: var(--text); padding: 8px 10px; }
.topbar nav .nav-more .menu-panel a:hover { background: var(--soft); color: var(--text); }

/* pop-ups */
dialog.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: inherit; padding: 20px; width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog.dlg::backdrop { background: rgba(0, 0, 0, .35); }
dialog.dlg h2 { margin: 0 0 8px; font-size: 1.1rem; }

/* Início: blocos Orçamento (compras) e Caixa (mês escolhido) */
.home-block { margin-bottom: 20px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 0 0 10px; }
.block-head h2 { margin: 0; font-size: 1.05rem; }
.block-head .month-nav { margin-left: auto; }
.budget-big small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.budget-big.negc small { color: inherit; }

/* header "+": adds a gasto or a receita from any page */
.add-btn { margin-left: auto; display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; cursor: pointer; flex: none; }
.add-btn:hover { filter: brightness(1.1); }
.topbar-inner .add-btn ~ .profile-menu { margin-left: 0; }
.quick-add[popover] { margin: min(10vh, 80px) auto auto; inset: 0; height: fit-content; max-height: calc(100vh - min(10vh, 80px) - 16px); overflow: auto;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: inherit; padding: 20px;
  width: min(440px, calc(100vw - 24px)); box-shadow: var(--shadow); }
.quick-add::backdrop { background: rgba(0, 0, 0, .35); }
.kind-seg { display: flex; }
.kind-seg label { flex: 1; margin: 0; }
.kind-seg input { position: absolute; opacity: 0; pointer-events: none; }
.kind-seg span { display: block; text-align: center; color: var(--muted); font-weight: 600; font-size: .9rem; padding: 7px 12px;
  border-radius: 8px; cursor: pointer; }
.kind-seg input:checked + span { background: var(--tab-on); color: var(--heading); box-shadow: var(--shadow); }
.kind-seg input:focus-visible + span { outline: 2px solid var(--accent); }
.more-opts > summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
.more-opts[open] > summary { margin-bottom: 10px; }
.more-opts > * + * { margin-top: 10px; }
.card-head .btn.small { margin-left: auto; }

/* Perfil → Open Finance */
.of-page { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.of-page .card { margin: 0; }
.of-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.of-bank { padding: 12px 0; border-top: 1px solid var(--line); }
.of-bank:first-of-type { border-top: 0; }
.of-alert { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 8px 0 0; padding: 10px 12px;
  border-radius: 10px; background: color-mix(in srgb, var(--warn, #c62828) 10%, transparent); color: var(--text); font-size: .92rem; }
.of-more { position: relative; }
.of-more > summary { list-style: none; cursor: pointer; }
.of-more > summary::-webkit-details-marker { display: none; }
.of-more[open] > .form, .of-more[open] > label, .of-more[open] > .hint { margin-top: 10px; }
.of-row > .of-more[open] { flex-basis: 100%; }
.of-bank .of-more[open] { flex-basis: auto; }
.of-more .menu-panel { right: 0; left: auto; min-width: 220px; }
.menu-btn { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; color: var(--text); font: inherit; cursor: pointer; }
.menu-btn:hover, .of-more .menu-panel a:hover { background: var(--soft); }
.of-more .menu-panel a { padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.danger-text { color: var(--warn, #c62828); }
.of-connect { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 12px; }
.of-how { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.steps { padding-left: 18px; }

/* ---------- home: small charts ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.spark { position: relative; height: 40px; margin-top: 4px; }
.spark.week-bars { height: 62px; margin-top: 6px; }
.burnup { position: relative; height: 96px; margin: 6px 0 2px; }
.legend-dash { display: inline-block; width: 16px; border-top: 2px dashed var(--muted); opacity: .6; vertical-align: middle; }
.budget-hero, .kpis.kpis-3 { align-items: stretch; }
.kpis.kpis-3 .kpi { justify-content: flex-start; }
.next-months .flow-stats { margin-bottom: 8px; }
.chart.flow-main { height: 200px; }
.next-months .flow-note { margin: 8px 0 0; }
.bars.cats { display: grid; grid-template-columns: minmax(90px, 1.1fr) 2fr auto; gap: 10px; align-items: center; }
.bars.cats li { display: contents; }
.bars.cats .num { text-align: right; white-space: nowrap; }
.bar .b-resto { background: var(--muted); opacity: .45; }
.bars.cats .bar { position: relative; overflow: visible; }
.bars.cats .bar > span { overflow: hidden; }
.avg-tick { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: .55; border-radius: 1px; }
.avg-tick.inline { position: static; display: inline-block; height: .9em; vertical-align: -2px; margin: 0 4px 0 0; }
.cat-delta { font-weight: 600; margin-left: 4px; }
.cat-delta.up { color: var(--expense); }
.cat-delta.down { color: var(--income); }
.cats-legend { margin: 10px 0 0; font-size: .78rem; }
@media (max-width: 640px) {
  .budget-hero { grid-template-columns: 1fr; }
  .chart.flow-main { height: 180px; }
  .bars.cats { grid-template-columns: minmax(80px, 1fr) 1fr auto; }
  .bars.cats .num { display: flex; flex-direction: column; align-items: flex-end; }
  .cat-delta { margin-left: 0; }
}

.tools-row { display: flex; justify-content: flex-end; margin: -6px 0 10px; }
.dlg.dlg-wide { width: min(640px, calc(100vw - 32px)); }
#month-area { transition: opacity .15s; }
#month-area.loading { opacity: .55; pointer-events: none; }

/* long lists inside a card scroll inside it instead of stretching the page */
.scroll-box { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.scroll-box .grid { margin: 0; }
.grid.sticky-head thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); box-shadow: inset 0 -1px 0 var(--line); }
.rules-filter { width: 100%; margin: 0 0 8px; }
.more-cats > summary { cursor: pointer; color: var(--link); font-size: .88rem; margin-top: 10px; list-style: none; }
.more-cats > summary::-webkit-details-marker { display: none; }
.more-cats[open] > summary { margin-bottom: 10px; }

/* limite do cartão */
.limit-use { margin: 4px 0 12px; }
.limit-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: .9rem; }
.limit-head > span:first-child { color: var(--muted); }

/* "Caixa hoje" leads to Investimentos */
.kpi-link { color: inherit; text-decoration: none; }
.kpi-link:hover .kpi-value, .kpi-link:focus-visible .kpi-value { text-decoration: underline; text-underline-offset: 3px; }

/* Orçamento → Como calculamos: which categories count */
.budget-how { margin: 0 0 16px; }
.budget-how summary { cursor: pointer; font-weight: 600; }
.budget-cats { list-style: none; padding: 0; margin: 10px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 16px; }
.budget-cats li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--soft); }
.budget-cats li.off label { color: var(--muted); text-decoration: line-through; }
.budget-cats .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.budget-sum { margin-top: 12px; }

/* Perfil → Categorias */
.cat-table td { vertical-align: top; }
.cat-table .cat-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.cat-table details > summary { list-style: none; cursor: pointer; }
.cat-table details > summary::-webkit-details-marker { display: none; }
.cat-table details[open] { flex-basis: 100%; }
.cat-table details .inline-form { margin-top: 8px; }
.cat-table .tag { font-size: .75rem; padding: 1px 6px; border-radius: 999px; background: var(--soft); color: var(--muted); margin-left: 4px; }

/* ---------- Investimentos: celular ---------- */
@media (max-width: 860px) {
  /* .topbar nav { overflow: visible } (do antigo menu "Mais") anulava a rolagem: com a aba Investimentos, a barra alargava a página toda */
  .topbar nav { overflow-x: auto; }
}
.inv-sub { display: none; }
@media (max-width: 640px) {
  /* KPIs: Patrimônio e Outros bens na linha toda, Caixa e Cripto lado a lado; valor longo quebra depois do "R$" em vez de ser cortado */
  .kpis.kpis-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpis.kpis-3 .kpi:first-child, .kpis.kpis-3 .kpi:last-child { grid-column: 1 / -1; }
  .kpis.kpis-3 .kpi-value { white-space: normal; overflow-wrap: anywhere; }
  /* números do caixa e da cripto em duas colunas; o último sozinho ocupa a linha */
  #caixa .flow-stats, #cripto .flow-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
  #caixa .flow-stats > div:last-child:nth-child(odd), #cripto .flow-stats > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
  /* tabelas: colunas secundárias viram uma linha abaixo do nome, para o valor caber sem rolar */
  .inv-table .inv-col { display: none; }
  .inv-table .inv-sub { display: block; margin-top: 2px; font-size: .75rem; font-weight: 400; }
  .inv-table .inv-when { display: block; }
  .inv-table td.num { white-space: nowrap; }
  .inv-table th, .inv-table td { padding-left: 8px; padding-right: 8px; }
  /* menu ⋯ dos bens abre logo abaixo do botão, não preso no topo da tela (regra geral dos menus no celular) */
  #bens .table-scroll { overflow: visible; }
  #bens .of-more .menu-panel { position: absolute; top: calc(100% + 6px); right: 0; left: auto; min-width: 160px; }
}

/* Receitas/Gastos → Por categoria: share of the month and the 6-month average */
.cat-share-card { margin-bottom: 16px; }
.bars.cat-share li { grid-template-columns: minmax(90px, 1fr) 2fr 11.5em; }
.bars.cat-share .bar { position: relative; overflow: visible; }
.bars.cat-share .bar > span { overflow: hidden; }
.bars.cat-share .num { text-align: right; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.cat-avg { font-size: .74rem; color: var(--muted); }
.cat-avg.up { color: var(--expense); }
@media (max-width: 640px) {
  .bars.cat-share li { grid-template-columns: minmax(80px, 1fr) 1fr 7.6em; gap: 8px; }
  .bars.cat-share .num > span { display: flex; flex-direction: column; align-items: flex-end; }
}
.bars.cat-share .num > span { white-space: nowrap; }

/* ---------- Investimentos → Analisar ---------- */
.seg.seg-links { margin: 4px 0 16px; flex-wrap: wrap; }
.seg.seg-links a { color: var(--muted); font-weight: 600; font-size: .86rem; padding: 6px 12px; border-radius: 8px; text-decoration: none; }
.seg.seg-links a.on { background: var(--tab-on); color: var(--heading); box-shadow: var(--shadow); }
.nw-kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.nw-table td.num { white-space: nowrap; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 640px) { .head-actions { width: 100%; } .head-actions .analysis-btn { flex: 1; justify-content: center; } }

/* Investimentos: what the crypto "Atualizar" click did, on the button */
[data-live-refresh] .btn.is-busy { opacity: .7; cursor: progress; }
[data-live-refresh] .btn.is-done { color: var(--income); border-color: currentColor; }
[data-live-refresh] .btn.is-error { color: var(--expense); border-color: currentColor; }
