/* ==========================================================
   CART.CSS - Sistema de Cotação (Carrinho + WhatsApp)
   Conecta AHP Paraguay
   - Stepper de quantidade em cada product-item
   - Botão "Agregar al carrito"
   - FAB do carrinho (substitui .whatsapp-float)
   - Drawer lateral (sidebar desktop / bottom sheet mobile)
   ========================================================== */

/* ====== Cursor/feedback para áreas que abrem o modal ====== */

.product-item .image-wrapper,
.product-item .product-title {
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.product-item .image-wrapper:hover,
.product-item .product-title:hover {
    opacity: 0.85;
}

/* ====== STEPPER + BOTÃO AGREGAR (dentro de cada .product-item) ====== */

.product-item {
    position: relative;
    padding-bottom: 88px; /* espaço para a barra de ação fixa dentro do card */
}

.product-item .product-qty-bar {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    display: flex;
    align-items: stretch;
    gap: 6px;
    z-index: 2;
}

.product-item .qty-stepper {
    display: inline-flex;
    align-items: center;
    background: #ffffff;
    border: 1.5px solid var(--primary-green, #00a55a);
    border-radius: 10px;
    overflow: hidden;
    height: 40px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    flex: 0 0 auto;
}

.product-item .qty-stepper button {
    background: transparent;
    border: 0;
    width: 32px;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary-green, #00a55a);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease;
    user-select: none;
}

.product-item .qty-stepper button:hover {
    background: rgba(0, 165, 90, 0.1);
}

.product-item .qty-stepper button:active {
    background: rgba(0, 165, 90, 0.2);
}

.product-item .qty-stepper button:disabled {
    color: #c0c4c2;
    cursor: not-allowed;
    background: transparent;
}

.product-item .qty-stepper input {
    width: 36px;
    height: 100%;
    border: 0;
    border-left: 1px solid rgba(0, 165, 90, 0.25);
    border-right: 1px solid rgba(0, 165, 90, 0.25);
    background: transparent;
    text-align: center;
    font-weight: 700;
    font-size: 14px;
    color: var(--text-dark, #1a1d1b);
    font-family: inherit;
    -moz-appearance: textfield;
    padding: 0;
    outline: none;
    min-width: 0;
}

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

.product-item .add-to-cart-btn {
    flex: 1 1 auto;
    min-width: 0;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: var(--primary-green, #00a55a);
    color: #ffffff;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 12px;
    box-shadow: 0 2px 6px rgba(0, 165, 90, 0.3);
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================
   Padrão "Agregar" -> "En el carrito"
   - Estado padrão: ícone de carrinho vazio + texto "Agregar"
   - Estado .added: ícone de carrinho cheio + "En el carrito" + qty inline
   ========================================= */

/* Ícones alternados: add-icon (carrinho vazio) e added-icon (carrinho cheio) */
.product-item .add-to-cart-btn .add-icon {
    display: inline-flex;
}

.product-item .add-to-cart-btn .added-icon {
    display: none;
}

.product-item .add-to-cart-btn.added .add-icon {
    display: none;
}

.product-item .add-to-cart-btn.added .added-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
}

/* Quantidade inline (visível só no estado .added) */
.product-item .add-to-cart-btn .btn-qty-inline {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 7px;
    min-width: 26px;
    height: 20px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--accent-orange, #f26522);
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.product-item .add-to-cart-btn.added .btn-qty-inline {
    display: inline-flex;
    animation: btn-qty-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes btn-qty-pop {
    0%   { transform: scale(0.4); opacity: 0; }
    60%  { transform: scale(1.18); opacity: 1; }
    100% { transform: scale(1); }
}

.product-item .add-to-cart-btn:hover {
    background: var(--primary-green-dark, #007a3f);
    box-shadow: 0 3px 10px rgba(0, 165, 90, 0.4);
}

.product-item .add-to-cart-btn:active {
    transform: scale(0.97);
}

.product-item .add-to-cart-btn[disabled] {
    background: #c0c4c2;
    box-shadow: none;
    cursor: not-allowed;
}

.product-item .add-to-cart-btn.added {
    background: linear-gradient(135deg, var(--accent-orange, #f26522) 0%, var(--accent-orange-hover, #e0551a) 100%);
    box-shadow: 0 2px 8px rgba(242, 101, 34, 0.35);
}

.product-item .add-to-cart-btn.added:hover {
    background: linear-gradient(135deg, var(--accent-orange-hover, #e0551a) 0%, #c84a15 100%);
    box-shadow: 0 3px 12px rgba(242, 101, 34, 0.5);
}

.product-item .add-to-cart-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ====== MOBILE: stepper em cima, botão embaixo (vertical) ====== */

@media (max-width: 640px) {
    .product-item {
        padding-bottom: 100px;
    }

    .product-item .product-qty-bar {
        flex-direction: column;
        gap: 5px;
        left: 6px;
        right: 6px;
        bottom: 6px;
    }

    .product-item .qty-stepper {
        width: 100%;
        justify-content: space-between;
    }

    .product-item .qty-stepper button {
        width: 38px;
    }

    .product-item .qty-stepper input {
        flex: 1 1 auto;
        width: auto;
    }

    .product-item .add-to-cart-btn {
        width: 100%;
    }
}

/* ====== ANIMAÇÃO "voando para o carrinho" (fly-to-cart) ====== */

@keyframes fly-to-cart {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
        opacity: 1;
    }
    60% {
        opacity: 0.95;
    }
    100% {
        transform: translate(var(--fly-dx, 0px), var(--fly-dy, -400px)) scale(0.2) rotate(20deg);
        opacity: 0;
    }
}

.fly-to-cart-clone {
    position: fixed;
    width: 60px;
    height: 60px;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 8px 20px rgba(0, 122, 63, 0.35);
    z-index: 120;
    pointer-events: none;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fly-to-cart 0.75s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

.fly-to-cart-clone img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Flash no FAB quando recebe o item */
@keyframes fab-pulse {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.18); }
    60%  { transform: scale(0.96); }
    100% { transform: scale(1); }
}

.cart-fab.is-pulsing {
    animation: fab-pulse 0.5s ease;
}

/* Pulso verde no botão "Agregar" quando confirma */
@keyframes add-btn-pulse {
    0%   { box-shadow: 0 2px 6px rgba(0, 165, 90, 0.3); }
    40%  { box-shadow: 0 0 0 6px rgba(0, 165, 90, 0.2), 0 4px 14px rgba(0, 165, 90, 0.5); }
    100% { box-shadow: 0 2px 6px rgba(0, 165, 90, 0.3); }
}

.product-item .add-to-cart-btn.is-pulsing {
    animation: add-btn-pulse 0.55s ease;
}

/* ====== FAB DO CARRINHO (substitui o .whatsapp-float) ====== */

.cart-fab {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 0;
    background: var(--primary-green, #00a55a);
    color: #ffffff;
    box-shadow: 0 6px 18px rgba(0, 122, 63, 0.4),
                0 2px 6px rgba(0, 0, 0, 0.15);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 95;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.cart-fab:hover {
    background: var(--primary-green-dark, #007a3f);
    transform: scale(1.05);
}

.cart-fab:active {
    transform: scale(0.95);
}

.cart-fab svg {
    width: 30px;
    height: 30px;
    fill: currentColor;
}

.cart-fab__count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--accent-orange, #f26522);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    border: 2px solid #ffffff;
    box-sizing: content-box;
    pointer-events: none;
    transition: transform 0.2s ease;
}

.cart-fab__count[data-bump="1"] {
    animation: cart-bump 0.35s ease;
}

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

/* Empurra o FAB acima da bottom-nav em mobile */
@media (max-width: 768px) {
    .cart-fab {
        right: 16px;
        bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    }
}

/* ====== DRAWER DO CARRINHO ====== */

.cart-drawer {
    position: fixed;
    inset: 0;
    z-index: 110;
    pointer-events: none;
}

.cart-drawer[aria-hidden="false"] {
    pointer-events: auto;
}

.cart-drawer__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 46, 26, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.cart-drawer[aria-hidden="false"] .cart-drawer__backdrop {
    opacity: 1;
}

.cart-drawer__panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(420px, 100%);
    background: #ffffff;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.cart-drawer[aria-hidden="false"] .cart-drawer__panel {
    transform: translateX(0);
}

.cart-drawer__header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    background: linear-gradient(135deg, var(--primary-green, #00a55a), var(--primary-green-dark, #007a3f));
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.cart-drawer__header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.cart-drawer__close {
    background: rgba(255, 255, 255, 0.15);
    border: 0;
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    font-family: inherit;
}

.cart-drawer__close:hover {
    background: rgba(255, 255, 255, 0.28);
}

.cart-drawer__items {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    list-style: none;
    margin: 0;
    padding: 8px 0;
}

.cart-drawer__empty {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    color: #6b7480;
}

.cart-drawer__empty[hidden] {
    display: none;
}

.cart-drawer__empty-icon {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
    opacity: 0.35;
    color: var(--primary-green, #00a55a);
}

.cart-drawer__empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark, #1a1d1b);
    margin: 0 0 6px;
}

.cart-drawer__empty-hint {
    font-size: 14px;
    margin: 0;
}

/* Item de linha no carrinho */

.cart-item {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    gap: 12px;
    padding: 12px 20px;
    align-items: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    animation: cart-item-in 0.25s ease;
}

@keyframes cart-item-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

.cart-item__img {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    background: #f5f8f6;
    object-fit: contain;
    display: block;
}

.cart-item__body {
    min-width: 0;
}

.cart-item__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark, #1a1d1b);
    line-height: 1.3;
    margin: 0 0 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cart-item__code {
    font-size: 11px;
    color: #6b7480;
    margin: 0;
    font-family: 'Inter', monospace;
}

.cart-item__actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.cart-item__qty {
    display: inline-flex;
    align-items: center;
    background: #ffffff;
    border: 1.5px solid var(--primary-green, #00a55a);
    border-radius: 8px;
    overflow: hidden;
    height: 30px;
}

.cart-item__qty button {
    background: transparent;
    border: 0;
    width: 26px;
    height: 100%;
    color: var(--primary-green, #00a55a);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    font-family: inherit;
}

.cart-item__qty button:hover {
    background: rgba(0, 165, 90, 0.1);
}

.cart-item__qty input {
    width: 30px;
    height: 100%;
    border: 0;
    border-left: 1px solid rgba(0, 165, 90, 0.25);
    border-right: 1px solid rgba(0, 165, 90, 0.25);
    background: transparent;
    text-align: center;
    font-weight: 700;
    font-size: 13px;
    color: var(--text-dark, #1a1d1b);
    font-family: inherit;
    -moz-appearance: textfield;
    padding: 0;
    outline: none;
}

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

.cart-item__remove {
    background: transparent;
    border: 0;
    color: #b53a3a;
    cursor: pointer;
    padding: 4px 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-radius: 4px;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease;
}

.cart-item__remove:hover {
    background: rgba(181, 58, 58, 0.1);
    color: #8a2828;
}

/* Rodapé do drawer */

.cart-drawer__footer {
    flex: 0 0 auto;
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    background: #f7f9f8;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cart-drawer__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: #6b7480;
}

.cart-drawer__summary b {
    color: var(--text-dark, #1a1d1b);
    font-size: 18px;
    font-weight: 700;
}

.cart-drawer__actions {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
}

.cart-drawer__clear {
    background: transparent;
    border: 1.5px solid #d0d4d2;
    color: #6b7480;
    border-radius: 10px;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s ease;
}

.cart-drawer__clear:hover {
    border-color: #b53a3a;
    color: #b53a3a;
    background: rgba(181, 58, 58, 0.05);
}

.cart-drawer__send {
    background: #25D366;
    color: #ffffff;
    text-decoration: none;
    border-radius: 10px;
    padding: 12px 16px;
    font-weight: 700;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 6px rgba(37, 211, 102, 0.3);
    cursor: pointer;
}

.cart-drawer__send:hover {
    background: #1ebd59;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.45);
}

.cart-drawer__send:active {
    transform: scale(0.98);
}

.cart-drawer__send[aria-disabled="true"] {
    background: #c0c4c2;
    box-shadow: none;
    cursor: not-allowed;
    pointer-events: none;
}

.cart-drawer__send svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    flex-shrink: 0;
}

/* ====== Mobile: drawer vira bottom sheet ====== */

@media (max-width: 540px) {
    .cart-drawer__panel {
        top: auto;
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 90vh;
        max-height: 90vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.2);
    }

    .cart-drawer[aria-hidden="false"] .cart-drawer__panel {
        transform: translateY(0);
    }

    .cart-drawer__header {
        border-radius: 20px 20px 0 0;
        position: relative;
    }

    .cart-drawer__header::before {
        content: "";
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: rgba(255, 255, 255, 0.4);
    }
}

/* ====== Estados e utilitários ====== */

.cart-drawer[hidden] {
    display: none;
}

body.cart-open {
    overflow: hidden;
}

/* Foco visível para acessibilidade */

.product-item .qty-stepper button:focus-visible,
.product-item .add-to-cart-btn:focus-visible,
.cart-fab:focus-visible,
.cart-drawer__close:focus-visible,
.cart-drawer__clear:focus-visible,
.cart-drawer__send:focus-visible,
.cart-item__qty button:focus-visible,
.cart-item__remove:focus-visible {
    outline: 3px solid rgba(0, 165, 90, 0.5);
    outline-offset: 2px;
}
