/* Reset básico e fontes (Mobile First) */
:root {
    --primary-color: #007bff; /* Azul primário (botões, preços) */
    --primary-hover: #0056b3; /* Azul mais escuro para hover */
    --secondary-color: #6c757d; /* Cinza secundário (texto menos importante) */
    --light-gray: #f8f9fa; /* Cinza claro (fundos de filtros) */
    --border-color: #dee2e6; /* Cor de borda suave */
    --background-color: #f4f4f4; /* Fundo geral da página */
    --card-background: #ffffff; /* Fundo dos cards */
    --text-color: #333; /* Cor principal do texto */
    --success-color: #28a745; /* Verde para botões de sucesso */
    --success-hover: #218838;
    --danger-color: #dc3545; /* Vermelho para alertas/contagem/remover */
    --danger-hover: #a01c29; /* Vermelho mais escuro */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

*, *:before, *:after {
    box-sizing: inherit;
}

.container {
    width: 100%;
    max-width: 1300px;
    margin: 0 auto;
    padding: 15px;
    background-color: var(--card-background);
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
    min-height: 100vh;
}

/* Cabeçalho e Navegação */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 10px;
}

.logo a {
    display: inline-block;
}

.logo img {
    height: 45px;
    width: auto;
    vertical-align: middle;
}

nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

nav a {
    text-decoration: none;
    color: var(--text-color);
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
    display: inline-block;
    font-size: 0.95em;
    background-color: #fff;
}

nav a:hover {
    background-color: var(--light-gray);
    border-color: #bbb;
    color: #000;
}
nav a.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    font-weight: bold;
}

.cart-icon {
    position: relative;
    cursor: pointer;
    font-size: 1.8em;
    color: var(--text-color);
}

.cart-count {
    position: absolute;
    top: -5px;
    right: -8px;
    background-color: var(--danger-color);
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 0.6em;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
    line-height: 1.3;
    border: 1px solid white;
    display: none;
}
.cart-count[style*="inline-block"] {
    display: inline-block !important;
}

h1 {
    text-align: center;
    margin-bottom: 30px;
    color: var(--primary-color);
    font-weight: 600;
}

/* Filtros */
.filters {
    margin-bottom: 30px;
    padding: 15px;
    background-color: var(--light-gray);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px 25px;
    align-items: center;
}

.filters label {
    font-weight: 600;
    margin-right: 5px;
    font-size: 0.9em;
    color: var(--secondary-color);
}

.filters select {
    padding: 10px 15px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #fff;
    min-width: 180px;
    flex-grow: 1;
    font-size: 0.95em;
    cursor: pointer;
}

.filters select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.2);
}


/* Listagem de Produtos */
.product-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 25px;
}

.product-card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    background-color: var(--card-background);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    overflow: hidden;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
}

/* Container da Imagem Clicável */
.product-image-container {
    cursor: pointer;
    margin-bottom: 8px; /* Espaço ligeiramente reduzido abaixo da imagem */
}
.product-image-container img {
     max-width: 100%;
     height: auto;
     max-height: 200px; /* MANTENHA ESTA ALTURA MÁXIMA OU AJUSTE */
     object-fit: contain;
     display: block;
     margin: 0 auto;
}

/* Título do Produto */
.product-card h3 {
    font-size: 1.1em;
    margin: 0 0 4px 0;  /* Margem inferior MÍNIMA */
    min-height: auto;
    color: #222;
    font-weight: 600;
    line-height: 1.3; /* Reduzir um pouco a altura da linha do título */
}

/* Bloco de Informações (Material & Embalagem) */
.product-info-block {
    margin: 0 0 5px 0; /* Margem inferior MÍNIMA antes do preço */
    text-align: left;
    padding: 0 5px;
}

.product-info-block .product-material,
.product-info-block .product-packaging {
    font-size: 0.85em;
    color: var(--secondary-color);
    margin: 1;      /* GARANTE SEM MARGENS */
    padding: 0;     /* GARANTE SEM PADDING */
    line-height: 1.2; /* VALOR MAIS APERTADO - Pode tentar 1.1 ou até 1.0 se ainda for muito */
}


.product-info-block .product-material strong,
.product-info-block .product-packaging strong {
    color: var(--text-color);
    margin-right: 4px; /* ligeiramente menos espaço */
}

/* Preço */
.product-card .price {
    font-weight: bold;
    color: var(--primary-color);
    margin: 0 0 8px 0; /* SEM margem em cima, margem inferior MÍNIMA antes do botão */
    font-size: 1.3em;
    text-align: center;
    line-height: 1.2; /* Linha do preço mais apertada */
}

/* Botão Adicionar */
.product-card .add-to-cart-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 12px; /* Padding ligeiramente menor se necessário */
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    font-weight: 600;
    margin-top: 0; /* Garante sem margem acima */
}

.product-card .add-to-cart-btn:hover {
    background-color: var(--primary-hover);
}

/* Esconde a linha antiga de substância/marca */
.product-card .substance-brand {
     display: none;
}

/* Estilo para mensagem "carregando" ou "sem resultados" */
.product-grid p {
    text-align: center;
    padding: 30px 15px;
    color: var(--secondary-color);
    grid-column: 1 / -1;
    font-style: italic;
}

/* Página de Checkout */
.checkout-container {
    max-width: 800px;
    margin: 30px auto;
}

#cart-items-list {
    list-style: none;
    padding: 0;
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

#cart-items-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    background-color: #fff;
}
#cart-items-list li:last-child {
    border-bottom: none;
}
#cart-items-list li:only-child:not(:has(button)) {
    justify-content: center;
    font-style: italic;
    color: var(--secondary-color);
    padding: 20px;
}


.cart-item-details {
    flex-grow: 1;
    margin-right: 15px;
    font-size: 0.95em;
}

.cart-item-price {
    font-weight: bold;
    min-width: 70px;
    text-align: right;
    font-size: 1em;
    color: var(--primary-color);
}

/* Botão Remover Checkout */
.remove-item-btn {
    background: none;
    border: none;
    color: var(--danger-color);
    font-size: 1.5em;
    font-weight: bold;
    line-height: 1;
    padding: 0 5px;
    margin-left: 15px;
    cursor: pointer;
    transition: color 0.2s ease, transform 0.1s ease;
}

.remove-item-btn:hover {
    color: var(--danger-hover);
    transform: scale(1.1);
}


.totals {
    margin: 25px 0;
    padding: 20px;
    text-align: right;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--light-gray);
}

.totals p {
    margin: 8px 0;
    font-size: 1.1em;
    color: #444;
}

.totals span {
    font-weight: bold;
    min-width: 80px;
    display: inline-block;
    text-align: right;
}
.totals p strong span {
   color: var(--primary-color);
   font-size: 1.2em;
}


.checkout-form {
    margin-top: 30px;
    padding: 25px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #fff;
}

.checkout-form h2 {
    text-align: center;
    margin-bottom: 25px;
    color: var(--primary-color);
}

.checkout-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9em;
}

.checkout-form input[type="text"] {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
}
.checkout-form input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.2);
}


#buy-now-btn {
    background-color: var(--success-color);
    color: white;
    border: none;
    padding: 15px 25px;
    font-size: 1.2em;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.3s;
    width: 100%;
    margin-top: 10px;
    font-weight: bold;
    text-transform: uppercase;
}

#buy-now-btn:disabled {
    background-color: #aaa;
    cursor: not-allowed;
}

#buy-now-btn:not(:disabled):hover {
    background-color: var(--success-hover);
}

/* Footer */
footer {
    text-align: center;
    margin-top: 40px;
    padding: 20px;
    color: var(--secondary-color);
    font-size: 0.9em;
    border-top: 1px solid var(--border-color);
    background-color: #fff;
}


/* --- Media Queries para Responsividade --- */

/* Telas Pequenas */
@media (min-width: 480px) {
    .product-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
    .filters select {
        min-width: 150px;
    }
}


/* Tablets e Desktops Pequenos */
@media (min-width: 768px) {
    .container {
        padding: 20px 30px;
    }
    .logo img {
        height: 50px;
    }
    .filters {
        justify-content: flex-start;
    }
    .filters select {
         flex-grow: 0;
         min-width: 200px;
    }
    .product-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
     .product-card h3 {
        font-size: 1.15em;
    }
    .product-card .price {
        font-size: 1.35em;
    }
    .checkout-form {
        padding: 30px 40px;
    }
}

/* Desktops Médios */
@media (min-width: 1024px) {
     nav a {
        padding: 10px 15px;
        font-size: 1em;
    }
    .product-grid {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
    .product-card img { /* Mantém a imagem do desktop */
        max-height: 220px;
    }
    /* Aumenta um pouco a altura máxima da imagem em desktops maiores */
    .product-image-container img {
         max-height: 220px;
    }
}

/* Desktops Grandes */
@media (min-width: 1200px) {
    .product-grid {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
}

/* --- Estilos para Modal de Zoom da Imagem --- */
.image-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.85);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-content {
    position: relative;
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
}

.modal-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    border-radius: 5px;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    line-height: 1;
}

.close-modal:hover,
.close-modal:focus {
    color: #bbb;
    text-decoration: none;
}

/* --- Estilos para Produtos Esgotados --- */

/* Aplica filtro de cor e opacidade à imagem */
.product-card.out-of-stock .product-image-container img {
    filter: grayscale(80%) opacity(0.6); /* Ajuste a intensidade conforme preferir */
    /* Pode remover o cursor pointer se não quiser zoom em esgotados */
    /* cursor: default; */
}

/* Garante que o container da imagem pode conter a sobreposição */
.product-image-container {
    position: relative; /* Essencial para a sobreposição absoluta */
    overflow: hidden; /* Para garantir que a sobreposição não saia dos limites se for muito grande */
}

/* Estilo da sobreposição "Esgotado!" */
.stock-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Centraliza perfeitamente */
    background-color: rgba(220, 53, 69, 0.85); /* Cor de perigo (vermelho) com transparência */
    color: white;
    padding: 6px 12px; /* Espaçamento interno */
    border-radius: 4px; /* Cantos arredondados */
    font-weight: bold;
    font-size: 0.9em; /* Tamanho da fonte */
    text-align: center;
    z-index: 5; /* Garante que fica por cima da imagem */
    pointer-events: none; /* Permite clicar "através" da overlay na imagem para zoom */
    white-space: nowrap; /* Impede quebra de linha */
    display: block; /* Já está a ser controlado pela classe .out-of-stock no elemento pai */
}

/* Estilo do botão desativado */
.product-card.out-of-stock .add-to-cart-btn {
    background-color: var(--secondary-color); /* Cinza */
    cursor: not-allowed; /* Cursor de "não permitido" */
    opacity: 0.65; /* Ligeiramente transparente */
}

/* Remove efeito hover do botão desativado */
.product-card.out-of-stock .add-to-cart-btn:hover {
     background-color: var(--secondary-color); /* Mantém a cor cinza */
}

/* --- Fim dos Estilos para Produtos Esgotados --- */