/* Cofre da Família — estilo (mobile-first) */
:root {
  --bg: #f3f4f9; --card: #ffffff; --ink: #141a2a; --mut: #67708a; --line: #e6e8f2;
  --pri: #4f46e5; --ok: #10b981; --neg: #e11d48; --warn: #f59e0b; --r: 16px;
  --shadow: 0 1px 2px rgba(20,26,42,.06), 0 8px 24px -12px rgba(20,26,42,.18);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
}
body.noscroll { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }

/* topbar */
.top { position: sticky; top: 0; z-index: 30; background: linear-gradient(180deg, #1e1b4b, #312e81); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px; display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand .logo { font-size: 26px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.3)); }
.brand b { display: block; font-size: 14.5px; line-height: 1.1; }
.brand small { color: #c7d2fe; font-size: 10.5px; display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; display: inline-block; }
.monthnav { display: flex; align-items: center; gap: 2px; background: rgba(255,255,255,.12); border-radius: 999px; padding: 2px; }
.navbtn { border: 0; background: transparent; color: #e0e7ff; width: 34px; height: 32px; border-radius: 999px; font-size: 19px; line-height: 1; }
.navbtn.mid { width: auto; padding: 0 10px; font-size: 13px; }
.iconbtn { border: 0; background: rgba(255,255,255,.12); width: 34px; height: 34px; border-radius: 10px; font-size: 16px; }

main#view { padding: 14px 14px 8px; display: grid; gap: 14px; }
section { margin: 0; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; }
.card h3 { margin: 0 0 8px; font-size: 15px; display: flex; align-items: center; gap: 6px; justify-content: space-between; flex-wrap: wrap;}
.muted { color: var(--mut); font-weight: 400; font-size: 12px; }
.hint { color: var(--mut); font-size: 12.5px; margin: 6px 0 0; }
.empty { color: var(--mut); font-size: 13px; font-style: italic; margin: 6px 0; }
.ok { color: var(--ok); font-size: 12px; font-weight: 600; }
.warn { color: var(--warn); }

/* hero */
.hero { border-radius: 20px; padding: 16px 16px 12px; color: #fff; box-shadow: var(--shadow);
  background: radial-gradient(120% 140% at 0% 0%, #6366f1 0%, #4338ca 55%, #3730a3 100%); }
.hero.neg { background: radial-gradient(120% 140% at 0% 0%, #f43f5e 0%, #9f1239 70%, #881337 100%); }
.hero-top { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: #e0e7ff; text-transform: capitalize; }
.hero .chipbtn { background: rgba(255,255,255,.18); color: #fff; border-color: transparent; }
.hero-balance { font-size: clamp(34px, 9vw, 46px); font-weight: 800; letter-spacing: -.5px; margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.hero-bar { height: 8px; background: rgba(255,255,255,.22); border-radius: 99px; overflow: hidden; }
.hero-bar i { display: block; height: 100%; border-radius: 99px; }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.hero-grid > div { background: rgba(255,255,255,.14); border-radius: 12px; padding: 8px 10px; }
.hero-grid small { display: block; font-size: 11px; color: #e0e7ff; }
.hero-grid b { font-size: 16px; font-variant-numeric: tabular-nums; }
.in, .pos-txt { color: #6ee7b7; } .out, .neg-txt { color: #fda4af; }
.hero .in, .hero .out { color: #fff; }

/* minicards */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.minicard { position: relative; text-align: left; border: 0; border-radius: var(--r); background: var(--card); box-shadow: var(--shadow); padding: 12px 12px 10px; overflow: hidden; display: grid; gap: 1px; }
.minicard .stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.minicard b { font-size: 14.5px; }
.minicard small { color: var(--mut); font-size: 12px; }
.minicard small.ok { color: var(--ok); } .minicard small.warn { color: var(--warn); }

/* alertas */
ul.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
ul.alerts li { display: flex; gap: 8px; align-items: center; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font-size: 13.5px; }
ul.alerts li > div { flex: 1; min-width: 0; }
ul.alerts li.lvl-warn { border-color: #fcd34d; background: #fffbeb; }
ul.alerts li.lvl-ok { border-color: #a7f3d0; background: #ecfdf5; }

/* listas de lançamentos */
.wallet-sec header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.w-title { display: flex; align-items: center; gap: 7px; min-width: 0; }
.w-title i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.w-title h3 { margin: 0; font-size: 14.5px; }
.w-total { display: flex; align-items: center; gap: 8px; }
.w-total b { font-size: 15.5px; font-variant-numeric: tabular-nums; }
.wallet-sec footer { margin-top: 6px; display: flex; gap: 14px; }
ul.entries { list-style: none; margin: 6px 0 0; padding: 0; }
.entry { display: flex; align-items: center; gap: 8px; padding: 8px 2px; border-top: 1px solid var(--line); cursor: pointer; }
.entry:first-child { border-top: 0; }
.entry.paid .e-name, .entry.paid .e-amt { color: var(--mut); text-decoration: line-through; text-decoration-thickness: 1px; text-decoration-color: #10b981; }
.e-main { flex: 1; min-width: 0; }
.e-name { font-size: 13.8px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.e-sub { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.e-amt { font-variant-numeric: tabular-nums; font-size: 13.8px; white-space: nowrap; }
.inst { background: #eef2ff; color: #4338ca; font-size: 10.5px; font-weight: 700; border-radius: 6px; padding: 1px 6px; }
.chip { --cc: #94a3b8; font-size: 11px; color: #475569; background: color-mix(in srgb, var(--cc) 12%, white); border: 1px solid color-mix(in srgb, var(--cc) 30%, white);
  border-radius: 99px; padding: 0px 7px; white-space: nowrap; }
.chip.due { --cc: #f59e0b; } .chip.person { --cc: #8b5cf6; }
.ck input { width: 20px; height: 20px; accent-color: var(--ok); margin: 0; padding: 4px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* chips/botões */
.chipbtn { border: 1px solid var(--line); background: #fff; border-radius: 999px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; color: var(--pri); }
.chipbtn:hover { background: #eef2ff; }
.linkbtn { border: 0; background: none; color: var(--pri); font-size: 13px; font-weight: 600; padding: 6px 0 0; }
.btn { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: #fff; font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.ghost { background: #f1f5f9; border-color: transparent; color: #334155; }
.btn.danger { background: #fff1f2; border-color: #fecdd3; color: #be123c; }

/* orçamento */
.budget { margin-bottom: 10px; }
.budget-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 3px; }
.budget-row small { color: var(--mut); }
.bar { height: 8px; background: #eef1f8; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.budget-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.brow { display: grid; gap: 3px; font-size: 12px; color: var(--mut); }
.brow input { border: 1px solid var(--line); border-radius: 10px; padding: 8px; font: inherit; background: #f8fafc; }

/* calendário */
table.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th { font-size: 11px; color: var(--mut); padding: 4px 0; font-weight: 600; }
.cal td { vertical-align: top; border: 1px solid var(--line); height: 62px; padding: 3px 4px; font-size: 11px; cursor: pointer; border-radius: 0; }
.cal td.void { border: 0; background: none; cursor: default; }
.cal td b { font-size: 12.5px; }
.cal td.today { background: #eef2ff; outline: 2px solid var(--pri); outline-offset: -2px; }
.cal td.has { background: #fbfcff; }
.cal td i { display: inline-block; width: 14px; height: 4.5px; border-radius: 2px; background: var(--c, #888); margin-right: 2px; font-style: normal; }
.cal td s { display: block; margin-top: 3px; color: #be123c; text-decoration: none; font-weight: 700; font-size: 10.5px; }
.cal td .more { background: none; color: var(--mut); width: auto; font-weight: 600; }

/* tabelas */
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; color: var(--mut); font-size: 11px; font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 5px 6px; border-bottom: 1px solid #f1f3fa; }
.tbl .tot { font-weight: 700; }

/* barras */
.bars { display: flex; gap: 8px; align-items: flex-end; overflow-x: auto; padding: 8px 2px 4px; }
.bar-col { flex: 1; min-width: 56px; display: grid; justify-items: center; gap: 2px; }
.bar-pair { height: 78px; display: flex; gap: 3px; align-items: flex-end; }
.b { width: 14px; border-radius: 4px 4px 0 0; }
.b.out { background: #818cf8; } .b.in { background: #34d399; }
.bar-col small { color: var(--mut); font-size: 11px; text-transform: capitalize; }
.bar-col b { font-size: 10.5px; white-space: nowrap; }
ul.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
ul.hbars li { display: grid; grid-template-columns: minmax(70px,1.4fr) 3fr auto auto; gap: 8px; align-items: center; font-size: 12.5px; }
ul.hbars small { color: var(--mut); width: 34px; text-align: right; }
.hb-track { height: 9px; background: #eef1f8; border-radius: 99px; overflow: hidden; }
.hb-track i { display: block; height: 100%; border-radius: 99px; }
.hb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* bottom nav + fab */
nav.bottom { position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: #fff; border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.tab { border: 0; background: none; display: grid; justify-items: center; gap: 0; font-size: 10.5px; color: var(--mut); padding: 4px 14px; border-radius: 12px; }
.tab span { font-size: 19px; line-height: 1.2; }
.tab.on { color: var(--pri); background: #eef2ff; font-weight: 700; }
.fab { position: fixed; right: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 41; width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--pri); color: #fff; font-size: 26px; box-shadow: 0 10px 24px -6px rgba(79,70,229,.55); }
.fab:active { transform: scale(.94); }

/* modal */
#modalroot { position: fixed; inset: 0; z-index: 60; }
.modal-back { position: absolute; inset: 0; background: rgba(15,18,35,.5); display: flex; align-items: flex-end; justify-content: center; backdrop-filter: blur(2px); }
.modal { background: #fff; width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 88dvh; overflow: auto; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.form { display: grid; gap: 10px; margin-top: 10px; }
.fld { display: grid; gap: 3px; font-size: 12px; color: var(--mut); font-weight: 600; }
.fld input, .fld select, .fld textarea { border: 1.5px solid var(--line); border-radius: 11px; padding: 10px; font: inherit; background: #fbfcff; color: var(--ink); width: 100%; }
.fld input:focus, .fld select:focus { outline: none; border-color: var(--pri); }
.fld input[type=color] { padding: 3px; height: 42px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.check input { width: 19px; height: 19px; accent-color: var(--pri); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.modal-actions.column { flex-direction: column; align-items: stretch; }
.totals-strip { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 10px 12px; }
.totals-strip div { display: grid; gap: 1px; }
.totals-strip small { font-size: 11px; color: var(--mut); }
.totals-strip b { font-size: 14.5px; font-variant-numeric: tabular-nums; }
.monthgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.mbtn { border: 1px solid var(--line); background: #fff; border-radius: 11px; padding: 10px 4px; font-size: 12.5px; font-weight: 600; text-transform: capitalize; }
.mbtn.on { background: var(--pri); color: #fff; border-color: var(--pri); }

/* toast */
#toast { position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 90;
  background: #141a2a; color: #fff; padding: 10px 16px; border-radius: 99px; font-size: 13px; opacity: 0; pointer-events: none; transition: .25s; max-width: 92vw; text-align: center; box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 640px) {
  .grid2 { grid-template-columns: repeat(4, 1fr); }
  .modal-back { align-items: center; }
  .modal { border-radius: 22px; }
}

/* ---------- AI assistant ---------- */
.top-acts { display:flex; gap:6px; }
.iconbtn.ai { background: linear-gradient(135deg,#8b5cf6,#6366f1); box-shadow: 0 4px 14px -4px rgba(139,92,246,.8); }
#ai-root { position: fixed; inset: 0; z-index: 70; pointer-events: none; }
.ai-back { position:absolute; inset:0; background: rgba(15,18,35,.45); opacity:0; transition:.2s; }
.ai-sheet { position:absolute; right:0; top:0; bottom:0; width:min(460px,100vw); background:#fff; display:flex; flex-direction:column;
  transform: translateX(102%); transition: .22s cubic-bezier(.2,.8,.2,1); box-shadow: -18px 0 60px -20px rgba(15,18,35,.4); }
#ai-root.on { pointer-events:auto; }
#ai-root.on .ai-back { opacity:1; }
#ai-root.on .ai-sheet { transform:none; }
.ai-sheet header { display:flex; justify-content:space-between; align-items:center; padding: 14px 14px 10px; background: linear-gradient(135deg,#4c1d95,#4338ca); color:#fff; }
.ai-sheet header b { font-size:16px; display:block; }
.ai-sheet header small { color:#ddd6fe; font-size:10.5px; display:block; max-width: 250px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.ai-sheet header .iconbtn { background: rgba(255,255,255,.14); color:#fff; }
.ai-body { flex:1; overflow-y:auto; padding:12px; display:flex; flex-direction:column; gap:10px; background:#f6f5fc; }
.ai-msg { max-width: 92%; }
.ai-msg .ai-bubble { border-radius:16px; padding:9px 12px; font-size:13.5px; background:#fff; box-shadow: var(--shadow); white-space:pre-wrap; }
.ai-msg.me { align-self:flex-end; }
.ai-msg.me .ai-bubble { background:#4f46e5; color:#fff; border-bottom-right-radius:6px; }
.ai-msg.bot .ai-bubble { border-bottom-left-radius:6px; }
.ai-msg.bot a { color:#4f46e5; }
.ai-bubble.thinking i { display:inline-block; width:6px; height:6px; border-radius:50%; background:#8b5cf6; margin-right:2px; animation: ping 1s infinite; }
.ai-bubble.thinking i:nth-child(2) { animation-delay:.18s } .ai-bubble.thinking i:nth-child(3) { animation-delay:.36s }
@keyframes ping { 0%,100%{opacity:.25} 50%{opacity:1} }
.ai-actions { margin-top:8px; border:1.5px dashed #a5b4fc; border-radius:12px; padding:8px 10px; background:#eef2ff; font-size:12.5px; }
.ai-actions.applied { border-style:solid; border-color:#86efac; background:#f0fdf4; }
.ai-actions-head { font-weight:700; font-size:12px; margin-bottom:4px; color:#3730a3; }
.ai-actions ul { margin:0; padding-left:2px; list-style:none; display:grid; gap:3px; }
.ai-errs { border-top:1px solid #fca5a5; margin-top:5px !important; color:#b91c1c; }
.ai-actions-btns { display:flex; gap:8px; margin-top:8px; }
.btn.sm { padding:6px 12px; font-size:12.5px; }
.ai-chips { display:flex; gap:6px; overflow-x:auto; padding: 8px 12px 0; background:#f6f5fc; scrollbar-width:none; }
.ai-chips button { flex:0 0 auto; border:1px solid #c7d2fe; background:#fff; color:#4338ca; border-radius:999px; font-size:11.5px; padding:6px 10px; font-weight:600; }
.ai-input { display:flex; gap:8px; padding:10px 12px calc(12px + env(safe-area-inset-bottom)); background:#fff; border-top:1px solid var(--line); }
.ai-input input { flex:1; border:1.5px solid var(--line); border-radius:12px; padding:11px 12px; font:inherit; background:#fbfcff; }
.ai-input input:focus { outline:none; border-color:#6366f1; }
.ai-input button { border:0; background:#4f46e5; color:#fff; border-radius:12px; width:44px; font-size:16px; }
.ai-cfg { display:grid; gap:10px; padding:4px; }
.ai-cfg h4 { margin:0; }
@media (min-width:900px){ .ai-sheet { border-radius:18px 0 0 18px; } }
