* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1a365d;
    --secondary-color: #2c5282;
    --success-color: #22543d;
    --danger-color: #742a2a;
    --warning-color: #744210;
    --info-color: #2c5282;
    --dark-bg: #1a202c;
    --light-bg: #f7fafc;
    --card-bg: #ffffff;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f4f8;
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 24px 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--primary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-content h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 4px;
    letter-spacing: -0.025em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 400;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.btn-projection {
    background: white;
    color: #9333ea;
    border: 2px solid #9333ea;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-projection:hover {
    background: linear-gradient(135deg, #9333ea 0%, #7c3aed 100%);
    color: white;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.btn-projection.btn-receitas {
    background: transparent;
    color: #10b981;
    border: 2px solid #10b981;
}

.btn-projection.btn-receitas:hover {
    background: #10b981;
    color: white;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.btn-upload {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.btn-upload:hover {
    background: var(--secondary-color);
    box-shadow: var(--shadow-md);
}

.btn-refresh {
    background: white;
    color: var(--primary-color);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    border-color: var(--primary-color);
    background: var(--light-bg);
}

.btn-logout {
    background: #dc2626;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.btn-logout:hover {
    background: #b91c1c;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.btn-logout:active {
    transform: translateY(0);
}

/* Filtros */
.filters-section {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--info-color);
}

.filters-header {
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.filters-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.filter-info {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.info-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: #e6f3ff;
    border: 1px solid #b3d9ff;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--primary-color);
    cursor: help;
    transition: all 0.2s ease;
}

.info-badge:hover {
    background: #cce7ff;
    border-color: #99ccff;
    transform: translateY(-1px);
}

.filters-container {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
}

.filter-group label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.filter-group input,
.filter-group select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9375rem;
    font-family: inherit;
    transition: all 0.2s ease;
    background: white;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.1);
}

.btn-clear {
    background: white;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: auto;
}

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

/* KPI Cards */
.kpi-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    transition: all 0.2s ease;
    position: relative;
    border-left: 4px solid;
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
}

.kpi-card.revenue {
    border-color: var(--success-color);
}

.kpi-card.expenses {
    border-color: var(--danger-color);
}

.kpi-card.profit {
    border-color: var(--info-color);
}

.kpi-card.margin {
    border-color: #166534;
}

.kpi-content {
    flex: 1;
}

.kpi-content h3 {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.kpi-card.revenue .kpi-value {
    color: var(--success-color);
}

.kpi-card.expenses .kpi-value {
    color: var(--danger-color);
}

.kpi-card.profit .kpi-value {
    color: var(--info-color);
}

.kpi-card.margin .kpi-value {
    color: var(--warning-color);
}

.kpi-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* KPI Cards Secundários (largura completa) */
.kpi-section-secondary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card-wide {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    transition: all 0.2s ease;
    position: relative;
    border-left: 4px solid;
}

.kpi-card-wide:hover {
    box-shadow: var(--shadow-md);
}

.kpi-card-wide.investments {
    border-color: #9333ea; /* Roxo para investimentos */
}

.kpi-card-wide.investments .kpi-value {
    color: #9333ea;
}

.kpi-card-wide.anticipation {
    border-color: #9ca3af; /* Cinza claro para antecipação */
}

.kpi-card-wide.anticipation .kpi-value {
    color: #9ca3af;
}

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.chart-container {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.chart-container:hover {
    box-shadow: var(--shadow-md);
}

.chart-container.large {
    grid-column: 1 / -1;
}

.chart-header {
    margin-bottom: 20px;
}

.chart-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.025em;
}

.chart-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

canvas {
    max-height: 400px;
}

/* Table Section */
.table-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-lg);
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.table-header h3 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

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

/* Botões de exportação */
.export-btn {
    padding: 10px 18px;
    background: white;
    color: #10b981;
    border: 2px solid #10b981;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.export-btn:hover {
    background: #10b981;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.export-btn.pdf-btn {
    background: white;
    color: #ef4444;
    border: 2px solid #ef4444;
}

.export-btn.pdf-btn:hover {
    background: #ef4444;
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Botões de filtro */
.filter-btn {
    padding: 10px 18px;
    border: 2px solid;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    font-family: inherit;
}

.filter-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.filter-btn.active {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.investments-btn {
    border-color: #9333ea;
    color: #9333ea;
}

.investments-btn:hover,
.investments-btn.active {
    background: #9333ea;
    color: white;
}

.anticipation-btn {
    border-color: #9ca3af;
    color: #9ca3af;
}

.anticipation-btn:hover,
.anticipation-btn.active {
    background: #9ca3af;
    color: white;
}

.cost-type-btn {
    border-color: #3b82f6;
    color: #3b82f6;
}

.cost-type-btn:hover,
.cost-type-btn.active {
    background: #3b82f6;
    color: white;
}

/* Dropdown de Tipo de Custos */
.dropdown-container {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 5px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 280px;
    max-height: 400px;
    overflow-y: auto;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.dropdown-item:hover {
    background: #f3f4f6;
}

.dropdown-item.active {
    background: #eff6ff;
    color: #3b82f6;
    font-weight: 600;
}

.dropdown-item-text {
    flex: 1;
    font-size: 0.9rem;
}

.dropdown-item-value {
    font-size: 0.85rem;
    color: #6b7280;
    font-weight: 600;
    margin-left: 10px;
}

.dropdown-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 5px 0;
}

.all-btn {
    border-color: #6b7280;
    color: #6b7280;
}

.all-btn:hover,
.all-btn.active {
    background: #6b7280;
    color: white;
}

.table-actions input {
    padding: 10px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    width: 270px;
    font-family: inherit;
    transition: all 0.3s ease;
}

.table-actions input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--light-bg);
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background 0.2s ease;
    -webkit-user-select: none; /* Safari */
    user-select: none; /* Evita seleção de texto ao clicar */
}

th:hover {
    background: var(--border-color);
}

/* Ícone de ordenação nos cabeçalhos da tabela */
th.sortable {
    position: relative;
}

th.sortable .sort-icon {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    opacity: 0.5;
    transition: all 0.2s ease;
}

th.sortable:hover .sort-icon {
    opacity: 1;
    color: var(--primary-color);
}

th.sortable.sorted-asc .sort-icon::before {
    content: '▲';
    color: var(--primary-color);
    opacity: 1;
}

th.sortable.sorted-desc .sort-icon::before {
    content: '▼';
    color: var(--primary-color);
    opacity: 1;
}

th.sortable.sorted-asc .sort-icon,
th.sortable.sorted-desc .sort-icon {
    opacity: 0;
}

th.sortable.sorted-asc .sort-icon::before,
th.sortable.sorted-desc .sort-icon::before {
    position: absolute;
    margin-left: -16px;
}

td {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    font-size: 0.95rem;
}

tbody tr {
    transition: background 0.2s ease;
}

tbody tr:hover {
    background: var(--light-bg);
}

.type-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.type-badge.receita {
    background: #d1fae5;
    color: #065f46;
}

.type-badge.custo {
    background: #fee2e2;
    color: #991b1b;
}

.value-positive {
    color: var(--success-color);
    font-weight: 600;
}

.value-negative {
    color: var(--danger-color);
    font-weight: 600;
}

/* Insights Section */
.insights-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-lg);
}

.insights-header h3 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.insights-container {
    display: grid;
    gap: 15px;
}

.insight-card {
    padding: 20px;
    border-radius: 12px;
    border-left: 4px solid;
    transition: all 0.3s ease;
}

.insight-card:hover {
    transform: translateX(5px);
    box-shadow: var(--shadow-md);
}

.insight-card.success {
    background: #ecfdf5;
    border-color: var(--success-color);
}

.insight-card.warning {
    background: #fffbeb;
    border-color: var(--warning-color);
}

.insight-card.info {
    background: #eff6ff;
    border-color: var(--info-color);
}

.insight-card.danger {
    background: #fef2f2;
    border-color: var(--danger-color);
}

.insight-card h4 {
    font-size: 1.1rem;
    margin-bottom: 8px;
    font-weight: 600;
}

.insight-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Footer */
.footer {
    text-align: center;
    padding: 20px;
    color: white;
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content h1 {
        font-size: 1.8rem;
    }

    .charts-section {
        grid-template-columns: 1fr;
    }

    .filters-container {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    .table-actions input {
        width: 100%;
    }

    .kpi-section {
        grid-template-columns: 1fr;
    }

    .kpi-section-secondary {
        grid-template-columns: 1fr;
    }
}

/* Loading Animation */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Scroll suave */
html {
    scroll-behavior: smooth;
}

/* Input de arquivo escondido */
#fileInput {
    display: none;
}

/* Barra de rolagem personalizada */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--light-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}
