/* Finanças — estilos. Mobile primeiro; barra lateral a partir de 900px. */

:root {
  color-scheme: light;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tabbar-h: 56px;
  --bg: #f2f1ed;
  --bg-sheet: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #ebeae5;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --hover: rgba(11, 11, 11, 0.04);
  --press: rgba(11, 11, 11, 0.08);
  --accent: #2a78d6;
  --accent-soft: #e2edfb;
  --accent-strong: #1c5cab;
  --track: #cde2fb;
  --deemph: #c9c8c0;
  /* paleta categórica (ordem fixa) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  /* estados (reservados: bom / atenção / crítico) */
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --warn-text: #845500;
  --critical: #d03b3b;
  --critical-text: #b42d2d;
  --seg-ink-yellow: #0b0b0b;
  --toast-bg: #1f1f1d;
  --toast-fg: #f0efec;
  --toast-action: #86b6ef;
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0d0d0d; --bg-sheet: #161615; --surface: #1a1a19; --surface-2: #272725;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.18);
    --hover: rgba(255, 255, 255, 0.05); --press: rgba(255, 255, 255, 0.09);
    --accent: #3987e5; --accent-soft: rgba(57, 135, 229, 0.18); --accent-strong: #86b6ef; --track: rgba(57, 135, 229, 0.26);
    --deemph: #45453f;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-text: #0ca30c; --warn-text: #fab219; --critical-text: #f08a8a; --seg-ink-yellow: #ffffff;
    --toast-bg: #f0efec; --toast-fg: #0b0b0b; --toast-action: #1c5cab;
    --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --bg-sheet: #161615; --surface: #1a1a19; --surface-2: #272725;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.18);
  --hover: rgba(255, 255, 255, 0.05); --press: rgba(255, 255, 255, 0.09);
  --accent: #3987e5; --accent-soft: rgba(57, 135, 229, 0.18); --accent-strong: #86b6ef; --track: rgba(57, 135, 229, 0.26);
  --deemph: #45453f;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-text: #0ca30c; --warn-text: #fab219; --critical-text: #f08a8a; --seg-ink-yellow: #ffffff;
  --toast-bg: #f0efec; --toast-fg: #0b0b0b; --toast-action: #1c5cab;
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; font: 16px/1.4 var(--font); background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
body:has(dialog[open]) { overflow: hidden; }
a { color: var(--accent); }
h1, h2, h3 { letter-spacing: -0.01em; }
.icon { width: 20px; height: 20px; flex-shrink: 0; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.tnum { font-variant-numeric: tabular-nums; }
.pos { color: var(--good-text); }
.neg { color: var(--critical-text); }
.pad-x { padding: 0 4px; margin: 0 0 10px; }
.warn-text { color: var(--warn-text); font-style: normal; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------------- estrutura */
.app { min-height: 100vh; min-height: 100dvh; }
.main {
  max-width: 1120px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px) max(16px, env(safe-area-inset-left));
}
.boot { padding: 48px 0; text-align: center; color: var(--muted); }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.8); backdrop-filter: blur(18px) saturate(1.8);
  border-top: 1px solid var(--border);
}
.nav .brand, .nav-sync { display: none; }
.nav-item {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--tabbar-h); font-size: 10.5px; font-weight: 500; color: var(--muted); text-decoration: none;
}
.nav-item .icon { width: 24px; height: 24px; }
.nav-item.on { color: var(--accent); }
.nav-dot { position: absolute; top: 7px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--critical); }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 236px minmax(0, 1fr); }
  .nav {
    position: sticky; top: 0; height: 100vh; flex-direction: column; gap: 2px; padding: 22px 12px;
    background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none;
    border-top: 0; border-right: 1px solid var(--border);
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 0 10px 18px; }
  .nav .brand .icon { width: 26px; height: 26px; color: var(--accent); }
  .nav-item { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; height: 42px; padding: 0 12px; border-radius: 10px; font-size: 15px; color: var(--text-2); }
  .nav-item .icon { width: 20px; height: 20px; }
  .nav-item:hover { background: var(--hover); }
  .nav-item.on { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
  .nav-dot { position: static; margin-left: auto; }
  .nav-sync { display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 10px 12px; font-size: 13px; color: var(--text-2); text-decoration: none; border-radius: 10px; }
  .nav-sync:hover { background: var(--hover); }
  .nav-sync.idle .icon { color: var(--good-text); }
  .nav-sync.error .icon, .nav-sync.off .icon, .nav-sync.offline .icon { color: var(--warn-text); }
  .nav-sync.syncing .icon { color: var(--accent); }
  .main { padding: 30px 36px 56px; }
}

/* ----------------------------------------------------------------- títulos */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 14px; }
.page-title { min-width: 0; }
.page-head h1 { font-size: 30px; line-height: 1.1; letter-spacing: -0.025em; margin: 0; font-weight: 750; }
.page-sub { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ------------------------------------------------------------------ botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: color-mix(in srgb, var(--surface) 92%, var(--text)); }
.btn:active { transform: scale(0.985); }
.btn .icon { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn-danger:hover { background: #b83232; border-color: #b83232; }
.btn-danger-ghost { background: transparent; color: var(--critical-text); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--critical) 10%, transparent); }
.btn-block { width: 100%; }
.btn-small { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 9px; gap: 4px; }
.btn-small .icon { width: 14px; height: 14px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-text { background: none; border: 0; color: var(--accent); font: inherit; font-size: 16px; padding: 6px 2px; cursor: pointer; }
.btn-text.strong { font-weight: 650; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  display: inline-grid; place-items: center; color: var(--text); cursor: pointer; padding: 0;
}
.link { background: none; border: 0; color: var(--accent); font: inherit; font-size: 14px; display: inline-flex; align-items: center; gap: 1px; cursor: pointer; padding: 2px 0; white-space: nowrap; }
.link .icon { width: 16px; height: 16px; }
.link.inline { padding: 0; font-size: inherit; }
.stack { display: grid; gap: 8px; }
.stack > * { min-width: 0; }
.stack .btn { justify-content: flex-start; white-space: normal; text-align: left; padding-top: 8px; padding-bottom: 8px; }
@media (max-width: 559px) {
  .btn-add { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
  .btn-add span { display: none; }
  .btn-add .icon { width: 22px; height: 22px; }
}

/* ---------------------------------------------------------------- filtros */
.filters { display: grid; gap: 8px; margin: 0 0 12px; }
.filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; max-width: 100%; padding: 1px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 13px;
  border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip .icon { width: 15px; height: 15px; }
.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip-count { font-size: 12px; opacity: 0.65; font-variant-numeric: tabular-nums; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper-label { min-width: 116px; text-align: center; font-weight: 600; font-size: 14px; }
.search {
  flex: 1 1 180px; display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 12px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; color: var(--muted);
}
.search .icon { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; font: inherit; font-size: 16px; color: var(--text); outline: none; padding: 0; -webkit-appearance: none; appearance: none; }
.select-inline { flex: 1 1 160px; min-width: 0; }
.select-inline select { min-height: 42px; }

.tabs { display: flex; gap: 2px; padding: 3px; margin: 0 0 14px; background: var(--surface-2); border-radius: 11px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; border: 0; background: none; font: inherit; font-size: 14px; padding: 7px 12px; border-radius: 9px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.10); }

.notice {
  display: flex; align-items: center; gap: 10px; width: 100%; margin: 0 0 12px; padding: 12px 14px; text-align: left;
  background: color-mix(in srgb, var(--warning) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent);
  border-radius: 14px; font: inherit; color: var(--text); cursor: pointer;
}
.notice > .icon:first-child { color: var(--warn-text); }
.notice span { flex: 1; font-size: 14px; }

/* ----------------------------------------------------------------- cartões */
/* itens de grelha nunca crescem para além da coluna (textos longos são cortados com "…") */
.grid > *, .day-groups > *, .filters > *, .rbars > *, .goal-grid > *, .kpis > *, .goals-mini > *, .sheet-content > * { min-width: 0; }
.grid { display: grid; gap: 12px; margin-bottom: 12px; }
.grid > .card { margin: 0; min-width: 0; }
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: 1 / -1; }
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; margin: 0; font-weight: 650; }
.card-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.card h2 { font-size: 16px; }

.kpis { display: grid; gap: 14px 12px; }
.kpis-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 700px) { .kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { min-width: 0; }
.stat-label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); }
.stat-value { font-size: 20px; font-weight: 650; letter-spacing: -0.015em; margin-top: 2px; white-space: nowrap; }
.stat-value.neg { color: var(--critical-text); }
.stat-value.pos { color: var(--good-text); }
.stat-value.warn { color: var(--warn-text); }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.big-num { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
/* em ecrãs estreitos, 3 indicadores viram linhas (rótulo à esquerda, valor à direita) */
@media (max-width: 559px) {
  .kpis-3 { grid-template-columns: 1fr; gap: 0; }
  .kpis-3 .stat { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "l v" "s v"; align-items: center; column-gap: 12px; padding: 9px 0; }
  .kpis-3 .stat + .stat { border-top: 1px solid var(--grid); }
  .kpis-3 .stat:first-child { padding-top: 0; }
  .kpis-3 .stat:last-child { padding-bottom: 0; }
  .kpis-3 .stat-label { grid-area: l; font-size: 14px; color: var(--text); }
  .kpis-3 .stat-value { grid-area: v; font-size: 17px; margin: 0; }
  .kpis-3 .stat-sub { grid-area: s; }
}

.hero-card { padding-top: 18px; }
.hero-label { font-size: 13.5px; color: var(--text-2); }
.hero { font-size: clamp(40px, 12vw, 56px); font-weight: 750; letter-spacing: -0.035em; line-height: 1.05; margin: 4px 0 6px; white-space: nowrap; }
.hero.neg { color: var(--critical-text); }
.hero-sub { color: var(--text-2); font-size: 14px; margin-bottom: 16px; }
.hero-sub strong { color: var(--text); }

/* ------------------------------------------------------------------ listas */
.day-groups { display: grid; gap: 2px; }
.day { margin: 0 0 12px; }
.day-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 14px 4px 6px; }
.day-head > span { display: inline-flex; align-items: center; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.card .list { border-radius: 12px; }
.row {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 11px 14px;
  background: none; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--grid); }
.row:hover, .row-job:hover { background: var(--hover); }
.row:active { background: var(--press); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-note { font-size: 12.5px; color: var(--muted); white-space: normal; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.row .chev { color: var(--muted); width: 18px; height: 18px; }
.row-job { cursor: pointer; }
.row-job .row-hit { position: absolute; inset: 0; background: none; border: 0; padding: 0; cursor: pointer; z-index: 0; }
.row-job .row-main, .row-job .row-end { position: relative; pointer-events: none; }
.row-job .row-end .btn { pointer-events: auto; position: relative; z-index: 1; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15.5px; white-space: nowrap; }
.amount.pos { color: var(--good-text); }
.amount.struck { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.amount small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 1px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px 2px 6px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge .icon { width: 13px; height: 13px; stroke-width: 2.4; }
.badge.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-text); }
.badge.warning { background: color-mix(in srgb, var(--warning) 24%, transparent); color: var(--warn-text); }
.badge.neutral { background: var(--surface-2); color: var(--text-2); }
.badge.muted { background: var(--surface-2); color: var(--muted); }
.badge.tiny { font-size: 11px; padding: 1px 6px 1px 4px; }

.empty { text-align: center; padding: 36px 16px; color: var(--text-2); }
.empty-icon { width: 34px; height: 34px; color: var(--muted); }
.empty-title { font-weight: 650; color: var(--text); margin: 8px 0 4px; }
.empty-text { margin: 0 0 14px; font-size: 14px; }

/* ---------------------------------------------------------------- gráficos */
.chart { width: 100%; min-width: 0; }
.chart-svg { display: block; overflow: visible; font-family: var(--font); }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart-svg .axis { stroke: var(--axis); stroke-width: 1; }
.chart-svg .tick, .chart-svg .xlabel { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .xlabel.strong { fill: var(--text); font-weight: 650; }
.chart-svg .cap { fill: var(--text-2); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-svg text, .chart-svg .bar { pointer-events: none; }
.chart-svg .hit { fill: transparent; outline: none; }
.chart-svg .col-group.hover .hit, .chart-svg .hit:focus-visible { fill: var(--hover); }
.chart-svg .col-group.hover .bar { filter: brightness(1.1); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--text-2); margin: 0 0 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }

.tooltip {
  position: fixed; left: 0; top: 0; z-index: 300; pointer-events: none; min-width: 150px; max-width: 260px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-pop); padding: 8px 11px; font-size: 13px;
}
.tt-title { color: var(--text-2); font-size: 12px; margin-bottom: 4px; }
.tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tt-key { display: inline-block; width: 12px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.tt-row strong { font-variant-numeric: tabular-nums; font-weight: 650; }
.tt-row span { color: var(--text-2); }

.rbars { display: grid; gap: 11px; }
.rbar { display: grid; gap: 4px; }
.rbar[role="button"] { cursor: pointer; border-radius: 8px; }
.rbar[role="button"]:hover .rbar-label > span { text-decoration: underline; text-underline-offset: 3px; }
.rbar-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; }
.rbar-label > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rbar-label small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.rbar-track { display: flex; align-items: center; gap: 8px; }
.rbar-fill { display: block; height: 10px; min-width: 3px; border-radius: 0 4px 4px 0; }
.rbar-val { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

.segbar { display: flex; gap: 2px; height: 28px; margin: 12px 0 10px; }
.seg { display: flex; align-items: center; min-width: 3px; padding: 0 6px; border-radius: 4px; color: #fff; font-size: 12px; font-weight: 650; white-space: nowrap; outline-offset: 1px; }
.seg .ink-dark { color: var(--seg-ink-yellow); }

.meter { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.meter.good { background: color-mix(in srgb, var(--good) 22%, transparent); }
.meter.good i { background: var(--good); }

.table-view { margin-top: 8px; }
.table-view summary { display: inline-block; cursor: pointer; color: var(--accent); font-size: 14px; padding: 6px 0; list-style: none; }
.table-view summary::-webkit-details-marker { display: none; }
.table-view[open] summary { margin-bottom: 4px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
th { font-weight: 600; color: var(--text-2); font-size: 12.5px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 650; border-bottom: 0; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover { background: var(--hover); }

/* ----------------------------------------------------- objetivos e outros */
.goal-grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .goal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.goal { margin: 0; }
.goal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.goal-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.goal-nums { display: flex; align-items: baseline; gap: 6px; margin: 10px 0 8px; }
.goal-nums strong { font-size: 22px; letter-spacing: -0.02em; }
.goal-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.goals-mini { display: grid; gap: 12px; }
.goal-mini-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 6px; }
.goal-mini-head > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lock-card { max-width: 380px; margin: 12vh auto 0; text-align: center; display: grid; gap: 10px; }
.lock-card .form { text-align: left; }
.lock-card h1 { margin: 0; font-size: 26px; }
.lock-card p { margin: 0 0 6px; }
.lock-icon .icon { width: 44px; height: 44px; color: var(--accent); }
.lock-card .link { justify-self: center; }
.welcome h2 { margin: 0 0 6px; }
.welcome p { margin: 0 0 14px; }
.sync-line { display: flex; gap: 8px; align-items: center; margin: 0 0 8px; font-size: 14px; }
.sync-line.ok .icon { color: var(--good-text); }
.sync-line.err { color: var(--critical-text); }
.sync-line.warn .icon { color: var(--warn-text); }
.sync-line.spin .icon { animation: spin 1s linear infinite; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; font-size: 14px; }
.steps li { display: flex; gap: 10px; }
.steps .icon { color: var(--accent); margin-top: 1px; }

/* -------------------------------------------------------- folhas (modais) */
dialog.sheet { border: 0; padding: 0; margin: 0; width: 100%; height: 100%; max-width: none; max-height: none; background: transparent; color: var(--text); overflow: hidden; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.38); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-sheet); border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom);
  box-shadow: var(--shadow-pop); animation: sheet-up 0.22s ease-out;
}
@media (min-width: 700px) {
  .sheet-body { left: 50%; top: 50%; right: auto; bottom: auto; width: min(540px, 92vw); max-height: 86vh; border-radius: 18px; transform: translate(-50%, -50%); animation: sheet-pop 0.16s ease-out; padding-bottom: 0; }
  .sheet-small .sheet-body { width: min(420px, 92vw); }
}
.sheet-head {
  position: sticky; top: 0; z-index: 1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 14px; background: var(--bg-sheet); border-bottom: 1px solid var(--grid);
}
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 650; text-align: center; }
.sheet-content { padding: 16px; display: grid; gap: 14px; }
.sheet-msg { margin: 0; color: var(--text-2); }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > label { display: grid; gap: 6px; }
.label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.hint { color: var(--muted); font-size: 12px; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 11px; -webkit-appearance: none; appearance: none;
}
input[type="date"] { display: block; min-width: 0; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
textarea { resize: vertical; line-height: 1.4; }
select {
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23898781' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.search input:focus { outline: none; }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field.error input, .field.error select, .field.error textarea { border-color: var(--critical); }
.field-error { margin: 0; color: var(--critical-text); font-size: 13px; }
.form-error { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; color: var(--critical-text); background: color-mix(in srgb, var(--critical) 10%, transparent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; flex-shrink: 0; accent-color: var(--accent); }
.seg-ctl { display: flex; padding: 3px; background: var(--surface-2); border-radius: 11px; }
.seg-ctl label { flex: 1; position: relative; }
.seg-ctl input { position: absolute; opacity: 0; pointer-events: none; }
.seg-ctl span { display: block; padding: 8px; border-radius: 9px; text-align: center; font-size: 15px; color: var(--text-2); cursor: pointer; }
.seg-ctl input:checked + span { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.seg-ctl input:focus-visible + span { outline: 2px solid var(--accent); }

/* ------------------------------------------------------------------ avisos */
.toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 400; display: grid; gap: 8px; width: min(92vw, 440px); pointer-events: none;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
}
@media (min-width: 900px) { .toasts { bottom: 24px; } }
.toast {
  pointer-events: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px;
  background: var(--toast-bg); color: var(--toast-fg); border-radius: 12px; font-size: 14.5px; box-shadow: var(--shadow-pop);
  animation: sheet-up 0.2s ease-out; transition: opacity 0.2s;
}
.toast button { background: none; border: 0; color: var(--toast-action); font: inherit; font-weight: 650; cursor: pointer; padding: 4px; }
.toast.out { opacity: 0; }

@keyframes sheet-up { from { transform: translateY(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes sheet-pop { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print {
  .nav, .page-actions, .filters, .tabs, .toasts { display: none !important; }
  .main { padding: 0; }
}
