/* ===========================================================================
   Contas · Design system
   Identidade propria: indigo -> violeta, com teal para "pago".
   Mobile-first, premium, animacoes suaves. Tema claro + dark automatico.
   =========================================================================== */
:root {
  --bg: #eceefa;
  --bg-2: #e1e5f7;
  --surface: #ffffff;
  --surface-2: #f6f7fe;
  --ink: #15172b;
  --ink-2: #565a78;
  --muted: #9094b2;
  --line: #e7e9f5;

  --brand: #4b43c7;
  --brand-2: #7a5cf5;
  --brand-ink: #2f2a78;
  --grad: linear-gradient(135deg, #5b4de0 0%, #7a5cf5 52%, #9a6cf0 100%);
  --grad-soft: linear-gradient(135deg, #eee9ff, #f3edff);

  --accent: #0fb5a6;
  --accent-soft: #dff6f3;
  --warn: #e08600;
  --warn-soft: #fcefd6;
  --danger: #e5484d;
  --danger-soft: #fce6e7;
  --edit: #1f7ae0;
  --edit-soft: #e2efff;

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
  --sh-1: 0 1px 2px rgba(24, 27, 56, 0.06), 0 6px 18px rgba(24, 27, 56, 0.06);
  --sh-2: 0 12px 40px rgba(50, 42, 120, 0.18);
  --sh-brand: 0 10px 30px rgba(91, 77, 224, 0.35);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-h: 64px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f1d;
    --bg-2: #14152a;
    --surface: #191b30;
    --surface-2: #20223b;
    --ink: #eef0ff;
    --ink-2: #aeb2d6;
    --muted: #7f83a8;
    --line: #292c46;
    --grad-soft: linear-gradient(135deg, #232248, #2a2554);
    --accent-soft: #103833;
    --warn-soft: #3a2c12;
    --danger-soft: #3a1c20;
    --edit: #6ab0ff;
    --edit-soft: rgba(46, 144, 250, 0.18);
    --sh-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 22px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3 { font-family: "Sora", sans-serif; margin: 0; letter-spacing: -0.02em; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input { font-family: inherit; }
[hidden] { display: none !important; }

/* ============================== LOGIN ============================== */
.login-screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% -10%, #6a5bf0 0%, #4b43c7 45%, #2e2a78 100%);
  overflow: hidden;
}
.login-orb { position: absolute; border-radius: 50%; filter: blur(50px); opacity: 0.55; }
.orb-1 { width: 320px; height: 320px; background: #9a6cf0; top: -80px; right: -60px; animation: float1 9s var(--ease) infinite alternate; }
.orb-2 { width: 280px; height: 280px; background: #18d6c4; bottom: -90px; left: -60px; animation: float2 11s var(--ease) infinite alternate; }
@keyframes float1 { to { transform: translate(-30px, 40px) scale(1.1); } }
@keyframes float2 { to { transform: translate(40px, -30px) scale(1.08); } }

.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 380px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 26px;
  padding: 30px 26px 26px;
  box-shadow: var(--sh-2);
  animation: rise 0.6s var(--ease) both;
}
@media (prefers-color-scheme: dark) {
  .login-card { background: rgba(25, 27, 48, 0.86); border-color: rgba(255,255,255,0.08); }
}
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(0.98); } }
.brand-mark {
  width: 78px; height: 78px; border-radius: 20px; overflow: hidden;
  box-shadow: var(--sh-2); margin-bottom: 18px;
}
.brand-mark img { width: 100%; height: 100%; display: block; }
.login-logo { display: block; width: 248px; max-width: 80%; margin: 2px auto 14px; }
.login-title { font-size: 26px; font-weight: 700; }
.login-sub { color: var(--ink-2); margin: 6px 0 22px; font-size: 14.5px; }

/* ============================== FORM ============================== */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); padding-left: 2px; }
.field > span em { color: var(--muted); font-style: normal; font-weight: 500; }
.field input {
  width: 100%; padding: 14px 15px; font-size: 16px;
  background: var(--surface-2); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.field input::placeholder { color: var(--muted); }
.field input:focus {
  outline: none; border-color: var(--brand-2);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(122, 92, 245, 0.14);
}
.form-error {
  margin: 0; font-size: 13.5px; color: var(--danger);
  background: var(--danger-soft); padding: 10px 12px; border-radius: var(--r-sm);
}

/* ============================== BUTTONS ============================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 18px; font-size: 15.5px; font-weight: 650;
  border-radius: var(--r-md); transition: transform 0.12s var(--ease), box-shadow 0.2s, filter 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: var(--sh-brand); }
.btn-primary:hover { filter: brightness(1.04); }
.btn-ghost { background: var(--surface-2); color: var(--ink-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }

/* ============================== APP SHELL ============================== */
.app {
  min-height: 100%;
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 18px);
  animation: fade 0.4s var(--ease);
}
@keyframes fade { from { opacity: 0; } }

.app-header {
  position: sticky; top: 0; z-index: 30;
  padding: calc(var(--safe-top) + 14px) 18px 14px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.month-switch { display: flex; align-items: center; justify-content: center; gap: 8px; }
.month-label {
  font-size: 19px; font-weight: 700; min-width: 168px; text-align: center;
  text-transform: capitalize;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; color: var(--ink-2);
  display: grid; place-items: center; transition: background 0.2s, transform 0.12s;
}
.icon-btn:active { transform: scale(0.9); background: var(--surface-2); }
.month-label.off { color: var(--warn); }
.month-flag {
  display: block; margin: 9px auto 0; padding: 4px 13px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.01em;
  transition: transform 0.12s var(--ease);
}
.month-flag:active { transform: scale(0.95); }
.month-flag.is-current { background: var(--accent-soft); color: var(--accent); }
.month-flag.is-other { background: var(--warn-soft); color: var(--warn); }

/* destaque do mês de referência + confirmação no sheet */
.ref-badge {
  display: inline-block; margin: 0 0 8px; padding: 5px 13px; border-radius: 999px;
  background: var(--grad-soft); color: var(--brand); font-weight: 800; font-size: 12px;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.confirm-box { background: var(--surface-2); border-radius: var(--r-md); padding: 6px 16px 10px; margin-bottom: 16px; }
.confirm-q { font-weight: 700; font-size: 15px; margin: 12px 0; }
.confirm-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.confirm-line span { color: var(--ink-2); }
.confirm-line strong { font-weight: 700; text-align: right; }
.cf-ref { background: var(--accent-soft); color: var(--accent); padding: 3px 11px; border-radius: 8px; text-transform: uppercase; font-size: 12.5px; letter-spacing: 0.04em; }

.view { padding: 18px 16px 86px; max-width: 640px; margin: 0 auto; animation: slideUp 0.42s var(--ease); }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } }

/* ============================== RING (signature) ============================== */
.ring-card {
  background: var(--grad); border-radius: var(--r-lg); padding: 26px;
  box-shadow: var(--sh-brand); position: relative; overflow: hidden;
}
.ring-card::after {
  content: ""; position: absolute; width: 200px; height: 200px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.14); top: -70px; right: -50px;
}
.ring-wrap { position: relative; width: 220px; height: 220px; margin: 0 auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(255, 255, 255, 0.22); stroke-width: 16; }
.ring-bar {
  fill: none; stroke: #fff; stroke-width: 16; stroke-linecap: round;
  stroke-dasharray: 540; stroke-dashoffset: 540;
  transition: stroke-dashoffset 1s var(--ease);
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.15));
}
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: #fff; text-align: center;
  padding: 0 26px;
}
.ring-eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.85; }
.ring-value { font-family: "Sora"; font-size: 30px; font-weight: 800; margin-top: 4px; line-height: 1.05; white-space: nowrap; }
.ring-meta { font-size: 13px; opacity: 0.9; margin-top: 4px; }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.stat-chip {
  background: var(--surface); border-radius: var(--r-md); padding: 16px;
  box-shadow: var(--sh-1); display: flex; flex-direction: column; gap: 4px;
}
.stat-k { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.stat-v { font-family: "Sora"; font-size: 20px; font-weight: 700; }

/* ============================== PANELS ============================== */
.panel {
  background: var(--surface); border-radius: var(--r-lg); padding: 18px;
  box-shadow: var(--sh-1); margin-top: 14px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.panel-head h3 { font-size: 16px; font-weight: 700; }
.panel-note, .panel-head span { font-size: 12px; color: var(--muted); }

/* ============================== CHART (pago e previsto) ============================== */
.legend { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); margin: -4px 0 12px; }
.legend .lg { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.legend .lg-paid { background: var(--accent); }
.legend .lg-prev { background: rgba(122, 92, 245, 0.30); margin-left: 10px; }
.chart { display: flex; align-items: stretch; gap: 8px; height: 156px; padding-top: 8px; overflow: hidden; }
.chart.is-empty { display: grid; place-items: center; height: auto; min-height: 110px; }
.chart-empty { text-align: center; color: var(--muted); padding: 14px 8px; }
.chart-empty-ico { font-size: 28px; display: block; margin-bottom: 8px; opacity: 0.75; }
.chart-empty p { margin: 0; font-size: 13px; line-height: 1.5; }
.bar-col {
  flex: 1 1 0; min-width: 0; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 5px;
}
.bar-val { font-size: 9.5px; color: var(--ink-2); white-space: nowrap; height: 12px; line-height: 12px; }
.bar-track { flex: 1; width: 100%; max-width: 34px; display: flex; align-items: flex-end; margin: 0 auto; }
.bar-prev {
  width: 100%; background: rgba(122, 92, 245, 0.30); border-radius: 8px 8px 4px 4px;
  height: 0; transition: height 0.8s var(--ease); display: flex; align-items: flex-end; overflow: hidden;
}
.bar-paid {
  width: 100%; background: linear-gradient(180deg, #19c9b6, #0fb5a6);
  height: 0; transition: height 0.85s var(--ease) 0.15s; border-radius: 0 0 4px 4px;
}
.bar-col.current .bar-prev { background: rgba(122, 92, 245, 0.45); box-shadow: 0 0 0 2px var(--accent) inset; }
.bar-lab { font-size: 10.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.bar-col.current .bar-lab { color: var(--brand); font-weight: 700; }

/* ============================== LISTS (contas) ============================== */
.list { display: flex; flex-direction: column; gap: 11px; }
.bill {
  background: var(--surface); border-radius: var(--r-md); padding: 15px 16px;
  box-shadow: var(--sh-1); display: flex; align-items: center; gap: 13px;
  border-left: 4px solid var(--line);
  animation: pop 0.4s var(--ease) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
.bill.is-paid { border-left-color: var(--accent); }
.bill.is-partial { border-left-color: var(--edit); }
.bill.is-due { border-left-color: var(--warn); }
.bill.is-overdue { border-left-color: var(--danger); }
.bill-body { flex: 1; min-width: 0; }
.bill-name { font-weight: 650; font-size: 15.5px; display: flex; align-items: center; gap: 7px; }
.bill-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.bill-amt { font-family: "Sora"; font-weight: 700; font-size: 16.5px; text-align: right; white-space: nowrap; }
.bill-amt small { display: block; font-family: "Inter"; font-weight: 500; font-size: 11px; color: var(--muted); }
button.bill-amt { background: none; border: none; cursor: pointer; color: var(--ink); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.amt-edit { transition: transform 0.12s var(--ease); }
.amt-edit:active { transform: scale(0.94); }
.amt-edit small {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px 3px 7px; border-radius: 999px;
  background: var(--edit-soft); color: var(--edit);
  font-weight: 700; font-size: 10.5px; letter-spacing: 0.01em;
}
.amt-edit small svg { width: 12px; height: 12px; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
}
.tag-paid { background: var(--accent-soft); color: var(--accent); }
.tag-partial { background: var(--edit-soft); color: var(--edit); }
.tag-due { background: var(--warn-soft); color: var(--warn); }
.tag-overdue { background: var(--danger-soft); color: var(--danger); }
.tag-pending { background: var(--surface-2); color: var(--ink-2); }
.tag-cat { background: var(--grad-soft); color: var(--brand); }

.bill-action {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--grad); color: #fff; box-shadow: var(--sh-brand); flex-shrink: 0;
  transition: transform 0.12s var(--ease);
}
.bill-action:active { transform: scale(0.88); }
.bill-action.undo { background: var(--surface-2); color: var(--ink-2); box-shadow: none; }
.amt-residual small { color: var(--edit); font-weight: 600; }
.bill-actions { display: flex; flex-direction: column; gap: 6px; align-items: center; flex-shrink: 0; }
.bill-actions .bill-action { width: 42px; height: 34px; }
.bill-action.small { width: 42px; height: 28px; border-radius: 10px; }
.cf-after { margin-top: 12px; padding: 10px 12px; border-radius: var(--r-sm); font-size: 13px; font-weight: 700; text-align: center; }
.cf-after.partial { background: var(--edit-soft); color: var(--edit); }
.cf-after.full { background: var(--accent-soft); color: var(--accent); }

/* mini list (templates cadastrados) */
.list-mini { display: flex; flex-direction: column; gap: 8px; }
.mini {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  border-radius: var(--r-sm); background: var(--surface-2);
}
.mini-body { flex: 1; min-width: 0; }
.mini-name { font-weight: 600; font-size: 14px; }
.mini-sub { font-size: 11.5px; color: var(--muted); }
.mini-act { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--ink-2); }
.mini-act:active { background: var(--line); }
.mini-act.danger { color: var(--danger); }

/* ============================== SEGMENT / TOGGLES ============================== */
.seg {
  display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; margin-bottom: 18px;
}
.seg-opt {
  flex: 1; padding: 10px; border-radius: 11px; font-weight: 650; font-size: 14px; color: var(--ink-2);
  transition: all 0.25s var(--ease);
}
.seg-opt.is-active { background: var(--surface); color: var(--brand); box-shadow: var(--sh-1); }

.toggles { display: flex; flex-direction: column; gap: 12px; padding: 4px 0; }
.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle input { display: none; }
.toggle-ui {
  width: 46px; height: 28px; border-radius: 999px; background: var(--line);
  position: relative; transition: background 0.25s var(--ease); flex-shrink: 0;
}
.toggle-ui::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.25s var(--ease);
}
.toggle input:checked + .toggle-ui { background: var(--brand-2); }
.toggle input:checked + .toggle-ui::after { transform: translateX(18px); }
.toggle-label { font-size: 14.5px; font-weight: 550; }

/* ============================== EMPTY ============================== */
.empty { text-align: center; padding: 50px 24px; color: var(--ink-2); }
.empty-art { font-size: 46px; margin-bottom: 10px; }
.empty h3 { font-size: 17px; margin-bottom: 6px; }
.empty p { font-size: 14px; margin: 0 0 18px; }

/* ============================== PROFILE ============================== */
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 52px; height: 52px; border-radius: 16px; background: var(--grad); color: #fff;
  display: grid; place-items: center; font-family: "Sora"; font-weight: 700; font-size: 22px;
  box-shadow: var(--sh-brand); text-transform: uppercase;
}
.profile-name { font-weight: 700; font-size: 16px; }
.profile-email { font-size: 13px; color: var(--ink-2); }
.muted-text { color: var(--ink-2); font-size: 14px; margin: 0 0 14px; }
.hint { font-size: 12.5px; color: var(--ink-2); background: var(--warn-soft); padding: 12px; border-radius: var(--r-sm); margin: 12px 0 0; line-height: 1.5; }
.version { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0; }
.panel .btn + .btn { margin-top: 10px; }
#logout-btn { margin: 14px 16px 0; width: calc(100% - 32px); max-width: 608px; }
@media (min-width: 641px) { #logout-btn { margin-left: auto; margin-right: auto; display: block; } }

/* ============================== FAB + TABBAR ============================== */
.fab {
  position: fixed; right: 18px; z-index: 40;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
  width: 58px; height: 58px; border-radius: 19px; color: #fff; background: var(--grad);
  box-shadow: var(--sh-brand); display: grid; place-items: center;
  transition: transform 0.16s var(--ease);
}
.fab:active { transform: scale(0.9) rotate(90deg); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(18px); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 10.5px; font-weight: 600; transition: color 0.2s;
}
.tab svg { width: 23px; height: 23px; transition: transform 0.2s var(--ease); }
.tab.is-active { color: var(--brand); }
.tab.is-active svg { transform: translateY(-1px) scale(1.08); }

/* ============================== BOTTOM SHEET ============================== */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 16, 30, 0.5);
  backdrop-filter: blur(2px); animation: fade 0.25s;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--surface); border-radius: 26px 26px 0 0;
  padding: 12px 20px calc(24px + var(--safe-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
  max-width: 640px; margin: 0 auto;
  animation: sheetUp 0.4s var(--ease);
}
@keyframes sheetUp { from { transform: translateY(100%); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 4px auto 14px; }
.sheet-title { font-size: 19px; font-weight: 700; }
.sheet-sub { font-size: 13.5px; color: var(--ink-2); margin: 4px 0 18px; }
.sheet .field { margin-bottom: 14px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 6px; }

/* ============================== TOAST ============================== */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-bottom) + 24px);
  transform: translateX(-50%) translateY(20px); z-index: 60;
  background: var(--ink); color: var(--surface); font-size: 14px; font-weight: 600;
  padding: 12px 18px; border-radius: 14px; box-shadow: var(--sh-2);
  opacity: 0; transition: opacity 0.3s, transform 0.3s var(--ease); max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--accent); color: #fff; }
.toast.err { background: var(--danger); color: #fff; }

/* ============================== BURST ============================== */
.burst { position: fixed; inset: 0; z-index: 55; pointer-events: none; }

/* ============================== RESPONSIVE ============================== */
@media (min-width: 720px) {
  .ring-wrap { width: 240px; height: 240px; }
  .fab { right: calc(50% - 320px + 8px); }
}

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