/* ==========================================================================
   Controle de Finanças — Apple HIG / SwiftUI Inset Grouped / visionOS Glass
   ========================================================================== */

:root,
:root[data-theme="light"] {
  --bg: #F2F2F7;
  --bg-elevated: #FFFFFF;
  --card: #FFFFFF;
  --card-secondary: #F2F2F7;
  --glass: rgba(249, 249, 251, 0.78);
  --glass-card: rgba(255, 255, 255, 0.86);
  --glass-border: rgba(255, 255, 255, 0.65);
  --text: #1C1C1E;
  --muted: #6C6C70;
  --tertiary: #8E8E93;
  --line: rgba(60, 60, 67, 0.14);
  --row-active: rgba(60, 60, 67, 0.08);
  --seg-bg: rgba(118, 118, 128, 0.12);
  --seg-pill: #FFFFFF;
  --primary: #0D7A6F;
  --primary-soft: rgba(13, 122, 111, 0.13);
  --blue: #007AFF;
  --green: #248A3D;
  --green-soft: rgba(52, 199, 89, 0.15);
  --red: #D70015;
  --red-soft: rgba(255, 59, 48, 0.14);
  --amber: #B25000;
  --amber-soft: rgba(255, 159, 10, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --hero-grad: linear-gradient(145deg, #138B7E 0%, #0B645B 100%);
  --radius: 16px;
  --radius-lg: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --spring: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1C1C1E;
  --card: #1C1C1E;
  --card-secondary: #2C2C2E;
  --glass: rgba(28, 28, 30, 0.76);
  --glass-card: rgba(28, 28, 30, 0.84);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text: #F5F5F7;
  --muted: #98989F;
  --tertiary: #636366;
  --line: rgba(84, 84, 88, 0.48);
  --row-active: rgba(255, 255, 255, 0.08);
  --seg-bg: rgba(118, 118, 128, 0.24);
  --seg-pill: #636366;
  --primary: #2AD1C0;
  --primary-soft: rgba(42, 209, 192, 0.16);
  --blue: #0A84FF;
  --green: #30D158;
  --green-soft: rgba(48, 209, 88, 0.18);
  --red: #FF453A;
  --red-soft: rgba(255, 69, 58, 0.2);
  --amber: #FF9F0A;
  --amber-soft: rgba(255, 159, 10, 0.18);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.55);
  --hero-grad: linear-gradient(145deg, #15857A 0%, #0B564E 100%);
  color-scheme: dark;
}

:root { font-size: 19px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  transition: background-color .22s ease, color .22s ease;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input { -webkit-appearance: none; appearance: none; }
a { color: inherit; text-decoration: none; }

.splash { min-height: 100vh; display: grid; place-items: center; }
.splash img { width: 92px; height: 92px; border-radius: 22px; box-shadow: var(--shadow-lg); }

/* ---------- Barra Superior Translúcida (iOS NavigationBar) ---------- */
.navbar {
  position: sticky; top: 0; z-index: 25;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 0.5px solid var(--line);
  padding: calc(var(--safe-top) + 4px) 16px 8px;
}
.navbar-inner {
  max-width: 640px; margin: 0 auto;
  min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.navbar-title {
  font-size: .92rem; font-weight: 650; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.navbar-action {
  color: var(--primary); font-weight: 650; font-size: .95rem;
  min-height: 40px; display: inline-flex; align-items: center; gap: 4px; padding: 0 4px;
}

/* ---------- Estrutura e Animação de Tela ---------- */
.screen {
  min-height: calc(100vh - 56px);
  padding: 12px 16px calc(var(--safe-bottom) + 116px);
  max-width: 640px;
  margin: 0 auto;
  animation: screenIn .22s var(--spring);
}
@keyframes screenIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 40px; margin-bottom: 2px; }
.back {
  display: inline-flex; align-items: center; gap: 3px;
  color: var(--primary); font-size: 1.02rem; font-weight: 600;
  min-height: 42px; padding-right: 10px;
}
.back::before { content: "‹"; font-size: 1.95rem; line-height: 1; margin-top: -3px; }
.back:active { opacity: .6; }

h1 {
  font-size: 1.85rem; font-weight: 800; line-height: 1.12;
  margin: 2px 0 14px; letter-spacing: -0.024em;
}
h2 {
  font-size: .82rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em;
  margin: 24px 14px 8px; color: var(--muted);
}
h2 .count { color: var(--tertiary); font-weight: 600; }
.hello { color: var(--muted); font-size: .92rem; font-weight: 500; margin: 0 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* ---------- Barra de Abas Translúcida (iOS TabBar) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
  border-top: 0.5px solid var(--line);
  padding: 5px 6px calc(var(--safe-bottom) + 4px);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 0; color: var(--muted); font-size: .68rem; font-weight: 600;
  transition: color .15s ease, transform .12s var(--spring);
}
.tab:active { transform: scale(.93); }
.tab .ico { font-size: 1.45rem; line-height: 1.1; filter: grayscale(0.85); opacity: .68; transition: filter .15s ease, opacity .15s ease, transform .15s var(--spring); }
.tab.on { color: var(--primary); }
.tab.on .ico { filter: none; opacity: 1; transform: translateY(-1px); }

/* ---------- Cartões e Listas (SwiftUI .insetGrouped) ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 0.5px solid var(--line);
  padding: 16px;
  margin-bottom: 12px;
}
.list {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 0.5px solid var(--line);
  overflow: hidden;
  margin-bottom: 12px;
}
.row {
  position: relative;
  display: flex; align-items: center; gap: 13px; width: 100%; text-align: left;
  padding: 13px 16px; min-height: 64px;
  transition: background-color .12s ease;
}
.row:not(:last-child)::after {
  content: "";
  position: absolute; right: 0; bottom: 0; left: 16px;
  height: 0.5px; background: var(--line);
}
.row.has-lead:not(:last-child)::after { left: 74px; }
button.row:active, .row.tap:active { background: var(--row-active); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 650; font-size: 1.03rem; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.row .sub { color: var(--muted); font-size: .86rem; margin-top: 2px; }
.row .right { text-align: right; flex-shrink: 0; }
.row .amount { font-weight: 700; font-size: 1.04rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chev::after { content: "›"; color: var(--tertiary); font-size: 1.55rem; font-weight: 500; margin-left: 2px; }

.avatar {
  width: 45px; height: 45px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; color: #fff;
  box-shadow: inset 0 1px 1px rgba(255,255,255,.3);
}
.type-ico {
  width: 45px; height: 45px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 1.45rem; background: var(--primary-soft);
}

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; white-space: nowrap;
}
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.gray { background: var(--seg-bg); color: var(--muted); }

/* ---------- Resumo e Seletor de Mês ---------- */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.summary .card { margin: 0; padding: 15px; }
.summary .label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.summary .big { font-size: 1.38rem; font-weight: 800; margin-top: 4px; letter-spacing: -.015em; font-variant-numeric: tabular-nums; }
.summary .card.main {
  grid-column: 1 / -1;
  background: var(--hero-grad);
  border-color: rgba(255,255,255,.18);
  color: #fff;
  box-shadow: 0 8px 22px rgba(13, 122, 111, 0.24);
}
.summary .card.main .label { color: rgba(255,255,255,.86); }
.summary .card.main .big { font-size: 2.05rem; }

.month-nav {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 0.5px solid var(--line);
  border-radius: 14px; padding: 5px 6px; margin: 4px 0 12px;
  box-shadow: var(--shadow);
}
.month-nav .m { font-weight: 700; font-size: 1.04rem; text-transform: capitalize; }
.month-nav button {
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--card-secondary);
  font-size: 1.55rem; color: var(--primary); display: grid; place-items: center;
  transition: transform .1s var(--spring);
}
.month-nav button:active { transform: scale(.92); }
.today-link { display: block; margin: -4px auto 12px; color: var(--primary); font-weight: 650; font-size: .88rem; min-height: 32px; }

/* ---------- Botões HIG ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 56px; padding: 12px 18px; border-radius: 14px;
  font-weight: 700; font-size: 1.04rem; letter-spacing: -0.01em;
  background: #0D7A6F; color: #fff;
  box-shadow: 0 2px 10px rgba(13, 122, 111, 0.22);
  transition: transform .12s var(--spring), opacity .12s ease;
}
:root[data-theme="dark"] .btn { background: #149688; }
.btn:active { transform: scale(.98); opacity: .92; }
.btn.secondary {
  background: var(--card); color: var(--primary);
  border: 0.5px solid var(--line); box-shadow: var(--shadow);
}
.btn.danger {
  background: var(--card); color: var(--red);
  border: 0.5px solid var(--line); box-shadow: var(--shadow);
}
.btn.danger-solid { background: var(--red); color: #fff; box-shadow: none; }
.btn.green { background: var(--green); color: #fff; box-shadow: 0 2px 10px rgba(36, 138, 61, 0.25); }
.btn[disabled] { opacity: .45; }
.btn + .btn { margin-top: 10px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row .btn + .btn { margin-top: 0; }

.pay {
  min-height: 42px; padding: 8px 14px; border-radius: 999px;
  background: var(--green); color: #fff; font-weight: 700; font-size: .9rem; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(36, 138, 61, 0.22);
  transition: transform .1s var(--spring);
}
.pay:active { transform: scale(.94); }
.link { color: var(--primary); font-weight: 600; min-height: 42px; padding: 8px 4px; }
.link.red { color: var(--red); }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--safe-bottom) + 82px); z-index: 20;
  padding: 0 20px; height: 54px; border-radius: 27px;
  background: #0D7A6F; color: #fff; font-weight: 700; font-size: 1rem;
  box-shadow: 0 8px 22px rgba(13, 122, 111, 0.38);
  border: 0.5px solid rgba(255,255,255,.25);
  transition: transform .12s var(--spring);
}
:root[data-theme="dark"] .fab { background: #149688; }
.fab:active { transform: scale(.95); }

/* ---------- Estado Vazio ---------- */
.empty { text-align: center; padding: 28px 14px; color: var(--muted); }
.empty .big-ico { font-size: 2.8rem; display: block; margin-bottom: 8px; }

/* ---------- Formulários ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 650; margin: 0 4px 7px; font-size: .95rem; }
.input {
  width: 100%; min-height: 56px; padding: 12px 16px;
  border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--text); font-size: 1.12rem;
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.money { font-size: 1.85rem; font-weight: 800; text-align: center; letter-spacing: -.015em; font-variant-numeric: tabular-nums; }
.input[type="date"] { min-height: 56px; display: block; }
.hint { color: var(--muted); font-size: .86rem; margin: 8px 4px 0; }
.error-msg { color: var(--red); font-weight: 600; margin: 10px 4px 0; min-height: 1.2em; font-size: .92rem; }

/* ---------- Assistente (Nova Dívida) ---------- */
.wizard-q { font-size: 1.5rem; font-weight: 800; margin: 8px 0 16px; letter-spacing: -.015em; line-height: 1.2; }
.steps { display: flex; gap: 6px; margin: 4px 0 18px; }
.steps span { flex: 1; height: 5px; border-radius: 3px; background: var(--seg-bg); transition: background-color .2s ease; }
.steps span.done { background: var(--primary); }
.type-grid { display: grid; gap: 10px; }
.type-btn {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  min-height: 68px; padding: 12px 16px; border-radius: 16px; background: var(--card);
  box-shadow: var(--shadow); border: 2px solid var(--line); font-weight: 650; font-size: 1.04rem;
  transition: transform .1s var(--spring), border-color .15s ease, background-color .15s ease;
}
.type-btn:active { transform: scale(.985); }
.type-btn .type-ico { width: 46px; height: 46px; }
.type-btn.on { border-color: var(--primary); background: var(--primary-soft); }
.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 10px 0 18px; }
.stepper button {
  width: 64px; height: 64px; border-radius: 50%; background: var(--card);
  border: 0.5px solid var(--line); box-shadow: var(--shadow);
  font-size: 2rem; font-weight: 700; color: var(--primary);
  transition: transform .1s var(--spring);
}
.stepper button:active { transform: scale(.92); }
.stepper .n { font-size: 2.9rem; font-weight: 800; min-width: 90px; text-align: center; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 18px; }
.chip {
  min-width: 56px; min-height: 44px; padding: 8px 14px; border-radius: 999px;
  background: var(--card); border: 0.5px solid var(--line); box-shadow: var(--shadow); font-weight: 700;
}
.chip.on { background: var(--primary); color: #fff; border-color: transparent; }
:root[data-theme="dark"] .chip.on { color: #000; }
.wizard-nav { position: sticky; bottom: calc(var(--safe-bottom) + 12px); margin-top: 22px; }
.review dl { margin: 0; }
.review .item { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 0.5px solid var(--line); }
.review .item:last-child { border-bottom: 0; }
.review dt { color: var(--muted); }
.review dd { margin: 0; font-weight: 700; text-align: right; }

/* ---------- Detalhe da Dívida ---------- */
.progress { height: 10px; border-radius: 5px; background: var(--seg-bg); overflow: hidden; margin: 10px 0 6px; }
.progress > span { display: block; height: 100%; background: var(--green); border-radius: 5px; transition: width .25s var(--spring); }
.inst.paid .title { color: var(--muted); }
.inst .num {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-weight: 800; background: var(--seg-bg); color: var(--muted); font-size: .92rem;
}
.inst.paid .num { background: var(--green-soft); color: var(--green); }
.inst.late .num { background: var(--red-soft); color: var(--red); }
.inst.late .sub { color: var(--red); font-weight: 600; }
.edit-amount { color: var(--primary); font-size: .8rem; font-weight: 600; padding: 4px 0; display: block; margin-left: auto; }
.actions { margin-top: 26px; }

/* ---------- Tela de Entrada (iOS Lock / Passcode) ---------- */
.lock {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 20px) 24px calc(var(--safe-bottom) + 20px); text-align: center;
  max-width: 440px; margin: 0 auto;
  animation: screenIn .25s var(--spring);
}
.lock .logo { width: 82px; height: 82px; border-radius: 20px; box-shadow: var(--shadow-lg); }
.lock h1 { margin: 14px 0 4px; font-size: 1.55rem; }
.lock p { margin: 0 0 18px; color: var(--muted); }
.dots { display: flex; gap: 18px; justify-content: center; margin: 10px 0 8px; }
.dots span {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--primary);
  transition: background-color .12s ease, transform .12s var(--spring);
}
.dots span.on { background: var(--primary); transform: scale(1.08); }
.dots.shake { animation: shake .4s; }
@keyframes shake { 20%,60% { transform: translateX(-10px); } 40%,80% { transform: translateX(10px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 15px 24px; justify-content: center; margin-top: 14px; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%;
  background: var(--card); border: 0.5px solid var(--line); box-shadow: var(--shadow);
  font-size: 1.85rem; font-weight: 500;
  transition: transform .08s ease, background-color .1s ease;
}
.keypad button:active { background: var(--primary-soft); transform: scale(.94); }
.keypad .blank { visibility: hidden; }
.keypad .del { background: none; border: 0; box-shadow: none; font-size: 1.02rem; font-weight: 600; color: var(--primary); }
.faceid-btn { margin: 8px 0 14px; }
.lock form { width: 100%; text-align: left; }

/* ---------- Folha Modal (iOS Sheet) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.42);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet {
  width: 100%; max-width: 640px;
  background: var(--bg-elevated);
  border-top: 0.5px solid var(--glass-border);
  border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 20px);
  max-height: 92vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: sheetUp .26s var(--spring);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--tertiary); opacity: .45; margin: 0 auto 14px; }
.sheet h3 { font-size: 1.28rem; font-weight: 750; margin: 2px 0 8px; letter-spacing: -0.015em; }
.sheet p { margin: 0 0 16px; color: var(--muted); }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Aviso Rápido (Dynamic Pill Toast) ---------- */
#toast-root {
  position: fixed; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 90px);
  z-index: 60; display: flex; justify-content: center; pointer-events: none; padding: 0 14px;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px;
  background: rgba(28, 28, 30, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
  color: #fff; padding: 13px 18px; border-radius: 999px;
  box-shadow: var(--shadow-lg); font-weight: 600; max-width: 500px; width: 100%;
  border: 0.5px solid rgba(255,255,255,.14);
  animation: toastIn .22s var(--spring);
}
@keyframes toastIn { from { transform: translateY(20px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.toast .grow { flex: 1; }
.toast button { color: #5CE6D6; font-weight: 800; padding: 6px 4px; min-height: 36px; }

.install-tip { background: var(--amber-soft); border: 1px solid rgba(255, 159, 10, 0.35); display: flex; gap: 10px; align-items: flex-start; }
.install-tip .x { margin-left: auto; font-size: 1.15rem; color: var(--muted); min-width: 32px; min-height: 32px; }

.search { margin-bottom: 12px; }

/* ---------- Seletor Segmentado (iOS Segmented Control) ---------- */
.seg {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: var(--seg-bg); padding: 4px; border-radius: 13px;
}
.seg button {
  min-height: 46px; border-radius: 10px;
  font-weight: 700; font-size: .92rem; color: var(--muted);
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg button.on {
  background: var(--seg-pill); color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.version { text-align: center; color: var(--muted); font-size: .78rem; margin-top: 26px; }
