/* ===== Tokens ===== */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --border: #e1e7e4;
  --text: #13201b;
  --text-2: #5b6b64;
  --accent: #0f9f6e;
  --accent-2: #0d9488;
  --accent-soft: #e3f6ee;
  --on-accent: #ffffff;
  --up: #dc2626;        /* gasto/preço subiu = ruim */
  --up-soft: #fde8e8;
  --down: #059669;      /* gasto/preço caiu = bom */
  --down-soft: #dcf5ea;
  --warn: #b45309;
  --warn-soft: #fdf1dc;
  --shadow: 0 1px 2px rgba(16, 32, 27, .05), 0 4px 16px rgba(16, 32, 27, .06);
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0c1311;
  --surface: #141d1a;
  --surface-2: #1b2622;
  --border: #26332e;
  --text: #e7efeb;
  --text-2: #93a49c;
  --accent: #2fc28c;
  --accent-2: #22b3a5;
  --accent-soft: #143329;
  --on-accent: #062018;
  --up: #f87171;
  --up-soft: #3a1717;
  --down: #34d399;
  --down-soft: #10301f;
  --warn: #fbbf24;
  --warn-soft: #33270c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
svg { flex-shrink: 0; }

/* ===== Splash ===== */
.splash { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 20px; background: var(--bg); z-index: 50; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Auth ===== */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(120% 60% at 0% 0%, var(--accent-soft), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.auth-logo { border-radius: 16px; margin-bottom: 12px; }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card p { margin: 0 0 18px; font-size: 14px; }
.auth-card form { text-align: left; display: grid; gap: 12px; margin-top: 16px; }
.form-error { color: var(--up); background: var(--up-soft); padding: 10px 12px; border-radius: var(--radius-sm); margin: 0; font-size: 14px; }

/* ===== Buttons / fields ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--up); border-color: color-mix(in srgb, var(--up) 35%, var(--border)); }
.btn.ghost { background: transparent; }
.btn.link { border: 0; background: none; color: var(--accent); min-height: 36px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; border: 0; background: transparent; color: var(--text-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: var(--surface-2); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input, .field select, .field textarea, .input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-size: 16px; outline: none;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.money-input { position: relative; }
.money-input::before { content: "R$"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-2); font-size: 14px; pointer-events: none; }
.money-input input { padding-left: 36px; }
.hint { font-size: 13px; color: var(--accent); background: var(--accent-soft); padding: 8px 10px; border-radius: 10px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; min-height: 36px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--text-2); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ===== App shell ===== */
.app { max-width: 760px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.topbar-title { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; flex: 1; min-width: 0; }
.topbar-title img { border-radius: 8px; }
.topbar-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.month-pill { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 10px 6px 12px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-2); flex-shrink: 0; }
.sync-dot.on { background: var(--down); box-shadow: 0 0 0 3px var(--down-soft); }
.sync-dot.off { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

.view { padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 96px); outline: none; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.view > *, .sheet-body > *, .cat-group > * { min-width: 0; }
.sheet-body, .cat-group { grid-template-columns: minmax(0, 1fr); }
html, body { overflow-x: hidden; }

.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border); max-width: 760px; margin: 0 auto; }
.bottomnav button { border: 0; background: none; display: grid; justify-items: center; align-content: center; gap: 3px; color: var(--text-2); font-size: 11px; font-weight: 600; }
.bottomnav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.bottomnav button.active { color: var(--accent); }
.bottomnav button.active svg { stroke-width: 2.3; }

/* ===== Cards ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h3 { font-size: 15px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 6px 2px -4px; }

.hero { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: 0; }
.hero .label { font-size: 13px; opacity: .85; font-weight: 600; }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0 10px; }
.hero .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.up { background: var(--up-soft); color: var(--up); }
.badge.down { background: var(--down-soft); color: var(--down); }
.badge.neutral { background: var(--surface-2); color: var(--text-2); }
.badge.demo { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.hero .badge { background: rgba(255,255,255,.2); color: #fff; }
.badge svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
.banner svg, .stat .k svg { flex-shrink: 0; }
.row-item { font: inherit; color: inherit; cursor: pointer; }
div.row-item { cursor: default; }
.empty h3 { justify-content: center; }
.progress { height: 8px; border-radius: 99px; background: rgba(255,255,255,.25); overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; background: #fff; border-radius: 99px; transition: width .3s; }
.progress.light { background: var(--surface-2); }
.progress.light > i { background: var(--accent); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat .k { font-size: 12px; color: var(--text-2); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 20px; font-weight: 800; margin-top: 4px; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat .s { font-size: 12px; color: var(--text-2); margin-top: 2px; }
@media (min-width: 560px) { .stats.four { grid-template-columns: repeat(4, 1fr); } }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare .box { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.compare .box .k { font-size: 12px; color: var(--text-2); font-weight: 600; }
.compare .box .v { font-size: 17px; font-weight: 800; margin-top: 2px; }
.delta-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); font-weight: 700; }

.banner { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; font-size: 13px; font-weight: 600; }
.banner.demo { background: var(--warn-soft); color: var(--warn); }
.banner.done { background: var(--accent-soft); color: var(--accent); }
.banner .btn { margin-left: auto; }

.empty { text-align: center; padding: 28px 16px; color: var(--text-2); }
.empty svg { width: 44px; height: 44px; stroke: var(--text-2); fill: none; stroke-width: 1.6; opacity: .6; margin-bottom: 8px; }
.empty p { margin: 4px 0 14px; }

/* ===== Lista do mês ===== */
.list-head { display: flex; align-items: center; gap: 8px; }
.list-head .month-nav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; }
.list-head .month-nav strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary-strip > div { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; min-width: 0; }
.summary-strip .k { font-size: 11px; color: var(--text-2); font-weight: 600; }
.summary-strip .v { font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.search { flex: 1; position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; stroke: var(--text-2); fill: none; stroke-width: 2; }
.search input { width: 100%; min-height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); padding: 0 12px 0 36px; font-size: 15px; outline: none; }
.search input:focus { border-color: var(--accent); }

.cat-group { display: grid; gap: 8px; }
.cat-title { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; padding: 4px 2px 0; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 10px 10px 8px; display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; box-shadow: var(--shadow); transition: background .2s; }
.item.bought { background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 25%, var(--border)); }
.check { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; padding: 0; grid-row: span 2; align-self: start; }
.check i { width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--border); display: grid; place-items: center; background: var(--surface); transition: all .15s; }
.check svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.item.bought .check i { background: var(--accent); border-color: var(--accent); }
.item.bought .check svg { opacity: 1; }
.item-top { display: flex; align-items: flex-start; gap: 6px; min-width: 0; padding-top: 4px; }
.item-name { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; word-break: break-word; }
.item.bought .item-name { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text) 35%, transparent); }
.item-total { font-weight: 800; font-size: 15px; white-space: nowrap; }
.item-sub { font-size: 12px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.item-edit { display: flex; gap: 6px; align-items: center; grid-column: 2; flex-wrap: wrap; margin-top: 4px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); height: 38px; }
.stepper button { width: 32px; height: 36px; border: 0; background: none; font-size: 18px; font-weight: 700; color: var(--accent); }
.stepper input { width: 38px; text-align: center; border: 0; background: transparent; font-weight: 700; font-size: 16px; outline: none; height: 36px; padding: 0; }
.stepper .u { font-size: 11px; color: var(--text-2); padding-right: 7px; }
.price-inline { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); height: 38px; padding-left: 8px; }
.price-inline small { font-size: 11px; color: var(--text-2); font-weight: 600; }
.price-inline input { width: 64px; border: 0; background: transparent; font-weight: 700; font-size: 16px; outline: none; height: 36px; padding: 0 4px; }
.item-edit .icon-btn { width: 36px; height: 38px; }
.price-inline:focus-within, .stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.item-more { width: 32px !important; height: 28px !important; margin: -3px -4px 0 0; }
.item-more svg { width: 18px; height: 18px; }

.fab { position: fixed; right: max(16px, calc(50vw - 380px + 16px)); bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 15; width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent); }
.fab svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; }

/* ===== Listas genéricas ===== */
.rows { display: grid; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--border); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.row-item:last-child { border-bottom: 0; }
.row-item .grow { flex: 1; min-width: 0; }
.row-item .t { font-weight: 700; }
.row-item .d { font-size: 12px; color: var(--text-2); }
.row-item .r { text-align: right; font-weight: 800; white-space: nowrap; }
.row-item .r small { display: block; font-weight: 600; }
.row-item .chev { width: 18px; height: 18px; stroke: var(--text-2); fill: none; stroke-width: 2; }
.rank { width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; font-weight: 800; color: var(--text-2); flex-shrink: 0; }

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.prices { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
table.prices th, table.prices td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.prices th { font-size: 12px; color: var(--text-2); font-weight: 700; position: sticky; top: 0; background: var(--surface); }
table.prices th:first-child, table.prices td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; max-width: 140px; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
table.prices tr { cursor: pointer; }
table.prices td.na { color: var(--text-2); opacity: .5; }

.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }
.chart-box.donut { height: 260px; }
.chart-note { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; font-size: 13px; }

/* ===== Sheet ===== */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(5, 12, 10, .45); animation: fade .2s; }
.sheet { position: relative; width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; background: var(--surface); border-radius: 22px 22px 0 0; display: flex; flex-direction: column; animation: up .25s cubic-bezier(.2,.8,.2,1); padding-bottom: var(--safe-b); }
@media (min-width: 600px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 22px; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 9px; background: var(--border); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 4px 18px; }
.sheet-head h2 { font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 8px 18px 20px; display: grid; gap: 12px; }
.sheet-actions { display: flex; gap: 10px; position: sticky; bottom: -20px; background: var(--surface); padding: 12px 0 4px; }
.sheet-actions .btn { flex: 1; }
.total-preview { display: flex; justify-content: space-between; align-items: center; background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 12px 14px; font-weight: 700; }
.total-preview strong { font-size: 22px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv > div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.kv .k { font-size: 12px; color: var(--text-2); font-weight: 600; }
.kv .v { font-size: 16px; font-weight: 800; margin-top: 2px; }
.kv .s { font-size: 11px; color: var(--text-2); }

/* ===== Toast ===== */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 88px); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); max-width: calc(100vw - 32px); display: flex; gap: 12px; align-items: center; animation: up .2s; }
.toast button { border: 0; background: none; color: var(--accent); font-weight: 800; }

/* ===== Settings ===== */
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting:last-child { border-bottom: 0; }
.setting .grow { flex: 1; min-width: 0; }
.setting .t { font-weight: 700; }
.setting .d { font-size: 12px; color: var(--text-2); }
.avatar { width: 44px; height: 44px; border-radius: 14px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 800; font-size: 18px; flex-shrink: 0; }
.btn-col { display: grid; gap: 8px; }

/* ===== Relatório ===== */
.report h4 { margin: 14px 0 6px; font-size: 14px; }
.report ul { margin: 0; padding-left: 18px; font-size: 14px; }
.report li { margin: 3px 0; }

@media (min-width: 760px) {
  .view { padding-left: 20px; padding-right: 20px; }
}
