/* ============================================================
   1. BARRA DE SELECCIÓN (Ver selección / Agregar al carrito)
   ============================================================ */
.selection-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

/* Móvil: una columna, la acción principal primero */
.selection-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .5rem;
    width: 100%;
}
.selection-actions .btn,
.selection-actions .btn-add-selected {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    width: 100%;
    min-height: 46px;
    margin: 0;                 /* anula el margin-top:1rem de .btn-add-selected en ≤768px */
    font-size: .95rem;
    line-height: 1.2;
    text-align: center;
}
.selection-actions .btn-add-selected { order: -1; }
.selection-actions i { margin: 0 !important; }

@media (max-width: 360px) {
    .selection-actions .btn,
    .selection-actions .btn-add-selected {
        font-size: .85rem;
        padding-left: .5rem;
        padding-right: .5rem;
    }
}

/* ≥576px: botones en línea */
@media (min-width: 576px) {
    .selection-actions { display: flex; width: auto; }
    .selection-actions .btn,
    .selection-actions .btn-add-selected {
        width: auto;
        min-height: 40px;
        font-size: 1rem;
        white-space: nowrap;
    }
    .selection-actions .btn-add-selected { order: 0; }
}


/* ============================================================
   2. TABLA AVANZADA — BASE (escritorio ≥1400px)
   ============================================================ */
.table-avanzada th,
.table-avanzada td { vertical-align: middle; }

.table-avanzada .td-anio,
.table-avanzada .td-codigo { white-space: nowrap; }

.table-avanzada .cantidad-input { width: 70px; text-align: center; }

.table-avanzada .select-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    margin: 0;
    cursor: pointer;
}
.table-avanzada .select-all-text { display: none; }

/* Nombre y descripción más legibles */
.table-avanzada > tbody > tr > td.product-name,
.table-avanzada > tbody > tr > td.product-name a {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
}
.table-avanzada > tbody > tr > td.product-description small {
    font-size: .9rem;
    line-height: 1.35;
    color: #495057;
}


/* ============================================================
   3. TABLET / LAPTOP (768–1399px): tabla compacta sin descripción
   ============================================================ */
@media (min-width: 768px) and (max-width: 1399.98px) {
    .table-avanzada { font-size: .85rem; }
    .table-avanzada > :not(caption) > * > * { padding: .4rem .45rem; }

    .table-avanzada .col-descripcion { display: none; }

    .table-avanzada > tbody > tr > td.product-name { min-width: 170px; }
    .table-avanzada > tbody > tr > td.product-name,
    .table-avanzada > tbody > tr > td.product-name a { font-size: .95rem; }

    .table-avanzada .td-precio { min-width: 110px; }
}

/* ============================================================
   3b. ESCRITORIO (≥1400px): el contenedor se queda en 1400px,
   así que la tabla debe repartirse en ~960px con anchos fijos
   ============================================================ */
@media (min-width: 1400px) {
    .table-avanzada {
        table-layout: fixed;
        width: 100%;
        font-size: .85rem;
    }
    .table-avanzada > :not(caption) > * > * { padding: .5rem .4rem; }

    .table-avanzada .td-anio,
    .table-avanzada .td-codigo,
    .table-avanzada thead th { white-space: normal; }

    .table-avanzada td { overflow-wrap: anywhere; }

    /* Anchos por columna */
    .table-avanzada > thead > tr > th:nth-child(1) { width: 48px; }   /* check */
    .table-avanzada > thead > tr > th:nth-child(2),
    .table-avanzada > thead > tr > th:nth-child(3) { width: 62px; }   /* año i / año f */
    .table-avanzada > thead > tr > th:nth-child(4) { width: 150px; }  /* producto */
    /* 5 = descripción → auto (toma lo que sobra) */
    .table-avanzada > thead > tr > th:nth-child(6) { width: 90px; }   /* marca */
    .table-avanzada > thead > tr > th:nth-child(7) { width: 130px; }  /* código */
    .table-avanzada > thead > tr > th:nth-child(8) { width: 100px; }  /* stock */
    .table-avanzada > thead > tr > th:nth-child(9) { width: 115px; }  /* precio */

    .table-avanzada > tbody > tr > td.product-name,
    .table-avanzada > tbody > tr > td.product-name a { font-size: .95rem; }
    .table-avanzada > tbody > tr > td.product-description small { font-size: .85rem; }

    .table-avanzada .cantidad-input { width: 100%; max-width: 70px; }
    .table-avanzada .select-unidad  { width: 100%; }

    .table-avanzada .stock-badge,
    .table-avanzada .producto-unidad,
    .table-avanzada .price-value,
    .table-avanzada .price-original {
        white-space: nowrap;
        overflow-wrap: normal;
    }
}


/* ============================================================
   4. MÓVIL (<768px): cada fila = tarjeta
   ============================================================ */
@media (max-width: 767.98px) {

    /* Menos relleno lateral para aprovechar el ancho */
    .table-container { padding: .75rem; }

    .table-avanzada,
    .table-avanzada > tbody { display: block; width: 100%; }

    /* --- thead: se reduce a la barra "Seleccionar todos" --- */
    .table-avanzada > thead { display: block; margin-bottom: .6rem; }
    .table-avanzada > thead > tr {
        display: block;
        padding: .6rem .85rem;
        background: #f8f9fa;
        border: 1px solid #dee2e6;
        border-radius: .6rem;
    }
    .table-avanzada > thead > tr > th { display: none; }
    .table-avanzada > thead > tr > th:first-child {
        display: block;
        padding: 0;
        border: 0;
        text-align: left;
        white-space: normal;
        /* anula `.table thead th` (fondo azul + texto blanco) */
        background: transparent !important;
        color: #212529 !important;
        box-shadow: none !important;
    }
    .table-avanzada .select-all { justify-content: flex-start; min-height: 32px; }
    .table-avanzada .select-all-text {
        display: inline;
        font-size: .9rem;
        font-weight: 600;
        color: #212529;
    }

    /* --- tarjeta --- */
    .table-avanzada > tbody > tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: .6rem .75rem;
        position: relative;
        margin-bottom: .75rem;
        padding: .85rem;
        background: #fff;
        border: 1px solid #dee2e6;
        border-radius: .6rem;
    }
    /* Sin stock: ya lo pinta `table tbody tr.out-of-stock` (rosa + opacidad) en el CSS base */

    .table-avanzada > tbody > tr > td {
        display: block;
        min-width: 0;
        padding: 0;
        border: 0;
        background: transparent;
        box-shadow: none;            /* anula el striped de Bootstrap */
        text-align: left;
    }
    .table-avanzada > tbody > tr > td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: .15rem;
        font-size: .68rem;
        font-weight: 600;
        letter-spacing: .03em;
        text-transform: uppercase;
        color: #6c757d;
    }

    /* Checkbox arriba a la derecha */
    .table-avanzada > tbody > tr > td.td-check {
        position: absolute;
        top: .85rem;
        right: .85rem;
    }
    .table-avanzada .product-checkbox { width: 1.3rem; height: 1.3rem; }

    /* Nombre y descripción: ancho completo, primero */
    .table-avanzada > tbody > tr > td.product-name,
    .table-avanzada > tbody > tr > td.product-description {
        grid-column: 1 / -1;
        max-width: none;             /* anula max-width:200–300px de `.table tbody td.product-*` */
    }
    .table-avanzada > tbody > tr > td.product-name {
        order: -2;
        padding-right: 2rem;         /* espacio para el checkbox */
    }
    .table-avanzada > tbody > tr > td.product-description { order: -1; }
    .table-avanzada > tbody > tr > td.product-name::before,
    .table-avanzada > tbody > tr > td.product-description::before { display: none; }

    .table-avanzada > tbody > tr > td.product-name,
    .table-avanzada > tbody > tr > td.product-name a { font-size: 1.05rem; }

    .table-avanzada > tbody > tr > td.product-description small {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        overflow: hidden;
        font-size: .92rem;
    }

    /* Stock y precio alineados a la izquierda dentro de la tarjeta */
    .table-avanzada .stock-box,
    .table-avanzada .price-box { align-items: flex-start !important; }
    .table-avanzada .td-precio .producto-unidad { align-self: flex-start; }
    .table-avanzada .td-precio .select-unidad { max-width: 150px; }
    .table-avanzada .cantidad-input { width: 90px; }
}


/* ============================================================
   5. MODAL "PRODUCTOS SELECCIONADOS" (<576px): filas en tarjetas
   El prefijo #selectionModal es necesario: custom-tienda-avanzada.css
   tiene `#selectionModal .table td { padding... }` con id.
   ============================================================ */
#selectionModal .table-seleccion td.sel-producto strong { font-size: 1rem; }
#selectionModal .table-seleccion td.sel-producto small  { font-size: .85rem; }

@media (max-width: 575.98px) {
    #selectionModal .table-seleccion,
    #selectionModal .table-seleccion > tbody { display: block; width: 100%; }

    /* el total ya está en el footer del modal */
    #selectionModal .table-seleccion > thead,
    #selectionModal .table-seleccion > tfoot { display: none; }

    #selectionModal .table-seleccion > tbody > tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: .5rem .75rem;
        margin-bottom: .75rem;
        padding: .75rem;
        background: #fff;
        border: 1px solid #dee2e6;
        border-radius: .6rem;
    }
    #selectionModal .table-seleccion > tbody > tr > td {
        display: block;
        padding: 0;
        border: 0;
        background: transparent;
        box-shadow: none;
        text-align: left !important;
    }
    #selectionModal .table-seleccion td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: .68rem;
        font-weight: 600;
        text-transform: uppercase;
        color: #6c757d;
    }
    #selectionModal .table-seleccion td.sel-producto { grid-column: 1 / -1; }
    #selectionModal .table-seleccion td.sel-accion   { justify-self: end; align-self: end; }

    /* anula `#selectionModal .modal-cantidad-input { width:60px !important }` */
    #selectionModal .table-seleccion .modal-cantidad-input {
        width: 90px !important;
        margin: 0 !important;
    }
}