/**
 * FactuFlexa — mejoras móvil progresivas.
 * Solo aplica en pantallas <= 768px; escritorio (>= 992px) no se altera.
 */

@media (max-width: 768px) {
  /* Evitar desbordes horizontales en páginas sueltas e iframe */
  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    overflow-x: hidden;
  }

  img,
  video,
  canvas,
  svg {
    max-width: 100%;
    height: auto;
  }

  /* Controles táctiles (mín. ~44px recomendado) */
  .btn:not(.btn-link):not(.btn-close),
  a.btn:not(.btn-link),
  button:not(.btn-close):not(.btn-link),
  input[type="submit"],
  input[type="button"],
  .form-control,
  .form-select,
  select.form-select {
    min-height: 44px;
  }

  .btn-sm:not(.btn-link) {
    min-height: 44px;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
  }

  .btn-group .btn {
    min-width: 44px;
  }

  /* Tablas: scroll horizontal cuando no hay layout de tarjetas */
  .table-responsive,
  .ff-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .table-responsive > .table {
    margin-bottom: 0;
  }

  /* Opt-in: filas como tarjetas (añadir clase ff-table-mobile-cards al table) */
  table.ff-table-mobile-cards thead {
    display: none;
  }

  table.ff-table-mobile-cards tbody tr {
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    margin: 0 0 10px;
    padding: 8px 10px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  }

  table.ff-table-mobile-cards tbody td {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    border: 0 !important;
    padding: 5px 0 !important;
    width: 100% !important;
  }

  table.ff-table-mobile-cards tbody td::before {
    content: attr(data-label);
    font-weight: 650;
    color: #64748b;
    font-size: 0.78rem;
    text-transform: uppercase;
    flex: 0 0 42%;
    max-width: 48%;
  }

  table.ff-table-mobile-cards tbody td.text-end {
    justify-content: flex-end;
  }

  table.ff-table-mobile-cards tbody td.text-end::before {
    display: none;
  }

  /* Shell principal (index.php logueado) */
  body.ff-app-shell header .hamburger,
  body.ff-app-shell header .nav-desktop-toggle {
    min-width: 44px;
    min-height: 44px;
  }

  body.ff-app-shell main {
    padding: 0.5rem;
  }

  body.ff-app-shell iframe[name="principal"] {
    width: 100%;
    max-width: 100%;
    height: calc(100dvh - var(--header-h, 3.25rem) - 0.75rem);
    min-height: 220px;
    border-radius: 0.35rem;
  }

  /* Login sistema */
  body.ff-login-page {
    padding: 1rem;
    align-items: flex-start;
    padding-top: max(1rem, env(safe-area-inset-top, 0px));
  }

  body.ff-login-page .login-card .card-body {
    padding: 1.5rem 1.15rem;
  }

  body.ff-login-page .login-title {
    font-size: 1.35rem;
  }

  /* Inicio personalizado */
  body.ff-home-inicio .hi-wrap {
    padding: 1rem 0.75rem 1.5rem;
  }

  body.ff-home-inicio .hi-shortcut {
    min-height: 92px;
  }

  body.ff-home-inicio .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  body.ff-home-inicio .nav-tabs .nav-link {
    white-space: nowrap;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Gestión factura (complementa facturas_mobile.css) */
  body.gestion-factura-page {
    padding: 8px !important;
  }

  body.gestion-factura-page .acciones .btn,
  body.gestion-factura-page .acciones button,
  body.gestion-factura-page .acciones a.btn {
    flex: 1 1 auto;
    min-width: min(100%, 140px);
  }

  body.gestion-factura-page .factu-page-head {
    margin-bottom: 2px;
  }

  body.gestion-factura-page .factu-page-title .factu-ui-modo-badge {
    max-width: min(10rem, 38vw);
  }

  /* Salón — agenda */
  body.ff-salon-agenda .agenda-toolbar .btn,
  body.ff-salon-agenda .agenda-toolbar .form-control,
  body.ff-salon-agenda .agenda-toolbar .form-select {
    min-height: 44px;
  }

  body.ff-salon-agenda .table-responsive {
    max-height: calc(100dvh - 220px);
  }

  body.ff-salon-agenda .col-estilista {
    min-width: 168px;
    max-width: 240px;
  }

  body.ff-salon-agenda .agenda-buscar-est-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #f8fafc;
    padding-bottom: 0.35rem;
  }

  body.ff-salon-agenda .agenda-buscar-est-wrap .form-control {
    min-height: 44px;
  }

  body.ff-salon-agenda .agenda-est-chips {
    padding-bottom: 0.35rem;
  }

  body.ff-salon-agenda .agenda-est-chip {
    min-height: 36px;
    font-size: 0.85rem;
    max-width: 9.5rem;
  }

  body.ff-salon-agenda .agenda-est-chips-label {
    width: auto;
    min-width: 3.5rem;
  }

  /* Salón — cita */
  body.cita-page .cita-page-shell {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }

  body.cita-page .btn,
  body.cita-page .form-control,
  body.cita-page .form-select {
    min-height: 44px;
  }

  body.cita-page .cita-prod-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }

  /* Restaurante — mesas */
  body.ff-rest-mesas .rest-plano {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    grid-template-columns: unset !important;
    padding: 10px;
  }

  body.ff-rest-mesas .rest-plano > div:empty {
    display: none;
  }

  body.ff-rest-mesas .rest-plano > a.rest-mesa-card {
    flex: 1 1 calc(50% - 6px);
    min-width: 132px;
    max-width: 100%;
    min-height: 100px;
  }

  body.ff-rest-mesas .d-flex.flex-wrap.justify-content-between .btn-group {
    width: 100%;
    flex-wrap: wrap;
  }

  body.ff-rest-mesas .d-flex.flex-wrap.justify-content-between .btn-group .btn {
    flex: 1 1 auto;
  }
}

/* Escritorio: sin reglas aquí — el layout base permanece intacto desde 992px */
