* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

header {
    text-align: center;
    color: #333;
    padding: 15px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px 10px 0 0;
    color: white;
    position: relative;
}

.header-actions {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 10px;
}

header h1 {
    font-size: 1.5em;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

#currentYear {
    font-weight: bold;
    min-width: 60px;
}

.main-content {
    padding: 20px;
}

.btn-header {
    background: #ffd700;
    color: #333;
    border: 2px solid #ffed4e;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-header:hover {
    background: #ffed4e;
    border-color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.nav-btn-inline {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: bold;
    transition: all 0.3s;
}

.nav-btn-inline:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.6);
}

/* Tabela */
.table-container {
    overflow-x: auto;
    margin-bottom: 30px;
}

.budget-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.budget-table th {
    background: #667eea;
    color: white;
    padding: 6px 4px;
    text-align: center;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.budget-table th.category-header {
    text-align: left;
    min-width: 200px;
    background: #764ba2;
}

.budget-table th.saldo-inicial-header {
    background: #16a085;
    min-width: 100px;
}

.budget-table th.total-header {
    background: #764ba2;
}

.saldo-inicial-cell {
    cursor: pointer;
    transition: background 0.2s;
    font-weight: bold;
}

.saldo-inicial-cell:hover {
    background: rgba(22, 160, 133, 0.1) !important;
}

.saldo-inicial-cell.negative {
    color: #c0392b;
}

.budget-table td {
    padding: 4px 6px;
    text-align: center;
    border: 1px solid #e0e0e0;
}

.budget-table tbody tr:hover {
    background: #f8f9fa;
}

.separator-row:hover {
    background: transparent !important;
}

.separator-row td {
    padding: 0 !important;
}

.category-cell {
    text-align: left;
    font-weight: 500;
    color: #333;
    padding-left: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-cell.receita {
    background: #e8f5e9;
    border-left: 4px solid #4caf50;
}

.category-cell.despesa {
    background: #ffebee;
    border-left: 4px solid #f44336;
}

.category-name {
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 3px;
    transition: background 0.2s;
    display: inline-block;
}

.category-name:hover {
    background: rgba(0, 0, 0, 0.05);
}

.category-name-input {
    border: 2px solid #667eea;
    padding: 4px 8px;
    font-size: 0.9em;
    font-weight: 500;
    border-radius: 4px;
    width: 200px;
}

.category-actions {
    display: flex;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.budget-table tbody tr:hover .category-actions {
    opacity: 1;
}

.move-btn {
    background: #667eea;
    color: white;
    border: none;
    cursor: pointer;
    font-size: 0.8em;
    padding: 2px 6px;
    opacity: 0.8;
    transition: opacity 0.2s;
    border-radius: 3px;
}

.move-btn:hover {
    opacity: 1;
}

.value-cell {
    cursor: pointer;
    transition: background 0.2s;
    min-width: 90px;
}

.value-cell:hover {
    background: #e3f2fd;
}

.value-cell.editing {
    padding: 0;
}

.value-cell input {
    width: 100%;
    height: 100%;
    border: 2px solid #667eea;
    padding: 8px;
    text-align: center;
    font-size: 0.9em;
}

.total-cell {
    font-weight: bold;
    background: #f5f5f5;
    color: #333;
}

.total-row td {
    font-weight: bold;
    padding: 6px 4px;
    text-align: center;
}

.totals-label td {
    background: #2c3e50;
    color: white;
    font-size: 1.1em;
    text-align: center;
}

.receitas-row td {
    background: #27ae60;
    color: white;
}

.gastos-row td {
    background: #e74c3c;
    color: white;
}

.saldo-mes-row td {
    background: #3498db;
    color: white;
}

.saldo-mes-row td.negative {
    background: #c0392b !important;
}

.saldo-acumulado-row td {
    background: #16a085;
    color: white;
}

.saldo-acumulado-row td.negative {
    background: #c0392b !important;
}

.delete-btn {
    background: transparent;
    border: none;
    color: #f44336;
    cursor: pointer;
    font-size: 1.2em;
    padding: 0 5px;
    opacity: 0;
    transition: opacity 0.2s;
}

.budget-table tbody tr:hover .delete-btn {
    opacity: 1;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 30px;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
}

.close:hover,
.close:focus {
    color: #000;
}

.modal-content h3 {
    color: #333;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    color: #555;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1em;
    transition: border 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.btn-submit {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.3s;
}

.btn-submit:hover {
    transform: scale(1.02);
}

.empty-message {
    text-align: center;
    color: #999;
    padding: 30px;
    font-style: italic;
}

/* Previne zoom indesejado em inputs */
input, select, textarea {
    font-size: 16px;
}

/* Responsividade */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .container {
        border-radius: 0;
    }

    header {
        border-radius: 0;
        padding: 12px 10px;
    }

    header h1 {
        font-size: 1em;
        gap: 5px;
        flex-wrap: wrap;
    }

    .header-actions {
        position: static;
        transform: none;
        justify-content: center;
        margin-bottom: 8px;
        gap: 5px;
    }

    .btn-header {
        font-size: 0.75em;
        padding: 5px 10px;
    }

    .nav-btn-inline {
        font-size: 1em;
        padding: 4px 10px;
    }

    #currentYear {
        min-width: 50px;
        font-size: 1.1em;
    }

    .main-content {
        padding: 10px 5px;
    }

    .budget-table {
        font-size: 0.65em;
    }

    .budget-table th,
    .budget-table td {
        padding: 3px 2px;
    }

    .budget-table th.category-header {
        min-width: 100px;
        font-size: 0.9em;
    }

    .budget-table th.saldo-inicial-header {
        min-width: 60px;
    }

    .category-name {
        font-size: 0.95em;
    }

    .move-btn, .delete-btn {
        font-size: 0.9em;
        padding: 1px 4px;
    }

    /* Modal responsivo */
    .modal-content {
        width: 95%;
        margin: 5% auto;
        padding: 20px;
    }

    /* Tabela com scroll horizontal */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Melhora a usabilidade dos campos editáveis */
    .value-cell input,
    .category-name-input {
        font-size: 14px;
    }
}

/* Para telas muito pequenas */
@media (max-width: 480px) {
    header h1 {
        font-size: 0.85em;
    }

    .budget-table {
        font-size: 0.55em;
    }

    .btn-header {
        font-size: 0.7em;
        padding: 4px 8px;
    }
}
