/* Layout: celular = 1 coluna + barra de abas embaixo; tablet = 2 colunas;
   PC (≥1024px) = menu lateral fixo + grade de 12 colunas com cards lado a lado.
   Identidade: verde das cédulas do real com visual de vidro fosco (seção "Visual de vidro" no fim). */
:root {
  color-scheme: light;
  --bg: #f2f5f1;
  --surface: #fcfdfb;
  --surface-2: #e9eee7;
  --border: #d9e1d6;
  --text: #0f1f19;
  --text-2: #4a5a52;
  --text-3: #6f7e77;
  --accent: #0b6e4f;
  --accent-hover: #095c42;
  --accent-ink: #ffffff;
  --accent-soft: #dbeee4;
  --note: #0c3a2c;          /* fundo dos cartões de destaque (cédula) */
  --note-ink: #f1f7f3;
  --note-line: rgb(255 255 255 / 0.07);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #11753f;
  --warning: #995800;
  --critical: #c0302f;
  --good-bg: #e2f2e7;
  --warning-bg: #f9eed8;
  --critical-bg: #f9e3e2;
  --info-bg: #e7eef3;
  --focus: #2a78d6;

  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Instrument Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --radius: 16px;
  --radius-sm: 10px;
  --sidebar: 248px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c1210; --surface: #131b18; --surface-2: #1b2521; --border: #25322d;
    --text: #e7efea; --text-2: #a8b7af; --text-3: #7f8e87;
    --accent: #3cbd8d; --accent-hover: #55cb9e; --accent-ink: #04140e; --accent-soft: #163428;
    --note: #0f2a21; --note-ink: #e7f3ec; --note-line: rgb(255 255 255 / 0.05);
    --series-1: #3987e5; --series-2: #d95926;
    --good: #4cc27a; --warning: #e3a33b; --critical: #f07170;
    --good-bg: #143021; --warning-bg: #33270e; --critical-bg: #3a1919; --info-bg: #17232c;
    --focus: #6da7ec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1210; --surface: #131b18; --surface-2: #1b2521; --border: #25322d;
  --text: #e7efea; --text-2: #a8b7af; --text-3: #7f8e87;
  --accent: #3cbd8d; --accent-hover: #55cb9e; --accent-ink: #04140e; --accent-soft: #163428;
  --note: #0f2a21; --note-ink: #e7f3ec; --note-line: rgb(255 255 255 / 0.05);
  --series-1: #3987e5; --series-2: #d95926;
  --good: #4cc27a; --warning: #e3a33b; --critical: #f07170;
  --good-bg: #143021; --warning-bg: #33270e; --critical-bg: #3a1919; --info-bg: #17232c;
  --focus: #6da7ec;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* O cabeçalho fixo não pode cobrir o campo em foco. */
html { scroll-padding-top: 88px; -webkit-tap-highlight-color: transparent; }
button, a, input, select, textarea, summary { touch-action: manipulation; }
.sr-only, .skip-link:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip-link:focus {
  position: fixed; z-index: 30; top: calc(8px + env(safe-area-inset-top, 0px)); left: max(16px, env(safe-area-inset-left, 0px));
  background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: var(--radius-sm); font-weight: 600;
}
main:focus { outline: none; }
.form-status { margin: 0; font-size: 0.88rem; color: var(--good); min-height: 1.3em; }
.form-status.error { color: var(--critical); }
.form-status:empty { min-height: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--text-2); margin: 0 0 0.75rem; font-size: 0.9rem; }
kbd {
  font-family: var(--font-num); font-size: 0.75rem; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

/* ---------- Topo ---------- */
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface);
}
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 6;
  display: flex; align-items: center; gap: 12px;
  padding-block: 10px; padding-left: var(--gutter-l); padding-right: var(--gutter-r);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand, .side-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; letter-spacing: -0.02em; }
.page-title { margin: 0; font-size: 1.5rem; font-weight: 800; }
/* No celular o título fica só para leitores de tela (a aba ativa já aparece embaixo). */
@media (max-width: 1023px) {
  .page-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
.month-picker { margin-left: auto; display: flex; align-items: center; gap: 4px; font-weight: 600; font-size: 0.95rem; }
.month-picker span { min-width: 9.5em; text-align: center; }
.month-picker button {
  border: 1px solid var(--border); background: var(--surface); width: 34px; height: 34px; border-radius: 50%;
  cursor: pointer; font-size: 1.1rem; line-height: 1;
}
.month-picker button:hover { background: var(--surface-2); }

/* ---------- Grade ---------- */
main {
  max-width: 1280px; margin: 0 auto;
  padding-block: 16px 24px; padding-left: var(--gutter-l); padding-right: var(--gutter-r);
}
.tab { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.tab[hidden] { display: none; }
.tab > * { min-width: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 0.75rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.link { color: var(--accent); font-size: 0.9rem; font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* Cartão de destaque: fundo de cédula com guilhoché. */
.hero {
  position: relative; overflow: hidden; isolation: isolate;
  display: flex; flex-direction: column; gap: 6px; justify-content: center;
  background: var(--note); color: var(--note-ink); border: 0; min-height: 132px;
}
.hero::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background:
    repeating-radial-gradient(circle at 110% -10%, transparent 0 13px, var(--note-line) 13px 14px),
    repeating-radial-gradient(circle at -10% 120%, transparent 0 17px, var(--note-line) 17px 18px);
}
.hero .stat-label { color: inherit; opacity: 0.8; letter-spacing: 0.06em; text-transform: uppercase; font-size: 0.72rem; font-weight: 600; }
.hero .muted { color: inherit; opacity: 0.85; margin: 0; }
.hero-value { font-family: var(--font-num); font-size: clamp(1.9rem, 6vw, 2.6rem); font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

/* ---------- Botões ---------- */
.primary, .secondary, .danger {
  border: 0; border-radius: var(--radius-sm); padding: 10px 16px; font-weight: 600; cursor: pointer;
  transition: background-color 0.15s ease;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { background: var(--accent-hover); }
.secondary { background: var(--surface-2); }
.secondary:hover { background: var(--border); }
.danger { background: var(--critical-bg); color: var(--critical); }
button:disabled { opacity: 0.6; cursor: progress; }
.icon-btn {
  border: 0; background: var(--surface-2); border-radius: 8px; width: 32px; height: 32px; flex: none;
  cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--critical-bg); color: var(--critical); }

/* ---------- Início: conversa ---------- */
.chat-tab { display: block; }
.chat {
  max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px;
  padding-top: clamp(8px, 6vh, 64px);
}
.chat-greeting h2 {
  font-family: var(--font-display); font-weight: 800; font-size: clamp(1.8rem, 6vw, 2.6rem);
  letter-spacing: -0.03em; line-height: 1.1; margin: 0;
}
.chat-greeting p { margin: 6px 0 4px; color: var(--text-2); font-size: 1.05rem; }
.chat-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.chat-log:empty { display: none; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 18px; font-size: 0.95rem; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.bubble.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.bubble.bot strong { font-family: var(--font-display); font-weight: 600; font-size: 1rem; }
.bubble.bot ul { margin: 4px 0 0; padding: 0; list-style: none; font-family: var(--font-num); font-size: 0.85rem; color: var(--text-2); }
.bubble.bot p { margin: 6px 0 0; font-size: 0.88rem; color: var(--text-2); }
.bubble.bot.error { background: var(--critical-bg); border-color: transparent; }
.bubble.bot.error ul { font-family: var(--font-body); }
.bubble.bot.undone { opacity: 0.7; }
.undo {
  margin-top: 8px; border: 1px solid var(--border); background: transparent; border-radius: 999px;
  padding: 3px 12px; font-size: 0.8rem; color: var(--text-2); cursor: pointer;
}
.undo:hover { border-color: var(--critical); color: var(--critical); }

.composer {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 18px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px;
  box-shadow: 0 6px 24px -12px rgb(12 58 44 / 0.25);
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.composer input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 10px 0; font-size: 1.1rem; }
.composer input:focus { outline: none; }
.send {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  transition: background-color 0.15s ease;
}
.send:hover { background: var(--accent-hover); }
.send svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.preview { min-height: 1.6em; padding-inline: 12px; font-size: 0.88rem; color: var(--text-2); }
.preview:empty { min-height: 0; }
.preview .pill { display: inline-block; background: var(--accent-soft); color: var(--text); border-radius: 999px; padding: 3px 12px; margin: 2px 4px 2px 0; }
.preview .err { color: var(--critical); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding-inline: 4px; }
.chip {
  border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 5px 12px;
  font-size: 0.82rem; color: var(--text-2); cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chat-log:not(:empty) ~ .chips { display: none; }

.mini { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.mini-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.mini-head h2 { margin: 0; font-size: 0.95rem; color: var(--text-2); font-weight: 600; }
.mini-total { font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { border-top: 1px solid var(--border); }
.mini-list li:first-child { border-top: 0; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 0; cursor: pointer; font-size: 0.9rem; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Números do mês ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.stat-label { font-size: 0.78rem; color: var(--text-2); font-weight: 500; }
.stat-value { font-family: var(--font-num); font-size: clamp(0.82rem, 3.4vw, 1.35rem); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; letter-spacing: -0.02em; }
.neg { color: var(--critical); }
.pos { color: var(--good); }

/* ---------- Dicas e alertas ---------- */
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.insights:empty { display: none; }
.insights li {
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--info-bg); font-size: 0.92rem;
  display: flex; gap: 10px; align-items: baseline;
}
.insights li::before { content: "i"; flex: none; width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 0.72rem; font-weight: 700; background: var(--text-3); color: var(--surface); transform: translateY(2px); }
.insights li.good { background: var(--good-bg); }
.insights li.good::before { content: "✓"; background: var(--good); }
.insights li.warning { background: var(--warning-bg); }
.insights li.warning::before { content: "!"; background: var(--warning); }
.insights li.critical { background: var(--critical-bg); }
.insights li.critical::before { content: "!"; background: var(--critical); }

/* ---------- Listas de lançamentos ---------- */
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-list li { border-top: 1px solid var(--border); }
.tx-list li:first-child { border-top: 0; }
.tx-item { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 4px; background: none; border: 0; text-align: left; cursor: pointer; border-radius: 8px; }
button.tx-item:hover { background: var(--surface-2); }
.tx-main { flex: 1; min-width: 0; }
.tx-desc { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { display: block; font-size: 0.8rem; color: var(--text-2); }
.tx-amount { font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.95rem; }
.tx-amount.income { color: var(--good); }
.empty { color: var(--text-3); padding: 12px 0; text-align: center; list-style: none; }

/* ---------- Gráficos ---------- */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 28%) minmax(0, 1fr) auto; gap: 12px; align-items: center; font-size: 0.9rem; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 14px; background: var(--surface-2); border-radius: 4px; position: relative; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-budget { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); }
.hbar-value { font-family: var(--font-num); font-variant-numeric: tabular-nums; text-align: right; font-size: 0.85rem; }
.hbar-value small { display: block; color: var(--text-3); font-size: 0.72rem; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; font-family: var(--font-body); }
.chart .bar-1 { fill: var(--series-1); }
.chart .bar-2 { fill: var(--series-2); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hover-band.on { fill: var(--surface-2); }
.legend { display: flex; gap: 16px; font-size: 0.85rem; color: var(--text-2); margin-bottom: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--text); color: var(--surface);
  padding: 6px 10px; border-radius: 8px; font-size: 0.8rem; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.table-view { margin-top: 12px; font-size: 0.9rem; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 600; }
table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); font-weight: 600; }
td.num, th.num { text-align: right; }
.places { margin: 0; padding-left: 1.5rem; display: grid; gap: 8px; }
.places li { padding-left: 4px; }
.places li span { float: right; font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.places small { color: var(--text-3); }

.rule { display: grid; gap: 16px; }
.rule-row header { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 6px; gap: 8px; flex-wrap: wrap; }
.meter { height: 10px; background: var(--surface-2); border-radius: 4px; position: relative; overflow: hidden; }
.meter-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.meter-fill.over { background: var(--critical); }
.meter-target { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); }
.rule-row small { color: var(--text-2); display: block; margin-top: 4px; }

/* ---------- Investir ---------- */
.market { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.market div { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.market b { display: block; font-family: var(--font-num); font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.market span { font-size: 0.78rem; color: var(--text-2); }
.market-note { grid-column: 1 / -1; background: none !important; padding: 0 !important; font-size: 0.8rem; color: var(--text-3); margin: 0; }
.allocation { display: grid; gap: 10px; }
.alloc { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.alloc header { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.alloc header span:first-child { min-width: 0; }
.alloc header span:last-child { font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.alloc p { margin: 0; font-size: 0.85rem; color: var(--text-2); }
.alloc ul { margin: 2px 0 0; padding-left: 1.1rem; font-size: 0.88rem; }
.alloc li span { color: var(--text-2); }
.projection { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.projection div { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.projection b { display: block; font-family: var(--font-num); font-size: clamp(0.95rem, 1.3vw, 1.15rem); overflow-wrap: anywhere; font-weight: 600; font-variant-numeric: tabular-nums; }
.projection small { color: var(--text-2); display: block; }
.research-section h3 { font-size: 0.95rem; margin: 16px 0 6px; }
.table-scroll { overflow-x: auto; }
.research-section table { font-size: 0.86rem; }
.research-section td small { color: var(--text-2); display: block; }
.sources { font-size: 0.8rem; padding-left: 1.1rem; }
.sources a { color: var(--accent); overflow-wrap: anywhere; }
.import { margin-top: 14px; }
.import textarea { width: 100%; margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; background: var(--bg); font-family: var(--font-num); font-size: 0.8rem; }
.disclaimer { font-size: 0.78rem; color: var(--text-3); text-align: center; margin: 4px auto 0; max-width: 62ch; }
.progress-bar { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress-bar div { height: 100%; background: var(--good); border-radius: 0 4px 4px 0; }

/* ---------- Carteira ---------- */
.positions { display: grid; gap: 10px; }
.position { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.position-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.position-head b { font-family: var(--font-num); font-size: 1rem; letter-spacing: 0.02em; }
.position-head .val { font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.position-meta { display: flex; justify-content: space-between; align-items: center; gap: 4px 10px; font-size: 0.84rem; color: var(--text-2); flex-wrap: wrap; }
.position-meta .num { font-variant-numeric: tabular-nums; }
.position select { padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background-color: var(--bg); color: var(--text); font-size: 0.8rem; }
.watch-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; align-items: end; margin-bottom: 12px; }
.watch-form label { display: grid; gap: 4px; font-size: 0.85rem; font-weight: 600; }
.watch-form input { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); width: 100%; }
.watchlist { list-style: none; margin: 0; padding: 0; }
.watchlist li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.watchlist li:first-child { border-top: 0; }
.watchlist .w-main { flex: 1; min-width: 0; }
.watchlist .w-main b { font-family: var(--font-num); }
.watchlist small { display: block; color: var(--text-2); }
.watchlist .w-price { font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Formulários ---------- */
.form { display: grid; gap: 14px; align-content: start; }
.form h2 { margin: 0; }
.form label { display: grid; gap: 5px; font-size: 0.9rem; font-weight: 600; }
.form small { font-weight: 400; color: var(--text-3); }
.form input, .form select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background-color: var(--bg); color: var(--text); font-weight: 400; width: 100%;
}
.form > .primary { justify-self: start; }
.budgets { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 22px;
  width: min(460px, calc(100vw - 32px)); background: var(--surface); color: var(--text);
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgb(5 15 11 / 0.5); }
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

/* ---------- Navegação: barra embaixo (celular/tablet) ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.side-brand, .side-note { display: none; }
.tabbar button {
  border: 0; background: none; padding: 8px 2px 10px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 0.72rem; font-weight: 500; color: var(--text-2); cursor: pointer;
}
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); font-weight: 700; }

/* ---------- Tablet: 2 colunas ---------- */
@media (min-width: 700px) {
  .tab { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .w-12 { grid-column: 1 / -1; }
  .card { padding: 20px; }
}

/* ---------- PC: menu lateral + grade de 12 colunas ---------- */
@media (min-width: 1024px) {
  body { padding-bottom: 0; padding-left: var(--sidebar); }
  .brand { display: none; }
  .topbar { padding-left: max(32px, env(safe-area-inset-left, 0px)); padding-right: max(32px, env(safe-area-inset-right, 0px)); padding-block: 16px; }
  main { padding-block: 24px 40px; padding-left: max(32px, env(safe-area-inset-left, 0px)); padding-right: max(32px, env(safe-area-inset-right, 0px)); }
  .tab { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
  .w-12 { grid-column: span 12; }
  .w-7 { grid-column: span 7; }
  .w-6 { grid-column: span 6; }
  .w-5 { grid-column: span 5; }

  .tabbar {
    top: 0; right: auto; width: var(--sidebar);
    display: flex; flex-direction: column; gap: 4px;
    padding: 20px 14px; padding-left: max(14px, env(safe-area-inset-left, 0px));
    border-top: 0; border-right: 1px solid var(--border);
  }
  .side-brand { display: flex; padding: 4px 10px 22px; font-size: 1.3rem; }
  .tabbar button {
    flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 12px; border-radius: var(--radius-sm);
    font-size: 0.95rem;
  }
  .tabbar button:hover { background: var(--surface-2); color: var(--text); }
  .tabbar button.active { background: var(--accent-soft); color: var(--accent); }
  /* "Ajustes" fica no rodapé do menu. */
  .side-note { display: block; order: 98; margin: auto 10px 10px; font-size: 0.8rem; color: var(--text-3); }
  #nav-settings { order: 99; }

  .stat { padding: 16px 18px; }
  .tx-list { max-height: 640px; overflow-y: auto; }
  #research { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; align-items: start; }
  #research > p { grid-column: 1 / -1; }
}

@media (min-width: 1440px) {
  :root { --sidebar: 268px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Instalar como app ---------- */
.install-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  border: 0; border-radius: 999px; padding: 7px 12px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 0.85rem;
}
.install-btn:hover { background: var(--accent-hover); }
.install-btn[hidden] { display: none; }
.install-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#month-label .short { display: none; }
@media (max-width: 480px) {
  #month-label .long { display: none; }
  #month-label .short { display: inline; }
  .month-picker span#month-label { min-width: 4.6em; }
  .install-btn span { display: none; }
  .install-btn { padding: 8px; }
  .install-btn::after { content: "Instalar"; }
}
.steps { margin: 0; padding-left: 1.3rem; display: grid; gap: 10px; }
.inline-icon { width: 20px; height: 20px; vertical-align: -4px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* Aberto como app instalado: a barra de status do iPhone fica por cima do conteúdo. */
@media (display-mode: standalone) {
  body { padding-top: env(safe-area-inset-top, 0px); }
}

/* =====================================================================
   Visual de vidro (glassmorphism)
   Fundo: ambiente em degradê (luz quente de fim de tarde + verde da marca).
   Superfícies: vidro fosco translúcido com borda clara e reflexo no topo.
   PC: barra de ícones flutuante à esquerda; celular: pílula de vidro embaixo.
   ===================================================================== */
:root {
  --backdrop:
    radial-gradient(60% 50% at 12% 8%, rgb(255 214 170 / 0.85), transparent 70%),
    radial-gradient(55% 45% at 88% 12%, rgb(160 220 196 / 0.75), transparent 70%),
    radial-gradient(70% 55% at 75% 95%, rgb(170 200 240 / 0.7), transparent 70%),
    radial-gradient(60% 50% at 10% 90%, rgb(240 200 210 / 0.6), transparent 70%),
    linear-gradient(160deg, #eef3ee, #e6ece9);
  --glass: rgb(255 255 255 / 0.55);
  --glass-strong: rgb(255 255 255 / 0.78);
  --glass-inner: rgb(255 255 255 / 0.45);
  --glass-border: rgb(255 255 255 / 0.75);
  --glass-edge: rgb(15 31 25 / 0.08);
  --glass-shine: rgb(255 255 255 / 0.9);
  --glass-shadow: 0 12px 32px -14px rgb(20 50 40 / 0.28);
  --blur: 22px;
  --surface-2: rgb(15 31 25 / 0.06);
  --border: rgb(15 31 25 / 0.10);
  --bar-muted: rgb(15 31 25 / 0.16);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --backdrop:
      radial-gradient(55% 45% at 15% 10%, rgb(196 122 58 / 0.55), transparent 70%),
      radial-gradient(50% 45% at 90% 8%, rgb(11 110 79 / 0.55), transparent 70%),
      radial-gradient(65% 55% at 80% 100%, rgb(42 79 122 / 0.55), transparent 70%),
      radial-gradient(55% 50% at 0% 95%, rgb(120 70 50 / 0.45), transparent 70%),
      linear-gradient(160deg, #1a1511, #0e0f10 60%, #0c1112);
    --glass: rgb(36 32 29 / 0.42);
    --glass-strong: rgb(30 27 25 / 0.72);
    --glass-inner: rgb(255 255 255 / 0.05);
    --glass-border: rgb(255 255 255 / 0.12);
    --glass-edge: rgb(0 0 0 / 0.35);
    --glass-shine: rgb(255 255 255 / 0.18);
    --glass-shadow: 0 24px 48px -24px rgb(0 0 0 / 0.7);
    --surface-2: rgb(255 255 255 / 0.08);
    --border: rgb(255 255 255 / 0.10);
    --bar-muted: rgb(255 255 255 / 0.22);
  }
}
:root[data-theme="dark"] {
  --backdrop:
    radial-gradient(55% 45% at 15% 10%, rgb(196 122 58 / 0.55), transparent 70%),
    radial-gradient(50% 45% at 90% 8%, rgb(11 110 79 / 0.55), transparent 70%),
    radial-gradient(65% 55% at 80% 100%, rgb(42 79 122 / 0.55), transparent 70%),
    radial-gradient(55% 50% at 0% 95%, rgb(120 70 50 / 0.45), transparent 70%),
    linear-gradient(160deg, #1a1511, #0e0f10 60%, #0c1112);
  --glass: rgb(36 32 29 / 0.42);
  --glass-strong: rgb(30 27 25 / 0.72);
  --glass-inner: rgb(255 255 255 / 0.05);
  --glass-border: rgb(255 255 255 / 0.12);
  --glass-edge: rgb(0 0 0 / 0.35);
  --glass-shine: rgb(255 255 255 / 0.18);
  --glass-shadow: 0 24px 48px -24px rgb(0 0 0 / 0.7);
  --surface-2: rgb(255 255 255 / 0.08);
  --border: rgb(255 255 255 / 0.10);
  --bar-muted: rgb(255 255 255 / 0.22);
}

/* Fundo fixo numa camada própria (background-attachment: fixed não funciona no iPhone). */
body { background: var(--bg); }
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--backdrop);
}
body::before { background: transparent; }

/* Superfícies de vidro */
.card, .stat, .composer, .bubble.bot, dialog, .topbar, .tabbar {
  background: var(--glass);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(150%);
  backdrop-filter: blur(var(--blur)) saturate(150%);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--glass-shine), var(--glass-shadow);
}
dialog { background: var(--glass-strong); }
dialog::backdrop { background: rgb(5 8 7 / 0.45); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.card { border-radius: 22px; }
.stat { border-radius: 20px; }

/* Peças dentro de um card de vidro: só um véu, sem desfoque em cima de desfoque. */
.alloc, .position, .market div, .projection div, .chip, .month-picker button, kbd, .icon-btn, .secondary, .undo {
  background: var(--glass-inner);
  border-color: var(--glass-border);
}
.alloc, .position { border-radius: 16px; }
.secondary:hover, .month-picker button:hover, .icon-btn:hover { background: var(--surface-2); }
.form input, .form select, .watch-form input, .import textarea {
  background-color: var(--glass-inner);
}
.form select option { background: var(--bg); }
.bubble.user { box-shadow: 0 10px 24px -12px rgb(11 110 79 / 0.6); }

/* Cartão de destaque: vidro com tom verde da marca, guilhoché por cima. */
.hero {
  background: linear-gradient(135deg, rgb(11 110 79 / 0.78), rgb(12 58 44 / 0.62));
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  border: 1px solid rgb(255 255 255 / 0.18);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25), var(--glass-shadow);
  color: #f1f7f3;
}

/* Alertas e dicas translúcidos */
#home-alerts li, #pf-alerts li { -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border: 1px solid var(--glass-border); }

/* Topo flutuante */
.topbar { margin: 10px 12px 0; border-radius: 20px; top: calc(10px + env(safe-area-inset-top, 0px)); }

/* Celular: pílula de vidro flutuando sobre o conteúdo */
.tabbar {
  left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  border-radius: 26px; padding: 4px; background: var(--glass-strong);
}
.tabbar button { border-radius: 20px; padding: 7px 2px 8px; }
.tabbar button.active { background: var(--accent-soft); }
body { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }

/* Cards que sobem ao passar o mouse (só em telas com mouse) */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .stat, .alloc, .position, .projection div, .market div {
    transition: transform 0.25s cubic-bezier(.2, .8, .2, 1), box-shadow 0.25s ease;
  }
  .stat:hover, .alloc:hover, .position:hover, .projection div:hover, .market div:hover { transform: translateY(-4px); }
}

/* Números do mês com ícone e minigráfico */
.stat { position: relative; overflow: hidden; gap: 4px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.stat-icon {
  width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--glass-inner); border: 1px solid var(--glass-border);
}
.stat-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stat-icon.in { color: var(--good); }
.stat-icon.out { color: var(--series-2); }
.stat-icon.bal { color: var(--series-1); }
.spark { width: 100%; height: 34px; display: block; margin-top: 2px; overflow: visible; }
.spark .line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark .end { stroke: var(--glass-strong); stroke-width: 2; }
.stat .trend { font-size: 0.72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; width: fit-content; background: var(--glass-inner); }

/* Gráfico por dia: barras de vidro, hoje (ou o maior dia) destacado */
.chart .bar-muted { fill: var(--bar-muted); }
.chart .bar-hi { fill: var(--series-1); filter: drop-shadow(0 6px 10px rgb(42 120 214 / 0.45)); }

/* PC: barra de ícones flutuante à esquerda, com o nome ao passar o mouse */
@media (min-width: 1024px) {
  :root { --sidebar: 104px; }
  body { padding-bottom: 24px; }
  .brand { display: flex; }
  /* Alinhada com a grade de cards (main tem até 1280px com 32px de respiro de cada lado). */
  .topbar { width: min(1216px, 100% - 64px); margin: 16px auto 0; top: 16px; }
  .tabbar {
    top: 50%; bottom: auto; left: 20px; right: auto; width: auto; transform: translateY(-50%);
    padding: 10px 8px; gap: 6px; border-radius: 999px; border-right: 1px solid var(--glass-border);
  }
  .side-brand, .side-note { display: none; }
  #nav-settings { order: 0; }
  .tabbar button { position: relative; width: 48px; height: 48px; padding: 0; justify-content: center; border-radius: 50%; }
  .tabbar button span {
    position: absolute; left: calc(100% + 12px); top: 50%; transform: translate(-6px, -50%);
    white-space: nowrap; pointer-events: none; opacity: 0;
    padding: 6px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; color: var(--text);
    background: var(--glass-strong); border: 1px solid var(--glass-border);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    transition: opacity 0.15s ease, transform 0.15s ease;
  }
  .tabbar button:hover span, .tabbar button:focus-visible span { opacity: 1; transform: translate(0, -50%); }
  .tabbar button.active { background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 20px -8px rgb(11 110 79 / 0.7); }
  .tabbar button:hover:not(.active) { background: var(--surface-2); }
}

/* Sem suporte a desfoque: vidro mais opaco para manter a leitura. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .card, .stat, .composer, .bubble.bot, dialog, .topbar, .tabbar { background: var(--glass-strong); }
}

/* Saudação digitada letra por letra, com cursor piscando */
.caret {
  display: inline-block; width: 0.08em; height: 0.95em; margin-left: 0.06em; vertical-align: -0.08em;
  background: var(--accent); border-radius: 2px; animation: caret-blink 1s steps(1) infinite;
  transition: opacity 0.4s ease;
}
.caret.done { opacity: 0; animation: none; }
@keyframes caret-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .caret { display: none; } }
#name-dialog input { font-size: 1.1rem; padding: 12px 14px; }

/* Celular estreito: só o ícone da marca, para caber Instalar e o mês no topo. */
@media (max-width: 480px) {
  .brand-name { display: none; }
  .topbar { gap: 8px; }
  .month-picker { gap: 2px; }
  .month-picker button { width: 32px; height: 32px; }
}
