/**
 * CSS Otimizado para Loja Pública
 * 
 * Estilos para página pública de produtos com otimizações de performance
 * Inclui sistema de autocomplete e filtros modernos
 * 
 * @author Casa do Sereno
 * @since 2024-12
 */

/* Reset e Base */
.loja-page {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
}

/* Header da Página */
.page-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 80px 0 60px 0;
    text-align: center;
    position: relative;
    overflow: hidden;
    margin-top: 60px;
}

.page-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="75" cy="75" r="1" fill="rgba(255,255,255,0.1)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    opacity: 0.3;
}

.page-header-content {
    position: relative;
    z-index: 1;
}

.page-header h1 {
    font-size: 2.5rem;
    margin: 0 0 10px 0;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.page-header p {
    font-size: 1.1rem;
    margin: 0;
    opacity: 0.9;
}

/* Container Principal */
.main-content {
    padding: 40px 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Toggle mobile padrão: escondido no desktop */
.mobile-filters-toggle { display: none; }

/* Acessibilidade: esconder visualmente mantendo leitura por screen readers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Filtros Modernos */
.loja-filtros {
    background: white;
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
}

.filtros-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

/* Botões de ordenar no header: escondidos por padrão (desktop) */
.filtros-header .ordenar-header-toggles { display: none; }

.filtros-header h3 {
    margin: 0;
    color: #333;
    font-size: 1.3rem;
    font-weight: 600;
}

.filtros-header h3 i {
    margin-right: 8px;
    color: #667eea;
}

.filtros-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    align-items: end;
}

.filtro-grupo {
    display: flex;
    flex-direction: column;
}

.filtro-grupo label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filtro-grupo label i {
    color: #667eea;
    font-size: 0.8rem;
}

.filtro-select,
.busca-input {
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 10px;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    background: white;
    color: #333;
    width: 100%;
}

.filtro-select:focus,
.busca-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    transform: translateY(-1px);
}

/* Busca com Autocomplete */
.busca-autocomplete {
    position: relative;
}

.busca-container {
    position: relative;
}

.sugestoes-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #667eea;
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    z-index: 1000;
    max-height: 300px;
    overflow-y: auto;
}

.sugestao-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s ease;
    width: 100%;
    min-width: 0;
}

.sugestao-item:hover,
.sugestao-item.ativo {
    background-color: #f8f9fa;
}

.sugestao-item:last-child {
    border-bottom: none;
}

.sugestao-imagem {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    margin-right: 12px;
    border-radius: 8px;
    overflow: hidden;
    background: #f8f9fa;
}

.sugestao-imagem img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sugestao-conteudo {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sugestao-nome {
    font-weight: 600;
    color: #333;
    font-size: 0.95rem;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sugestao-info {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
    color: #666;
    flex-wrap: wrap;
}

.sugestao-categoria,
.sugestao-canal {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sugestao-preco {
    font-weight: 600;
    color: #28a745;
    font-size: 0.9rem;
}

/* Botões de Ação */
.filtros-acoes {
    display: flex;
    justify-content: center;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 2px solid #f0f0f0;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-outline {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-outline:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85rem;
}

/* Loading */
.loja-loading {
    text-align: center;
    padding: 60px 20px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.mobile-filters-toggle { display: none; }

/* Input com ícone à esquerda */
.input-with-icon { position: relative; }
.input-with-icon .input-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #667eea;
    font-size: 0.95rem;
    pointer-events: none;
}
.input-with-icon .busca-input,
.input-with-icon .filtro-select {
    padding-left: 56px !important; /* força afastamento suficiente do ícone */
}

/* Grupo ordenar com botões */
.ordenar-toggles { display: inline-flex; gap: 8px; }
.ordenar-btn {
    border: 1px solid #e1e5e9; background: #fff; color: #333;
    border-radius: 10px; padding: 10px 12px; cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.ordenar-btn.active, .ordenar-btn[aria-pressed="true"] {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff; border-color: transparent;
}

/* Esconder select de ordenação (usamos botões) */
.ordenar-grupo select { display: none; }

/* Linha compacta padrão (desktop também) */
.filtros-row-compact {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    align-items: center;
}

/* Resultados */
.loja-resultados {
    background: white;
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.resultados-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.resultados-info {
    font-size: 1.1rem;
    color: #333;
    font-weight: 600;
}

.resultados-paginacao {
    color: #666;
    font-size: 0.9rem;
}

/* Grid de Produtos */
.produtos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
}

.produto-card {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    border: 1px solid #e1e5e9;
    position: relative;
}

.produto-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.produto-card a {
    text-decoration: none;
    color: inherit;
    display: block;
}

/* Imagem do Produto */
.produto-imagem-container {
    position: relative;
    height: 200px;
    overflow: hidden;
    background: #f8f9fa;
}

.produto-imagem {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.produto-card:hover .produto-imagem {
    transform: scale(1.05);
}

/* Estilos para imagens com fallback */
.produto-imagem.fallback-image {
    opacity: 0.8;
    filter: grayscale(20%);
}

.produto-imagem.lazy {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.produto-imagem.lazy.loaded {
    opacity: 1;
}

/* Placeholder para imagens que falharem */
.produto-imagem-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f0f0f0, #e0e0e0);
    color: #999;
    font-size: 3rem;
    border-radius: 8px;
}

/* Badges */
.produto-badges {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.produto-badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.produto-badge.destaque {
    background: #ff6b6b;
    color: white;
}

.produto-badge.desconto {
    background: #51cf66;
    color: white;
}

/* Conteúdo do Card */
.produto-conteudo {
    padding: 20px;
}

.produto-nome {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #333;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.produto-descricao {
    font-size: 0.9rem;
    color: #666;
    margin: 0 0 15px 0;
    line-height: 1.4;
    /* Truncar descrição em 3 linhas */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sobrescrever para páginas de produto individual */
.produto-page .produto-descricao {
    margin-bottom: 32px;
}

.produto-page .produto-descricao h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
    margin: 0 0 12px 0;
}

.produto-page .produto-descricao p {
    line-height: 1.6;
    color: #555;
    margin: 0;
}

/* Preços */
.produto-precos {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.produto-preco-por {
    font-size: 1.3rem;
    font-weight: 700;
    color: #2d3748;
}

.produto-preco-de {
    font-size: 1rem;
    color: #718096;
    text-decoration: line-through;
}

/* Status */
.produto-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
}

.produto-status.disponivel {
    background: #d4edda;
    color: #155724;
}

.produto-status.em-estoque {
    background: #fff3cd;
    color: #856404;
}

.produto-status.indisponivel {
    background: #f8d7da;
    color: #721c24;
}

/* Paginação */
.paginacao {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 40px;
}

.paginacao-item {
    padding: 10px 15px;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    text-decoration: none;
    color: #333;
    transition: all 0.3s ease;
    background: white;
}

.paginacao-item:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: translateY(-2px);
}

.paginacao-item.ativo {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.paginacao-item.desabilitado {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Estados Vazios */
.loja-vazio {
    text-align: center;
    padding: 60px 20px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.vazio-icone {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.loja-vazio h3 {
    color: #333;
    margin-bottom: 10px;
}

.loja-vazio p {
    color: #666;
    margin-bottom: 20px;
}

/* Responsividade */
@media (max-width: 768px) {
    /* Cabeçalho e topo mais compactos */
    .page-header { padding: 16px 0 10px 0; margin-top: 72px; }
    .page-header p { display: none; }
    .main-content { padding: 14px 0 20px; margin-top: -16px; }
    
    /* Barra toggle para filtros no mobile */
    .mobile-filters-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        background: #fff;
        border: 1px solid #e1e5e9;
        border-radius: 12px;
        padding: 10px 14px;
        margin-bottom: 12px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05);
        color: #333;
    }
    .mobile-filters-toggle .toggle-left { display: inline-flex; align-items: center; gap: 8px; }
    .mobile-filters-toggle .toggle-right { display: inline-flex; align-items: center; gap: 10px; }
    .mobile-filters-toggle .badge {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: #fff;
        border-radius: 999px;
        font-size: 0.75rem;
        padding: 2px 8px;
        font-weight: 700;
    }

    /* Painel de filtros mais leve no mobile */
    .loja-filtros { padding: 12px; margin-bottom: 12px; }
    .filtros-grid { grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }

    /* Estado colapsado: esconder filtros por padrão no mobile (controlado via JS) */
    .loja-filtros.collapsed { display: none; }

    .page-header h1 {
        font-size: 2rem;
    }
    
    .filtros-grid { grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }
    
    /* Header dos filtros: título e ordenação na mesma linha (mobile) */
    .filtros-header { flex-direction: row; gap: 8px; align-items: center; justify-content: space-between; }
    .filtros-header h3 { flex: 1; }
    .filtros-header .ordenar-header-toggles { display: inline-flex; }
    /* Esconder os botões de ordenação da linha compacta no mobile (vamos usar os do header) */
    .filtros-row-compact .ordenar-toggles { display: none !important; }
    
    .produtos-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .resultados-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .paginacao {
        flex-wrap: wrap;
    }
    
    .sugestoes-dropdown {
        max-height: 250px;
    }
    
    .sugestao-item {
        padding: 10px 12px;
    }
    
    .sugestao-imagem {
        width: 40px;
        height: 40px;
    }

    /* Esconder labels e deixar controles compactos */
    .filtro-grupo label { display: none; }
    .filtro-grupo { width: 100%; }
    .filtro-select,
    .busca-input { padding: 10px 12px; font-size: 0.94rem; border-radius: 10px; }
    .filtro-select { -webkit-appearance: none; -moz-appearance: none; appearance: none; }
    .filtro-select.compact,
    .busca-input.compact { padding: 10px 12px; }
    /* Reforçar padding à esquerda quando há ícone embutido */
    .input-with-icon .busca-input.compact,
    .input-with-icon .filtro-select.compact { padding-left: 56px !important; }

    /* Linha compacta: empilhar campos no mobile (um por linha) */
    .filtros-row-compact { 
        display: grid; grid-template-columns: 1fr; gap: 16px; align-items: center; width: 100%;
    }
    .filtros-row-compact .filtro-grupo { width: 100%; }
    .input-with-icon { width: 100%; }
    .input-with-icon .input-icon { left: 12px; }
    /* Ocultar o grupo de ordenar desta linha no mobile (ordenar já está no header) */
    .filtros-row-compact .ordenar-grupo { display: none; }
    .filtro-grupo.compact { position: relative; }

    /* Ordenar: mostrar botões e esconder select */
    .ordenar-toggles { display: flex; }
    .ordenar-grupo select { display: none; }

    /* Ações: dois botões lado a lado */
    .filtros-acoes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #f0f0f0; }
    .filtros-acoes .btn { width: 100%; }
}

@media (min-width: 769px) {
    .produtos-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }
    /* Aproximar conteúdo no desktop */
    .main-content { margin-top: -10px; }
}

/* Animações de Entrada */
.produto-card {
    animation: fadeInUp 0.6s ease forwards;
    opacity: 0;
    transform: translateY(20px);
}

.produto-card:nth-child(1) { animation-delay: 0.1s; }
.produto-card:nth-child(2) { animation-delay: 0.2s; }
.produto-card:nth-child(3) { animation-delay: 0.3s; }
.produto-card:nth-child(4) { animation-delay: 0.4s; }
.produto-card:nth-child(5) { animation-delay: 0.5s; }
.produto-card:nth-child(6) { animation-delay: 0.6s; }

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Otimizações de Performance */
.produto-imagem {
    will-change: transform;
}

.produto-card {
    will-change: transform;
}

/* Preload hints para performance */
@media (prefers-reduced-motion: reduce) {
    .produto-card,
    .produto-imagem {
        animation: none;
        transition: none;
    }
} 
