:root {
    --bg-color: #f4f6fb;
    --card-bg: #ffffff;
    --text-main: #2d3436;
    --text-muted: #636e72;
    --primary-color: #6c5ce7;
    --primary-light: rgba(108, 92, 231, 0.12);
    --danger-color: #ff7675;
    --success-color: #00b894;
    --warning-color: #fdcb6e;
    --border-radius: 24px;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
    --bg-color: #121318;
    --card-bg: #1e2029;
    --text-main: #f5f6fa;
    --text-muted: #a4b0be;
    --primary-light: rgba(108, 92, 231, 0.25);
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}

/* BLOQUEIO RIGOROSO DE ESTOURO LATERAL */
html, body {
    overflow-x: hidden !important;
    width: 100%;
    max-width: 100vw;
    position: relative;
    margin: 0;
    padding: 0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    transition: background-color 0.3s, color 0.3s;
    padding-bottom: 110px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px 10px 20px;
    max-width: 600px;
    margin: 0 auto;
}

.logo-container { display: flex; align-items: center; gap: 10px; }
.logo-icon {
    width: 42px; height: 42px;
    background: var(--primary-color);
    color: white; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 5px 15px rgba(108, 92, 231, 0.3);
}
.logo-text { font-size: 1.35rem; font-weight: 700; }
.header-actions { display: flex; gap: 10px; }

.btn-icon {
    background: var(--card-bg);
    border: none; color: var(--text-muted);
    width: 40px; height: 40px; border-radius: 50%;
    cursor: pointer; box-shadow: var(--shadow);
    display: flex; align-items: center; justify-content: center;
}

/* SELETOR DE MESES */
.seletor-meses-wrapper {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px; max-width: 600px; margin: 0 auto 10px auto;
}

.btn-nav-mes {
    background: var(--card-bg); border: none; color: var(--text-main);
    width: 36px; height: 36px; border-radius: 50%;
    box-shadow: var(--shadow); cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}

.meses-scroll-viewport { flex-grow: 1; overflow: hidden; padding: 4px 8px; }
.meses-scroll-track { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.meses-scroll-track::-webkit-scrollbar { display: none; }

.mes-pill {
    background: var(--card-bg); color: var(--text-muted);
    padding: 8px 18px; border-radius: 20px; font-size: 0.85rem; font-weight: 600;
    white-space: nowrap; cursor: pointer; box-shadow: var(--shadow);
    transition: all 0.25s ease;
}

.mes-pill.ativo {
    background: var(--primary-color); color: white;
    transform: scale(1.05); box-shadow: 0 6px 16px rgba(108, 92, 231, 0.4);
}

.main-container {
    padding: 0 16px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* CARDS DE RESUMO */
.cards-resumo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
    width: 100%;
}

.card-resumo {
    background: var(--card-bg);
    padding: 12px 6px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    text-align: center;
    overflow: hidden;
    min-width: 0;
}

.card-resumo span {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    display: block;
    margin-bottom: 2px;
}

.card-resumo h3 {
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-resumo.total h3 { color: var(--primary-color); }
.card-resumo.pago h3 { color: var(--success-color); }
.card-resumo.pendente h3 { color: var(--danger-color); }

/* GRÁFICOS COMPACTOS */
.dashboard-card.compact-charts {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 12px 10px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.charts-wrapper {
    display: flex;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.chart-box {
    flex: 1;
    min-width: 0;
    text-align: center;
    overflow: hidden;
}

.chart-box small {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

.canvas-container {
    height: 105px;
    width: 100%;
    position: relative;
    min-width: 0;
}

.canvas-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* LISTA DE DESPESAS E TÓPICOS RECOLHÍVEIS */
.lista-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.lista-header h3 { color: var(--text-muted); font-size: 1rem; }
.badge-total-itens {
    background: var(--primary-light); color: var(--primary-color);
    font-size: 0.78rem; font-weight: 600; padding: 4px 10px; border-radius: 10px;
}

/* DIVISOR DE TÓPICO RECOLHÍVEL */
.grupo-header-wrapper {
    cursor: pointer;
    user-select: none;
    margin: 14px 0 6px 4px;
}

.grupo-titulo-divisor {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.icone-seta-topico {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.grupo-header-wrapper.fechado .icone-seta-topico {
    transform: rotate(-90deg);
}

.grupo-itens-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.3s ease;
}

.grupo-itens-container.fechado {
    display: none;
}

.despesas-list { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.despesa-item {
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    background: var(--card-bg);
    box-shadow: var(--shadow);
    width: 100%;
    box-sizing: border-box;
}

.despesa-acoes-lateral {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 8px;
    background: var(--card-bg);
    border-radius: 0 20px 20px 0;
    z-index: 1;
}

.btn-edit-side, .btn-delete-side {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.95rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    transition: transform 0.15s ease;
}

.btn-edit-side { background: var(--primary-color); }
.btn-delete-side { background: var(--danger-color); }
.btn-edit-side:active, .btn-delete-side:active { transform: scale(0.9); }

.despesa-frente {
    position: relative;
    background: var(--card-bg);
    padding: 14px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    width: 100%;
    cursor: pointer;
    user-select: none;
    z-index: 2;
    transition: transform 0.28s cubic-bezier(0.25, 1, 0.5, 1);
    box-sizing: border-box;
}

.despesa-icone {
    width: 42px; height: 42px; background: var(--primary-light);
    color: var(--primary-color); border-radius: 14px;
    display: flex; justify-content: center; align-items: center;
    font-size: 1.2rem; margin-right: 12px; flex-shrink: 0;
}

.despesa-detalhes {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

.despesa-detalhes h4 {
    font-size: 0.92rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.despesa-detalhes .despesa-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.despesa-valor {
    font-weight: 700;
    font-size: 0.98rem;
    text-align: right;
    margin-left: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

.despesa-pago-check {
    margin-left: 10px;
    font-size: 1.2rem;
    color: #b2bec3;
    flex-shrink: 0;
}

.despesa-pago-check.ativo { color: var(--success-color); }

/* CATEGORIAS MODAL */
.categoria-input-wrapper { display: flex; gap: 10px; margin-top: 6px; }
.categoria-input-wrapper input { flex: 1; }

.btn-salvar-cat {
    background: var(--primary-color); color: white;
    border: none; padding: 12px 18px; border-radius: 16px;
    font-weight: 600; cursor: pointer; font-size: 0.88rem; white-space: nowrap;
}

.lista-cat-container { margin-top: 18px; }

#lista-categorias-ul {
    list-style: none; display: flex; flex-direction: column; gap: 10px;
    margin-top: 8px; max-height: 240px; overflow-y: auto; padding-right: 4px;
}

#lista-categorias-ul li {
    background: var(--card-bg); padding: 12px 16px; border-radius: 16px;
    display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow);
}

#lista-categorias-ul li span { font-weight: 600; font-size: 0.9rem; }
.cat-acoes { display: flex; gap: 8px; }

.btn-cat-edit, .btn-cat-del {
    width: 34px; height: 34px; border-radius: 10px; border: none;
    cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 0.88rem;
}
.btn-cat-edit { background: var(--primary-light); color: var(--primary-color); }
.btn-cat-del { background: rgba(255, 118, 117, 0.15); color: var(--danger-color); }

/* BOTOES BACKUP */
.config-item.vertical-box { flex-direction: column; align-items: flex-start; gap: 10px; }
.backup-botoes { display: flex; gap: 10px; width: 100%; margin-top: 4px; }
.btn-backup {
    flex: 1; padding: 12px; border: none; border-radius: 14px;
    font-weight: 600; font-size: 0.85rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-backup.export { background: var(--primary-light); color: var(--primary-color); }
.btn-backup.import { background: var(--card-bg); color: var(--text-main); border: 1px solid rgba(0,0,0,0.1); }

/* FAB BUTTON */
.fab-btn {
    position: fixed; bottom: 25px; right: 25px;
    width: 60px; height: 60px; border-radius: 50%;
    background: var(--primary-color); color: white; border: none;
    font-size: 1.6rem; box-shadow: 0 10px 25px rgba(108, 92, 231, 0.45);
    cursor: pointer; z-index: 100; display: flex; align-items: center; justify-content: center;
}

/* MODAIS */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(6px);
    display: none; justify-content: center; align-items: flex-end; z-index: 1000;
}
.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--bg-color); width: 100%; max-width: 500px;
    border-radius: 32px 32px 0 0; padding: 25px 20px 30px 20px;
    max-height: 90vh; overflow-y: auto;
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-header h2 { font-size: 1.15rem; font-weight: 700; color: var(--primary-color); }

.btn-fechar {
    background: var(--card-bg); border: none; width: 36px; height: 36px;
    border-radius: 50%; font-size: 1rem; color: var(--text-main); cursor: pointer;
}

.input-group { margin-bottom: 14px; }
.input-row { display: flex; gap: 10px; }
.input-row .input-group { flex: 1; }

label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 5px; font-weight: 500; }
input, select {
    width: 100%; padding: 13px 16px; border: none; border-radius: 16px;
    background: var(--card-bg); color: var(--text-main); font-size: 0.9rem;
}

.select-config { width: auto; padding: 8px 12px; border-radius: 12px; }

.btn-salvar {
    width: 100%; padding: 16px; border: none; border-radius: var(--border-radius);
    background: var(--primary-color); color: white; font-size: 1rem; font-weight: 600;
    margin-top: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
}

.categoria-wrapper { display: flex; gap: 8px; }
.btn-add-cat {
    width: 48px; border: none; border-radius: 16px;
    background: var(--card-bg); color: var(--primary-color); font-size: 1.1rem; cursor: pointer;
}

/* MODAIS DIÁLOGOS CUSTOMIZADOS */
.modal-content.modal-dialog-custom {
    border-radius: 28px;
    margin: auto 16px;
    text-align: center;
    padding: 25px 20px;
}

.modal-dialog-icon {
    width: 54px; height: 54px; border-radius: 50%; margin: 0 auto 12px auto;
    display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
.modal-dialog-icon.danger { background: rgba(255, 118, 117, 0.15); color: var(--danger-color); }
.modal-dialog-icon.primary { background: var(--primary-light); color: var(--primary-color); }

.modal-dialog-custom h3 { font-size: 1.15rem; margin-bottom: 6px; }
.modal-dialog-custom p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 18px; }

.dialog-input { margin-bottom: 18px; text-align: center; }

.dialog-botoes { display: flex; gap: 10px; justify-content: center; }
.dialog-botoes.vertical { flex-direction: column; }

.btn-dialog-main { background: var(--primary-color); color: white; border: none; padding: 14px; border-radius: 16px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-dialog-alt { background: var(--primary-light); color: var(--primary-color); border: none; padding: 14px; border-radius: 16px; font-weight: 600; cursor: pointer; }
.btn-dialog-sec { background: var(--card-bg); color: var(--text-muted); border: none; padding: 14px; border-radius: 16px; font-weight: 600; cursor: pointer; }
.btn-dialog-danger { background: var(--danger-color); color: white; border: none; padding: 14px; border-radius: 16px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; }

/* CONFIGURATIVO SWITCH */
.config-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; }
.config-text span { font-weight: 600; font-size: 0.9rem; display: block; }
.config-text small { color: var(--text-muted); font-size: 0.75rem; }
.config-divisor { border: none; border-top: 1px solid rgba(0,0,0,0.06); margin: 8px 0; }
.color-picker-input { width: 40px; height: 40px; padding: 0; border: none; border-radius: 50%; cursor: pointer; }

.switch { position: relative; display: inline-block; width: 48px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top:0; left:0; right:0; bottom:0; background-color: #ccc; transition: .4s; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 4px; bottom: 4px; background-color: white; transition: .4s; }
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(22px); }
.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }

/* TOAST NOTIFICATION */
.toast-notification {
    position: fixed; top: 18px; left: 50%; transform: translateX(-50%) translateY(-100px);
    background: var(--card-bg); color: var(--text-main); padding: 10px 20px;
    border-radius: 20px; box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    display: flex; align-items: center; gap: 8px; z-index: 2000; font-size: 0.85rem; font-weight: 600;
    opacity: 0; transition: all 0.35s ease;
}
.toast-notification.show { transform: translateX(-50%) translateY(0); opacity: 1; }