/* ============================================================
   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-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); }

/* ---------- 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-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); }

/* ---------- 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; }

/* ---------- 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; }

/* ---------- Mapa ---------- */
.mapa { width: 100%; height: 220px; border: 0; display: block; }

/* ---------- 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 ---------- */
@media print {
    .app-bar, .bottom-nav, .no-print, .btn-volver { display: none !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; }
