/* =========================================================================
   MyMon — design system (CSS puro, mobile-first)
   Tema: tokens em :root (claro). Escuro via prefers-color-scheme (quando
   não há escolha manual) ou html[data-theme="dark"].
   ========================================================================= */

/* ---------- Tokens ---------- */
:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", "Segoe UI Mono", Menlo, Consolas, monospace;

  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 999px;

  --tap: 44px;
  --topbar-h: 56px;
  --tabbar-h: 64px;
  --sidebar-w: 256px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: 180ms;

  /* Cores — claro */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --surface-3: #e4e8ee;
  --border: #e1e5eb;
  --border-strong: #cbd2dc;
  --text: #0f172a;
  --text-muted: #556070;
  --text-subtle: #6b7686;
  --primary: #1d4ed8;
  --primary-hover: #1a43bb;
  --primary-soft: #e6edfd;
  --on-primary: #ffffff;
  --income: #15803d;
  --income-soft: #e3f4e9;
  --expense: #c62828;
  --expense-soft: #fbe7e7;
  --warning: #b45309;
  --warning-soft: #fdf0dd;
  --info: #1d4ed8;
  --info-soft: #e6edfd;
  --focus: #2563eb;
  --overlay: rgba(15, 23, 42, .45);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .18);
  --topbar-bg: rgba(255, 255, 255, .88);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #121a2b;
    --surface-2: #1a2338;
    --surface-3: #232e47;
    --border: #243049;
    --border-strong: #33415f;
    --text: #e7ebf3;
    --text-muted: #a3adbf;
    --text-subtle: #8a95a9;
    --primary: #7b9bff;
    --primary-hover: #95afff;
    --primary-soft: #1c2a4f;
    --on-primary: #0b1120;
    --income: #4ade80;
    --income-soft: #12301f;
    --expense: #f87171;
    --expense-soft: #3a1717;
    --warning: #fbbf24;
    --warning-soft: #3a2a0b;
    --info: #7b9bff;
    --info-soft: #1c2a4f;
    --focus: #93b0ff;
    --overlay: rgba(0, 0, 0, .6);
    --shadow-sm: none;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .02);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    --topbar-bg: rgba(18, 26, 43, .88);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #121a2b;
  --surface-2: #1a2338;
  --surface-3: #232e47;
  --border: #243049;
  --border-strong: #33415f;
  --text: #e7ebf3;
  --text-muted: #a3adbf;
  --text-subtle: #8a95a9;
  --primary: #7b9bff;
  --primary-hover: #95afff;
  --primary-soft: #1c2a4f;
  --on-primary: #0b1120;
  --income: #4ade80;
  --income-soft: #12301f;
  --expense: #f87171;
  --expense-soft: #3a1717;
  --warning: #fbbf24;
  --warning-soft: #3a2a0b;
  --info: #7b9bff;
  --info-soft: #1c2a4f;
  --focus: #93b0ff;
  --overlay: rgba(0, 0, 0, .6);
  --shadow-sm: none;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .02);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  --topbar-bg: rgba(18, 26, 43, .88);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { line-height: 1.25; font-weight: 650; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--font-num); font-size: .9em; }
small { font-size: var(--fs-sm); }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: var(--sp-6) 0; }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.text-muted { color: var(--text-muted); }
.text-income { color: var(--income); }
.text-expense { color: var(--expense); }
.eyebrow {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.skip-link {
  position: absolute;
  left: var(--sp-3);
  top: calc(var(--safe-top) + var(--sp-2));
  z-index: 100;
  padding: var(--sp-2) var(--sp-4);
  background: var(--primary);
  color: var(--on-primary);
  border-radius: var(--radius-sm);
}
/* Escondido até receber foco pelo teclado. translateY não bastava no PWA do iOS:
   com a safe area grande o link ainda aparecia sob a barra de status. */
.skip-link:not(:focus-visible) {
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Ícones ---------- */
.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
}

/* ---------- Valores monetários ---------- */
.money {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: filter var(--dur) var(--ease);
}
html.hide-values .money {
  filter: blur(7px);
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}
html.hide-values .money::selection { background: transparent; }

.show-when-hidden, html.hide-values .show-when-visible { display: none; }
html.hide-values .show-when-hidden { display: block; }

.show-when-dark { display: none; }
:root[data-theme="dark"] .show-when-dark { display: block; }
:root[data-theme="dark"] .show-when-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .show-when-dark { display: block; }
  :root:not([data-theme="light"]) .show-when-light { display: none; }
}

/* ---------- Layout logado ---------- */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) calc(var(--sp-3) + var(--safe-right)) 0 calc(var(--sp-4) + var(--safe-left));
  background: var(--topbar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { flex: none; }
.topbar__brand img { border-radius: 8px; }
.topbar__title {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-lg);
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__actions { display: flex; gap: var(--sp-1); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--primary); }

.content {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--sp-4) calc(var(--sp-4) + var(--safe-right)) calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-6)) calc(var(--sp-4) + var(--safe-left));
}
.content:focus { outline: none; }

/* Sidebar (somente desktop) */
.sidebar { display: none; }

/* Barra inferior (celular) */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: stretch;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--topbar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}
.tabbar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: var(--tap);
  padding: var(--sp-1) 0;
  border: 0;
  background: none;
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 500;
  text-decoration: none;
}
.tabbar__item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar__item:hover { text-decoration: none; color: var(--text); }
.tabbar__item.is-active { color: var(--primary); }
.tabbar__add-btn {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-top: -18px;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 6px 18px rgba(29, 78, 216, .35);
  transition: transform var(--dur) var(--ease);
}
.tabbar__add-btn .icon { width: 26px; height: 26px; }
.tabbar__add:active .tabbar__add-btn { transform: scale(.94); }

/* ---------- Sheet (menu "Mais") ---------- */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.sheet::backdrop { background: var(--overlay); }
.sheet[open] { animation: sheet-in 240ms var(--ease); }
.sheet[open]::backdrop { animation: fade-in 240ms var(--ease); }
.sheet__panel {
  display: flex;
  flex-direction: column;
  max-height: 88dvh;
  padding-bottom: calc(var(--sp-4) + var(--safe-bottom));
}
.sheet__handle {
  width: 40px; height: 5px;
  margin: var(--sp-2) auto 0;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}
.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-5);
}
.sheet__header h2 { font-size: var(--fs-lg); }
.sheet__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--sp-4);
}
.sheet__group {
  margin: var(--sp-4) var(--sp-1) var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}
.sheet__group:first-child { margin-top: var(--sp-1); }
.sheet__grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--sp-2);
}
.sheet__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-height: 76px;
  padding: var(--sp-2);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-align: center;
}
.sheet__item:hover { text-decoration: none; background: var(--surface-3); }
.sheet__item .icon { color: var(--primary); }
.sheet__item.is-active { background: var(--primary-soft); color: var(--primary); }
.sheet__logout { margin-top: var(--sp-5); }

@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Desktop ---------- */
@media (min-width: 1024px) {
  .tabbar, .topbar__brand, .sheet { display: none; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 35;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    padding: var(--sp-4) var(--sp-3);
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .app-shell { margin-left: var(--sidebar-w); }
  .topbar { padding-left: var(--sp-8); padding-right: var(--sp-6); }
  .topbar__title { font-size: var(--fs-xl); }
  .content { padding: var(--sp-6) var(--sp-8) var(--sp-8); }
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-1) var(--sp-3) var(--sp-3);
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: 700;
}
.brand:hover { text-decoration: none; }
.brand__logo { border-radius: 9px; }
.sidenav {
  flex: 1;
  overflow-y: auto;
  margin: 0 calc(var(--sp-3) * -1);
  padding: 0 var(--sp-3);
}
.sidenav__group {
  margin: var(--sp-3) var(--sp-3) 2px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}
.sidenav__group:first-child { margin-top: 0; }
.sidenav__list { list-style: none; margin: 0; padding: 0; }
.sidenav__link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 36px;
  padding: 6px var(--sp-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-align: left;
}
.sidenav__link .icon { width: 20px; height: 20px; }
.sidenav__link:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }
.sidenav__link.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar__footer {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-3);
  margin-top: var(--sp-3);
}
.sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-1) 0 var(--sp-1) var(--sp-3);
  min-width: 0;
}
.sidebar__user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sidebar__user-text strong, .sidebar__user-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__user-text strong { font-size: var(--fs-sm); }
.sidebar__user-text small { font-size: var(--fs-xs); color: var(--text-subtle); }
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px; height: 34px;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}
.sidebar__logout { margin-left: auto; }
.sidebar__logout:hover { color: var(--expense); background: var(--expense-soft); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--sp-4);
}
.card__title { font-size: var(--fs-md); font-weight: 650; margin-bottom: var(--sp-3); }
@media (min-width: 768px) { .card { padding: var(--sp-5); } }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.page-head__title { font-size: var(--fs-xl); }

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}
.kpi { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; padding: var(--sp-3) var(--sp-4); }
.kpi--featured, .kpi--wide { grid-column: span 2; }
.kpi__head { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.kpi__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
}
.kpi__icon .icon { width: 18px; height: 18px; }
.kpi__label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); line-height: 1.3; }
.kpi__value {
  font-size: var(--fs-lg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}
.kpi--featured .kpi__value { font-size: var(--fs-2xl); }
.kpi__hint { font-size: var(--fs-xs); color: var(--text-subtle); }
.kpi--income .kpi__icon { background: var(--income-soft); color: var(--income); }
.kpi--income .kpi__value { color: var(--income); }
.kpi--expense .kpi__icon { background: var(--expense-soft); color: var(--expense); }
.kpi--expense .kpi__value { color: var(--expense); }
.kpi--featured .kpi__icon { background: var(--primary-soft); color: var(--primary); }

@media (min-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); }
  .kpi { padding: var(--sp-4) var(--sp-5); }
}
@media (min-width: 1280px) {
  .kpi--featured .kpi__value { font-size: 2rem; }
}

/* Progresso */
.progress {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
  color: var(--primary);
}
.progress::-webkit-progress-bar { background: var(--surface-3); border-radius: var(--radius-pill); }
.progress::-webkit-progress-value { background: var(--primary); border-radius: var(--radius-pill); }
.progress::-moz-progress-bar { background: var(--primary); border-radius: var(--radius-pill); }

/* Gráficos */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}
@media (min-width: 768px) { .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); } }
.chart-card { min-height: 240px; display: flex; flex-direction: column; }
.chart-card .empty-state { flex: 1; }

/* Estado vazio */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.empty-state__icon { width: 36px; height: 36px; color: var(--text-subtle); }
.empty-state--page {
  max-width: 560px;
  margin: var(--sp-8) auto;
  padding: var(--sp-8) var(--sp-5);
  border-style: solid;
  background: var(--surface);
}
.empty-state--page h2 { font-size: var(--fs-xl); color: var(--text); }
.empty-state--page .empty-state__icon { width: 48px; height: 48px; color: var(--primary); }
.empty-inline { padding: var(--sp-2) 0; font-size: var(--fs-sm); }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform 80ms var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-busy="true"] { opacity: .6; cursor: not-allowed; }
.btn .icon { width: 20px; height: 20px; }
.btn--primary { background: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--surface-2); }
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--expense); color: #fff; }
.btn--danger-ghost { background: transparent; color: var(--expense); border-color: transparent; }
.btn--danger-ghost:hover { background: var(--expense-soft); }
.btn--block { width: 100%; }
.btn--lg { min-height: 52px; font-size: var(--fs-md); }
.btn--sm { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
@media (pointer: coarse) { .btn--sm { min-height: var(--tap); } }

/* ---------- Formulários ---------- */
.form { display: flex; flex-direction: column; gap: var(--sp-4); }
.form--narrow { max-width: 420px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.field__hint { font-size: var(--fs-xs); color: var(--text-subtle); }
.field__error { font-size: var(--fs-xs); color: var(--expense); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], input[type="tel"], input[type="url"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px var(--sp-3);
  font-size: 16px; /* >= 16px evita zoom automático no iOS */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
textarea { min-height: 96px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  outline: none;
}
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--expense); }

/* Controle segmentado (radios) */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin: 0;
  padding: var(--sp-1);
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.segmented__option { position: relative; }
.segmented__option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented__option span {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: 0 var(--sp-4);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-muted);
}
.segmented__option span .icon { width: 18px; height: 18px; }
.segmented__option input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }
.segmented__option input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---------- Alertas / badges ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
}
.alert .icon { width: 20px; height: 20px; margin-top: 1px; }
.alert--error { background: var(--expense-soft); color: var(--expense); }
.alert--info { background: var(--info-soft); color: var(--info); }
.alert--success { background: var(--income-soft); color: var(--income); }
.badge {
  display: inline-block;
  padding: 2px var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  vertical-align: middle;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge--primary { background: var(--primary-soft); color: var(--primary); }
.badge--income { background: var(--income-soft); color: var(--income); }
.badge--expense { background: var(--expense-soft); color: var(--expense); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  z-index: 60;
  left: calc(var(--sp-3) + var(--safe-left));
  right: calc(var(--sp-3) + var(--safe-right));
  top: calc(var(--safe-top) + var(--topbar-h) + var(--sp-2));
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}
.layout-auth .toasts { top: calc(var(--safe-top) + var(--sp-3)); }
@media (min-width: 640px) {
  .toasts { left: auto; width: 380px; }
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-2) var(--sp-3) var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 220ms var(--ease);
}
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity 200ms, transform 200ms; }
.toast__icon { width: 20px; height: 20px; margin-top: 2px; }
.toast__msg { flex: 1; font-size: var(--fs-sm); padding-top: 2px; }
.toast__close {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  margin: -4px 0;
  border: 0; border-radius: var(--radius-pill);
  background: none; color: var(--text-subtle);
}
.toast__close .icon { width: 18px; height: 18px; }
.toast--success { border-left-color: var(--income); }
.toast--success .toast__icon { color: var(--income); }
.toast--error { border-left-color: var(--expense); }
.toast--error .toast__icon { color: var(--expense); }
.toast--info { border-left-color: var(--info); }
.toast--info .toast__icon { color: var(--info); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Tabelas responsivas ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: var(--sp-3); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-subtle); background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .is-income { color: var(--income); }
.table .is-expense { color: var(--expense); }
/* Em telas pequenas, .table--stack vira lista de cartões (usar data-label nos <td>) */
@media (max-width: 639px) {
  .table--stack thead { display: none; }
  .table--stack tr { display: block; padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); }
  .table--stack tr:last-child { border-bottom: 0; }
  .table--stack td { display: flex; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-1) 0; border: 0; }
  .table--stack td::before { content: attr(data-label); color: var(--text-subtle); font-size: var(--fs-xs); }
  .table--stack .num { text-align: right; }
}

/* ---------- Listas de itens (configurações) ---------- */
.item-list { list-style: none; margin: 0 0 var(--sp-4); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); }
.item-list__row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.item-list__row:last-child { border-bottom: 0; }
.item-list__icon {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
}
.item-list__icon .icon { width: 20px; height: 20px; }
.item-list__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-list__text strong { font-size: var(--fs-sm); font-weight: 600; }
.item-list__text small { font-size: var(--fs-xs); color: var(--text-subtle); }
@media (max-width: 479px) {
  .item-list__row form .btn span { display: none; }
}

/* ---------- Configurações ---------- */
.settings { display: grid; gap: var(--sp-4); max-width: 760px; }
.section__title { font-size: var(--fs-lg); margin-bottom: var(--sp-1); }
.section__subtitle { font-size: var(--fs-md); margin: var(--sp-4) 0 var(--sp-1); }
.section__desc { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--sp-4); }
.section__desc--small { font-size: var(--fs-xs); margin: var(--sp-4) 0 0; }
.passkey-register { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-3); }
.passkey-register .field { width: 100%; max-width: 420px; }
.passkey-register .alert { width: 100%; }

/* ---------- Login / páginas sem navegação ---------- */
.layout-auth { background: var(--bg); }
.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-5);
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + var(--sp-6)) calc(var(--sp-4) + var(--safe-right)) calc(var(--safe-bottom) + var(--sp-6)) calc(var(--sp-4) + var(--safe-left));
}
.auth__brand { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); font-size: var(--fs-xl); font-weight: 700; }
.auth__brand img { border-radius: 16px; box-shadow: var(--shadow); }
.auth__card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-6) var(--sp-5); }
.auth__title { font-size: var(--fs-xl); }
.auth__subtitle { margin-top: calc(var(--sp-3) * -1); font-size: var(--fs-sm); }
.auth__foot { font-size: var(--fs-xs); text-align: center; max-width: 320px; }
.passkey-login { display: flex; flex-direction: column; gap: var(--sp-4); }
.divider {
  display: flex; align-items: center; gap: var(--sp-3);
  font-size: var(--fs-xs); color: var(--text-subtle);
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.error-page { text-align: center; align-items: center; }
.error-page__code { font-size: 3rem; font-weight: 800; color: var(--primary); line-height: 1; letter-spacing: -.02em; }

/* ---------- Movimento reduzido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Impressão ---------- */
@media print {
  .sidebar, .tabbar, .topbar__actions, .toasts, .sheet { display: none !important; }
  .app-shell { margin: 0 !important; }
  .content { padding: 0 !important; }
}

/* ---------- Complementos: configurações e login ---------- */
.theme-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
.codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2);
  margin: var(--sp-3) 0 var(--sp-4);
  padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-8);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.codes code { font-size: var(--fs-md); letter-spacing: .04em; user-select: all; -webkit-user-select: all; }
.item-list + form { margin-top: calc(var(--sp-2) * -1); }
.recovery { border-top: 1px solid var(--border); padding-top: var(--sp-3); }
.recovery summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  list-style: none;
}
.recovery summary::-webkit-details-marker { display: none; }
.recovery summary::after { content: "›"; margin-left: auto; font-size: 1.25rem; transition: transform var(--dur) var(--ease); }
.recovery[open] summary::after { transform: rotate(90deg); }
.recovery .form { margin-top: var(--sp-2); }

/* ---------- Fase 1.5: multiusuário, convites, sugestões, termos ---------- */
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.section__title:has(> .icon) { display: flex; align-items: center; gap: var(--sp-2); }
.section__title > .icon { color: var(--primary); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.btn-row .btn { flex: 1 1 200px; }
.btn--whatsapp { background: #0e7a3c; color: #fff; }
.btn--whatsapp:hover { background: #0b6632; color: #fff; }
.check { display: flex; align-items: flex-start; gap: var(--sp-3); font-weight: 400 !important; font-size: var(--fs-sm); cursor: pointer; min-height: var(--tap); }
.check input { flex: none; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--primary); }
.check input[aria-invalid="true"] { outline: 2px solid var(--expense); outline-offset: 1px; }

/* Convite */
.invite-notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); font-size: var(--fs-sm); }
.invite-notes li { display: flex; gap: var(--sp-3); align-items: flex-start; }
.invite-notes .icon { width: 20px; height: 20px; color: var(--primary); margin-top: 1px; }
.invite-expiry { font-size: var(--fs-xs); margin-top: calc(var(--sp-2) * -1); }
.invite-invalid__icon { width: 48px; height: 48px; color: var(--text-subtle); }

/* Administração */
.admin { display: grid; gap: var(--sp-4); max-width: 860px; }
.invite-ready { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); display: flex; flex-direction: column; gap: var(--sp-3); }
.invite-ready .section__title { margin: 0; }
.invite-ready input[readonly] { font-family: var(--font-num); font-size: 16px; background: var(--surface-2); }
.item-list__row .avatar { flex: none; }
.item-list__text strong .badge { margin-left: 2px; }
.item-list__text small + small { margin-top: 1px; }

/* Sugestões */
.feedback { display: grid; gap: var(--sp-4); max-width: 760px; }
.segmented--fill { display: flex; }
.segmented--fill .segmented__option { flex: 1; }
.segmented--fill .segmented__option span { width: 100%; justify-content: center; padding: 0 var(--sp-2); min-height: var(--tap); }
.segmented--scroll { display: flex; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.segmented--scroll::-webkit-scrollbar { display: none; }
.segmented--scroll .segmented__option span { white-space: nowrap; min-height: var(--tap); }
.segmented .count { font-size: var(--fs-xs); color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.feedback-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.feedback-list:not(.feedback-list--admin) .feedback-item { padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); }
.feedback-item { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.feedback-item__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.feedback-item__type { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-sm); font-weight: 600; }
.feedback-item__type .icon { width: 18px; height: 18px; color: var(--primary); }
.feedback-item__date { margin-left: auto; font-size: var(--fs-xs); }
.feedback-item__msg { font-size: var(--fs-sm); overflow-wrap: anywhere; }
.feedback-item code { overflow-wrap: anywhere; }
.feedback-item__reply { padding: var(--sp-2) var(--sp-3); border-left: 3px solid var(--primary); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--primary-soft); font-size: var(--fs-sm); }
.feedback-item__reply strong { color: var(--primary); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; }
.feedback-item__form { display: grid; gap: var(--sp-3); margin-top: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
@media (min-width: 768px) {
  .feedback-item__form { grid-template-columns: 180px 1fr auto; align-items: end; }
}

/* Configurações: boas-vindas e zona de perigo */
.welcome-card { border-color: var(--primary); background: linear-gradient(var(--primary-soft), var(--surface) 70%); }
.welcome-steps { margin: 0 0 var(--sp-2); padding-left: var(--sp-5); display: grid; gap: var(--sp-2); font-size: var(--fs-sm); }
.danger-zone { border-color: var(--expense); }
.danger-zone .section__title { color: var(--expense); }
.danger-zone .section__subtitle { margin-top: var(--sp-2); }
.plan-line { color: var(--text-subtle); }
#sec-security, #sec-recovery { scroll-margin-top: calc(var(--topbar-h) + var(--safe-top) + var(--sp-3)); }

/* Navegação: atalho de sugestão e links legais */
.sidebar__feedback {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 36px; margin-bottom: var(--sp-2); padding: 6px var(--sp-3);
  border-radius: var(--radius-sm); color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500;
}
.sidebar__feedback .icon { width: 20px; height: 20px; }
.sidebar__feedback:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }
.sheet__feedback { margin-top: var(--sp-5); }
.sheet__feedback + .sheet__logout { margin-top: var(--sp-2); }
.legal-links { font-size: var(--fs-xs); color: var(--text-subtle); text-align: center; }
.legal-links a { color: var(--text-muted); display: inline-block; padding: var(--sp-2) var(--sp-1); }
.legal-links--sidebar { margin-top: var(--sp-2); text-align: left; padding-left: var(--sp-3); }
.legal-links--sidebar a { padding: 2px 0; }
.sheet__body .legal-links { margin-top: var(--sp-2); }

/* Termos e privacidade */
.legal { width: 100%; max-width: 680px; padding: var(--sp-6) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); font-size: var(--fs-sm); }
.legal h2 { font-size: var(--fs-md); margin-top: var(--sp-3); }
.legal ul { margin: 0; padding-left: var(--sp-5); }
.legal__draft { display: flex; gap: var(--sp-2); align-items: flex-start; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); background: var(--warning-soft); color: var(--warning); font-weight: 700; font-size: var(--fs-xs); letter-spacing: .02em; }
.legal__draft .icon { width: 18px; height: 18px; }
.legal__back { margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px solid var(--border); text-align: center; }
