/* ==========================================================================
   SmartFinca · css/sf-movil.css · Fases B y C del plan «PLAN_MOVIL» (celulares y tablets). SOLO DESARROLLO.

   Reglas globales para pantallas <= 1024 px y para pantallas tactiles. Lo propio de cada pantalla va en css/movil/g1.css a g6.css.

   REGLAS DE ESTE ARCHIVO
   1. TODA regla esta dentro de un @media screen and (<= 1024.98px, <= 767.98px, <= 479.98px, <= 359.98px, celular horizontal o (pointer: coarse)).
      En PC (>= 1025 px con raton) este archivo no cambia ni un pixel. Excepciones: un @media print que OCULTA lo que sf-movil.js crea (barra y entrada del menu) y el modo
      tarjeta (seccion I), que rige en todos los anchos pero solo en las tablas .sf-tarjetas, que sf-movil.js marca unicamente en las pantallas de RUTAS_TARJETA.
   2. Se carga DOS veces a proposito: en <head> (primer pintado sin saltos ni menu abierto) y al final del <body> (gana a los
      <style> de cada pantalla, que van dentro del body). Las reglas son idempotentes.
   3. !important solo donde el CSS existente ya usa !important o hay un estilo en linea (se indica con «!i» en el comentario).
   4. Puntos de corte alineados con los que ya usa la app: 1024 (menu: sidebar*.css, sidebar-ui.js), 768/767 (plantilla.css), 640, 480.
   5. Colores: solo los de las variables de vistas/css/plantilla.css (--finca-*, --shadow-*), mas el blanco; el menu lateral conserva su paleta (--sb-*).

   CONTENIDO
    A. Base y desborde             G. Toques (pointer: coarse)      M. Celular horizontal
    B. Barra lateral (cajon)       H. Texto minimo 12 px            N. Celulares pequenos (<= 359.98)
    C. Barra superior y ☰ (Fase C) I. Tablas (envoltorio, sombra,   O. Impresion (oculta lo que crea sf-movil.js)
    D. Mapa flotante y su entrada     columna fija, TARJETAS)
       en el menu (Fase C)         J. Modales y cajones (pantalla completa, pie fijo)
    E. Panel lateral               K. Pestanas, chips y filtros
    F. Campos de formulario        L. Encabezados, tarjetas de indicadores y grillas

   Interfaz hacia las pantallas (la usa la Fase C en css/movil/gN.css):
    - table.sf-tarjetas ......... tabla en modo tarjeta (<= 767.98 siempre; en tableta y PC, solo en las listas de RUTAS_TARJETA de sf-movil.js). sf-movil.js copia el texto de cada <th> al data-label de cada <td>, marca la celda de
                                  acciones (.sfmv-acciones), la de solo casilla (.sfmv-sel) y la del titulo de la tarjeta (.sfmv-titulo).
                                  Tambien se activa desde CSS con  --sfmv-modo: tarjetas  en la tabla (p. ej. body[data-ruta="usuarios"] #tablaUsuarios { --sfmv-modo: tarjetas }).
    - table.sfmv-col-fija ........ primera columna fija al desplazar (<= 1024.98). CSS:  --sfmv-modo: fija.
    - .sfmv-fila ................. fila de una sola linea con desplazamiento horizontal (pestanas, chips, filtros).
    - .sfmv-scroll-x ............. envoltorio con desplazamiento horizontal (sf-movil.js lo pone solo cuando una tabla no tiene uno).
    - .sfmv-sin-piso ............. el texto de este elemento NO se sube a 12 px (excepcion; usar solo si hace falta).
   ========================================================================== */


/* ==========================================================================
   A. BASE Y DESBORDE  (<= 1024.98)
   Causa raiz del desborde horizontal: .sf-main es un hijo flex con min-width:auto; como las celdas de las tablas llevan
   white-space:nowrap !important, el minimo del contenido es el ancho de la tabla y .sf-main (y toda la pagina) se ensancha.
   ========================================================================== */
@media screen and (max-width: 1024.98px) {
  :root {
    --sfmv-ancho-menu: min(88vw, 300px);
    --sfmv-borde: 32px;
    --sfmv-barra: 56px;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  html body .sf-app,
  html body .sf-main,
  html body .sf-content {
    min-width: 0;
    max-width: 100%;
  }

  /* El cuerpo ya no deja sangria para la barra lateral (en <= 1024 es un cajon superpuesto). */
  body.has-sidebar,
  body.has-sidebar.sidebar-collapsed {
    padding-left: 0;
  }

  /* Con la barra superior fija, los saltos de enfoque y de ancla no dejan el elemento debajo de ella. */
  html.sfmv-con-barra {
    scroll-padding-top: calc(var(--sfmv-barra) + env(safe-area-inset-top, 0px) + 8px);
  }

  /* CELULAR REAL: en un celular de verdad 100vh es MAS ALTO que lo visible (la barra del navegador tapa el fondo). Los minimos de alto de la pagina pasan a 100dvh
     (el alto visible); donde el navegador no tiene dvh queda el 100vh de siempre (la pagina es un poco mas alta que lo visible, sin cortar nada). */
  html body,
  html body .sf-app,
  html body .sf-main {
    min-height: 100vh;
    min-height: 100dvh;
  }
}


/* ==========================================================================
   B. BARRA LATERAL COMO CAJON  (<= 1024.98)
   Cerrada al cargar, sin importar data-state ni lo guardado en localStorage. Se abre con la hamburguesa (clase .mobile-open,
   que ya pone plantilla/sidebar-ui.js), se superpone con fondo oscuro y se cierra al tocar fuera, con Escape, al navegar y con su boton.
   ========================================================================== */
@media screen and (max-width: 1024.98px) {
  /* CELULAR REAL: el cajon NO lleva alto en vh ni en %: se ancla arriba Y abajo (top:0; bottom:0; height:auto), asi termina donde termina lo visible
     aunque 100vh sea mas alto que la pantalla (la barra del navegador tapa el fondo). max-height con dvh es un tope extra donde el navegador lo conoce. */
  body.has-sidebar .app-sidebar {
    width: var(--sfmv-ancho-menu);
    max-width: var(--sfmv-ancho-menu);
    top: 0;
    bottom: 0;
    height: auto;
    max-height: 100%;
    max-height: 100dvh;
    transform: translateX(-105%);
    visibility: hidden;
    box-shadow: none;
    z-index: 1100;
    transition: transform .25s ease, visibility 0s linear .25s;
  }

  body.has-sidebar .app-sidebar.mobile-open {
    transform: none;
    visibility: visible;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .35);
    transition: transform .25s ease, visibility 0s;
  }

  /* Fondo oscuro con desvanecimiento (antes aparecia de golpe con display). */
  .sf-sidebar-backdrop {
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 1099;
    transition: opacity .2s ease, visibility 0s linear .2s;
  }

  .sf-sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity .2s ease, visibility 0s;
  }

  /* Dentro del cajon: lista con desplazamiento propio y sin arrastrar la pagina. Sin alto propio en vh (sidebar-ui.css le ponia calc(100vh - 56px)):
     ocupa lo que sobra entre la cabecera, el buscador y la cuenta, y se encoge (min-height:0) para que la cuenta siempre quede a la vista. */
  body.has-sidebar .app-sidebar .sf-sidebar__scroll {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* Partes fijas del cajon mas compactas (dejan mas sitio a la lista): sin la ayuda de teclado «/ para buscar rapido» ni la etiqueta «Buscar» (el campo ya lo dice). */
  body.has-sidebar .app-sidebar .sf-search-hint,
  body.has-sidebar .app-sidebar .sf-search-label {
    display: none;
  }

  body.has-sidebar .app-sidebar .sf-sidebar__search {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  /* El boton interno del cajon pasa a ser «cerrar» (X). sf-movil.js intercepta su clic en <= 1024 y cierra el cajon. */
  body.has-sidebar .app-sidebar .sidebar-toggle {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    font-size: 22px;
    line-height: 1;
  }

  body.has-sidebar .app-sidebar .sidebar-toggle svg {
    display: none;
  }

  body.has-sidebar .app-sidebar .sidebar-toggle::before {
    content: "\00d7";
    font-size: 30px;
    line-height: 1;
  }

  /* Tamanos legibles y tocables dentro del cajon (el texto minimo es 12 px). */
  body.has-sidebar .app-sidebar .sf-subtitle,
  body.has-sidebar .app-sidebar .sf-search-label,
  body.has-sidebar .app-sidebar .sf-search-hint,
  body.has-sidebar .app-sidebar .sf-search-hint kbd,
  body.has-sidebar .app-sidebar .sf-group-label,
  body.has-sidebar .app-sidebar .sf-group-badge,
  body.has-sidebar .app-sidebar .sf-section,
  body.has-sidebar .app-sidebar .sf-nav-section-title,
  body.has-sidebar .app-sidebar .sf-user-role {
    font-size: 12px;
  }

  body.has-sidebar .app-sidebar .sf-group-header {
    min-height: 44px;
  }

  body.has-sidebar .app-sidebar .sf-item,
  body.has-sidebar .app-sidebar .sf-nav-item {
    min-height: 44px;
    font-size: .9rem;
  }

  body.has-sidebar .app-sidebar .sf-group-items .sf-item {
    font-size: .9rem;
  }

  body.has-sidebar .app-sidebar .sf-search-input {
    min-height: 44px;
  }

  body.has-sidebar .app-sidebar .sf-search-clear {
    width: 44px;
    height: 44px;
    right: 2px;
    background: transparent;
    font-size: 14px;
  }

  /* Entrada «Mapa de modulos» (la crea sf-movil.js): va debajo de «Map» y abre el mismo Mapa del boton flotante. */
  body.has-sidebar .app-sidebar .sfmv-item-mapa {
    margin-bottom: 4px;
  }

  /* Sin dvh (navegadores viejos): el cajon no lleva ningun alto en vh. Ancla arriba y abajo y su tope es el 100 % de lo visible. */
  @supports not (height: 100dvh) {
    body.has-sidebar .app-sidebar {
      max-height: 100%;
    }
  }
}

/* Pantallas bajas (<= 640 px de alto visible: celulares chicos, o con el teclado abierto): las partes fijas (cabecera, buscador y cuenta, unos 300 px) dejaban
   a la lista 2 o 3 filas. Ahora se desplaza TODO el cajon (la cabecera con la X queda pegada arriba) y la cuenta queda al final de la lista, siempre alcanzable. */
@media screen and (max-width: 1024.98px) and (max-height: 640px) {
  body.has-sidebar .app-sidebar {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  body.has-sidebar .app-sidebar .sf-sidebar__scroll {
    flex: 0 0 auto;
    overflow: visible;
    height: auto;
  }
}

/* La cabecera con la X queda pegada arriba solo si sobra alto (de 501 a 640 px): en celular horizontal (<= 500 px) la cabecera pegada y la cuenta del pie se comian
   todo el alto y el ultimo item de la lista quedaba debajo de la cabecera; ahi la cabecera se desplaza con el resto (se cierra tocando fuera o con Escape). */
@media screen and (max-width: 1024.98px) and (min-height: 501px) and (max-height: 640px) {
  body.has-sidebar .app-sidebar .sf-sidebar__header {
    position: sticky;
    top: 0;
    z-index: 3;
  }
}


/* ==========================================================================
   C. BARRA SUPERIOR Y BOTON ☰  (<= 1024.98)  · FASE C
   sf-movil.js crea <div id="sfmvBarra" class="sfmv-barra"> con el titulo de la pantalla y pone la clase sfmv-con-barra en <html>.
   La barra es fija, de 56 px, en --finca-green-dark; el ☰ (el #sfMobileToggle de siempre) queda a su izquierda. Sin la clase (si el JS no corre)
   queda el ☰ flotante de la Fase B. Los modales (z-index 10000) y el cajon (1100) la cubren; el contenido va por debajo.
   ========================================================================== */
@media screen and (max-width: 1024.98px) {
  html body .sfmv-barra {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 1040;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    height: calc(var(--sfmv-barra) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 16px 0 calc(60px + env(safe-area-inset-left, 0px));
    background: var(--finca-green-dark);
    color: #fff;
    box-shadow: var(--shadow-md);
  }

  html body .sfmv-barra__titulo {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: .01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  html.sfmv-con-barra body.has-sidebar .sf-mobile-toggle {
    top: calc(6px + env(safe-area-inset-top, 0px));
    left: calc(6px + env(safe-area-inset-left, 0px));
    z-index: 1041;
    width: 44px;
    height: 44px;
    background: transparent;
    color: #fff;
    border: 0;
    border-radius: 12px;
    box-shadow: none;
    font-size: 22px;
    -webkit-tap-highlight-color: transparent;
  }

  html.sfmv-con-barra body.has-sidebar .sf-mobile-toggle:active {
    background: rgba(255, 255, 255, .18);
  }

  html.sfmv-con-barra body.has-sidebar .sf-mobile-toggle:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -3px;
  }

  /* Con el cajon abierto la hamburguesa sobra (el cajon tiene su propia X). */
  .app-sidebar.mobile-open ~ .sf-main .sf-mobile-toggle {
    visibility: hidden;
  }

  /* El contenido empieza debajo de la barra. Sin barra (el JS no corrio) queda el espacio de la Fase B. */
  body.has-sidebar .sf-content {
    padding: calc(64px + env(safe-area-inset-top, 0px)) 16px calc(96px + env(safe-area-inset-bottom, 0px));
  }

  html.sfmv-con-barra body.has-sidebar .sf-content {
    padding: calc(var(--sfmv-barra) + env(safe-area-inset-top, 0px) + 16px) 16px calc(96px + env(safe-area-inset-bottom, 0px));
  }
}

@media screen and (min-width: 768px) and (max-width: 1024.98px) {
  body.has-sidebar .sf-content,
  html.sfmv-con-barra body.has-sidebar .sf-content {
    padding-left: 24px;
    padding-right: 24px;
  }
}

/* En celular (sin boton flotante del Mapa) el contenido no necesita el hueco de abajo. */
@media screen and (max-width: 767.98px) {
  html.sfmv-mapa-menu.sfmv-con-barra body.has-sidebar .sf-content {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
}


/* ==========================================================================
   D. BOTON FLOTANTE «MAPA DE MODULOS», SU CAPA Y SU ENTRADA EN EL MENU  (<= 1024.98)
   El boton lleva estilo en linea (position/bottom/right/width/height): por eso las medidas llevan !i.
   Fase C: sf-movil.js agrega la entrada «Mapa de modulos» al menu ☰ y pone la clase sfmv-mapa-menu en <html>; solo entonces el boton flotante se
   oculta en <= 767 (de 768 a 1024 queda, y la entrada tambien existe).
   ========================================================================== */
@media screen and (max-width: 767.98px) {
  html body .sf-mapa-fab {
    width: 44px !important;               /* !i: estilo en linea */
    height: 44px !important;              /* !i */
    right: calc(12px + env(safe-area-inset-right, 0px)) !important;   /* !i */
    bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important; /* !i */
    font-size: 1rem !important;           /* !i */
  }

  html.sfmv-mapa-menu body .sf-mapa-fab {
    display: none !important;             /* !i: el estilo en linea trae display:flex */
  }
}

@media screen and (max-width: 1024.98px) {
  /* Cerrada, la capa del Mapa no cuenta como elemento visible ni recibe foco. */
  .sf-mapa-overlay {
    visibility: hidden;
    transition: opacity .25s ease, visibility 0s linear .25s;
  }

  .sf-mapa-overlay.open {
    visibility: visible;
    transition: opacity .25s ease, visibility 0s;
  }

  .sf-mapa-close {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }

  .sf-mapa-modal-title small,
  .sf-mapa-layer-desc,
  .sf-mapa-layer-num,
  .sf-mapa-layer-name,
  .sf-mapa-legend-title,
  .sf-mapa-legend-item,
  .sf-mn-label,
  .sf-mapa-node-highlight .sf-mn-label {
    font-size: 12px;
  }

  .sf-mn-label {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* CELULAR REAL: la ventana del Mapa medía 90vh (88vh en <= 700): mas alto que lo visible en un celular de verdad. Ahora es un % de su capa (fija, a pantalla
     completa: es lo visible) y, donde el navegador conoce dvh, ese tope tambien. */
  .sf-mapa-modal {
    max-height: calc(100% - 16px);
    max-height: calc(100dvh - 16px);
  }
}

@media screen and (max-width: 767.98px) {
  .sf-mapa-modal {
    max-height: 92%;
    max-height: 92dvh;
  }

  .sf-mapa-node {
    flex: 1 1 96px;
    min-width: 0;
  }

  .sf-mapa-modal-title {
    flex-wrap: wrap;
  }
}

/* Las flechas del mapa se dibujan entre nodos de capas distintas: con los nodos en varias filas se cruzan sobre el texto. */
@media screen and (max-width: 575.98px) {
  .sf-mapa-svg {
    display: none;
  }
}


/* ==========================================================================
   E. PANEL LATERAL («sidePanel»)  (<= 1024.98)
   ========================================================================== */
@media screen and (max-width: 1024.98px) {
  .sf-side-panel:not(.open) {
    visibility: hidden;
  }

  .sf-side-panel-close {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }
}

@media screen and (max-width: 767.98px) {
  html body .sf-side-panel {
    width: 100%;
    max-width: 100%;
  }
}


/* ==========================================================================
   F. CAMPOS DE FORMULARIO  (<= 767.98)
   16 px evita el zoom automatico de iOS al enfocar. !i: .form-control y .sf-form-control-sm ya usan !important.
   ========================================================================== */
@media screen and (max-width: 767.98px) {
  /* La cadena de :not() sube la especificidad para ganar a .sf-form-control-sm / .form-control (!important, 1 clase). */
  html body input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]),
  html body select:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]),
  html body textarea:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]) {
    font-size: 16px !important;           /* !i */
  }

  html body .sf-form-control,
  html body .form-control {
    min-height: 44px;
  }

  html body .sf-form-label,
  html body .sf-label,
  html body .modal label {
    font-size: 13px;
  }

  html body .sf-field-error,
  html body .sf-form-hint,
  html body small[id^="help_"],
  html body small[id^="hint_"] {
    font-size: 12px;
  }

  /* Formularios de UNA columna: las cuadriculas de formulario de plantilla.css (ya a 1 columna en <= 768) y las que traen columnas en linea. */
  html body .sf-form-grid,
  html body .sf-form-grid-3,
  html body .sf-form-grid-4 {
    grid-template-columns: minmax(0, 1fr);
  }

  html body .sf-form-grid > *,
  html body .sf-form-grid-3 > *,
  html body .sf-form-grid-4 > * {
    min-width: 0;
  }
}


/* ==========================================================================
   G. TAMANOS DE TOQUE  (solo pantallas tactiles)
   Todos los toques >= 44 px (regla del usuario para celulares). En PC con raton no se aplica.
   ========================================================================== */
@media screen and (pointer: coarse) {
  html body button,
  html body .sf-btn,
  html body .btn,
  html body a.sf-btn,
  html body input[type="button"],
  html body input[type="submit"],
  html body input[type="reset"],
  html body [role="button"],
  html body [role="tab"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Botones de acciones dentro de tablas y botones pequenos: tambien 44 px. */
  html body table button,
  html body table .sf-btn,
  html body table .btn,
  html body .sf-btn-sm,
  html body .btn-sm {
    min-height: 44px;
    min-width: 44px;
  }

  /* Enlaces dentro de tablas (p. ej. numero de contrato): area tocable de 44 px sin tocar los enlaces de parrafos. */
  html body td a[href],
  html body th a[href] {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  html body .sf-nav-item,
  html body .sf-quick-action-item,
  html body .sf-checkbox,
  html body .sf-radio {
    min-height: 44px;
  }

  html body .sf-checkbox input,
  html body .sf-radio input,
  html body .sf-form-check-input {
    width: 22px;
    height: 22px;
  }

  /* Sin la espera de 300 ms ni el zoom por doble toque en controles. */
  html body button,
  html body a,
  html body input,
  html body select,
  html body label,
  html body [role="button"],
  html body [role="tab"] {
    touch-action: manipulation;
  }
}

/* En pantallas tactiles (sin hover) las tarjetas y botones no «saltan» al tocarlos (el :hover se queda pegado). */
@media screen and (hover: none) and (pointer: coarse) {
  html body .sf-btn:hover,
  html body .sf-stat-card:hover,
  html body .sf-interactive-card:hover,
  html body .sf-user-card-item:hover,
  html body .sf-mapa-node:hover {
    transform: none;
  }
}


/* ==========================================================================
   H. TEXTO MINIMO DE 12 PX  (<= 1024.98)
   Aqui: utilidades y texto con estilo en linea que dejan menos de 12 px. El resto lo mide sf-movil.js y le pone .sfmv-t12.
   Para dejar un texto pequeno a proposito: .sfmv-sin-piso en el elemento (sf-movil.js no lo toca) y una regla con mas especificidad.
   ========================================================================== */
@media screen and (max-width: 1024.98px) {
  html body .sf-text-xs,                 /* !i: .sf-text-xs ya es !important */
  html body .sfmv-t12:not(.sfmv-sin-piso),
  html body [style*="font-size:9px"], html body [style*="font-size: 9px"],
  html body [style*="font-size:10px"], html body [style*="font-size: 10px"],
  html body [style*="font-size:11px"], html body [style*="font-size: 11px"],
  html body [style*="font-size:10.5px"], html body [style*="font-size:11.5px"],
  html body [style*="font-size:.5"], html body [style*="font-size: .5"], html body [style*="font-size:0.5"], html body [style*="font-size: 0.5"],
  html body [style*="font-size:.6"], html body [style*="font-size: .6"], html body [style*="font-size:0.6"], html body [style*="font-size: 0.6"],
  html body [style*="font-size:.7rem"], html body [style*="font-size: .7rem"], html body [style*="font-size:0.7rem"], html body [style*="font-size: 0.7rem"],
  html body [style*="font-size:.7em"], html body [style*="font-size:0.7em"],
  html body [style*="font-size:.72"], html body [style*="font-size:0.72"], html body [style*="font-size:.74"], html body [style*="font-size:0.74"] {
    font-size: 12px !important;           /* !i: estilo en linea */
  }
}


/* ==========================================================================
   I. TABLAS  (<= 1024.98 envoltorio, sombra y columna fija; <= 767.98 TARJETAS)
   ========================================================================== */
@media screen and (max-width: 1024.98px) {
  /* Envoltorio con desplazamiento: sf-movil.js lo pone en el padre de una tabla ancha que no tenia uno. */
  .sfmv-scroll-x {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .sf-table-responsive,
  .sfmv-scroll-x {
    overscroll-behavior-x: contain;
  }

  /* Sombra (desvanecido) en el borde donde hay mas contenido. sf-movil.js pone .sfmv-mas-izq / .sfmv-mas-der. */
  .sfmv-mas-der {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - var(--sfmv-borde)), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - var(--sfmv-borde)), transparent);
  }

  .sfmv-mas-izq {
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - var(--sfmv-borde)), transparent);
    mask-image: linear-gradient(to left, #000 calc(100% - var(--sfmv-borde)), transparent);
  }

  .sfmv-mas-izq.sfmv-mas-der {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--sfmv-borde), #000 calc(100% - var(--sfmv-borde)), transparent);
    mask-image: linear-gradient(to right, transparent, #000 var(--sfmv-borde), #000 calc(100% - var(--sfmv-borde)), transparent);
  }

  /* Primera columna fija (tablas numericas densas). */
  html body table.sfmv-col-fija th:first-child,
  html body table.sfmv-col-fija td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
    box-shadow: 2px 0 4px -2px rgba(0, 0, 0, .25);
  }

  html body table.sfmv-col-fija thead th:first-child {
    background: var(--finca-stone-light);
    z-index: 3;
  }
}

@media screen {
  /* Modo tarjeta: cada fila es una tarjeta con un titulo (la primera celda), pares «ETIQUETA  valor» y las acciones al pie (.sfmv-acciones).
     Las cabeceras quedan solo para lectores de pantalla. Sin tope de ancho: solo actua sobre las tablas .sf-tarjetas, que sf-movil.js pone en celular (<= 767.98)
     y, en tableta y PC, solo en las pantallas de RUTAS_TARJETA. */
  html body table.sf-tarjetas,
  html body table.sf-tarjetas tbody,
  html body table.sf-tarjetas tfoot,
  html body table.sf-tarjetas tr,
  html body table.sf-tarjetas td {
    display: block;
    width: 100% !important;               /* !i: celdas con ancho en linea */
    min-width: 0 !important;              /* !i */
    max-width: 100% !important;           /* !i */
    box-sizing: border-box;
  }

  html body table.sf-tarjetas thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  /* Las tarjetas se apoyan sobre una bandeja gris calida (el envoltorio de la tabla; sf-movil.js le pone .sfmv-lista). */
  html body .sfmv-lista {
    padding: 12px;
    overflow: visible;
    background: var(--finca-stone-light);
    -webkit-mask-image: none;
    mask-image: none;
  }

  html body table.sf-tarjetas tr {
    margin: 0 0 12px;
    padding: 0 0 6px;
    overflow: hidden;
    border: 1px solid var(--finca-stone-light);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-md);
  }

  html body table.sf-tarjetas tr:last-child {
    margin-bottom: 0;
  }

  html body .sf-content table.sf-tarjetas tbody td,
  html body .sf-content table.sf-tarjetas tbody td * {
    white-space: normal !important;       /* !i: plantilla.css fuerza nowrap con !important */
    overflow-wrap: anywhere;
  }

  html body .sf-content table.sf-tarjetas tbody td {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 12px;
    padding: 8px 16px;
    border: 0 !important;                 /* !i: plantilla.css pone border-right !important */
    font-size: 14px;
    line-height: 1.35;
    text-align: right;
  }

  html body table.sf-tarjetas td::before {
    content: attr(data-label);
    flex: 0 0 38%;
    max-width: 38%;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
    text-align: left;
    color: var(--finca-stone);            /* gris calido de la marca (el mismo de las cabeceras de tabla de plantilla.css) */
  }

  html body table.sf-tarjetas td[data-label=""]::before,
  html body table.sf-tarjetas td:not([data-label])::before {
    display: none;
  }

  /* Filas de una sola celda ancha (p. ej. «No hay registros»): centradas. */
  html body .sf-content table.sf-tarjetas tbody td[data-label=""]:not(.sfmv-acciones) {
    justify-content: center;
    text-align: center;
  }

  /* El titulo de la tarjeta: la primera celda con texto. */
  html body .sf-content table.sf-tarjetas tbody td.sfmv-titulo {
    display: block;
    margin: 0 0 4px;
    padding: 12px 16px;
    background: var(--finca-stone-light);
    color: var(--finca-stone-dark);
    font-size: 16px;
    font-weight: 700;
    text-align: left;
  }

  html body table.sf-tarjetas td.sfmv-titulo::before {
    display: none;
  }

  /* Casilla de seleccion: arriba, a la izquierda, sin etiqueta. */
  html body .sf-content table.sf-tarjetas tbody td.sfmv-sel {
    justify-content: flex-start;
    padding: 6px 16px 0;
  }

  html body table.sf-tarjetas td.sfmv-sel::before {
    display: none;
  }

  /* Acciones de la fila: TODAS dentro de la tarjeta, al pie, con botones de 44 px. */
  html body .sf-content table.sf-tarjetas tbody td.sfmv-acciones {
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
    padding: 10px 12px 6px;
    border-top: 1px solid var(--finca-stone-light) !important;   /* !i */
    text-align: right;
  }

  html body table.sf-tarjetas td.sfmv-acciones::before {
    display: none;
  }
}

/* Tarjetas en tableta y PC (>= 768): las tarjetas se acomodan en una rejilla de columnas automaticas de 300 px como minimo y 14 px de separacion
   (celular: una sola columna, como antes). Hover y foco visibles; los botones de cada tarjeta siguen siendo los mismos de la fila. */
@media screen and (min-width: 768px) {
  html body table.sf-tarjetas tbody {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
    gap: 14px;
    align-items: stretch;
  }

  html body table.sf-tarjetas tbody tr {
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 0;
    transition: box-shadow .15s ease, border-color .15s ease;
  }

  /* Fila de una sola celda ancha («No hay registros»): ocupa todo el ancho de la rejilla. */
  html body table.sf-tarjetas tbody tr:has(> td[colspan]) {
    grid-column: 1 / -1;
  }

  /* Las acciones quedan al pie de la tarjeta aunque la tarjeta vecina sea mas alta. */
  html body .sf-content table.sf-tarjetas tbody td.sfmv-acciones {
    margin-top: auto;
  }

  html body table.sf-tarjetas tbody tr:hover {
    border-color: var(--finca-green-light);
    box-shadow: var(--shadow-lg);
  }

  html body table.sf-tarjetas tbody tr:focus-within {
    border-color: var(--finca-green);
    box-shadow: 0 0 0 3px var(--finca-green-light), var(--shadow-md);
  }

  html body table.sf-tarjetas tbody td a:focus-visible,
  html body table.sf-tarjetas tbody td button:focus-visible,
  html body table.sf-tarjetas tbody td input:focus-visible,
  html body table.sf-tarjetas tbody td select:focus-visible,
  html body table.sf-tarjetas tbody td textarea:focus-visible,
  html body table.sf-tarjetas tbody td [tabindex]:focus-visible {
    outline: 2px solid var(--finca-green-dark);
    outline-offset: 2px;
  }
}

@media screen and (min-width: 768px) and (prefers-reduced-motion: reduce) {
  html body table.sf-tarjetas tbody tr {
    transition: none;
  }
}


/* ==========================================================================
   I2. SANEAMIENTO DEL DESBORDE DE LA PAGINA  (<= 1024.98)
   sf-movil.js revisa si la pagina se desplaza de lado y, solo entonces, pone una de estas clases en el contenedor culpable:
    .sfmv-grid-1 ... cuadricula con columnas mas anchas que la pantalla (repeat(auto-fill, minmax(400px, 1fr)) o columnas fijas) -> una columna
    .sfmv-wrap ..... fila flex sin salto de linea -> con salto de linea
    .sfmv-fluid .... elemento con ancho minimo o fijo mayor que la pantalla -> como mucho el ancho de su contenedor
   !i: los estilos en linea de cada pantalla mandan.
   ========================================================================== */
@media screen and (max-width: 1024.98px) {
  html body .sfmv-grid-1 {
    grid-template-columns: minmax(0, 1fr) !important;   /* !i */
  }

  html body .sfmv-grid-1 > * {
    min-width: 0;
  }

  html body .sfmv-wrap {
    flex-wrap: wrap !important;           /* !i */
  }

  html body .sfmv-fluid {
    min-width: 0 !important;              /* !i */
    max-width: 100% !important;           /* !i */
    box-sizing: border-box;
  }

  html body img.sfmv-fluid,
  html body video.sfmv-fluid {
    height: auto;
  }
}


/* ==========================================================================
   J. MODALES Y CAJONES  (estructura <= 1024.98; pantalla completa en <= 767.98 y en celular horizontal; pie con Guardar y Cancelar siempre a la vista)
   Familias que usa la app:
    .modal > .modal-dialog > .modal-content > [form >] cabecera, cuerpo, pie   (smartfinca-core.js y plantilla.css; el <form> envuelve a las 3 partes
                                                                                en la mayoria de los modales, y hay variantes -custom)
    .sf-modal-overlay > .sf-modal > .sf-modal-header / .sf-modal-body / .sf-modal-footer   (kardex, disparador)
   Las medidas llevan !i porque plantilla.css (99vw/99vh !important) y los estilos en linea de cada modal ya usan !important.
   Para llegar a «Guardar» y «Cancelar» el <form> tambien es una columna flex: sin eso el cuerpo crece sin limite y nada se desplaza, o (en tableta)
   el pie tapa los ultimos 20 px del cuerpo.
   ========================================================================== */
@media screen and (max-width: 1024.98px) {
  /* CELULAR REAL: plantilla.css y los modulos dan alto a los modales en vh (99vh, 98vh, min-height:96vh..., y hasta height:98vh !important en linea en Proveedores): en un celular de
     verdad 100vh es mas alto que lo visible y el pie con Guardar quedaba debajo del borde. Ahora el tope es un % del modal (que es fixed; inset:0, o sea lo visible). */
  html body .modal:not(#sfmv) > .modal-dialog {
    display: flex;
    flex-direction: column;
    min-height: 0 !important;             /* !i: min-height:100vh de los modales xl/xxl */
    max-height: calc(100% - 2vh) !important;   /* !i: tambien gana a un height:98vh !important en linea; los margenes del dialogo son de .5vh a 1vh por lado */
  }

  /* :not(#sfmv) sube la especificidad (como un id) para ganar a las reglas con #id y a .modal.sf-modal.sf-modal-xl de plantilla.css (!important). */
  html body .modal:not(#sfmv) .modal-content {
    flex: 0 1 auto;
    min-height: 0 !important;             /* !i */
    max-height: none !important;          /* !i: 99vh / 98vh !important; el tope lo pone el dialogo */
    display: flex !important;             /* !i */
    flex-direction: column !important;    /* !i */
  }

  /* Familia .sf-modal-overlay > .sf-modal (Kardex, Disparador): mismo criterio, con el tope en % de su capa fija. */
  html body .sf-modal-overlay > .sf-modal {
    display: flex !important;             /* !i */
    flex-direction: column !important;    /* !i */
    max-height: calc(100% - 16px) !important;   /* !i: max-height:90vh !important del modulo */
  }

  html body .sf-modal-overlay > .sf-modal > .sf-modal-body {
    flex: 1 1 auto !important;            /* !i */
    min-height: 0 !important;             /* !i */
    max-height: none !important;          /* !i: estilo en linea max-height:80vh */
    overflow-y: auto !important;          /* !i */
    -webkit-overflow-scrolling: touch;
  }

  html body .sf-modal-overlay > .sf-modal > .sf-modal-header,
  html body .sf-modal-overlay > .sf-modal > .sf-modal-footer {
    flex: 0 0 auto !important;            /* !i */
  }

  html body .modal .modal-content > form {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 0;
  }

  html body .modal [class*="modal-header"] {
    flex: 0 0 auto;
  }

  html body .modal:not(#sfmv) [class*="modal-body"] {
    flex: 1 1 auto !important;            /* !i */
    min-height: 0;
    max-height: none !important;          /* !i: plantilla.css calc(99vh - 140px) !important */
    overflow-y: auto !important;          /* !i */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  html body .modal [class*="modal-footer"] {
    flex: 0 0 auto;
  }
}

@media screen and (max-width: 767.98px), screen and (max-width: 1024.98px) and (max-height: 500px) {
  html body .modal {
    padding: 0 !important;                /* !i */
    overflow-y: hidden;
  }

  html body .modal:not(#sfmv) > .modal-dialog {
    width: 100% !important;               /* !i: plantilla.css 99vw / 98vw !important */
    max-width: 100% !important;           /* !i */
    height: 100% !important;              /* !i */
    max-height: 100% !important;          /* !i: tambien gana a un height:98vh !important en linea (el tope pasa de calc(100% - 8px) a 100%) */
    min-height: 0 !important;             /* !i: min-height:100vh de los modales xl/xxl (100vh es mas alto que la pantalla visible en el celular) */
    margin: 0 !important;                 /* !i */
  }

  html body .modal:not(#sfmv) .modal-content {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    max-height: none !important;          /* !i: plantilla.css 99vh !important */
    border-radius: 0 !important;          /* !i */
  }

  html body .modal [class*="modal-header"] {
    padding: 12px 16px;
  }

  /* Cabecera con titulo y una fila de botones al lado (p. ej. Ticket de ingreso): la fila baja a su propia linea en vez de salirse. */
  html body .modal .modal-header {
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  html body .modal .modal-header > div:not([class]) {
    flex-wrap: wrap;
    max-width: 100%;
    gap: 8px;
  }

  html body .modal:not(#sfmv) [class*="modal-body"] {
    padding: 16px;
  }

  html body .modal [class*="modal-footer"] {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    box-shadow: 0 -4px 12px rgba(28, 25, 23, .08);
  }

  html body .modal [class*="modal-footer"] .sf-btn,
  html body .modal [class*="modal-footer"] .btn,
  html body .modal [class*="modal-footer"] button {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
    min-height: 44px;
  }

  html body .modal [class*="modal-header"] .close,
  html body .modal [class*="modal-header"] [class*="close"],
  html body .modal .sf-modal-close {
    min-width: 44px;
    min-height: 44px;
  }

  /* Familia .sf-modal-overlay > .sf-modal (kardex, disparador): pantalla completa. */
  html body .sf-modal-overlay {
    padding: 0 !important;                /* !i */
    align-items: stretch !important;      /* !i */
  }

  html body .sf-modal-overlay > .sf-modal {
    display: flex !important;             /* !i */
    flex-direction: column !important;    /* !i */
    width: 100% !important;               /* !i: estilo en linea max-width:calc(100vw - 40px) */
    max-width: 100% !important;           /* !i */
    height: 100% !important;              /* !i */
    max-height: none !important;          /* !i: max-height:90vh !important */
    border-radius: 0 !important;          /* !i */
    margin: 0 !important;                 /* !i */
  }

  html body .sf-modal-overlay > .sf-modal > .sf-modal-body {
    flex: 1 1 auto !important;            /* !i */
    min-height: 0 !important;             /* !i */
    max-height: none !important;          /* !i: estilo en linea max-height:80vh */
    overflow-y: auto !important;          /* !i */
    -webkit-overflow-scrolling: touch;
    padding: 16px !important;             /* !i */
  }

  html body .sf-modal-overlay > .sf-modal > .sf-modal-header,
  html body .sf-modal-overlay > .sf-modal > .sf-modal-footer {
    flex: 0 0 auto !important;            /* !i */
  }

  html body .sf-modal-overlay > .sf-modal > .sf-modal-footer {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)) !important;   /* !i */
    flex-wrap: wrap !important;           /* !i */
    gap: 8px !important;                  /* !i */
    background: #fff;
    box-shadow: 0 -4px 12px rgba(28, 25, 23, .08);
  }

  html body .sf-modal-overlay > .sf-modal > .sf-modal-footer button,
  html body .sf-modal-overlay > .sf-modal > .sf-modal-footer .sf-btn {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }

  /* Ayudas y avisos flotantes. */
  html body .kx-help-modal {
    width: 94%;
    max-height: 90dvh;
  }

  /* Navegadores sin dvh (WebView y iOS viejos): nada de vh; el tope es un % de lo visible (la capa de la ayuda es fija). */
  @supports not (height: 100dvh) {
    html body .kx-help-modal {
      max-height: 90%;
    }
  }

  html body .sf-alert-box {
    padding: 24px 20px;
  }
}

@media screen and (max-width: 767.98px) {
  /* Cuadriculas de formulario con columnas fijas en linea: una columna dentro de los modales. */
  html body .modal-body [style*="grid-template-columns"]:not([style*="auto-fit"]):not([style*="auto-fill"]):not([style*="1fr;"]),
  html body .sf-modal-body [style*="grid-template-columns"]:not([style*="auto-fit"]):not([style*="auto-fill"]):not([style*="1fr;"]) {
    grid-template-columns: 1fr !important;   /* !i: estilo en linea */
  }

  /* Tres columnas en linea («1fr 1fr 1fr;» con punto y coma): la regla de arriba las salta por el :not([style*="1fr;"]) y los campos quedaban de 50 px
     (Pagos diferidos: Monto / Fecha / Medio de pago). Una columna. */
  html body .modal-body [style*="grid-template-columns:1fr 1fr 1fr"],
  html body .modal-body [style*="grid-template-columns: 1fr 1fr 1fr"],
  html body .sf-modal-body [style*="grid-template-columns:1fr 1fr 1fr"],
  html body .sf-modal-body [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;   /* !i: estilo en linea */
  }

  /* Rejilla de una sola columna sin pista definida (display:grid; gap:...): la pista «auto» crece hasta el contenido mas ancho y empujaba el modal
     fuera de la pantalla (Orden de compra, bloques del contrato de cacao: 9 a 16 px de mas, titulo cortado y sin la x de cerrar). */
  html body .modal-body .sf-contract-form-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Botones del pie con texto largo («Guardar Compra / Recepcion», «Crear Orden de Compra», «Guardar Reconciliacion»): el texto baja a otra linea
     en vez de salirse del boton. */
  html body .modal [class*="modal-footer"] .sf-btn,
  html body .modal [class*="modal-footer"] .btn,
  html body .modal [class*="modal-footer"] button,
  html body .sf-modal-overlay > .sf-modal > .sf-modal-footer button,
  html body .sf-modal-overlay > .sf-modal > .sf-modal-footer .sf-btn {
    white-space: normal;
    line-height: 1.25;
    overflow-wrap: anywhere;
    text-align: center;
  }
}


/* ==========================================================================
   K. PESTANAS, CHIPS Y FILTROS  (<= 767.98: una sola fila con desplazamiento horizontal)
   ========================================================================== */
@media screen and (max-width: 767.98px) {
  html body .sf-tabs {
    flex-direction: row;
    flex-wrap: nowrap !important;         /* !i: plantilla.css ya es !important */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  html body .sf-tab {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  html body .sf-filter-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }

  html body .sf-filter-pill {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  html body .sfmv-fila {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    padding-bottom: 6px;
  }

  html body .sfmv-fila > * {
    flex: 0 0 auto;
  }
}


/* ==========================================================================
   L. ENCABEZADOS, TARJETAS DE INDICADORES Y GRILLAS  (<= 767.98 / <= 479.98)
   El encabezado del modulo pasa a ser compacto: icono pequeno junto al titulo, subtitulo debajo y los botones a todo el ancho.
   ========================================================================== */
@media screen and (max-width: 767.98px) {
  html body .sf-module-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px 16px;
    margin-bottom: 14px;
    border-radius: 16px;
    text-align: left;
  }

  html body .sf-module-header-content {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    text-align: left;
  }

  html body .sf-module-header-icon {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 20px;
  }

  html body .sf-module-header h1 {
    font-size: 20px;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  html body .sf-module-header p {
    margin-top: 2px;
    font-size: 13px;
    line-height: 1.35;
  }

  html body .sf-content {
    overflow-wrap: break-word;            /* codigos, correos y RUC largos se parten en vez de salirse de la tarjeta */
  }

  html body .sf-module-header-actions {
    width: 100%;
    gap: 8px;
  }

  html body .sf-module-header-actions > * {
    flex: 1 1 auto;
  }

  html body .sf-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  html body .sf-toolbar {
    padding: 12px;
  }
}

@media screen and (max-width: 479.98px) {
  html body .sf-stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  html body .sf-content .sf-card-header,
  html body .sf-content .sf-table-header {
    padding: 14px 16px;
  }

  html body .sf-content .sf-card-body {
    padding: 16px;
  }
}


/* ==========================================================================
   M. CELULAR EN HORIZONTAL  (poca altura)
   La barra superior baja a 48 px y los modales, el cajon y el Mapa aprovechan toda la altura.
   ========================================================================== */
@media screen and (max-width: 1024.98px) and (max-height: 500px) and (orientation: landscape) {
  :root {
    --sfmv-barra: 48px;
  }

  body.has-sidebar .sf-content {
    padding-top: calc(60px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  html.sfmv-con-barra body.has-sidebar .sf-content {
    padding-top: calc(var(--sfmv-barra) + env(safe-area-inset-top, 0px) + 12px);
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  html.sfmv-con-barra body.has-sidebar .sf-mobile-toggle {
    top: calc(2px + env(safe-area-inset-top, 0px));
  }

  html body .sfmv-barra__titulo {
    font-size: 17px;
  }

  html body .sf-mapa-fab {
    width: 44px !important;               /* !i */
    height: 44px !important;              /* !i */
    bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;   /* !i */
    right: calc(10px + env(safe-area-inset-right, 0px)) !important;     /* !i */
  }

  body.has-sidebar .app-sidebar .sf-sidebar__header {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  body.has-sidebar .app-sidebar .sf-sidebar__search {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  /* Con tan poca altura la lista interna quedaba de una fila: se desplaza el cajon completo (cabecera, buscador, lista y cuenta). */
  body.has-sidebar .app-sidebar {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  body.has-sidebar .app-sidebar .sf-sidebar__scroll {
    flex: 0 0 auto;
    overflow: visible;
    height: auto;
  }

  html body .modal [class*="modal-header"] {
    padding: 8px 16px;
  }

  html body .modal .modal-title {
    font-size: 16px;
  }

  html body .modal:not(#sfmv) [class*="modal-body"] {
    padding: 12px 16px;
  }

  html body .modal [class*="modal-footer"] {
    padding-top: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    flex-wrap: nowrap;
  }

  html body .sf-modal-overlay > .sf-modal > .sf-modal-header {
    padding-top: 8px !important;          /* !i */
    padding-bottom: 8px !important;       /* !i */
  }

  html body .sf-modal-overlay > .sf-modal > .sf-modal-footer {
    padding-top: 8px !important;          /* !i */
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;   /* !i */
    flex-wrap: nowrap !important;         /* !i */
  }
}


/* ==========================================================================
   N. CELULARES PEQUENOS  (<= 359.98: Galaxy Fold cerrado, iPhone SE de 1.a generacion)
   ========================================================================== */
@media screen and (max-width: 359.98px) {
  body.has-sidebar .sf-content,
  html.sfmv-con-barra body.has-sidebar .sf-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  html body .sfmv-barra {
    padding-right: 12px;
  }

  html body .sfmv-barra__titulo {
    font-size: 17px;
  }

  html body .sf-module-header {
    padding: 14px 12px;
  }

  html body .modal [class*="modal-body"] {
    padding: 12px;
  }

  html body .modal [class*="modal-footer"] .sf-btn,
  html body .modal [class*="modal-footer"] .btn,
  html body .modal [class*="modal-footer"] button {
    flex: 1 1 100%;
  }
}


/* ==========================================================================
   O. IMPRESION  (lo unico fuera de pantalla: oculta lo que crea sf-movil.js; no toca nada de PC, donde esos elementos no existen)
   ========================================================================== */
@media print {
  .sfmv-barra,
  .sfmv-item-mapa {
    display: none !important;
  }
}


/* ==========================================================================
   P. LISTAS EN TABLA EN COMPUTADORA  (>= 992)  · pase CJM3, bloque C2
   Pedido del cliente (11-nov-2026): en computadora todos los registros se ven en tabla, por lineas.
   - Desde 992 px sf-movil.js ya no convierte estas tablas en tarjetas. Por debajo de 992 px todo sigue igual (tarjetas).
   - El desplazamiento horizontal fue el motivo original de las tarjetas: aqui NO vuelve. Las celdas parten el texto en varias
     lineas (plantilla.css fuerza nowrap con !important; por eso estas reglas llevan !important y van con el id de cada tabla).
   - Cabecera fija: si la lista es mas alta que la pantalla, se desplaza dentro de su marco y la cabecera queda arriba.
   - Insignias y botones no se parten; la columna de acciones sigue al final.
   - Ingreso de DEC (22 campos) y Proceso de Embarque (12): los campos afines van de a dos por columna (arriba y abajo, con la
     cabecera en el mismo orden). No se quita ningun campo y el HTML no cambia: es solo posicion (rejilla CSS).
   - Financiamiento y Financiadores NO estan en esta lista: siguen como estaban.
   Tablas: las de css/movil/g1.css a g5.css con --sfmv-modo: tarjetas.
   ========================================================================== */
@media screen and (min-width: 992px) {
  /* marco de la lista: la tabla se ajusta al ancho; si la lista es larga, se desplaza dentro del marco con la cabecera fija */
  html body :is(div, section):has(> :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table)) {
    overflow-x: auto !important;
    overflow-y: auto !important;
    max-height: calc(100vh - 16px);
  }

  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) :is(th, td),
  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) :is(th, td) * {
    white-space: normal !important;
  }

  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) :is(th, td) {
    padding: 7px 6px !important;
    overflow-wrap: break-word;
    word-break: normal;
    line-height: 1.3;
    vertical-align: middle;
  }

  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) tbody td {
    font-size: 13px;
  }

  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    font-size: 11.5px;
    letter-spacing: 0.1px;
    box-shadow: inset 0 -2px 0 #E5E7EB;
  }

  /* lo que no debe partirse: insignias y botones (mas compactos para que quepan en su columna) */
  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) :is(.sf-badge, .badge, .sf-btn, .btn, button, .sf-chip, .sf-status) {
    white-space: nowrap !important;
  }

  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) :is(.sf-badge, .badge) {
    padding: 3px 8px;
    font-size: 11px;
    letter-spacing: 0;
  }

  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) :is(.sf-btn-sm, .btn-sm, .sf-btn-icon) {
    padding: 5px 7px;
    min-width: 0;
  }

  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) td :is(.sf-table-actions, .sf-actions, .btn-group) {
    flex-wrap: wrap;
    gap: 4px;
  }

  /* celdas que el diseno original recortaba con puntos suspensivos: en tabla se muestran completas, en varias lineas */
  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) td :is(.sf-text-truncate, [style*="text-overflow"]),
  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) td[style*="text-overflow"],
  html body :is(#tablaUsuarios, #tablaTrabajadores, #tablaProductos, #tablaUnidades, #tablaAlmacenes, #tablaSocios, #tablaClientes, #tablaContratosReporte, #tablaSalidas, #tablaTraslados, #tablaDecIngresos, #tablaOP, #tablaMuestras, #tablaEmbarques, #tablaReconciliacion, #tablaBancosCuentas, #tablaMovimientosBanco, #tablaCxp, #tablaCxc, body[data-ruta="disparador"] .dis-hist-table) td[style*="max-width"] {
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  /* ---- Rejilla: Ingreso de DEC y Proceso de Embarque (dos lineas por registro) ---- */
  html body :is(#tablaDecIngresos, #tablaEmbarques) {
    display: block;
  }

  html body :is(#tablaDecIngresos, #tablaEmbarques) :is(thead, tbody, tfoot) {
    display: block;
  }

  html body :is(#tablaDecIngresos, #tablaEmbarques) thead {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #F9FAFB;
    box-shadow: inset 0 -2px 0 #E5E7EB;
  }

  html body :is(#tablaDecIngresos, #tablaEmbarques) thead th {
    position: static;
    box-shadow: none;
    border-bottom: 0 !important;
  }

  html body :is(#tablaDecIngresos, #tablaEmbarques) tr {
    display: grid;
    grid-template-rows: auto auto;
    column-gap: 0;
    border-bottom: 1px solid #E5E7EB;
  }

  html body :is(#tablaDecIngresos, #tablaEmbarques) tr > :is(th, td) {
    display: block;
    width: auto !important;
    min-width: 0;
    border-right: 0 !important;
    border-bottom: 0 !important;
  }

  html body :is(#tablaDecIngresos, #tablaEmbarques) tr > td[colspan] {
    grid-column: 1 / -1 !important;
    grid-row: 1 / span 2 !important;
    text-align: center !important;
  }

  html body :is(#tablaDecIngresos, #tablaEmbarques) :is(.sf-badge, .badge) {
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  /* Si la ventana es mas angosta que lo que la rejilla necesita (computadora de 1025 a ~1270 px con el menu abierto, o con el
     zoom del navegador subido), la lista no se encoge mas: su marco se desplaza de lado. Asi nunca se monta un dato sobre otro.
     A 1280 y 1366 px cabe completa, sin barra. */
  html body :is(#tablaDecIngresos, #tablaEmbarques) {
    min-width: 915px !important;
    max-width: none !important;
  }

  /* Ingreso de DEC: 22 campos en 12 columnas */
  html body #tablaDecIngresos {
    font-size: 12px !important;
  }

  html body #tablaDecIngresos tr {
    grid-template-columns: 30px minmax(0, 1.1fr) minmax(0, 1.8fr) minmax(0, 1.25fr) minmax(0, 0.65fr) minmax(0, 0.9fr) minmax(0, 0.8fr) minmax(0, 0.8fr) minmax(0, 0.8fr) minmax(0, 1.1fr) minmax(0, 2.3fr) 48px;
  }

  html body #tablaDecIngresos tr > :is(th, td) {
    padding: 4px 6px !important;
    font-size: 12px;
  }

  html body #tablaDecIngresos thead th {
    font-size: 11px;
    letter-spacing: 0;
  }
  html body #tablaDecIngresos tr > :nth-child(1) { grid-column: 1; grid-row: 1 / span 2; align-self: center; text-align: center !important; }
  html body #tablaDecIngresos tr > :nth-child(3) { grid-column: 2; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: left !important; }
  html body #tablaDecIngresos tr > :nth-child(2) { grid-column: 2; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: left !important; }
  html body #tablaDecIngresos tr > :nth-child(5) { grid-column: 3; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: left !important; }
  html body #tablaDecIngresos tr > :nth-child(4) { grid-column: 3; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: left !important; }
  html body #tablaDecIngresos tr > :nth-child(6) { grid-column: 4; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: left !important; }
  html body #tablaDecIngresos tr > :nth-child(17) { grid-column: 4; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: left !important; }
  html body #tablaDecIngresos tr > :nth-child(7) { grid-column: 5; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(9) { grid-column: 5; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(8) { grid-column: 6; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(10) { grid-column: 6; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(11) { grid-column: 7; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(12) { grid-column: 7; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(13) { grid-column: 8; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(14) { grid-column: 8; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(15) { grid-column: 9; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(21) { grid-column: 9; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(16) { grid-column: 10; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(19) { grid-column: 10; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: right !important; }
  html body #tablaDecIngresos tr > :nth-child(18) { grid-column: 11; grid-row: 1; align-self: end; padding-bottom: 1px !important; text-align: left !important; }
  html body #tablaDecIngresos tr > :nth-child(20) { grid-column: 11; grid-row: 2; align-self: start; padding-top: 1px !important; text-align: left !important; }
  html body #tablaDecIngresos tr > :nth-child(22) { grid-column: 12; grid-row: 1 / span 2; align-self: center; }

  html body #tablaDecIngresos tbody tr > :is(:nth-child(2), :nth-child(4), :nth-child(17), :nth-child(19), :nth-child(20), :nth-child(21)) {
    color: var(--finca-stone, #6B7280);
  }

  /* Proceso de Embarque: 12 campos en 10 columnas (ETD sobre ETA; Estado sobre Doc.) */
  html body #tablaEmbarques tr {
    grid-template-columns: 30px minmax(0, 1.3fr) minmax(0, 1.3fr) minmax(0, 1.1fr) minmax(0, 1.2fr) minmax(0, 1.3fr) 86px 124px 120px 84px;
  }

  html body #tablaEmbarques tr > :is(th, td) {
    padding: 6px 6px !important;
  }
  html body #tablaEmbarques tr > :nth-child(1) { grid-column: 1; grid-row: 1 / span 2; align-self: center; }
  html body #tablaEmbarques tr > :nth-child(2) { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  html body #tablaEmbarques tr > :nth-child(3) { grid-column: 3; grid-row: 1 / span 2; align-self: center; }
  html body #tablaEmbarques tr > :nth-child(4) { grid-column: 4; grid-row: 1 / span 2; align-self: center; }
  html body #tablaEmbarques tr > :nth-child(5) { grid-column: 5; grid-row: 1 / span 2; align-self: center; }
  html body #tablaEmbarques tr > :nth-child(6) { grid-column: 6; grid-row: 1 / span 2; align-self: center; }
  html body #tablaEmbarques tr > :nth-child(7) { grid-column: 7; grid-row: 1; align-self: end; padding-bottom: 1px !important; }
  html body #tablaEmbarques tr > :nth-child(8) { grid-column: 7; grid-row: 2; align-self: start; padding-top: 1px !important; }
  html body #tablaEmbarques tr > :nth-child(9) { grid-column: 8; grid-row: 1 / span 2; align-self: center; }
  html body #tablaEmbarques tr > :nth-child(10) { grid-column: 9; grid-row: 1; align-self: end; padding-bottom: 1px !important; }
  html body #tablaEmbarques tr > :nth-child(11) { grid-column: 9; grid-row: 2; align-self: start; padding-top: 1px !important; }
  html body #tablaEmbarques tr > :nth-child(12) { grid-column: 10; grid-row: 1 / span 2; align-self: center; }

  html body #tablaEmbarques tbody td:nth-child(8) {
    color: var(--finca-stone, #6B7280);
  }
}
