/* ==========================================================================
   LIFEAPP — "livro-caixa noturno": preto real, tinta quente, um único citrino.
   Valores em serifa grande, números de conta em mono, régua do ciclo como marca.
   ========================================================================== */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0d0d0b;
  --surface-2: #181815;
  --line: #2a2a25;
  --ink: #f5f3ea;
  --ink-2: #b0aea2;
  --ink-3: #85837a;
  --accent-bg: #d9f24f;
  --accent-on: #101300;
  --accent-text: #d9f24f;
  --good: #8be3ac;
  --warn: #f6bd55;
  --bad: #ff8073;
  --s1: #869e0e;
  --s2: #4490dc;
  --s3: #dd6733;
  --s4: #9f70e0;
  --backdrop: rgba(0, 0, 0, 0.72);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f0e8;
  --surface: #fbf9f3;
  --surface-2: #ebe7db;
  --line: #d9d4c6;
  --ink: #14130f;
  --ink-2: #55534a;
  --ink-3: #6f6c61;
  --accent-bg: #d9f24f;
  --accent-on: #101300;
  --accent-text: #566400;
  --good: #1d7a44;
  --warn: #9a6400;
  --bad: #c0392b;
  --s1: #6e7f00;
  --s2: #1f6fc0;
  --s3: #c8501f;
  --s4: #7d4bc4;
  --backdrop: rgba(20, 19, 15, 0.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Hanken Grotesk", ui-sans-serif, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
h1, h2, h3, p, dl, dd, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; border-radius: 6px; }
small { font-size: 12px; color: var(--ink-3); font-weight: 400; }

.fig { font-family: "DM Mono", ui-monospace, monospace; font-size: 13.5px; white-space: nowrap; letter-spacing: -0.02em; }
.fig small { font-family: inherit; }
.dim { color: var(--ink-3); }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.eyebrow { font-size: 12px; color: var(--ink-2); letter-spacing: 0.02em; }
.hint { font-size: 13px; color: var(--ink-3); margin-top: 8px; }
.lede { color: var(--ink-2); font-size: 14px; margin: 2px 0 14px; }
.alert { color: var(--bad); font-size: 13.5px; margin-top: 8px; }
.note { font-size: 13px; color: var(--ink-2); margin-top: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

/* ---------- Estrutura ---------- */
.page {
  max-width: 540px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 112px);
}
.page.with-flag { padding-top: 36px; }
.demo-flag {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  background: var(--accent-bg); color: var(--accent-on);
  font-size: 12px; font-weight: 600; text-align: center; padding: 4px 8px;
}
.top { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.top h1 { font-family: "Instrument Serif", serif; font-weight: 400; font-size: 27px; letter-spacing: -0.01em; }
.top-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%;
  color: var(--ink-2); transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }
.ico { display: block; flex: none; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; margin-right: 8px; background: var(--ink-3); transition: background 0.2s; }
.sync-dot[data-state="saved"] { background: var(--good); }
.sync-dot[data-state="saving"] { background: var(--warn); animation: pulse 1s infinite; }
.sync-dot[data-state="offline"] { background: var(--bad); }

.switcher { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.switcher-label { flex: 1; text-align: center; display: grid; gap: 0; }
.switcher-label strong { font-weight: 600; font-size: 14.5px; }

/* ---------- Herói ---------- */
.hero { padding: 16px 0 22px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.big {
  display: block; font-family: "Instrument Serif", serif; font-size: 64px; line-height: 1.04;
  letter-spacing: -0.03em; margin-top: 2px; font-variant-numeric: lining-nums;
}
.big.neg { color: var(--bad); }
.big-cur { font-size: 22px; margin-right: 6px; color: var(--ink-3); letter-spacing: 0; vertical-align: 26px; }
.big-cents { font-size: 30px; color: var(--ink-3); }

/* A régua do ciclo */
.ruler { margin: 22px 0 18px; }
.ruler-track { position: relative; height: 26px; }
.ruler-ticks { position: absolute; inset: 0; }
.ruler-ticks i { position: absolute; bottom: 0; width: 1px; height: 8px; background: var(--line); }
.ruler-fill { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent-bg); }
.ruler-mark {
  position: absolute; top: 2px; width: 7px; height: 7px; margin-left: -3px;
  background: var(--warn); transform: rotate(45deg);
}
.ruler-mark.paid { background: var(--ink-3); opacity: 0.55; }
.ruler-now {
  position: absolute; bottom: 0; width: 2px; height: 22px; margin-left: -1px; background: var(--accent-bg);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent-bg) 55%, transparent);
}
:root[data-theme="light"] .ruler-fill,
:root[data-theme="light"] .ruler-now { background: var(--ink); box-shadow: none; }
.ruler-ends { position: relative; display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-3); margin-top: 6px; }
.ruler-ends em { font-style: normal; margin-left: 4px; opacity: 0.75; }
.ruler-today { position: absolute; top: 0; transform: translateX(-50%); color: var(--accent-text); font-weight: 600; }

.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.trio dt { font-size: 12px; color: var(--ink-3); }
.trio dd { margin-top: 2px; font-size: 13px; }
.trio.boxed { padding: 14px 0; border-block: 1px solid var(--line); margin-bottom: 4px; }

/* ---------- Blocos e linhas ---------- */
.block { padding: 20px 0 18px; border-bottom: 1px solid var(--line); }
.block h2, .sheet-head h2 { font-size: 15px; font-weight: 600; }
.block-head { margin-bottom: 8px; }
.block > h2 { margin-bottom: 8px; }
.block h3, .sheet-body h3 {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; font-weight: 500; color: var(--ink-3); margin: 14px 0 2px;
}
.link { color: var(--accent-text); font-size: 13.5px; font-weight: 500; }
.link.spaced { display: block; margin-top: 12px; }

.line { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent); min-height: 54px; }
.block-head + .line, h2 + .line, h3 + .line { border-top: 0; }
.line-btn { width: 100%; }
.line-btn:hover .line-title { color: var(--accent-text); }
.line-main { flex: 1; min-width: 0; display: grid; text-align: left; }
.line-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-sub { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack-right { display: grid; justify-items: end; }
.check {
  width: 24px; height: 24px; flex: none; border: 1.5px solid var(--ink-3); border-radius: 50%;
  display: grid; place-items: center; color: var(--accent-on); transition: 0.15s;
}
.check:hover { border-color: var(--accent-text); }
.check.on { background: var(--accent-bg); border-color: var(--accent-bg); }
.chip {
  flex: none; border: 1px solid var(--line); border-radius: 99px; padding: 7px 13px;
  font-size: 12.5px; font-weight: 500; min-height: 34px;
}
.chip:hover { border-color: var(--accent-text); color: var(--accent-text); }
.order {
  width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-2); font-family: "DM Mono", monospace; font-size: 12px; color: var(--ink-2);
}
.delta { font-family: "DM Mono", monospace; font-size: 12.5px; white-space: nowrap; }
.delta.up { color: var(--bad); }
.delta.down { color: var(--good); }
.delta.flat { color: var(--ink-3); }

.meter { height: 3px; background: var(--surface-2); margin: 7px 0 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent-bg); transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
.meter.warn i { background: var(--warn); }
.meter.bad i { background: var(--bad); }
.meter.soft i { background: var(--ink-2); }
:root[data-theme="light"] .meter i { background: var(--ink); }
:root[data-theme="light"] .meter.warn i { background: var(--warn); }
:root[data-theme="light"] .meter.bad i { background: var(--bad); }
:root[data-theme="light"] .meter.soft i { background: var(--ink-3); }
.source { margin-top: 12px; }
.source .hint { margin-top: 0; }
.cat { margin-top: 12px; font-size: 14px; }
.cat small { margin-left: 3px; }

.banner {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--accent-bg); color: var(--accent-on); padding: 13px 16px; margin: 14px 0 0; border-radius: 4px;
}
.banner .fig { font-size: 14px; font-weight: 500; }
.banner-cta { font-weight: 700; font-size: 13.5px; }
.empty { padding: 8px 0; color: var(--ink-3); font-size: 14px; }
.empty .btn { margin-top: 10px; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px;
  padding: 0 18px; border-radius: 4px; font-weight: 600; font-size: 14.5px; text-decoration: none; text-align: center; cursor: pointer;
}
.btn.solid { background: var(--accent-bg); color: var(--accent-on); }
.btn.solid:hover { filter: brightness(1.06); }
.btn.solid:disabled { opacity: 0.6; }
.btn.ghost { border: 1px solid var(--line); }
.btn.ghost:hover { border-color: var(--ink-3); }
.btn.danger { color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent); }
.btn.wide { width: 100%; flex: 1; margin-top: 12px; }
.sheet-foot .btn.wide { margin-top: 0; }
.btn-row { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 130px; }

/* ---------- Cartões ---------- */
.plastics { display: grid; gap: 8px; margin-bottom: 8px; }
.plastic { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.plastic.open { border-color: var(--ink-3); }
.plastic-head { display: flex; justify-content: space-between; gap: 12px; width: 100%; padding: 14px; align-items: center; }
.plastic-head strong { display: block; font-family: "Instrument Serif", serif; font-weight: 400; font-size: 22px; line-height: 1.15; }
.plastic-value { display: grid; justify-items: end; flex: none; }
.plastic-body { padding: 14px; border-top: 1px solid var(--line); }
.upcoming { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.upcoming div { display: grid; gap: 1px; font-size: 12.5px; color: var(--ink-3); }
.upcoming .fig { color: var(--ink); }
.person-name { font-family: "Instrument Serif", serif; font-size: 22px; }

/* ---------- Gráfico ---------- */
.chart { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; height: 170px; align-items: stretch; margin-top: 10px; }
.bar { display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; min-width: 0; }
.bar-stack { flex: 1; min-height: 0; display: flex; flex-direction: column-reverse; justify-content: flex-start; gap: 2px; }
.bar-stack i { display: block; min-height: 2px; }
.bar-stack i:last-child { border-radius: 4px 4px 0 0; }
.bar-label { font-size: 11px; color: var(--ink-3); text-align: center; padding-top: 4px; border-top: 2px solid transparent; }
.bar.on .bar-label { color: var(--ink); border-top-color: var(--ink); font-weight: 600; }
.bar:not(.on) .bar-stack { opacity: 0.62; }
.bar:hover .bar-stack { opacity: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 4px; padding: 3px; margin: 6px 0; }
.segmented button { text-align: center; padding: 9px; border-radius: 2px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.segmented .on { background: var(--ink); color: var(--bg); }
.top-seg { margin-bottom: 8px; }

/* ---------- Navegação ---------- */
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  display: grid; justify-items: center; gap: 2px; padding: 9px 0 8px; font-size: 11px; color: var(--ink-3); text-align: center;
}
.nav .on { color: var(--ink); }
.nav .on .ico { color: var(--accent-text); }
.fab {
  position: fixed; z-index: 11; right: max(16px, calc(50vw - 254px)); bottom: calc(env(safe-area-inset-bottom) + 72px);
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-bg); color: var(--accent-on);
  box-shadow: 0 10px 28px color-mix(in srgb, var(--accent-bg) 28%, transparent);
  transition: transform 0.15s;
}
.fab:hover { transform: scale(1.05); }

/* ---------- Folhas ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 20; background: var(--backdrop); cursor: default; }
.sheet-enter .sheet-back { animation: fade 0.18s; }
.sheet-enter .sheet { animation: slide 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet {
  position: fixed; z-index: 21; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(100%, 540px); max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--surface); border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 8px 4px 16px; }
.sheet-head h2 { font-family: "Instrument Serif", serif; font-weight: 400; font-size: 24px; }
.sheet-body { padding: 4px 16px 16px; overflow-y: auto; flex: 1; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); border-top: 1px solid var(--line); }

.field { display: grid; gap: 4px; margin-top: 12px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--ink-2); }
.field small { font-size: 11.5px; }
input:not([type="checkbox"]), select, textarea {
  width: 100%; min-width: 0; min-height: 46px; padding: 10px 12px; font-size: 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; appearance: none;
}
:root[data-theme="light"] input:not([type="checkbox"]),
:root[data-theme="light"] select,
:root[data-theme="light"] textarea { background-color: #fff; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 20px, calc(100% - 12px) 20px;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent-text); }
.input-big { font-family: "DM Mono", monospace; font-size: 24px !important; letter-spacing: -0.03em; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: 42px; margin-top: 8px; font-size: 14px; }
.toggle.row { border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent); padding: 6px 0; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent-text); flex: none; }
.preview { font-size: 13px; color: var(--ink-2); background: var(--surface-2); padding: 10px 12px; margin-top: 12px; border-radius: 4px; }
.heard { font-size: 13.5px; color: var(--ink-2); margin-top: 8px; font-style: italic; }
.capture { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 4px; }
.voice {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 58px; width: 100%; margin-top: 4px;
  border: 1px solid var(--accent-text); border-radius: 4px; color: var(--accent-text); font-weight: 600;
}
.voice.live { background: var(--accent-bg); color: var(--accent-on); animation: pulse 1.1s infinite; }
.capture-alt {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 58px; padding: 0 14px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 4px; font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.capture-alt.wide { margin-top: 12px; width: 100%; }

/* ---------- Login ---------- */
.login { max-width: 400px; margin: 0 auto; padding: 14dvh 20px 32px; display: grid; gap: 8px; }
.login h1 { font-family: "Instrument Serif", serif; font-weight: 400; font-size: 52px; line-height: 1; letter-spacing: -0.02em; margin-top: 12px; }
.login form { margin-top: 10px; }
.login .btn { margin-top: 16px; }

#toast {
  position: fixed; z-index: 40; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 138px); transform: translate(-50%, 16px);
  width: max-content; max-width: calc(100vw - 32px); background: var(--ink); color: var(--bg);
  padding: 10px 14px; border-radius: 4px; font-size: 13.5px; font-weight: 500; opacity: 0; pointer-events: none; transition: 0.2s;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Movimento ---------- */
.enter .rise { animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.enter .rise:nth-of-type(2) { animation-delay: 40ms; }
.enter .rise:nth-of-type(3) { animation-delay: 80ms; }
.enter .rise:nth-of-type(4) { animation-delay: 120ms; }
.pulse { animation: pulse 1.2s infinite; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes pulse { 50% { opacity: 0.55; } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translate(-50%, 24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 360px) {
  .big { font-size: 52px; }
  .big-cur { vertical-align: 20px; }
  .trio dd, .fig { font-size: 12.5px; }
}
