/* Controle Financeiro — mobile-first */

:root {
  --bg: #0b1220;
  --bg-elevated: #111827;
  --bg-card: #151f32;
  --bg-soft: #1a2438;
  --border: rgba(148, 163, 184, 0.16);
  --text: #e5eefc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-press: #2563eb;
  --income: #22c55e;
  --expense: #f43f5e;
  --balance: #38bdf8;
  --danger: #ef4444;
  --success-bg: rgba(34, 197, 94, 0.12);
  --error-bg: rgba(244, 63, 94, 0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: 56px;
  --bottom-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(59, 130, 246, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(34, 197, 94, 0.08), transparent 45%),
    var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
img { max-width: 100%; }

/* ---------- Guest / Login ---------- */
.guest-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.guest-shell {
  width: 100%;
  max-width: 420px;
}

.login-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent 40%), var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px 22px 24px;
  box-shadow: var(--shadow);
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.logo-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, #3b82f6, #22c55e);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.35);
}

.login-brand h1 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.login-brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-hint {
  margin: 18px 0 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.login-hint code {
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.8rem;
}

/* ---------- App shell ---------- */
.app-body {
  min-height: 100vh;
  padding-bottom: calc(var(--bottom-h) + var(--safe-bottom) + 12px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: 44px 1fr 40px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: rgba(11, 18, 32, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-title h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--income));
  flex-shrink: 0;
}

.topbar-filter {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.topbar-filter:active {
  background: rgba(255, 255, 255, 0.08);
}

.topbar-filter[aria-expanded="true"] {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  color: #dbeafe;
}

.topbar-filter .funnel-icon {
  display: block;
}

.topbar-filter-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 0 0 2px rgba(11, 18, 32, 0.9);
}

.topbar-filter-badge:empty,
.topbar-filter-badge[hidden] {
  display: none;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:active { background: rgba(255,255,255,0.06); }

.sandwich-lines {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 20px;
}

.sandwich-lines span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

body.menu-open .sandwich-lines span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
body.menu-open .sandwich-lines span:nth-child(2) {
  opacity: 0;
}
body.menu-open .sandwich-lines span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Side sandwich menu */
.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  z-index: 50;
}

.side-menu {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(86vw, 320px);
  z-index: 60;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(-105%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  padding: 16px 14px calc(16px + var(--safe-bottom));
}

body.menu-open .side-menu {
  transform: translateX(0);
}

.side-menu-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  padding: 6px 4px 14px;
  border-bottom: 1px solid var(--border);
}

.side-menu-label {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.side-menu-name {
  margin: 2px 0 0;
  font-weight: 700;
  font-size: 1.1rem;
}

.side-nav {
  display: grid;
  gap: 8px;
  flex: 1;
}

.side-link {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.side-link strong {
  display: block;
  font-size: 1rem;
}

.side-link small {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.side-link.is-active,
.side-link:hover {
  background: var(--bg-soft);
  border-color: var(--border);
}

.side-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.1rem;
}

.side-icon.outcome { background: rgba(244, 63, 94, 0.15); color: var(--expense); }
.side-icon.income { background: rgba(34, 197, 94, 0.15); color: var(--income); }
.side-icon.balance { background: rgba(56, 189, 248, 0.15); color: var(--balance); }
.side-icon.graphs { background: rgba(167, 139, 250, 0.16); color: #c4b5fd; }

.side-account {
  margin-top: auto;
  padding-top: 12px;
  display: grid;
  gap: 10px;
}

.side-logout {
  margin: 0;
}

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: calc(var(--bottom-h) + var(--safe-bottom));
  padding: 0 8px var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(11, 18, 32, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.bottom-nav a span {
  font-size: 1rem;
  line-height: 1;
}

.bottom-nav a.is-active {
  color: var(--text);
}

.bottom-nav a.is-active span {
  color: var(--primary);
}

/* Page content */
.page {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 14px 14px 24px;
  display: grid;
  gap: 14px;
}

/* Cards / forms */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-title {
  margin: 0 0 14px;
  font-size: 1rem;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  min-height: 46px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus {
  border-color: rgba(59, 130, 246, 0.55);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.form-grid,
.filters-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.field-full,
.field-grow {
  grid-column: 1 / -1;
}

.form-card .btn {
  margin-top: 14px;
}

.filters-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-lg { min-height: 48px; font-size: 1rem; }

.btn-primary {
  background: linear-gradient(180deg, #4f8ff7, var(--primary));
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.28);
}

.btn-primary:hover { background: var(--primary-press); }

.btn-secondary {
  background: var(--bg-soft);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

/* Alerts */
.alert {
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.92rem;
  border: 1px solid transparent;
}

.alert-error {
  background: var(--error-bg);
  border-color: rgba(244, 63, 94, 0.3);
  color: #fecdd3;
}

.alert-success {
  background: var(--success-bg);
  border-color: rgba(34, 197, 94, 0.3);
  color: #bbf7d0;
}

/* Stats */
.summary-row {
  display: grid;
  gap: 12px;
}

.stat-card,
.net-card {
  border-radius: var(--radius);
  padding: 16px 18px;
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.stat-card.expense { border-color: rgba(244, 63, 94, 0.28); }
.stat-card.income { border-color: rgba(34, 197, 94, 0.28); }
.stat-card.balance { border-color: rgba(56, 189, 248, 0.28); }

.stat-label {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.stat-value {
  margin: 6px 0 2px;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.stat-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.net-card.is-positive .stat-value { color: var(--income); }
.net-card.is-negative .stat-value { color: var(--expense); }

/* Transaction list */
.tx-list,
.wallet-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.tx-item,
.wallet-item {
  padding: 12px;
  border-radius: 14px;
  background: var(--bg-soft);
  border: 1px solid transparent;
}

.tx-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}

.tx-main {
  min-width: 0;
}

.tx-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.tx-delete-form {
  margin: 0;
}

.tx-action-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.tx-action-btn:active {
  transform: scale(0.96);
}

.tx-action-btn.tx-edit:hover,
.tx-action-btn.tx-edit:focus-visible {
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.45);
  background: rgba(59, 130, 246, 0.12);
}

.tx-action-btn.tx-delete:hover,
.tx-action-btn.tx-delete:focus-visible {
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.4);
  background: rgba(244, 63, 94, 0.12);
}

.tx-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.tx-desc {
  font-size: 0.95rem;
}

.tx-amount {
  font-weight: 800;
  white-space: nowrap;
}

.tx-amount.is-expense { color: var(--expense); }
.tx-amount.is-income { color: var(--income); }

.tx-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--chip, #64748b) 18%, transparent);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--chip, #64748b) 35%, transparent);
  font-size: 0.75rem;
  font-weight: 600;
}

.chip.muted {
  opacity: 0.92;
}

.tx-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag-pill {
  font-size: 0.75rem;
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 999px;
  padding: 2px 8px;
}

.empty-state {
  margin: 0;
  color: var(--text-muted);
  text-align: center;
  padding: 18px 8px;
}

/* Graph options + layouts */
.graph-options {
  display: grid;
  gap: 12px;
}

.graph-options-grid {
  display: grid;
  gap: 14px;
}

.graph-option-group {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.graph-option-group legend {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.graph-options-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
}

.segmented.segmented-3 {
  grid-template-columns: repeat(3, 1fr);
}

.segmented-item {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 8px 6px;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.segmented-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-item.is-on {
  background: color-mix(in srgb, var(--primary) 22%, transparent);
  color: var(--text);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 40%, transparent);
}

.graphs-grid {
  display: grid;
  gap: 14px;
}

@media (min-width: 900px) {
  .graphs-grid-2 {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .graph-options-grid {
    grid-template-columns: 1fr 1.2fr;
    align-items: end;
  }
}

/* Tag bar chart */
.bar-chart {
  display: grid;
  gap: 12px;
}

/* Tag pie chart */
.pie-layout {
  display: grid;
  gap: 18px;
  justify-items: center;
}

.pie-visual {
  width: min(220px, 70vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 10px rgba(11, 18, 32, 0.35);
  background: #334155;
}

.pie-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: grid;
  gap: 10px;
}

.pie-legend-item {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 10px;
  align-items: center;
}

.pie-legend-name {
  display: grid;
  gap: 2px;
  font-size: 0.88rem;
  font-weight: 600;
  min-width: 0;
}

.pie-legend-name small {
  color: var(--text-muted);
  font-weight: 500;
}

.pie-legend-value {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
}

@supports not (background: color-mix(in srgb, red 10%, transparent)) {
  .segmented-item.is-on {
    background: rgba(59, 130, 246, 0.18);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.4);
  }
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.bar-label small {
  color: var(--text-muted);
  font-weight: 500;
}

.tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  min-width: 4px;
  transition: width 0.35s ease;
}

.bar-value {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Wallets */
.wallet-item {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 12px;
  align-items: center;
}

.wallet-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.wallet-info strong {
  display: block;
}

.wallet-info small {
  color: var(--text-muted);
}

.wallet-balance {
  font-weight: 800;
}

.wallet-balance.is-income { color: var(--income); }
.wallet-balance.is-expense { color: var(--expense); }

/* ---------- Desktop ---------- */
@media (min-width: 768px) {
  .app-body {
    padding-bottom: 24px;
  }

  .bottom-nav {
    display: none;
  }

  .page {
    padding: 20px 24px 32px;
    gap: 16px;
  }

  .topbar {
    padding: 0 20px;
    grid-template-columns: 48px 1fr 40px;
  }

  .form-grid,
  .filters-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .bar-row {
    grid-template-columns: 160px 1fr 110px;
    align-items: center;
    gap: 12px;
  }

  .bar-value {
    text-align: right;
  }

  .login-card {
    padding: 36px 32px 28px;
  }
}

@media (min-width: 1024px) {
  .side-menu {
    width: 300px;
  }

  .page {
    width: min(1040px, 100%);
  }

  /* Two-column content on large screens for forms + lists */
  .page > .form-card {
    /* keep full width for simplicity; can enhance later */
  }
}

/* Fallback if color-mix unsupported */
@supports not (background: color-mix(in srgb, red 10%, transparent)) {
  .chip {
    background: rgba(100, 116, 139, 0.2);
    border-color: rgba(100, 116, 139, 0.35);
  }
}

/* ---------- Report page intro ---------- */
.page-intro {
  margin-bottom: 2px;
}

.page-eyebrow {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.page-heading {
  margin: 0 0 6px;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.page-lead {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.side-hint {
  margin: 8px 4px 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* Extra room for FABs above bottom nav */
.app-body {
  padding-bottom: calc(var(--bottom-h) + var(--safe-bottom) + 88px);
}

/* ---------- Floating action buttons ---------- */
.fab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bottom-h) + var(--safe-bottom) + 12px);
  z-index: 45;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
}

.fab {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.fab:active {
  transform: scale(0.94);
}





.fab-income {
  background: linear-gradient(145deg, #34d399, #16a34a);
  box-shadow: 0 12px 28px rgba(22, 163, 74, 0.45);
}

.fab-expense {
  background: linear-gradient(145deg, #fb7185, #e11d48);
  box-shadow: 0 12px 28px rgba(225, 29, 72, 0.45);
}

.fab:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.55);
  outline-offset: 3px;
}

/* ---------- Entry modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(4px);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  pointer-events: none;
}

.modal:not([hidden]) {
  pointer-events: auto;
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: min(92vh, 760px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.4);
  padding: 8px 16px calc(20px + var(--safe-bottom));
  transform: translateY(110%);
  transition: transform 0.24s ease;
}

body.modal-open .modal:not([hidden]) .modal-sheet {
  transform: translateY(0);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-kicker {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.modal-head.income .modal-kicker { color: var(--income); }
.modal-head.expense .modal-kicker { color: var(--expense); }
.modal-head.password .modal-kicker { color: #c4b5fd; }

.modal-form .form-grid {
  margin-bottom: 16px;
}

.modal-form .form-grid.form-grid-single {
  grid-template-columns: 1fr;
}

.btn-income {
  background: linear-gradient(180deg, #34d399, #16a34a);
  color: #fff;
  border: 0;
  box-shadow: 0 8px 18px rgba(22, 163, 74, 0.3);
}

.btn-expense {
  background: linear-gradient(180deg, #fb7185, #e11d48);
  color: #fff;
  border: 0;
  box-shadow: 0 8px 18px rgba(225, 29, 72, 0.3);
}

body.modal-open {
  overflow: hidden;
}

/* Hide FABs while menu or modal is open */
body.menu-open .fab-bar,
body.modal-open .fab-bar {
  opacity: 0;
  pointer-events: none;
}

@media (min-width: 768px) {
  .app-body {
    padding-bottom: 100px;
  }

  .fab-bar {
    bottom: 28px;
    padding: 0 max(24px, calc((100vw - 1040px) / 2 + 24px));
  }

  .modal {
    align-items: center;
    padding: 24px;
  }

  .modal-sheet {
    border-radius: 20px;
    max-height: min(88vh, 720px);
    padding: 12px 22px 22px;
    transform: translateY(24px) scale(0.98);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  body.modal-open .modal:not([hidden]) .modal-sheet {
    transform: translateY(0) scale(1);
    opacity: 1;
  }

  .page-heading {
    font-size: 1.4rem;
  }
}

/* ---------- FAB glyph only ---------- */
.fab {
  width: 60px;
  height: 60px;
}

.fab-glyph {
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  margin-top: -2px;
}

.fab-expense .fab-glyph {
  font-size: 2.15rem;
  margin-top: -4px;
}

/* ---------- Date bar (top of reports) ---------- */
.date-bar {
  position: sticky;
  top: calc(var(--topbar-h) + 0px);
  z-index: 20;
  background: rgba(21, 31, 50, 0.94);
  backdrop-filter: blur(10px);
}

.date-bar-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
}

.date-apply {
  grid-column: 1 / -1;
}

/* ---------- Summary with applied filters ---------- */
.summary-row {
  display: grid;
  gap: 12px;
}

.summary-main .stat-value {
  font-size: 1.7rem;
}

.summary-substats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 10px;
  font-weight: 700;
  font-size: 0.9rem;
}

.summary-applied {
  background: var(--bg-soft);
}

.applied-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.applied-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.applied-pill.is-warn {
  border-color: rgba(244, 63, 94, 0.35);
  color: #fecdd3;
  background: rgba(244, 63, 94, 0.1);
}

/* ---------- Filter sheet (topbar funnel) ---------- */
.filter-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(2, 6, 23, 0.55);
}

.filter-sheet-backdrop[hidden],
.filter-sheet[hidden],
.topbar-filter[hidden] {
  display: none !important;
}

.filter-sheet {
  position: fixed;
  z-index: 60;
  top: calc(var(--topbar-h) + 8px);
  right: 12px;
  left: 12px;
  max-width: 420px;
  margin-left: auto;
  max-height: min(78vh, calc(100vh - var(--topbar-h) - var(--bottom-h) - 28px));
  display: flex;
  flex-direction: column;
  background: var(--bg-card, #111827);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.filter-sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.filter-sheet-kicker {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.filter-sheet-title {
  margin: 2px 0 0;
  font-size: 1.05rem;
  font-weight: 750;
}

.filter-sheet-body {
  padding: 12px 14px 8px;
  overflow: auto;
  display: grid;
  gap: 18px;
  -webkit-overflow-scrolling: touch;
}

.filter-sheet-foot {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(15, 23, 42, 0.65);
}

body.filter-sheet-open {
  overflow: hidden;
}

@media (min-width: 480px) {
  .filter-sheet {
    left: auto;
    width: min(400px, calc(100vw - 24px));
  }
}

/* ---------- Selectable chip filters ---------- */
.chip-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.chip-panel-head .card-title {
  margin: 0;
  font-size: 0.95rem;
}

.chip-panel-actions {
  display: flex;
  gap: 10px;
}

.btn-link {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 4px 2px;
}

.btn-link:active {
  opacity: 0.75;
}

.chip-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.select-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
  -webkit-tap-highlight-color: transparent;
}

.select-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.select-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--chip, #64748b);
  opacity: 0.45;
  flex-shrink: 0;
}

.select-chip.is-on {
  color: var(--text);
  border-color: color-mix(in srgb, var(--chip, #64748b) 55%, transparent);
  background: color-mix(in srgb, var(--chip, #64748b) 22%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--chip, #64748b) 20%, transparent);
}

.select-chip.is-on .select-chip-dot {
  opacity: 1;
}

.select-chip:active {
  transform: scale(0.97);
}

.report-filters {
  display: grid;
  gap: 14px;
}

@media (min-width: 768px) {
  .date-bar-grid {
    grid-template-columns: 1fr 1fr auto;
  }

  .date-apply {
    grid-column: auto;
    min-width: 140px;
  }

  .summary-row {
    grid-template-columns: minmax(220px, 0.9fr) 1.1fr;
    align-items: stretch;
  }

  .summary-balance {
    grid-template-columns: 1fr 1fr;
  }
}

@supports not (background: color-mix(in srgb, red 10%, transparent)) {
  .select-chip.is-on {
    border-color: rgba(59, 130, 246, 0.45);
    background: rgba(59, 130, 246, 0.16);
  }
}
