:root {
  --red: #DA0000;
  --red-dark: #A80000;
  --red-soft: #FDECEC;
  --bg: #F4F4F6;
  --card: #fff;
  --ink: #1A1A1F;
  --muted: #6B6B76;
  --line: #E8E8EC;
  --ok: #12805C;
  --ok-soft: #E3F5EE;
  --warn: #B45309;
  --warn-soft: #FEF3E2;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 6px 18px rgba(20, 20, 30, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior-y: none;
}
h1, h2, h3, p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border: 0; border-radius: 14px;
  font-weight: 650; font-size: 16px; cursor: pointer; transition: transform .1s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .6; pointer-events: none; }
.btn-block { width: 100%; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:active { background: var(--red-dark); }
.btn-light { background: #fff; color: var(--red); }
.btn-ghost { background: var(--red-soft); color: var(--red-dark); }
.btn-outline { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn-sm { min-height: 42px; padding: 0 16px; font-size: 15px; border-radius: 12px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: #3A3A44; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 54px; padding: 0 16px; font-size: 16px;
  border: 1.5px solid var(--line); border-radius: 14px; background: #fff; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { padding: 14px 16px; min-height: 120px; resize: vertical; }
.field select { appearance: none; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236B6B76' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center; padding-right: 44px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--red); box-shadow: 0 0 0 4px rgba(218, 0, 0, .12); }
.pw { position: relative; }
.pw input { padding-right: 52px; }
.pw-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; }
.form-erro { background: var(--red-soft); color: var(--red-dark); padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 550; margin-bottom: 14px; }

/* ---------- Login ---------- */
.login-body { background: var(--red); }
.login { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.login-top { padding: calc(var(--safe-top) + 44px) 24px 38px; text-align: center; color: #fff; }
.login-logo { width: 168px; height: auto; display: block; margin: 0 auto 6px; }
.login-sub { font-size: 15px; opacity: .92; letter-spacing: .02em; }
.login-sheet {
  flex: 1; background: #fff; border-radius: 30px 30px 0 0;
  padding: 30px 24px calc(var(--safe-bottom) + 28px);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .12);
}
.login-sheet h1 { font-size: 26px; font-weight: 750; letter-spacing: -.01em; }
.login-sheet > .muted { margin: 4px 0 24px; font-size: 15px; }
.login-help { text-align: center; font-size: 13px; margin-top: 22px; }

/* ---------- Shell ---------- */
.app { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 12px); }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--red); color: #fff;
  padding: calc(var(--safe-top) + 10px) 16px 10px; display: flex; align-items: center; justify-content: space-between;
}
.topbar-logo { height: 34px; width: auto; display: block; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .14); color: #fff; display: grid; place-items: center; }
.icon-btn:active { background: rgba(255, 255, 255, .28); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom);
}
.tabbar a { height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; font-weight: 600; color: #8A8A95; }
.tabbar a.on { color: var(--red); }
.tabbar svg { width: 24px; height: 24px; }

.view { padding: 0 16px 8px; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-head { padding: 22px 2px 14px; }
.page-head h1 { font-size: 26px; font-weight: 750; letter-spacing: -.01em; }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* ---------- Home ---------- */
.home-head { background: var(--red); color: #fff; margin: 0 -16px; padding: 6px 20px 70px; border-radius: 0 0 28px 28px; }
.home-head h1 { font-size: 24px; font-weight: 750; letter-spacing: -.01em; }
.home-head p { font-size: 14px; opacity: .9; margin-top: 2px; }

.hero {
  position: relative; margin: -52px 0 14px; background: var(--card); border-radius: 22px; padding: 20px;
  box-shadow: 0 2px 4px rgba(20, 20, 30, .06), 0 14px 32px rgba(20, 20, 30, .12);
}
.hero-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.hero-valor { font-size: 40px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 2px; line-height: 1.1; }
.hero-sub { font-size: 14px; color: var(--muted); }
.hero .btn { margin-top: 16px; }
.hero.late { border: 1.5px solid #F2B0B0; }
.hero.late .hero-valor { color: var(--red-dark); }
.hero-more { margin-top: 12px; font-size: 13px; color: var(--red-dark); font-weight: 600; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.chip-late { background: var(--red-soft); color: var(--red-dark); }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-neutral { background: #EEF0F3; color: #4A4A55; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card-link { display: flex; align-items: center; gap: 14px; }
.card-ico { width: 46px; height: 46px; border-radius: 14px; background: var(--red-soft); color: var(--red); display: grid; place-items: center; flex: none; }
.card-txt { flex: 1; min-width: 0; }
.card-txt b { display: block; font-size: 16px; font-weight: 700; }
.card-txt span { display: block; font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-link > svg:last-child { color: #B8B8C2; width: 20px; height: 20px; }
.badge { min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: var(--red); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; }

.addr { display: flex; gap: 12px; align-items: flex-start; }
.addr .card-ico { width: 40px; height: 40px; border-radius: 12px; }
.addr small { display: block; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.addr p { font-size: 15px; line-height: 1.4; }

.section-title { font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 20px 2px 10px; }

/* ---------- Listas ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #E7E7EC; border-radius: 14px; padding: 4px; margin-bottom: 14px; }
.seg button { border: 0; background: none; min-height: 40px; border-radius: 11px; font-weight: 650; font-size: 14.5px; color: #5A5A66; }
.seg button.on { background: #fff; color: var(--red); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.item { display: block; width: 100%; text-align: left; border: 0; font: inherit; }
.item .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.item .t { font-weight: 700; font-size: 16px; }
.item .s { font-size: 13.5px; color: var(--muted); margin-top: 2px; }
.item .v { font-weight: 800; font-size: 18px; }
.item.late { border-left: 4px solid var(--red); }
.item.soon { border-left: 4px solid #F2A33A; }
.item.paid { border-left: 4px solid #35B58B; }

.empty { text-align: center; padding: 44px 24px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; stroke-width: 1.4; color: #C4C4CC; margin-bottom: 10px; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

.kv { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 600; text-align: right; }

.fab-row { margin: 8px 0 14px; }
.form-gap { margin-top: 16px; }
.sr-copy { position: fixed; left: -9999px; top: 0; opacity: 0; font-size: 16px; }

/* ---------- Bottom sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 15, 20, .5); animation: fadebg .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: #fff; border-radius: 26px 26px 0 0; padding: 10px 20px calc(var(--safe-bottom) + 22px);
  animation: up .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet-handle { width: 42px; height: 5px; border-radius: 3px; background: #D5D5DB; margin: 0 auto 14px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fadebg { from { opacity: 0; } to { opacity: 1; } }
.sheet h2 { font-size: 22px; font-weight: 750; }
.sheet .valor { font-size: 34px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 2px; }
.qr { display: block; width: 210px; height: 210px; margin: 16px auto 8px; border-radius: 12px; border: 1px solid var(--line); padding: 8px; image-rendering: pixelated; }
.code {
  background: #F4F4F6; border-radius: 12px; padding: 12px 14px; font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all; max-height: 84px; overflow: hidden; color: #3A3A44; margin: 8px 0 10px;
}
.stack { display: grid; gap: 10px; margin-top: 14px; }
.lbl { font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 18px; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Toast e skeleton ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-bottom) + 18px); transform: translateX(-50%); z-index: 80;
  background: #1A1A1F; color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14.5px; font-weight: 550;
  max-width: calc(100% - 32px); text-align: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: fade .2s;
}
.toast.err { background: var(--red-dark); }
.sk { position: relative; overflow: hidden; background: #E6E6EB; border-radius: 12px; }
.sk::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .6), transparent); transform: translateX(-100%); animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.sk-line { height: 14px; margin: 8px 0; }
.sk-card { height: 92px; margin-bottom: 12px; border-radius: var(--radius); }
.sk-hero { height: 180px; border-radius: 22px; margin: -52px 0 14px; position: relative; }

@media (min-width: 560px) {
  body { background: #E9E9EE; }
  .app, .login { max-width: 480px; margin: 0 auto; background: var(--bg); box-shadow: 0 0 40px rgba(0, 0, 0, .08); }
  .tabbar, .sheet-panel { max-width: 480px; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
