/* [2026-10-17] AI MAX EN EL MÓVIL (mockup aprobado). Solo por debajo de 700 px: el ordenador no cambia.
 *
 * Medido en el último mes: en el móvil se genera MÁS que en el ordenador (21 % de las sesiones frente a 12 %)
 * pero solo la mitad descarga. Motivo: la cabecera tenía 10 botones y BC3/WORD/PDF/EXCEL quedaban fuera de la
 * pantalla; la tabla medía 608 px en una pantalla de 390 (no se veían cantidad, precio ni importe) y el
 * presupuesto generado quedaba debajo de las plantillas.
 *
 * - Cabecera de una línea (marca, plan y «⋯»). Los botones ocultos siguen existiendo: la barra de abajo y las
 *   hojas (js/bg-aimax-movil.js) llaman a los MISMOS botones y funciones.
 * - Partidas en tarjetas, como el visor BC3 (css/bg-visor-movil.css). Mismas celdas: «Editar» funciona igual.
 * - Pestañas que se deslizan; menús PDF/Word/Excel como hojas desde abajo.
 * Columnas de .budget-table: 1 código · 2 ud · 3 descripción · 4 cantidad · 5 precio · 6 importe
 */
@media (max-width: 699px) {
  /* ── Cabecera ── */
  .navbar { flex-direction: row !important; flex-wrap: nowrap !important; align-items: center !important; justify-content: space-between !important; gap: 8px !important; padding: 10px 12px !important; min-height: 0 !important; height: auto !important; }
  .navbar .nav-left { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap !important; justify-content: flex-start !important; }
  .navbar .nav-actions { overflow: visible !important; padding-bottom: 0 !important; }
  .navbar .nav-center,
  .navbar .nav-sep,
  .navbar .btn-new,
  .navbar .btn-bgt-save,
  .navbar #undoRedoBtns,
  .navbar .nav-left > span { display: none !important; }
  .navbar .nav-actions { flex: 0 0 auto; flex-wrap: nowrap !important; gap: 6px !important; }
  .navbar .nav-actions > *:not(#bgPlanPill):not(#bgPlanPillPro):not(#bgmMas) { display: none !important; }
  .navbar .brand-text { font-size: 1.05rem !important; }
  #bgmMas { display: inline-flex !important; }

  /* ── Barra fija abajo ── */
  body.bgm-on { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important; }
  #bgmBarra { display: grid !important; }
  body.bgm-on #chatFab { display: none !important; }            /* el chat está en la barra */
  body.bgm-on .bg-feedback-tab { bottom: 84px !important; }
  body.bgm-on #bg-cookie-toggle { bottom: 84px !important; }   /* que no tape «Descargar» */
  /* Total de abajo en una línea */
  #summaryFooter { padding: 10px 14px !important; gap: 8px; align-items: center; }
  #summaryFooter .summary-label { font-size: 0.8rem !important; line-height: 1.2; }
  #summaryFooter .summary-value { font-size: 1.35rem !important; white-space: nowrap; }

  /* ── Pestañas ── */
  .content-area .tabs { flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; gap: 6px; padding: 8px 10px !important; }
  .content-area .tabs::-webkit-scrollbar { display: none; }
  .content-area .tabs > div[style*="flex: 1"] { display: none !important; }
  .content-area .tabs .tab-btn, .content-area .tabs .toolbar-btn { flex: 0 0 auto; white-space: nowrap; margin: 0 !important; padding: 7px 12px !important; border-radius: 999px !important; font-size: 0.82rem !important; }

  /* ── Tabla → tarjetas ── */
  .content-area, #tab-presupuesto { overflow-x: visible !important; }
  .budget-table { width: 100% !important; min-width: 0 !important; border-collapse: separate !important; border-spacing: 0 !important; table-layout: auto !important; background: transparent !important; box-shadow: none !important; }
  .budget-table thead { display: none !important; }
  .budget-table tbody { display: block; }
  .budget-table td.empty-state { display: block; }

  /* Capítulo: código y nombre a la izquierda, total a la derecha */
  .budget-table tr.chapter-row { display: grid !important; grid-template-columns: auto 1fr auto; grid-template-areas: "cod des tot" "cod cnt tot"; align-items: center; column-gap: 8px; padding: 9px 10px; margin-top: 10px; border-radius: 10px; }
  .budget-table tr.chapter-row > td { display: block; border: 0 !important; padding: 0 !important; background: transparent !important; min-width: 0; text-align: left !important; }
  .budget-table tr.chapter-row > td:nth-child(1) { grid-area: cod; font-size: 0.8rem; }
  .budget-table tr.chapter-row > td:nth-child(2) { grid-area: des; font-size: 0.86rem; line-height: 1.3; }
  .budget-table tr.chapter-row > td:nth-child(3) { grid-area: cnt; white-space: normal !important; }
  .budget-table tr.chapter-row > td:nth-child(3) .chapter-count { font-size: 0.7rem !important; margin: 0 !important; }
  .budget-table tr.chapter-row > td:nth-child(4) { grid-area: tot; text-align: right !important; font-weight: 800; white-space: nowrap; font-size: 0.86rem; }

  /* Partida: tarjeta */
  .budget-table tr.item-row { display: grid !important; grid-template-columns: auto auto 1fr; grid-template-areas: "cod ud ud" "des des des" "can pre imp"; column-gap: 6px; row-gap: 3px; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 8px 10px 9px 12px !important; margin-top: 6px; }
  .budget-table tr.item-row > td { display: block; border: 0 !important; padding: 0 !important; background: transparent !important; min-width: 0; text-align: left !important; white-space: normal; }
  .budget-table tr.item-row > td:nth-child(1) { grid-area: cod; font-size: 0.72rem; }
  .budget-table tr.item-row > td:nth-child(2) { grid-area: ud; font-size: 0.72rem; color: #64748b; font-weight: 700; align-self: center; }
  .budget-table tr.item-row > td:nth-child(3) { grid-area: des; font-size: 0.86rem; line-height: 1.38; }
  .budget-table tr.item-row > td:nth-child(4) { grid-area: can; font-size: 0.8rem; color: #475569; align-self: end; }
  .budget-table tr.item-row > td:nth-child(5) { grid-area: pre; font-size: 0.8rem; color: #475569; align-self: end; }
  .budget-table tr.item-row > td:nth-child(6) { grid-area: imp; text-align: right !important; font-weight: 800; white-space: nowrap; font-size: 0.86rem; }
  .budget-table tr.item-row > td:nth-child(5)::before { content: "× "; color: #94a3b8; }
  .budget-table tr.item-row > td:nth-child(5)::after { content: " €"; }
  .budget-table tr.item-row .item-text { font-size: 0.76rem; color: #64748b; margin-top: 4px; }
  .budget-table tr.item-row .move-arrows { display: inline-flex; margin-right: 4px; }

  /* Mediciones / descompuesto: a todo el ancho bajo su tarjeta */
  .budget-table tr.item-detail-row { display: block; margin: 0 0 4px; }
  .budget-table tr.item-detail-row > td { display: block; padding: 6px 4px !important; overflow-x: auto; }
  .budget-table .bg-det-cols { display: block !important; }

  /* ── Menús PDF / Word / Excel como hojas desde abajo ── */
  #pdfDropdownMenu, #docDropdownMenu, #xlsDropdownMenu { left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important; width: auto !important; min-width: 0 !important; }
  #pdfDropdownMenu .pdf-dropdown-inner, #docDropdownMenu .pdf-dropdown-inner, #xlsDropdownMenu .pdf-dropdown-inner { border-radius: 18px 18px 0 0 !important; padding: 10px 6px calc(16px + env(safe-area-inset-bottom, 0px)) !important; max-height: 72vh; overflow-y: auto; box-shadow: 0 -12px 34px rgba(15, 23, 42, .25) !important; }
  #pdfDropdownMenu .pdf-dropdown-item, #docDropdownMenu .pdf-dropdown-item, #xlsDropdownMenu .pdf-dropdown-item { font-size: 0.95rem !important; padding: 13px 14px !important; white-space: normal !important; }
}

/* Piezas propias: fuera del móvil no existen */
#bgmBarra, #bgmMas { display: none; }
#bgmBarra { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100; background: #fff; border-top: 1px solid #e2e8f0; grid-template-columns: repeat(4, 1fr); padding: 6px 4px calc(8px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -6px 18px rgba(15, 23, 42, .06); font-family: inherit; }
#bgmBarra button { background: none; border: 0; padding: 2px 0; font: inherit; font-size: 0.68rem; font-weight: 700; color: #475569; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
#bgmBarra button .ic { font-size: 1.15rem; line-height: 1.6rem; height: 1.6rem; }
#bgmBarra button.p .ic { background: #2563eb; color: #fff; border-radius: 12px; width: 48px; }
#bgmBarra button.p { color: #2563eb; }
#bgmBarra button.on { color: #2563eb; }
#bgmMas { width: 34px; height: 34px; border-radius: 9px; background: rgba(255, 255, 255, .14); border: 0; color: #fff; font-size: 1.25rem; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto; }
.bgm-velo { position: fixed; inset: 0; z-index: 100000; background: rgba(15, 23, 42, .45); }
.bgm-hoja { position: fixed; left: 0; right: 0; bottom: 0; z-index: 100001; background: #fff; border-radius: 18px 18px 0 0; padding: 10px 14px calc(16px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -12px 34px rgba(15, 23, 42, .25); font-family: inherit; color: #0f172a; max-height: 80vh; overflow-y: auto; }
.bgm-hoja .asa { width: 40px; height: 4px; background: #cbd5e1; border-radius: 4px; margin: 0 auto 10px; }
.bgm-hoja h4 { margin: 0 0 6px; font-size: 1rem; }
.bgm-hoja .est { font-size: 0.8rem; color: #64748b; margin: -2px 0 6px; }
.bgm-op { display: flex; align-items: center; gap: 12px; width: 100%; background: none; border: 0; border-bottom: 1px solid #f1f5f9; padding: 11px 2px; font: inherit; font-size: 0.95rem; font-weight: 600; color: #0f172a; text-align: left; cursor: pointer; }
.bgm-op:last-child { border-bottom: 0; }
.bgm-op .ic { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 900; color: #fff; flex: 0 0 auto; background: #64748b; }
.bgm-op small { display: block; font-weight: 400; color: #64748b; font-size: 0.78rem; margin-top: 1px; }
