:root {
  --fondo: #f2f2f2;
  --tarjeta: #ffffff;
  --texto: #121212;
  --suave: #6b6b6b;
  --linea: #dedede;
  --prim: #141414;
  --prim-2: #3d3d3d;
  --rojo: #c92a2a;
  --rojo-f: #fff0f0;
  --verde: #2b8a3e;
  --verde-f: #ebfbee;
  /* colores por frecuencia */
  --diario-f: #ffffff;
  --diario-b: #dedede;
  --semanal-f: #fff4e6;
  --semanal-b: #f76707;
  --quincenal-f: #e7f1ff;
  --quincenal-b: #1c7ed6;
  --sombra: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--fondo); color: var(--texto); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.cargando { padding: 40vh 16px; text-align: center; color: var(--suave); }

/* ---------- Barra superior ---------- */
.barra { position: sticky; top: 0; z-index: 10; background: var(--prim); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; display: flex; align-items: center; gap: 10px; }
.barra h1 { font-size: 15px; letter-spacing: .05em; margin: 0; flex: 1; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.barra h1 small { letter-spacing: 0; }
.logo-barra { width: 34px; height: 34px; object-fit: contain; }
.barra h1 small { display: block; font-size: 12px; font-weight: 400; opacity: .8; }
.btn-sync { background: #fff; color: var(--prim); border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 700; display: flex; align-items: center; gap: 6px; position: relative; }
.btn-sync .badge { background: var(--rojo); color: #fff; border-radius: 999px; font-size: 12px; min-width: 20px; height: 20px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; }
.btn-sync .badge[hidden] { display: none; }
.btn-sync.girando svg { animation: girar 1s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
.btn-icono { background: transparent; border: 0; color: inherit; padding: 6px; display: flex; }

/* ---------- Pestañas ---------- */
.pestanas { display: flex; background: var(--prim); padding: 0 8px; position: sticky; top: 0; }
.pestanas button { flex: 1; background: none; border: 0; color: rgba(255,255,255,.7); padding: 10px; font-weight: 600; border-bottom: 3px solid transparent; }
.pestanas button.activa { color: #fff; border-bottom-color: #fff; }

.contenido { padding: 12px 12px 110px; max-width: 640px; margin: 0 auto; }

/* ---------- Resumen ---------- */
.resumen { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.dato { background: var(--tarjeta); border-radius: 12px; padding: 10px 12px; box-shadow: var(--sombra); }
.dato span { display: block; font-size: 12px; color: var(--suave); }
.dato b { font-size: 18px; }
.dato.grande { grid-column: 1 / -1; background: var(--prim); color: #fff; }
.dato.grande span { color: rgba(255,255,255,.8); }
.dato.grande b { font-size: 24px; }

/* ---------- Buscador y filtros ---------- */
.buscar { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--linea); background: var(--tarjeta); margin-bottom: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; scrollbar-width: none; }
.chip { white-space: nowrap; border: 1px solid var(--linea); background: var(--tarjeta); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip.activa { background: var(--texto); color: #fff; border-color: var(--texto); }
.chip.semanal.activa { background: var(--semanal-b); border-color: var(--semanal-b); }
.chip.quincenal.activa { background: var(--quincenal-b); border-color: var(--quincenal-b); }

/* ---------- Tarjetas de cliente ---------- */
.cliente { display: flex; gap: 10px; align-items: center; background: var(--diario-f); border: 1px solid var(--diario-b); border-left-width: 6px; border-radius: 12px; padding: 12px; margin-bottom: 8px; box-shadow: var(--sombra); width: 100%; text-align: left; }
.cliente.semanal { background: var(--semanal-f); border-color: #ffd8a8; border-left-color: var(--semanal-b); }
.cliente.quincenal { background: var(--quincenal-f); border-color: #a5d8ff; border-left-color: var(--quincenal-b); }
.cliente.pagado { opacity: .65; }
.cliente .info { flex: 1; min-width: 0; }
.cliente .nombre { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cliente .sub { font-size: 13px; color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cliente .valores { text-align: right; flex-shrink: 0; }
.cliente .valores b { display: block; }
.cliente .valores small { color: var(--suave); font-size: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: #e6e6e6; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--prim); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.etiqueta { display: inline-block; font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 6px; margin-top: 3px; }
.etiqueta.rojo { background: var(--rojo-f); color: var(--rojo); }
.etiqueta.verde { background: var(--verde-f); color: var(--verde); }
.etiqueta.gris { background: #eef1f0; color: var(--suave); }
.etiqueta.semanal { background: var(--semanal-b); color: #fff; }
.etiqueta.quincenal { background: var(--quincenal-b); color: #fff; }
.etiqueta.diario { background: #eef1f0; color: var(--texto); }
.sin-subir { font-size: 11px; color: #e8590c; font-weight: 600; }
.vacio { text-align: center; color: var(--suave); padding: 40px 16px; }

/* ---------- Botón flotante ---------- */
.fab { position: fixed; right: 18px; bottom: calc(22px + env(safe-area-inset-bottom)); width: 62px; height: 62px; border-radius: 50%; background: var(--prim); color: #fff; border: 0; box-shadow: 0 6px 18px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 20; }
.fab svg { width: 30px; height: 30px; }

/* ---------- Ventanas (modales) ---------- */
.capa { position: fixed; inset: 0; background: rgba(10,20,17,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: aparecer .15s ease; }
@keyframes aparecer { from { opacity: 0; } }
.ventana { background: var(--fondo); width: 100%; max-width: 640px; max-height: 94vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; animation: subir .2s ease; }
@keyframes subir { from { transform: translateY(40px); } }
.ventana.completa { max-height: 100vh; height: 100%; border-radius: 0; }
.ventana header { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; border-bottom: 1px solid var(--linea); }
.ventana header h2 { margin: 0; font-size: 18px; flex: 1; }
.ventana .cuerpo { overflow-y: auto; padding: 14px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.cerrar { background: #ececec; border: 0; border-radius: 50%; width: 34px; height: 34px; font-size: 20px; line-height: 1; }

/* ---------- Formularios ---------- */
.grupo { background: var(--tarjeta); border-radius: 14px; padding: 12px; margin-bottom: 12px; box-shadow: var(--sombra); }
.grupo h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--suave); }
label.campo { display: block; margin-bottom: 10px; }
label.campo > span { display: block; font-size: 13px; color: var(--suave); margin-bottom: 4px; }
label.campo > span i { color: var(--rojo); font-style: normal; }
.campo input, .campo select, .campo textarea { width: 100%; padding: 12px; border: 1px solid var(--linea); border-radius: 10px; background: #fff; font-size: 16px; }
.campo input:focus, .campo textarea:focus { outline: 2px solid var(--prim-2); border-color: transparent; }
.campo.error input { border-color: var(--rojo); background: var(--rojo-f); }
.fila { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.frecuencias { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.frecuencias button { padding: 12px 4px; border-radius: 10px; border: 2px solid var(--linea); background: #fff; font-weight: 700; }
.frecuencias button.activa.diario { border-color: var(--texto); }
.frecuencias button.semanal { color: var(--semanal-b); }
.frecuencias button.quincenal { color: var(--quincenal-b); }
.frecuencias button.activa.semanal { background: var(--semanal-b); border-color: var(--semanal-b); color: #fff; }
.frecuencias button.activa.quincenal { background: var(--quincenal-b); border-color: var(--quincenal-b); color: #fff; }
.calculo { background: #f0f0f0; border-radius: 10px; padding: 10px 12px; display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.calculo b { display: block; font-size: 18px; color: var(--prim); }

.fotos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.foto-btn { border: 2px dashed var(--linea); background: #fff; border-radius: 12px; height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--suave); font-size: 13px; position: relative; overflow: hidden; padding: 0; }
.foto-btn svg { width: 30px; height: 30px; color: var(--prim); }
.foto-btn img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.foto-btn .cambiar { position: absolute; bottom: 6px; left: 6px; right: 6px; background: rgba(0,0,0,.55); color: #fff; border-radius: 8px; font-size: 12px; padding: 3px; }

.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px; font-weight: 700; font-size: 16px; background: var(--prim); color: #fff; }
.btn.secundario { background: #e9e9e9; color: var(--prim); }
.btn.peligro { background: var(--rojo-f); color: var(--rojo); }
.btn:disabled { opacity: .5; }
.botones { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.botones .btn { padding: 12px 8px; font-size: 15px; }
.rapidos { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.rapidos button { border: 1px solid var(--linea); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; }

/* ---------- Detalle ---------- */
.cabeza-cliente { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.cabeza-cliente .avatar { width: 64px; height: 64px; font-size: 22px; }
.cabeza-cliente h3 { margin: 0; font-size: 20px; }
.lista-datos { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; }
.lista-datos dt { color: var(--suave); }
.lista-datos dd { margin: 0; word-break: break-word; }
.prestamo-card { border-left: 6px solid var(--diario-b); }
.prestamo-card.semanal { border-left-color: var(--semanal-b); background: var(--semanal-f); }
.prestamo-card.quincenal { border-left-color: var(--quincenal-b); background: var(--quincenal-f); }
.numeros { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 8px 0 12px; }
.numeros div { background: rgba(255,255,255,.75); border-radius: 10px; padding: 8px 10px; }
.numeros span { display: block; font-size: 12px; color: var(--suave); }
.numeros b { font-size: 17px; }
.numeros .saldo { grid-column: 1 / -1; }
.numeros .saldo b { font-size: 26px; color: var(--rojo); }
.barra-progreso { height: 8px; background: #e6e6e6; border-radius: 999px; overflow: hidden; margin: 6px 0; }
.barra-progreso div { height: 100%; background: var(--verde); }
.movimiento { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--linea); gap: 8px; }
.movimiento:last-child { border-bottom: 0; }
.movimiento small { display: block; color: var(--suave); font-size: 12px; }
.movimiento.anulado { text-decoration: line-through; opacity: .5; }
.valor-mas { color: var(--verde); font-weight: 700; }
.valor-menos { color: var(--rojo); font-weight: 700; }
.foto-grande { width: 100%; border-radius: 12px; display: block; }
.acciones-contacto { display: flex; gap: 8px; margin-bottom: 12px; }
.acciones-contacto a { flex: 1; text-align: center; text-decoration: none; background: #fff; border: 1px solid var(--linea); border-radius: 10px; padding: 10px; color: var(--prim); font-weight: 700; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login .logo { width: 170px; height: auto; margin: 0 auto 12px; display: block; }
.login h1 { text-align: center; margin: 0 0 4px; color: var(--prim); letter-spacing: .08em; text-transform: uppercase; }
.login p.sub { text-align: center; color: var(--suave); margin: 0 0 20px; }
.enlace { background: none; border: 0; color: var(--prim); text-decoration: underline; padding: 12px; display: block; margin: 8px auto 0; font-size: 14px; }
.mensaje-error { background: var(--rojo-f); color: var(--rojo); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; }
.mensaje-info { background: #e7f5ff; color: #1864ab; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; }

.aviso { position: fixed; left: 12px; right: 12px; bottom: calc(96px + env(safe-area-inset-bottom)); max-width: 520px; margin: 0 auto; background: #121212; color: #fff; padding: 12px 14px; border-radius: 12px; z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.3); font-size: 15px; }
.aviso.error { background: var(--rojo); }
.aviso.ok { background: var(--verde); }
.titulo-seccion { font-size: 13px; font-weight: 700; color: var(--suave); text-transform: uppercase; letter-spacing: .04em; margin: 16px 4px 8px; }
