/* ==========================================================================
   Tienda Online - Módulo de carrito
   Extiende las variables definidas en main.css (:root)
   ========================================================================== */

.cart-title {
    font-size: 1.9rem;
    margin: 0 0 20px;
}

/* El atributo hidden debe ganar a los display de las clases. */
.cart-layout[hidden],
.cart-empty[hidden] {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Layout: items + resumen (2 columnas, 1 en móvil)
   -------------------------------------------------------------------------- */
.cart-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 28px;
    align-items: start;
}

.cart-items {
    display: flex;
    flex-direction: column;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Fila de artículo
   -------------------------------------------------------------------------- */
.cart-item {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr) auto auto auto;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.cart-item:last-child {
    border-bottom: 0;
}

.cart-item-media {
    width: 84px;
    height: 84px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.cart-item-media .img-initials {
    font-size: 1.6rem;
}

.cart-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.cart-item-name {
    font-weight: 600;
    color: var(--dark);
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.cart-item-name:hover {
    color: var(--primary);
    text-decoration: none;
}

.cart-item-variant {
    font-size: 0.85rem;
    color: var(--muted);
}

.cart-item-unit {
    font-size: 0.85rem;
    color: var(--muted);
}

.cart-item-total {
    font-weight: 700;
    color: var(--dark);
    white-space: nowrap;
    min-width: 84px;
    text-align: right;
}

/* --------------------------------------------------------------------------
   Selector de cantidad
   -------------------------------------------------------------------------- */
.cart-item-qty {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--white);
}

.cart-item-qty .qty-btn {
    width: 34px;
    height: 38px;
    border: 0;
    background: transparent;
    color: var(--dark);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease;
}

.cart-item-qty .qty-btn:hover {
    background: var(--bg);
}

.cart-item-qty .qty-input {
    width: 52px;
    height: 38px;
    padding: 0 4px;
    border: 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-radius: 0;
    text-align: center;
    font-weight: 600;
    -moz-appearance: textfield;
    appearance: textfield;
}

.cart-item-qty .qty-input::-webkit-outer-spin-button,
.cart-item-qty .qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* --------------------------------------------------------------------------
   Botón eliminar
   -------------------------------------------------------------------------- */
.cart-item-remove {
    width: 34px;
    height: 34px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.cart-item-remove:hover {
    background: #fee2e2;
    color: var(--danger);
}

.cart-item-remove:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Resumen sticky
   -------------------------------------------------------------------------- */
.cart-summary {
    position: sticky;
    top: 88px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 22px;
}

.cart-summary h2 {
    font-size: 1.15rem;
    margin: 0 0 16px;
}

.summary-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
    font-size: 1.05rem;
}

.summary-row strong {
    font-size: 1.3rem;
}

.summary-note {
    color: var(--muted);
    font-size: 0.82rem;
    margin: 0 0 16px;
}

.cart-summary .btn-block + .btn-block {
    margin-top: 10px;
}

/* --------------------------------------------------------------------------
   Estado vacío
   -------------------------------------------------------------------------- */
.cart-empty {
    text-align: center;
    padding: 56px 24px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.cart-empty-icon {
    display: block;
    font-size: 3rem;
    margin-bottom: 8px;
}

.cart-empty h2 {
    margin: 0 0 6px;
}

.cart-empty p {
    margin: 0 0 20px;
}

/* --------------------------------------------------------------------------
   Animación del contador del header
   -------------------------------------------------------------------------- */
#cart-count.is-bump {
    animation: cart-count-bump 0.5s ease;
}

@keyframes cart-count-bump {
    0% {
        transform: scale(1);
    }

    35% {
        transform: scale(1.45);
    }

    100% {
        transform: scale(1);
    }
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
    .cart-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .cart-summary {
        position: static;
    }
}

@media (max-width: 640px) {
    .cart-item {
        grid-template-columns: 72px minmax(0, 1fr);
        grid-template-areas:
            "media info"
            "qty   total"
            "remove remove";
        gap: 12px 14px;
    }

    .cart-item-media {
        grid-area: media;
        width: 72px;
        height: 72px;
    }

    .cart-item-info {
        grid-area: info;
    }

    .cart-item-qty {
        grid-area: qty;
        justify-self: start;
    }

    .cart-item-total {
        grid-area: total;
        align-self: center;
        text-align: right;
    }

    .cart-item-remove {
        grid-area: remove;
        justify-self: end;
    }
}
