/* Panel IMBIO en celular: navegación inferior, encabezado compacto y ventanas a pantalla completa. */
#mov-nav, #mov-hoja, #mov-velo { display: none; }
.mov-corto { display: none; }
/* Tarjetas de color oscuro: la etiqueta hereda el texto blanco (también en computadora) */
.stat[style*="color:#fff"] .lbl { color: rgba(255,255,255,.92); }

@media (max-width: 820px) {
  html { font-size: 16px; }
  /* clip (no hidden) para que el body no sea un contenedor de desplazamiento: así el encabezado se queda fijo */
  html, body { overflow-x: clip; }
  body { -webkit-tap-highlight-color: transparent; }

  /* Encabezado */
  #app > nav {
    position: sticky; top: 0; z-index: 1500;
    min-height: 54px; padding: calc(env(safe-area-inset-top) + 6px) 12px 6px;
    flex-wrap: nowrap;
  }
  #app > nav .brand { font-size: 1.02rem; gap: 8px; flex-wrap: nowrap; white-space: nowrap; overflow: hidden; }
  #app > nav .brand span { font-size: 1.5rem; }
  #app > nav .brand .mov-largo { display: none; }
  #app > nav .brand .mov-corto { display: inline; font-weight: 800; }
  #app > nav .user-info #nav-nombre, #app > nav .user-info .logout { display: none; }
  #app > nav .user-info { gap: 8px; flex-wrap: nowrap; }
  #app > nav #nav-rol { font-size: .72rem; padding: 2px 8px; }

  /* Contenido: la barra lateral se sustituye por la barra inferior */
  .app-layout { display: block; min-height: 0; }
  #sidebar { display: none; }
  main {
    max-height: none; overflow: visible;
    padding: 14px 12px calc(84px + env(safe-area-inset-bottom));
  }
  main h2 { font-size: 1.28rem; line-height: 1.25; }
  main h3 { font-size: 1.08rem; }

  /* Controles cómodos para el dedo; 16px evita el zoom de iOS al escribir */
  input, select, textarea { font-size: 16px; min-height: 44px; }
  textarea { min-height: 88px; }
  input[type=checkbox], input[type=radio] { min-height: 0; width: 20px; height: 20px; }
  .btn { min-height: 42px; padding: 10px 16px; }
  .btn-sm { min-height: 36px; padding: 6px 12px; }
  .filters, .map-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .filters > *, .map-filters > * { width: 100% !important; min-width: 0 !important; }
  .filters input[type=text], .filters input[type=search] { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .detail-grid, .domicilio-grid { grid-template-columns: 1fr; }

  /* Tarjetas de resumen */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat { padding: 14px 10px; border-radius: 14px; }
  .stat .num { font-size: 1.6rem; }
  .stat .lbl { font-size: .86rem; overflow-wrap: anywhere; hyphens: auto; }

  /* Rejillas fijas de la página que no caben en el celular */
  #page-dashboard > div[style*="grid-template-columns:1fr 1fr"],
  main div[style*="grid-template-columns:1fr 1fr 1fr"],
  #ver-checklist-wrap, #ver-det-checklist { grid-template-columns: 1fr !important; }
  #page-dashboard > div[style*="display:grid"] > div { min-width: 0; }
  #app > nav #nav-rol { background: #fff !important; color: var(--verde-oscuro) !important; }

  /* Mapas */
  #map-reportes { height: 62vh; }
  #page-mapa.active { height: calc(100dvh - 54px - env(safe-area-inset-top) - 28px - 84px - env(safe-area-inset-bottom)); min-height: 420px; }
  #page-mapa .mapa-barra h2 { font-size: 1.12rem; }
  #page-mapa .map-filters { width: 100%; }
  #page-mapa .mapa-capas { left: 52px; right: 8px; top: 8px; max-width: none; }
  #page-mapa .mapa-leyenda { left: 8px; right: 8px; bottom: 18px; font-size: .8rem; padding: 6px 8px; }
  #page-mapa .mapa-leyenda-items { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  #page-mapa .mapa-leyenda-items button { flex: 0 0 auto; }
  #page-mapa .mapa-estado { display: none; }
  #map-picker { height: 46vh; }
  #est-mapa { height: 58vh !important; }
  .map-layer-ctrl { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .map-layer-ctrl::-webkit-scrollbar { display: none; }
  .map-layer-ctrl button { flex: 0 0 auto; padding: 8px 12px; }

  /* Tablas convertidas en tarjetas (las etiquetas las pone panel-movil.js) */
  table.mov-tarjetas, table.mov-tarjetas tbody, table.mov-tarjetas tr, table.mov-tarjetas td { display: block; width: 100%; }
  table.mov-tarjetas { min-width: 0 !important; }
  table.mov-tarjetas thead { display: none; }
  table.mov-tarjetas tr.fila-reporte:active { background: #E8F1FB; }
  table.mov-tarjetas tr {
    background: #fff; border: 1px solid var(--borde); border-radius: 14px;
    padding: 10px 12px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
  }
  table.mov-tarjetas tr:hover td { background: transparent; }
  table.mov-tarjetas td {
    border: none; padding: 4px 0; display: flex; gap: 10px; align-items: baseline;
    justify-content: space-between; text-align: right !important; white-space: normal !important; max-width: none !important;
  }
  table.mov-tarjetas td::before {
    content: attr(data-label); flex: 0 0 38%; text-align: left;
    font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  }
  table.mov-tarjetas td:not([data-label])::before, table.mov-tarjetas td[data-label=""]::before { display: none; }
  table.mov-tarjetas td:not([data-label]), table.mov-tarjetas td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; }
  table.mov-tarjetas td[colspan] { justify-content: center; text-align: center !important; }
  table.mov-tarjetas td:last-child { padding-top: 8px; gap: 6px; flex-wrap: wrap; }
  .table-wrap { overflow-x: visible; }

  /* Ventanas emergentes: hoja a pantalla completa */
  .modal-bg { align-items: flex-end !important; padding: 0 !important; }
  .modal-bg > .modal, .modal-bg > div:first-child {
    width: 100vw !important; max-width: 100vw !important; margin: 0 !important;
    max-height: 94dvh !important; overflow-y: auto !important;
    border-radius: 18px 18px 0 0 !important;
    padding: 18px 14px calc(18px + env(safe-area-inset-bottom)) !important;
  }
  .modal-footer { position: sticky; bottom: -18px; background: #fff; padding: 10px 0; margin-top: 12px; flex-wrap: wrap; }
  .modal-footer .btn { flex: 1 1 auto; justify-content: center; }

  /* Barra inferior */
  body.mov-sesion #mov-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1600;
    background: #fff; border-top: 1px solid var(--borde);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(0,0,0,.08);
  }
  #mov-nav button {
    background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 0; font: 600 .7rem/1.1 inherit; color: #64748b; cursor: pointer; position: relative; border-radius: 12px;
  }
  #mov-nav button .ic { font-size: 1.35rem; line-height: 1; filter: grayscale(.6); opacity: .8; }
  #mov-nav button.activo { color: var(--verde); }
  #mov-nav button.activo .ic { filter: none; opacity: 1; }
  #mov-nav button.activo::before {
    content: ''; position: absolute; top: -4px; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--verde);
  }
  #mov-nav button.nuevo .ic {
    background: var(--verde); color: #fff; width: 42px; height: 42px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center; margin-top: -18px; filter: none; opacity: 1;
    box-shadow: 0 4px 12px rgba(0,59,122,.35); font-size: 1.5rem;
  }
  #mov-nav .punto {
    position: absolute; top: 2px; right: calc(50% - 20px); min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px; background: #dc2626; color: #fff; font-size: .68rem; line-height: 18px; display: none;
  }

  /* Menú "Más" */
  #mov-velo { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1700; }
  #mov-velo.abierto { display: block; }
  body.mov-sesion #mov-hoja {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1701;
    background: #fff; border-radius: 20px 20px 0 0; max-height: 82dvh; overflow-y: auto;
    padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
    transform: translateY(105%); transition: transform .22s ease;
  }
  body.mov-sesion #mov-hoja.abierto { transform: translateY(0); }
  #mov-hoja .asa { width: 40px; height: 5px; border-radius: 3px; background: #cbd5e1; margin: 4px auto 12px; }
  #mov-hoja .usuario { display: flex; align-items: center; gap: 10px; padding: 4px 4px 12px; border-bottom: 1px solid #eef2f7; margin-bottom: 10px; }
  #mov-hoja .usuario b { display: block; }
  #mov-hoja .rejilla { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  #mov-hoja .rejilla a {
    display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
    padding: 12px 6px; border-radius: 14px; background: #f1f5f9; color: var(--texto);
    font-size: .8rem; font-weight: 600; cursor: pointer; text-decoration: none; position: relative;
  }
  #mov-hoja .rejilla a .ic { font-size: 1.6rem; width: auto; }
  #mov-hoja .rejilla a.active { background: #E8F1FB; color: var(--verde); outline: 2px solid var(--azul-borde); }
  #mov-hoja .rejilla a span[id$="-badge"] { position: absolute; top: 6px; right: 10px; margin: 0 !important; }
  #mov-hoja .acciones { display: grid; gap: 8px; margin-top: 14px; }
  #mov-hoja .acciones button { width: 100%; justify-content: center; }

  /* El asistente flotante no tapa la barra inferior */
  #matlacho-fab { bottom: calc(80px + env(safe-area-inset-bottom)) !important; right: 12px !important; width: 52px !important; height: 52px !important; }
  #matlacho-panel { bottom: calc(142px + env(safe-area-inset-bottom)) !important; right: 8px !important; left: 8px !important; width: auto !important; max-height: 60dvh !important; }
}

/* Abierta como app instalada */
@media (display-mode: standalone) and (max-width: 820px) {
  #app > nav { padding-top: calc(env(safe-area-inset-top) + 8px); }
}
