/* Gastos — estilo iOS: fondo difuminado, tarjetas de vidrio y hoja que sube desde abajo. */
:root {
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.62);
  --glass: rgba(255, 255, 255, 0.16);
  --glass-strong: rgba(255, 255, 255, 0.24);
  --line: rgba(255, 255, 255, 0.14);
  --field: rgba(0, 0, 0, 0.22);
  --sheet: #1c1c1f;
  --row: #2a2a2e;
  --green: #34c759;
  --red: #ff453a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: #1b1a22;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input { font-family: inherit; }
.hidden { display: none !important; }

/* Fondo tipo pantalla de inicio desenfocada */
.wallpaper {
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(40% 35% at 20% 30%, #4b5d7a 0%, transparent 70%),
    radial-gradient(35% 30% at 80% 25%, #7a5e66 0%, transparent 70%),
    radial-gradient(40% 35% at 35% 75%, #3d5a52 0%, transparent 70%),
    radial-gradient(35% 35% at 80% 80%, #5a4a7e 0%, transparent 70%),
    linear-gradient(180deg, #6c6763 0%, #3a3740 55%, #1b1a22 100%);
  filter: blur(40px) saturate(1.1);
  z-index: -1;
}

.view {
  min-height: 100%;
  padding: calc(var(--safe-top) + 64px) 16px calc(var(--safe-bottom) + 24px);
  max-width: 480px;
  margin: 0 auto;
}

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(30px) saturate(1.4);
  backdrop-filter: blur(30px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 28px;
}
.card { padding: 22px 18px 18px; transition: transform 0.35s cubic-bezier(.2, .8, .2, 1), opacity 0.3s ease; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 16px 10px;
  font-size: 17px;
  font-weight: 600;
}

.title { margin: 0 0 4px; font-size: 28px; font-weight: 700; letter-spacing: -0.4px; }
.sub { margin: 0 0 18px; font-size: 15px; color: var(--muted); line-height: 1.4; }

.amount {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  padding: 6px 0 18px;
}
.currency { font-size: 34px; font-weight: 600; color: var(--muted); }
.amount input {
  width: 1.4ch;
  min-width: 1.4ch;
  max-width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font-size: 52px;
  font-weight: 700;
  letter-spacing: -1px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  caret-color: #ffffff;
}
.amount input::placeholder { color: rgba(255, 255, 255, 0.3); }

.field {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 14px 16px;
  font-size: 17px;          /* 16px o más: iOS no hace zoom al escribir */
  color: var(--text);
  background: var(--field);
  border: 1px solid transparent;
  border-radius: 14px;
  outline: none;
}
.field::placeholder { color: rgba(255, 255, 255, 0.45); }
.field:focus { border-color: rgba(255, 255, 255, 0.35); }

.btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 15px;
  font-size: 17px;
  font-weight: 600;
  color: #111;
  background: #ffffff;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.35; cursor: default; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.card > .link { display: block; margin: 16px auto 0; font-weight: 500; color: var(--muted); }
.link.small { display: block; margin: 18px auto 0; font-size: 14px; font-weight: 500; color: var(--muted); }

/* Al registrar: la tarjeta se cierra y aparece la palomita */
.closing .card { transform: scale(0.9) translateY(-14px); opacity: 0; }
.done {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 34px;
  border-radius: 24px;
  background: rgba(30, 30, 34, 0.72);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  font-size: 17px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(.2, .8, .2, 1);
}
.done svg { width: 56px; height: 56px; fill: none; stroke: var(--green); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.done circle { stroke-width: 2.5; opacity: 0.35; }
.done path { stroke-dasharray: 40; stroke-dashoffset: 40; }
.done.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.done.show path { animation: check 0.4s 0.1s ease forwards; }
@keyframes check { to { stroke-dashoffset: 0; } }

/* Hoja con la lista de gastos */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 10; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  max-width: 560px;
  margin: 0 auto;
  height: min(78vh, 680px);
  display: flex;
  flex-direction: column;
  padding: 8px 16px calc(var(--safe-bottom) + 16px);
  background: var(--sheet);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.35);
  transform: translateY(105%);
  transition: transform 0.38s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: none; }
.grabber { width: 38px; height: 5px; margin: 0 auto 10px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 4px 4px 12px; }
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 700; }
.sheet-head p { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.day { margin: 14px 4px 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }
.group { background: var(--row); border-radius: 14px; overflow: hidden; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row-desc { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { font-size: 13px; color: var(--muted); }
.row { cursor: pointer; }
.row-amount { grid-row: 1; grid-column: 2; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
/* Tocar un gasto muestra "Eliminar" (para corregir una captura equivocada). */
.row-del {
  display: none;
  grid-row: 2;
  grid-column: 2;
  justify-self: end;
  background: none;
  border: 0;
  padding: 0;
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.row.armed { background: rgba(255, 255, 255, 0.04); }
.row.armed .row-del { display: block; }
.row.pending .row-time::after { content: " · sin conexión, se enviará"; }
.empty { padding: 40px 10px; text-align: center; color: var(--muted); font-size: 15px; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 14px);
  transform: translate(-50%, -20px);
  z-index: 20;
  max-width: 90%;
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(40, 40, 44, 0.9);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .card, .sheet, .done, .toast { transition: none; }
}
