/* Módulo: carrito + botones flotantes
   Parciales asociados:
   - resources/views/catalogo/partials/carrito.blade.php
   - resources/views/catalogo/partials/flotantes.blade.php
   Responsabilidad:
   - panel #carrito-flotante, lista, totales, .btn-confirmar
   - .boton-flotante, .boton-whatsapp-flotante (z-index 10000, safe-area inferior)
   Z-index: carrito 9998 (por debajo de .modal-overlay 10000 y flotantes)
*/
/* ==========================================
   PEDIFACIL PREMIUM CART CONTAINER
   Solo “carrocería” del panel; ítems sin cambios.
========================================== */

.carrito-flotante {
    position: fixed;
    top: calc(24px + env(safe-area-inset-top, 0px));
    right: calc(24px + env(safe-area-inset-right, 0px));
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    width: 90%;
    max-width: 342px;
    width: calc(100vw - 48px);
    max-width: 390px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 30px 30px 14px 30px;
    overflow: hidden;
    box-shadow:
        0 20px 45px rgba(0, 0, 0, 0.08),
        0 40px 90px rgba(0, 0, 0, 0.10);
    transform: translateX(calc(100% + 32px));
    opacity: 0;
    pointer-events: none;
    transition:
        transform 0.35s ease,
        opacity 0.30s ease,
        box-shadow 0.35s ease;
    z-index: 9999;
}

.carrito-flotante.activo {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.carrito-header {
    flex-shrink: 0;
    min-height: 90px;
    padding: 20px 18px 18px 22px;
    background: linear-gradient(165deg, #cd0220 0%, #cd0220 42%, #9e0118 100%);
    color: #fff;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 16px rgba(158, 1, 24, 0.22);
}

.carrito-header__text {
    flex: 1;
    min-width: 0;
    padding-top: 2px;
}

.carrito-header h4 {
    margin: 0 0 5px;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.carrito-header h4 i {
    opacity: 0.92;
}

.carrito-header__subtitulo {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 0.01em;
}

.carrito-header__cerrar {
    width: 40px;
    height: 40px;
    margin-top: 2px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.carrito-header__cerrar:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.28);
}

.carrito-header__cerrar:active {
    transform: scale(0.94);
}

#listaCarrito,
.lista-carrito {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    padding: 18px 22px;
}

.item-carrito {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    border-bottom: 1px solid #eee;
    padding: 12px 0;
    gap: 12px;
}

.img-miniatura {
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}

.img-miniatura img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid #f3f4f6;
    display: block;
}

.item-carrito .info {
    flex: 1;
    min-width: 0;
}

.item-carrito .info strong {
    display: block;
    font-size: 0.95rem;
    color: #222;
    margin-bottom: 4px;
    font-weight: 600;
}

.item-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 4px;
    min-width: 0;
}

.item-nombre-principal {
    display: block;
    color: #222;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.25;
    min-width: 0;
    white-space: normal;
    word-break: break-word;
}

.item-nombre-unico {
    font-weight: 700;
}

/* Badge descuento — píldora plana (solo carrito) */
#listaCarrito .badge-descuento {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 2;
    background: #cd0220;
    color: #fff;
    font-weight: 700;
    font-size: 0.62rem;
    padding: 2px 7px;
    border-radius: 999px;
    line-height: 1.35;
    letter-spacing: 0.02em;
    transform: none;
    box-shadow: none;
    border: none;
    pointer-events: none;
}

.item-carrito .info small {
    color: #777;
    font-size: 0.8rem;
    display: block;
    margin-top: 4px;
    font-style: italic;
}

.item-carrito .info small.item-mitad-line {
    min-width: 0;
    max-width: 100%;
}

.item-carrito .info small .fa-pizza-slice {
    color: #777;
    font-size: 0.88em;
    opacity: 0.9;
}

/* Controles de cantidad — cápsula minimalista */
#listaCarrito .cantidad-carrito {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

#listaCarrito .cantidad-carrito__capsule {
    display: inline-flex;
    align-items: center;
    padding: 2px 5px;
    background: #f9fafb;
    border: 1px solid #f3f4f6;
    border-radius: 999px;
}

#listaCarrito .cantidad-carrito__btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #6b7280;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1;
    transition: color 0.2s ease, background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#listaCarrito .cantidad-carrito__btn:hover {
    color: #cd0220;
    background: rgba(205, 2, 32, 0.08);
    transform: none;
}

#listaCarrito .cantidad-carrito__valor {
    min-width: 22px;
    padding: 0 2px;
    text-align: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: #cd0220;
}

.precio-eliminar {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
}

.precio-eliminar p {
    color: var(--rojo);
    font-weight: 700;
    font-size: 1rem;
    margin: 0;
}

#listaCarrito .precio-normal {
    color: #cd0220;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
}

#listaCarrito .precio-original {
    text-decoration: line-through;
    color: #9ca3af;
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.2;
}

#listaCarrito .precio-final {
    color: #cd0220;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
}

.ahorro {
    color: #2e7d32;
    font-size: 0.76rem;
    font-weight: 700;
    line-height: 1.15;
}

#listaCarrito .btn-trash {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 0.82rem;
    transition: color 0.2s ease, background 0.2s ease;
    padding: 0;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 0;
    flex-shrink: 0;
}

#listaCarrito .btn-trash:hover {
    color: #cd0220;
    background: rgba(205, 2, 32, 0.08);
    transform: none;
}

.carrito-footer {
    flex-shrink: 0;
    background: #fff;
    padding: 22px;
    border-top: 1px solid #f0f0f0;
}

.carrito-footer #totalCarrito {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--rojo);
    margin-bottom: 15px;
    text-align: center;
}

.carrito-footer #totalCarrito .total-final {
    font-size: 1.3rem;
    font-weight: 900;
    color: var(--rojo);
}

.carrito-footer #totalCarrito .ahorro-total {
    margin-top: 4px;
    color: #2e7d32;
    font-size: 0.86rem;
    font-weight: 800;
}

.carrito-footer #totalCarrito .total-convertido {
    margin-top: 4px;
    color: #5c6b7a;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.2;
}

.carrito-footer #totalCarrito .carrito-aviso-envio {
    margin-top: 10px;
    margin-bottom: 10px;
    padding: 0 10px;
    font-size: 0.72rem;
    font-style: italic;
    color: #8a8f98;
    line-height: 1.4;
    text-align: center;
    user-select: none;
}

.carrito-footer #totalCarrito .carrito-aviso-envio i {
    margin-right: 4px;
    opacity: 0.65;
    font-size: 0.68rem;
}

.precio-eliminar .precio-convertido {
    font-size: 11px;
    line-height: 1.1;
    font-weight: 600;
    color: #5c6b7a;
    margin-top: 1px;
}

.btn-confirmar {
    width: 100%;
    height: 58px;
    padding: 0 16px;
    border: none;
    border-radius: 18px;
    background: linear-gradient(135deg, #e13030, #b82828);
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.btn-confirmar:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(225, 48, 48, 0.30);
}

.btn-confirmar:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* =========================================
   BOTONES FLOTANTES - safe-area / iOS stacking
   Carrito abajo derecha; móvil sube para no tapar banner PWA.
========================================= */

.boton-flotante,
.boton-whatsapp-flotante {
    position: fixed !important;
    left: auto !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    pointer-events: auto !important;
    /* Por encima del drawer categorías (9999) y overlay (9998) */
    z-index: 10000 !important;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

@keyframes carrito-fab-pulse {
    0%, 100% {
        box-shadow:
            0 8px 25px rgba(0, 0, 0, 0.22),
            0 0 0 0 rgba(211, 47, 47, 0.48);
    }
    50% {
        box-shadow:
            0 10px 30px rgba(0, 0, 0, 0.28),
            0 0 0 14px rgba(211, 47, 47, 0);
    }
}

/* Carrito: abajo derecha */
.boton-flotante {
    bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    right: 16px !important;
    background: var(--rojo);
    color: #fff;
    border: 3px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    width: 76px;
    height: 76px;
    font-size: 1.75rem;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
    flex-direction: column;
}

.boton-flotante:not(.oculto) {
    animation: carrito-fab-pulse 2.4s ease-in-out infinite;
}

.boton-flotante:not(.oculto):hover,
.boton-flotante:not(.oculto):focus-visible {
    animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
    .boton-flotante:not(.oculto) {
        animation: none;
    }
}

.boton-flotante:hover {
    background: var(--rojo-oscuro);
    transform: translateZ(0) scale(1.06);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

.boton-flotante span {
    font-size: 0.8rem;
    background: #fff;
    color: var(--rojo);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    min-width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-top: -4px;
    line-height: 1;
}

.boton-flotante.oculto {
    display: none !important;
}

/* WhatsApp: encima del carrito (60px botón + ~20px aire ≈ 80px) */
.boton-whatsapp-flotante {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    right: 16px !important;
    background: #25d366;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 58px;
    height: 58px;
    font-size: 1.65rem;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
    text-decoration: none;
}

.boton-whatsapp-flotante:hover {
    background: #128c7e;
    transform: translateZ(0) scale(1.06);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
    color: #fff;
}

/* Safari iOS: capa de composición estable (sin !important para no pisar :hover scale) */
@supports (-webkit-touch-callout: none) {
    .boton-flotante,
    .boton-whatsapp-flotante {
        transform: translate3d(0, 0, 0);
        -webkit-transform: translate3d(0, 0, 0);
    }
}

@media (max-width: 768px) {
    .carrito-flotante {
        top: calc(14px + env(safe-area-inset-top, 0px));
        right: calc(14px + env(safe-area-inset-right, 0px));
        left: calc(14px + env(safe-area-inset-left, 0px));
        bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-width: none;
        border-radius: 26px 26px 12px 26px;
    }

    .carrito-flotante:not(.activo) {
        transform: translateY(calc(100% + 28px));
        opacity: 0;
    }

    .carrito-flotante.activo {
        transform: translateY(0);
        opacity: 1;
    }

    .carrito-header {
        padding: 18px 14px 16px 18px;
        min-height: 84px;
    }

    .carrito-header h4 {
        font-size: 1.1rem;
    }

    .carrito-header__subtitulo {
        font-size: 0.72rem;
    }

    .carrito-header__cerrar {
        width: 38px;
        height: 38px;
        font-size: 1.05rem;
    }

    /* Carrito móvil / PWA: nombre y mitad en una sola línea horizontal */
    #listaCarrito .item-nombre-principal,
    #listaCarrito .item-mitad-line {
        white-space: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
        overflow-wrap: normal;
        word-break: normal;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    #listaCarrito .item-nombre-principal::-webkit-scrollbar,
    #listaCarrito .item-mitad-line::-webkit-scrollbar {
        display: none;
    }

    #listaCarrito .item-nombre-principal {
        font-size: 0.8rem;
        line-height: 1.2;
    }

    #listaCarrito .item-mitad-line {
        font-size: 0.75rem;
        line-height: 1.2;
    }

    #listaCarrito .precio-normal,
    #listaCarrito .precio-final {
        font-size: 0.875rem;
    }

    #listaCarrito .precio-original {
        font-size: 0.68rem;
    }

    #listaCarrito .precio-eliminar {
        flex-shrink: 0;
        min-width: 0;
    }

    .boton-flotante {
        width: 74px;
        height: 74px;
        font-size: 1.65rem;
        /* Por encima del banner de instalación PWA (ancho completo abajo) */
        bottom: calc(108px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .boton-whatsapp-flotante {
        width: 56px;
        height: 56px;
        bottom: calc(168px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .carrito-flotante {
        transition: opacity 0.2s ease;
    }

    .carrito-flotante:not(.activo) {
        transform: none;
    }

    .btn-confirmar:hover:not(:disabled) {
        transform: none;
    }
}
