:root {
  --azul: #1d3557; --azul2: #274b78; --acento: #2a9d8f; --rojo: #c0392b; --naranja: #d9822b; --verde: #2e8b57;
  --fondo: #f3f5f8; --card: #fff; --texto: #1c2430; --suave: #667085; --borde: #dfe3ea; --radio: 10px;
  --sombra: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fondo); color: var(--texto); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--azul2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--suave); text-transform: uppercase; letter-spacing: .03em; }

/* Estructura */
.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.layout > div { min-width: 0; }
.side { background: var(--azul); color: #fff; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .marca { font-weight: 700; font-size: 1.05rem; padding: 4px 10px 16px; line-height: 1.2; }
.side .marca small { display: block; font-weight: 400; opacity: .7; font-size: .78rem; margin-top: 4px; }
.side nav a { display: flex; align-items: center; gap: 10px; color: #dbe4f0; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.side nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.side nav a.on { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.side .sep { border-top: 1px solid rgba(255,255,255,.15); margin: 10px 0; }
.main { padding: 22px 26px 40px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top .acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.movil-top, .movil-nav { display: none; }
.ico { width: 18px; height: 18px; flex: none; }

/* Tarjetas */
.card { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; box-shadow: var(--sombra); margin-bottom: 16px; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); }
.kpi .t { font-size: .78rem; color: var(--suave); text-transform: uppercase; letter-spacing: .03em; }
.kpi .v { font-size: 1.35rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: .8rem; color: var(--suave); }
.kpi.rojo .v { color: var(--rojo); } .kpi.verde .v { color: var(--verde); } .kpi.azul .v { color: var(--azul2); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* Tablas */
.tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; color: var(--suave); letter-spacing: .03em; border-bottom: 2px solid var(--borde); padding: 8px; white-space: nowrap; }
td { border-bottom: 1px solid var(--borde); padding: 8px; vertical-align: top; }
tr.clic { cursor: pointer; } tr.clic:hover td { background: #f7f9fc; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.c, th.c { text-align: center; }
tr.vencida td { background: #fdf1f0; }
tr.pagada td { color: #8a94a6; }
tr.anulado td { text-decoration: line-through; color: #aaa; }
.vacio { color: var(--suave); padding: 18px; text-align: center; }

/* Etiquetas */
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.tag.rojo { background: #fde8e6; color: var(--rojo); } .tag.verde { background: #e3f4ea; color: var(--verde); }
.tag.gris { background: #eef0f4; color: #556; } .tag.naranja { background: #fdf0e1; color: #a85f12; } .tag.azul { background: #e5eef9; color: var(--azul2); }

/* Formularios */
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
label { display: block; font-size: .8rem; font-weight: 600; color: #3b4555; margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid #c9d0db; border-radius: 8px; background: #fff; color: var(--texto); min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ea; border-color: var(--azul2); }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: .9rem; }
.check input { width: 18px; min-height: 18px; }
.check { margin: 0; cursor: pointer; }
/* Filtros por zona y grupos */
.filtros { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 12px; }
.filtros select { width: auto; min-width: 200px; max-width: 100%; }
.grupo-zona { margin-bottom: 18px; }
.grupo-zona h3 { margin: 6px 0 8px; padding: 6px 10px; background: #e8eef5; border-radius: 8px; color: var(--azul); font-size: .95rem; }
.rojo-t { color: var(--rojo); }
tr.total td { background: #eef2f7; }
/* Fecha real de un cobro registrado tarde (sólo admin) */
.fecha-cobro input { max-width: 220px; }
.fecha-cobro.tarde { border: 2px solid #e8a33d; background: #fff8ec; }
/* Fotos del préstamo */
.fotos-prest { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.fotos-prest h3 { margin: 0 0 8px; font-size: .9rem; }
.fotos-prest .fotos { min-height: 60px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); cursor: pointer; vertical-align: middle; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; background: var(--azul); color: #fff; min-height: 40px; white-space: nowrap; text-decoration: none !important; }
.btn:hover { filter: brightness(1.1); }
.btn.sec { background: #fff; color: var(--azul); border-color: #c9d0db; }
.btn.verde { background: var(--verde); } .btn.rojo { background: var(--rojo); } .btn.peq { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.botones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.buscar { display: flex; gap: 8px; margin-bottom: 12px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 99px; background: #e6eaf0; color: #334; font-size: .88rem; font-weight: 600; }
.tabs a.on { background: var(--azul); color: #fff; text-decoration: none; }

/* Fichas */
.ficha { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 16px; }
.ficha div small { display: block; font-size: .72rem; text-transform: uppercase; color: var(--suave); letter-spacing: .03em; }
.ficha div b { font-weight: 600; word-break: break-word; }
.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.fotos .f { position: relative; aspect-ratio: 4/3; background: #e9edf2; border-radius: 8px; overflow: hidden; }
.fotos img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.fotos .x { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 6px; padding: 2px 7px; cursor: pointer; }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.docs a { display: flex; align-items: center; gap: 8px; border: 1px solid var(--borde); border-radius: 8px; padding: 10px 12px; background: #fafbfd; font-weight: 600; font-size: .9rem; }
.docs a:hover { background: #eef3fa; text-decoration: none; }
.resumen-pago { background: #f6f8fb; border-radius: 8px; padding: 12px; display: grid; gap: 4px; }
.resumen-pago div { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.resumen-pago .tot { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--borde); padding-top: 6px; margin-top: 4px; }
.barra { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.barra .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.barra .pila { width: 100%; max-width: 46px; display: flex; flex-direction: column-reverse; border-radius: 5px 5px 0 0; overflow: hidden; }
.barra .pila span { display: block; }
.barra small { font-size: .7rem; color: var(--suave); }
.leyenda { display: flex; gap: 14px; font-size: .78rem; color: var(--suave); margin-top: 8px; flex-wrap: wrap; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.aviso { background: #fff7e6; border: 1px solid #f2c97d; color: #7a4d00; border-radius: 8px; padding: 10px 12px; font-size: .88rem; margin-bottom: 12px; }
.muted { color: var(--suave); font-size: .85rem; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #1d3557, #274b78 60%, #2a9d8f); }
.login .card { width: 100%; max-width: 370px; padding: 26px; }
.login h1 { margin-bottom: 4px; color: var(--azul); }

/* Ventana emergente */
.modal-fondo { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; max-width: 520px; width: 100%; padding: 20px; max-height: 92vh; overflow: auto; }
.visor { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.visor img { max-width: 96vw; max-height: 92vh; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(30px); background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .25s; z-index: 70; pointer-events: none; max-width: 90vw; }
#toast.on { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--rojo); }
.cargando { padding: 40px; text-align: center; color: var(--suave); }

/* Celular */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .movil-top { display: flex; align-items: center; justify-content: space-between; background: var(--azul); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 20; }
  .movil-top b { font-size: .98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .movil-top button { background: transparent; border: 0; color: #fff; padding: 6px; }
  .main { padding: 14px 16px 90px; }
  .movil-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--borde); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .movil-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; color: #667; font-size: .7rem; font-weight: 600; }
  .movil-nav a.on { color: var(--azul); }
  .movil-nav a:hover { text-decoration: none; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 11px 12px; } .kpi .v { font-size: 1.1rem; }
  h1 { font-size: 1.15rem; }
  .top { margin-bottom: 12px; }
  .ocultar-movil { display: none; }
  .menu-mas { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; }
  .menu-mas .hoja { background: #fff; width: 100%; border-radius: 14px 14px 0 0; padding: 10px 10px calc(14px + env(safe-area-inset-bottom)); }
  .menu-mas a { display: flex; gap: 12px; align-items: center; padding: 13px 12px; color: var(--texto); font-weight: 600; border-bottom: 1px solid #f0f2f5; }
  td, th { padding: 7px 6px; }
  .form { grid-template-columns: 1fr; }
}
@media print { .side, .movil-top, .movil-nav, .botones, .top .acciones { display: none !important; } .layout { display: block; } }
