/* ============ Liquid Glass ============ */
:root {
  --bg: #0b0b1a;
  --text: #f5f6ff;
  --muted: rgba(235, 238, 255, .62);
  --glass-fill: linear-gradient(135deg, rgba(255,255,255,.16), rgba(255,255,255,.04) 55%, rgba(255,255,255,.09));
  --glass-border: rgba(255,255,255,.28);
  --glass-shadow: 0 10px 40px rgba(0,0,0,.35);
  --hi: inset 0 1px 0 rgba(255,255,255,.55), inset 0 -1px 0 rgba(255,255,255,.08), inset 0 0 22px rgba(255,255,255,.06);
  --need: #5ac8fa;
  --want: #ff9f0a;
  --save: #30d158;
  --danger: #ff453a;
  --accent: #a78bfa;
  --r: 28px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
h2 { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: -.01em; }

/* Fondo animado de color: es lo que hace que el cristal "brille" */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .75; animation: float 22s ease-in-out infinite alternate; }
.b1 { width: 55vmax; height: 55vmax; background: #6d28d9; top: -18vmax; left: -15vmax; }
.b2 { width: 45vmax; height: 45vmax; background: #0ea5e9; bottom: -15vmax; right: -12vmax; animation-delay: -6s; }
.b3 { width: 35vmax; height: 35vmax; background: #ec4899; top: 35%; left: 45%; animation-delay: -12s; opacity: .55; }
.b4 { width: 28vmax; height: 28vmax; background: #10b981; top: 60%; left: -8vmax; animation-delay: -3s; opacity: .45; }
@keyframes float {
  0% { transform: translate(0,0) scale(1); }
  50% { transform: translate(6vmax,-4vmax) scale(1.08); }
  100% { transform: translate(-4vmax,5vmax) scale(.95); }
}
@media (prefers-reduced-motion: reduce) { .blob { animation: none; } }

/* La pieza clave */
.glass {
  position: relative;
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(26px) saturate(185%);
  backdrop-filter: blur(26px) saturate(185%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r);
  box-shadow: var(--hi), var(--glass-shadow);
  isolation: isolate;
}
/* reflejo especular superior */
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  background: radial-gradient(120% 60% at 20% 0%, rgba(255,255,255,.28), transparent 55%),
              radial-gradient(80% 50% at 100% 100%, rgba(255,255,255,.10), transparent 60%);
}
/* borde con brillo tipo refracción */
.glass::after {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none; padding: 1px;
  background: linear-gradient(135deg, rgba(255,255,255,.7), rgba(255,255,255,0) 35%, rgba(255,255,255,0) 65%, rgba(255,255,255,.35));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}

/* ============ Layout ============ */
.app {
  position: relative; z-index: 1;
  max-width: 980px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px calc(120px + var(--safe-b));
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; margin-bottom: 16px; border-radius: 999px;
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 8px); z-index: 5;
}
.month { display: flex; flex-direction: column; align-items: center; }
.month-label { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.month-sub { font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.1); font-size: 22px; cursor: pointer; line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4); transition: transform .15s, background .2s;
}
.icon-btn:active { transform: scale(.9); background: rgba(255,255,255,.2); }

.view { display: none; animation: rise .35s ease; }
.view.active { display: grid; gap: 16px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Las dos cuentas: sólo se ve la elegida */
.acc { display: none; }
body:not([data-acc="ahorro"]) .acc-gastos, body[data-acc="ahorro"] .acc-ahorro { display: contents; }
#view-tips .seg, #view-settings .seg { display: none; }

@media (min-width: 860px) {
  #view-home.active, #view-charts.active { grid-template-columns: 1fr 1fr; }
  #view-home .kpis, .wide { grid-column: 1 / -1; }
  .tall { grid-row: span 2; }
}

/* Selector Cuenta gastos / Cuenta ahorros */
.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 5px; border-radius: 999px; margin-bottom: 16px; }
.seg button { position: relative; z-index: 1; border: 0; background: none; padding: 10px 6px; border-radius: 999px; font-weight: 650; font-size: 14px; color: var(--muted); cursor: pointer; transition: color .3s; white-space: nowrap; }
.seg button.on { color: #fff; }
.seg-pill { position: absolute; z-index: 0; top: 5px; bottom: 5px; left: 5px; width: calc(50% - 5px); border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,.3), rgba(255,255,255,.1)); border: 1px solid rgba(255,255,255,.4);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 4px 16px rgba(0,0,0,.25); transition: transform .45s cubic-bezier(.3,1.4,.5,1); }
body[data-acc="ahorro"] .seg-pill { transform: translateX(100%); }
body.view-tips .seg, body.view-settings .seg { display: none; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 860px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.kpi-value { font-size: clamp(22px, 6vw, 30px); font-weight: 750; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-foot { font-size: 12px; color: var(--muted); text-align: left; padding: 0; }
.up { color: #ff8a80; } .down { color: #69f0ae; }

.card { padding: 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; }
.chip-soft { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); color: var(--muted); white-space: nowrap; }
.link { background: none; border: 0; color: #c4b5fd; cursor: pointer; font-weight: 600; font-size: 13px; }
.muted { color: var(--muted); margin: 0 0 12px; }

/* 50/30/20 */
.rule-row { margin-bottom: 14px; }
.rule-row:last-child { margin-bottom: 0; }
.rule-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.rule-top b { font-weight: 650; }
.rule-top small { color: var(--muted); }
.track { position: relative; height: 12px; border-radius: 999px; background: rgba(255,255,255,.1); box-shadow: inset 0 1px 3px rgba(0,0,0,.35); overflow: visible; }
.fill { height: 100%; border-radius: inherit; box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 0 14px currentColor; transition: width .6s cubic-bezier(.2,.8,.2,1); max-width: 100%; }
.target { position: absolute; top: -4px; bottom: -4px; width: 2px; background: #fff; border-radius: 2px; opacity: .85; }

/* Lista */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid rgba(255,255,255,.08); }
.item:last-child { border-bottom: 0; }
.ico { width: 40px; height: 40px; flex: none; border-radius: 14px; display: grid; place-items: center; font-size: 19px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); box-shadow: inset 0 1px 0 rgba(255,255,255,.4); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12px; color: var(--muted); }
.item-amt { font-weight: 700; white-space: nowrap; }
.del { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.del:hover { color: var(--danger); background: rgba(255,69,58,.12); }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; }

/* Charts */
.chart-wrap { position: relative; height: 240px; }
.chart-wrap.donut { height: 230px; }
.legend { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }
.legend .l-name { flex: 1; }
.legend .l-pct { color: var(--muted); font-size: 12px; width: 42px; text-align: right; }

/* Consejos */
.hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 18px; }
.hero-value { font-size: clamp(36px, 11vw, 52px); font-weight: 800; letter-spacing: -.03em; background: linear-gradient(180deg, #fff, #b9f6ca); -webkit-background-clip: text; background-clip: text; color: transparent; }
#tips { display: grid; gap: 12px; }
.tip { padding: 16px 16px 16px 18px; }
.tip-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.tip-emoji { font-size: 22px; line-height: 1.1; }
.tip-title { font-weight: 650; flex: 1; }
.tip-save { font-weight: 700; color: #69f0ae; white-space: nowrap; font-size: 14px; }
.tip p { margin: 0; color: var(--muted); font-size: 14px; }
.tip .src { display: block; margin-top: 8px; font-size: 11.5px; opacity: .8; }
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; margin-bottom: 8px; }
.badge.alta { background: rgba(255,69,58,.22); color: #ffb4ab; border: 1px solid rgba(255,69,58,.4); }
.badge.media { background: rgba(255,159,10,.2); color: #ffd59e; border: 1px solid rgba(255,159,10,.4); }
.badge.bien { background: rgba(48,209,88,.2); color: #b9f6ca; border: 1px solid rgba(48,209,88,.4); }
.badge.info { background: rgba(167,139,250,.2); color: #ddd6fe; border: 1px solid rgba(167,139,250,.4); }
.disclaimer { font-size: 11.5px; color: var(--muted); text-align: center; margin: 4px 8px 0; }
.challenge-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.challenge-big { font-size: 28px; font-weight: 800; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); min-width: 0; }
.glass-input {
  width: 100%; padding: 12px 14px; border-radius: 16px; border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.08); color: var(--text); font-size: 16px; outline: none;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.3), inset 0 -1px 0 rgba(255,255,255,.08);
  transition: border-color .2s, background .2s;
}
.glass-input:focus { border-color: rgba(196,181,253,.8); background: rgba(255,255,255,.13); }
input[type="date"] { color-scheme: dark; min-height: 47px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border-radius: 999px; border: 1px solid rgba(255,255,255,.25);
  background: linear-gradient(180deg, rgba(255,255,255,.2), rgba(255,255,255,.06));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 4px 14px rgba(0,0,0,.2);
  font-weight: 600; cursor: pointer; transition: transform .15s, filter .2s; flex: 1; text-align: center;
}
.btn:active { transform: scale(.96); }
.btn:hover { filter: brightness(1.12); }
.btn.primary { background: linear-gradient(180deg, rgba(167,139,250,.85), rgba(109,40,217,.75)); border-color: rgba(221,214,254,.6); }
.btn.danger { background: linear-gradient(180deg, rgba(255,69,58,.5), rgba(255,69,58,.25)); border-color: rgba(255,180,171,.5); }
.btn-row { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

/* FAB y barra de pestañas */
.fab {
  position: fixed; right: 20px; bottom: calc(96px + var(--safe-b)); z-index: 20;
  width: 62px; height: 62px; border-radius: 50%; font-size: 32px; font-weight: 300; cursor: pointer;
  background: linear-gradient(160deg, rgba(196,181,253,.75), rgba(109,40,217,.55));
  transition: transform .2s;
}
.fab:active { transform: scale(.9) rotate(90deg); }
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); z-index: 15;
  display: flex; gap: 4px; padding: 6px; border-radius: 999px; width: min(440px, calc(100% - 32px));
}
.tab {
  flex: 1; border: 0; background: transparent; border-radius: 999px; padding: 8px 4px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; font-weight: 600;
  color: var(--muted); cursor: pointer; transition: background .25s, color .25s;
}
.tab span { font-size: 18px; line-height: 1.1; }
.tab.active { color: #fff; background: rgba(255,255,255,.18); box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 2px 10px rgba(0,0,0,.2); }

/* Hoja inferior */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 30; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 31; width: min(560px, 100%);
  transform: translate(-50%, 110%); transition: transform .4s cubic-bezier(.2,.9,.2,1);
  border-radius: 32px 32px 0 0; padding: 10px 18px calc(20px + var(--safe-b));
  max-height: 92vh; overflow-y: auto;
  background: linear-gradient(135deg, rgba(40,30,80,.55), rgba(20,20,45,.6));
}
.sheet.open { transform: translate(-50%, 0); }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.4); margin: 0 auto 12px; }
.sheet h2 { text-align: center; margin-bottom: 8px; }
.amount-input {
  width: 100%; text-align: center; font-size: 44px; font-weight: 750; letter-spacing: -.02em;
  background: transparent; border: 0; outline: none; padding: 6px 0 14px; color: #fff;
}
.amount-input::placeholder { color: rgba(255,255,255,.3); }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 18px;
  border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.07); cursor: pointer;
  font-size: 11px; color: var(--muted); transition: all .2s; text-align: center; line-height: 1.15;
}
.cat .e { font-size: 22px; }
.cat.sel { background: rgba(255,255,255,.22); color: #fff; border-color: rgba(255,255,255,.55); box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 0 18px rgba(167,139,250,.35); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 16px); transform: translate(-50%, -150%);
  padding: 12px 20px; border-radius: 999px; z-index: 50; transition: transform .35s cubic-bezier(.2,.9,.2,1);
  font-weight: 600; font-size: 14px; max-width: calc(100% - 32px);
}
.toast.show { transform: translate(-50%, 0); }

/* Sin soporte de backdrop-filter: cristal más opaco para que se lea */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: rgba(30, 28, 60, .88); }
}

/* ============ Añadidos ============ */
.small { font-size: 12px; margin: 10px 0 0; }
.cloud { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.3); margin-right: 6px; vertical-align: middle; transition: background .3s, box-shadow .3s; }
.cloud.on { background: #30d158; box-shadow: 0 0 8px #30d158; }
.cloud.busy { background: #ffd60a; box-shadow: 0 0 8px #ffd60a; }
.cloud.off { background: #ff9f0a; }

.bump { animation: bump .5s cubic-bezier(.3,1.6,.5,1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.08); } 100% { transform: scale(1); } }
.item { animation: slideIn .45s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-14px) scale(.98); } to { opacity: 1; transform: none; } }
.card, .kpi { transition: transform .25s cubic-bezier(.3,1.4,.5,1); }
@media (hover: hover) { .kpi:hover, .tip:hover { transform: translateY(-3px); } }

.asset { cursor: pointer; border-radius: 16px; transition: background .2s; }
.asset:hover { background: rgba(255,255,255,.06); }
.asset .ico { font-weight: 800; font-size: 17px; }
.asset-right { text-align: right; }
.mini-track { height: 5px; border-radius: 99px; background: rgba(255,255,255,.1); margin-top: 6px; overflow: hidden; }
.mini-track div { height: 100%; border-radius: inherit; box-shadow: 0 0 8px currentColor; transition: width .6s; }

.swatches { display: flex; gap: 10px; justify-content: center; margin: 4px 0 8px; flex-wrap: wrap; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); cursor: pointer; box-shadow: inset 0 1px 0 rgba(255,255,255,.5); transition: transform .2s; }
.sw.sel { transform: scale(1.2); border-color: #fff; box-shadow: 0 0 14px rgba(255,255,255,.5); }
.btn.ghost { width: 100%; margin-top: 10px; background: transparent; box-shadow: none; }
.sync-user { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.sync-user .ico { font-size: 18px; }
.or { text-align: center; color: var(--muted); font-size: 12px; margin: 12px 0 2px; }

/* ============ Capa de animaciones ============ */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.fx-item { position: absolute; left: 0; top: 0; will-change: transform, opacity; line-height: 1; user-select: none; filter: drop-shadow(0 6px 12px rgba(0,0,0,.35)); }
.fx-flash { position: absolute; inset: 0; background: radial-gradient(circle at 50% 40%, rgba(255,255,255,.55), transparent 60%); }
.fx-ring { position: absolute; border-radius: 50%; border: 3px solid rgba(255,255,255,.8); box-shadow: 0 0 30px rgba(255,255,255,.5), inset 0 0 20px rgba(255,255,255,.3); }
