/* Control Bancario — estilo "libro contable": tinta verde azulada sobre papel claro.
 * Tipografía: Plus Jakarta Sans (texto) + JetBrains Mono (montos y códigos).
 */
:root {
  --ink: #12312F;
  --ink-2: #1D4744;
  --paper: #F4F2EA;
  --card: #FFFFFF;
  --line: #E1DDD0;
  --line-2: #EFECE2;
  --muted: #6A7977;
  --gold: #C99A2E;
  --ok: #1E7A4D;
  --ok-bg: #E4F3EA;
  --warn: #A66A00;
  --warn-bg: #FBF0D8;
  --danger: #B4332B;
  --danger-bg: #FBE6E3;
  --info: #2563A8;
  --info-bg: #E3EEFA;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(18, 49, 47, .06), 0 4px 14px rgba(18, 49, 47, .05);
  --topbar-h: 56px;
  --tabbar-h: 64px;
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font);
  font-size: 15px; line-height: 1.45; overscroll-behavior-y: none;
}
body.modal-abierto { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 16px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--muted); }
.ic { width: 20px; height: 20px; flex: none; vertical-align: -4px; }

/* ---------- Estructura ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 30;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top));
  background: var(--ink); color: #F4F2EA;
}
.topbar .logo {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: #F4F2EA; color: var(--ink); flex: none;
}
.topbar .logo .ic { width: 19px; height: 19px; }
.topbar .titulo { font-weight: 700; font-size: 16px; line-height: 1.1; }
.topbar .sub { font-size: 11px; opacity: .7; font-weight: 500; }
.topbar .espacio { flex: 1; }
.topbar .icon-btn { color: #F4F2EA; }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; opacity: .85; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: #5BD18C; display: block; }
.sync.demo i { background: var(--gold); }

.demo-banner {
  position: fixed; left: 0; right: 0; z-index: 29; top: calc(var(--topbar-h) + env(safe-area-inset-top));
  background: var(--gold); color: #3A2A00; font-size: 11.5px; font-weight: 700; text-align: center; padding: 4px 8px;
  letter-spacing: .02em;
}
#screen-root {
  padding-top: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  min-height: 100vh;
}
body.con-demo #screen-root { padding-top: calc(var(--topbar-h) + env(safe-area-inset-top) + 26px); }
.wrap { max-width: 860px; margin: 0 auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 14px; }
.centro { min-height: 70vh; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; max-width: 200px; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; padding: 6px 2px;
}
.tab .ic { width: 22px; height: 22px; }
.tab.on { color: var(--ink); }
.tab.on::before { content: ''; position: absolute; top: 0; width: 34px; height: 3px; border-radius: 0 0 3px 3px; background: var(--ink); }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center;
}
.badge.amber { background: var(--warn); }

/* ---------- Tarjetas y piezas ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card.compacta { padding: 10px 12px; }
.card-cab { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.titulo-sec { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 2px -4px; }
.hint { color: var(--muted); font-size: 13px; }
.fila { display: flex; align-items: center; gap: 8px; }
.fila.entre { justify-content: space-between; }
.fila.wrap-f { flex-wrap: wrap; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metrica label { display: block; font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.metrica b { display: block; font-size: 17px; font-family: var(--mono); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.metrica small { color: var(--muted); font-size: 11px; }
.pos { color: var(--ok); } .neg { color: var(--danger); } .warn-t { color: var(--warn); }

.pill, .estado {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: 10.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
}
.pill.ok, .estado.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn, .estado.warn { background: var(--warn-bg); color: var(--warn); }
.pill.danger, .estado.danger { background: var(--danger-bg); color: var(--danger); }
.pill.info, .estado.info { background: var(--info-bg); color: var(--info); }
.pill.neutral, .estado.neutral { background: #ECEAE0; color: #5B6866; }

.upill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 2px 9px 2px 7px;
  border-radius: 999px; background: color-mix(in srgb, var(--c) 13%, #fff); color: color-mix(in srgb, var(--c) 78%, #000);
  border: 1px solid color-mix(in srgb, var(--c) 30%, #fff);
}
.upill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.upill.sin { --c: #9AA5A3; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 700; font-size: 14px; padding: 10px 16px; cursor: pointer; min-height: 42px; transition: transform .05s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn.pri { background: var(--ink); color: #F4F2EA; }
.btn.pri:hover { background: var(--ink-2); }
.btn.sec { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn.sec:hover { background: #F7F5EE; }
.btn.ghost { background: none; color: var(--ink-2); padding-inline: 8px; }
.btn.peligro { background: var(--danger); color: #fff; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 13px; border-radius: 9px; }
.btn.bloque { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 10px; cursor: pointer; color: inherit; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(127, 127, 127, .15); }
.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 20;
  width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--ink); color: #F4F2EA; cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(18, 49, 47, .35);
}
.fab .ic { width: 24px; height: 24px; }

/* ---------- Formularios ---------- */
.campo { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.campo label, .lbl { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
.req { color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=month], input[type=number], select, textarea {
  width: 100%; background: #fff; border: 1px solid #CFCABB; border-radius: 10px; padding: 10px 12px; font-size: 15px; min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--ink) 55%, transparent); outline-offset: 1px; border-color: var(--ink); }
textarea { resize: vertical; }
.ayuda { font-size: 12px; color: var(--muted); }
.error-form, .error-txt { color: var(--danger); background: var(--danger-bg); border-radius: 9px; padding: 8px 10px; font-size: 13px; font-weight: 600; }
.check { display: flex; gap: 9px; align-items: center; font-size: 14px; margin: 4px 0 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }

.buscar { position: relative; }
.buscar .ic { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.buscar input { padding-left: 38px; }
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 1px 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 13px;
  font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--ink); color: #F4F2EA; border-color: var(--ink); }
.chip .pt { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #999); }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #E8E5D9; border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 9px 6px; border-radius: 9px; font-weight: 700; font-size: 13.5px; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Inicio ---------- */
.cuadre.ok { border-left: 5px solid var(--ok); }
.cuadre.warn { border-left: 5px solid var(--danger); }
.cuadre.neutral { border-left: 5px solid #B7B3A3; }
.bolsillos { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.bolsillo {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow); cursor: pointer; border-left: 6px solid var(--c); width: 100%;
}
.bolsillo .nom { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.bolsillo .saldo { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: -.04em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.bolsillo .det { font-size: 11.5px; color: var(--muted); }
.bolsillo .nota-neg { font-size: 11.5px; color: var(--danger); margin-top: 3px; }
.suma-fila { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 14px; border-bottom: 1px dashed var(--line); }
.suma-fila:last-child { border-bottom: 0; font-weight: 700; }

/* ---------- Movimientos ---------- */
.lista { display: flex; flex-direction: column; gap: 8px; }
.mov {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px; box-shadow: var(--shadow); text-align: left; width: 100%;
}
.mov:hover { border-color: #C9C4B2; }
.mov-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.mov-top .fecha { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.mov-top .monto { font-family: var(--mono); font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.monto.ing { color: var(--ok); } .monto.egr { color: var(--ink); }
.mov .desc { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.mov .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.sug-fila { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 6px; border-top: 1px dashed var(--line); margin-top: 3px; }
.sug-fila .sug { font-size: 12.5px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 150px; }
.sug-fila .sug .ic { color: var(--gold); width: 16px; height: 16px; }
.mas { align-self: center; }

/* ---------- Ventanas ---------- */
.modal-fondo {
  position: fixed; inset: 0; z-index: 60; background: rgba(10, 28, 27, .55); display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .15s ease;
}
.modal-fondo.saliendo { opacity: 0; transition: opacity .15s; }
.modal {
  background: #FBFAF6; width: 100%; max-width: 560px; max-height: 94vh; display: flex; flex-direction: column;
  border-radius: 20px 20px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .25); animation: subir .2s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
.modal.ancho { max-width: 720px; }
.modal-cab { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; }
.modal-cuerpo { padding: 4px 16px 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.modal-pie { display: flex; gap: 10px; justify-content: flex-end; padding: 10px 16px 14px; border-top: 1px solid var(--line-2); }
.modal-pie .btn { flex: 1; }
.texto-modal { font-size: 15px; line-height: 1.5; }
@media (min-width: 700px) {
  .modal-fondo { align-items: center; }
  .modal { border-radius: 18px; max-height: 88vh; }
  .modal-pie .btn { flex: none; min-width: 120px; }
}
@keyframes subir { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.toasts { position: fixed; z-index: 90; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 76px); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 14px; }
.toast { background: var(--ink); color: #F4F2EA; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: 520px; animation: subir .2s ease; }
.toast.error { background: var(--danger); } .toast.warn { background: var(--warn); }
.toast.fuera { opacity: 0; transition: opacity .3s; }
.busy { position: fixed; inset: 0; z-index: 100; background: rgba(244, 242, 234, .72); display: grid; place-items: center; }
.busy-box { background: var(--ink); color: #F4F2EA; padding: 16px 22px; border-radius: 14px; display: flex; align-items: center; gap: 12px; font-weight: 600; box-shadow: 0 8px 30px rgba(0, 0, 0, .3); }
.spin { width: 20px; height: 20px; border-radius: 50%; border: 3px solid rgba(244, 242, 234, .3); border-top-color: #F4F2EA; animation: giro .8s linear infinite; }
@keyframes giro { to { transform: rotate(360deg); } }

/* ---------- Clasificar ---------- */
.parte { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; position: relative; }
.parte .full { grid-column: 1 / -1; }
.parte .quitar { position: absolute; right: 4px; top: 4px; }
.parte label { font-size: 11.5px; font-weight: 700; color: var(--muted); display: block; margin-bottom: 3px; }
.resumen-mov { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.falta { font-size: 13px; font-weight: 700; padding: 8px 10px; border-radius: 9px; margin-bottom: 10px; }
.falta.ok { background: var(--ok-bg); color: var(--ok); }
.falta.mal { background: var(--warn-bg); color: var(--warn); }
.falta.excede { background: var(--danger-bg); color: var(--danger); }
.detalle-fila { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.detalle-fila span:first-child { color: var(--muted); flex: none; }
.detalle-fila span:last-child { text-align: right; overflow-wrap: anywhere; }

/* ---------- Importar ---------- */
.tabla-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
table.prev { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.prev th, table.prev td { padding: 6px 8px; border-bottom: 1px solid var(--line-2); text-align: left; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
table.prev th { background: #F4F2EA; font-weight: 700; }
table.prev th select { min-height: 34px; padding: 4px 6px; font-size: 12.5px; min-width: 120px; }
table.prev td.num { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
table.prev tr.dup td { opacity: .5; }
.pasos { display: flex; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.pasos span { padding: 3px 10px; border-radius: 999px; background: #E8E5D9; }
.pasos span.on { background: var(--ink); color: #F4F2EA; }
.drop { border: 2px dashed #BDB8A6; border-radius: 14px; padding: 18px; text-align: center; background: #FBFAF6; cursor: pointer; display: block; }
.drop:hover { border-color: var(--ink); }
.drop input { display: none; }
details > summary { cursor: pointer; font-weight: 700; font-size: 14px; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary .ic { transform: rotate(90deg); }
.fila-ajuste { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.fila-ajuste:last-child { border-bottom: 0; }
.fila-ajuste .izq { display: flex; align-items: center; gap: 8px; min-width: 0; }
.fila-ajuste .izq span:last-child { overflow-wrap: anywhere; }
.punto { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }

/* ---------- Acceso ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login-card { background: #FBFAF6; border-radius: 20px; padding: 26px 22px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.login .marca { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 18px; text-align: center; }
.login .marca .logo { width: 56px; height: 56px; border-radius: 50%; background: var(--ink); color: #F4F2EA; display: grid; place-items: center; }
.login .marca .logo .ic { width: 28px; height: 28px; }
.login h1 { font-size: 21px; }

@media (max-width: 520px) {
  .parte { grid-template-columns: 1fr; }
}
@media (min-width: 900px) {
  .grid3 { gap: 14px; }
  .metrica b { font-size: 20px; }
}
@media print { .topbar, .tabbar, .fab, .demo-banner { display: none !important; } #screen-root { padding: 0; } }

/* ---------- Pagos programados (Fase 2) ---------- */
.pago { border-left: 4px solid var(--line); display: flex; flex-direction: column; }
.pago.venc { border-left-color: var(--danger); }
.pago.hoy, .pago.pronto { border-left-color: var(--warn); }
.pago.ok { border-left-color: var(--info); }
.pago.fin { border-left-color: var(--ok); opacity: .75; }
.pago-n { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.pago-s { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pago-m { text-align: right; display: flex; flex-direction: column; align-items: flex-end; font-size: 15px; }
.resumen-pagos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.resumen-pagos > div { display: flex; flex-direction: column; gap: 2px; }
.resumen-pagos b { font-size: 18px; }
.cands { display: flex; flex-direction: column; gap: 6px; }
.cand { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: left; width: 100%;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font: inherit; color: inherit; cursor: pointer; min-height: 44px; }
.cand:hover, .cand:focus-visible { border-color: var(--ink); }
.cand-d { overflow-wrap: anywhere; }
.det-sec { margin-top: 4px; } .det-sec > summary { cursor: pointer; font-weight: 600; padding: 8px 2px; color: var(--muted); }
.det-sec[open] > summary { margin-bottom: 8px; }
.det-sec > .card { margin-bottom: 10px; }
@media (max-width: 380px) { .tab span:not(.badge) { font-size: 10.5px; } }
.pago-acc { flex-wrap: nowrap; flex-shrink: 0; } .pago-acc .btn { white-space: nowrap; }
.pago .fila.entre > .fila.wrap-f { min-width: 0; }
