/* Teto — estilos. Mobile-first, sem dependências. */

:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --card: #ffffff;
  --card-2: #f0efeb;
  --line: #e4e2dc;
  --ink: #141413;
  --ink-2: #57564f;
  --ink-3: #8a897f;
  --good: #0c8a0c;
  --warn: #c98500;
  --bad: #d03b3b;
  --good-bar: #0ca30c;
  --warn-bar: #fab219;
  --bad-bar: #d03b3b;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  --accent-base: #1f8a5b;
  --accent: var(--accent-base);
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in oklab, var(--accent) 12%, var(--card));
  --r: 18px;
  --tabbar: 64px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e;
  --card: #1a1a19;
  --card-2: #242422;
  --line: #2e2e2b;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --ink-3: #8f8e85;
  --good: #3fbf3f;
  --warn: #fab219;
  --bad: #ef6b6b;
  --good-bar: #0ca30c;
  --warn-bar: #fab219;
  --bad-bar: #e05252;
  --shadow: none;
  --accent: color-mix(in oklab, var(--accent-base) 78%, white);
  --accent-ink: #0f0f0e;
  --accent-soft: color-mix(in oklab, var(--accent) 16%, var(--card));
}

/* Cores de destaque (Ajustes → Cor) */
[data-accent="verde"] { --accent-base: #1f8a5b; }
[data-accent="azul"] { --accent-base: #2a6fd6; }
[data-accent="roxo"] { --accent-base: #6250d6; }
[data-accent="rosa"] { --accent-base: #cf3f7a; }
[data-accent="laranja"] { --accent-base: #dd5f24; }
[data-accent="terracota"] { --accent-base: #b3541e; }
[data-accent="petroleo"] { --accent-base: #0f7c86; }
[data-accent="grafite"] { --accent-base: #3f4650; }
:root[data-theme="dark"][data-accent="grafite"] { --accent: #b7bec8; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
#app { min-height: 100dvh; }
.loading { display: grid; place-items: center; color: var(--ink-3); }

.top {
  position: sticky; top: 0; z-index: 10;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.month-nav { display: flex; align-items: center; gap: 2px; }
.month-nav .arrow {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--ink-2);
}
.month-nav .arrow:active { background: var(--card-2); }
.month-name { font-weight: 700; font-size: 19px; padding: 6px 4px; min-width: 150px; text-align: center; }
.sync { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; min-width: 64px; justify-content: flex-end; }
.sync .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn-bar); }

main {
  padding: 4px 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 28px);
  max-width: 560px; margin: 0 auto;
  animation: fade 0.22s var(--ease);
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; display: flex; justify-content: space-between; align-items: baseline; }
.card h2 small { font-weight: 500; color: var(--ink-3); font-size: 13px; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; }

/* ---------- hero ---------- */
.hero { display: flex; gap: 16px; align-items: center; padding: 18px 16px; }
.ring { flex: 0 0 auto; width: 104px; height: 104px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--card-2); }
.ring .val { transition: stroke-dashoffset 0.6s var(--ease); }
.ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.ring .pct small { display: block; font-size: 11px; font-weight: 500; color: var(--ink-3); text-align: center; margin-top: -2px; }
.hero-txt { min-width: 0; }
.hero-label { font-size: 13px; color: var(--ink-2); font-weight: 550; }
.hero-big { font-size: 32px; font-weight: 750; line-height: 1.1; margin: 2px 0 4px; letter-spacing: -0.02em; }
.hero-big.bad { color: var(--bad); }
.hero-sub { font-size: 13px; color: var(--ink-2); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat .k { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 4px; }
.stat .v { font-size: 18px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .s { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.tag.good { color: var(--good); }
.tag.warn { color: var(--warn); }
.tag.bad { color: var(--bad); }

.setup { background: var(--accent-soft); border: 1px dashed color-mix(in oklab, var(--accent) 45%, transparent); text-align: center; }
.setup p { margin: 0 0 10px; color: var(--ink-2); font-size: 14px; }

/* ---------- gráfico ---------- */
.chart { position: relative; height: 170px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 11px; }
.chart .ref { stroke: var(--ink-3); stroke-width: 1.5; stroke-dasharray: 4 4; fill: none; }
.chart .cap-line { stroke: var(--bad); stroke-width: 1.5; stroke-dasharray: 6 4; opacity: 0.8; }
.chart .ref-label { font-size: 11px; fill: var(--ink-2); font-weight: 600; }
.chart .line { stroke: var(--accent); stroke-width: 2.25; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: 0.1; }
.chart .now { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart .cross { stroke: var(--ink-3); stroke-width: 1; }
.chart .tip {
  position: absolute; top: -6px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 10px;
  padding: 6px 9px; font-size: 12px; line-height: 1.3; white-space: nowrap; pointer-events: none;
}
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.chart-legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 5px; }

/* ---------- categorias ---------- */
.cat { display: grid; grid-template-columns: 40px 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 0; width: 100%; text-align: left; }
.cat + .cat { border-top: 1px solid var(--line); }
.emoji { width: 40px; height: 40px; border-radius: 12px; background: var(--card-2); display: grid; place-items: center; font-size: 20px; grid-row: span 2; }
.cat .name { font-weight: 600; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat .amt { font-size: 14px; font-weight: 650; text-align: right; white-space: nowrap; }
.cat .amt span { color: var(--ink-3); font-weight: 500; }
.cat .meta { grid-column: 2 / 4; display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 8px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--good-bar); transform-origin: left; animation: grow 0.6s var(--ease) both; }
.bar > i.warn { background: var(--warn-bar); }
.bar > i.bad { background: var(--bad-bar); }
.bar > i.none { background: var(--ink-3); }
@keyframes grow { from { transform: scaleX(0); } }
.cat .left { font-size: 12px; white-space: nowrap; min-width: 92px; text-align: right; }

.people { display: flex; gap: 8px; }
.person { flex: 1; background: var(--card-2); border-radius: 12px; padding: 10px 12px; }
.person .k { font-size: 12px; color: var(--ink-2); }
.person .v { font-weight: 700; font-size: 16px; }

/* ---------- lançamentos ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px; padding-inline: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 99px; background: var(--card);
  font-size: 14px; font-weight: 550; color: var(--ink-2); box-shadow: var(--shadow);
  border: 1px solid var(--line); white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.day-h { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); font-weight: 600; padding: 14px 4px 6px; }
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 0 14px; }
.item { display: grid; grid-template-columns: 40px 1fr auto; gap: 0 12px; align-items: center; padding: 10px 0; width: 100%; text-align: left; }
.item + .item { border-top: 1px solid var(--line); }
.item .emoji { grid-row: span 2; }
.item .t { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .d { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .v { font-weight: 700; grid-row: span 2; white-space: nowrap; }
.item.pending .v::after { content: " •"; color: var(--warn-bar); }
.empty { text-align: center; color: var(--ink-3); padding: 36px 16px; font-size: 14px; }
.empty b { display: block; font-size: 34px; margin-bottom: 6px; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 4px; }
.total-line b { font-size: 22px; }

/* ---------- tetos ---------- */
.cap-row { display: grid; grid-template-columns: 40px 1fr 128px; gap: 12px; align-items: center; padding: 8px 0; }
.cap-row + .cap-row { border-top: 1px solid var(--line); }
.cap-row .emoji { grid-row: auto; }
.cap-row .nm { min-width: 0; text-align: left; }
.cap-row .nm b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cap-row .nm small { color: var(--accent); font-size: 12px; font-weight: 600; }
.money-in {
  width: 100%; text-align: right; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); font-weight: 650; font-variant-numeric: tabular-nums; outline: none;
}
.money-in:focus { border-color: var(--accent); background: var(--card); }
.cap-total { display: flex; justify-content: space-between; align-items: baseline; }
.cap-total b { font-size: 24px; }

/* ---------- formulários ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 50px; border-radius: 14px; font-weight: 650; font-size: 16px;
  background: var(--accent); color: var(--accent-ink); transition: transform 0.12s, opacity 0.12s;
}
.btn:active { transform: scale(0.98); opacity: 0.9; }
.btn.ghost { background: var(--card-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--bad); }
.btn.sm { min-height: 40px; width: auto; padding: 0 16px; font-size: 14px; display: inline-flex; }
.btn[disabled] { opacity: 0.45; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); font-weight: 600; margin-bottom: 6px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); outline: none; font-size: 16px;
}
.input:focus { border-color: var(--accent); background: var(--card); }
.seg { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }

/* ---------- ajustes ---------- */
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row > span { font-weight: 550; }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.swatch { aspect-ratio: 1; border-radius: 16px; background: var(--sw); position: relative; display: grid; place-items: end center; padding-bottom: 6px; font-size: 11px; color: #fff; font-weight: 600; }
.swatch.on::after { content: "✓"; position: absolute; top: 6px; right: 8px; font-size: 14px; }
.swatch:active { transform: scale(0.96); }
.help { font-size: 14px; color: var(--ink-2); margin: 0; }
.help li { margin: 4px 0; }

/* ---------- barra de abas ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in oklab, var(--card) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--ink-3); height: 100%; justify-content: center; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--accent); }
.tab-add { display: grid; place-items: center; }
.tab-add button {
  width: 54px; height: 54px; border-radius: 18px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 6px 18px color-mix(in oklab, var(--accent) 40%, transparent);
  transform: translateY(-10px); transition: transform 0.15s var(--ease);
}
.tab-add button:active { transform: translateY(-10px) scale(0.92); }
.tab-add svg { width: 28px; height: 28px; }

/* ---------- sheet (modal de baixo) ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 0.4);
  animation: bd 0.2s ease both;
}
.backdrop.out { animation: bd 0.2s ease reverse both; }
@keyframes bd { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto;
  background: var(--card); border-radius: 24px 24px 0 0;
  max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
  animation: up 0.32s var(--ease) both;
}
.sheet.out { animation: down 0.22s ease-in both; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes down { to { transform: translateY(100%); } }
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 2px auto 10px; }
.sheet h3 { margin: 0 0 12px; font-size: 18px; display: flex; justify-content: space-between; align-items: center; }
.sheet h3 button { color: var(--ink-3); font-size: 15px; font-weight: 500; }

.amount {
  display: block; width: 100%; border: 0; background: transparent; outline: none; text-align: center;
  font-size: 44px; font-weight: 750; letter-spacing: -0.02em; padding: 6px 0 2px; caret-color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.amount-hint { text-align: center; font-size: 13px; color: var(--ink-3); min-height: 18px; margin-bottom: 12px; }
.amount-hint.bad { color: var(--bad); font-weight: 600; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.cat-pick {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 2px 7px;
  border-radius: 14px; background: var(--card-2); border: 2px solid transparent; font-size: 11.5px; font-weight: 600;
  color: var(--ink-2); min-width: 0;
}
.cat-pick span:first-child { font-size: 22px; }
.cat-pick span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.cat-pick.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.date-row { display: flex; gap: 6px; }
.date-row .chip { box-shadow: none; }
.date-row input { flex: 1; min-width: 0; padding: 7px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--card-2); font-size: 14px; }
.emoji-in { width: 64px; text-align: center; font-size: 24px; padding: 8px; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.emoji-pick button { width: 40px; height: 40px; border-radius: 10px; font-size: 21px; }
.emoji-pick button:active { background: var(--card-2); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.logo { width: 76px; height: 76px; border-radius: 22px; margin: 0 auto 14px; display: block; }
.login h1 { margin: 0 0 4px; font-size: 28px; }
.login p { margin: 0 0 22px; color: var(--ink-2); }
.who-pick { display: grid; gap: 10px; }
.who-pick .btn { min-height: 60px; font-size: 18px; }

/* ---------- toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 14px); z-index: 60; display: grid; justify-items: center; pointer-events: none; padding: 0 16px; }
.toast {
  background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-size: 14px; font-weight: 550;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2); animation: toast 2.8s var(--ease) both; max-width: 100%;
}
@keyframes toast { 0% { opacity: 0; transform: translateY(12px); } 8%, 88% { opacity: 1; transform: none; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
