:root {
  color-scheme: light;
  --bg: #F2F5F3;
  --card: #FFFFFF;
  --ink: #0F2A22;
  --muted: #6B7F77;
  --line: #E3EAE6;
  --brand: #123D30;
  --pos: #1F9D66;
  --neg: #D9604A;
  --warn: #D98E1F;
  --save: #6D5DF5;
  --info: #3E8EF7;
  --chip: #E9F0EC;
  --fab-ink: #FFFFFF;
  --shadow: 0 1px 2px rgba(16, 40, 32, .04), 0 8px 24px -14px rgba(16, 40, 32, .16);
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0A1310;
  --card: #121E19;
  --ink: #E6F0EB;
  --muted: #8FA39A;
  --line: #20302A;
  --brand: #3CCB8A;
  --pos: #3CCB8A;
  --neg: #F08A74;
  --warn: #F2B557;
  --save: #9087FF;
  --info: #6AA9FF;
  --chip: #1A2A23;
  --fab-ink: #062018;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: Inter, "SF Pro Text", system-ui, -apple-system, "Segoe UI", sans-serif; font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--brand); text-decoration: none; }
p, h1, h2, h3 { margin: 0; }

.ic { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 16px; height: 16px; }
.ic.xs { width: 13px; height: 13px; }

/* ====== Layout responsivo (desktop sidebar + mobile bottom nav) ====== */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100dvh; max-width: 1440px; margin: 0 auto; }
.sidebar { position: sticky; top: 0; height: 100dvh; padding: 24px 16px; background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 22px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px; }
.brand-mark { width: 38px; height: 38px; border-radius: 13px; background: #123D30; color: #BFF0D6; display: grid; place-items: center; font-weight: 800; font-size: 14px; flex: none; }
.brand-title { font-weight: 800; font-size: 15px; line-height: 1.15; letter-spacing: -.02em; }
.brand-sub { font-size: 11.5px; color: var(--muted); font-weight: 500; }

.side-nav { display: grid; gap: 4px; }
.side-nav button { display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 14px; font-weight: 600; font-size: 14px; color: var(--muted); transition: background .15s, color .15s; text-align: left; }
.side-nav button:hover { background: var(--chip); color: var(--ink); }
.side-nav button.on { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); font-weight: 700; }
.side-cta { margin-top: 6px; padding: 12px 14px; border-radius: 14px; background: var(--brand); color: var(--fab-ink); font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.side-foot { margin-top: auto; display: grid; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }

.main { padding: 22px clamp(16px, 3vw, 40px) 48px; min-width: 0; max-width: 1060px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.mobile-brand { display: none; }

.iconbtn { width: 40px; height: 40px; border-radius: 13px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink); position: relative; }
.iconbtn:hover { background: var(--chip); }
.iconbtn .badge-dot { position: absolute; top: 8px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--neg); }

.period-select { appearance: none; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 30px 8px 12px; font-weight: 700; font-size: 13.5px; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }

/* ====== Cards & Typography ====== */
.h1 { font-size: clamp(24px, 3vw, 30px); font-weight: 800; letter-spacing: -.03em; }
.h2 { font-size: 16px; font-weight: 750; letter-spacing: -.015em; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.amt small { font-size: .58em; opacity: .75; font-weight: 600; }
.privacy-hide .amt { filter: blur(9px); user-select: none; }

.card { background: var(--card); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); border: 1px solid transparent; }
:root[data-theme="dark"] .card { border-color: var(--line); }

.hero { background: radial-gradient(120% 130% at 100% 0%, #2E8264 0%, #174A3A 48%, #0C2A21 100%); color: #EAF5EF; border-radius: 26px; padding: 22px; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -45px; top: -45px; width: 180px; height: 180px; border-radius: 50%; border: 30px solid rgba(255,255,255,.05); pointer-events: none; }
.hero-value { font-size: clamp(34px, 5vw, 44px); font-weight: 800; letter-spacing: -.035em; line-height: 1.05; margin-top: 6px; }
.hero-bar { display: flex; height: 9px; border-radius: 99px; overflow: hidden; gap: 3px; margin-top: 16px; background: rgba(255,255,255,.12); }
.hero-bar span { border-radius: 99px; }
.hero-legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; font-size: 12px; margin-top: 10px; opacity: .92; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stack { display: grid; gap: 14px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.stat-card { padding: 14px; }
.stat-icon { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; margin-bottom: 8px; }
.stat-val { font-size: clamp(16px, 2vw, 20px); font-weight: 800; letter-spacing: -.025em; margin-top: 2px; }
.stat-sub { font-size: 11px; font-weight: 700; margin-top: 3px; }

/* ====== Chips, Pills, Buttons ====== */
.chip { background: var(--chip); color: var(--ink); border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 650; white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.chip.on { background: var(--brand); color: var(--fab-ink); }
.pill { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.btn { padding: 10px 15px; border-radius: 12px; font-weight: 700; font-size: 13.5px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); }
.btn.primary { background: var(--brand); color: var(--fab-ink); border-color: var(--brand); }
.btn.soft { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); border-color: transparent; }
.btn.danger { background: color-mix(in srgb, var(--neg) 14%, transparent); color: var(--neg); border-color: transparent; }
.btn.sm { padding: 7px 11px; font-size: 12px; border-radius: 10px; }

/* ====== Lists & Transactions ====== */
.tx-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; }
.tx-row + .tx-row { border-top: 1px solid var(--line); }
.cat-icon { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; flex: none; }
.bank-dot { width: 16px; height: 16px; border-radius: 5px; font-size: 7.5px; font-weight: 800; color: #fff; display: inline-grid; place-items: center; vertical-align: -3px; margin-right: 4px; }
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.tx-right { text-align: right; white-space: nowrap; }
.tx-amt { font-weight: 750; font-size: 14.5px; }
.tx-usd { font-size: 11px; color: var(--muted); }

/* ====== Donut legend ====== */
.donut-wrap { display: grid; grid-template-columns: 165px minmax(0, 1fr); gap: 14px; align-items: center; margin-top: 10px; }
.legend-list { display: grid; gap: 7px; font-size: 12.5px; }
.legend-item { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ====== Insights Carousel ====== */
.insight-card { position: relative; }
.insight-dots { display: flex; gap: 6px; align-items: center; }
.insight-dots button { height: 6px; border-radius: 99px; transition: width .2s; }

/* ====== Heatmap ====== */
.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; margin-top: 12px; }
.hm-head { font-size: 10.5px; font-weight: 700; color: var(--muted); }
.hm-cell { height: 32px; border-radius: 9px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--muted); background: var(--chip); }
.hm-cell.l1 { background: color-mix(in srgb, var(--neg) 18%, var(--chip)); }
.hm-cell.l2 { background: color-mix(in srgb, var(--neg) 42%, var(--chip)); color: var(--ink); }
.hm-cell.l3 { background: color-mix(in srgb, var(--neg) 72%, var(--chip)); color: #fff; }
.hm-cell.l4 { background: var(--neg); color: #fff; }
.hm-cell.today { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink); }

/* ====== Goals Ring ====== */
.ring-wrap { position: relative; width: 122px; height: 122px; flex: none; }
.ring { width: 100%; height: 100%; border-radius: 50%; background: conic-gradient(var(--save) var(--p, 0%), var(--chip) 0); display: grid; place-items: center; position: relative; }
.ring::before { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: var(--card); }
.ring-inner { position: relative; z-index: 1; text-align: center; }
.ring-inner strong { font-size: 22px; font-weight: 800; letter-spacing: -.03em; display: block; }
.ring-inner span { font-size: 10.5px; color: var(--muted); font-weight: 600; }

/* ====== Search & Filters ====== */
.search-box { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 15px; padding: 0 14px; height: 44px; }
.search-box input { border: 0; background: none; outline: none; width: 100%; font-size: 14px; }
.chips-row { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips-row::-webkit-scrollbar { display: none; }

/* ====== Forms & Dialogs ====== */
dialog { border: 1px solid var(--line); border-radius: 24px; padding: 0; width: min(490px, calc(100% - 24px)); max-height: 90dvh; background: var(--card); color: var(--ink); box-shadow: 0 28px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(8, 22, 18, .62); backdrop-filter: blur(4px); }
.dlg-body { padding: 20px; display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 12.5px; font-weight: 650; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); color: var(--ink); font-size: 14px; font-weight: 500; }
.seg { display: flex; background: var(--chip); border-radius: 13px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 10px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.code-box { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); word-break: break-all; }

/* ====== Toast ====== */
.toast { position: fixed; right: 20px; bottom: 24px; z-index: 50; background: #0F2A22; color: #EAF5EF; padding: 12px 16px; border-radius: 14px; font-size: 13.5px; font-weight: 650; box-shadow: 0 12px 30px rgba(0,0,0,.3); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: none; }

/* ====== Mobile Bottom Nav ====== */
.mobile-nav { display: none; }

@media (max-width: 860px) {
  .shell { display: block; }
  .sidebar { display: none; }
  body::before {
    content: "";
    position: fixed;
    inset: 0 0 auto;
    height: var(--safe-area-top);
    background: var(--bg);
    pointer-events: none;
    z-index: 40;
  }
  .main {
    padding: calc(14px + var(--safe-area-top)) max(14px, var(--safe-area-right))
      calc(104px + env(safe-area-inset-bottom)) max(14px, var(--safe-area-left));
  }
  .topbar { align-items: flex-start; gap: 8px; }
  .topbar-left { min-width: 0; flex: 1; flex-wrap: wrap; gap: 8px; }
  .topbar-actions { flex: none; gap: 6px; }
  .topbar-actions .iconbtn { width: 38px; height: 38px; }
  .mobile-brand { display: flex; gap: 8px; min-width: 0; padding: 0; }
  .mobile-brand .brand-mark { width: 36px; height: 36px; }
  .mobile-brand .brand-sub { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .period-select { max-width: 100%; min-height: 36px; padding: 7px 24px 7px 9px; font-size: 13px; }
  .grid-2 { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); right: 14px; left: 14px; text-align: center; }

  .mobile-nav {
    position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom));
    height: 66px; border-radius: 22px; z-index: 30;
    background: color-mix(in srgb, var(--card) 88%, transparent);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--line); box-shadow: 0 12px 30px -12px rgba(0,0,0,.3);
    display: flex; align-items: center; justify-content: space-around; padding: 0 6px;
  }
  .mobile-nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 650; color: var(--muted); width: 62px; }
  .mobile-nav button.on { color: var(--brand); }
  .mobile-nav .fab { width: 52px; height: 52px; border-radius: 17px; background: var(--brand); color: var(--fab-ink); display: grid; place-items: center; margin-top: -28px; box-shadow: 0 12px 22px -8px color-mix(in srgb, var(--brand) 75%, transparent); }
}

@media (max-width: 420px) {
  .grid-3 { gap: 8px; }
  .stat-card { padding: 11px 10px; }
  .stat-val { font-size: 15px; }
}
