/* ========== CARRINHO SIDEBAR ========== */

/* Overlay do carrinho - CORRIGIDO */
.cart-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

.cart-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Sidebar do carrinho - CORRIGIDO PARA MOBILE */
.cart-sidebar {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    height: 100%;
    background-color: var(--branco-puro);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.15);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform: translateX(100%);
    overflow: hidden;
    max-width: none !important;
    border-radius: 0 !important;
}

.cart-sidebar.active {
    right: 0;
    transform: translateX(0);
}

/* Header do carrinho */
.cart-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--preto-10);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background-color: var(--branco-puro);
    min-height: 60px;
    position: relative;
    z-index: 2;
}

.cart-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--preto-90);
    margin: 0;
}

.cart-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--preto-60);
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transicao-rapida);
    -webkit-appearance: none;
    appearance: none;
}

.cart-close:hover,
.cart-close:active {
    background-color: var(--preto-5);
    color: var(--preto-puro);
}

/* Container dos itens - CORRIGIDO */
.cart-items {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

/* Previne scroll horizontal indesejado */
.cart-items::-webkit-scrollbar {
    width: 4px;
}

.cart-items::-webkit-scrollbar-track {
    background: var(--preto-5);
}

.cart-items::-webkit-scrollbar-thumb {
    background: var(--preto-20);
    border-radius: 2px;
}

/* Carrinho vazio */
.cart-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--preto-40);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    min-height: 300px;
}

.cart-empty i {
    font-size: 48px;
    margin-bottom: 20px;
    opacity: 0.2;
}

.cart-empty p {
    font-size: 16px;
    margin: 0;
    color: var(--preto-60);
}

/* Item do carrinho - CORRIGIDO PARA MOBILE */
.cart-item {
    display: flex;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--preto-10);
    border-radius: 12px;
    background-color: var(--branco-puro);
    animation: slideIn 0.3s ease;
    flex-shrink: 0;
    min-height: 120px;
    align-items: center;
}

.cart-item-image {
    width: 80px;
    height: 80px;
    min-width: 80px;
    border-radius: 8px;
    overflow: hidden;
    background-color: var(--preto-5);
    flex-shrink: 0;
    position: relative;
}

.cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cart-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
}

.cart-item-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--preto-90);
    margin: 0;
    line-height: 1.3;
    word-break: break-word;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cart-item-price {
    font-size: 16px;
    font-weight: 600;
    color: var(--preto-puro);
    margin: 0;
}

.cart-item-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    gap: 10px;
    flex-wrap: wrap;
}

.quantity-control {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--preto-5);
    border-radius: 8px;
    padding: 6px;
    flex-shrink: 0;
    min-width: 120px;
}

.quantity-btn {
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--preto-60);
    font-size: 16px;
    font-weight: bold;
    transition: var(--transicao-rapida);
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
}

.quantity-btn:hover,
.quantity-btn:active {
    background-color: var(--preto-10);
    color: var(--preto-puro);
}

.quantity-display {
    font-size: 15px;
    font-weight: 600;
    color: var(--preto-90);
    min-width: 30px;
    text-align: center;
}

.remove-item {
    background: none;
    border: none;
    color: var(--preto-40);
    font-size: 13px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: var(--transicao-rapida);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
}

.remove-item:hover,
.remove-item:active {
    color: #e53935;
    background-color: rgba(229, 57, 53, 0.1);
}

.cart-item-total {
    font-size: 14px;
    color: var(--preto-60);
    padding-top: 8px;
    border-top: 1px solid var(--preto-10);
    margin-top: 8px;
    width: 100%;
}

.cart-item-total strong {
    color: var(--preto-puro);
    font-weight: 600;
}

/* Resumo do carrinho */
.cart-summary {
    padding: 20px 16px;
    border-top: 1px solid var(--preto-10);
    background-color: var(--preto-5);
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.cart-totals {
    margin-bottom: 20px;
}

.cart-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--preto-60);
}

.cart-total-row.total {
    font-size: 18px;
    font-weight: 600;
    color: var(--preto-90);
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--preto-10);
}

.cart-subtotal,
.cart-total {
    font-weight: 600;
    color: var(--preto-puro);
}

.cart-shipping {
    color: var(--preto-40);
    font-size: 13px;
}

.btn-checkout {
    display: block;
    width: 100%;
    padding: 18px;
    background-color: #25D366;
    color: var(--branco-puro);
    border: none;
    border-radius: 12px;
    font-family: var(--fonte-texto);
    font-weight: 600;
    font-size: 17px;
    cursor: pointer;
    transition: var(--transicao-rapida);
    margin-bottom: 16px;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
    min-height: 56px;
}

.btn-checkout:hover:not(:disabled),
.btn-checkout:active:not(:disabled) {
    background-color: #128C7E;
    transform: translateY(-2px);
}

.btn-checkout:disabled {
    background-color: var(--preto-30);
    cursor: not-allowed;
    transform: none;
    opacity: 0.7;
}

.cart-continue {
    text-align: center;
    margin: 0;
}

.cart-continue a {
    color: var(--preto-60);
    text-decoration: none;
    font-size: 15px;
    transition: var(--transicao-rapida);
    display: inline-block;
    padding: 8px;
}

.cart-continue a:hover,
.cart-continue a:active {
    color: var(--preto-puro);
}

/* Notificação de item adicionado - CORRIGIDA PARA MOBILE */
.cart-notification {
    position: fixed;
    top: 80px;
    right: 16px;
    left: 16px;
    background-color: var(--preto-puro);
    color: var(--branco-puro);
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    display: flex;
    align-items: center;
    gap: 12px;
    transform: translateY(-20px);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: calc(100% - 32px);
    pointer-events: none;
}

.cart-notification.show {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.cart-notification i {
    font-size: 22px;
    color: #4CAF50;
    flex-shrink: 0;
}

.cart-notification-content {
    flex: 1;
}

.cart-notification-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.cart-notification-message {
    font-size: 13px;
    opacity: 0.9;
    margin: 0;
    line-height: 1.4;
}

/* Ícone do carrinho no header */
.cart-icon.has-items .cart-count {
    background-color: #4CAF50;
    animation: bounce 0.3s ease;
    transform-origin: center;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ========== RESPONSIVIDADE CARRINHO ========== */

/* Tablets pequenos */
@media (min-width: 481px) and (max-width: 768px) {
    .cart-sidebar {
        width: 400px;
        right: -400px;
        transform: translateX(400px);
    }
    
    .cart-notification {
        right: 20px;
        left: auto;
        max-width: 380px;
    }
}

/* Desktop */
@media (min-width: 769px) {
    .cart-sidebar {
        width: 420px;
        right: -420px;
        transform: translateX(420px);
    }
    
    .cart-sidebar.active ~ .whatsapp-button {
        right: 440px;
        transition: right 0.3s ease;
    }
    
    .cart-notification {
        right: 40px;
        left: auto;
        max-width: 350px;
    }
}

/* Celulares muito pequenos */
@media (max-width: 360px) {
    .cart-item {
        flex-direction: column;
        text-align: center;
        padding: 12px;
        gap: 12px;
    }
    
    .cart-item-image {
        width: 100%;
        height: 150px;
        min-height: 150px;
    }
    
    .cart-item-info {
        width: 100%;
        align-items: center;
    }
    
    .cart-item-controls {
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }
    
    .quantity-control {
        width: 100%;
        justify-content: center;
    }
    
    .remove-item {
        width: 100%;
        justify-content: center;
    }
    
    .cart-item-total {
        text-align: center;
    }
    
    .cart-header {
        padding: 16px 12px;
        min-height: 56px;
    }
    
    .cart-title {
        font-size: 17px;
    }
    
    .btn-checkout {
        padding: 16px;
        font-size: 16px;
        min-height: 52px;
    }
}

/* iPhone X/11/12/13/14/15 - Safe Area */
@supports (padding: max(0px)) {
    .cart-sidebar {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .cart-summary {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

/* Ajuste específico para telas muito altas */
@media (min-height: 800px) {
    .cart-empty {
        min-height: 400px;
    }
}

/* Prevenir zoom em input em iOS */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}


/* Prevenir scroll em dispositivos móveis quando carrinho estiver aberto */
.cart-sidebar.active {
    touch-action: none;
}

/* Garantir que o overlay cubra toda a tela */
.cart-overlay.active {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Correção específica para iOS Safari */
@supports (-webkit-touch-callout: none) {
    .cart-sidebar {
        height: -webkit-fill-available;
    }
    
    body.cart-open {
        position: relative;
        overflow: hidden;
    }
}

/* Garantir que em todos os dispositivos o carrinho ocupe a altura certa */
@media (max-width: 768px) {
    .cart-sidebar {
        height: 100vh;
        height: -webkit-fill-available;
        height: fill-available;
    }
}

/* ========== CORREÇÕES PARA MOBILE ========== */

/* Controla scroll apenas quando carrinho está aberto */
body:has(.cart-sidebar.active) {
    overflow: hidden;
    position: relative;
}

/* Carrinho em mobile ocupa toda a tela */
@media (max-width: 768px) {
    .cart-sidebar {
        width: 100%;
        right: -100%;
        transform: translateX(100%);
    }
    
    .cart-sidebar.active {
        right: 0;
        transform: translateX(0);
    }
    
    /* Ajusta botão WhatsApp quando carrinho está aberto */
    .cart-sidebar.active ~ .whatsapp-button {
        right: 20px;
        bottom: 20px;
        transform: scale(0.8);
        transition: all 0.3s ease;
    }
}

/* Correção para iOS */
@supports (-webkit-touch-callout: none) {
    .cart-sidebar {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    .cart-items {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* Botões com área de toque adequada */
.cart-close,
.quantity-btn,
.remove-item,
.btn-checkout {
    min-height: 44px;
    min-width: 44px;
}

/* Corrige scroll no carrinho */
.cart-items {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Overlay fixo */
.cart-overlay.active {
    position: fixed;
}

/* ========== CORREÇÕES PARA MOBILE ========== */

/* Controla scroll apenas quando carrinho está aberto */
body:has(.cart-sidebar.active) {
    overflow: hidden;
    position: relative;
}

/* Carrinho em mobile ocupa toda a tela */
@media (max-width: 768px) {
    .cart-sidebar {
        width: 100%;
        right: -100%;
        transform: translateX(100%);
    }
    
    .cart-sidebar.active {
        right: 0;
        transform: translateX(0);
    }
    
    /* Ajusta botão WhatsApp quando carrinho está aberto */
    .cart-sidebar.active ~ .whatsapp-button {
        right: 20px;
        bottom: 20px;
        transform: scale(0.8);
        transition: all 0.3s ease;
    }
}

/* Correção para iOS */
@supports (-webkit-touch-callout: none) {
    .cart-sidebar {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    .cart-items {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* Botões com área de toque adequada */
.cart-close,
.quantity-btn,
.remove-item,
.btn-checkout {
    min-height: 44px;
    min-width: 44px;
}

/* Corrige scroll no carrinho */
.cart-items {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Overlay fixo */
.cart-overlay.active {
    position: fixed;
}