
/* Búsqueda comercial: las filas conservan la tabla en escritorio y se leen
 * como tarjetas táctiles en móvil, sin una segunda barra horizontal. */
.commercial-card-details {
  display: none;
}

@media (max-width: 768px) {
  .commercial-search-primary {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .commercial-search-primary input[type="search"] {
    grid-column: 1 / -1;
    min-height: 48px;
  }

  .commercial-sort-field {
    min-width: 0;
  }

  .commercial-action-buttons {
    align-self: end;
  }

  .commercial-filter-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .commercial-search-form.is-enhanced .commercial-native-control {
    clip: auto;
    clip-path: none;
    height: auto;
    margin: 0;
    overflow: visible;
    position: static;
    white-space: normal;
    width: 100%;
  }

  .commercial-search-form.is-enhanced .commercial-chip-field:not(.commercial-section-order-wrap) {
    display: none;
  }

  .commercial-section-order-wrap {
    display: block;
    grid-column: 1 / -1;
    min-width: 0;
  }

  .commercial-section-order-wrap.is-hidden {
    display: none;
  }

  .commercial-section-order-wrap .commercial-filter-label,
  .commercial-section-order-wrap .commercial-chip-group {
    display: none !important;
  }

  .commercial-rule-summary-values {
    display: none;
  }

  .commercial-rule-details summary::after {
    color: var(--muted);
    content: "Mostrar ajustes";
    font-size: 12px;
    font-weight: 800;
  }

  .commercial-rule-details[open] summary::after {
    content: "Ocultar ajustes";
  }

  .commercial-results-responsive {
    overflow: visible;
  }

  .commercial-results-table {
    display: block;
    min-width: 0;
    overflow: visible;
    white-space: normal;
    width: 100%;
  }

  .commercial-results-table thead {
    display: none;
  }

  .commercial-results-table tbody {
    display: grid;
    gap: 12px;
  }

  .commercial-results-table tbody tr {
    display: grid;
    gap: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--color-surface, #fff);
    box-shadow: 0 5px 14px rgba(12, 42, 26, 0.07);
  }

  .commercial-results-table tbody td {
    display: block;
    min-width: 0;
    padding: 12px;
    border: 0;
    border-bottom: 1px solid rgba(23, 52, 36, 0.09);
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .commercial-results-table tbody td[colspan] {
    grid-column: 1 / -1;
  }

  .commercial-results-table tbody td::before {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
  }

  .commercial-unified-results-table td:nth-child(1),
  .commercial-unified-results-table td:nth-child(3),
  .commercial-unified-results-table td:nth-child(9),
  .commercial-products-results-table td:nth-child(2),
  .commercial-products-results-table td:nth-child(7),
  .commercial-products-results-table td:nth-child(8),
  .commercial-provider-results-table td:nth-child(1),
  .commercial-provider-results-table td:nth-child(3),
  .commercial-provider-results-table td:nth-child(8) {
    grid-column: 1 / -1;
  }

  .commercial-unified-results-table td:nth-child(1) { order: 1; }
  .commercial-unified-results-table td:nth-child(8) { order: 2; }
  .commercial-unified-results-table td:nth-child(3) { order: 3; }
  .commercial-unified-results-table td:nth-child(4) { order: 4; }
  .commercial-unified-results-table td:nth-child(5) { order: 5; }
  .commercial-unified-results-table td:nth-child(6) { order: 6; }
  .commercial-unified-results-table td:nth-child(7) { order: 7; }
  .commercial-unified-results-table td:nth-child(2) { order: 8; }
  .commercial-unified-results-table td:nth-child(9) { order: 9; }

  .commercial-products-results-table td:nth-child(7) { order: 1; }
  .commercial-products-results-table td:nth-child(1) { order: 2; }
  .commercial-products-results-table td:nth-child(2) { order: 3; }
  .commercial-products-results-table td:nth-child(3) { order: 4; }
  .commercial-products-results-table td:nth-child(4) { order: 5; }
  .commercial-products-results-table td:nth-child(5) { order: 6; }
  .commercial-products-results-table td:nth-child(6) { order: 7; }
  .commercial-products-results-table td:nth-child(8) { order: 8; }

  .commercial-provider-results-table td:nth-child(1) { order: 1; }
  .commercial-provider-results-table td:nth-child(3) { order: 2; }
  .commercial-provider-results-table td:nth-child(2) { order: 3; }
  .commercial-provider-results-table td:nth-child(4) { order: 4; }
  .commercial-provider-results-table td:nth-child(5) { order: 5; }
  .commercial-provider-results-table td:nth-child(6) { order: 6; }
  .commercial-provider-results-table td:nth-child(7) { order: 7; }
  .commercial-provider-results-table td:nth-child(8) { order: 8; }

  .commercial-unified-results-table td:nth-child(5)::before,
  .commercial-products-results-table td:nth-child(4)::before,
  .commercial-provider-results-table td:nth-child(5)::before {
    content: "Stock";
  }

  .commercial-unified-results-table td:nth-child(6)::before,
  .commercial-products-results-table td:nth-child(5)::before,
  .commercial-provider-results-table td:nth-child(6)::before {
    content: "Costo / referencia";
  }

  .commercial-unified-results-table td:nth-child(7)::before,
  .commercial-products-results-table td:nth-child(6)::before,
  .commercial-provider-results-table td:nth-child(7)::before {
    content: "Precio sugerido · IGV incluido";
  }

  .commercial-unified-results-table td:nth-child(8)::before,
  .commercial-products-results-table td:nth-child(7)::before {
    content: "Disponibilidad y estado";
  }

  .commercial-unified-results-table td:nth-child(9)::before,
  .commercial-products-results-table td:nth-child(8)::before,
  .commercial-provider-results-table td:nth-child(8)::before {
    content: "Acciones";
  }

  .commercial-source-cell {
    min-width: 0;
  }

  .commercial-source {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px 10px;
  }

  .commercial-source-logo,
  .commercial-source-placeholder {
    grid-row: span 3;
    width: 74px;
    height: 38px;
  }

  .commercial-desktop-secondary {
    display: none;
  }

  .commercial-card-details {
    display: block;
    margin-top: 9px;
    padding-top: 9px;
    border-top: 1px solid rgba(23, 52, 36, 0.1);
  }

  .commercial-card-details summary,
  .commercial-card-secondary-actions summary {
    cursor: pointer;
    color: var(--green-dark);
    font-size: 13px;
    font-weight: 850;
  }

  .commercial-card-details p {
    margin: 8px 0 0;
  }

  .commercial-card-relation-details {
    border-top: 0;
    padding-top: 6px;
  }

  .commercial-result-actions {
    border-bottom: 0 !important;
  }

  .commercial-result-action-group,
  .commercial-result-action-group.offer-action-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
  }

  .commercial-result-action-group .icon-button,
  .commercial-result-action-group .commercial-card-primary-unavailable {
    display: inline-flex;
    justify-content: flex-start;
    min-height: 44px;
    width: 100%;
    padding: 9px 12px;
  }

  .commercial-result-action-group .icon-button::after,
  .commercial-result-action-group .commercial-card-primary-unavailable::after {
    margin-left: 8px;
    content: attr(aria-label);
    font-size: 13px;
    font-weight: 800;
  }

  .commercial-result-action-group .icon-button:not(:first-child) {
    background: #f8fbf9;
    border-color: var(--line);
    color: var(--ink);
  }
}

/* Búsqueda comercial móvil: composición independiente de la tabla de escritorio.
 * Las tarjetas usan los mismos datos, pero priorizan la decisión comercial y un
 * único control principal sin reordenar celdas de tabla. */
.commercial-mobile-results {
  display: none;
}

@media (max-width: 768px) {
  .catalog-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .catalog-tools .button {
    align-items: center;
    display: inline-flex;
    justify-content: center;
    min-height: 44px;
    min-width: 0;
    text-align: center;
  }

  .catalog-tools .button:not(.secondary) {
    grid-column: 1 / -1;
  }

  .commercial-search-card,
  .commercial-results-card {
    min-width: 0;
  }

  .commercial-search-primary {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

  .commercial-search-primary input[type="search"] {
    grid-column: 1 / -1;
  }

  .commercial-sort-field {
    min-width: 0;
  }

  .commercial-sort-field select,
  .commercial-native-control,
  .commercial-search-button,
  .commercial-reset-button {
    min-height: 44px;
  }

  .commercial-action-buttons {
    gap: 8px;
  }

  .commercial-filter-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .commercial-section-order-wrap {
    grid-column: 1 / -1;
  }

  .commercial-rule-details summary {
    align-items: center;
    gap: 8px;
    min-height: 44px;
  }

  .commercial-rule-summary-values {
    display: none;
  }

  .commercial-results-responsive {
    display: none;
  }

  .commercial-mobile-results {
    display: grid;
    gap: 12px;
    min-width: 0;
  }

  .commercial-mobile-card,
  .commercial-mobile-empty-state {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .commercial-mobile-card {
    display: grid;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--color-surface, #fff);
    box-shadow: 0 5px 14px rgba(12, 42, 26, 0.07);
    padding: 14px;
  }

  .commercial-mobile-card-header {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    min-width: 0;
  }

  .commercial-mobile-product-media,
  .commercial-mobile-product-media img,
  .commercial-mobile-product-media span {
    width: 58px;
    height: 58px;
  }

  .commercial-mobile-product-media {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f3f7f5;
  }

  .commercial-mobile-product-media img {
    display: block;
    object-fit: contain;
  }

  .commercial-mobile-product-media span {
    display: grid;
    place-items: center;
    color: var(--green-dark);
    font-size: 1.2rem;
    font-weight: 900;
  }

  .commercial-mobile-product-identity {
    min-width: 0;
  }

  .commercial-mobile-card-type,
  .commercial-mobile-product-identity h3,
  .commercial-mobile-product-identity p {
    margin: 0;
  }

  .commercial-mobile-card-type {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 850;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .commercial-mobile-product-identity h3 {
    color: var(--ink);
    font-size: 1rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .commercial-mobile-identifiers {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.79rem;
    font-weight: 750;
  }

  .commercial-mobile-sku {
    color: var(--green-dark);
    font-weight: 900;
  }

  .commercial-mobile-sku.is-unlinked {
    color: #9a6700;
  }

  .commercial-mobile-decision {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(92px, auto);
    gap: 12px;
    min-width: 0;
    border-block: 1px solid rgba(23, 52, 36, 0.1);
    padding-block: 12px;
  }

  .commercial-mobile-price,
  .commercial-mobile-availability,
  .commercial-mobile-context > div {
    display: grid;
    align-content: start;
    gap: 3px;
    min-width: 0;
  }

  .commercial-mobile-price > span,
  .commercial-mobile-availability > span:last-child,
  .commercial-mobile-context span,
  .commercial-mobile-context small {
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.3;
  }

  .commercial-mobile-price > strong {
    color: var(--ink);
    font-size: 1.2rem;
    line-height: 1.18;
    overflow-wrap: anywhere;
  }

  .commercial-mobile-price small {
    color: #53675b;
    font-size: 0.82rem;
    font-weight: 800;
  }

  .commercial-mobile-availability {
    justify-items: end;
    text-align: right;
  }

  .commercial-mobile-availability strong {
    color: var(--ink);
    font-size: 1rem;
  }

  .commercial-mobile-context {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .commercial-mobile-context strong,
  .commercial-mobile-provider-details dd {
    color: var(--ink);
    font-size: 0.88rem;
    overflow-wrap: anywhere;
  }

  .commercial-mobile-provider-details,
  .commercial-card-secondary-actions {
    border-top: 1px solid rgba(23, 52, 36, 0.1);
    padding-top: 4px;
  }

  .commercial-mobile-provider-details summary,
  .commercial-card-secondary-actions summary {
    align-items: center;
    color: var(--green-dark);
    cursor: pointer;
    display: flex;
    font-size: 0.88rem;
    font-weight: 850;
    min-height: 44px;
  }

  .commercial-mobile-provider-details dl {
    display: grid;
    gap: 10px;
    margin: 4px 0 10px;
  }

  .commercial-mobile-provider-details dl > div {
    display: grid;
    gap: 2px;
  }

  .commercial-mobile-provider-details dt {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 850;
  }

  .commercial-mobile-provider-details dd {
    margin: 0;
  }

  .commercial-mobile-card-actions {
    display: grid;
    gap: 8px;
  }

  .commercial-mobile-primary-action,
  .commercial-mobile-primary-unavailable,
  .commercial-mobile-secondary-action-list .button {
    align-items: center;
    box-sizing: border-box;
    display: inline-flex;
    justify-content: center;
    min-height: 44px;
    width: 100%;
  }

  .commercial-mobile-primary-unavailable {
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 750;
  }

  .commercial-mobile-secondary-action-list {
    display: grid;
    gap: 8px;
    padding: 4px 0 8px;
  }

  .commercial-mobile-empty-state {
    border: 1px dashed var(--line);
    border-radius: 16px;
    background: #fbfdfb;
    padding: 18px;
  }

  .commercial-mobile-empty-state p {
    margin-bottom: 0;
  }

  .commercial-mobile-card a:focus-visible,
  .commercial-mobile-card button:focus-visible,
  .commercial-mobile-card summary:focus-visible,
  .commercial-search-form select:focus-visible {
    outline: 3px solid var(--focus-ring-color);
    outline-offset: 3px;
  }
}

@media (max-width: 380px) {
  .catalog-tools {
    grid-template-columns: 1fr;
  }

  .catalog-tools .button:not(.secondary) {
    grid-column: auto;
  }

  .commercial-mobile-card {
    padding: 12px;
  }

  .commercial-mobile-decision,
  .commercial-mobile-context {
    grid-template-columns: 1fr;
  }

  .commercial-mobile-availability {
    justify-items: start;
    text-align: left;
  }
}
