:root,
[data-theme="light"] {
    --bg: #f0f7f5;
    --surface: #ffffff;
    --surface-2: #f6faf9;
    --surface-offset: #e8f3f1;
    --border: rgba(0, 0, 0, 0.07);
    --divider: rgba(0, 0, 0, 0.05);
    --text: #1a1a1a;
    --text-muted: #5a6b67;
    --text-faint: #9db0ac;
    --primary: #00878f;
    --primary-hover: #006b72;
    --primary-light: #d6eeec;
    --primary-subtle: #edf7f6;
    --gray: 6b7280;
    --success: #15803d;
    --success-bg: #dcfce7;
    --success-border: #bbf7d0;
    --error: #b91c1c;
    --error-bg: #fee2e2;
    --error-border: #fecaca;
    --shadow-sm: 0 1px 3px rgba(0, 90, 80, 0.07);
    --shadow-md: 0 4px 14px rgba(0, 90, 80, 0.09);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --font-body: "Nunito", sans-serif;
    --font-display: "Rubik", sans-serif;
}
[data-theme="dark"] {
    --bg: #0f1a18;
    --surface: #182421;
    --surface-2: #1e2d2a;
    --surface-offset: #243530;
    --border: rgba(255, 255, 255, 0.07);
    --divider: rgba(255, 255, 255, 0.05);
    --text: #e2edeb;
    --text-muted: #7ea49f;
    --text-faint: #4a6662;
    --primary: #2fb5be;
    --primary-hover: #4ecdd5;
    --primary-light: #1a3a3c;
    --primary-subtle: #152928;
    --gray: 6b7280;
    --success: #4ade80;
    --success-bg: #14532d;
    --success-border: #166534;
    --error: #f87171;
    --error-bg: #450a0a;
    --error-border: #7f1d1d;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
}
body {
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    min-height: 100dvh;
    line-height: 1.5;
    transition:
        background 0.2s,
        color 0.2s;
}
button {
    cursor: pointer;
    font: inherit;
    border: none;
    background: none;
}
select {
    font: inherit;
    cursor: pointer;
}

/* HEADER */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 0 24px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-logo {
    max-width: 24px;
}
.header-title {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 500;
    color: var(--primary);
    letter-spacing: -0.01em;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.btn-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition:
        background 0.15s,
        color 0.15s;
}
.btn-icon:hover {
    background: var(--surface-offset);
    color: var(--text);
}
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 12px;
    font-weight: 600;
    color: white;
    cursor: pointer;
}

/* MAIN */
.main {
    padding: 20px 24px 40px;
    max-width: 1280px;
    margin: 0 auto;
}

/* FILTER BAR */
.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.filter-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
}
.filter-select {
    height: 36px;
    padding: 0 28px 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
    min-width: 140px;
    transition: border-color 0.15s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239db0ac' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}
.filter-select:focus {
    outline: none;
    border-color: var(--primary);
}
.filter-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* BUTTONS */
.btn {
    height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition:
        background 0.15s,
        color 0.15s,
        border-color 0.15s;
    white-space: nowrap;
}
.btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}
.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.btn-primary {
    background: var(--primary);
    color: white;
    border: 1px solid transparent;
}
.btn-primary:hover {
    background: var(--primary-hover);
}

/* KPI GRID */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}
.kpi-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    margin-bottom: 6px;
}
.kpi-value {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1;
}
.kpi-value.is-teal {
    color: var(--primary);
}
.kpi-value.is-red {
    color: var(--error);
}
.kpi-value.is-gray {
    color: var(--gray);
}
.kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
    font-weight: 400;
}
.kpi-sub strong {
    font-weight: 600;
}

/* CONTENT GRID */
.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 14px;
    align-items: start;
}

/* SECTION CARD */
.section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Altura máxima = altura da coluna de gráficos, com scroll interno */
    max-height: var(--charts-col-height, 680px);
}
.section-header {
    padding: 14px 18px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--divider);
    flex-shrink: 0;
}
.section-title {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

/* SEARCH */
.search-wrap {
    position: relative;
}
.search-wrap svg {
    position: absolute;
    left: 9px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-faint);
    pointer-events: none;
}
.search-input {
    height: 32px;
    padding: 0 10px 0 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    width: 190px;
    transition:
        border-color 0.15s,
        width 0.2s;
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    width: 220px;
}
.search-input::placeholder {
    color: var(--text-faint);
}

/* TABLE */
.table-wrap {
    overflow-x: auto;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}
table {
    width: 100%;
    border-collapse: collapse;
}
thead tr {
    border-bottom: 1px solid var(--divider);
}
th {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    padding: 10px 12px;
    text-align: center;
    white-space: nowrap;
}
th:first-child {
    text-align: left;
    padding-left: 18px;
}
tbody tr {
    border-bottom: 1px solid var(--divider);
    transition: background 0.12s;
}
tbody tr:last-child {
    border-bottom: none;
}
tbody tr:hover {
    background: var(--primary-subtle);
}
/* Fixed-height rows so table matches charts height */
tbody tr {
    height: 64px;
}
td {
    padding: 10px 12px;
    text-align: center;
    vertical-align: middle;
}
td:first-child {
    text-align: left;
    padding-left: 18px;
}

.member-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
}
.member-grau {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 1px;
}

/* CONTRIBUTION CELL */
.contrib-cel {
    display: flex;
    align-items: center;
    gap: 8px;
}
.contrib-cel--multi {
    align-items: center;
}
.contrib-multi-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.contrib-multi-row {
    display: flex;
    align-items: center;
    line-height: 1.4;
}
.contrib-multi-val {
    font-size: 12px;
    color: var(--text-main);
}
.contrib-icon.paid {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success);
}
.contrib-icon.unpaid {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error);
}
.contrib-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.contrib-icon svg {
    width: 11px;
    height: 11px;
}

/* BADGE */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.badge-ok {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success);
}
.badge-ok::before {
    background: var(--success);
}
.badge-pending {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error);
}
.badge-pending::before {
    background: var(--error);
}

/* CHARTS COL */
.charts-col {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}
.chart-card-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    margin-bottom: 8px;
}
.chart-wrap {
    position: relative;
    height: 130px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chart-legend {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 8px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
}
.legend-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* EMPTY ROW */
.empty-row td {
    color: var(--text-faint);
    text-align: center;
    border-bottom: 1px solid var(--divider) !important;
}

/* RESPONSIVE */
@media (max-width: 1024px) {
    .content-grid {
        grid-template-columns: 1fr;
    }
    .charts-col {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 768px) {
    .main {
        padding: 12px 12px 32px;
    }
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-actions {
        margin-left: 0;
    }
    .charts-col {
        grid-template-columns: 1fr;
    }
    .header {
        padding: 0 14px;
    }
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg: #0f1a18;
        --surface: #182421;
        --surface-2: #1e2d2a;
        --surface-offset: #243530;
        --border: rgba(255, 255, 255, 0.07);
        --divider: rgba(255, 255, 255, 0.05);
        --text: #e2edeb;
        --text-muted: #7ea49f;
        --text-faint: #4a6662;
        --primary: #2fb5be;
        --primary-hover: #4ecdd5;
        --primary-light: #1a3a3c;
        --primary-subtle: #152928;
        --success: #4ade80;
        --success-bg: #14532d;
        --success-border: #166534;
        --error: #f87171;
        --error-bg: #450a0a;
        --error-border: #7f1d1d;
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    }
}
/* KPI DUO */
.kpi-duo {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: nowrap;
    white-space: nowrap;
}
.kpi-duo .kpi-value {
    font-size: 22px;
    line-height: 1;
}
.kpi-sep {
    color: var(--border);
    font-weight: 300;
    font-size: 22px;
    line-height: 1;
    font-family: var(--font-display);
    user-select: none;
}
.kpi-hint {
    font-size: 10px;
    color: var(--text-faint);
    margin-top: 4px;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

/* ERROR BANNER */
.error-banner {
    display: none;
    align-items: center;
    gap: 10px;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error);
    border-radius: var(--radius-md);
    padding: 10px 16px;
    margin-bottom: 14px;
    font-size: 13px;
    font-weight: 500;
}
.error-banner.visible {
    display: flex;
}
.error-banner svg {
    flex-shrink: 0;
}
.error-banner-msg {
    flex: 1;
}
.error-banner-close {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s;
    background: none;
    border: none;
    color: inherit;
    padding: 0;
    line-height: 1;
}
.error-banner-close:hover {
    opacity: 1;
}
/* LOADING STATE */
.btn-primary.loading {
    opacity: 0.7;
    pointer-events: none;
}
.spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* LAST UPDATE BADGE */
.last-update {
    font-size: 11px;
    color: var(--text-faint);
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}
.last-update svg {
    flex-shrink: 0;
}
.last-update strong {
    color: var(--text-muted);
    font-weight: 600;
}

/* INAPTO */
.contrib-icon.inapto {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    color: var(--gray);
}
[data-theme="dark"] .contrib-icon.inapto {
    background: #1f2937;
    border-color: #374151;
    color: #9ca3af;
}
.contrib-value.inapto-label {
    color: #9ca3af;
    font-size: 10px;
}
.badge-inapto {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    color: #6b7280;
}
[data-theme="dark"] .badge-inapto {
    background: #1f2937;
    border-color: #374151;
    color: #9ca3af;
}
.badge-inapto::before {
    background: #9ca3af !important;
}
