/* ============================================================
   gao-movil.css — Adaptación a celular del portal GAO.
   Se incluye al FINAL del <head> de cada pantalla, junto con
   gao-movil.js:
       <link rel="stylesheet" href="gao-movil.css?v=1"/>
       <script src="gao-movil.js?v=1" defer></script>

   IMPORTANTE: TODO lo que hay aquí vive dentro de @media
   (max-width:768px). Por encima de ese ancho (escritorio y
   tablet horizontal) este archivo no cambia absolutamente nada.
   No modifica los demás CSS/JS del portal; solo los sobrescribe
   en pantallas pequeñas.
   ============================================================ */

@media screen and (max-width:768px){

  /* ── BASE ─────────────────────────────────────────────── */
  html{-webkit-text-size-adjust:100%; text-size-adjust:100%;}
  html body{max-width:100%;}
  html body .main,
  html body main.main{padding:1.25rem 1rem 1.5rem !important; min-width:0;}
  html body .layout{min-width:0;}
  html body img,
  html body video{max-width:100%;}

  /* Inputs a 16px: evita que iOS haga zoom al enfocar un campo */
  html body input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  html body select,
  html body textarea{font-size:16px !important;}
  html body input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
  html body select{min-height:44px;}
  html body td input:not([type="checkbox"]):not([type="radio"]),
  html body td select{min-height:38px;}

  /* Botones cómodos para el dedo */
  html body button,
  html body [class*="btn-"],
  html body .btn{min-height:40px;}
  html body td button,
  html body td [class*="btn-"]{min-height:36px;}

  /* Zonas táctiles: sin retraso ni resaltado gris */
  html body a, html body button, html body [onclick], html body label, html body select{
    -webkit-tap-highlight-color:transparent; touch-action:manipulation;
  }

  /* ── BARRA SUPERIOR ───────────────────────────────────── */
  html body .gao-topbar{display:flex !important; align-items:center; justify-content:space-between; flex-wrap:nowrap !important;}
  html body .gao-topbar .topbar-right,
  html body .gao-topbar .topbar-logo{display:flex; align-items:center;}
  html body .gao-topbar .topbar-right{flex:0 0 auto;}
  html body .gao-topbar .topbar-logo{flex:0 1 auto; min-width:0;}
  html body .gao-topbar{padding-left:12px !important; padding-right:12px !important; gap:8px !important; min-width:0;}
  html body .gao-topbar .gao-marca{gap:8px; min-width:0;}
  html body .gao-topbar .gao-marca img{height:30px;}
  html body .gao-topbar .gao-marca-txt b{font-size:18px !important;}
  html body .gao-topbar .gao-marca-txt small{display:none;}
  html body .gao-topbar .topbar-right{margin-left:auto; min-width:0;}
  html body .gao-topbar .ds-buscador-top{display:none !important;}

  /* Pantallas de alta / editores: acciones compactas, sin desbordar */
  html body .gao-topbar > .nav-actions,
  html body .gao-topbar > .nav-back{margin-left:auto; min-width:0; gap:8px; flex-wrap:nowrap;}
  html body .gao-topbar .nav-actions > *{flex:0 1 auto; min-width:0;}
  html body .gao-topbar .nav-back{
    font-size:0 !important; letter-spacing:0 !important; gap:0 !important;
    width:44px; height:44px; padding:0 !important; justify-content:center; align-items:center;
    border-radius:50% !important; flex:none;
  }
  html body .gao-topbar .nav-back .ic,
  html body .gao-topbar .nav-back svg{width:20px; height:20px; font-size:initial; margin:0;}
  html body .gao-topbar .nav-actions button:not(.gao-menu-toggle),
  html body .gao-topbar .nav-actions [class*="btn-"]{
    padding:0 14px !important; font-size:.72rem !important; letter-spacing:.06em !important;
    height:44px; white-space:nowrap; max-width:46vw; overflow:hidden; text-overflow:ellipsis;
  }

  /* Sin scroll lateral de toda la página (cada tabla ancha se desliza dentro de su propia caja) */
  html{overflow-x:hidden;}
  html body{overflow-x:hidden;}
  html body main.main,
  html body .main{overflow-x:hidden !important;}

  /* ── AJUSTE AUTOMÁTICO (lo aplica gao-movil.js solo donde mide desborde real) ── */
  html body .gao-wrap{flex-wrap:wrap !important; row-gap:.6rem;}
  html body .gao-wrap > *{max-width:100%; min-width:0;}
  html body .gao-wrap > :is(button,a,.btn,[class*="btn-"]){flex:1 1 auto; justify-content:center; text-align:center;}
  html body .gao-fit{max-width:100% !important; min-width:0 !important; box-sizing:border-box;}
  html body .gao-1col{grid-template-columns:minmax(0,1fr) !important;}

  /* Botones de formularios y filtros: ocupan el ancho disponible */
  html body .modal-acciones > *, html body .form-acciones > *{flex:1 1 140px;}

  /* ── GENERADORES: selector Formulario / Vista previa ── */
  html body .gao-vista-switch{
    position:sticky; top:60px; z-index:20; display:flex; gap:6px; padding:8px 12px;
    background:rgba(8,11,15,.96); border-bottom:1px solid var(--borde,rgba(118,63,214,.28));
    -webkit-backdrop-filter:blur(10px); backdrop-filter:blur(10px);
  }
  html body .gao-vista-switch button{
    flex:1 1 0; min-height:42px; border-radius:999px; cursor:pointer;
    border:1px solid rgba(255,255,255,.22); background:transparent; color:#b8c4cd;
    font-family:inherit; font-size:.8rem; letter-spacing:.1em; text-transform:uppercase;
  }
  html body .gao-vista-switch button[aria-pressed="true"]{
    color:#fff; border-color:transparent;
    background:linear-gradient(100deg,rgba(113,55,220,.85),rgba(213,44,218,.7));
  }
  html body:not(.modo-pdf-activo) .main-layout.gao-ver-prev > .panel-form{display:none !important;}
  html body:not(.modo-pdf-activo) .main-layout.gao-ver-form > .panel-preview{display:none !important;}
  html body:not(.modo-pdf-activo) .main-layout.gao-ver-prev > .panel-preview{
    display:block; height:calc(100vh - 60px - 58px); height:calc(100dvh - 60px - 58px); min-height:420px; padding:0 !important;
  }

  /* ── CUADRÍCULAS DE MÉTRICAS ──────────────────────────── */
  html body .metricas-row,
  html body .balance-kpis,
  html body .radial-kpis,
  html body .metricas{
    grid-template-columns:repeat(auto-fit,minmax(150px,1fr)) !important;
    gap:.75rem !important;
  }

  /* ── FORMULARIOS ──────────────────────────────────────── */
  html body .form-grid,
  html body .form-fila-doble,
  html body .form-row,
  html body .grid-2,
  html body .grid-3,
  html body .modal-grid,
  html body .modal-grid-editable{grid-template-columns:minmax(0,1fr) !important;}
  html body .grid-2 > .full,
  html body .grid-3 > .full,
  html body .form-grid > .full{grid-column:auto !important;}

  /* ── MODALES: hoja que sube desde abajo ───────────────── */
  html body .modal-overlay,
  html body .overlay{align-items:flex-end !important; padding:0 !important;}
  html body .modal-overlay > .modal,
  html body .overlay > .modal{
    width:100% !important; max-width:100% !important; margin:0 !important;
    max-height:92vh; max-height:92dvh; overflow-y:auto; -webkit-overflow-scrolling:touch;
    border-radius:18px 18px 0 0 !important;
    padding-bottom:max(1rem, env(safe-area-inset-bottom));
  }
  html body .modal-acciones{flex-wrap:wrap; gap:.6rem;}
  html body .modal-acciones > *{flex:1 1 140px;}

  /* ── TABLAS ───────────────────────────────────────────── */
  /* (a) Tablas anchas: se deslizan de lado dentro de su propia caja */
  html body table.gao-scroll{
    display:block; max-width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch;
    overscroll-behavior-x:contain;
  }
  html body .tabla-wrap{overflow-x:auto !important; -webkit-overflow-scrolling:touch;}

  /* (b) Listados: cada fila se vuelve una tarjeta */
  html body table.gao-cards,
  html body table.gao-cards > tbody{display:block; width:100% !important; min-width:0 !important; max-width:100%;}
  html body table.gao-cards > thead{display:none !important;}
  html body table.gao-cards > tbody > tr{
    display:block; margin:0 0 .75rem; padding:.3rem .95rem; box-sizing:border-box;
    background:var(--gris-oscuro,#141527) !important;
    border:1px solid var(--borde,rgba(118,63,214,.28)) !important;
    border-radius:14px; box-shadow:0 10px 24px -14px rgba(0,0,0,.6);
  }
  html body table.gao-cards > tbody > tr:active{border-color:var(--azul-intenso,#9f2dde) !important;}
  html body table.gao-cards > tbody > tr > td,
  html body table.gao-cards > tbody > tr > th{
    display:flex; justify-content:space-between; align-items:flex-start; gap:1rem;
    width:auto !important; min-width:0 !important; max-width:none !important; box-sizing:border-box;
    padding:.6rem 0 !important; border:0 !important;
    border-bottom:1px solid rgba(195,215,231,.08) !important;
    text-align:right !important; white-space:normal !important; word-break:break-word;
    position:static !important; left:auto !important; background:transparent !important;
  }
  html body table.gao-cards > tbody > tr > td:last-child{border-bottom:0 !important;}
  html body table.gao-cards > tbody > tr > td::before{
    content:attr(data-label); flex:0 0 40%; max-width:40%; text-align:left;
    font-size:.66rem; line-height:1.35; letter-spacing:.09em; text-transform:uppercase;
    color:var(--texto-muted,#8195a4); font-weight:500; padding-top:.15rem;
  }
  html body table.gao-cards > tbody > tr > td[data-label=""]::before{display:none;}
  html body table.gao-cards > tbody > tr > td.gao-vacio{display:none;}
  /* Fila de aviso (sin resultados, cargando…) */
  html body table.gao-cards > tbody > tr.gao-fila-aviso{background:transparent !important; border:0 !important; box-shadow:none; padding:0;}
  html body table.gao-cards > tbody > tr > td.gao-full{display:block; text-align:center !important; border:0 !important;}
  html body table.gao-cards > tbody > tr > td.gao-full::before{display:none;}
  /* Primer dato (nombre / folio): funciona como título de la tarjeta */
  html body table.gao-cards > tbody > tr > td:first-child:not(.gao-full):not(.gao-acciones){
    flex-direction:column; align-items:flex-start; gap:.2rem; text-align:left !important;
    font-size:1.02rem; font-weight:600; color:var(--blanco,#e9f4f9);
  }
  html body table.gao-cards > tbody > tr > td:first-child:not(.gao-full)::before{flex:none; max-width:100%;}
  /* Acciones: botones en fila al pie de la tarjeta, sin etiqueta */
  html body table.gao-cards > tbody > tr > td.gao-acciones::before{display:none;}
  html body table.gao-cards > tbody > tr > td.gao-acciones{justify-content:flex-end; flex-wrap:wrap; gap:.5rem;}
  html body table.gao-cards td.td-acciones,
  html body table.gao-cards td:has(> .acciones-cell),
  html body table.gao-cards td:has(> button:only-child),
  html body table.gao-cards td[data-label=""]{justify-content:flex-end; flex-wrap:wrap;}
  html body table.gao-cards .acciones-cell{display:flex; flex-wrap:wrap; gap:.5rem; justify-content:flex-end;}
  /* Celdas con contenido de ancho fijo (inputs, selects): ocupan el espacio disponible */
  html body table.gao-cards td input,
  html body table.gao-cards td select{max-width:60%;}

  /* ── PARTIDAS DE LOS GENERADORES ──────────────────────── */
  html body .partidas-header{display:none !important;}
  html body .partida-row{
    grid-template-columns:repeat(2,minmax(0,1fr)) !important; gap:.55rem !important; align-items:stretch !important;
    padding:.8rem; margin-bottom:.8rem !important;
    border:1px solid var(--borde,rgba(118,63,214,.28)); border-radius:12px;
    background:rgba(255,255,255,.02);
  }
  html body .partida-row > *{min-width:0;}
  html body .partida-row > [data-gao-etq]::before{
    content:attr(data-gao-etq); display:block; margin-bottom:.2rem;
    font-size:.62rem; letter-spacing:.1em; text-transform:uppercase; color:var(--texto-muted,#8195a4);
  }
  html body .partida-row > :nth-child(1),
  html body .partida-row > :nth-child(2){grid-column:1 / -1;}
  html body .partida-row > .entrega-wrap,
  html body .partida-row > .btn-remove{grid-column:1 / -1;}
  html body .adjuntos-grid{grid-template-columns:repeat(2,minmax(0,1fr)) !important;}

}

/* Pantallas muy angostas */
@media screen and (max-width:380px){
  html body .main,
  html body main.main{padding-left:.75rem !important; padding-right:.75rem !important;}
  html body .metricas-row,
  html body .balance-kpis,
  html body .radial-kpis,
  html body .metricas{grid-template-columns:repeat(2,minmax(0,1fr)) !important;}
}
