/* Administración desde el móvil (≤ 767 px). Pieza común a todas las pantallas de admin.

   1) Tablas → tarjetas. Una tabla con la clase «dsg-tabla-movil» deja de ser una tabla en pantallas pequeñas: cada fila pasa a ser una tarjeta y cada celda una línea
      «ETIQUETA ........ valor». Las etiquetas salen de la cabecera de la propia tabla (static/js/dsg-tablas-movil.js las copia a cada celda), así que no hay que
      escribirlas a mano ni se desincronizan. La primera celda (el nombre de la persona, el producto…) hace de título de la tarjeta, sin etiqueta.
      Sin scroll lateral: todo se ve y todos los botones de acción quedan a mano.
   2) Cabeceras de página y barras de botones que se ajustan al ancho.
   3) Objetivos táctiles de al menos 40 px en las acciones de las tarjetas. */

/* El contenido de cada celda va en un span; fuera del móvil no existe a efectos de maquetación */
.dsg-celda-valor { display: contents; }

/* Las tablas pasan a tarjetas hasta 991 px (móvil, móvil en horizontal y tablet vertical): ahí caben a lo sumo 5-6 columnas y las demás exigirían scroll lateral */
@media (max-width: 991.98px) {
  /* ── 1) Tablas → tarjetas ── */
  .dsg-celda-valor { display: block; flex: 1 1 0; min-width: 0; text-align: right; overflow-wrap: anywhere; }
  .dsg-celda-valor > * + * { margin-top: .15rem; }
  .dsg-celda-valor > * { max-width: none !important; justify-content: flex-end; }      /* bloques con ancho fijo pensado para la columna de escritorio */
  .dsg-tabla-movil > tbody > tr > td { max-width: none !important; }
  .table-responsive:has(> table.dsg-tabla-movil) { overflow: visible; }
  table.dsg-tabla-movil, .dsg-tabla-movil > tbody { display: block; width: 100%; }
  .dsg-tabla-movil > thead { display: block; position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }   /* se queda para lectores de pantalla */
  .dsg-tabla-movil > tbody > tr:first-child { margin-top: .75rem; }
  .dsg-tabla-movil > tbody > tr {
    display: block; margin: 0 0 .75rem; padding: .3rem .95rem;
    background: var(--dsg-surface); border: 1px solid var(--dsg-border); border-radius: 12px;
  }
  .dsg-tabla-movil.table-hover > tbody > tr:hover { background: var(--dsg-surface); }
  .dsg-tabla-movil > tbody > tr > td {
    display: flex; align-items: center; justify-content: space-between; gap: .85rem;
    width: auto; padding: .55rem 0 !important; border: 0 !important; background: transparent !important; box-shadow: none !important;
    text-align: right !important; min-height: 2.6rem;
  }
  .dsg-tabla-movil > tbody > tr > td + td { border-top: 1px solid rgba(148, 163, 184, .14) !important; }
  .dsg-tabla-movil > tbody > tr > td::before {
    content: attr(data-label); flex: 0 0 34%; max-width: 40%; text-align: left;
    font-size: .7rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--dsg-muted); line-height: 1.25;
  }
  /* Primera celda = título de la tarjeta; celdas sin etiqueta (casillas, botón de desplegar, acciones sueltas) ocupan la línea entera */
  .dsg-tabla-movil > tbody > tr > td:not([data-label])::before,
  .dsg-tabla-movil > tbody > tr > td[data-label=""]::before { display: none; }
  .dsg-tabla-movil > tbody > tr > td:not([data-label]),
  .dsg-tabla-movil > tbody > tr > td[data-label=""] { justify-content: flex-start; text-align: left !important; }
  .dsg-tabla-movil > tbody > tr > td:not([data-label]):not([data-acciones]):not([data-extra]) { flex-wrap: wrap; row-gap: .1rem; }
  .dsg-tabla-movil > tbody > tr > td:first-child { padding-top: .7rem !important; }
  /* Casilla de selección o botón de desplegar: en la esquina de la tarjeta, no en una línea propia */
  .dsg-tabla-movil > tbody > tr { position: relative; }
  .dsg-tabla-movil > tbody > tr > td[data-extra] { position: absolute; top: .55rem; right: .75rem; padding: 0 !important; min-height: 0; z-index: 1; width: auto; }
  .dsg-tabla-movil > tbody > tr > td[data-extra]::before { display: none; }
  .dsg-tabla-movil > tbody > tr:has(> td[data-extra]) > td:not([data-extra]):not([data-label]):not([data-acciones]):not([colspan]) { padding-right: 3.2rem !important; }
  /* Fila de «no hay resultados» y celdas que ocupan toda la tabla (colspan): sin formato de línea */
  .dsg-tabla-movil > tbody > tr > td[colspan] { display: block; text-align: center !important; justify-content: center; }
  .dsg-tabla-movil > tbody > tr > td[colspan]::before { display: none; }
  /* Acciones: botones en fila, con espacio y que no se salgan */
  .dsg-tabla-movil td .d-flex { flex-wrap: wrap; justify-content: flex-end; gap: .4rem; }
  .dsg-tabla-movil td .action-btn, .dsg-tabla-movil td .btn.btn-sm { min-width: 40px; min-height: 40px; }
  .dsg-tabla-movil td [style*="width:32px"] { width: 40px !important; height: 40px !important; }
  .dsg-tabla-movil td .badge-rol, .dsg-tabla-movil td .pill { white-space: normal; }
  /* Columna de acciones: una sola fila con los botones repartidos a todo el ancho (no se parten en dos líneas) */
  .dsg-tabla-movil > tbody > tr > td[data-acciones] { display: block; padding-top: .7rem !important; padding-bottom: .65rem !important; }
  .dsg-tabla-movil td[data-acciones]::before { display: none; }
  .dsg-tabla-movil td[data-acciones] > .d-flex, .dsg-tabla-movil td[data-acciones] > div { display: flex; flex-wrap: nowrap; width: 100%; justify-content: stretch; gap: .45rem; }
  .dsg-tabla-movil td[data-acciones] .d-flex > *, .dsg-tabla-movil td[data-acciones] > div > * { flex: 1 1 0; min-width: 0; }
  .dsg-tabla-movil td[data-acciones] form { display: flex; }
  .dsg-tabla-movil td[data-acciones] form > * { flex: 1 1 auto; }
  .dsg-tabla-movil td[data-acciones] .action-btn, .dsg-tabla-movil td[data-acciones] .btn, .dsg-tabla-movil td[data-acciones] [style*="width:32px"] {
    width: 100% !important; height: 44px !important; min-width: 0; }
  /* Un único botón de icono (p. ej. «editar permisos»): se rotula con su título para que se entienda */
  .dsg-tabla-movil td[data-acciones] .action-btn:only-child { gap: .5rem; }
  .dsg-tabla-movil td[data-acciones] .action-btn:only-child[title]::after { content: attr(title); font-size: .85rem; font-weight: 600; }
  /* Contenido que antes se centraba en la columna */
  .dsg-tabla-movil td .text-center, .dsg-tabla-movil td .text-start { text-align: right !important; }
  .dsg-tabla-movil > tbody > tr > td:not([data-label]) .text-center { text-align: left !important; }
  .dsg-tabla-movil td [style*="white-space:nowrap"] { white-space: normal !important; }

}

/* Tablet vertical y móvil grande: las tarjetas en dos columnas (las tablas con filas que se despliegan, como el historial de permisos, siguen en una) */
@media (min-width: 576px) and (max-width: 991.98px) {
  .dsg-tabla-movil:not(.tabla-1col) > tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; padding-top: .75rem; align-items: start; }
  .dsg-tabla-movil:not(.tabla-1col) > tbody > tr, .dsg-tabla-movil:not(.tabla-1col) > tbody > tr:first-child { margin: 0; }
  .dsg-tabla-movil:not(.tabla-1col) > tbody > tr:has(> td[colspan]) { grid-column: 1 / -1; }
}

@media (max-width: 767.98px) {
  /* ── 2) Cabeceras y barras de botones ── */
  .page-header { flex-wrap: wrap; gap: .6rem .75rem; }
  .page-header h1, .page-header .h1 { font-size: 1.45rem; word-break: break-word; }
  .page-header > div { min-width: 0; }
  .page-header .d-flex, .map-header, .legend, .dsg-acciones { flex-wrap: wrap; }              /* filas de botones y leyendas: bajan de línea en vez de ensanchar la página */
  .page-header .d-flex.flex-wrap, .page-header .acciones, .dsg-acciones { width: 100%; }
  .map-header { gap: .6rem; }
  .map-header h5, .map-header .h5 { flex: 1 1 100%; }
  .page-header .btn, .page-header .dsg-actualizar { flex: 0 1 auto; }
  .list-header, .dsg-card .d-flex.flex-wrap { row-gap: .5rem; }
  .list-header .d-flex.flex-wrap > .btn, .list-header .d-flex.flex-wrap > a.btn { flex: 1 1 auto; }
  .btn, .dsg-btn-filter, .dsg-btn-order, .dsg-btn-clear { min-height: 40px; }
  .dsg-filter-bar { padding: .85rem 1rem; }
  .dsg-filter-bar > * { flex: 1 1 100%; min-width: 0; }
  .dsg-filter-bar .dsg-btn-filter, .dsg-filter-bar .dsg-btn-order { flex: 1 1 calc(50% - 5px); justify-content: center; }
  /* Nada de la página puede ser más ancho que la pantalla */
  main img, main video, main canvas { max-width: 100%; }
  /* Objetivos táctiles: botones pequeños, enlaces de stands y casillas de selección con zona de toque suficiente */
  main .btn-sm { min-height: 40px; min-width: 40px; }
  a.hist-stand { min-height: 36px; display: inline-flex; align-items: center; padding-inline: .6rem; }
  .dsg-chk { padding: .45rem; margin: -.45rem; }
  .dsg-chk-box { width: 22px; height: 22px; }
  /* Tarjetas de producto: precio arriba y los botones debajo, a todo el ancho */
  .producto-footer { flex-wrap: wrap; gap: .5rem; }
  .producto-footer > span { flex: 1 1 100%; }
  .producto-footer > div { display: flex; flex: 1 1 100%; gap: .4rem; }
  .producto-footer > div > * { flex: 1 1 0; }
  /* Plano de stands (clase dsg-mapa-movil): recuadro desplazable con zoom (static/js/dsg-mapa-movil.js) */
  .map-wrapper.dsg-mapa-movil { overflow: auto; max-height: 68vh; -webkit-overflow-scrolling: touch; border-radius: 10px; touch-action: pan-x pan-y pinch-zoom; }
  .map-wrapper.dsg-mapa-movil svg { max-width: none; height: auto; }
  .mapa-zoom { display: flex; gap: .4rem; justify-content: flex-end; margin: 0 0 .5rem; }
  .mapa-zoom[hidden] { display: none; }
  .mapa-zoom button { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--dsg-border); background: var(--dsg-surface2); color: var(--dsg-text); font-size: 1.1rem; display: inline-flex; align-items: center; justify-content: center; }
  .mapa-zoom button:active { background: rgba(249, 115, 22, .2); color: var(--dsg-orange); }
  footer a { display: inline-block; padding: .45rem 0; }
  /* Pestañas «Confirmados / Pendientes»: ocupan el ancho disponible en vez de empujarlo */
  .dsg-tabs-estado { max-width: 100%; }
  .dsg-tabs-track { display: flex; width: 100%; }
  .dsg-tab { flex: 1 1 0; min-width: 0; justify-content: center; padding-inline: .6rem; }
  main select, main .form-select, .dsg-select { max-width: 100%; min-width: 0 !important; }
  .dsg-select { width: 100%; }
  .subir > *, .subir .zona-archivo { min-width: 0; max-width: 100%; flex: 1 1 100% !important; }      /* pantallas de «sube un archivo» (acreditaciones, importaciones) */
  /* Barras flotantes de selección (productos, proveedores): caben en la pantalla y bajan de línea */
  .barra-seleccion-flotante.barra-seleccion-flotante, .barra-prov-flotante.barra-prov-flotante {
    min-width: 0 !important; width: calc(100vw - 1.5rem); max-width: 440px; flex-wrap: wrap; gap: .5rem .75rem; bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); }
  .modal-dialog { margin: .5rem; }
  /* Los modales se desplazan enteros (comportamiento de Bootstrap): no se limita su alto, para que el botón de guardar siempre sea alcanzable */
}

/* Dispositivos táctiles (también tablets): los botones de icono de las listas, algo más grandes */
@media (hover: none) and (pointer: coarse) {
  .action-btn { min-width: 40px; min-height: 40px; }
}

@media (min-width: 768px) { .mapa-zoom { display: none; } }

@media (max-width: 991.98px) {
  .dsg-card .d-flex.justify-content-between, .dsg-card .d-flex.justify-content-between.align-items-center { flex-wrap: wrap; gap: .5rem .75rem; }
}


/* ── Campos de fecha y paginación en el móvil (≤ 767 px) ──────────────────────────────────────────────────────────────────────────────
   · El <input type="date"> del iPhone tiene un ancho propio y se sale de su contenedor por la derecha: se le quita la apariencia nativa y se le obliga a respetar el ancho.
     El alto mínimo evita que un campo de fecha vacío se quede en una línea en iOS.
   · La paginación numerada no cabe ni se maneja bien con el dedo: se queda «‹ Página 2 de 5 ›», con botones grandes. */
@media (max-width: 767.98px) {
  input[type="date"], input[type="datetime-local"], input[type="month"], input[type="time"] {
    -webkit-appearance: none; appearance: none; min-width: 0; max-width: 100%; box-sizing: border-box; min-height: 2.6rem;
  }
  input[type="date"]::-webkit-date-and-time-value, input[type="datetime-local"]::-webkit-date-and-time-value { text-align: left; min-height: 1.4em; }
}
@media (max-width: 575.98px) {
  .pg-barra { flex-direction: column; align-items: stretch !important; text-align: center; }
  .pg-barra nav { width: 100%; }
  .pg-barra .pagination { display: flex; flex-wrap: nowrap; justify-content: center; gap: .5rem; }
  .pg-barra .pg-num:not(.active) { display: none; }
  .pg-barra .pg-ant, .pg-barra .pg-sig { flex: 1 1 0; }
  .pg-barra .page-link { min-height: 46px; display: flex; align-items: center; justify-content: center; border-radius: 10px !important; }
  .pg-barra .pg-num.active .page-link { min-width: 56px; }
}
