/* =========================================================
   DOBLE-CE | CARRITO
   Panel lateral, items, controles y toast
   ========================================================= */

/* ── Contenedor de botones flotantes ──────────────────────────────────────────
   Agrupa WhatsApp (siempre visible) y Carrito (solo con artículos).
   Flex column: WA queda arriba, carrito abajo, ambos alineados a la derecha.
   El contenedor crece hacia arriba al aparecer el botón de carrito.
   ─────────────────────────────────────────────────────────────────────────── */
.botones-flotantes {
    position: fixed;
    bottom: 28px;
    right: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 1000;
}

/* --- Botón flotante WhatsApp --- */
.btn-flotante-whatsapp {
    width: 75px;
    height: 75px;
    border-radius: 50%;
    background-color: #25d366;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.45);
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.btn-flotante-whatsapp img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    display: block;
}

.btn-flotante-whatsapp:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 28px rgba(37, 211, 102, 0.60);
}

.btn-flotante-whatsapp:active {
    transform: scale(0.96);
}

/* --- Botón flotante Carrito ---
   Oculto por defecto. carrito.js añade .visible cuando hay artículos. */
.cart-btn-flotante {
    position: relative; /* necesario para que .cart-contador se ancle aquí */
    background-color: var(--color5);
    border: 2px solid var(--color2);
    color: white;
    border-radius: 50%;
    width: 75px;
    height: 75px;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    box-shadow: 0 6px 20px rgba(45, 62, 40, 0.40);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
    /* Oculto hasta que haya artículos */
    display: none;
}

.cart-btn-flotante.visible {
    display: flex;
    animation: cartAppear 0.28s cubic-bezier(.22, .81, .01, 1);
}

@keyframes cartAppear {
    from { opacity: 0; transform: scale(0.7); }
    to   { opacity: 1; transform: scale(1); }
}

.cart-btn-flotante:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 28px rgba(45, 62, 40, 0.50);
}

.cart-btn-flotante:active {
    transform: scale(0.96);
}

/* --- Animación pulse al agregar un producto --- */
@keyframes cartPulse {
    0%   { transform: scale(1);    box-shadow: 0 6px 20px rgba(45, 62, 40, 0.40); }
    25%  { transform: scale(1.22); box-shadow: 0 10px 32px rgba(248, 202, 113, 0.55); }
    55%  { transform: scale(0.94); }
    75%  { transform: scale(1.08); }
    100% { transform: scale(1);    box-shadow: 0 6px 20px rgba(45, 62, 40, 0.40); }
}

.cart-btn-flotante.pulsando {
    animation: cartPulse 0.45s cubic-bezier(.36,.07,.19,.97) both;
}

/* --- Contador de items --- */
.cart-contador {
    position: absolute;
    top: -6px;
    right: -6px;
    background-color: var(--color4);
    color: white;
    font-size: 11px;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: none;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
    border: 2px solid var(--bg-color);
}

.cart-contador.visible {
    display: flex;
}

/* --- Panel lateral --- */
.cart-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 410px;
    height: 100%;
    background-color: #fff;
    box-shadow: -8px 0 40px rgba(45, 62, 40, 0.16);
    transition: right 0.35s cubic-bezier(.22, .81, .01, 1);
    z-index: 1001;
    padding: 24px;
    display: flex;
    flex-direction: column;
    border-left: 3px solid var(--color2);
}

.cart-panel.abierto {
    right: 0;
}

/* --- Cabecera del panel --- */
.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 16px;
}

.cart-header h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--color5);
}

.cart-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.cerrar-cart {
    background: none;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    width: 32px;
    height: 32px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    color: #888;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cerrar-cart:hover {
    background: var(--color4);
    color: white;
    border-color: var(--color4);
}

.btn-vaciar-carrito {
    background: transparent;
    border: 1px solid rgba(184, 92, 42, 0.32);
    border-radius: var(--radius);
    padding: 5px 12px;
    font-size: 0.75rem;
    font-family: var(--font-body);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color4);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    height: 32px;
    display: flex;
    align-items: center;
}

.btn-vaciar-carrito:hover {
    background: var(--color4);
    color: white;
}

/* --- Lista de items --- */
#lista-carrito {
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 20px;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--color2) transparent;
}

.carrito-vacio {
    text-align: center;
    color: #bbb;
    margin-top: 30px;
    font-style: italic;
}

.grupo-carrito {
    border-bottom: 1px dashed var(--border-subtle);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.item-carrito {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.item-info {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    color: var(--color5);
    font-size: 0.95rem;
    gap: 8px;
}

.item-peso {
    font-size: 0.80rem;
    color: var(--color-body);
    font-weight: 400;
}

.item-controles {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.controles-cantidad {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 3px;
    border: 1px solid var(--border-subtle);
}

/* Span de cantidad dentro de controles */
.item-cantidad {
    width: 20px;
    text-align: center;
}

.btn-ctrl {
    background: white;
    border: 1px solid var(--border-subtle);
    border-radius: 3px;
    width: 26px;
    height: 26px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-weight: 700;
    color: var(--color5);
    transition: background 0.2s;
}

.btn-ctrl:hover {
    background: var(--color2);
    color: var(--color5);
}

.btn-eliminar {
    background: transparent;
    color: var(--color4);
    border: 1px solid rgba(184, 92, 42, 0.30);
    padding: 5px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.80rem;
    font-family: var(--font-body);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transition: background 0.2s, color 0.2s;
}

.btn-eliminar:hover {
    background: var(--color4);
    color: white;
}

/* --- Descuento por cantidad --- */
.descuento-nota {
    background: linear-gradient(135deg, #eaf5ee 0%, #d4edda 100%);
    color: #1e7e34;
    padding: 5px 12px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-top: 6px;
    text-align: center;
    font-weight: 500;
    border: 1px solid rgba(39, 174, 96, 0.22);
}

.precio-tachado {
    text-decoration: line-through;
    color: #aaa;
    font-size: 0.88em;
    margin-right: 6px;
}

.precio-optimo {
    color: #1e7e34;
    font-weight: 700;
}

/* --- Pie del panel --- */
.cart-footer {
    border-top: 1px solid var(--border-subtle);
    padding-top: 16px;
}

.cart-total {
    font-family: var(--font-display);
    font-size: 1.4rem;
    margin-bottom: 14px;
    text-align: right;
    color: var(--color5);
    font-weight: 700;
}

.btn-whatsapp {
    background-color: var(--color5);
    color: var(--color2);
    border: none;
    margin-bottom: 15px;
    padding: 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.95rem;
    font-family: var(--font-body);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    width: 100%;
    transition: background 0.25s, transform 0.15s;
}

.btn-whatsapp:hover {
    background-color: var(--color3);
    color: white;
    transform: translateY(-2px);
}

.btn-whatsapp:active {
    transform: translateY(0);
}

.nota-whatsapp {
    text-align: center;
    font-size: 0.80rem;
    color: #aaa;
    margin-top: 8px;
    margin-bottom: 3px;
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background-color: var(--color5);
    color: var(--color2);
    padding: 10px 22px;
    border-radius: var(--radius);
    border-left: 3px solid var(--color3);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, transform 0.3s, visibility 0.3s;
    z-index: 2000;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.toast.mostrar {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* =========================================================
   RESPONSIVE — CARRITO
   ========================================================= */
@media (max-width: 600px) {
    .cart-panel {
        max-width: 100%;
    }

    .botones-flotantes {
        bottom: 20px;
        right: 20px;
        gap: 10px;
    }

    .btn-flotante-whatsapp,
    .cart-btn-flotante {
        width: 62px;
        height: 62px;
    }

    .btn-flotante-whatsapp img {
        width: 36px;
        height: 36px;
    }
}