:root {
  --bg: #0b1220;
  --bg-2: #0f1a2e;
  --card: #16233c;
  --card-2: #1c2c49;
  --text: #eef2f8;
  --muted: #93a3bd;
  --border: #26364f;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --green: #34d399;
  --green-bg: rgba(52,211,153,.12);
  --red: #f87171;
  --red-bg: rgba(248,113,113,.12);
  --amber: #fbbf24;
  --radius: 18px;
  --shadow: 0 12px 30px rgba(0,0,0,.4);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: contain;
}
body { min-height: 100dvh; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }

.wrap { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(30px + var(--safe-bottom)); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 12px) 14px 12px;
  background: linear-gradient(180deg, var(--bg) 60%, rgba(11,18,32,.85));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.tb-title { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; }
.tb-title.compact { gap: 0; }
.tb-title h1 { font-size: 18px; margin: 0; font-weight: 800; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-sub { font-size: 12px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo-sm {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 19px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: 20px; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { transform: scale(.92); }
#backBtn { font-size: 28px; font-weight: 300; }

/* ---------- Banda de total ---------- */
.total-band {
  max-width: 720px; margin: 12px auto 0; padding: 0 14px;
}
.total-card {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow);
}
.total-card .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: #bfdbfe; }
.total-card .val { font-size: 27px; font-weight: 800; font-family: var(--mono); margin-top: 3px; }
.total-card .val.neg { color: #fecaca; }

/* ---------- Tarjetas de libreta (dashboard) ---------- */
.lib-card {
  display: flex; align-items: center; gap: 13px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 14px; margin-bottom: 11px;
  transition: transform .08s ease, background .15s ease;
}
.lib-card:active { transform: scale(.985); background: var(--card-2); }
.lib-card .avatar {
  width: 46px; height: 46px; border-radius: 13px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 17px; color: #fff;
}
.lib-card .info { flex: 1; min-width: 0; }
.lib-card .info .nom { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-card .info .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.lib-card .bal { text-align: right; flex: none; }
.lib-card .bal .n { font-size: 17px; font-weight: 800; font-family: var(--mono); }
.lib-card .bal .n.pos { color: var(--green); }
.lib-card .bal .n.neg { color: var(--red); }
.lib-card .bal .cur { font-size: 11px; color: var(--muted); }
.lib-card .menu {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: transparent; border: none; color: var(--muted); font-size: 20px; cursor: pointer;
}
.lib-card .menu:active { background: var(--card-2); }

.add-btn { margin-top: 6px; }

/* ---------- Botones ---------- */
.btn {
  width: 100%; padding: 14px; border: none; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: filter .15s ease, transform .08s ease;
}
.btn:active { transform: scale(.98); }
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--card-2); border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: var(--red); }
.btn.danger.ghost { background: transparent; border: 1px solid var(--red); color: var(--red); }
.btn:disabled { opacity: .55; }
.load-more { margin-top: 8px; }

/* ---------- Filtros (detalle) ---------- */
.filter-strip {
  position: sticky; top: 0; z-index: 15;
  display: flex; gap: 8px; align-items: center;
  padding: 10px 14px; background: var(--bg-2);
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.chip {
  flex: none; padding: 8px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip-main { background: var(--accent); border-color: var(--accent); }
.chips-active { display: flex; gap: 6px; }
.chip.active-filter { background: var(--card-2); }
.chip.active-filter b { color: var(--accent-2); }

/* ---------- Movimientos ---------- */
.mov {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 15px; padding: 13px 14px; margin-bottom: 9px;
}
.mov .dir {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  display: grid; place-items: center; font-size: 18px; font-weight: 800;
}
.mov .dir.in { background: var(--green-bg); color: var(--green); }
.mov .dir.out { background: var(--red-bg); color: var(--red); }
.mov .body { flex: 1; min-width: 0; }
.mov .concepto { font-size: 15px; font-weight: 600; line-height: 1.3; }
.mov .sub { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mov .sub .cuenta { font-weight: 600; color: #c7d2e6; }
.mov .right { text-align: right; flex: none; }
.mov .monto { font-size: 16px; font-weight: 800; font-family: var(--mono); white-space: nowrap; }
.mov .monto.in { color: var(--green); }
.mov .monto.out { color: var(--red); }
.mov .fecha { font-size: 11px; color: var(--muted); margin-top: 3px; }

.badge { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .3px; }
.badge.confirmado { background: var(--green-bg); color: var(--green); }
.badge.pendiente { background: rgba(251,191,36,.14); color: var(--amber); }
.badge.cancelado { background: var(--red-bg); color: var(--red); }

/* ---------- Estados ---------- */
.empty, .loading { text-align: center; color: var(--muted); padding: 54px 20px; }
.empty .big { font-size: 42px; margin-bottom: 12px; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Gate (PIN) ---------- */
.pin-screen { width: 100%; max-width: 340px; text-align: center; }
.pin-screen .gate-logo { width: 62px; height: 62px; border-radius: 19px; margin: 0 auto 16px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; font-size: 31px; }
.pin-screen h1 { font-size: 22px; margin: 0 0 4px; }
.pin-screen p { color: var(--muted); font-size: 14px; margin: 0 0 26px; min-height: 20px; transition: color .15s; }
.pin-screen p.err { color: var(--red); }

.pin-dots { display: flex; justify-content: center; gap: 18px; margin-bottom: 34px; }
.pin-dots .dot { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--muted); transition: transform .12s, background .12s, border-color .12s; }
.pin-dots .dot.on { background: var(--accent); border-color: var(--accent); transform: scale(1.1); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; max-width: 280px; margin: 0 auto; }
.key {
  height: 72px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: 27px; font-weight: 600; cursor: pointer;
  display: grid; place-items: center; user-select: none;
  transition: transform .08s, background .12s;
}
.key:active { transform: scale(.9); background: var(--accent); }
.key-del { border: none; background: transparent; font-size: 22px; }
.key-del:active { background: transparent; color: var(--accent); }
.key-ghost { border: none; background: transparent; cursor: default; }

/* ---------- Gate (genérico, otras pantallas) ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 360px; text-align: center; background: var(--card); border: 1px solid var(--border); border-radius: 24px; padding: 34px 26px; box-shadow: var(--shadow); }
.gate-logo { width: 66px; height: 66px; border-radius: 20px; margin: 0 auto 18px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; font-size: 33px; }
.gate-card h1 { font-size: 22px; margin: 0 0 6px; }
.gate-card p { color: var(--muted); font-size: 14px; margin: 0 0 22px; }

/* ---------- Campos ---------- */
.field { margin-bottom: 14px; text-align: left; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-2);
  color: var(--text); font-size: 16px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.error-msg { color: var(--red); font-size: 14px; margin: 10px 0 0; min-height: 18px; }

/* ---------- Modal (bottom sheet) ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: flex-end; justify-content: center; z-index: 90; }
.modal-back.show { display: flex; }
.modal { width: 100%; max-width: 480px; background: var(--card); border: 1px solid var(--border); border-radius: 24px 24px 0 0; padding: 10px 18px calc(20px + var(--safe-bottom)); animation: up .22s ease; max-height: 90dvh; overflow-y: auto; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
.modal-grip { width: 42px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 14px; }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal .row { display: flex; gap: 10px; margin-top: 18px; }
.modal .row .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px); background: #05203f; border: 1px solid var(--accent); color: var(--text); padding: 12px 18px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 24px; }
}
