/* ============================================================
   Prestamos RD — Capa MOVIL / PWA  (app-mobile.css)
   Se carga DESPUES de velonic.css. Solo agrega reglas para
   pantallas chicas; en escritorio no cambia nada.
   ============================================================ */

:root {
  --app-nav-h: 62px;
  --app-topbar-h: 56px;
  --app-safe-b: env(safe-area-inset-bottom, 0px);
  --app-safe-t: env(safe-area-inset-top, 0px);
  --app-radius: 14px;
  --app-shadow: 0 2px 10px rgba(15, 23, 42, .06);
}

html { -webkit-text-size-adjust: 100%; }
body {
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   ESCRITORIO: el boton hamburguesa COLAPSA el menu a una barra
   de iconos (76px). Se recuerda en localStorage.
   ============================================================ */
@media (min-width: 992px) {
  body.side-mini .leftside-menu {
    width: 76px !important; min-width: 76px !important;
    overflow-x: hidden;
  }
  body.side-mini .leftside-menu .side-nav-link {
    justify-content: center; padding: 14px 0; border-left-width: 0;
  }
  body.side-mini .leftside-menu .side-nav-link i { margin: 0; font-size: 1.25rem; }
  body.side-mini .leftside-menu .side-nav-link span,
  body.side-mini .leftside-menu .side-nav-title,
  body.side-mini .leftside-menu .menu-arrow,
  body.side-mini .leftside-menu .side-nav-second-level,
  body.side-mini .leftside-menu .only-mobile { display: none !important; }
  body.side-mini .leftside-menu .side-nav-link.active { background: rgba(var(--fxf-primary-rgb), .1); }
  body.side-mini .content-page { margin-left: 76px; }
  body.side-mini .button-toggle-menu { color: var(--fxf-primary); }
}

/* ============================================================
   AVISO DE MODO DEMO (cuando el usuario demo esta logueado)
   ============================================================ */
.demo-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  flex-wrap: wrap;
  background: linear-gradient(90deg, #b45309, #d97706 55%, #f59e0b);
  color: #fff; font-size: .82rem; font-weight: 600;
  padding: 8px 14px;
  position: relative; z-index: 900; /* debajo del menu lateral (1055) para que el drawer lo tape al abrirse */
}
.demo-banner i { font-size: 1rem; }
.demo-banner strong { letter-spacing: .03em; }
.demo-banner-btn {
  background: rgba(255, 255, 255, .95); color: #92400e;
  border: 0; border-radius: 99px; padding: 6px 14px;
  font-size: .78rem; font-weight: 800; cursor: pointer;
  min-height: 34px;
}
.demo-banner-btn:active { transform: scale(.97); }

/* utilidades */
.only-mobile { display: none !important; }

/* ============================================================
   TOPBAR en movil
   ============================================================ */
@media (max-width: 991.98px) {
  .navbar-custom {
    height: calc(var(--app-topbar-h) + var(--app-safe-t));
    padding-top: var(--app-safe-t);
  }
  .topbar {
    height: var(--app-topbar-h);
    padding: 0 10px;
    gap: 6px;
  }
  .navbar-custom .logo-topbar { font-size: 1rem; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .button-toggle-menu { font-size: 1.5rem; padding: 6px 8px; min-width: 44px; min-height: 44px; border-radius: 10px; }
  .button-toggle-menu:active { background: rgba(var(--fxf-primary-rgb), .12); }
  .topbar-menu { gap: 4px; }
  .topbar-menu .nav-link { padding: 8px; min-width: 40px; min-height: 40px; justify-content: center; }

  /* el topbar tiene que caber en 390px: el logo se encoge, no empuja */
  .navbar-custom { width: 100%; }
  .topbar { gap: 2px; }
  .topbar > .d-flex { min-width: 0; flex: 1 1 auto; }
  .navbar-custom .logo-topbar { flex: 0 1 auto; min-width: 0; max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-menu { flex: 0 0 auto; min-width: 0; }
  .btn-install-top { padding: 8px 10px; }
  .btn-install-top span { display: none; }
  .topbar-menu .nav-user img { width: 30px; height: 30px; }
  .topbar-menu .dropdown-menu {
    position: fixed !important;
    top: calc(var(--app-topbar-h) + var(--app-safe-t) + 4px) !important;
    left: 8px !important; right: 8px !important;
    width: auto !important; max-width: none;
    transform: none !important;
    max-height: 70vh; overflow-y: auto;
    border-radius: var(--app-radius);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
  }
  .noti-icon-badge { top: 0; right: 0; }

  /* barra de busqueda: oculta (ya estaba d-none d-lg-block) */
  .app-search { display: none !important; }
}

/* ============================================================
   SIDEBAR como drawer (off-canvas)
   ============================================================ */
.sidebar-mobile-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--fxf-border-color);
  font-weight: 700;
  color: var(--fxf-heading-color);
}
.sidebar-mobile-head button {
  border: 0; background: rgba(var(--fxf-primary-rgb), .1); color: var(--fxf-primary);
  width: 36px; height: 36px; border-radius: 10px; font-size: 1.1rem; display: flex;
  align-items: center; justify-content: center;
}

.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(2px);
  z-index: 1050;
  opacity: 0; visibility: hidden;
  transition: opacity .25s ease, visibility .25s ease;
}
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

@media (max-width: 991.98px) {
  .leftside-menu {
    top: 0 !important;
    height: 100% !important;
    bottom: 0;
    width: 84% !important;
    max-width: 320px;
    z-index: 1055;
    padding-top: var(--app-safe-t);
    padding-bottom: calc(16px + var(--app-safe-b));
    box-shadow: 6px 0 30px rgba(15, 23, 42, .18);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    will-change: transform;
  }
  .leftside-menu.open { transform: translateX(0); }
  .sidebar-mobile-head { display: flex; }

  .side-nav { padding-bottom: 24px; }
  .side-nav-link { padding: 14px 18px; font-size: .95rem; min-height: 48px; }
  .side-nav-link i { font-size: 1.25rem; width: 24px; }
  .side-nav-second-level a { padding: 12px 18px 12px 46px; font-size: .875rem; }
  .side-nav-title { padding: 16px 18px 6px; }

  .content-page { margin-left: 0; }
}

/* ============================================================
   CONTENIDO en movil
   ============================================================ */
@media (max-width: 991.98px) {
  .content { padding: 12px 12px 0; }
  .content-page {
    padding-bottom: calc(var(--app-nav-h) + var(--app-safe-b) + 12px);
    min-height: auto;
  }
  /* la cadena flex tiene que poder encogerse o el contenido empuja la pagina */
  .content-page, .content, .content-page .container-fluid { min-width: 0 !important; max-width: 100%; }
  .content-page { width: 100%; }
  .page-title-box { margin-bottom: 12px; gap: 8px; }
  .page-title { font-size: 1.15rem; font-weight: 600; }
  .page-title-right, .page-title-box .breadcrumb { font-size: .8125rem; }
  .page-title-box > div { width: 100%; }
  .page-title-box .btn { width: 100%; }

  /* tarjetas mas compactas y redondeadas */
  .card { border-radius: var(--app-radius); margin-bottom: 12px; box-shadow: var(--app-shadow); }
  .card-body { padding: 14px; }
  .header-title { font-size: .95rem; }

  /* KPIs del dashboard */
  .widget-flat .card-body { padding: 16px; }
  .widget-flat h6 { font-size: .7rem; letter-spacing: .03em; }
  .widget-flat h2 { font-size: 1.5rem; margin: .35rem 0 !important; }
  .widget-flat .widget-icon { font-size: 1.6rem; }
  .widget-flat p { font-size: .78rem; }

  /* botones y campos tactiles */
  .btn { border-radius: 10px; }
  .btn:not(.btn-sm):not(.btn-close) { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-sm { min-height: 36px; }
  /* 16px evita el zoom automatico de iOS al enfocar */
  .form-control, .form-select, .select2-container .select2-selection--single,
  input, select, textarea { font-size: 16px !important; }
  .form-control, .form-select { min-height: 46px; border-radius: 10px; }
  .form-label { font-size: .8125rem; }
  .input-group-text { border-radius: 10px 0 0 10px; }
  .mb-3 { margin-bottom: .85rem !important; }

  /* tablas: si no se apilan, que hagan scroll suave */
  .table-responsive { -webkit-overflow-scrolling: touch; border-radius: 12px; }

  /* paginacion */
  .pagination { flex-wrap: wrap; gap: 4px; }
  .pagination .page-link { min-width: 40px; min-height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px !important; }

  /* footer minimalista (la barra inferior ya ocupa el fondo) */
  .footer { padding: 12px; font-size: .72rem; text-align: center; border-top: 0; }

  /* modales = bottom sheet */
  .modal-dialog { margin: 0 !important; position: fixed; bottom: 0; left: 0; right: 0; max-width: 100%; }
  .modal-dialog .modal-content {
    border-radius: 20px 20px 0 0;
    border: 0;
    max-height: 92vh;
    overflow-y: auto;
    padding-bottom: var(--app-safe-b);
  }
  .modal.fade .modal-dialog { transform: translateY(60px); transition: transform .25s ease-out; }
  .modal.show .modal-dialog { transform: none; }
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; gap: 8px; }
  .modal-footer .btn { flex: 1 1 auto; }

  /* avatares y listas */
  .list-group-item { padding: 12px 14px; }
}

/* ============================================================
   TABLAS -> TARJETAS (apiladas) en celular
   La clase .table-stack la pone app-mobile.js automaticamente
   y copia el texto del <thead> a data-label de cada <td>.
   ============================================================ */
@media (max-width: 767.98px) {
  /* tablas que no se apilan (sin <thead>) al menos que corten el texto */
  .content-page table.table-nowrap th,
  .content-page table.table-nowrap td { white-space: normal !important; }
  .content-page .table { --bs-table-cell-padding-x: .5rem; font-size: .85rem; }

  table.table-stack { border-collapse: separate; border-spacing: 0; width: 100%; }
  table.table-stack thead { display: none; }
  table.table-stack tbody { display: block; }
  table.table-stack tr {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e8ecf1;
    border-radius: var(--app-radius);
    margin-bottom: 10px;
    padding: 4px 2px;
    box-shadow: var(--app-shadow);
  }
  table.table-stack tr:active { background: #fbfdff; }
  table.table-stack td {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: 100% !important;
    max-width: 100% !important;
    border: 0 !important;
    border-bottom: 1px dashed #eef1f5 !important;
    padding: 9px 14px !important;
    text-align: right;
    white-space: normal !important;
    font-size: .9rem;
  }
  table.table-stack td:last-child { border-bottom: 0 !important; }
  table.table-stack td { flex-wrap: wrap; overflow-wrap: anywhere; }
  /* dentro de la tarjeta nada se sale: telefonos, correos, montos largos */
  table.table-stack td a,
  table.table-stack td small,
  table.table-stack td .text-nowrap,
  table.table-stack td span { white-space: normal !important; overflow-wrap: anywhere; }
  table.table-stack td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    text-align: left;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: #8a93a3;
    line-height: 1.25;
  }
  /* la celda del cliente/nombre hace de titulo de la tarjeta */
  table.table-stack td.stack-title {
    order: -1;
    display: block !important;
    text-align: left;
    font-weight: 700;
    font-size: 1rem;
    color: var(--fxf-heading-color);
    background: rgba(var(--fxf-primary-rgb), .05);
    border-radius: 11px;
    padding: 10px 14px !important;
    border-bottom: 1px solid #eef1f5 !important;
  }
  table.table-stack td.stack-title::before { display: none; }
  /* numero de fila / ID: al final y en gris */
  table.table-stack td.stack-meta {
    order: 99;
    font-size: .78rem;
    color: #98a2b3;
    border-bottom: 0 !important;
    padding-top: 4px !important;
  }
  table.table-stack td.stack-meta::before { color: #b6bfcc; }
  /* celdas sin encabezado (acciones) van a lo ancho */
  table.table-stack td[data-label=""] { justify-content: flex-end; }
  table.table-stack td[data-label=""]::before { display: none; }
  table.table-stack td .btn { min-height: 38px; }
  table.table-stack td > .d-flex { width: 100%; justify-content: flex-end; }
  /* celdas con colspan (mensajes de "no hay datos") no se tocan */
  table.table-stack tr.table-empty { display: block; }
}

/* ============================================================
   BARRA INFERIOR tipo app  (Inicio / Clientes / Prestamos...)
   ============================================================ */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--app-nav-h) + var(--app-safe-b));
  padding-bottom: var(--app-safe-b);
  background: rgba(255, 255, 255, .97);
  backdrop-filter: blur(12px);
  border-top: 1px solid #e6ebf1;
  z-index: 1040;
  box-shadow: 0 -2px 14px rgba(15, 23, 42, .06);
}
.bottom-nav a {
  flex: 1 1 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  color: #8a93a3;
  font-size: .66rem;
  font-weight: 600;
  text-decoration: none;
  position: relative;
  min-width: 0;
  padding: 6px 2px 4px;
}
.bottom-nav a i { font-size: 1.3rem; line-height: 1; }
.bottom-nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bottom-nav a.active { color: var(--fxf-primary); }
.bottom-nav a.active::before {
  content: '';
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 26px; height: 3px; border-radius: 0 0 4px 4px;
  background: var(--fxf-primary);
}
.bottom-nav a:active { background: rgba(var(--fxf-primary-rgb), .08); }
.bottom-nav .bn-badge {
  position: absolute; top: 4px; right: calc(50% - 20px);
  background: var(--fxf-danger); color: #fff;
  font-size: .6rem; padding: 1px 5px; border-radius: 99px; line-height: 1.4;
}

@media (max-width: 991.98px) {
  .bottom-nav { display: flex; }
  .only-mobile { display: revert !important; }
}

/* ============================================================
   BOTON INSTALAR / BANNER iOS / AVISO OFFLINE
   ============================================================ */
.btn-install-top {
  display: none;
  align-items: center; gap: 6px;
  background: rgba(var(--fxf-primary-rgb), .12);
  color: var(--fxf-primary) !important;
  border: 0; border-radius: 99px;
  padding: 8px 12px; font-size: .78rem; font-weight: 700;
  min-height: 40px;
}
.btn-install-top.show { display: inline-flex; }

.ios-install-hint {
  position: fixed;
  left: 10px; right: 10px;
  bottom: calc(var(--app-nav-h) + var(--app-safe-b) + 10px);
  background: #0f172a;
  color: #fff;
  border-radius: var(--app-radius);
  padding: 13px 14px;
  font-size: .82rem;
  line-height: 1.45;
  z-index: 1060;
  display: none;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .3);
}
.ios-install-hint.show { display: block; }
.ios-install-hint b { color: #7dd3fc; }
.ios-install-hint .close-hint {
  position: absolute; top: 6px; right: 8px;
  background: none; border: 0; color: #94a3b8; font-size: 1.1rem; padding: 4px;
}

.app-toast {
  position: fixed;
  left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--app-nav-h) + var(--app-safe-b) + 14px);
  background: #0f172a; color: #fff;
  padding: 11px 18px; border-radius: 99px;
  font-size: .82rem; font-weight: 600;
  z-index: 1070; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  max-width: 92vw; text-align: center;
}
.app-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.offline-bar {
  display: none;
  background: #b45309; color: #fff;
  text-align: center; font-size: .78rem; font-weight: 600;
  padding: 6px 10px;
  position: sticky; top: calc(var(--app-topbar-h) + var(--app-safe-t));
  z-index: 1030;
}
body.is-offline .offline-bar { display: block; }

/* SW actualizado -> recargar */
.sw-update-bar {
  position: fixed; left: 10px; right: 10px;
  bottom: calc(var(--app-nav-h) + var(--app-safe-b) + 10px);
  background: var(--fxf-primary); color: #fff;
  border-radius: var(--app-radius);
  padding: 12px 14px; font-size: .84rem; font-weight: 600;
  display: none; align-items: center; justify-content: space-between; gap: 10px;
  z-index: 1065;
}
.sw-update-bar.show { display: flex; }
.sw-update-bar button {
  background: #fff; color: var(--fxf-primary); border: 0;
  border-radius: 99px; padding: 7px 14px; font-weight: 700; font-size: .8rem;
}

/* ============================================================
   TABLET (768 - 991): 2 columnas comodas
   ============================================================ */
@media (min-width: 768px) and (max-width: 991.98px) {
  .content { padding: 16px 16px 0; }
  .page-title-box .btn { width: auto; }
  .page-title-box > div { width: auto; }
}

/* ============================================================
   Detalles finos: quitar hover pegado en tactil
   ============================================================ */
@media (hover: none) {
  .table-hover tbody tr:hover { background: transparent; }
  .side-nav-link:hover { background: transparent; }
}
