:root {
  --bg: #eef0f4;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #1b2430;
  --ink-soft: #3a4453;
  --muted: #6b7688;
  --line: #dfe3ea;
  --line-strong: #cad0da;

  --a: #3b5bdb; /* persona A (editable) */
  --b: #e8590c; /* persona B (editable) */
  --pos: #2f9e44;
  --neg: #c92a2a;
  --warn: #b6811a;
  --warn-bg: #fdf4e0;

  --r: 12px;
  --r-sm: 8px;
  --shadow: 0 1px 2px rgba(23, 32, 48, .06), 0 8px 24px rgba(23, 32, 48, .06);
  --shadow-sm: 0 1px 2px rgba(23, 32, 48, .07);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.mono, .cifra {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ---------------------------------------------------------------- Pantalla de PIN */
.pin-wrap {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(120% 120% at 50% 0%, #f4f6fa 0%, #e5e8ef 100%);
  padding: 24px;
  z-index: 50;
}
.pin-card {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; letter-spacing: -.02em; font-size: 18px;
  margin-bottom: 4px;
}
.brand .dot-a, .brand .dot-b { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.brand .dot-a { background: var(--a); }
.brand .dot-b { background: var(--b); margin-left: -6px; }
.pin-card h1 { font-size: 19px; margin: 14px 0 4px; letter-spacing: -.02em; }
.pin-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 8px 0 22px; height: 16px; }
.pin-dots i {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--line-strong); transition: transform .12s, background .12s;
}
.pin-dots i.on { background: var(--ink); transform: scale(1.05); }
.pin-dots.err i { background: var(--neg); animation: shake .3s; }
@keyframes shake {
  0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)}
}

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 8px; }
.keypad button {
  aspect-ratio: 1 / 1; border: none; border-radius: 50%;
  background: var(--surface-2); color: var(--ink);
  font-size: 22px; font-weight: 500;
  transition: background .1s, transform .05s;
}
.keypad button:hover { background: #eceef3; }
.keypad button:active { transform: scale(.94); }
.keypad button.ghost { background: transparent; font-size: 15px; color: var(--muted); font-weight: 600; }
.keypad button.ghost:hover { background: var(--surface-2); }
.pin-msg { min-height: 20px; margin-top: 16px; font-size: 13px; color: var(--neg); }
.pin-msg.info { color: var(--muted); }

/* Pantalla de acceso con Google (login.html) */
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 22px; padding: 12px 18px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font-size: 15px; font-weight: 600; text-decoration: none;
  box-shadow: var(--shadow-sm); transition: background .1s, border-color .1s;
}
.btn-google:hover { background: var(--surface-2); border-color: var(--muted); }
.btn-google:active { transform: scale(.99); }
.pin-card .pie { margin: 18px 0 0; font-size: 12px; color: var(--muted); }

/* Cuenta de Google en Ajustes */
.sesion-cuenta {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sesion-punto { width: 8px; height: 8px; border-radius: 50%; background: var(--pos); flex: none; }

/* ---------------------------------------------------------------- Layout app */
.app { display: none; min-height: 100vh; }
.app.on { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 940px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
}
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: none; background: none; color: var(--muted);
  padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 14px;
  white-space: nowrap;
}
.tabs button:hover { color: var(--ink); background: var(--surface-2); }
.tabs button.on { color: var(--ink); background: var(--surface-2); }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; width: 34px; height: 34px; color: var(--muted);
  display: grid; place-items: center;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }

main { max-width: 940px; margin: 0 auto; padding: 22px 20px 96px; }
.view { display: none; }
.view.on { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

h2.titulo { font-size: 20px; letter-spacing: -.02em; margin: 4px 0 2px; }
.subtitulo { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

/* Selector de mes */
.mes-sel { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 18px; }
.mes-sel button {
  border: 1px solid var(--line); background: var(--surface);
  width: 30px; height: 30px; border-radius: 8px; color: var(--ink-soft); font-size: 16px;
}
.mes-sel button:hover { border-color: var(--line-strong); }
.mes-sel span { font-weight: 600; min-width: 150px; text-align: center; text-transform: capitalize; }

/* Tarjetas y grids */
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: 1fr 1fr; }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-sm); padding: 16px 18px;
}
.card.pad-lg { padding: 20px; }

.stat .k { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .v.pos { color: var(--pos); }
.stat .v.neg { color: var(--neg); }
.stat .hint { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

/* Balance entre nosotros — elemento distintivo */
.balance-card { padding: 20px; }
.balance-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; }
.balance-head .quien { font-weight: 700; letter-spacing: -.01em; }
.balance-head .cuanto { font-family: var(--mono); font-weight: 700; font-size: 18px; }
.balance-bar {
  height: 12px; border-radius: 999px; overflow: hidden;
  display: flex; background: var(--line);
}
.balance-bar > div { min-width: 2px; }
.balance-legend { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* Reparto por titular */
.titular-lista { margin-top: 12px; display: flex; flex-direction: column; }
.titular-fila {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px;
}
.titular-fila:first-child { border-top: none; }
.titular-fila .cifra { font-weight: 600; }
.titular-fila .cifra.neg { color: var(--neg); }

/* ---------------------------------------------------------------- Cuentas */
.acciones-fila { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.grupo-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 22px 0 10px; font-size: 14px; color: var(--muted);
}
.grupo-head:first-of-type { margin-top: 4px; }
.grupo-head b { color: var(--ink); font-size: 15px; }
.grupo-head .cifra { font-weight: 600; color: var(--ink-soft); }

.cuenta-card { display: flex; flex-direction: column; gap: 12px; }
.cuenta-card.archivada { opacity: .6; }
.cuenta-top { display: flex; align-items: center; gap: 11px; }
.cuenta-icono {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 17px;
}
.cuenta-nombre { font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cuenta-top .meta { font-size: 12.5px; color: var(--muted); }
.cuenta-saldo .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.cuenta-saldo .v {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 22px; font-weight: 700; letter-spacing: -.02em;
}
.cuenta-saldo .v.pos { color: var(--pos); }
.cuenta-saldo .v.neg { color: var(--neg); }
.cuenta-saldo .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cuenta-acciones {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-top: 1px solid var(--line); padding-top: 10px; margin-top: auto;
}
.mini-link {
  border: none; background: transparent; color: var(--muted);
  padding: 4px 8px; border-radius: 6px; font-size: 13px; font-weight: 600;
}
.mini-link:hover { background: var(--surface-2); color: var(--ink); }

/* Filtros de movimientos */
.barra-filtros { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.barra-filtros .mes-sel { margin-bottom: 0; }
.filtro-cuenta {
  border: 1px solid var(--line-strong); border-radius: 9px; padding: 7px 10px;
  background: var(--surface); color: var(--ink); max-width: 100%;
}

.check-linea {
  display: flex; align-items: flex-start; font-size: 13.5px; color: var(--ink-soft);
  margin-bottom: 14px; cursor: pointer;
}

/* Edición de titulares */
.titular-edit { display: grid; grid-template-columns: 1fr 52px 32px; gap: 8px; margin-bottom: 8px; }
.titular-edit input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 9px 11px; background: var(--surface); color: var(--ink);
}
.titular-edit input[type="color"] { padding: 4px; height: 40px; }

/* Próximos cargos — timeline */
.timeline { display: flex; flex-direction: column; }
.tl-row {
  display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.tl-row:last-child { border-bottom: none; }
.tl-day { text-align: center; }
.tl-day .d { font-weight: 700; font-size: 17px; line-height: 1; }
.tl-day .m { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tl-main .n { font-weight: 600; }
.tl-main .meta { font-size: 12.5px; color: var(--muted); }
.tl-amt { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.tl-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; padding: 2px 7px; border-radius: 999px; vertical-align: middle;
}
.badge-sub { background: #eef1ff; color: #3446a8; }
.badge-fact { background: #e7f4ec; color: #1f6b41; }
.badge-card { background: #fdeee6; color: #b4571d; }
.badge-fin { background: #eceef3; color: var(--ink-soft); }
.badge-venc { background: #fbe4e4; color: var(--neg); }

/* Listas de items */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px 14px;
}
.item:hover { border-color: var(--line-strong); }
.pill-persona { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.item .desc { min-width: 0; }
.item .desc .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .desc .meta { font-size: 12.5px; color: var(--muted); }
.item .monto { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.item .monto.pos { color: var(--pos); }
.item .monto.neg { color: var(--ink); }
.item .monto.transf { color: var(--muted); }
.item .monto { text-align: right; }
.monto-sub { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.mini-btn.cobrar:hover { background: #eef1ff; color: #3446a8; }
.item .acciones { display: flex; gap: 4px; }
.mini-btn {
  border: none; background: transparent; color: var(--muted);
  width: 28px; height: 28px; border-radius: 6px; font-size: 14px;
}
.mini-btn:hover { background: var(--surface-2); color: var(--ink); }
.mini-btn.del:hover { color: var(--neg); background: #fbe9e9; }

.tag { display:inline-block; font-size:11.5px; color:var(--muted); background:var(--surface-2);
  border:1px solid var(--line); border-radius:999px; padding:1px 8px; margin-right:4px; }
/* Suscripción ya cancelada que sigue cobrando hasta que acabe el periodo. */
.tag.tag-fin { color: var(--warn); background: var(--warn-bg); border-color: #f0e0bb; }

.factura-icono { font-size: 17px; width: 22px; text-align: center; flex: none; }

/* Número de cuenta de la factura: se toca y se copia. */
.ref-copiar {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 5px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft);
  border-radius: 7px; padding: 3px 8px; max-width: 100%;
}
.ref-copiar:hover { border-color: var(--line-strong); background: #eceef3; }
.ref-copiar:active { transform: scale(.98); }
.ref-num {
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ref-ico { font-size: 12px; color: var(--muted); flex: none; }
.field .ref-copiar { margin-top: 0; padding: 8px 12px; }
.field .ref-copiar .ref-num { font-size: 14px; }

/* Tarjeta de crédito (card view) */
.cc {
  background: linear-gradient(135deg, #232a38 0%, #313c52 100%);
  color: #fff; border-radius: 14px; padding: 18px; position: relative; overflow: hidden;
}
.cc::after { content:""; position:absolute; right:-40px; top:-40px; width:150px; height:150px;
  background: rgba(255,255,255,.06); border-radius:50%; }
.cc .banco { font-size: 13px; opacity: .8; }
.cc .nombre { font-weight: 700; font-size: 17px; letter-spacing: -.01em; margin-top: 2px; }
.cc .deuda-l { font-size: 12px; opacity: .75; margin-top: 16px; }
.cc .deuda { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 24px; font-weight: 700; }
.cc .cc-desglose { font-size: 12px; opacity: .75; margin-top: 3px; }
.cc .barra { height: 6px; border-radius: 999px; background: rgba(255,255,255,.2); margin: 12px 0 6px; overflow: hidden; }
.cc .barra i { display:block; height:100%; background:#fff; }
.cc .cc-meta { display: flex; justify-content: space-between; font-size: 12px; opacity: .85; }
.cc .cc-fechas { display:flex; gap:16px; margin-top:12px; font-size:12px; }
.cc .cc-fechas b { display:block; font-family: var(--mono); font-size:14px; }
.cc-acciones { display:flex; gap:6px; margin-top:14px; }
.cc-acciones button {
  border:1px solid rgba(255,255,255,.25); background:rgba(255,255,255,.08); color:#fff;
  border-radius:7px; padding:5px 10px; font-size:12.5px; font-weight:600;
}
.cc-acciones button:hover { background: rgba(255,255,255,.16); }

.cuota-row {
  display:grid; grid-template-columns:1fr auto; gap:8px; align-items:center;
  padding:10px 0; border-top:1px solid var(--line);
}
.cuota-row .prog { font-size:12px; color:var(--muted); }
.cuota-prog-bar { height:5px; background:var(--line); border-radius:999px; margin-top:5px; width:180px; max-width:40vw; overflow:hidden; }
.cuota-prog-bar i { display:block; height:100%; background:var(--a); }

/* Botón flotante + primario */
.fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 25;
  border: none; background: var(--ink); color: #fff;
  height: 52px; padding: 0 22px 0 18px; border-radius: 999px;
  font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 6px 20px rgba(23,32,48,.28);
}
.fab:hover { background: #2a3444; }
.fab .plus { font-size: 20px; line-height: 1; }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 9px; padding: 9px 15px; font-weight: 600; font-size: 14px;
}
.btn:hover { border-color: var(--line-strong); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #2a3444; }
.btn.danger { color: var(--neg); border-color: #f0c8c8; }
.btn.danger:hover { background: #fbe9e9; }
.btn.block { width: 100%; justify-content: center; display: flex; }

/* Empty states */
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 15px; color: var(--ink-soft); font-weight: 600; margin-bottom: 4px; }

/* ---------------------------------------------------------------- Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(23,32,48,.42);
  display: none; place-items: center; z-index: 40; padding: 18px;
}
.modal-bg.on { display: grid; }
.modal {
  width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 10px;
}
.modal-head h3 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.modal-body { padding: 4px 20px 8px; }
.modal-foot { padding: 14px 20px 20px; display: flex; gap: 10px; }
.modal-foot .btn { flex: 1; justify-content: center; display: flex; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 10px 12px; background: var(--surface); color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--a); box-shadow: 0 0 0 3px rgba(59,91,219,.12);
}
.field .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg {
  display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 10px;
}
.seg button {
  flex: 1; border: none; background: transparent; padding: 8px; border-radius: 7px;
  font-weight: 600; font-size: 13.5px; color: var(--muted);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
/* Nota de ayuda. Con margen propio (no negativo) para que no se solape con lo
   de arriba, y sin margen inferior cuando va dentro de un .field, que ya lo
   pone él. Vale igual para <p> que para <div>. */
.hint-line { font-size: 12px; line-height: 1.45; color: var(--muted); margin: 6px 0 14px; }
.field .hint-line { margin-bottom: 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 60;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

:focus-visible { outline: 2px solid var(--a); outline-offset: 2px; }

@media (max-width: 640px) {
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  main { padding: 18px 14px 96px; }
  .topbar-inner { padding: 10px 14px; }
  .stat .v { font-size: 23px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
