:root {
  --bg: #0f1220;
  --bg2: #171a2b;
  --card: #1e2136;
  --card2: #262a44;
  --line: #2f3354;
  --txt: #eef0fb;
  --muted: #9aa0c4;
  --primary: #6c7bff;
  --primary2: #8a97ff;
  --ingreso: #3ddc97;
  --gasto: #ff6b7d;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; }
input, select, button { font-size: 16px; }

/* ---------- LOGIN ---------- */
.login {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #23284a 0%, var(--bg) 60%);
}
.login-box {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 30px 24px;
}
.brand { text-align: center; margin-bottom: 24px; }
.brand .logo {
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(108, 123, 255, .45);
}
.brand h1 { margin: 14px 0 4px; font-size: 27px; font-weight: 800; letter-spacing: -.5px; }
.brand h1 span {
  background: linear-gradient(90deg, var(--primary2), #ffd54a);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand .sub { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.feats { display: flex; justify-content: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.feats span {
  font-size: 12px; color: var(--txt);
  background: var(--card2); border: 1px solid var(--line);
  padding: 6px 11px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 5px;
}
.ic { width: 24px; height: 24px; display: inline-block; vertical-align: middle; }
.feats .ic { width: 15px; height: 15px; }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login input {
  width: 100%; padding: 14px 16px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--txt); outline: none;
}
.login input:focus { border-color: var(--primary); }
.codigo-input { text-align: center; letter-spacing: 10px; font-size: 24px; font-weight: 700; }
.msg { text-align: center; font-size: 14px; margin-top: 14px; min-height: 20px; color: var(--muted); }
.msg.error { color: var(--gasto); }
.msg.ok { color: var(--ingreso); }

.primary {
  width: 100%; margin-top: 16px; padding: 14px;
  background: linear-gradient(180deg, var(--primary2), var(--primary));
  color: #fff; font-weight: 700; border-radius: 12px; font-size: 16px;
}
.primary:active { transform: translateY(1px); }
.ghost { width: 100%; margin-top: 10px; padding: 12px; background: transparent; color: var(--muted); border-radius: 12px; }

/* ---------- APP SHELL ---------- */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px calc(14px);
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.topbar-title { font-size: 20px; font-weight: 800; }
.mes-pill {
  background: var(--card2); color: var(--txt);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 4px;
}
.mes-pill .caret { opacity: .55; font-size: 10px; }
.mes-menu {
  position: absolute; top: calc(100% - 6px); right: 16px; z-index: 60;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .45);
  padding: 6px; max-height: 62vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px; min-width: 172px;
}
.mes-op {
  text-align: left; padding: 11px 14px; border-radius: 9px;
  color: var(--txt); font-size: 14px; background: transparent;
  white-space: nowrap; text-transform: capitalize;
}
.mes-op:active { background: var(--card2); }
.mes-op.activo { background: var(--primary); color: #fff; font-weight: 700; }

.vista { flex: 1; overflow-y: auto; min-height: 0; }

/* ---------- CHAT ---------- */
#v-chat { display: flex; flex-direction: column; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 12px; }
.burbuja { max-width: 84%; padding: 12px 14px; border-radius: 16px; font-size: 15px; line-height: 1.4; }
.burbuja.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.burbuja.bot { align-self: flex-start; background: var(--card); color: var(--txt); border-bottom-left-radius: 5px; }
.burbuja.bot.aviso { background: #3a2f1e; color: #ffce85; }

/* Tarjeta de confirmación de movimiento */
.mov-card {
  align-self: flex-start; width: 84%;
  background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--gasto); border-radius: 14px; padding: 14px;
}
.mov-card.ingreso { border-left-color: var(--ingreso); }
.mov-card .mc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mov-card .mc-monto { font-size: 22px; font-weight: 800; }
.mov-card.gasto .mc-monto { color: var(--gasto); }
.mov-card.ingreso .mc-monto { color: var(--ingreso); }
.mov-card .mc-cat {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  background: var(--card2); padding: 4px 9px; border-radius: 999px; color: var(--muted);
}
.mov-card .mc-desc { margin: 6px 0 2px; font-size: 15px; }
.mov-card .mc-meta { font-size: 12px; color: var(--muted); }
.mov-card .mc-acciones { display: flex; gap: 8px; margin-top: 12px; }
.mov-card .mc-acciones button {
  flex: 1; padding: 9px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--card2); color: var(--txt);
}
.mov-card .mc-acciones .ok { background: var(--ingreso); color: #072; }

.chat-bar {
  display: flex; gap: 10px; padding: 12px 14px;
  padding-bottom: calc(12px + var(--safe-b));
  border-top: 1px solid var(--line); background: var(--bg);
}
.chat-bar input[type="text"] {
  flex: 1; min-width: 0; padding: 14px 16px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 999px; color: var(--txt); outline: none;
}
.chat-bar input[type="text"]:focus { border-color: var(--primary); }
.iconbtn {
  width: 44px; height: 50px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--txt); font-size: 21px; border-radius: 12px;
  cursor: pointer;
}
.iconbtn:active { background: var(--card2); }
.iconbtn .ic { width: 26px; height: 26px; }
.mic.rec {
  background: var(--gasto); border-radius: 50%; width: 50px;
  animation: pulso 1s ease-in-out infinite;
}
.mic.rec .ic { filter: brightness(0) invert(1); }
@keyframes pulso { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.send {
  width: 50px; height: 50px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(180deg, var(--primary2), var(--primary));
  color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.send .ic { width: 23px; height: 23px; }

/* ---------- RESUMEN ---------- */
#v-resumen { padding: 18px 16px calc(18px + var(--safe-b)); }
.resumen-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rcard {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.rcard span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.rcard b { font-size: 22px; }
.rcard.ingreso b { color: var(--ingreso); }
.rcard.gasto b { color: var(--gasto); }
.rcard.resultado { grid-column: 1 / -1; }
.rcard.resultado b { font-size: 28px; }
.rcard.resultado.pos b { color: var(--ingreso); }
.rcard.resultado.neg b { color: var(--gasto); }
.seccion { margin: 26px 0 12px; font-size: 15px; color: var(--muted); }
.categorias { display: flex; flex-direction: column; gap: 12px; }
.cat-row .cat-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.cat-row .cat-top b { font-weight: 700; }
.cat-bar { height: 8px; background: var(--card2); border-radius: 999px; overflow: hidden; }
.cat-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary2)); border-radius: 999px; }
.vacio { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; line-height: 1.5; }

/* ---------- MOVIMIENTOS ---------- */
#v-movimientos { padding: 12px 12px calc(18px + var(--safe-b)); }
.mov-lista { display: flex; flex-direction: column; }
.dia-sep { font-size: 12px; color: var(--muted); margin: 16px 6px 8px; text-transform: capitalize; }
.mov-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.mov-item .mi-ico {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  background: var(--card2);
}
.mov-item .mi-body { flex: 1; min-width: 0; }
.mov-item .mi-desc { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mov-item .mi-cat { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.mov-item .mi-monto { font-weight: 800; font-size: 16px; white-space: nowrap; }
.mov-item .mi-monto.gasto { color: var(--gasto); }
.mov-item .mi-monto.ingreso { color: var(--ingreso); }

/* ---------- CUENTA ---------- */
#v-cuenta { padding: 18px 16px calc(18px + var(--safe-b)); }
.plan-estado { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.plan-estado.trial { border-left: 4px solid var(--primary); }
.plan-estado.pro { border-left: 4px solid var(--ingreso); }
.plan-estado.vencido { border-left: 4px solid var(--gasto); }
.pe-top { display: flex; justify-content: space-between; align-items: center; font-size: 15px; font-weight: 700; }
.badge-ok { font-size: 11px; background: var(--ingreso); color: #063; padding: 3px 9px; border-radius: 999px; font-weight: 700; }
.pe-dias { font-size: 34px; font-weight: 800; margin: 10px 0 8px; color: var(--primary2); }
.pe-dias small { font-size: 14px; font-weight: 500; color: var(--muted); }
.pe-bar { height: 8px; background: var(--card2); border-radius: 999px; overflow: hidden; }
.pe-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary2)); }
.pe-sub { margin-top: 12px; font-size: 13px; color: var(--muted); line-height: 1.4; }

.planes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.plan-card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 14px 14px; text-align: center; }
.plan-card.destacado { border-color: var(--primary); }
.plan-card.sel { outline: 2px solid var(--ingreso); outline-offset: -1px; }
.pc-tag { position: absolute; top: -9px; left: 50%; transform: translateX(-50%); font-size: 10px; font-weight: 700; background: var(--primary); color: #fff; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pc-nombre { font-size: 13px; color: var(--muted); }
.pc-precio { font-size: 22px; font-weight: 800; margin: 6px 0 12px; }
.pc-precio small { font-size: 12px; color: var(--muted); font-weight: 500; }
.pc-btn { width: 100%; padding: 10px; border-radius: 10px; font-weight: 700; font-size: 13px; background: var(--card2); color: var(--txt); }
.plan-card.destacado .pc-btn { background: linear-gradient(180deg, var(--primary2), var(--primary)); color: #fff; }

.cuenta-acciones { margin-top: 22px; display: flex; flex-direction: column; gap: 8px; }
.fila-accion { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--txt); font-size: 15px; }
.fila-accion em { color: var(--muted); font-style: normal; font-size: 13px; }
.fila-accion.salir { color: var(--gasto); }
.cuenta-mail { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ---------- NAV ---------- */
.nav {
  display: flex; border-top: 1px solid var(--line); background: var(--bg);
  padding-bottom: var(--safe-b);
}
.nav-btn {
  flex: 1; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 8px; font-size: 11px; font-weight: 600;
}
.nav-ic { width: 26px; height: 26px; filter: grayscale(1); opacity: .5; transition: filter .15s, opacity .15s; }
.nav-btn.activo { color: var(--primary2); }
.nav-btn.activo .nav-ic { filter: none; opacity: 1; }

/* ---------- MODAL ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal-box {
  width: 100%; max-width: 480px;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + var(--safe-b)); border-top: 1px solid var(--line);
}
.modal-box h3 { margin: 0 0 16px; }
.campo { margin-bottom: 14px; }
.campo label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.campo input, .campo select {
  width: 100%; padding: 12px 14px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; color: var(--txt); outline: none;
}
.segmented { display: flex; background: var(--bg2); border-radius: 10px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; padding: 10px; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 600; }
.segmented button.activo { background: var(--card2); color: var(--txt); }
.modal-acciones { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.modal-acciones .spacer { flex: 1; }
.modal-acciones button { padding: 12px 16px; border-radius: 10px; font-weight: 600; }
.danger { background: transparent; color: var(--gasto); }
.modal-acciones .primary, .modal-acciones .ghost { width: auto; margin: 0; }
