/* ══════════════════════════════════════════════════════════════════════════
   Casa Camejo — capa móvil (web app)
   Se carga con media="(max-width: 768px)": en escritorio NO existe, no se toca nada.
   Objetivos: leerse sin zoom, tocarse con el dedo (≥ 40 px), navegar como app (barra inferior + menú «Más»),
   tablas como tarjetas, modales como hojas inferiores y respetar notch / barra de gestos (safe areas).
   ══════════════════════════════════════════════════════════════════════════ */

:root { --bnav-h: 62px; --sa-b: env(safe-area-inset-bottom, 0px); --sa-t: env(safe-area-inset-top, 0px); }

/* ── Base ─────────────────────────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: contain; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
body.mnav-abierto { overflow: hidden; }
.page-content { padding: 14px 14px 22px; }
.main-content { margin-left: 0 !important; padding-bottom: calc(var(--bnav-h) + var(--sa-b) + 6px); min-height: 100dvh; }
img, svg, canvas, video { max-width: 100%; }

/* ── Barra superior con el título de la pantalla ──────────────────────────── */
.topbar { height: auto; min-height: 54px; padding: calc(var(--sa-t) + 0px) 12px 0; gap: 8px; justify-content: flex-start; background: #fff; }
.topbar-title { display: block; flex: 1 1 auto; min-width: 0; margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -.01em; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-date { display: none; }
.topbar-notif-btn { width: 40px; height: 40px; }
.topbar-notif-btn svg { width: 18px; height: 18px; }
.intelli-fab, .intelli-fab-icon { width: 40px !important; height: 40px !important; }
.intelli-fab-icon img { width: 22px !important; height: 22px !important; }

/* ── Barra inferior: 4 accesos + Más ──────────────────────────────────────── */
.bottom-nav {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 400;
  height: calc(var(--bnav-h) + var(--sa-b)); padding: 0 4px var(--sa-b);
  background: #fff; border-top: 1px solid var(--border); box-shadow: 0 -6px 24px rgba(21,41,26,.08);
  overflow: visible; justify-content: space-around; align-items: stretch;
}
.bnav-item {
  flex: 1 1 0; min-width: 0; min-height: var(--bnav-h); padding: 6px 2px; gap: 3px;
  color: var(--text-muted); font-size: 11px; font-weight: 600; background: none; border: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; position: relative;
}
.bnav-ic svg { width: 23px; height: 23px; }
.bnav-lbl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bnav-item.active { color: var(--primary-dark); }
.bnav-item.active .bnav-ic { background: var(--primary-light); border-radius: 999px; padding: 3px 16px; margin: -3px 0; }
.bnav-item.active .bnav-ic svg { stroke-width: 2.4; }
.bnav-item:active { background: var(--border-light); }
body.kb-open .bottom-nav, body.kb-open .qa-fab-wrap { display: none; }
body.kb-open .main-content { padding-bottom: 12px; }

/* El botón flotante «+» y los avisos quedan por encima de la barra */
.qa-fab-wrap { right: 16px; bottom: calc(var(--bnav-h) + var(--sa-b) + 14px); }
.qa-fab { width: 52px; height: 52px; }
/* Pantallas con su propia acción principal o mapa: sin el «+» flotante encima */
body[data-page="mostrador.html"] .qa-fab-wrap, body[data-page="mapa-calor.html"] .qa-fab-wrap, body[data-page="red-referidos.html"] .qa-fab-wrap,
body[data-page="ajustes.html"] .qa-fab-wrap, body[data-page="motor.html"] .qa-fab-wrap, body[data-page="usuarios.html"] .qa-fab-wrap { display: none; }
.toast-container, #toast-container { bottom: calc(var(--bnav-h) + var(--sa-b) + 12px) !important; }

/* ── Menú «Más» (launcher a pantalla casi completa) ───────────────────────── */
.mnav-overlay { position: fixed; inset: 0; z-index: 900; background: rgba(10,24,18,.5); opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; }
.mnav-overlay.open { opacity: 1; visibility: visible; }
.mnav-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: #fff; border-radius: 24px 24px 0 0; padding: 8px 16px calc(20px + var(--sa-b));
  transform: translateY(100%); transition: transform .26s cubic-bezier(.22,.9,.3,1);
}
.mnav-overlay.open .mnav-panel { transform: none; }
.mnav-grip { width: 42px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 12px; }
.mnav-head { display: flex; align-items: center; gap: 12px; padding: 2px 0 14px; }
.mnav-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--brand-dark); color: #fff; font-weight: 800; font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.mnav-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mnav-who b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mnav-who span { font-size: 12px; color: var(--text-muted); }
.mnav-x { width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--border-light); color: var(--text-secondary); display: flex; align-items: center; justify-content: center; }
.mnav-search { width: 100%; margin-bottom: 4px; border: 1.5px solid var(--border); border-radius: 14px; padding: 0 14px; background: var(--bg); }
.mnav-grupo h3 { margin: 18px 2px 8px; font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-muted); }
.mnav-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mnav-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; min-height: 82px; padding: 10px 6px; text-align: center; text-decoration: none;
  border: 1px solid var(--border); border-radius: 16px; background: #fff; color: var(--text-primary); font-size: 12px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere;
}
.mnav-tile .mnav-ic svg { width: 24px; height: 24px; color: var(--primary-dark); }
.mnav-tile:active { background: var(--primary-xlight); }
.mnav-tile.active { background: var(--primary-light); border-color: var(--accent-dim); box-shadow: inset 0 0 0 1px var(--accent); }
.mnav-empty { text-align: center; color: var(--text-muted); font-size: 13px; padding: 22px 0; }
.mnav-install { display: none; width: 100%; margin-top: 18px; min-height: 48px; border-radius: 14px; border: 1.5px solid var(--primary-dark); background: var(--primary-xlight); color: var(--primary-dark); font-weight: 700; font-size: 14px; }
.mnav-install.on { display: block; }
.mnav-hint { margin: 14px 2px 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; text-align: center; }
.mnav-logout { width: 100%; margin-top: 18px; min-height: 48px; border-radius: 14px; border: 1.5px solid var(--danger-border); background: #fff; color: var(--danger-dark); font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 8px; }

/* ── Tocar con el dedo: tamaños mínimos ───────────────────────────────────── */
button:not(.bnav-item):not(.mnav-x):not(.mnav-tile):not(.leaflet-touch *):not(.leaflet-control *),
.btn, [role="button"], a.btn, select { min-height: 40px !important; }
.btn-xs, .table-scroll button, .table-scroll .btn-xs { min-height: 36px !important; }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=hidden]):not([type=color]):not([type=submit]),
select, textarea { font-size: 16px !important; }     /* 16 px evita que iPhone haga zoom al enfocar un campo */
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=hidden]):not([type=color]), select { min-height: 44px; }
.form-input, .form-select { padding-top: 10px; padding-bottom: 10px; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
label { -webkit-user-select: none; user-select: none; }
.btn { padding: 10px 16px; font-size: 14px; gap: 6px; }
.btn-sm { padding: 8px 13px; font-size: 13px; }
.btn-xs { padding: 7px 11px; font-size: 12.5px; }
.btn-lg { padding: 13px 20px; font-size: 15px; }
.form-label, label.form-label { font-size: 13px; }
.form-row, .form-row-3, .form-grid { grid-template-columns: 1fr !important; }

/* ── Tarjetas, KPIs y dashboard: legibles y de 2 columnas ─────────────────── */
.card { padding: 14px; border-radius: 18px; }
.card-header { padding: 14px; flex-wrap: wrap; gap: 8px; }
.card-title { font-size: 15px; }
.card-body { padding: 14px; }
.section-title { font-size: 17px; }
.kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
.kpi-card { padding: 12px 14px; min-height: 0; text-align: left; align-items: flex-start; }
.kpi-header { flex-direction: row; align-items: center; justify-content: flex-start; gap: 8px; width: 100%; }
.kpi-header > div { text-align: left; width: auto; }
.kpi-label, .stat-card-label { font-size: 11px !important; letter-spacing: .05em; text-align: left; width: auto; }
.kpi-label[data-short]::after, .stat-card-label[data-short]::after { content: none; }
.kpi-value { font-size: 19px !important; text-align: left; width: auto; }
.stats-row { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
.stat-card { padding: 12px 14px; text-align: left; align-items: flex-start; }
.stat-card-value { font-size: 18px !important; text-align: left; }
.comparativo-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
.comparativo-card { padding: 12px 10px; }
.comparativo-card .c-value { font-size: 17px; }
.comparativo-card .c-label { font-size: 10.5px; letter-spacing: .03em; }
.aging-grid { display: flex !important; overflow-x: auto; gap: 8px; padding-bottom: 6px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.aging-card { flex: 0 0 122px; scroll-snap-align: start; padding: 10px 10px; border-radius: 12px; }
.aging-label { font-size: 10.5px; gap: 5px; margin-bottom: 5px; }
.aging-label::before { width: 8px; height: 8px; }
.aging-count { font-size: 22px; }
.aging-monto { font-size: 11.5px; }
.chart-container { height: 230px; }
.dash-2col .dash-side .intelli-stack { flex-direction: column; }
.dash-2col .dash-side .intelli-stack > .intelli-card { padding: 14px; align-items: stretch; }
.dash-2col .dash-side .intelli-stack .card-header { flex-direction: row; justify-content: space-between; text-align: left; }
.dash-2col .dash-side .intelli-stack .card-title { font-size: 14px; justify-content: flex-start; text-align: left; }
.dash-2col .dash-side .intelli-stack .card-title svg { display: inline-block; }
.dash-2col .dash-side .intelli-stack .btn-sm { font-size: 13px; padding: 8px 14px; }
.ejecutivo-card { padding: 12px; gap: 10px; }
.ejecutivo-avatar { width: 38px; height: 38px; font-size: 15px; }
.ejecutivo-info h4 { font-size: 14px; }
.ejecutivo-info p { font-size: 12px; }
.stat-value { font-size: 14px; }
.stat-label { font-size: 10.5px; }
.mora-analysis-title { font-size: 13px; }
.mora-analysis-row { font-size: 13px; }
.mora-charts-row canvas { max-height: 240px; }

/* ── Chips, pestañas y barras de vista: deslizables, sin cortarse ─────────── */
.ajustes-tabs, .view-toggle, .pa-chips, .mos-seg, .motor-chips, .chips, .tabs, .seg, .co-seg { display: flex; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; max-width: 100%; }
.ajustes-tabs::-webkit-scrollbar, .view-toggle::-webkit-scrollbar, .co-seg::-webkit-scrollbar { display: none; }
.ajustes-tab, .view-toggle button, .co-seg button { flex: 0 0 auto; white-space: nowrap; min-height: 42px; padding: 8px 14px; font-size: 13.5px; }
.ajustes-tabs { margin: 0 -14px 16px; padding: 0 14px; }
.matriz-toolbar, .table-filters, .mapa-filters, .mapa-toolbar { gap: 8px; }
.matriz-toolbar .form-input, .matriz-toolbar .form-select { min-height: 44px; }

/* ── Encabezados de tablas y filtros ──────────────────────────────────────── */
.table-header { padding: 14px; gap: 10px; flex-wrap: wrap; }
.table-title { font-size: 15px; }
.table-header > .btn { flex: 1 1 auto; }
.table-header > .table-title { flex: 1 1 100%; }
.table-header > .table-filters { flex: 1 1 100%; width: 100%; }
.table-header .table-filters input, .table-header .table-filters select { max-width: none !important; width: 100%; }

/* ── Tablas → tarjetas (las etiqueta MobileTables en utils.js) ────────────── */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { font-size: 13px; }
.data-table th, .data-table td { padding: 10px 11px; }
table.mob-tarjetas, table.mob-tarjetas tbody, table.mob-tarjetas tr, table.mob-tarjetas td { display: block; width: 100%; box-sizing: border-box; }
table.mob-tarjetas { min-width: 0 !important; width: 100% !important; }
table.mob-tarjetas thead { display: none; }
table.mob-tarjetas tbody tr { position: static; margin: 0 0 10px; padding: 12px 14px; background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-xs); }
table.mob-tarjetas tbody tr:active { background: var(--primary-xlight); }
table.mob-tarjetas td { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 5px 0 !important; border: 0 !important; background: transparent !important; white-space: normal !important; text-align: right !important; font-size: 13.5px; position: static !important; box-shadow: none !important; min-width: 0 !important; max-width: none !important; }
table.mob-tarjetas td::before { content: attr(data-label); flex: 0 0 38%; max-width: 44%; text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); }
table.mob-tarjetas td:not([data-label])::before, table.mob-tarjetas td[data-label=""]::before { content: none; }
table.mob-tarjetas td:empty { display: none; }
table.mob-tarjetas td:first-child { font-size: 15px; font-weight: 700; padding-top: 0 !important; color: var(--text-primary); justify-content: flex-start; text-align: left !important; }
table.mob-tarjetas td:first-child::before { content: none; }
table.mob-tarjetas td.mob-acciones { flex-wrap: wrap; justify-content: flex-start; padding-top: 10px !important; margin-top: 6px; border-top: 1px solid var(--border-light) !important; }
table.mob-tarjetas td.mob-acciones::before { content: none; }
table.mob-tarjetas td.mob-acciones .actions, table.mob-tarjetas td.mob-acciones > div { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
table.mob-tarjetas .cell-clip { max-width: none !important; white-space: normal; }
/* Tabla ancha con columnas elegidas (directorio de clientes): en la tarjeta solo se muestran las marcadas */
table.mob-tarjetas.mob-selectivo td:not(.m-show):not(.col-fixed-1):not(.col-fixed-2):not(.mob-acciones) { display: none; }
table.mob-tarjetas.mob-selectivo td.col-fixed-1 { position: absolute !important; top: 14px; right: 14px; left: auto !important; width: auto !important; max-width: none !important; font-size: 11px; font-weight: 600; color: var(--text-hint); }
table.mob-tarjetas.mob-selectivo td.col-fixed-1::before { content: '#'; flex: 0 0 auto; }
table.mob-tarjetas.mob-selectivo tbody tr { position: relative; }
table.mob-tarjetas.mob-selectivo td.col-fixed-2 { display: block; font-size: 16px; font-weight: 700; text-align: left !important; padding: 0 46px 8px 0 !important; color: var(--text-primary); }
table.mob-tarjetas.mob-selectivo td.col-fixed-2::before { content: none; }
table.mob-tarjetas td.mob-vacio { display: none; }
.table-scroll { height: calc(100dvh - 300px); min-height: 320px; padding: 10px; }
.table-scroll .data-table.wide { width: 100% !important; }

/* ── Modales como hoja inferior ───────────────────────────────────────────── */
.modal-overlay { align-items: flex-end; padding: 0; }
.modal, .modal-lg, .modal-xl { width: 100%; max-width: none; max-height: 94dvh; border-radius: 22px 22px 0 0; margin: 0; transform: translateY(24px); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.modal-overlay.open .modal { transform: none; }
.modal-header { padding: 16px 18px 12px; border-radius: 22px 22px 0 0; }
.modal-header::before { content: ''; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--border); }
.modal-title { font-size: 17px; }
.modal-header .modal-close { width: 40px !important; height: 40px !important; font-size: 26px; }
.modal-footer .modal-close { width: auto !important; height: auto !important; font-size: 14px !important; }
.modal-body { padding: 14px 18px; }
.modal-footer { position: sticky; bottom: 0; background: #fff; padding: 12px 18px calc(12px + var(--sa-b)); border-top: 1px solid var(--border-light); display: flex; gap: 10px; }
.modal-footer .btn { flex: 1 1 0; justify-content: center; min-height: 46px !important; }

/* ── INTELLI (asistente): pantalla completa ───────────────────────────────── */
.intelli-panel { width: 100vw; max-width: 100vw; height: 100dvh; border-left: 0; }

/* ── Detalle de préstamos, pagos, etc. en columnas → una sola ─────────────── */
.detail-grid, .info-grid, .two-col, .doc-upload-grid, .motor-grid { grid-template-columns: 1fr !important; }

/* ── Mapa ─────────────────────────────────────────────────────────────────── */
body .mapa-wrap { height: calc(100dvh - var(--bnav-h) - var(--sa-b) - 300px); min-height: 340px; }
body .mapa-kpis { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
body .mapa-kpi { min-width: 0; padding: 8px 12px; }
body .mapa-wrap { display: flex; flex-direction: column; }
body #mapa-leaflet { flex: 1 1 auto; min-height: 0; height: auto; }
body .mapa-banner { position: static; transform: none; flex: 0 0 auto; width: 100%; border-radius: 0; border: 0; border-bottom: 1px solid #fde68a; box-shadow: none; font-size: 11.5px; padding: 7px 12px; }
body .mapa-legend { bottom: 10px; left: 10px; padding: 8px 10px; }
body .mapa-legend-bar { width: 110px; }
.leaflet-control-zoom a { width: 38px !important; height: 38px !important; line-height: 38px !important; font-size: 20px !important; }

/* ── Mostrador (herramienta principal de tienda) ──────────────────────────── */
body .mos-qr-desktop { display: none; }
body .mos-only-mobile { display: inline-flex; }

/* ── Público / portal ─────────────────────────────────────────────────────── */
body.login-page input { font-size: 16px !important; }

/* ── Motor financiero ─────────────────────────────────────────────────────── */
.motor-toolbar, .motor-picker { width: 100%; }
.motor-picker .smart-select, .smart-select { width: 100%; display: block; }
.smart-select-input { min-height: 44px; }
.motor-pesos-body { flex-direction: column; align-items: stretch; gap: 16px; }
.pesos-dona { margin: 0 auto; }
.pesos-lista { min-width: 0; flex: 1 1 auto; }
.motor-pesos-sub { display: block; margin: 2px 0 0; }

/* ── Detalles de tamaño táctil y legibilidad ──────────────────────────────── */
.intelli-panel-clear, .intelli-panel-close, .intelli-tools-x { min-width: 40px; min-height: 40px !important; }
table.mob-tarjetas td a[href^="tel:"] { display: inline-block; padding: 6px 0; font-size: 15px; font-weight: 600; }
table.mob-tarjetas td a { min-height: 32px; display: inline-flex; align-items: center; }
body .pa-kpi span, body .fd-kpi span, body .cb-kpi span, body .mapa-kpi span, body .ml-kpi span, body .kpi-mini-lbl { font-size: 11px; }

/* ── Barras de filtros: cuadrícula de 2 columnas (el buscador ocupa todo el ancho) ─── */
body .pa-filtros, body .filters, body [class*="-filtros"] { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 14px; align-items: stretch; }
body .pa-filtros > *, body .filters > *, body [class*="-filtros"] > * { width: 100% !important; min-width: 0 !important; max-width: none !important; margin: 0 !important; }
body .pa-filtros > input[type=text], body .pa-filtros > input[type=search], body .pa-filtros > .btn:last-child, body .filters > input[type=text], body [class*="-filtros"] > input[type=text] { grid-column: 1 / -1; }

table.mob-tarjetas td { overflow-wrap: anywhere; word-break: break-word; }
table.mob-tarjetas td::before { overflow-wrap: normal; word-break: normal; }

/* Capas: los modales (hojas inferiores) quedan por encima de la barra de navegación; los avisos por encima de todo */
.modal-overlay { z-index: 600; }
.toast { bottom: calc(var(--bnav-h) + var(--sa-b) + 14px) !important; max-width: calc(100vw - 28px); }
body:has(.modal-overlay.open) .toast { bottom: calc(var(--sa-b) + 16px) !important; }
