/* ==========================================================================================================================================
   FarmaFlow en el celular (360-430 px). Se carga despues de ff-theme.css. Todo va dentro de media queries: en la compu no cambia nada.
   Reglas: campos de 16 px (iOS no hace zoom), botones de 44 px, una sola columna, tablas como tarjetas, barra de abajo con lo principal.
   ========================================================================================================================================== */
:root { --ff-navmovil-alto: 64px; }

/* La barra de abajo y la hoja «Más» solo existen en celular */
.ff-navmovil, .ff-avatar-movil { display: none; }

/* El aviso de «hay tickets para imprimir» (solo en la compu, ver cola_impresion.js) */
.ff-aviso-impresion { position: fixed; right: 16px; bottom: 16px; z-index: 1060; max-width: 360px; background: #fff; border: 1px solid var(--ff-primario); border-left-width: 5px; border-radius: 12px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.14); }
.ff-aviso-impresion .titulo { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.ff-aviso-impresion .detalle { font-size: 13px; color: var(--ff-texto-3); margin: 2px 0 8px; }
@media print { .ff-aviso-impresion, .ff-navmovil, .ff-avatar-movil, .ff-tip, .ff-camara-fondo { display: none !important; } }

/* Globo de ayuda que se abre con un toque (en el celular no hay «pasar el mouse») */
.ff-tip { position: absolute; z-index: 2200; max-width: min(300px, calc(100vw - 24px)); background: #17201C; color: #fff; font-size: 13.5px; line-height: 1.35; padding: 8px 11px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
[data-ff-tip-tocable] { cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }

/* ---------- cámara (escaneo) ---------- */
.ff-btn-camara { flex: 0 0 auto; }
.ff-camara-fondo { position: fixed; inset: 0; z-index: 2300; background: rgba(8, 12, 10, .94); display: flex; flex-direction: column; color: #fff; }
.ff-camara-cab { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top)); }
.ff-camara-cab .titulo { font-weight: 700; font-size: 16px; }
.ff-camara-cab .btn { min-height: 44px; }
.ff-camara-visor { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.ff-camara-visor video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.ff-camara-marco { position: absolute; left: 10%; right: 10%; top: 30%; height: 34%; border: 3px solid rgba(255,255,255,.85); border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; }
.ff-camara-marco.leido { border-color: #4ADE80; }
.ff-camara-pie { padding: 12px 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); text-align: center; font-size: 15px; min-height: 76px; }
.ff-camara-pie .ultimo { font-weight: 700; }
.ff-camara-pie .sub { font-size: 13px; opacity: .8; }
.ff-camara-aviso { padding: 22px 18px; text-align: center; max-width: 420px; margin: auto; }
.ff-camara-aviso .bi { font-size: 38px; }

/* ---------- ticket en pantalla (venta hecha desde el celular) ---------- */
.ff-ticket-pantalla { font-family: var(--ff-mono); font-size: 13px; line-height: 1.45; background: #fff; border: 1px dashed var(--ff-borde-input); border-radius: 10px; padding: 14px; text-align: left; max-width: 340px; margin: 0 auto 12px; }
.ff-ticket-pantalla .centro { text-align: center; }
.ff-ticket-pantalla hr { border-top: 1px dashed var(--ff-borde-input); opacity: 1; margin: 8px 0; }
.ff-ticket-pantalla .fila { display: flex; justify-content: space-between; gap: 10px; }
.ff-ticket-pantalla .total { font-weight: 700; font-size: 16px; }
.ff-ticket-pantalla .nombre { overflow-wrap: anywhere; }

@media (max-width: 767.98px) {
    html { scroll-padding-bottom: 150px; }
    body { overflow-x: hidden; }
    img, video, canvas, svg { max-width: 100%; }
    pre, code { overflow-wrap: anywhere; white-space: pre-wrap; }

    /* campos de 16 px (iOS no hace zoom al enfocar) y botones de 44 px */
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=hidden]), select, textarea,
    .form-control, .form-control-sm, .form-control-lg, .form-select, .form-select-sm, .form-select-lg { font-size: 16px !important; min-height: 44px; }
    .btn, .btn-sm, .btn-lg { min-height: 44px; }
    .btn-close { min-width: 44px; min-height: 44px; }
    .form-check-input { width: 1.4em; height: 1.4em; }
    .form-check-label { padding-top: 2px; }
    .dropdown-item, .list-group-item-action { min-height: 44px; display: flex; align-items: center; }
    .page-link { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    label, .form-label { font-size: 14px; }

    /* titulos y cabeceras de pagina: los botones bajan en vez de apretarse al costado */
    .ff-cabecera { align-items: stretch; flex-direction: column; gap: 10px; }
    .ff-cabecera > div:last-child:not(:first-child):not(.ff-acciones) { display: flex; flex-wrap: wrap; gap: 8px; }
    .ff-cabecera > div:last-child:not(:first-child):not(.ff-acciones) .btn { flex: 1 1 calc(50% - 8px); }

    /* modales a pantalla casi completa */
    .modal-dialog:not(.modal-dialog-centered) { margin: .5rem; }
    .modal-dialog.modal-lg, .modal-dialog.modal-xl { max-width: none; }
    .modal-body { padding: 14px; }
    .modal-footer > .btn, .modal-footer > a.btn { flex: 1 1 100%; }

    /* tablas como tarjetas: cada fila una tarjeta con sus rotulos (data-label lo pone ff-movil.js desde el encabezado) */
    .tabla-movil thead, .ff-tarjetas thead { display: none; }
    .tabla-movil, .tabla-movil tbody, .ff-tarjetas, .ff-tarjetas tbody { display: block; width: 100%; min-width: 0 !important; }
    .tabla-movil tr, .ff-tarjetas tr { display: block; margin: 0 0 .75rem; padding: .55rem .8rem; background: #fff; border: 1px solid var(--ff-borde); border-radius: 12px; }
    .tabla-movil td, .ff-tarjetas td { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; padding: .3rem 0 !important; border: 0 !important; text-align: right; min-width: 0; overflow-wrap: anywhere; }
    .tabla-movil td::before, .ff-tarjetas td::before { content: attr(data-label); flex: 0 0 34%; font-weight: 600; color: var(--ff-texto-3); text-align: left; font-size: 13px; }
    .tabla-movil td:not([data-label])::before, .ff-tarjetas td:not([data-label])::before, .tabla-movil td[data-label=""]::before, .ff-tarjetas td[data-label=""]::before { content: none; }
    .tabla-movil td[colspan], .ff-tarjetas td[colspan] { display: block; text-align: center; }
    .tabla-movil td[colspan]::before, .ff-tarjetas td[colspan]::before { content: none; }
    .tabla-movil td.acciones-movil, .ff-tarjetas td.acciones-movil { display: block; text-align: left; }
    .tabla-movil td.acciones-movil .btn, .ff-tarjetas td.acciones-movil .btn { width: 100%; margin-top: .35rem; }
    .ff-tarjetas td.ff-celda-principal { display: block; text-align: left; font-weight: 600; }
    .ff-tarjetas td.ff-celda-principal::before { content: none; }
    .table-responsive > .ff-tarjetas, .table-responsive > .tabla-movil { min-width: 0; }
    .ff-tarjetas td .btn, .ff-tarjetas td .btn-group { margin-left: auto; }
    /* una tarjeta no tiene que quedar adentro de una caja que hace scroll: el contenedor deja de cortar */
    .table-responsive:has(> .ff-tarjetas), .table-responsive:has(> .tabla-movil) { overflow: visible; }
    .card > .ff-tarjetas, .card-body > .ff-tarjetas, .card-body > div > .ff-tarjetas { display: block; overflow: visible; }

    /* ---------- barra de abajo ---------- */
    .ff-navmovil { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035; background: #fff; border-top: 1px solid var(--ff-borde); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 10px rgba(0,0,0,.05); }
    .ff-navmovil > a, .ff-navmovil > button { flex: 1 1 0; min-width: 0; min-height: var(--ff-navmovil-alto); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 2px; font-size: 11.5px; font-weight: 600; color: var(--ff-texto-3) !important; background: none; border: 0; text-decoration: none; line-height: 1.1; text-align: center; position: relative; }
    .ff-navmovil .bi { font-size: 22px; line-height: 1; }
    .ff-navmovil .activo { color: var(--ff-primario) !important; }
    .ff-navmovil .activo::before { content: ""; position: absolute; top: 0; left: 24%; right: 24%; height: 3px; border-radius: 0 0 3px 3px; background: var(--ff-primario); }
    .ff-navmovil .ff-insignia { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--ff-error); color: #fff; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; }
    body.ff-con-navmovil, body:has(.ff-navmovil) { padding-bottom: calc(var(--ff-navmovil-alto) + env(safe-area-inset-bottom)); }
    body.ff-teclado .ff-navmovil { display: none; }
    body.ff-teclado.ff-con-navmovil, body.ff-teclado:has(.ff-navmovil) { padding-bottom: 0; }
    /* con la barra de abajo, el menu hamburguesa de arriba sobra: el menu completo es «Más» y el avatar */
    body:has(.ff-navmovil) .ff-topbar .navbar-toggler, body:has(.ff-navmovil) .ff-topbar .navbar-collapse { display: none !important; }
    body:has(.ff-navmovil) .ff-topbar-inner { flex-wrap: nowrap; }
    .ff-avatar-movil { display: inline-flex; align-items: center; justify-content: center; margin-left: auto; min-width: 44px; min-height: 44px; border: 0; background: none; padding: 0; }
    .ff-avatar-movil .ff-iniciales { width: 40px; height: 40px; font-size: 14px; }
    .ff-pie { margin-top: 20px; padding-bottom: 20px; }

    /* hoja «Más» */
    #ff-mas.offcanvas-bottom { height: auto; max-height: 86dvh; border-radius: 18px 18px 0 0; z-index: 1056; }
    #ff-mas .offcanvas-header { padding: 14px 16px 8px; }
    #ff-mas .ff-mas-usuario { display: flex; align-items: center; gap: 12px; min-width: 0; }
    #ff-mas .ff-mas-usuario .ff-iniciales { width: 44px; height: 44px; flex: 0 0 auto; }
    #ff-mas .ff-mas-nombre { font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
    #ff-mas .ff-mas-sub { font-size: 13px; color: var(--ff-texto-3); }
    #ff-mas .offcanvas-body { padding: 4px 12px 14px; overflow-y: auto; }
    #ff-mas .ff-mas-titulo { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ff-texto-3); padding: 12px 6px 4px; }
    #ff-mas .ff-mas-lista { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    #ff-mas .ff-mas-item { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; border: 1px solid var(--ff-borde); border-radius: 12px; background: #fff; color: var(--ff-texto) !important; text-decoration: none; font-weight: 600; font-size: 14.5px; line-height: 1.2; }
    #ff-mas .ff-mas-item .bi { font-size: 19px; color: var(--ff-primario); flex: 0 0 auto; }
    #ff-mas .ff-mas-item.peligro, #ff-mas .ff-mas-item.peligro .bi { color: var(--ff-error) !important; }
    #ff-mas .ff-mas-item:active { background: var(--ff-primario-suave); }
    #ff-mas .ff-mas-modo { display: inline-flex; align-items: center; gap: 6px; }

    /* ---------- venta libre: barra de cobro siempre visible ---------- */
    .vl-barra-cobro { position: fixed; left: 0; right: 0; bottom: calc(var(--ff-navmovil-alto) + env(safe-area-inset-bottom)); z-index: 1034; background: #fff; border-top: 1px solid var(--ff-borde); padding: 8px 12px; box-shadow: 0 -3px 12px rgba(0,0,0,.08); }
    body.ff-teclado .vl-barra-cobro { bottom: 0; }
    .vl-barra-cobro .btn { margin-top: 0 !important; }
    .vl-barra-cobro #vl-boton-motivo { margin-top: 4px !important; font-size: 12.5px; }
    .vl-barra-cobro #vl-boton-motivo:empty { display: none; }
    body:has(.vl-barra-cobro) { padding-bottom: calc(var(--ff-navmovil-alto) + 110px + env(safe-area-inset-bottom)); }
    .vl-barra-cobro .vl-barra-total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-weight: 700; }
    .vl-barra-cobro .vl-barra-total .ff-num { font-size: 22px; color: var(--ff-primario); }
    .ff-cobro-monto { font-size: 32px; }
}
@media (min-width: 768px) { .vl-barra-cobro .vl-barra-total { display: none; } }

/* el cuerpo del ticket en pantalla y la cámara usan toda la pantalla chica */
@media (max-width: 400px) { .ff-ticket-pantalla { font-size: 12px; padding: 10px; } }

/* ---------- botones de cabecera de pagina y filas de detalle de las tarjetas ---------- */
.ff-acciones { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
@media (max-width: 767.98px) {
    .ff-acciones { justify-content: stretch; width: 100%; }
    .ff-acciones > .btn, .ff-acciones > a.btn { flex: 1 1 calc(50% - 8px); }
    .ff-cabecera > h2, .ff-cabecera > .ff-titulo { font-size: 22px; }
    /* la fila que se abre debajo de una tarjeta (lotes de un producto): sin marco propio, el contenido es la tarjeta */
    .ff-tarjetas tr.ff-fila-detalle { padding: 0; border: 0; background: transparent; margin: -.5rem 0 .75rem; }
    .ff-tarjetas tr.ff-fila-detalle > td { display: block; padding: 0 !important; text-align: left; }
    .ff-tarjetas tr.ff-fila-detalle > td::before { content: none; }
    .ff-tarjetas tr.ff-fila-detalle .collapse.show > div, .ff-tarjetas tr.ff-fila-detalle .collapsing > div { border: 1px solid var(--ff-borde); border-radius: 12px; background: #fff; }
    .ff-fila-detalle .list-group-item { flex-wrap: wrap; gap: 8px; }
    .ff-fila-detalle .list-group-item > div { min-width: 0; }
    .ff-tarjetas td.acciones-movil .btn { width: 100%; }
}
@media (max-width: 767.98px) { .ff-tarjetas td.acciones-movil::before, .tabla-movil td.acciones-movil::before { content: none; } }
@media (max-width: 575.98px) {
    /* «Abrir caja»: el monto arriba y el botón abajo, a lo ancho */
    .input-group:has(#monto-inicial-caja) { flex-wrap: wrap; }
    .input-group:has(#monto-inicial-caja) > .form-control { flex: 1 1 0; min-width: 0; }
    .input-group:has(#monto-inicial-caja) > .btn { flex: 1 1 100%; margin: 10px 0 0 !important; border-radius: var(--ff-radio-campo) !important; }
    #caja-abierta h4 { font-size: 20px; }
}
@media (max-width: 767.98px) {
    .tabla-movil td.ff-celda-principal { display: block; text-align: left; }
    .tabla-movil td.ff-celda-principal::before { content: none; }
    .tabla-movil td:not([data-label]), .ff-tarjetas td:not([data-label]) { justify-content: flex-end; }
    .tabla-movil td .ff-cerrar, .ff-tarjetas td .ff-cerrar { min-width: 44px; min-height: 44px; }
}
