:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #e9eef0;
  --text: #13262b;
  --muted: #5d7076;
  --accent: #0e9aa7;
  --accent-text: #ffffff;
  --accent-soft: #d4f0f2;
  --danger: #c0392b;
  --ok: #1e8e4e;
  --warn: #b7791f;
  --border: #d5dee1;
  --shadow: 0 1px 2px rgb(0 0 0 / .08);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1719;
    --surface: #182427;
    --surface-2: #213135;
    --text: #e6f0f2;
    --muted: #93a8ad;
    --accent: #22b8c5;
    --accent-text: #06272b;
    --accent-soft: #123a3f;
    --danger: #ff7b6b;
    --ok: #4cd08a;
    --warn: #f0b64a;
    --border: #2b3d41;
    --shadow: none;
    color-scheme: dark;
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] { display: none !important; }

.view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(12px, env(safe-area-inset-left));
  max-width: 520px;
  margin: 0 auto;
}

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.35em; margin: 6px 0; text-align: center; }
.title { font-weight: 600; }

.top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}
.top .title { flex: 1; text-align: center; }
.who { font-weight: 600; flex: 1; }
.link-btn { color: var(--accent); padding: 10px 6px; font-weight: 600; }
.link-btn.danger { color: var(--danger); }

.pill {
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill.warn { color: var(--warn); }
.pill.err { color: var(--danger); }

/* --- monto --- */
.amount {
  text-align: center;
  font-size: clamp(40px, 13vw, 60px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
  padding: 4px 0 8px;
  white-space: nowrap;
  overflow: hidden;
}
.amount .cur { color: var(--muted); font-weight: 500; margin-right: 6px; }
.amount.vacio #amount-val { color: var(--muted); }
.amount.shake { animation: shake .35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* --- opciones --- */
.opts { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.chip {
  position: relative;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip-date input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.desc-row { display: flex; gap: 8px; margin-bottom: 8px; }
.desc-row input {
  flex: 1;
  font: inherit;
  font-size: 16px; /* evita el zoom de iOS al enfocar */
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.icon-btn { font-size: 20px; padding: 0 12px; border-radius: 10px; background: var(--surface-2); }
.icon-btn.rec { background: var(--danger); }

/* --- categorías --- */
.cats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
  flex: 1;
  align-content: end;
}
.cat {
  min-height: 52px;
  padding: 6px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.15;
  box-shadow: var(--shadow);
  word-break: break-word;
}
.cat:active { filter: brightness(.9); transform: scale(.97); }
.cats.inactivo .cat { opacity: .45; }
.cat.mas { background: var(--surface-2); color: var(--text); }

/* --- teclado --- */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding-bottom: 8px;
}
.key {
  height: clamp(50px, 7.5dvh, 64px);
  border-radius: 12px;
  background: var(--surface);
  font-size: 26px;
  font-weight: 500;
  box-shadow: var(--shadow);
}
.key:active { background: var(--surface-2); }
.key.fn { background: transparent; box-shadow: none; font-size: 22px; }
.key.ok { background: var(--accent); color: var(--accent-text); font-size: 18px; font-weight: 700; }

/* --- login --- */
.login-top { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.login-top h1 { margin: 0 0 4px; font-size: 32px; }
.users { display: flex; gap: 10px; margin: 14px 0 22px; }
.user-btn {
  padding: 12px 22px;
  border-radius: 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  font-size: 18px;
  font-weight: 600;
}
.user-btn.on { border-color: var(--accent); color: var(--accent); }
.pin-dots { display: flex; gap: 12px; height: 18px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.on { background: var(--text); border-color: var(--text); }

/* --- últimos --- */
.rec-lista { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.rec {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.rec-monto { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.rec-cat { font-weight: 600; }
.rec-det { font-size: 13px; color: var(--muted); grid-column: 1 / -1; }
.rec-estado { font-size: 13px; }
.rec-estado.ok { color: var(--ok); }
.rec-estado.warn { color: var(--warn); }
.rec-estado.err { color: var(--danger); }
.rec-btn { font-size: 14px; color: var(--danger); font-weight: 600; padding: 4px 0; justify-self: end; }
.rec-footer { padding: 8px 0; font-size: 14px; }
.rec-footer p { margin: 0 0 4px; text-align: center; }
.rec-acciones { display: flex; justify-content: space-between; }

/* --- hoja de categorías --- */
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / .4); }
.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 85dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 8px max(12px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.sheet-cats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  overflow-y: auto;
  padding-top: 4px;
}

/* --- toast --- */
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  top: calc(env(safe-area-inset-top) + 8px);
  max-width: 496px;
  margin: 0 auto;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 4px 16px rgb(0 0 0 / .25);
  animation: toast-in .18s ease-out;
}
.toast span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-undo { color: var(--accent); font-weight: 700; padding: 2px 4px; }
@keyframes toast-in { from { transform: translateY(-12px); opacity: 0; } }
