:root {
  --bg: #F3F6F5; --card: #FFFFFF; --ink: #1B1D22; --mute: #6B6F78; --line: #E1E7E5; --chip: #E8EEEC;
  --acc: #0F766E; --acc-ink: #FFFFFF; --acc-soft: #DDF3EF;
  --ok: #15803D; --ok-soft: #DCFCE7; --warn: #B45309; --warn-soft: #FEF3C7; --bad: #B91C1C; --bad-soft: #FEE2E2;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --r: 14px;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
/* Modo oscuro: automático según el iPhone, o forzado desde Apariencia (data-theme en <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --card: #1B1E24; --ink: #F2F2F4; --mute: #9AA0AA; --line: #2B2F37; --chip: #262A31;
    --acc: #2DD4BF; --acc-ink: #0B1F1D; --acc-soft: #12302C;
    --ok: #4ADE80; --ok-soft: #12301D; --warn: #FBBF24; --warn-soft: #362A0C; --bad: #F87171; --bad-soft: #3A1515;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --card: #1B1E24; --ink: #F2F2F4; --mute: #9AA0AA; --line: #2B2F37; --chip: #262A31;
  --acc: #2DD4BF; --acc-ink: #0B1F1D; --acc-soft: #12302C;
  --ok: #4ADE80; --ok-soft: #12301D; --warn: #FBBF24; --warn-soft: #362A0C; --bad: #F87171; --bad-soft: #3A1515;
  --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(--ink); }
body { font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
a { color: var(--acc); }
h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 13px; font-weight: 700; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; margin: 20px 2px 6px; display: flex; justify-content: space-between; align-items: baseline; }
h3 .link { font-size: 14px; text-transform: none; letter-spacing: 0; padding: 0; }
small { font-size: 13px; }
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -4px; }
.mute { color: var(--mute); }
.bad { color: var(--bad); }
.okc { color: var(--ok); }
.warnc { color: var(--warn); }
.center { text-align: center; }
.sm { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.boot { padding: 40px; text-align: center; color: var(--mute); }
.nowrap { white-space: nowrap; }
.tl { text-align: left; }
.sumline { margin: 10px 2px 0; font-size: 14px; }
.sumline b { color: var(--ink); }
button.phead { width: 100%; text-align: left; }

/* ---- estructura ---- */
.shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
header.top { padding: calc(var(--st) + 10px) 16px 8px; background: var(--bg); }
.hrow { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; min-height: 40px; }
.hbtns { display: flex; gap: 8px; align-items: center; }
.eyebrow { font-size: 13px; color: var(--mute); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
main.main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 16px 24px; overscroll-behavior: contain; }
body.has-sheet main.main { overflow: hidden; }
.tabbar { display: flex; background: var(--card); border-top: 1px solid var(--line); padding: 4px 4px calc(var(--sb) + 2px); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0 4px; font-size: 11px; font-weight: 600; color: var(--mute); position: relative; }
.tab .i { width: 24px; height: 24px; }
.tab.on { color: var(--acc); }
.tab .dot { position: absolute; top: 2px; left: calc(50% + 8px); background: var(--bad); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }

/* ---- controles ---- */
.ibtn { width: 44px; height: 44px; border-radius: 12px; background: var(--card); display: grid; place-items: center; box-shadow: var(--shadow); border: 1px solid var(--line); flex: none; }
.ibtn.pri { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: 15px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn.pri { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.btn.bad { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 0 10px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .45; }
.btn:active, .ibtn:active, .lrow:active, .chip:active, .mi:active, .act:active { transform: scale(.98); }
.link { color: var(--acc); font-weight: 600; font-size: 16px; padding: 6px 0; }
.link.bad { color: var(--bad); }
.in { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; min-height: 46px; -webkit-appearance: none; appearance: none; }
.in:focus { outline: 2px solid var(--acc); outline-offset: -1px; }
.in.money { font-size: 22px; font-weight: 700; }
textarea.in { resize: vertical; min-height: 70px; }
select.in { background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%), linear-gradient(135deg, var(--mute) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type="date"].in { display: block; }
.field { display: block; margin-top: 12px; }
.field small { display: block; margin-top: 4px; }
.fl { display: block; font-size: 13px; font-weight: 700; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 6px; }
.field .fl { margin-top: 0; }
.inrow { display: flex; gap: 6px; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 > .field { min-width: 0; }
.search { display: flex; align-items: center; gap: 8px; flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; min-height: 44px; box-shadow: var(--shadow); color: var(--mute); margin-top: 8px; }
.search input { flex: 1; border: 0; background: transparent; font: inherit; font-size: 16px; color: var(--ink); outline: none; min-width: 0; height: 42px; -webkit-appearance: none; }
.chips { display: flex; gap: 6px; margin: 10px 0 4px; flex-wrap: wrap; }
.chips.scrollx { flex-wrap: nowrap; overflow-x: auto; margin-left: -16px; margin-right: -16px; padding: 0 16px 2px; scrollbar-width: none; }
.chips.scrollx::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 8px 13px; border-radius: 999px; background: var(--chip); font-size: 14px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.chip.on { background: var(--acc); color: var(--acc-ink); }
.chip small { font-weight: 500; opacity: .8; }
/* Opciones de activar/desactivar con interruptor a la derecha */
.toggle { display: flex; align-items: center; gap: 8px; width: 100%; padding: 12px 70px 12px 14px; margin-top: 10px; border-radius: 12px; font-size: 15px; line-height: 1.3; text-align: left; background: var(--card); border: 1px solid var(--line); color: var(--ink); position: relative; min-height: 50px; }
.toggle small { display: block; color: var(--mute); }
.toggle::after { content: ''; position: absolute; right: 12px; top: 50%; width: 46px; height: 28px; margin-top: -14px; border-radius: 14px; background: var(--line); transition: background .2s; }
.toggle::before { content: ''; position: absolute; right: 33px; top: 50%; width: 22px; height: 22px; margin-top: -11px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); z-index: 1; transition: transform .2s; }
.toggle.on { border-color: var(--acc); }
.toggle.on::after { background: var(--ok); }
.toggle.on::before { transform: translateX(18px); }
.seg { display: flex; background: var(--chip); border-radius: 11px; padding: 3px; margin: 8px 0; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; text-align: center; color: var(--mute); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.seg.wrap { flex-wrap: wrap; }
.seg.tall button { padding: 10px 4px; line-height: 1.15; }
.note { display: flex; gap: 10px; align-items: flex-start; width: 100%; padding: 11px 12px; border-radius: 12px; background: var(--chip); font-size: 14px; margin: 8px 0; text-align: left; }
.note > .i { margin-top: 1px; }
.note.acc { background: var(--acc-soft); color: var(--ink); }
.note.acc > .i { color: var(--acc); }
.note.ok { background: var(--ok-soft); }
.note.ok > .i { color: var(--ok); }
.note.warn { background: var(--warn-soft); }
.note.warn > .i { color: var(--warn); }
.note.bad { background: var(--bad-soft); }
.note.bad > .i { color: var(--bad); }
.note .btn { margin-top: 8px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--chip); color: var(--mute); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.acc { background: var(--acc-soft); color: var(--acc); }
.empty { text-align: center; color: var(--mute); padding: 30px 16px 14px; }
.empty .i { width: 36px; height: 36px; opacity: .5; }
.empty p { margin: 8px 0 0; }

/* ---- listas y tarjetas ---- */
.list { background: var(--card); border-radius: var(--r); border: 1px solid var(--line); overflow: hidden; margin-top: 8px; box-shadow: var(--shadow); }
.lrow { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.lrow:last-child { border-bottom: 0; }
.lrow b { font-weight: 600; }
.lrow .grow b, .lrow .grow small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lrow small { color: var(--mute); }
.lrow > .i { color: var(--mute); }
.lrow .wa { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: #25D36622; color: #128C4B; flex: none; }
.ra { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; flex: none; }
.ra b { font-weight: 700; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--acc-soft); color: var(--acc); display: grid; place-items: center; font-weight: 800; font-size: 14px; flex: none; }
.avatar.bad { background: var(--bad-soft); color: var(--bad); }
.avatar.ok { background: var(--ok-soft); color: var(--ok); }
.avatar.mute { background: var(--chip); color: var(--mute); }
.qn { width: 40px; height: 40px; border-radius: 10px; background: var(--chip); display: grid; place-items: center; font-weight: 800; font-size: 14px; flex: none; color: var(--mute); }
.qn.ok { background: var(--ok-soft); color: var(--ok); }
.qn.bad { background: var(--bad-soft); color: var(--bad); }
.qn.today { background: var(--warn-soft); color: var(--warn); }
.qn.acc { background: var(--acc-soft); color: var(--acc); }
.bar { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--acc); border-radius: 4px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; box-shadow: var(--shadow); min-width: 0; text-align: left; }
.stat small { color: var(--mute); font-weight: 600; display: block; }
.stat b { display: block; font-size: 20px; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat span { font-size: 12px; color: var(--mute); }
.stat.bad b { color: var(--bad); }
.stat.ok b { color: var(--ok); }
.stat.wide { grid-column: span 2; }
.hero { background: var(--acc); color: var(--acc-ink); border-radius: 18px; padding: 16px; margin-top: 6px; box-shadow: 0 6px 20px rgba(15,118,110,.25); }
.hero small { opacity: .85; font-weight: 600; }
.hero .big { font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0 6px; }
.hero .row2 { display: flex; gap: 16px; font-size: 14px; flex-wrap: wrap; }
.hero .row2 b { display: block; font-size: 16px; }
.hero .bar { background: rgba(255,255,255,.25); }
.hero .bar i { background: #fff; }
.menu { background: var(--card); border-radius: var(--r); border: 1px solid var(--line); overflow: hidden; margin: 12px 0; box-shadow: var(--shadow); }
.mi { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; }
.mi:last-child { border-bottom: 0; }
.mi > .i:first-child { color: var(--acc); width: 22px; height: 22px; }
.mi > .i:last-child { color: var(--mute); }
.mi b { display: block; font-weight: 600; }
.mi small { color: var(--mute); display: block; }
.kv { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 12px; margin-top: 10px; }
.kv .tr { padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv .tr:last-child { border-bottom: 0; }
.tr { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.tr > span:first-child { color: var(--mute); }
.tr > span:last-child { text-align: right; font-weight: 600; }
.tr.big { font-size: 20px; font-weight: 800; }
.tr.big > span:first-child { color: var(--ink); }
.tr.bad > span:last-child { color: var(--bad); }
.tr.ok > span:last-child { color: var(--ok); }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 12px 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; font-size: 13px; font-weight: 600; text-align: center; }
.act .i { color: var(--acc); width: 22px; height: 22px; }
.act.bad .i, .act.bad { color: var(--bad); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0 4px; font-size: 13px; color: var(--mute); }
.pager .btn:disabled { opacity: .35; }
.vchart { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding: 10px 8px 0; margin-top: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.vc { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.vc .stack { width: 100%; max-width: 26px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; }
.vc .stack i { display: block; width: 100%; }
.vc .stack i.cap { background: var(--acc-soft); border: 1px solid var(--acc); border-bottom: 0; }
.vc .stack i.int { background: var(--acc); }
.vc small { font-size: 10px; color: var(--mute); padding: 3px 0 4px; white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--mute); margin: 6px 2px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend i.int { background: var(--acc); }
.legend i.cap { background: var(--acc-soft); border: 1px solid var(--acc); }

/* Tabla del plan de pagos */
.sched { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin-top: 8px; }
.sched th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--mute); font-weight: 700; text-align: right; padding: 8px 8px 6px; border-bottom: 1px solid var(--line); }
.sched td { padding: 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.sched tr:last-child td { border-bottom: 0; }
.sched th:first-child, .sched td:first-child { text-align: left; }
.sched tfoot td { font-weight: 800; background: var(--chip); }
.sched .gap td { text-align: center; color: var(--mute); }

/* Vista previa del préstamo */
.preview { background: var(--acc-soft); border-radius: var(--r); padding: 14px; margin-top: 14px; }
.preview .q { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.preview .tr { padding: 4px 0; }
.preview .tr > span:first-child { color: var(--ink); opacity: .75; }

/* Recibo */
.receipt { background: #fff; color: #111; border-radius: 12px; padding: 18px 16px; margin-top: 10px; font-size: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.receipt .rh { text-align: center; border-bottom: 1px dashed #bbb; padding-bottom: 10px; margin-bottom: 8px; }
.receipt .rh b { font-size: 17px; display: block; }
.receipt .tr { padding: 3px 0; }
.receipt .tr > span:first-child { color: #555; }
.receipt .tot { font-size: 22px; font-weight: 800; text-align: center; padding: 10px 0; border-top: 1px dashed #bbb; border-bottom: 1px dashed #bbb; margin: 8px 0; }
.receipt .ft { text-align: center; color: #666; font-size: 12px; margin-top: 10px; }

.steps { padding-left: 22px; }
.steps li { margin: 10px 0; }
.welcome { max-width: 460px; margin: 0 auto; padding: calc(var(--st) + 40px) 20px calc(var(--sb) + 30px); text-align: center; overflow-y: auto; height: 100dvh; }
.welcome .logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: var(--shadow); }
.welcome h1 { margin: 14px 0 6px; }
.welcome .field, .welcome .note { text-align: left; }

/* ---- ventanas ---- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-wrap .backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); opacity: 0; transition: opacity .2s; }
.sheet-wrap.in .backdrop { opacity: 1; }
.sheet-wrap.under .backdrop { opacity: 0; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: calc(100dvh - var(--st) - 20px); background: var(--bg); border-radius: 18px 18px 0 0; display: flex; flex-direction: column; transform: translateY(100%); transition: transform .26s cubic-bezier(.2,.8,.2,1); box-shadow: 0 -8px 30px rgba(0,0,0,.18); }
.sheet.full { height: calc(100dvh - var(--st) - 20px); }
.sheet-wrap.in .sheet { transform: none; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); position: relative; }
.sheet-head::before { content: ''; position: absolute; top: 5px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line); }
.sheet-head h2 { text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
.sheet-head .link:first-child { justify-self: start; }
.head-r { justify-self: end; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 16px 20px; overscroll-behavior: contain; }
.sheet-foot { display: flex; gap: 8px; padding: 10px 16px calc(var(--sb) + 10px); border-top: 1px solid var(--line); background: var(--card); }
.sheet-foot[hidden] { display: none; }
.sheet-foot .btn { flex: none; padding: 0 12px; }
.sheet-foot .btn.grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.phead { display: flex; gap: 14px; align-items: center; margin-top: 10px; }
.phead .avatar { width: 56px; height: 56px; font-size: 18px; }
.phead h2 { font-size: 20px; }

/* ---- bloqueo y aviso ---- */
#lock { position: fixed; inset: 0; z-index: 70; background: var(--bg); display: grid; place-items: center; padding: 20px; }
#lock[hidden] { display: none; }
.lockbox { text-align: center; width: 100%; max-width: 300px; }
.lock-ic .i { width: 40px; height: 40px; color: var(--acc); }
.pindots { display: flex; justify-content: center; gap: 14px; margin: 18px 0 24px; }
.pindots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--acc); }
.pindots i.on { background: var(--acc); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.keypad button { height: 68px; border-radius: 50%; background: var(--card); font-size: 26px; font-weight: 500; text-align: center; box-shadow: var(--shadow); width: 68px; justify-self: center; }
#toast { position: fixed; left: 50%; bottom: calc(var(--sb) + 90px); transform: translate(-50%, 20px); background: #1B1D22; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--bad); }

@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; width: 560px; margin-left: -280px; }
  main.main, header.top { padding-left: max(16px, calc(50vw - 330px)); padding-right: max(16px, calc(50vw - 330px)); }
}
