/* ============================================================
   MêsAzul - Estilos Principais
   ============================================================ */

/* ---- Variáveis tema claro ---------------------------------- */
:root {
    --bg-body:       #f1f5f9;
    --bg-card:       #ffffff;
    --bg-sidebar:    #1e293b;
    --bg-topbar:     #ffffff;
    --bg-input:      #ffffff;
    --bg-hover:      #f8fafc;
    --bg-row-alt:    #f8fafc;

    --text-primary:  #0f172a;
    --text-secondary:#64748b;
    --text-muted:    #94a3b8;
    --text-sidebar:  #cbd5e1;
    --text-sidebar-active: #ffffff;

    --border-color:  #e2e8f0;
    --border-input:  #cbd5e1;

    --color-income:  #22c55e;
    --color-expense: #ef4444;
    --color-primary: #3b82f6;
    --color-warning: #f59e0b;
    --color-info:    #06b6d4;

    --shadow-card:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-modal:  0 20px 60px rgba(0,0,0,.15);

    --sidebar-width: 240px;
    --topbar-height: 60px;
    --radius:        10px;
    --radius-sm:     6px;
}

/* ---- Variáveis tema escuro --------------------------------- */
[data-theme="dark"] {
    --bg-body:       #0f172a;
    --bg-card:       #1e293b;
    --bg-sidebar:    #0f172a;
    --bg-topbar:     #1e293b;
    --bg-input:      #0f172a;
    --bg-hover:      #1e293b;
    --bg-row-alt:    #1a2540;

    --text-primary:  #f1f5f9;
    --text-secondary:#94a3b8;
    --text-muted:    #64748b;

    --border-color:  #334155;
    --border-input:  #334155;

    --shadow-card:   0 1px 3px rgba(0,0,0,.3);
}

/* ---- Reset e base ----------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    transition: background .2s, color .2s;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* ---- Layout principal ------------------------------------- */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---------------------------------------------- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .25s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-logo .logo-icon {
    width: 36px; height: 36px;
    background: var(--color-primary);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-logo .logo-text {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.3px;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: #475569;
    padding: 12px 20px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-sidebar);
    font-size: 14px;
    font-weight: 500;
    border-radius: 0;
    transition: background .15s, color .15s;
    cursor: pointer;
    position: relative;
}

.nav-item:hover, .nav-item.active {
    background: rgba(255,255,255,.07);
    color: var(--text-sidebar-active);
    text-decoration: none;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--color-primary);
    border-radius: 0 2px 2px 0;
}

.nav-item i { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }

/* ---- Topbar ----------------------------------------------- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 12px;
}

.topbar-hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

.topbar-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Notificação */
.notif-btn {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 18px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: background .15s, color .15s;
}
.notif-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.notif-badge {
    position: absolute;
    top: 2px; right: 2px;
    width: 8px; height: 8px;
    background: var(--color-expense);
    border-radius: 50%;
    border: 2px solid var(--bg-topbar);
}

/* ---- Dropdown do sininho --------------------------------- */
.notif-menu { position: relative; display: inline-block; }

.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-modal);
    width: 290px;
    display: none;
    z-index: 200;
    overflow: hidden;
}
.notif-dropdown.open { display: block; }

.notif-dd-header {
    padding: 11px 14px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.notif-dd-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
}
.notif-dd-text  { flex: 1; min-width: 0; }
.notif-dd-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.notif-dd-desc  { font-size: 12px; color: var(--text-muted); margin-top: 2px; line-height: 1.45; }

.notif-dd-foot {
    padding: 9px 14px;
    font-size: 11.5px;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 6px;
    word-break: break-all;
}

/* Em telas estreitas o dropdown nao pode estourar a viewport */
@media (max-width: 480px) {
    .notif-dropdown { width: calc(100vw - 32px); right: -8px; }
}

/* Avatar / dropdown usuário */
.user-menu { position: relative; }

.user-avatar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    transition: background .15s;
}
.user-avatar-btn:hover { background: var(--bg-hover); }

.user-avatar-btn img,
.user-avatar-btn .avatar-placeholder {
    width: 34px; height: 34px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-placeholder {
    background: var(--color-primary);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 14px;
}

.user-info { text-align: left; }
.user-name  { font-size: 13px; font-weight: 600; color: var(--text-primary); line-height: 1.2; }
.user-role  { font-size: 11px; color: var(--text-muted); }

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-modal);
    min-width: 200px;
    padding: 6px 0;
    display: none;
    z-index: 200;
}

.user-dropdown.open { display: block; }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background .15s;
}
.dropdown-item:hover { background: var(--bg-hover); text-decoration: none; color: var(--text-primary); }
.dropdown-item i { width: 16px; text-align: center; color: var(--text-secondary); }
.dropdown-divider { height: 1px; background: var(--border-color); margin: 4px 0; }
.dropdown-item.danger { color: var(--color-expense); }
.dropdown-item.danger i { color: var(--color-expense); }

/* ---- Conteúdo principal ----------------------------------- */
.page-content {
    padding: 24px;
    flex: 1;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* ---- Cards ------------------------------------------------ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body { padding: 20px; }

/* ---- Stat cards (dashboard) ------------------------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-card);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.stat-icon.income  { background: #dcfce7; color: #16a34a; }
.stat-icon.expense { background: #fee2e2; color: #dc2626; }
.stat-icon.balance { background: #dbeafe; color: #2563eb; }
.stat-icon.budget  { background: #fef3c7; color: #d97706; }

[data-theme="dark"] .stat-icon.income  { background: rgba(34,197,94,.15);  }
[data-theme="dark"] .stat-icon.expense { background: rgba(239,68,68,.15);  }
[data-theme="dark"] .stat-icon.balance { background: rgba(59,130,246,.15); }
[data-theme="dark"] .stat-icon.budget  { background: rgba(245,158,11,.15); }

.stat-info { flex: 1; min-width: 0; }
.stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin-bottom: 4px; }
.stat-value { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.stat-sub   { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---- Orçamento: labels só aparecem em mobile -------------- */
.budget-row .budget-fields label { display: none; }

/* ---- Listas de lançamentos -------------------------------- */
.transaction-list { width: 100%; }

.list-header,
.list-row {
    display: grid;
    grid-template-columns: 90px 1fr 130px 110px 110px 100px;
    gap: 12px;
    padding: 10px 16px;
    align-items: center;
    font-size: 13px;
}

.list-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    background: var(--bg-row-alt);
    border-bottom: 1px solid var(--border-color);
}

.list-row {
    border-bottom: 1px solid var(--border-color);
    transition: background .12s;
}

.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--bg-hover); }

.list-row .desc { font-weight: 500; color: var(--text-primary); }
.list-row .date { color: var(--text-secondary); }
.list-row .amount { font-weight: 600; }

/* ---- Status badges ---------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-clickable  { cursor: pointer; user-select: none; }
.badge-clickable:hover { filter: brightness(.93); }
.badge-pending    { background: #fef3c7; color: #92400e; }
.badge-scheduled  { background: #dbeafe; color: #1d4ed8; }
.badge-auto_debit { background: #ede9fe; color: #6d28d9; }
.badge-paid       { background: #dcfce7; color: #15803d; }
.badge-received   { background: #dcfce7; color: #15803d; }
.badge-cancelled  { background: #f1f5f9; color: #64748b; }
.badge-income     { background: #dcfce7; color: #15803d; }
.badge-expense    { background: #fee2e2; color: #dc2626; }

[data-theme="dark"] .badge-pending    { background: rgba(245,158,11,.15); color: #fbbf24; }
[data-theme="dark"] .badge-scheduled  { background: rgba(59,130,246,.15); color: #60a5fa; }
[data-theme="dark"] .badge-auto_debit { background: rgba(139,92,246,.15); color: #a78bfa; }
[data-theme="dark"] .badge-paid       { background: rgba(34,197,94,.15);  color: #4ade80; }
[data-theme="dark"] .badge-received   { background: rgba(34,197,94,.15);  color: #4ade80; }
[data-theme="dark"] .badge-cancelled  { background: rgba(100,116,139,.15);color: #94a3b8; }

/* ---- Textos de valor -------------------------------------- */
.text-income  { color: var(--color-income) !important; }
.text-expense { color: var(--color-expense) !important; }

/* ---- Botões ----------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: opacity .15s, transform .1s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn:active { transform: scale(.98); }

.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-success   { background: var(--color-income);  color: #fff; }
.btn-danger    { background: var(--color-expense); color: #fff; }
.btn-warning   { background: var(--color-warning); color: #fff; }
.btn-secondary { background: var(--border-color);  color: var(--text-primary); }
.btn-outline   {
    background: transparent;
    border: 1px solid var(--border-input);
    color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-hover); }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon { padding: 7px 9px; }

/* Botões de entrada/saída */
.btn-income  { background: var(--color-income);  color: #fff; }
.btn-expense { background: var(--color-expense); color: #fff; }

/* ---- Formulários ------------------------------------------ */
.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
    -webkit-appearance: none;
}

.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

select.form-control { cursor: pointer; }

.form-control::placeholder { color: var(--text-muted); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.form-error { font-size: 12px; color: var(--color-expense); margin-top: 4px; }

/* ---- Alertas / Flash -------------------------------------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-danger  { background: #fee2e2; color: #dc2626; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }

[data-theme="dark"] .alert-success { background: rgba(34,197,94,.1);  border-color: rgba(34,197,94,.2);  }
[data-theme="dark"] .alert-danger  { background: rgba(239,68,68,.1);  border-color: rgba(239,68,68,.2);  }
[data-theme="dark"] .alert-warning { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.2); }
[data-theme="dark"] .alert-info    { background: rgba(59,130,246,.1); border-color: rgba(59,130,246,.2); }

/* ---- Modal ------------------------------------------------ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-modal);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalIn .2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-16px) scale(.97); }
    to   { opacity: 1; transform: none; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-color);
}
.modal-title { font-size: 16px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color .15s;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body   { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ---- Página de login -------------------------------------- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
    padding: 24px 16px;
}

.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-modal);
    width: 100%;
    max-width: 440px;
    padding: 40px 36px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo .logo-icon {
    width: 56px; height: 56px;
    background: var(--color-primary);
    border-radius: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 26px;
    color: #fff;
    margin-bottom: 10px;
}

.auth-logo h1 { font-size: 24px; font-weight: 700; }
.auth-logo p  { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }

.auth-divider {
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    margin: 16px 0;
    position: relative;
}
.auth-divider::before {
    content: '';
    position: absolute;
    top: 50%; left: 0;
    width: 100%; height: 1px;
    background: var(--border-color);
}
.auth-divider span {
    background: var(--bg-card);
    padding: 0 10px;
    position: relative;
}

/* ---- Categorias - grade de ícones ------------------------- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}

.category-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: border-color .15s, background .15s;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.category-item:hover  { border-color: var(--color-primary); }
.category-item.active { border-color: var(--color-primary); background: rgba(59,130,246,.08); color: var(--text-primary); }

.category-item .cat-icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    color: #fff;
}

/* ---- Barra de progresso (orçamento) ----------------------- */
.progress-bar {
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
}
.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width .3s ease;
}
.progress-fill.ok      { background: var(--color-income);  }
.progress-fill.warning { background: var(--color-warning); }
.progress-fill.danger  { background: var(--color-expense); }

/* ---- Navegação de mês ------------------------------------- */
.month-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}
.month-nav button {
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 13px;
    transition: background .15s;
}
.month-nav button:hover { background: var(--border-color); }
.month-nav .current-month {
    font-size: 15px;
    font-weight: 600;
    min-width: 160px;
    text-align: center;
}

/* ---- Toggle switch investimentos -------------------------- */
.inv-switch { position:relative; display:inline-block; width:36px; height:20px; flex-shrink:0; cursor:pointer; }
.inv-switch input { opacity:0; width:0; height:0; }
.inv-slider {
    position:absolute; inset:0;
    background:var(--border-color);
    border-radius:20px;
    transition:background .2s;
}
.inv-slider::before {
    content:'';
    position:absolute;
    width:14px; height:14px;
    left:3px; top:3px;
    background:#fff;
    border-radius:50%;
    transition:transform .2s;
}
.inv-switch input:checked + .inv-slider { background:#8b5cf6; }
.inv-switch input:checked + .inv-slider::before { transform:translateX(16px); }

/* ---- Sumário de contas ------------------------------------ */
.accounts-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.account-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color .15s;
    font-size: 13px;
}
.account-chip:hover, .account-chip.active { border-color: var(--color-primary); }
.account-chip .chip-icon {
    width: 28px; height: 28px;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
    color: #fff;
}
.account-chip .chip-info .chip-name  { font-weight: 600; }
.account-chip .chip-info .chip-balance { font-size: 12px; color: var(--text-secondary); }

/* ---- Calculadora mini ------------------------------------ */
.calc-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.calc-row .form-control { flex: 1; }
.calc-result {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 100px;
    text-align: right;
}

/* ---- Totalizador de lançamentos -------------------------- */
.list-totals {
    display: flex;
    gap: 24px;
    padding: 12px 16px;
    background: var(--bg-row-alt);
    border-top: 2px solid var(--border-color);
    font-size: 13px;
    font-weight: 600;
}
.total-item { display: flex; align-items: center; gap: 6px; }
.total-label { color: var(--text-muted); font-weight: 400; }

/* ---- Ações de linha --------------------------------------- */
.row-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}
.row-actions .btn-icon {
    width: 28px; height: 28px;
    padding: 0;
    font-size: 12px;
    border-radius: 4px;
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.row-actions .btn-icon:hover { color: var(--text-primary); }

/* ---- Empty state ----------------------------------------- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state i { font-size: 40px; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 15px; }

/* ---- Page header ----------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 {
    font-size: 20px;
    font-weight: 700;
}

/* ---- Responsividade --------------------------------------- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.2);
    }
    .main-content {
        margin-left: 0;
        overflow-x: hidden;
    }
    .topbar-hamburger { display: flex; }

    .page-content { padding: 12px; }

    .form-row,
    .form-row.cols-3 { grid-template-columns: 1fr; }

    .list-header { display: none; }

    /* ---- Lançamentos em mobile: card compacto de 2 colunas ---- */
    /* !important necessário pois o PHP gera grid-template-columns inline em cada .list-row */
    .list-row {
        grid-template-columns: 1fr auto !important;
        /* Uma linha por metadado: compartilhar uma única área "meta" fazia os
           elementos se empilharem, com o badge de status cobrindo a data */
        grid-template-areas:
            "desc     amount"
            "m-date   m-date"
            "m-acct   m-acct"
            "m-cat    m-cat"
            "m-status m-status"
            "m-bal    m-bal"
            "actions  actions";
        gap: 2px 10px;
        padding: 12px 14px;
        align-items: start;
        position: relative;
    }
    .list-row .col-desc     { grid-area: desc; font-size: 14px; font-weight: 600; line-height: 1.3; }
    .list-row .col-amount   { grid-area: amount; font-size: 15px; font-weight: 700; text-align: right; white-space: nowrap; }

    /* Cada metadado na sua própria área, em flex para o conteúdo fluir */
    .list-row .col-date,
    .list-row .col-account,
    .list-row .col-category,
    .list-row .col-status,
    .list-row .col-balance {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 5px;
        font-size: 12px;
        color: var(--text-muted);
        min-width: 0;
        position: static;   /* position:relative inline criaria contexto de empilhamento */
    }
    .list-row .col-date     { grid-area: m-date; }
    .list-row .col-account  { grid-area: m-acct; }
    .list-row .col-category { grid-area: m-cat; }
    .list-row .col-status   { grid-area: m-status; margin-top: 3px; }
    /* .text-right vem inline do PHP: no mobile o saldo fica à esquerda,
       alinhado com os demais metadados */
    .list-row .col-balance  { grid-area: m-bal; text-align: left; justify-content: flex-start; }

    /* Metadado vazio não ocupa linha */
    .list-row .col-date:empty,
    .list-row .col-account:empty,
    .list-row .col-category:empty,
    .list-row .col-status:empty,
    .list-row .col-balance:empty { display: none; }

    .list-row .row-actions  { grid-area: actions; justify-content: flex-start; margin-top: 8px; }

    /* Badges de status não encolhem nem quebram no meio */
    .list-row .col-status .badge { flex-shrink: 0; white-space: nowrap; }

    /* Cards de resumo do mês: 2 colunas em mobile */
    .summary-cards-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* ---- Stat cards: 2 colunas, empilha ícone e valor ---- */
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 14px 12px;
    }
    .stat-icon  { width: 32px; height: 32px; font-size: 14px; }
    .stat-label { font-size: 11px; line-height: 1.25; }
    .stat-value {
        font-size: 17px;
        line-height: 1.15;
        word-break: break-word;
        overflow-wrap: anywhere;
    }
    .stat-value small { font-size: 11px !important; display: block; margin-top: 2px; }

    /* ---- Orçamento: uma coluna por linha, sem tabela ---- */
    .budget-header { display: none !important; }
    .budget-row {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
        padding: 14px 16px !important;
    }
    .budget-row .budget-cat    { width: 100%; }
    .budget-row .budget-fields {
        display: grid !important;
        grid-template-columns: 1fr 1fr auto;
        gap: 10px;
        align-items: end;
        width: 100%;
    }
    .budget-row .budget-fields label {
        display: block !important;
        font-size: 10px;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: .04em;
        margin-bottom: 3px;
        font-weight: 600;
    }

    .auth-card { padding: 28px 20px; }

    .modal { max-width: 100%; margin: 0; border-radius: var(--radius) var(--radius) 0 0; }
    .modal-overlay { align-items: flex-end; }

    /* Barra de contas: scroll horizontal sem estouro */
    .accounts-bar {
        gap: 8px;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        scrollbar-width: none;
    }
    .accounts-bar::-webkit-scrollbar { display: none; }
    .account-chip { flex-shrink: 0; }

    .list-totals  { flex-wrap: wrap; gap: 12px; }

    /* Page header: empilha em mobile */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .page-header > div { width: 100%; }
}

@media (max-width: 400px) {
    /* Mantém 2 colunas — 1 coluna deixa os cards altos demais.
       Reduz apenas a tipografia para caber valores acima de 10 mil. */
    .stat-value  { font-size: 15px; }
    .stat-label  { font-size: 10px; }
    .stat-card   { padding: 12px 10px; }
    .summary-cards-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .budget-row .budget-fields {
        grid-template-columns: 1fr 1fr;
    }
    .budget-row .budget-pct { grid-column: 1 / -1; text-align: left !important; }
}

/* ---- Overlay sidebar (mobile) ----------------------------- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
}
.sidebar-overlay.open { display: block; }

/* ---- Scrollbar custom (desktop) -------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Utilitários ----------------------------------------- */
.d-flex  { display: flex; }
.gap-8   { gap: 8px; }
.gap-12  { gap: 12px; }
.mt-4    { margin-top: 4px; }
.mt-8    { margin-top: 8px; }
.mt-16   { margin-top: 16px; }
.mb-16   { margin-bottom: 16px; }
.mb-24   { margin-bottom: 24px; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.fw-600  { font-weight: 600; }
.fs-12   { font-size: 12px; }
.fs-13   { font-size: 13px; }
.text-muted    { color: var(--text-muted); }
.text-secondary{ color: var(--text-secondary); }
.w-100   { width: 100%; }

/* ---- Impressão / PDF -------------------------------------- */
@media print {
    .no-print,
    .sidebar,
    .sidebar-overlay,
    .topbar { display: none !important; }

    .main-content { margin-left: 0 !important; }
}

/* ================================================================
   Aviso de envio em andamento
   ================================================================
   O disparo do e-mail com o codigo pode levar alguns segundos. Sem
   retorno visual a pessoa acha que o botao nao funcionou e clica de
   novo, o que gera codigo novo e invalida o anterior. */

.enviando-overlay {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, .62);
    backdrop-filter: blur(2px);
}
.enviando-overlay.open { display: flex; }

.enviando-caixa {
    background: var(--bg-card, #fff);
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(15, 23, 42, .28);
    padding: 30px 28px;
    max-width: 370px;
    width: 100%;
    text-align: center;
}

.enviando-icone {
    width: 54px;
    height: 54px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--color-primary-light, #eff6ff);
    color: var(--color-primary, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 21px;
}

.enviando-titulo {
    font-size: 16.5px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    margin-bottom: 7px;
}

.enviando-texto {
    font-size: 13.5px;
    color: var(--text-secondary, #475569);
    line-height: 1.6;
}

/* Barra de progresso indeterminada: indica atividade sem prometer prazo */
.enviando-barra {
    margin-top: 18px;
    height: 4px;
    border-radius: 4px;
    background: var(--border-color, #e2e8f0);
    overflow: hidden;
}
.enviando-barra span {
    display: block;
    height: 100%;
    width: 38%;
    border-radius: 4px;
    background: var(--color-primary, #3b82f6);
    animation: enviandoDesliza 1.15s ease-in-out infinite;
}
@keyframes enviandoDesliza {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(300%); }
}

.enviando-aviso {
    margin-top: 15px;
    font-size: 12px;
    color: var(--text-muted, #94a3b8);
    line-height: 1.55;
}

@media (prefers-reduced-motion: reduce) {
    .enviando-barra span { animation: none; width: 100%; }
    .enviando-icone i { animation: none !important; }
}
