/* ==========================================================================
   1. RESET E CONFIGURAÇÕES GERAIS
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: #f4f6f9;
    color: #333;
    overflow-x: hidden;
}

/* Container que divide a tela entre Menu e Conteúdo */
.dashboard-container {
    display: flex;
    min-height: 100vh;
}

/* ==========================================================================
   2. MENU LATERAL (SIDEBAR)
   ========================================================================== */
.sidebar {
    width: 260px;
    background-color: #334155; /* Azul escuro elegante */
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
}

.sidebar .logo {
    padding: 24px;
    text-align: center;
    border-bottom: 1px solid #475569;
}

.sidebar .logo h2 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #38bdf8; /* Detalhe em azul claro */
}

/* Links do Menu */
.sidebar .menu {
    display: flex;
    flex-direction: column;
    padding: 15px 0;
    flex-grow: 1;
}

.sidebar .menu a {
    color: #cbd5e1;
    text-decoration: none;
    padding: 12px 24px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
}

/* Efeito Hover e Link Ativo */
.sidebar .menu a:hover,
.sidebar .menu a.active {
    background-color: #475569;
    color: #fff;
    border-left: 4px solid #38bdf8;
    padding-left: 20px; /* Leve recuo no hover */
}

/* Botão de Sair (Logout) posicionado na parte inferior */
.sidebar .menu .btn-logout {
    margin-top: auto;
    border-left: none;
    color: #ef4444; /* Vermelho */
    border-top: 1px solid #475569;
    padding-top: 20px;
}

.sidebar .menu .btn-logout:hover {
    background-color: #991b1b;
    color: #fff;
    border-left: none;
    padding-left: 24px;
}

/* ==========================================================================
   3. ÁREA DE CONTEÚDO PRINCIPAL (MAIN CONTENT)
   ========================================================================== */
.main-content {
    margin-left: 260px; /* Empurra o conteúdo para não ficar sob a sidebar fixa */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* Barra Superior */
.topbar {
    background-color: #fff;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Alinha infos do usuário à direita */
    padding: 0 30px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.user-info {
    font-size: 0.95rem;
    color: #475569;
}

/* Badge indicando o nível do usuário (Aluno, Professor, etc) */
.badge-nivel {
    background-color: #e2e8f0;
    color: #475569;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-left: 8px;
    display: inline-block;
}

/* Corpo do Dashboard */
.dashboard-body {
    padding: 30px;
    flex-grow: 1; /* Ocupa o espaço vertical restante, empurrando o footer para o fim */
}

.dashboard-body h1 {
    font-size: 1.8rem;
    color: #0f172a;
    margin-bottom: 8px;
}

.dashboard-body p {
    color: #64748b;
    margin-bottom: 30px;
}

/* Rodapé fixo ao fim de .main-content */
footer {
    padding: 16px 30px;
    color: #94a3b8;
    font-size: 0.85rem;
    border-top: 1px solid #e2e8f0;
}

.cabecalho-lista {
    display: flex;
    align-items: center;
    gap: 200px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.cabecalho-lista h1,
.cabecalho-lista .form-busca {
    margin-bottom: 0;
}

/* ==========================================================================
   4. CARDS DE ATALHO (GRID)
   ========================================================================== */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.card {
    background-color: #fff;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.06);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 10px 15px rgba(0, 0, 0, 0.03);
}

.card h3 {
    font-size: 1.15rem;
    color: #334155;
    margin-bottom: 10px;
}

.card p {
    font-size: 0.9rem;
    color: #627d98;
    margin-bottom: 20px;
    flex-grow: 1; /* Garante que o link fique sempre embaixo se o texto for curto */
}

.card-link {
    color: #0284c7;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: color 0.2s;
}

.card-link:hover {
    color: #0369a1;
}

/* ==========================================================================
   5. OPÇÕES "EM BREVE" (sidebar e lista de gerenciar conta)
   ========================================================================== */
.sidebar .menu .opcao-em-breve {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    font-size: 0.95rem;
    color: #64748b;
    cursor: default;
}

.sidebar .menu .opcao-em-breve small {
    margin-left: 6px;
    font-size: 0.75rem;
    font-style: italic;
}

.lista-opcoes-conta {
    list-style: none;
    margin-top: 20px;
    max-width: 480px;
}

.lista-opcoes-conta li {
    padding: 14px 4px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.95rem;
}

.lista-opcoes-conta li a {
    color: #0284c7;
    text-decoration: none;
    font-weight: 600;
}

.lista-opcoes-conta li a:hover {
    color: #0369a1;
}

.lista-opcoes-conta li.opcao-em-breve {
    color: #94a3b8;
    cursor: default;
}

.lista-opcoes-conta li.opcao-em-breve span {
    font-size: 0.8rem;
    font-style: italic;
    margin-left: 6px;
}

/* ==========================================================================
   6. TABELAS
   ========================================================================== */
table {
    width: 100%;
    border-collapse: collapse;
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.06);
    margin-top: 20px;
}

thead {
    background-color: #334155;
}

th {
    color: #fff;
    text-align: left;
    padding: 12px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    padding: 12px 16px;
    font-size: 0.9rem;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background-color: #f8fafc;
}

table a {
    color: #0284c7;
    text-decoration: none;
    font-weight: 600;
}

table a:hover {
    color: #0369a1;
}

/* ==========================================================================
   7. FORMULÁRIOS
   ========================================================================== */
/* Cada campo é uma linha: label com largura fixa à esquerda,
   caixa de texto com largura fixa alinhada à direita da label. */
.form-row {
    display: flex;
    align-items: center;
    margin-bottom: 18px;
}

.form-row label {
    width: 160px;
    flex-shrink: 0;
    font-size: 0.95rem;
    color: #334155;
    font-weight: 600;
}

.form-row input,
.form-row select {
    width: 320px;
    max-width: 100%;
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    color: #334155;
}

.form-row input:focus,
.form-row select:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.campo-senha {
    position: relative;
    width: 320px;
    max-width: 100%;
}

.campo-senha input {
    width: 100%;
    padding-right: 42px;
}

.alternar-senha {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    border-radius: 6px;
    padding: 0;
    color: #94a3b8;
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.alternar-senha:hover {
    color: #334155;
    background-color: #f1f5f9;
}

.alternar-senha svg {
    display: block;
}

button[type="submit"] {
    background-color: #334155;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

button[type="submit"]:hover {
    background-color: #475569;
}

.lista-niveis-atuais {
    list-style: none;
    margin: 12px 0 24px;
}

.lista-niveis-atuais li {
    display: flex;
    align-items: center;
    padding: 8px 0;
    font-size: 0.95rem;
    color: #334155;
}

.lista-niveis-atuais .nome-nivel {
    width: 160px;
    flex-shrink: 0;
}

.lista-niveis-atuais li form {
    display: contents;
}

/* ==========================================================================
   8. BUSCA E PAGINAÇÃO (listarUsuarios.php)
   ========================================================================== */
.form-busca {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.form-busca input[type="text"] {
    width: 320px;
    max-width: 100%;
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    color: #334155;
}

.form-busca input[type="text"]:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.link-limpar-busca {
    color: #64748b;
    text-decoration: none;
    font-size: 0.9rem;
}

.link-limpar-busca:hover {
    color: #334155;
    text-decoration: underline;
}

.info-paginacao {
    color: #64748b;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.paginacao {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 20px;
}

.paginacao a,
.paginacao .pagina-atual {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 0.9rem;
    text-decoration: none;
}

.paginacao a {
    color: #334155;
    background-color: #fff;
    border: 1px solid #e2e8f0;
}

.paginacao a:hover {
    background-color: #f1f5f9;
}

.paginacao .pagina-atual {
    background-color: #334155;
    color: #fff;
    font-weight: 600;
}

/* ==========================================================================
   9. RESPONSIVIDADE (TELA MENORES)
   ========================================================================== */
@media (max-width: 768px) {
    .dashboard-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
    }

    .main-content {
        margin-left: 0;
    }

    .sidebar .menu {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 5px;
    }

    .sidebar .menu a {
        padding: 10px 15px;
        font-size: 0.85rem;
    }

    .sidebar .menu .btn-logout {
        margin-top: 0;
        border-top: none;
        padding-top: 10px;
    }

    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .form-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .form-row label {
        width: auto;
        margin-bottom: 6px;
    }

    .form-row input,
    .form-row select {
        width: 100%;
    }

    .form-busca {
        flex-wrap: wrap;
    }

    .form-busca input[type="text"] {
        width: 100%;
    }

    .cabecalho-lista {
        gap: 12px;
    }

    main.conteudo-com-sidebar {
        padding: 0 0.5rem;
    }

    .conteudo-com-sidebar .conteudo-principal section {
        padding: 16px;
    }
}

/* ==========================================================================
   10. PÁGINAS PÚBLICAS (login e outras que ainda usam a estrutura antiga
   main.conteudo-com-sidebar > .conteudo-principal > section, em vez do
   dashboard novo com .sidebar/.main-content)
   ========================================================================== */
main.conteudo-com-sidebar {
    max-width: 900px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.conteudo-com-sidebar .conteudo-principal section {
    background-color: #fff;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.conteudo-com-sidebar .conteudo-principal section h2 {
    color: #0f172a;
    margin-bottom: 16px;
}

/* ==========================================================================
   11. NOVA LISTA (seleção de itens em duas colunas + carrinho lateral)
   ========================================================================== */
.layout-nova-lista {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.coluna-principal {
    flex: 2;
    min-width: 0;
}

.coluna-carrinho {
    flex: 3;
    min-width: 420px;
    flex-shrink: 0;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.06);
    border: 1px solid #e2e8f0;
    padding: 20px;
    position: sticky;
    top: 20px;
}

.coluna-carrinho h2 {
    font-size: 1.1rem;
    color: #0f172a;
    margin-bottom: 12px;
}

.coluna-carrinho table {
    margin-top: 0;
    box-shadow: none;
    border: 1px solid #e2e8f0;
}

.coluna-carrinho form {
    margin-top: 16px;
}

.coluna-carrinho .form-row label {
    width: auto;
    display: block;
    margin-bottom: 6px;
}

.coluna-carrinho .form-row input {
    width: 100%;
}

.coluna-carrinho .form-row {
    flex-direction: column;
    align-items: stretch;
}

/* Resultados de busca (também usado no fragmento AJAX) */
.lista-busca-itens {
    list-style: none;
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    margin-bottom: 24px;
    overflow: hidden;
}

.lista-busca-itens li {
    display: block;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.lista-busca-itens li:last-child {
    border-bottom: none;
}

.linha-item-busca {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
}

.lista-precos-item {
    list-style: none;
    margin-top: 8px;
    padding-left: 4px;
    border-top: 1px dashed #e2e8f0;
    padding-top: 8px;
}

.lista-precos-item li {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: none;
    font-size: 0.85rem;
}

.lista-precos-item .nome-mercado-preco {
    color: #475569;
}

.lista-precos-item .valor-preco {
    color: #0284c7;
    font-weight: 600;
}

.sem-preco-item {
    margin-top: 8px;
    font-size: 0.8rem;
    color: #94a3b8;
    font-style: italic;
}

.lista-busca-itens .nome-item {
    font-weight: 600;
    color: #334155;
    margin-right: 8px;
}

.lista-busca-itens .detalhe-item {
    color: #64748b;
    font-size: 0.85rem;
    flex-grow: 1;
}

.botao-adicionar {
    background-color: #334155;
    color: #fff;
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background-color 0.2s ease;
}

.botao-adicionar:hover {
    background-color: #475569;
}

.selo-nao-encontrado {
    background-color: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.aviso-sem-preco {
    background-color: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.9rem;
    margin-bottom: 16px;
}

/* Grade de categorias */
.categorias-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.categoria-bloco {
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    padding: 16px;
}

.categoria-bloco h3 {
    font-size: 1rem;
    color: #0f172a;
    margin-bottom: 10px;
}

.categoria-bloco ul {
    list-style: none;
}

.categoria-bloco li {
    padding: 4px 0;
}

.categoria-bloco li a {
    color: #0284c7;
    text-decoration: none;
    font-size: 0.9rem;
}

.categoria-bloco li a:hover {
    color: #0369a1;
    text-decoration: underline;
}

.categoria-bloco em {
    color: #94a3b8;
    font-size: 0.85rem;
}

/* Cards inteiros viraram <a>, não só o texto final —
   remove decoração padrão de link e mantém cursor de clique */
.card {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

/* Comparação de preços do carrinho (melhor geral + por mercado) */
.comparacao-carrinho {
    margin: 16px 0;
    padding: 14px;
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
}

.comparacao-carrinho .melhor-geral {
    font-size: 0.95rem;
    color: #166534;
    margin-bottom: 8px;
}

.comparacao-carrinho .melhor-geral strong {
    font-size: 1.05rem;
}

.detalhe-melhor-geral {
    margin-top: 6px;
    font-size: 0.85rem;
}

.detalhe-melhor-geral summary {
    cursor: pointer;
    color: #0284c7;
    font-weight: 600;
}

.detalhe-melhor-geral .grupo-mercado-nome {
    font-weight: 700;
    color: #166534;
    margin-top: 10px;
    margin-bottom: 2px;
}

.detalhe-melhor-geral .grupo-mercado-subtotal {
    text-align: right;
    font-size: 0.85rem;
    color: #166534;
    border-top: 1px dashed #bbf7d0;
    padding-top: 4px;
    margin-bottom: 4px;
}

.detalhe-melhor-geral ul {
    list-style: none;
    margin-top: 6px;
    padding-left: 8px;
}

.detalhe-melhor-geral li {
    padding: 3px 0;
    color: #475569;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.lista-mercados-comparacao {
    list-style: none;
    border-top: 1px solid #bbf7d0;
    padding-top: 8px;
}

.lista-mercados-comparacao li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.9rem;
}

.lista-mercados-comparacao .nome-mercado-preco {
    color: #334155;
}

.lista-mercados-comparacao .nome-mercado-preco small {
    color: #94a3b8;
    font-size: 0.75rem;
}

.lista-mercados-comparacao .valor-preco {
    color: #166534;
    font-weight: 600;
}

.link-imprimir {
    text-decoration: none;
    font-size: 0.9rem;
    margin-left: 6px;
}

.opcoes-upload-cupom {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.botao-upload-cupom {
    background-color: #fff;
    color: #334155;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.botao-upload-cupom:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
}

.divisor-historico {
    display: flex;
    align-items: center;
    margin: 30px 0 12px;
    color: #94a3b8;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.divisor-historico::before,
.divisor-historico::after {
    content: '';
    flex: 1;
    height: 1px;
    background-color: #cbd5e1;
}

.divisor-historico span {
    padding: 0 12px;
}

.tabela-historico {
    opacity: 0.85;
}

.tabela-historico thead {
    background-color: #94a3b8;
}

/* Card de destaque na tela inicial (Iniciar Minha Lista) */
.card-destaque {
    border: 2px solid #38bdf8;
    background: linear-gradient(135deg, #ffffff 0%, #f0f9ff 100%);
}

.card-destaque h3 {
    color: #0284c7;
}

/* Ícone de carrinho flutuante, com contador de itens */
.carrinho-flutuante {
    position: fixed;
    top: 84px;
    right: 30px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    background-color: #fbbf24;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    text-decoration: none;
    transition: transform 0.15s ease;
}

.carrinho-flutuante:hover {
    transform: scale(1.05);
}

.carrinho-flutuante svg {
    width: 26px;
    height: 26px;
    stroke: #78350f;
}

.carrinho-flutuante .contador-carrinho {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 4px;
    background-color: #ef4444;
    color: #fff;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

@media (max-width: 900px) {
    .layout-nova-lista {
        flex-direction: column;
    }

    .coluna-carrinho {
        width: 100%;
        position: static;
    }
}
