/* Reset e Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #1a1a2e;
    --secondary: #16213e;
    --accent: #0f3460;
    --success: #00C851;
    --danger: #ff4444;
    --warning: #ffbb33;
    --neutral: #6c757d;
    --light: #f8f9fa;
    --dark: #212529;
    --white: #ffffff;
    --border-radius: 12px;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    min-height: 100vh;
    color: var(--dark);
}

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

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box {
    background: var(--white);
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 30px;
    font-size: 24px;
}

.login-box .subtitle {
    text-align: center;
    color: var(--neutral);
    margin-bottom: 30px;
    font-size: 14px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--dark);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background: var(--accent);
    color: var(--white);
    width: 100%;
}

.btn-primary:hover {
    background: var(--secondary);
}

.btn-secondary {
    background: var(--neutral);
    color: var(--white);
}

.btn-secondary:hover {
    background: #5a6268;
}

.error-message {
    background: #ffebee;
    color: var(--danger);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: none;
}

/* Header */
.header {
    background: var(--white);
    padding: 20px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    color: var(--primary);
    font-size: 24px;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.header .date-display {
    background: var(--light);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 500;
}

/* Hero Card - Net Profit */
.hero-card {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 40px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    margin-bottom: 30px;
}

.hero-card .label {
    font-size: 18px;
    color: var(--neutral);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.hero-card .value {
    font-size: 56px;
    font-weight: 700;
    margin-bottom: 10px;
    transition: color 0.3s;
}

.hero-card .value.positive {
    color: var(--success);
}

.hero-card .value.negative {
    color: var(--danger);
}

.hero-card .value.neutral {
    color: var(--neutral);
}

.hero-card .sub-value {
    font-size: 22px;
    color: #2196F3;
    /* Azul Material Design */
    font-weight: 600;
    margin-top: -5px;
    margin-bottom: 20px;
}

.hero-card .summary {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.hero-card .summary-item {
    text-align: center;
}

.hero-card .summary-item .label {
    font-size: 12px;
    margin-bottom: 5px;
}

.hero-card .summary-item .value {
    font-size: 42px;
    font-weight: 700;
}

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

/* Card */
.card {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.card-header h3 {
    color: var(--primary);
    font-size: 16px;
    font-weight: 600;
}

.card-header .total {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
}

.card-header .total.revenue {
    color: var(--success);
}

.card-header .total.cost {
    color: var(--danger);
}

/* Card Items */
.card-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

.card-item.sub-item {
    padding-left: 20px;
    font-size: 0.9em;
    color: #666;
    border-bottom: 1px dashed #eee;
}

.card-item.sub-item .value {
    font-weight: normal;
}

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

.card-item .label {
    color: var(--neutral);
    font-size: 14px;
}

.card-item .value {
    font-weight: 600;
    color: var(--dark);
}

.card-item .value.small {
    font-size: 12px;
    color: var(--neutral);
}

.revenue-text {
    color: var(--success);
}

.cost-text {
    color: var(--danger);
}

/* Manual Inputs Section */
.manual-inputs {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.manual-inputs h3 {
    color: var(--primary);
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.inputs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-size: 14px;
    color: var(--neutral);
    margin-bottom: 8px;
}

.input-group input {
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    text-align: right;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.input-prefix {
    position: relative;
}

.input-prefix::before {
    content: 'R$';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--neutral);
}

.input-prefix input {
    padding-left: 40px;
}

.btn-save {
    background: var(--success);
    color: var(--white);
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-save:hover {
    background: #00a844;
}

.btn-save:disabled {
    background: var(--neutral);
    cursor: not-allowed;
}

/* Settings Page */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.settings-section {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.settings-section h3 {
    color: var(--primary);
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item label {
    display: block;
    font-size: 14px;
    color: var(--neutral);
    margin-bottom: 8px;
}

.setting-item input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
}

.setting-item input:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-item .hint {
    font-size: 12px;
    color: var(--neutral);
    margin-top: 5px;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 16px 24px;
    border-radius: 8px;
    color: var(--white);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

/* Loading Spinner */
.loading {
    display: none;
    text-align: center;
    padding: 40px;
}

.loading.show {
    display: block;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Responsive - Tablets */
@media (max-width: 992px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .inputs-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    /* Header Mobile */
    .header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
        padding: 15px;
    }

    .header h1 {
        font-size: 20px;
    }

    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }

    .header .date-display {
        font-size: 12px;
        padding: 6px 12px;
        order: -1;
        width: 100%;
    }

    .btn-sync,
    .nav-link,
    .btn-logout {
        font-size: 12px;
        padding: 6px 12px;
    }

    /* Hero Card Mobile */
    .hero-card {
        padding: 20px 15px;
        margin-bottom: 20px;
    }

    .hero-card .label {
        font-size: 14px;
    }

    .hero-card .value {
        font-size: 36px;
    }

    .hero-card .summary {
        flex-direction: column;
        gap: 15px;
        margin-top: 15px;
        padding-top: 15px;
    }

    .hero-card .summary-item .value {
        font-size: 28px;
    }

    /* Cards Grid Mobile */
    .cards-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .card {
        padding: 15px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 15px;
        padding-bottom: 10px;
    }

    .card-header h3 {
        font-size: 14px;
    }

    .card-header .total {
        font-size: 18px;
    }

    .card-item {
        padding: 8px 0;
    }

    .card-item .label {
        font-size: 13px;
    }

    .card-item .value {
        font-size: 14px;
    }

    /* Formulário de Reajustes Mobile */
    .specific-expenses {
        padding: 15px;
        margin-top: 15px;
    }

    .specific-expenses h3 {
        font-size: 16px;
        margin-bottom: 15px;
        padding-bottom: 10px;
    }

    .inputs-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .input-group label {
        font-size: 12px;
    }

    .input-group input,
    .select-input {
        padding: 10px;
        font-size: 14px;
    }

    .btn-save {
        width: 100%;
        padding: 12px;
        font-size: 14px;
    }

    /* Lista de Reajustes Mobile */
    .expenses-list {
        margin-top: 15px;
    }

    .expense-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px;
    }

    .expense-info {
        width: 100%;
    }

    .expense-info .expense-name {
        font-size: 14px;
    }

    .expense-value {
        margin: 0;
        font-size: 16px;
    }

    .expense-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .btn-edit,
    .btn-delete {
        padding: 8px 16px;
        font-size: 12px;
    }

    /* Histórico Mobile */
    .history-section {
        padding: 15px;
        margin-top: 15px;
    }

    .history-section h3 {
        font-size: 16px;
        margin-bottom: 15px;
        padding-bottom: 10px;
    }

    .history-table {
        font-size: 12px;
    }

    .history-table th,
    .history-table td {
        padding: 10px 8px;
    }

    .history-table th {
        font-size: 10px;
    }

    /* Modal Mobile */
    .modal {
        margin: 15px;
        padding: 20px;
        max-width: calc(100% - 30px);
    }

    .modal h3 {
        font-size: 18px;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions .btn-cancel,
    .modal-actions .btn-save {
        width: 100%;
    }

    /* Toast Mobile */
    .toast {
        left: 15px;
        right: 15px;
        bottom: 15px;
        text-align: center;
    }
}

/* Responsive - Small Mobile */
@media (max-width: 480px) {
    .hero-card .value {
        font-size: 28px;
    }

    .hero-card .summary-item .value {
        font-size: 24px;
    }

    .header h1 {
        font-size: 18px;
    }

    .card-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .card-header h3 {
        font-size: 13px;
    }

    .card-header .total {
        font-size: 16px;
    }

    /* Tabela de histórico em coluna para telas muito pequenas */
    .history-table-wrapper {
        margin: 0 -15px;
    }

    .history-table th:nth-child(3),
    .history-table td:nth-child(3) {
        display: none;
    }

    /* Expense compact items */
    .expense-item-compact {
        font-size: 12px;
    }

    /* Botões de ação empilhados */
    .expense-actions {
        flex-direction: column;
        gap: 5px;
    }

    .btn-edit,
    .btn-delete {
        width: 100%;
        text-align: center;
    }

    /* Login Mobile */
    .login-box {
        padding: 25px 20px;
    }

    .login-box h1 {
        font-size: 20px;
        margin-bottom: 20px;
    }

    .login-box .subtitle {
        font-size: 12px;
        margin-bottom: 20px;
    }

    .form-group input {
        font-size: 16px;
        padding: 14px;
    }
}

/* Nav link */
.nav-link {
    color: var(--accent);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 8px;
    transition: background 0.3s;
}

.nav-link:hover {
    background: var(--light);
}

/* Sync button */
.btn-sync {
    background: var(--warning);
    color: var(--dark);
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-sync:hover {
    background: #e6a82e;
}

.btn-sync:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Logout button */
.btn-logout {
    background: transparent;
    color: var(--danger);
    border: 2px solid var(--danger);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-logout:hover {
    background: var(--danger);
    color: var(--white);
}

/* Card Divider */
.card-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 15px 0;
}

/* Specific Expenses Section */
.specific-expenses {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-top: 20px;
}

.specific-expenses h3 {
    color: var(--primary);
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.specific-expenses .input-group input[type="text"] {
    text-align: left;
}

/* Expenses List */
.expenses-list {
    margin-top: 20px;
}

.expense-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--light);
    border-radius: 8px;
    margin-bottom: 10px;
}

.expense-item:last-child {
    margin-bottom: 0;
}

.expense-info {
    flex: 1;
}

.expense-info .expense-name {
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 4px;
}

.expense-info .expense-description {
    font-size: 12px;
    color: var(--neutral);
}

.expense-value {
    font-weight: 700;
    color: var(--danger);
    margin: 0 15px;
    white-space: nowrap;
}

.expense-actions {
    display: flex;
    gap: 8px;
}

.btn-edit,
.btn-delete {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.btn-edit {
    background: var(--accent);
    color: var(--white);
}

.btn-edit:hover {
    background: var(--secondary);
}

.btn-delete {
    background: var(--danger);
    color: var(--white);
}

.btn-delete:hover {
    background: #cc3636;
}

/* Expense item in card (compact) */
#specificExpensesList .expense-item-compact {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid #f0f0f0;
}

#specificExpensesList .expense-item-compact:last-child {
    border-bottom: none;
}

#specificExpensesList .expense-item-compact .label {
    color: var(--neutral);
}

#specificExpensesList .expense-item-compact .value {
    font-weight: 500;
    color: var(--dark);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--neutral);
    font-size: 14px;
}

/* Modal para edição */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal h3 {
    color: var(--primary);
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.btn-cancel {
    background: var(--neutral);
    color: var(--white);
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    flex: 1;
}

.btn-cancel:hover {
    background: #5a6268;
}

/* History Section */
.history-section {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-top: 20px;
}

.history-section h3 {
    color: var(--primary);
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.history-table-wrapper {
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.history-table th,
.history-table td {
    padding: 12px 15px;
    text-align: right;
    border-bottom: 1px solid #f0f0f0;
}

.history-table th {
    background: var(--light);
    color: var(--neutral);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
}

.history-table th:first-child,
.history-table td:first-child {
    text-align: left;
}

.history-table tbody tr {
    transition: background 0.2s;
    cursor: pointer;
}

.history-table tbody tr:hover {
    background: var(--light);
}

.history-table .date-cell {
    font-weight: 500;
    color: var(--dark);
}

.history-table .revenue-cell {
    color: var(--success);
    font-weight: 500;
}

.history-table .cost-cell {
    color: var(--danger);
    font-weight: 500;
}

.history-table .profit-cell {
    font-weight: 700;
}

.history-table .profit-cell.positive {
    color: var(--success);
}

.history-table .profit-cell.negative {
    color: var(--danger);
}

.history-table .profit-cell.neutral {
    color: var(--neutral);
}

.history-table .empty-state {
    text-align: center;
    color: var(--neutral);
    padding: 30px;
}

/* Text colors for revenue/cost */
.revenue-text {
    color: var(--success) !important;
}

.cost-text {
    color: var(--danger) !important;
}

/* Badge de tipo (Receita/Gasto) */
.expense-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.badge-income {
    background: rgba(0, 200, 81, 0.15);
    color: var(--success);
}

.badge-expense {
    background: rgba(255, 68, 68, 0.15);
    color: var(--danger);
}

.badge-piggy {
    background: rgba(156, 39, 176, 0.15);
    color: #9c27b0;
}

.piggy-text {
    color: #9c27b0 !important;
}

/* Expense item com cores baseadas no tipo */
.expense-item.income-item {
    border-left: 3px solid var(--success);
}

.expense-item.piggy-item {
    border-left: 3px solid #9c27b0;
}

.expense-item.expense-item-type {
    border-left: 3px solid var(--danger);
}

/* Compact list items */
.expense-item-compact.income-item .label {
    color: var(--success);
}

.expense-item-compact.expense-item .label {
    color: var(--danger);
}

/* Select input styling */
.select-input {
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    background: var(--white);
    cursor: pointer;
    width: 100%;
}

.select-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Expense value com receita (sobrescreve cor padrão) */
.expense-value.revenue-text {
    color: var(--success);
}

/* Animações para atualizações inteligentes */
.expense-item {
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.expense-item:first-child {
    animation: slideIn 0.3s ease;
}

/* Efeito de highlight ao atualizar */
.expense-item.updated {
    background-color: rgba(0, 200, 81, 0.1);
}