/* togetherb2b. · correcciones mobile globales (carga después del CSS de cada página) */
@media (max-width: 780px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  body { min-width: 0; }
  img, svg, video, canvas { max-width: 100%; height: auto; }
  .wrap, .top-in, .pageview-in { width: 100%; max-width: 100%; padding-left: 12px !important; padding-right: 12px !important; }
  .top-in { height: auto !important; min-height: 58px; flex-wrap: wrap !important; padding-top: 8px !important; padding-bottom: 8px !important; gap: 7px !important; }
  .top-in > .brand, .top-in > .brand-wrap { flex: 1 1 100%; max-width: 100%; min-width: 0; }
  .top .right, .top-in .right, .top-right { display: flex; flex-wrap: wrap !important; gap: 6px !important; min-width: 0; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .top .right .pill, .top-in .right .pill, .top-right .pill, .top .right .btn, .top-in .right .btn { flex: 0 0 auto; height: 30px; font-size: 10px; padding: 0 8px; }
  .top .right .hide-sm, .top-in .right .hide-sm, .top-right .hide-sm { display: none !important; }
  .tabs { width: 100%; max-width: 100%; overflow-x: auto !important; flex-wrap: nowrap !important; -webkit-overflow-scrolling: touch; }
  .tabs .tab, .tabs > * { flex: 0 0 auto; }
  .filters, .filterbar, .toolbar, .actions, .page-head, .page-head .right { display: flex !important; flex-wrap: wrap !important; gap: 7px !important; min-width: 0; width: 100%; }
  .filters > *, .filterbar > *, .toolbar > * { min-width: 0; max-width: 100%; }
  .filters input[type=search], .filters input[type=text], .filterbar input[type=search], .toolbar input[type=search] { width: 100% !important; min-width: 0 !important; }
  .grid2, .grid3, .stat-strip, .kpis, .cards, .colors, .providers, .advgrid, .form-grid, .settings-grid, .preview-wrap { grid-template-columns: 1fr !important; }
  .grid2[style*="grid-template-columns"], .stat-strip[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .table-wrap { display: block; width: 100%; max-width: 100%; overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 760px; }
  .table-wrap .line-table { min-width: 760px; }
  .card, .table-card, .sheet, .product-sheet, .msgcard, .modal-card { min-width: 0; max-width: 100%; }
  .modal-card, .modal-card.lg, .modal-card.md { width: calc(100vw - 20px) !important; max-width: calc(100vw - 20px) !important; }
  .modal-card .foot, .drawer-foot { flex-wrap: wrap; }
  .sheet { padding: 18px !important; }
  .cover { flex-direction: column !important; }
  .cover-right { text-align: left !important; }
  .sheets { grid-template-columns: 1fr !important; }
  .product-sheet { grid-template-columns: 1fr !important; min-height: 0; }
  .product-sheet .ps-img { border-right: 0 !important; border-bottom: 1px solid var(--line2, #eee); padding: 16px; }
  .product-sheet .ps-img img { max-height: 210px; }
  .editor-grid, .editor-main { grid-template-columns: 1fr !important; }
  .row2, .row3 { grid-template-columns: 1fr !important; }
  .hero, .hero-grid, .signup, .landing-grid { grid-template-columns: 1fr !important; }
  .signup, .landing-grid > * { min-width: 0; }
  .brands-wrap { width: 100%; max-width: 100%; overflow-x: auto !important; }
  .brand-chips { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .top .brand-tools, .top-in .brand-tools { display: none !important; }
  .search, .brand-tools input { min-width: 0 !important; }
  .toast { max-width: 92vw !important; }
}

/* Mail en mobile: una columna, sin panel de carpetas */
@media (max-width: 780px) {
  .layout { display: block !important; height: auto !important; min-height: 0 !important; }
  .folders { display: none !important; }
  .listpane { height: auto !important; max-height: 42vh; border-right: 0 !important; border-bottom: 1px solid var(--line, #e5e5e5); }
  .reader { height: auto !important; min-height: 58vh; overflow: visible !important; }
  .reader-scroll { max-height: none !important; }
  .msgcard-body { max-width: 100% !important; }
  .compose-card { width: calc(100vw - 20px) !important; max-width: calc(100vw - 20px) !important; }
}

/* Portal / catálogo / precios: acciones y tablas contenidas */
@media (max-width: 780px) {
  .portal-page .grid2, .portal-page .grid3 { grid-template-columns: 1fr !important; }
  .stat-strip { grid-template-columns: 1fr 1fr !important; }
  .preview-wrap { grid-template-columns: 1fr !important; }
  .preview-side { position: static !important; }
  .orderbar { max-width: calc(100vw - 20px) !important; }
  .float-right { display: none !important; }
  .tabs { margin-left: 0 !important; margin-right: 0 !important; }
}

/* Branding */
@media (max-width: 780px) {
  .grid { grid-template-columns: 1fr !important; }
  .preview-card { position: static !important; }
  .colors { grid-template-columns: 1fr 1fr !important; }
  .brand-row, .logo-row { flex-wrap: wrap; }
}

/* Facturas */
@media (max-width: 780px) {
  .editor-grid, .settings-grid { grid-template-columns: 1fr !important; }
  .series-row { grid-template-columns: 1fr 1fr !important; }
  .series-row > *:last-child { grid-column: 1 / -1; }
  .kpis { grid-template-columns: 1fr 1fr !important; }
}

/* Ajustes finos de la auditoría mobile */
@media (max-width: 780px) {
  /* Headers standalone */
  .top-in .right, .top-right {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100% !important;
    overflow: visible !important;
  }
  .top-in .right > *, .top-right > * {
    width: 100% !important;
    min-width: 0 !important;
    height: 34px !important;
    justify-content: center !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .top-in .right a[href="/mail"],
  .top-in .right a[href="/review?demo=1"],
  .top-in .right #theme,
  .top-right #theme,
  .top-right .mode,
  .top-right .top-points,
  .top-right #points { display: none !important; }

  /* Precios: barra de pedido compacta, sin tapar contenido */
  .orderbar {
    width: calc(100vw - 16px) !important;
    bottom: 8px !important;
    padding: 7px 9px !important;
    gap: 7px !important;
    border-radius: 12px !important;
    align-items: center !important;
  }
  .orderbar .o-left { gap: 6px !important; flex-wrap: wrap; }
  .orderbar .units { font-size: 10px !important; padding: 5px 7px !important; }
  .orderbar .total { font-size: 14px !important; }
  .orderbar .hint { display: none !important; }
  .orderbar .review { height: 34px !important; padding: 0 11px !important; font-size: 11px !important; white-space: nowrap; }
  body { padding-bottom: 0; }
  body:has(.orderbar) { padding-bottom: 74px; }

  /* Catalogo: acciones en grilla, no una por fila */
  .actions { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px !important; width: 100%; }
  .actions .btn, .actions a { width: 100% !important; justify-content: center; }
  .actions .btn[href*="mail"], .actions .btn:last-child { grid-column: 1 / -1; }

  /* Mail: sin panel de lectura vacío */
  #reader:empty { display: none !important; }
  .reader .empty { min-height: 160px !important; }
  .listpane { max-height: calc(100vh - 190px) !important; }

  /* Admin: breadcrumb oculto y acciones sin cortar el título */
  body.light .top, .top { height: auto !important; min-height: 56px; flex-wrap: wrap; padding: 7px 12px !important; }
  .crumb { display: none !important; }
  .top .right { margin-left: auto !important; flex-wrap: wrap !important; gap: 5px !important; width: auto !important; overflow: visible !important; }
  .top .right > * { flex: 0 0 auto; }

  /* Facturas / documentos: tablas contenidas */
  .table-wrap { overflow-x: auto !important; }
  .line-table { font-size: 10px; }
  .kpi b, .kpi .v { font-size: 20px !important; }

  /* Landing MID: menos aire vertical y CTA de formulario visible antes */
  .mid-landing .mid-real-intro { margin-bottom: 14px !important; }
  .mid-landing .landing-grid { gap: 16px !important; }
  .mid-landing .signup { margin-top: 4px; }
}

/* Header mobile mínimo: marca + acciones esenciales, sin controles vacíos */
@media (max-width: 780px) {
  .top-in .right { display: flex !important; flex-wrap: wrap !important; width: 100% !important; gap: 6px !important; overflow: visible !important; }
  .top-in .right > * { display: none !important; }
  .top-in .right > .pill.on,
  .top-in .right > a[href="/cuenta"],
  .top-in .right > a[href^="/migracion"],
  .top-in .right > a[href="/tenant"],
  .top-in .right > a[href^="/tenant"],
  .top-in .right > a[href="/portal#/panel"],
  .top-in .right > .bell-wrap { display: inline-flex !important; width: auto !important; }
  .top-right > * { display: none !important; }
  .top-in .right > .pill, .top-in .right > a { height: 32px !important; font-size: 10px !important; padding: 0 10px !important; }
  .top-in .right > .bell-wrap { margin-left: auto; }

  /* FAB no debe tapar la barra de pedido */
  body:has(.orderbar) .tb-agent-fab { bottom: 78px !important; }
  @supports not selector(:has(*)) { .tb-agent-fab { bottom: 78px; } }

  /* Evitar que los títulos de página se aplasten junto a acciones */
  .page-head h1, .hero h1, main h1 { overflow-wrap: anywhere; }
  .page-head .right, .page-head .actions { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
  .page-head .right .btn, .page-head .actions .btn { flex: 1 1 auto; }
}

/* Branding: el guardado superior tiene que seguir visible en mobile */
@media (max-width: 780px) {
  .top-in .right > #saveTop,
  .top-in .right > .btn,
  .top-in .right > a[href="/dominio"] { display: inline-flex !important; width: auto !important; }
}

/* Portail: historique de prix en cartes mobiles, avec variation visible */
@media (max-width:780px){
  .hist-mobile .table-wrap{overflow:visible!important}
  .hist-mobile table{display:block!important;min-width:0!important;width:100%!important}
  .hist-mobile thead{display:none!important}
  .hist-mobile #histRows{display:grid;gap:9px}
  .hist-mobile #histRows tr{display:grid;grid-template-columns:1fr auto;gap:3px 10px;border:1px solid #E6DDC8;border-radius:11px;background:#fff;padding:11px 12px}
  .hist-mobile #histRows td{display:flex;justify-content:space-between;align-items:baseline;gap:10px;border:0;padding:2px 0;font-size:10px}
  .hist-mobile #histRows td:before{content:attr(data-label);font-size:7.5px;letter-spacing:.08em;text-transform:uppercase;color:#9A9283;font-weight:800;flex:0 0 auto}
  .hist-mobile #histRows td:nth-child(1){grid-column:1;grid-row:1;color:#8A8172;font-size:9px;align-self:center}
  .hist-mobile #histRows td:nth-child(2){grid-column:1/-1;grid-row:2;display:block;padding:2px 0 6px}
  .hist-mobile #histRows td:nth-child(2):before{display:none}
  .hist-mobile #histRows td:nth-child(2) b{font-size:13px;line-height:1.2}
  .hist-mobile #histRows td:nth-child(3){display:none}
  .hist-mobile #histRows td:nth-child(4){grid-column:1;grid-row:3}
  .hist-mobile #histRows td:nth-child(5){grid-column:2;grid-row:3;justify-content:flex-end}
  .hist-mobile #histRows td:nth-child(6){grid-column:2;grid-row:1;font-size:15px;font-weight:900;justify-content:flex-end;align-self:center}
  .hist-mobile #histRows td:nth-child(6):before{display:none}
  .hist-mobile #histRows td:nth-child(7){grid-column:1/-1;grid-row:4;border-top:1px solid #F2EBDD;margin-top:3px;padding-top:5px;color:#6D675C;font-size:9px}
  .hist-mobile #histRows td:nth-child(8){grid-column:1/-1;grid-row:5;padding-top:4px}
  .hist-mobile #histRows td:nth-child(8) .btn{width:100%;justify-content:center}
}

/* Precios mobile: cuenta y carrito visibles y accionables */
@media (max-width:780px){
  .top-right > .keep-account,.top-right > #cartBubble{display:inline-flex!important;width:34px!important;height:34px!important;padding:0!important;justify-content:center!important;flex:0 0 34px!important}
  .top-right > #cartBubble{margin-left:0!important}
}
