/* ============================================================
   PrestamosApp - tema compartido (web + Android). Mobile-first.
   ============================================================ */
:root {
    --primary: #0f766e;      /* teal 700 */
    --primary-dark: #115e59;
    --primary-light: #ccfbf1;
    --accent: #f59e0b;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --danger: #dc2626;
    --ok: #16a34a;
    --warn: #d97706;
    --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.06);
    --radius: 14px;
    --nav-h: 62px;
    --bar-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}
h1,h2,h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }
.text-muted { color: var(--muted); font-size: .85rem; }

/* ---------- Shell ---------- */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }
.app-auth { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
    background: linear-gradient(160deg, var(--primary), var(--primary-dark)); }

.app-bar {
    height: var(--bar-h); background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px; position: sticky; top: 0; z-index: 20;
    box-shadow: var(--shadow);
}
.app-bar-info { display: flex; flex-direction: column; overflow: hidden; }
.app-bar-title { font-weight: 700; font-size: 1.05rem; line-height: 1.1; }
.app-bar-sub { font-size: .72rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-bar-logo { height: 38px; width: 38px; object-fit: contain; border-radius: 8px; background: #fff; padding: 2px; margin-right: 10px; flex-shrink: 0; }
.app-bar-actions { display: flex; gap: 4px; }
.btn-icon { background: rgba(255,255,255,.15); color: #fff; border: none; width: 38px; height: 38px;
    border-radius: 10px; font-size: 1.1rem; display: grid; place-items: center; }
.btn-icon:active { background: rgba(255,255,255,.3); }

.app-content { flex: 1; padding-bottom: calc(var(--nav-h) + 12px); }

/* ---------- Banner conexion / sync ---------- */
.banner { padding: 8px 14px; font-size: .82rem; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.banner-offline { background: #fef3c7; color: #92400e; }
.banner-sync { background: var(--primary-light); color: var(--primary-dark); }
.banner-sync button { background: var(--primary); color: #fff; border: none; border-radius: 8px; padding: 5px 12px; font-weight: 600; font-size: .8rem; }
.banner-sync button:disabled { opacity: .6; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; z-index: 20; padding-bottom: env(safe-area-inset-bottom);
}
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; text-decoration: none; color: var(--muted); font-size: .68rem; }
.nav-item.activo { color: var(--primary); }
.nav-icono { font-size: 1.35rem; line-height: 1; }
.nav-item.activo .nav-icono { transform: translateY(-1px); }

/* ---------- Pagina ---------- */
.pagina { max-width: 640px; margin: 0 auto; padding: 16px; }
.pagina-titulo { font-size: 1.35rem; font-weight: 700; }
.pagina-cabecera { display: flex; align-items: center; justify-content: space-between; }
.seccion { font-size: 1rem; margin: 4px 0 8px; }

/* ---------- Login ---------- */
.login-card { background: var(--surface); border-radius: 20px; padding: 32px 24px; width: 100%;
    max-width: 380px; box-shadow: 0 20px 40px rgba(0,0,0,.2); text-align: center; }
.login-logo { font-size: 3rem; }
.login-logo-img { max-height: 90px; max-width: 200px; object-fit: contain; margin: 0 auto 4px; display: block; }
.login-titulo { font-size: 1.6rem; font-weight: 800; color: var(--primary); margin-top: 4px; }
.login-sub { color: var(--muted); margin: 4px 0 20px; }
.login-card .campo { text-align: left; }

/* ---------- Formularios ---------- */
.campo { margin-bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
.campo label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.input { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px;
    font-size: 1rem; background: var(--surface); color: var(--text); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Botones ---------- */
.btn { padding: 11px 16px; border: none; border-radius: 10px; font-size: .95rem; font-weight: 600; }
.btn-sm { padding: 7px 12px; font-size: .85rem; }
.btn-primario { background: var(--primary); color: #fff; }
.btn-primario:active { background: var(--primary-dark); }
.btn-primario:disabled { opacity: .6; }
.btn-secundario { background: var(--primary-light); color: var(--primary-dark); }
.btn-bloque { width: 100%; margin-top: 6px; }
.btn-volver { background: none; border: none; color: var(--primary); font-weight: 600; padding: 4px 0; margin-bottom: 4px; }

/* ---------- Alertas / toast ---------- */
.alerta { padding: 10px 12px; border-radius: 10px; font-size: .88rem; margin: 10px 0; }
.alerta-error { background: #fef2f2; color: var(--danger); }
.alerta-ok { background: #f0fdf4; color: var(--ok); }
.alerta-info { background: #eff6ff; color: #1d4ed8; }
.toast { position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
    background: var(--text); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: .9rem;
    z-index: 60; box-shadow: var(--shadow); max-width: 90%; text-align: center; }

/* ---------- Tarjetas / listas ---------- */
.tarjeta { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.lista { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.tarjeta-boton { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
    border: none; background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tarjeta-icono { font-size: 1.4rem; }
.tarjeta-titulo { flex: 1; font-weight: 600; }
.tarjeta-flecha { color: var(--muted); font-size: 1.3rem; }
.tarjeta-peligro .tarjeta-titulo { color: var(--danger); }

.resumen-linea { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin: 10px 2px; }

/* ---------- Stats ---------- */
.grid-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 14px 10px; text-align: center; box-shadow: var(--shadow); }
.stat-num { display: block; font-size: 1.15rem; font-weight: 700; color: var(--primary); }
.stat-lbl { font-size: .7rem; color: var(--muted); }
.stat-ok .stat-num { color: var(--ok); }
.stat-gasto .stat-num { color: var(--danger); }

.progreso-recaudo { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin: 12px 0; }
.progreso-cabecera { display: flex; justify-content: space-between; margin-bottom: 8px; }
.barra { height: 12px; background: var(--border); border-radius: 6px; overflow: hidden; }
.barra-relleno { height: 100%; background: linear-gradient(90deg, var(--primary), var(--ok)); border-radius: 6px; transition: width .4s; }
.progreso-cifras { display: flex; justify-content: space-between; margin-top: 8px; font-size: .9rem; }
.acciones-rapidas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.acciones-rapidas .btn { width: 100%; }

/* ---------- Buscador ---------- */
.buscador { display: flex; gap: 8px; margin: 8px 0; }
.buscador .input { flex: 1; }

/* ---------- Semaforo ---------- */
.semaforo { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; }
.semaforo-punto { width: 12px; height: 12px; border-radius: 50%; }
.semaforo-verde .semaforo-punto { background: var(--ok); }
.semaforo-amarillo .semaforo-punto { background: var(--warn); }
.semaforo-rojo .semaforo-punto { background: var(--danger); }
.semaforo-verde { color: var(--ok); }
.semaforo-amarillo { color: var(--warn); }
.semaforo-rojo { color: var(--danger); }

/* ---------- Fila credito (recaudo) ---------- */
.fila-credito { display: flex; align-items: center; gap: 12px; background: var(--surface);
    border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.fila-credito-info { flex: 1; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.fila-credito-nombre { font-weight: 600; }
.fila-credito-sub { font-size: .78rem; color: var(--muted); }
.fila-credito-atraso { font-size: .72rem; color: var(--danger); font-weight: 600; }
.btn-cobrar { background: var(--primary); color: #fff; border: none; border-radius: 10px; padding: 9px 14px; font-weight: 600; font-size: .85rem; }
.btn-cobrar:active { background: var(--primary-dark); }

/* ---------- Cliente ---------- */
.fila-cliente { display: flex; align-items: center; gap: 12px; background: var(--surface);
    border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.fila-cliente-info { flex: 1; display: flex; flex-direction: column; }
.fila-cliente-nombre { font-weight: 600; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--primary-light); color: var(--primary-dark);
    display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.2rem; }
.perfil { display: flex; align-items: center; gap: 14px; background: var(--surface); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow); margin: 12px 0; }
.perfil strong { display: block; }

/* ---------- Detalle credito ---------- */
.detalle-cliente { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.detalle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detalle-grid .lbl { display: block; font-size: .72rem; color: var(--muted); }
.detalle-grid .destacado { font-weight: 700; color: var(--primary); }
.cierre-calculo { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px dashed var(--border); }
.cierre-desc strong { color: var(--danger); }
.cierre-calculo strong.cierre-desc { color: var(--danger); }
.desembolso { margin-top: 8px; padding: 10px 12px; background: var(--primary-light); border-radius: 10px; }
.desembolso .cierre-calculo { border-top-color: rgba(15,118,110,.25); }
.desembolso .cierre-calculo:first-child { border-top: none; }

/* ---------- Tabla ---------- */
.tabla-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.tabla { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tabla th, .tabla td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tabla th { background: #f8fafc; color: var(--muted); font-weight: 600; }
.fila-pagada { opacity: .55; }
.fila-abono { display: flex; justify-content: space-between; align-items: center; background: var(--surface);
    border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }

/* ---------- Badges ---------- */
.badge { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.badge-activo, .badge-parcial { background: #fef9c3; color: #854d0e; }
.badge-pagada, .badge-cancelado { background: #dcfce7; color: #166534; }
.badge-pendiente { background: #e2e8f0; color: #475569; }
.badge-anulado { background: #fee2e2; color: #991b1b; }
.badge-refinanciado { background: #e0e7ff; color: #3730a3; }

/* ---------- Chips ---------- */
.chips { display: flex; gap: 8px; margin-bottom: 12px; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: .82rem; }
.chip.activo { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Modal ---------- */
.modal-fondo { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50;
    display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 480px; border-radius: 20px 20px 0 0;
    padding: 20px; max-height: 90dvh; overflow-y: auto; animation: subir .2s ease; }
.modal h3 { margin-bottom: 4px; }
.modal-acciones { display: flex; gap: 10px; margin-top: 16px; }
.modal-acciones .btn { flex: 1; }
@keyframes subir { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
@media (min-width: 560px) { .modal-fondo { align-items: center; } .modal { border-radius: 20px; } }

/* ---------- Estados de carga ---------- */
.estado-carga, .estado-error { text-align: center; padding: 40px 20px; color: var(--muted); }
.estado-carga { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pantalla-carga { min-height: 100dvh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: girar .8s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
.version { text-align: center; color: var(--muted); font-size: .75rem; margin-top: 20px; }

/* ---------- Grafico de barras (reportes) ---------- */
.grafico { display: flex; flex-direction: column; gap: 10px; }
.barra-row { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 10px; }
.barra-label { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra-track { background: var(--bg); border-radius: 6px; height: 18px; overflow: hidden; }
.barra-fill { height: 100%; background: var(--primary); border-radius: 0 6px 6px 0; min-width: 3px; transition: width .4s; }
.barra-fill.barra-verde { background: var(--ok); }
.barra-fill.barra-amarillo { background: var(--warn); }
.barra-fill.barra-rojo { background: var(--danger); }
.barra-val { font-size: .78rem; font-weight: 700; color: var(--text); white-space: nowrap; }

/* ---------- Grafico de columnas (Inicio) ---------- */
.grafico-cols { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; height: 160px; padding-top: 8px; }
.col-item { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.col-val { font-size: .62rem; color: var(--muted); height: 14px; }
.col-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.col-bar { width: 70%; margin: 0 auto; background: var(--primary); border-radius: 5px 5px 0 0; min-height: 3px; transition: height .4s; }
.col-lbl { font-size: .62rem; color: var(--muted); margin-top: 4px; white-space: nowrap; }

/* ---------- Fotos ---------- */
.foto-picker { display: flex; flex-direction: column; gap: 6px; }
.foto-preview { position: relative; width: 100%; }
.foto-preview img { width: 100%; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.foto-quitar { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%;
    background: rgba(220,38,38,.9); color: #fff; border: none; font-size: .8rem; line-height: 1; }
.fotos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin: 8px 0; }
.foto-item { position: relative; }
.foto-item img { width: 100%; height: 100px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); cursor: pointer; }
.foto-tipo { position: absolute; bottom: 4px; left: 4px; background: rgba(15,23,42,.7); color: #fff;
    font-size: .65rem; padding: 1px 6px; border-radius: 999px; }
.foto-ampliada { max-width: 92%; max-height: 88dvh; border-radius: 12px; margin: auto; display: block; }

/* ---------- Mapa ---------- */
.mapa { width: 100%; height: 220px; border: 0; display: block; }
.mapa-ruta { width: 100%; height: 62vh; min-height: 340px; border-radius: 12px; box-shadow: var(--shadow); position: relative; z-index: 0; }
.mapa-pin { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff;
    display: grid; place-items: center; font-weight: 700; font-size: .82rem; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.45); }
.mapa-pin-cobrado { background: var(--ok); }
.mapa-pin-visitado { background: var(--warn); }
.mapa-pin-pendiente { background: var(--primary); }
.leaflet-popup-content { font-size: .85rem; }

.mapa-leyenda { display: flex; gap: 16px; margin: 6px 2px 10px; font-size: .8rem; color: var(--muted); }
.mapa-leyenda span { display: inline-flex; align-items: center; gap: 5px; }
.leyenda-punto { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.lp-cobrado { background: var(--ok); }
.lp-visitado { background: var(--warn); }
.lp-pendiente { background: var(--primary); }

/* ---------- Enrutamiento ---------- */
.fila-enrutar { display: flex; align-items: center; gap: 12px; background: var(--surface);
    border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.orden-num { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-light); color: var(--primary-dark);
    display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.orden-botones { display: flex; gap: 6px; }
.btn-orden { width: 38px; height: 38px; border: 1px solid var(--border); background: var(--surface);
    border-radius: 10px; font-size: 1rem; color: var(--primary); }
.btn-orden:disabled { opacity: .35; }
.btn-orden:active:not(:disabled) { background: var(--primary-light); }

/* ---------- Anular ---------- */
.btn-anular { background: #fee2e2; color: var(--danger); border: none; border-radius: 8px; padding: 6px 12px; font-weight: 600; font-size: .8rem; }
.btn-anular:active { background: #fecaca; }

/* ---------- Impresion de recibo ---------- */
.solo-print { display: none; }
.recibo-encabezado { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 10px; }
.recibo-encabezado img { max-height: 70px; max-width: 180px; object-fit: contain; }
.recibo-encabezado strong { font-size: 1.2rem; }
.recibo-encabezado span { font-size: .8rem; }
@media print {
    .app-bar, .bottom-nav, .no-print, .btn-volver { display: none !important; }
    .solo-print { display: flex !important; }
    .app-content { padding: 0 !important; }
    body { background: #fff; }
    .tarjeta, .fila-abono, .tabla-wrap { box-shadow: none !important; border: 1px solid #ccc; }
}

/* ---------- Admin ---------- */
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check { display: flex; align-items: center; gap: 6px; font-size: .9rem; }
.check input { width: 18px; height: 18px; }
.param-cab { display: flex; justify-content: space-between; align-items: center; }
.param-edit { display: flex; gap: 8px; margin-top: 8px; }
.param-edit .input { flex: 1; }

/* ---------- Blazor error UI ---------- */
#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    background: #fee2e2; color: #991b1b; padding: 12px 16px; box-shadow: 0 -2px 10px rgba(0,0,0,.15);
    font-size: .9rem;
}
#blazor-error-ui .reload { color: #991b1b; font-weight: 700; text-decoration: underline; margin-left: 6px; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }
.loading-progress, .loading-progress-text { display: none; }
