/* Estilos Gerais */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f8f9fa;
    color: #212529;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 16px; /* Base font size */
}

header {
    background-color: #005f73;
    color: #fff;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
}

/* Navegação */
header nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

header nav ul li a {
    color: #fff;
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 0;
    border-bottom: 2px solid transparent;
    transition: border-bottom-color 0.2s ease-in-out, color 0.2s ease-in-out;
}

header nav ul li a:hover,
header nav ul li a.active {
    color: #e9d8a6;
    border-bottom-color: #e9d8a6;
}

main {
    padding: 1.5rem;
    max-width: 1200px;
    margin: 1.5rem auto;
    display: grid;
    gap: 1.5rem;
}

section {
    background-color: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #dee2e6;
}

section h2 {
    margin-top: 0;
    color: #005f73;
    border-bottom: 2px solid #e9d8a6;
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 600;
}

section h3 {
    color: #0077b6;
    margin-bottom: 1rem;
    font-size: 1.25rem;
    font-weight: 600;
}

/* Resumo Geral */
#resumo .cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.5rem;
}

#resumo .card {
    background-color: #ffffff;
    padding: 1.25rem;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #dee2e6;
    box-shadow: none;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

#resumo .card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
}

#resumo .card h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    color: #495057;
    font-size: 1rem;
    font-weight: 600;
}

#resumo .card p {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
    color: #0a9396;
}

#resumo .card #total-despesa {
    color: #ae2012;
}

#resumo .card #saldo-atual {
    color: #005f73;
}

#resumo .card #taxa-poupanca {
    color: #2a9d8f;
}

/* Gráficos */
.grafico-container {
    height: 350px;
    position: relative;
    border: 1px solid #dee2e6;
    padding: 1rem;
    border-radius: 4px;
    background-color: #fff;
}

/* Tabelas */
.table-container {
    overflow-x: auto;
    margin-top: 1rem;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

table {
    width: 100%;
    border-collapse: collapse;
    /* white-space: nowrap; REMOVED - Allow wrapping where appropriate */
}

table th,
table td {
    padding: 0.8rem 1rem;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
    vertical-align: middle;
    white-space: nowrap; /* Keep content on one line initially */
}

table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
    white-space: normal; /* Allow header text to wrap */
    border-bottom-width: 2px;
}

table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

table tbody tr:hover {
    background-color: #e9ecef;
}

/* Align numeric columns to the right */
table td:nth-child(2):not(:has(button)),
table td:nth-child(3):not(:has(button)),
table td:nth-child(4):not(:has(button)),
table td:nth-child(5):not(:has(button)) {
    text-align: right;
    font-feature-settings: "tnum";
}

/* Specific table adjustments */
#analise-metas td:nth-child(5), /* Status */
#tabela-categorias-body td:nth-child(3), /* Ações */
#tabela-metas-body td:nth-child(3), /* Ações */
#tabela-receitas-body td:nth-child(5) { /* Ações */
    text-align: center;
    white-space: nowrap;
}

#tabela-transacoes td:nth-child(4) { /* Tipo */
    text-align: left;
}

/* Formulários */
form {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #495057;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 1rem;
    background-color: #fff;
    transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #0a9396;
    box-shadow: 0 0 0 3px rgba(10, 147, 150, 0.15);
}

button[type="submit"],
.btn-editar,
.btn-excluir {
    padding: 0.7rem 1.3rem; /* Slightly larger tap target */
    border: none;
    border-radius: 4px;
    font-size: 1rem; /* Ensure readable font size */
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out, transform 0.1s ease-in-out;
    color: #fff;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

button[type="submit"]:active,
.btn-editar:active,
.btn-excluir:active {
    transform: translateY(1px);
}

button[type="submit"] {
    background-color: #0a9396;
}

button[type="submit"]:hover {
    background-color: #0077b6;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-editar {
    background-color: #ffb703;
    margin-right: 0.5rem;
}

.btn-editar:hover {
    background-color: #fb8500;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn-excluir {
    background-color: #d00000;
}

.btn-excluir:hover {
    background-color: #9d0208;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Footer */
footer {
    text-align: center;
    margin-top: 2rem;
    padding: 1.5rem;
    background-color: #e9ecef;
    color: #6c757d;
    font-size: 0.9rem;
}

/* --- Responsividade --- */

/* Medium screens (Tablets, larger phones) */
@media (max-width: 992px) {
    main {
        padding: 1rem;
        margin: 1rem auto;
        gap: 1rem;
    }
    section {
        padding: 1rem;
    }
    header {
        padding: 1rem;
    }
    header h1 {
        font-size: 1.5rem;
    }
    header nav ul {
        gap: 1rem;
    }
    #resumo .cards-container {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }
    .grafico-container {
        height: 320px; /* Adjust height */
    }
}

/* Small screens (Mobiles) */
@media (max-width: 768px) {
    body {
        font-size: 15px;
        -webkit-text-size-adjust: 100%; /* Prevent font scaling on iOS */
    }
    header {
        flex-direction: column;
        padding: 1rem;
        text-align: center; /* Center title when stacked */
    }
    header h1 {
        margin-bottom: 0.8rem;
        font-size: 1.4rem;
    }
    header nav ul {
        justify-content: center;
        gap: 0.8rem;
        margin-top: 0.5rem; /* Add space between title and nav */
    }
    header nav ul li a {
        font-size: 0.9rem;
        padding: 0.4rem 0;
    }

    main {
        padding: 1rem 0.5rem; /* Reduce horizontal padding */
        gap: 1rem;
    }
    section {
        padding: 1rem;
    }

    section h2 {
        font-size: 1.3rem;
    }
    section h3 {
        font-size: 1.1rem;
    }

    #resumo .cards-container {
        grid-template-columns: 1fr 1fr; /* Two columns */
        gap: 0.8rem; /* Reduce gap */
    }
    #resumo .card {
        padding: 1rem;
    }
    #resumo .card h3 {
        font-size: 0.9rem;
    }
    #resumo .card p {
        font-size: 1.3rem; /* Reduce font size */
    }

    .grafico-container {
        height: 280px; /* Further reduce height */
        padding: 0.5rem; /* Reduce padding */
    }

    /* Table adjustments for mobile */
    .table-container {
        margin-top: 0.8rem;
    }
    table th,
    table td {
        padding: 0.6rem 0.5rem; /* Reduce padding */
        font-size: 0.85rem;
        white-space: normal; /* Allow content wrapping */
    }
    /* Make specific columns wrap or hide */
    #tabela-transacoes th:nth-child(3), /* Categoria */
    #tabela-transacoes td:nth-child(3) {
        /* Example: Hide category column on small screens */
        /* display: none; */ 
        /* Or allow wrapping */
         white-space: normal;
         min-width: 80px; /* Give it some minimum space */
    }
    #tabela-transacoes th:nth-child(2), /* Descrição */
    #tabela-transacoes td:nth-child(2) {
         white-space: normal;
         min-width: 100px;
    }
    #analise-metas th,
    #analise-metas td {
        white-space: normal;
    }

    form {
        padding: 1rem;
    }

    button[type="submit"],
    .btn-editar,
    .btn-excluir {
        padding: 0.6rem 1.1rem; /* Adjust padding */
        font-size: 0.95rem;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    body {
        font-size: 14px;
    }
    header h1 {
        font-size: 1.3rem;
    }
    header nav ul {
        gap: 0.5rem;
    }
    header nav ul li a {
        padding: 0.3rem 0;
    }
    main {
        padding: 0.8rem 0.3rem;
    }
    section {
        padding: 0.8rem;
    }
    section h2 {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }
    section h3 {
        font-size: 1rem;
        margin-bottom: 0.8rem;
    }

    #resumo .cards-container {
        grid-template-columns: 1fr; /* Stack cards */
        gap: 0.5rem;
    }
    #resumo .card p {
        font-size: 1.2rem;
    }

    .grafico-container {
        height: 250px; /* Even smaller height */
    }

    table th,
    table td {
        padding: 0.5rem 0.4rem;
        font-size: 0.8rem;
    }
    /* Example: Hide more columns on very small screens */
    #tabela-transacoes th:nth-child(3), /* Categoria */
    #tabela-transacoes td:nth-child(3) {
        display: none; /* Hide category */
    }
    #analise-metas th:nth-child(4), /* Diferença */
    #analise-metas td:nth-child(4) {
        display: none; /* Hide difference */
    }

    button[type="submit"],
    .btn-editar,
    .btn-excluir {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}



/* --- Menu Sanduíche (Hamburger) --- */
.menu-toggle {
    display: none; /* Oculto por padrão (desktop) */
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    margin-left: 1rem; /* Espaço à esquerda */
    z-index: 1001; /* Acima do conteúdo */
}

.menu-toggle .bar {
    display: block;
    width: 25px;
    height: 3px;
    background-color: #fff;
    margin: 5px auto;
    transition: all 0.3s ease-in-out;
    border-radius: 2px;
}

/* Estilos para telas pequenas (onde o menu sanduíche aparece) */
@media (max-width: 768px) {
    .menu-toggle {
        display: block; /* Exibe o botão no mobile */
    }

    .nav-menu {
        display: none; /* Esconde o menu normal */
        position: absolute;
        top: 60px; /* Ajustar conforme altura do header */
        left: 0;
        width: 100%;
        background-color: #005f73; /* Mesmo fundo do header */
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        padding: 1rem 0;
        z-index: 1000;
    }

    .nav-menu.active {
        display: block; /* Exibe o menu quando ativo */
    }

    .nav-menu ul {
        flex-direction: column; /* Empilha os itens */
        align-items: center;
        gap: 0; /* Remove gap original */
        margin-top: 0; /* Remove margin-top anterior */
    }

    .nav-menu ul li {
        width: 100%;
        text-align: center;
    }

    .nav-menu ul li a {
        display: block;
        padding: 0.8rem 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* Separador leve */
        font-size: 1rem;
    }
    .nav-menu ul li:last-child a {
        border-bottom: none;
    }

    .nav-menu ul li a:hover,
    .nav-menu ul li a.active {
        background-color: rgba(255, 255, 255, 0.1);
        border-bottom-color: transparent; /* Remove borda no hover/active */
        color: #e9d8a6;
    }

    /* Animação do botão hamburger para 'X' */
    .menu-toggle.active .bar:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }
    .menu-toggle.active .bar:nth-child(2) {
        opacity: 0;
    }
    .menu-toggle.active .bar:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }

    /* Ajuste no header para acomodar o botão */
    header {
        flex-direction: row; /* Mantém lado a lado no mobile */
        justify-content: space-between; /* Espaça título e botão */
        text-align: left; /* Alinha título à esquerda */
    }
    header h1 {
        margin-bottom: 0; /* Remove margem inferior */
    }
}



/* --- Melhorias Responsividade Tabelas --- */
@media (max-width: 768px) {
    /* Esconde cabeçalhos da tabela */
    table thead {
        display: none;
    }
    /* Transforma linhas em blocos */
    table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 4px;
        overflow: hidden; /* Garante que bordas arredondadas funcionem */
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }
    table tbody tr:nth-child(even) {
        background-color: #fff; /* Remove zebra striping no modo bloco */
    }
    table tbody tr:hover {
        background-color: #f8f9fa; /* Ajusta hover */
    }

    /* Transforma células em linhas, com label */
    table td {
        display: block;
        text-align: right; /* Alinha valor à direita */
        padding-left: 50%; /* Espaço para o label */
        position: relative;
        border-bottom: 1px solid #e9ecef; /* Linha separadora mais leve */
        white-space: normal; /* Permite quebra de linha */
    }
    table td:last-child {
        border-bottom: none; /* Remove borda da última célula */
    }

    /* Adiciona o label antes do conteúdo da célula */
    table td::before {
        content: attr(data-label);
        position: absolute;
        left: 10px; /* Posição do label */
        width: 45%; /* Largura do label */
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: bold;
        color: #495057;
    }

    /* Ajustes específicos para colunas de ação */
    #tabela-categorias-body td:nth-child(3),
    #tabela-metas-body td:nth-child(3),
    #tabela-receitas-body td:nth-child(5) {
        text-align: center; /* Centraliza botões */
        padding-left: 0; /* Remove padding para centralizar */
    }
    #tabela-categorias-body td:nth-child(3)::before,
    #tabela-metas-body td:nth-child(3)::before,
    #tabela-receitas-body td:nth-child(5)::before {
        display: none; /* Esconde label para colunas de ação */
    }

    /* Remove overflow-x do container, pois a tabela não precisa mais rolar */
    .table-container {
        overflow-x: visible;
        border: none;
        border-radius: 0;
    }
}

@media (max-width: 480px) {
    /* Ajustes finos para telas extra pequenas, se necessário */
    table td {
        padding-left: 40%;
    }
    table td::before {
        width: 35%;
    }
    /* Ocultar colunas menos importantes se ainda for necessário */
    #analise-metas td[data-label="Diferença (R$)"] {
        /* display: none; */ /* Exemplo: Ocultar diferença */
    }
}



/* --- Destaque Meta Ultrapassada --- */
#analise-metas tbody tr.meta-ultrapassada {
    background-color: rgba(208, 0, 0, 0.08); /* Fundo vermelho bem claro */
    border-left: 4px solid #d00000; /* Borda esquerda vermelha */
}

#analise-metas tbody tr.meta-ultrapassada:nth-child(even) {
    background-color: rgba(208, 0, 0, 0.12); /* Ajuste para zebra striping */
}

#analise-metas tbody tr.meta-ultrapassada:hover {
    background-color: rgba(208, 0, 0, 0.18); /* Hover mais escuro */
}

/* Ajuste para visualização em cartão (mobile) */
@media (max-width: 768px) {
    #analise-metas table tr.meta-ultrapassada {
        border: 1px solid #d00000; /* Borda vermelha no cartão */
        background-color: rgba(208, 0, 0, 0.05);
        box-shadow: 0 1px 3px rgba(208, 0, 0, 0.15);
    }
    #analise-metas table tr.meta-ultrapassada:hover {
        background-color: rgba(208, 0, 0, 0.1);
    }
    /* Opcional: Destacar o status também */
    #analise-metas table tr.meta-ultrapassada td[data-label="Status"] {
        color: #d00000;
        font-weight: bold;
    }
}

#filtro-data {
    background-color: #ffffff;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.filtro-container {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filtro-container label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

.filtro-container input[type="date"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 1rem;
    background-color: #f9f9f9;
    color: #333;
    transition: border-color 0.2s;
}

.filtro-container input[type="date"]:focus {
    border-color: #005f73;
    outline: none;
    background-color: #fff;
}

.filtro-container button {
    background-color: #005f73;
    color: white;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s;
}

.filtro-container button:hover {
    background-color: #007b8a;
}

@media (max-width: 768px) {
    td {
      text-align: left !important;
      padding-left: 20px !important;
    }
}
