/* ══════════════════════════════════════════════════════════════════
   Pappitas — Capa responsive global (móvil ≤ 768px)
   Se carga DESPUÉS del <style> principal. Varias pantallas arman sus
   filas con estilos inline (grid de 4 columnas, flex sin wrap, anchos
   mínimos fijos): por eso algunas reglas llevan !important — es la
   única forma de ganarle a un style="" sin reescribir cada pantalla.
   Colores: solo variables del theme de MASTER.
   ══════════════════════════════════════════════════════════════════ */
/* El botón "Filtros" solo existe en móvil */
.m-filter-btn { display: none; }

@media (max-width: 768px) {

  /* ── KPIs compactos: una tira de mini-tarjetas (antes 2 cajas enormes por fila) ── */
  #app-shell .kpi-grid {
    display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px !important; margin-bottom: 16px !important;
  }
  #app-shell .kpi-grid:not(:has(> :nth-child(3))),
  #app-shell .kpi-grid:has(> :nth-child(4)) { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  #app-shell .kpi-card {
    min-width: 0; padding: 11px 13px 12px !important; border-radius: 14px !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04) !important; transform: none !important;
    display: flex; flex-direction: column; justify-content: space-between;
  }
  #app-shell .kpi-card .kpi-icon, #app-shell .kpi-card .icon-badge { display: none !important; }
  #app-shell .kpi-card .kpi-label {
    font-size: 10px !important; letter-spacing: .04em !important; margin: 0 0 6px !important; line-height: 1.25;
    white-space: normal; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    padding-right: 0 !important;
  }
  #app-shell .kpi-grid:has(> :nth-child(3)):not(:has(> :nth-child(4))) .kpi-label { min-height: 2.5em; }
  #app-shell .kpi-card .kpi-sub { padding: 0 !important; }
  #app-shell .kpi-card .kpi-value { font-size: 20px !important; line-height: 1.1; letter-spacing: -.02em; }
  #app-shell .kpi-card .kpi-sub { font-size: 10.5px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  #app-shell .kpi-card .kpi-sub > * { display: inline; }

  /* ── Encabezados de tarjeta: título arriba, botones abajo a lo ancho ── */
  #app-shell .section-card-header { flex-wrap: wrap !important; row-gap: 10px; }
  #app-shell .section-card-header:has(> .btn-primary, > .btn-secondary) > .section-card-title { flex: 1 1 100% !important; }
  #app-shell .section-card-header > .btn-primary,
  #app-shell .section-card-header > .btn-secondary { flex: 1 1 0 !important; justify-content: center; min-width: 0; white-space: normal !important; }
  #app-shell .page-header > .btn-primary { width: 100% !important; justify-content: center; }

  /* ── Tiras de pestañas: una sola línea que se desliza ── */
  #app-shell .ns-tabs, #app-shell [id$="-filter-tabs"] {
    display: flex !important; flex-wrap: nowrap !important; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; max-width: 100%; scroll-snap-type: x proximity; padding-bottom: 2px;
  }
  #app-shell .ns-tabs::-webkit-scrollbar, #app-shell [id$="-filter-tabs"]::-webkit-scrollbar { display: none; }
  #app-shell .ns-tabs > *, #app-shell [id$="-filter-tabs"] > * { flex: 0 0 auto !important; white-space: nowrap; scroll-snap-align: start; }
  #app-shell .ns-tab { padding: 9px 14px !important; min-height: 0 !important; flex-direction: row !important; gap: 6px; }
  #app-shell .section-card-header:has(> [id$="-filter-tabs"]) > .section-card-title { flex: 1 1 100% !important; }
  #app-shell .section-card-header > [id$="-filter-tabs"] { flex: 1 1 100% !important; }

  /* ── Filtros de Landing / Formularios (Grupo, Dominio, Categoría, País):
        etiqueta + selector a lo ancho, "Gestionar…" como link chico debajo ── */
  #checkout-filters-row, #landing-filters-row {
    flex-direction: column; align-items: stretch !important; gap: 12px !important;
    margin: 0 0 14px !important; padding: 12px 14px !important; box-shadow: none !important;
  }
  #checkout-filters-row > div:not([id]), #landing-filters-row > div:not([id]) { display: none !important; }
  #checkout-category-tabs, #checkout-country-tabs, #landing-group-tabs, #landing-domain-tabs {
    display: grid !important; grid-template-columns: 74px minmax(0, 1fr); align-items: center; column-gap: 10px; row-gap: 4px; min-width: 0;
  }
  #checkout-category-tabs > svg, #checkout-country-tabs > svg, #landing-group-tabs > svg, #landing-domain-tabs > svg { display: none; }
  #checkout-category-tabs > select, #checkout-country-tabs > select, #landing-group-tabs > select, #landing-domain-tabs > select { width: 100%; min-width: 0; }
  #checkout-category-tabs > .btn-link, #checkout-country-tabs > .btn-link, #landing-group-tabs > .btn-link, #landing-domain-tabs > .btn-link {
    grid-column: 2; justify-self: start; font-size: 12px !important; padding: 2px 0 !important;
  }
  #checkout-category-tabs > span, #checkout-country-tabs > span, #landing-group-tabs > span, #landing-domain-tabs > span {
    grid-column: 1 / -1; font-size: 12px !important;
  }

  /* ── Barras de filtros (.filters): buscador + botón "Filtros"; el resto
        se despliega al tocarlo (responsive.js agrega el botón) ── */
  #app-shell .filters { display: grid !important; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px !important; padding: 0 !important; background: none !important; border: 0 !important; box-shadow: none !important; }
  #app-shell .filters > * { grid-column: span 3; width: 100% !important; min-width: 0 !important; max-width: none !important; margin: 0 !important; }
  #app-shell .filters > .btn-secondary, #app-shell .filters > .btn-primary { justify-content: center; }
  #app-shell .filters input[type="date"] { min-height: 42px; }
  #app-shell .filters.m-collapsible > :first-child { grid-column: span 5; }
  #app-shell .filters.m-collapsible > .m-filter-btn { grid-column: span 1; }
  #app-shell .filters.m-collapsible:not(.m-open) > :not(:first-child):not(.m-filter-btn) { display: none !important; }
  #app-shell .filters:not(.m-collapsible) > input:not([type="date"]):first-child { grid-column: 1 / -1; }
  .m-filter-btn {
    position: relative; display: flex; align-items: center; justify-content: center; height: 100%; min-height: 42px;
    border: 1px solid var(--border); border-radius: var(--radius-md, 12px); background: var(--bg-card); color: var(--text-primary); cursor: pointer;
  }
  .m-filter-btn svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
  .filters.m-open > .m-filter-btn { background: var(--text-primary); color: var(--bg-card); border-color: var(--text-primary); }
  .m-filter-btn i { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--brand-primary); color: #fff; font-style: normal; font-size: 10.5px; font-weight: 800; line-height: 18px; text-align: center;
    box-shadow: 0 0 0 2px var(--bg-app); }
  .m-filter-btn i:empty { display: none; }

  /* Fila de acciones de Campañas (Actualizar / Procesar / Nueva) */
  #page-marketing > div:has(> #mkt-filter-tabs) { flex-direction: column; align-items: stretch !important; }
  #page-marketing > div:has(> #mkt-filter-tabs) > div:last-child { display: grid !important; grid-template-columns: 1fr 1fr; }
  #page-marketing > div:has(> #mkt-filter-tabs) > div:last-child > .btn-primary { grid-column: 1 / -1; width: 100% !important; justify-content: center; }

  /* Paginación */
  #app-shell .dt-pagination { flex-wrap: wrap; row-gap: 10px; padding-left: 2px !important; padding-right: 2px !important; }
  #app-shell .dt-pagination > div { margin-left: auto; }

  /* ── TABLAS → TARJETAS ──────────────────────────────────────────
     responsive.js clasifica cada celda: .m-title (nombre), .m-head
     (lo que va arriba a la derecha: n.º o estado), .m-wide (a lo
     ancho), .m-empty (sin dato → se oculta), .m-actions (botones).
     La tarjeta: título + estado arriba, datos en 2 columnas (etiqueta
     chica arriba, valor abajo) y acciones al pie. La tarjeta que
     envolvía la tabla se vuelve transparente: nada de tarjeta dentro
     de tarjeta. */
  #app-shell .section-card:has(.data-table.m-cards) { background: none !important; border: 0 !important; box-shadow: none !important; overflow: visible !important; }
  #app-shell .section-card:has(.data-table.m-cards) > .section-card-header { padding-left: 2px !important; padding-right: 2px !important; border-bottom: 0 !important; }
  #app-shell .section-card-body:has(> .data-table.m-cards) { overflow-x: visible !important; padding: 0 !important; }
  #app-shell .data-table.m-cards { display: block; width: 100%; min-width: 0 !important; border: 0; background: none; }
  #app-shell .data-table.m-cards thead { display: none; }
  #app-shell .data-table.m-cards tbody { display: flex; flex-direction: column; gap: 10px; padding: 0; }
  #app-shell .data-table.m-cards tbody tr {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 16px; row-gap: 12px;
    position: relative; margin: 0; padding: 15px 16px 14px;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 16px -12px rgba(16, 24, 40, .18);
  }
  #app-shell .data-table.m-cards tbody tr:hover { background: var(--bg-card); }
  #app-shell .data-table.m-cards tbody tr[onclick]:active { transform: scale(.995); }
  #app-shell .data-table.m-cards tbody td {
    display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 3px;
    padding: 0 !important; border: 0 !important; width: auto !important; max-width: none !important; min-width: 0;
    text-align: left !important; font-size: 13.5px; font-weight: 600; color: var(--text-primary); white-space: normal !important;
    overflow: hidden; text-overflow: ellipsis; line-height: 1.3;
  }
  #app-shell .data-table.m-cards tbody td::before {
    content: attr(data-label); font-size: 11px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--text-muted);
  }
  #app-shell .data-table.m-cards tbody td[data-label=""]::before { display: none; }
  #app-shell .data-table.m-cards tbody td:empty,
  #app-shell .data-table.m-cards tbody td.m-empty { display: none; }
  #app-shell .data-table.m-cards tbody td.m-wide { grid-column: 1 / -1; }
  #app-shell .data-table.m-cards tbody td .dt-email { font-size: 12px; font-weight: 500; }
  #app-shell .data-table.m-cards .m-dash { display: none !important; }

  /* Encabezado de la tarjeta */
  #app-shell .data-table.m-cards tbody td.m-title {
    display: block; grid-column: 1 / -1; grid-row: 1; font-size: 15px; font-weight: 800; letter-spacing: -.01em; line-height: 1.25;
    overflow-wrap: anywhere;
  }
  #app-shell .data-table.m-cards tbody td.m-title a { overflow-wrap: anywhere; }
  #app-shell .data-table.m-cards tbody tr.m-has-head td.m-title { grid-column: 1; }
  #app-shell .data-table.m-cards tbody td.m-title::before { display: none; }
  #app-shell .data-table.m-cards tbody td.m-title .dt-avatar { width: 36px; height: 36px; font-size: 13px; }
  #app-shell .data-table.m-cards tbody td.m-title .dt-name { font-size: 15px; font-weight: 800; }
  #app-shell .data-table.m-cards tbody td.m-title .dns-status { margin-top: 6px !important; flex-wrap: wrap; }
  #app-shell .data-table.m-cards tbody td.m-head {
    grid-column: 2; grid-row: 1; justify-self: end; align-self: start; align-items: flex-end; text-align: right !important;
  }
  #app-shell .data-table.m-cards tbody td.m-head::before { display: none; }
  /* línea fina bajo el encabezado */
  #app-shell .data-table.m-cards tbody tr::after {
    content: ""; grid-column: 1 / -1; grid-row: 2; height: 1px; background: var(--border); margin: -2px 0;
  }

  /* Acciones al pie: íconos sin caja, alineados a la derecha */
  #app-shell .data-table.m-cards tbody td.m-actions {
    grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; align-items: center;
    padding-top: 10px !important; margin-top: 0; border-top: 1px solid var(--border) !important; overflow: visible;
  }
  #app-shell .data-table.m-cards tbody td.m-actions::before { display: none; }
  #app-shell .data-table.m-cards tbody td.m-actions .dt-actions { justify-content: flex-end; flex-wrap: wrap; gap: 6px; padding: 0 !important; }
  #app-shell .data-table.m-cards tbody td.m-actions .dt-icon-btn {
    width: 38px; height: 38px; border: 0 !important; border-radius: 11px; background: var(--bg-app);
  }

  /* Filas vacías / "Cargando…" no son tarjetas */
  #app-shell .data-table.m-cards tbody tr.m-plain { display: block; background: none; border: 0; box-shadow: none; padding: 0; }
  #app-shell .data-table.m-cards tbody tr.m-plain::after { display: none; }
  #app-shell .data-table.m-cards tbody tr.m-plain td { display: block; text-align: center !important; padding: 28px 8px !important; color: var(--text-muted); font-weight: 500; }
  #app-shell .data-table.m-cards tbody tr.m-plain td::before { display: none; }

  /* ── Pasarela de pago: nombre arriba, controles abajo (antes se pisaban) ── */
  #app-shell .gw-card { flex-wrap: wrap; padding: 14px !important; gap: 12px !important; }
  #app-shell .gw-card .gw-info { flex: 1 1 calc(100% - 60px); }
  #app-shell .gw-card .gw-name { white-space: normal; line-height: 1.25; }
  #app-shell .gw-card .gw-actions { flex: 1 1 100%; justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--border); }
  #app-shell .gw-card .gw-actions .gw-toggle { margin-right: auto; }
  #app-shell .gw-card .gw-actions .dt-icon-btn { width: 38px; height: 38px; border: 0; background: var(--bg-app); border-radius: 11px; }

  /* ── Ganchos de venta: tarjeta compacta ── */
  #app-shell .pb-camp-card { padding: 16px !important; border-radius: 18px !important; }
  #app-shell .pb-camp-row { gap: 14px !important; }
  #app-shell .pb-camp-col-name { flex: 0 0 auto !important; min-width: 0 !important; padding-right: 56px; }
  #app-shell .pb-camp-name { white-space: normal; font-size: 16px; }
  #app-shell .pb-camp-card .pb-camp-actions > .switch { position: absolute; top: 16px; right: 16px; margin: 0 !important; }
  #app-shell .pb-stats-row { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 0 !important; width: 100%;
    border: 1px solid var(--border); border-radius: 12px; background: var(--bg-card); overflow: hidden; }
  #app-shell .pb-stats-row .pb-stat { background: none !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important;
    padding: 9px 4px !important; min-width: 0 !important; text-align: center; }
  #app-shell .pb-stats-row .pb-stat + .pb-stat { border-left: 1px solid var(--border) !important; }
  #app-shell .pb-camp-actions { display: grid !important; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px !important; width: 100%; margin: 0 !important; }
  #app-shell .pb-camp-actions > .btn-secondary {
    display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 9px 2px !important; font-size: 11px !important;
    border: 0 !important; background: var(--bg-app) !important; border-radius: 12px !important; box-shadow: none !important; min-width: 0;
  }
  #app-shell .pb-camp-actions > .btn-secondary .icon { width: 17px; height: 17px; margin: 0; }
  #app-shell .pb-camp-assign-block { margin-top: 12px !important; }

  /* ── Tienda: la columna de edición nunca más ancha que la pantalla ── */
  #app-shell .store-workspace, #app-shell .store-workspace > * { min-width: 0; max-width: 100%; }
  #app-shell #store-section-menu .section-card > div:not(.section-card-header) { padding: 14px !important; }
  #app-shell #store-menu-items-list, #app-shell #store-menu-items-list * { max-width: 100%; box-sizing: border-box; }
  #app-shell #store-section-menu .section-card > div > div:last-child { flex-wrap: wrap; }
  #app-shell #store-section-menu .section-card > div > div:last-child > button { flex: 1 1 auto; justify-content: center; }

  /* ── Formularios: nunca más anchos que la pantalla ── */
  #app-shell .form-input, #app-shell select.form-input { max-width: 100%; }
  #app-shell .section-card { max-width: 100%; }
}
