@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');

:root {
    --bg-color: #f4f7f9;
    --container-bg-color: #fff;
    --text-color: #333;
    --title-color: #2c3e50;
    --border-color: #eef;
    --table-header-bg: #ecf0f1;
    --table-border-color: #ddd;
    --input-focus-bg: #fdf3e6;
    --reserva-bg-inicial: #f0f4f8;
    --reserva-border-inicial: #d6e0ea;
    --sidebar-bg: #ffffff;
    --sidebar-border: #eef;
    --sidebar-text: #333;
    --sidebar-active-bg: #3498db;
    --sidebar-active-text: #ffffff;
    --positivo: #27ae60;
    --negativo: #c0392b;
    /* Cores de Alerta */
    --alerta-vermelho: #c0392b;
    --alerta-laranja: #f39c12;
    --alerta-verde: #27ae60;
}

body.dark-mode {
    --bg-color: #121212;
    --container-bg-color: #1e1e1e;
    --text-color: #e0e0e0;
    --title-color: #ffffff;
    --border-color: #2c2c2c;
    --table-header-bg: #2a2a2a;
    --table-border-color: #444;
    --input-focus-bg: #332b21;
    --reserva-bg-inicial: #2c2c2c;
    --reserva-border-inicial: #444;
    --sidebar-bg: #1e1e1e;
    --sidebar-border: #2c2c2c;
    --sidebar-text: #e0e0e0;
    --sidebar-active-bg: #3498db;
    --sidebar-active-text: #ffffff;
}

html { scroll-behavior: smooth; }

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    transition: background-color 0.3s, color 0.3s;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

/* --- LAYOUT DASHBOARD --- */
.dashboard-container { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    transition: background-color 0.3s, border-color 0.3s, transform 0.3s ease-in-out;
}

.sidebar-header {
    font-size: 1.5em; font-weight: 700; color: var(--title-color);
    padding: 20px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header img {
    max-width: 160px;
    height: auto;
    vertical-align: middle;
}

.sidebar-menu { list-style: none; padding: 20px; margin: 0; flex-grow: 1; }
.sidebar-menu li { margin-bottom: 10px; }
.sidebar-menu a {
    display: block; padding: 12px 15px; text-decoration: none;
    color: var(--sidebar-text); border-radius: 8px; font-weight: 500;
    transition: background-color 0.2s, color 0.2s; cursor: pointer;
}
.sidebar-menu li.active a,
.sidebar-menu a:hover {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}
.sidebar-footer {
    padding: 20px; border-top: 1px solid var(--sidebar-border);
    display: flex; justify-content: center; align-items: center;
}
#theme-toggle {
    background: none; border: 1px solid var(--table-border-color);
    border-radius: 50%; width: 40px; height: 40px; font-size: 20px;
    cursor: pointer; transition: background-color 0.3s, color 0.3s;
    color: var(--text-color);
}
#theme-toggle:hover { background-color: var(--bg-color); }

.main-content {
    flex-grow: 1;
    padding: 30px;
    overflow-y: auto;
    min-height: 100vh;
    box-sizing: border-box;
    width: 100%;
}
.main-header { 
    margin-bottom: 20px; 
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.main-header h1 { color: var(--title-color); margin: 0; }

/* --- SISTEMA DE PÁGINAS --- */
.page-section {
    display: none;
}
.page-section.active {
    display: block;
}

/* --- CARDS DE ESTATÍSTICAS (READ-ONLY) --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}
.stat-card {
    background-color: var(--container-bg-color);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    transition: background-color 0.3s;
    
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 90px;
    box-sizing: border-box;
}
.stat-card label {
    display: block; font-weight: 600; margin-bottom: 5px;
    font-size: 0.9em; color: var(--text-color); text-transform: uppercase;
}
.stat-card .stat-value {
    font-size: 1.8em;
    font-weight: 700;
    line-height: 1.2;
}
#stats-renda-fluxo { color: var(--positivo); }
#stats-despesas { color: var(--negativo); }
#stats-saldo-final.positivo { color: var(--positivo); }
#stats-saldo-final.negativo { color: var(--negativo); }
#stats-patrimonio-total.positivo { color: var(--positivo); }
#stats-patrimonio-total.negativo { color: var(--negativo); }


.stat-card-highlight {
    border: 2px solid var(--border-color);
    padding: 20px;
    transition: border-color 0.5s ease;
}
.stat-card-highlight .sugestao-item {
    padding: 0;
    border-left: none;
    box-shadow: none;
    color: var(--text-color); 
    font-size: 1.05em;
    line-height: 1.6;
}
.stat-card-highlight .sugestao-item strong {
     color: var(--title-color);
     font-weight: 700;
}

.section-title-highlight {
    font-size: 1.5em; font-weight: 600; color: var(--title-color);
    margin-top: 0; margin-bottom: 20px;
}

/* --- GRID DE CONTEÚDO (DASHBOARD) --- */
.main-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
}

/* --- COMPONENTES GENÉRICOS --- */
.content-box {
    background-color: var(--container-bg-color);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    transition: background-color 0.3s;
    margin-bottom: 30px;
}
.section-title {
    font-size: 1.5em; font-weight: 600; color: var(--title-color);
    margin-top: 0; margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color); padding-bottom: 10px;
}

.input-container label {
    display: block; font-weight: 600; margin-bottom: 10px;
    font-size: 1.1em;
}
.input-container input[type="number"] {
    width: 100%;
    max-width: 300px;
    padding: 12px;
    font-size: 1.2em;
    border: 1px solid var(--table-border-color);
    border-radius: 5px;
    font-weight: 600;
    background-color: var(--bg-color);
    color: var(--text-color);
    box-sizing: border-box;
}

/* --- ESTILOS DE TABELA --- */
.table-container { 
    /* Mantém o overflow-x: auto como uma segurança,
       mas a meta é não usá-lo */
    overflow-x: auto;
    width: 100%;
}
table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-bottom: 20px; 
    /* table-layout: fixed força a tabela a ter 100% de largura
       e força o conteúdo a quebrar */
    table-layout: fixed; 
}
th, td { 
    padding: 12px 8px; 
    text-align: center; 
    border: 1px solid var(--table-border-color); 
    
    /* CORREÇÃO: Esta é a nova propriedade.
       Ela quebra a linha ENTRE palavras, não em letras. */
    overflow-wrap: break-word;

    /* (A propriedade 'word-break: break-word' foi removida) */
}
thead th { 
    background-color: var(--table-header-bg); 
    font-weight: 600; 
}

#despesas-table tbody td input { 
    padding: 8px; 
    border: none; 
    background-color: transparent; 
    font-family: 'Poppins', sans-serif; 
    font-size: 1em; 
    text-align: center; 
    color: var(--text-color);
    width: 100%;
    min-width: 80px; /* Garante um espaço mínimo para o input */
    box-sizing: border-box;
}
#despesas-table tbody td input:focus { background-color: var(--input-focus-bg); outline: 1px solid #e67e22; }

.resultado-col { font-weight: 700; }
.positivo { color: var(--positivo); }
.negativo { color: var(--negativo); }
.mes-header { font-weight: 600; text-align: left; }

#dashboard-tabela-principal td { padding: 10px 8px; font-size: 0.95em; }
#dashboard-tabela-principal .mes-header { font-size: 1em; }


.renda-variavel-item {
    display: flex; 
    gap: 10px; 
    margin-bottom: 10px; 
    align-items: center;
    flex-wrap: wrap;
}
.renda-variavel-item input[type="text"] { 
    flex-grow: 1; 
    flex-basis: 100%;
}
.renda-variavel-item input[type="number"] {
    flex-grow: 1;
}
.renda-variavel-item input { 
    padding: 8px; 
    border: 1px solid var(--table-border-color); 
    border-radius: 5px; 
    background-color: var(--container-bg-color); 
    color: var(--text-color); 
}

/* --- PAINEL RESERVA (Estilo unificado) --- */
.painel-reserva-container {
    background-color: var(--reserva-bg-inicial); border: 1px solid var(--reserva-border-inicial);
    position: relative; overflow: hidden;
    transition: background-color 0.5s, border-color 0.5s;
}
.painel-reserva-container::before {
    content: ''; position: absolute; bottom: -80px; right: -100px; width: 300px; height: 300px; z-index: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cdefs%3E%3CradialGradient id='grad' cx='50%25' cy='50%25' r='50%25' fx='50%25' fy='50%25'%3E%3Cstop offset='0%25' style='stop-color:rgb(255,223,0);stop-opacity:1' /%3E%3Cstop offset='100%25' style='stop-color:rgb(255,165,0);stop-opacity:1' /%3E%3C/defs%3E%3Ccircle cx='50' cy='50' r='45' fill='url(%23grad)' stroke='%23DAA520' stroke-width='3'/%3E%3Ctext x='50' y='65' font-family='Arial, sans-serif' font-size='40' font-weight='bold' fill='%23B8860B' text-anchor='middle'%3E$%3C/text%3E%3C/svg%3E");
    background-repeat: no-repeat; background-size: contain; opacity: 0.1; transform: rotate(-15deg);
}
body.dark-mode .painel-reserva-container { background-color: var(--reserva-bg-inicial); }
body.dark-mode .painel-reserva-container::before { opacity: 0.05; }

.progress-bar-container { width: 100%; background-color: #555; border-radius: 10px; overflow: hidden; margin-top: 15px; }
.progress-bar { height: 25px; width: 0%; background-color: var(--positivo); text-align: center; color: white; line-height: 25px; font-weight: 600; transition: width 0.5s ease; }
.reserva-status { font-size: 1.3em; font-weight: 600; margin-bottom: 15px; }
.reserva-chart-wrapper { display: flex; align-items: center; justify-content: center; min-height: 220px; background-color: rgba(0,0,0,0.02); border-radius: 8px; margin-top: 20px; }
.reserva-gif { max-width: 100%; max-height: 200px; border-radius: 8px; object-fit: contain; }

.reserva-gamify {
    font-size: 0.95em;
    font-weight: 500;
    margin-top: -10px;
    margin-bottom: 15px;
    color: var(--text-color);
    line-height: 1.4;
}

@keyframes glow-sutil-animation {
    0% { box-shadow: 0 0 4px rgba(255, 215, 0, 0.4); }
    50% { box-shadow: 0 0 16px rgba(255, 215, 0, 0.7); }
    100% { box-shadow: 0 0 4px rgba(255, 215, 0, 0.4); }
}
.painel-reserva-container.meta-alcancada { 
    animation: glow-sutil-animation 2.5s infinite ease-in-out; 
}

.controls { display: flex; gap: 15px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.controls input[type="text"] { padding: 10px; border: 1px solid var(--table-border-color); border-radius: 5px; flex-grow: 1; background-color: var(--container-bg-color); color: var(--text-color); }
.controls button, .add-btn { padding: 10px 15px; border: none; border-radius: 5px; background-color: #3498db; color: white; font-weight: 600; cursor: pointer; transition: background-color 0.2s; }
.controls button.reset-btn { background-color: #e74c3c; }
.controls button:hover, .add-btn:hover { opacity: 0.85; }
.delete-btn { color: var(--negativo); font-weight: bold; cursor: pointer; margin-left: 8px; }

.cta-button {
    padding: 10px 15px;
    border: none;
    border-radius: 5px;
    background-color: #3498db;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 15px;
    width: 100%;
}
.cta-button:hover {
    opacity: 0.85;
}


/* --- PÁGINA ANÁLISE --- */
.pie-charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 25px; text-align: center; }
.pie-charts-grid.compact-view { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.pie-chart-container h3 { margin-bottom: 10px; font-size: 1.1em; color: var(--title-color); }
.pie-chart-wrapper {
    position: relative;
    height: 300px; 
    width: 100%;
}
.pie-chart-container canvas {
    max-width: 100%;
    max-height: 100%;
}

/* --- ESTILOS PÁGINA PATRIMÔNIO (SIMPLIFICADO) --- */
#patrimonio-table { width: 100%; }
#patrimonio-table td {
    padding: 10px 5px; border-bottom: 1px solid var(--border-color);
}
#patrimonio-table tr:last-child td { border-bottom: none; }

/* ============================================= */
/* ESTILOS DA CAIXA DE MOVIMENTAÇÃO (RESERVA) */
/* ============================================= */
.movimento-reserva-container .input-container input[type="number"] {
    max-width: 100%;
}

.movimento-reserva-container .input-container input[type="text"] {
    width: 100%;
    max-width: 100%;
    padding: 12px;
    font-size: 1.1em;
    border: 1px solid var(--table-border-color);
    border-radius: 5px;
    background-color: var(--bg-color);
    color: var(--text-color);
    box-sizing: border-box; 
}


.movimento-reserva-botoes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 20px;
}
.movimento-btn {
    padding: 12px 15px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}
.movimento-btn:hover {
    opacity: 0.85;
}
.movimento-btn.add {
    background-color: var(--positivo);
    color: white;
}
.movimento-btn.remove {
    background-color: var(--negativo);
    color: white;
}


/* ============================================= */
/* NOVOS ESTILOS: MENU MOBILE E RESPONSIVIDADE */
/* ============================================= */

.menu-toggle {
    display: none; 
    font-size: 28px;
    font-weight: bold;
    background: transparent;
    border: none;
    color: var(--title-color);
    cursor: pointer;
    padding: 0 10px;
    z-index: 1100; 
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 900;
}
.overlay.active {
    display: block;
}


@media (max-width: 1100px) { 
    .main-grid { 
        grid-template-columns: 1fr; 
    } 
}

/* --- ESTILOS DE TELEMÓVEL --- */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    .dashboard-container {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: 0; 
        top: 0; 
        height: 100%;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1000;
        width: 240px; 
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
        box-shadow: 5px 0 15px rgba(0,0,0,0.2);
    }
    
    .menu-toggle {
        display: block; 
    }

    .main-content {
        padding: 15px; 
        width: 100%;
        box-sizing: border-box;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .pie-chart-wrapper {
        height: 250px; 
    }

    /* CORREÇÃO: Implementa a sua sugestão de fonte menor */
    th, td {
        font-size: 0.9em; /* 10% menor */
        padding: 8px 4px; /* Menos padding lateral */
    }
}

@media (max-width: 500px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    .controls input[type="text"] {
        width: 100%;
        box-sizing: border-box;
    }
    
    .controls input[type="number"] {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* CORREÇÃO: Reduz ainda mais a fonte em ecrãs muito pequenos */
    th, td {
        font-size: 0.85em; /* 15% menor */
    }

    /* Inputs da tabela principal de despesas */
    #despesas-table tbody td input {
        font-size: 1em; /* 1em relativo ao 0.85em do 'td' */
        padding: 6px 2px;
        min-width: 70px; /* Reduz o min-width */
    }
}