/* ==========================================================================
   SystemFin — Controle Financeiro Pessoal
   ========================================================================== */

:root {
    --color-bg: #f4f6fb;
    --color-surface: #ffffff;
    --color-border: #e5e9f2;
    --color-text: #1f2430;
    --color-text-muted: #6b7280;
    --color-primary: #4f7cff;
    --color-primary-dark: #3a63e0;
    --color-success: #16a34a;
    --color-success-bg: #ecfdf3;
    --color-danger: #e0473f;
    --color-danger-bg: #fdecea;
    --color-warning: #d97706;
    --color-warning-bg: #fef7e6;
    --color-sidebar-bg: #171b2e;
    --color-sidebar-text: #b7bdd6;
    --color-sidebar-text-active: #ffffff;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

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

h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 600; }
p { margin: 0 0 .75rem; }

/* ---------- Layout do app (logado) ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--color-sidebar-bg);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
}

.sidebar .brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    padding: 0 20px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    margin-bottom: 10px;
}
.sidebar .brand span.dot { color: var(--color-primary); }

.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.sidebar a.nav-link {
    color: var(--color-sidebar-text);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: .92rem;
    border-left: 3px solid transparent;
    text-decoration: none;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar a.nav-link.active {
    background: rgba(79,124,255,.15);
    color: var(--color-sidebar-text-active);
    border-left-color: var(--color-primary);
    font-weight: 600;
}

.sidebar .user-box {
    padding: 14px 20px;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .85rem;
}
.sidebar .user-box .user-name { color: #fff; font-weight: 600; display: block; margin-bottom: 6px; }
.sidebar .user-box a { color: var(--color-sidebar-text); }

.main {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    padding: 28px 32px 60px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
}
.topbar h1 { font-size: 1.5rem; }
.topbar .subtitle { color: var(--color-text-muted); font-size: .9rem; margin-top: 2px; }

/* ---------- Cards ---------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}
.card h2, .card h3 { margin-bottom: 14px; }

.grid { display: grid; gap: 18px; }
.grid > * { min-width: 0; } /* evita que itens de grid (ex: cards com tabela larga) forcem overflow horizontal */
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- Stat tiles ---------- */
.stat-tile { display: flex; flex-direction: column; gap: 4px; }
.stat-tile .label { color: var(--color-text-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-tile .value { font-size: 1.6rem; font-weight: 700; }
.stat-tile .value.positive { color: var(--color-success); }
.stat-tile .value.negative { color: var(--color-danger); }
.stat-tile .hint { color: var(--color-text-muted); font-size: .82rem; }

/* ---------- Botões ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #f2f4f9; }
.btn-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.btn-danger:hover { background: #fbdad7; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Formulários ---------- */
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; color: var(--color-text); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=month], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: .92rem;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79,124,255,.15);
}
textarea { resize: vertical; min-height: 70px; }

.input-color { padding: 3px; height: 40px; cursor: pointer; }

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

fieldset { border: 1px solid var(--color-border); border-radius: 8px; padding: 14px; margin: 0 0 16px; }
legend { font-weight: 600; font-size: .85rem; padding: 0 6px; }

/* ---------- Tabelas ---------- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th {
    text-align: left;
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfd; }
.table-wrap { overflow-x: auto; }
.text-right { text-align: right; }
.text-center { text-align: center; }

.amount-receita { color: var(--color-success); font-weight: 600; }
.amount-despesa { color: var(--color-danger); font-weight: 600; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-neutral { background: #eef0f6; color: var(--color-text-muted); }

.color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--color-text-muted);
}

/* ---------- Barra de progresso ---------- */
.progress { background: #eef0f6; border-radius: 20px; height: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--color-primary); border-radius: 20px; }
.progress.over > div { background: var(--color-danger); }

/* ---------- Flash messages ---------- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.flash-error { background: var(--color-danger-bg); color: var(--color-danger); }
.flash-success { background: var(--color-success-bg); color: var(--color-success); }
.flash-info { background: #eaf1ff; color: var(--color-primary-dark); }

/* ---------- Páginas de autenticação ---------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1c2340, #4f7cff);
    padding: 20px;
}
.auth-card {
    background: #fff;
    width: 100%;
    max-width: 380px;
    border-radius: 14px;
    padding: 32px 30px;
    box-shadow: var(--shadow-md);
}
.auth-card .brand {
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}
.auth-card .brand span { color: var(--color-primary); }
.auth-card .subtitle { text-align: center; color: var(--color-text-muted); font-size: .85rem; margin-bottom: 22px; }
.auth-card .switch { text-align: center; font-size: .87rem; margin-top: 16px; color: var(--color-text-muted); }

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

.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.section-divider { border: none; border-top: 1px solid var(--color-border); margin: 20px 0; }

.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }

.chart-wrap { position: relative; height: 300px; }
.chart-wrap.small { height: 220px; }

/* ---------- Mobile: sidebar vira menu retrátil ---------- */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 8px;
    background: var(--color-sidebar-bg);
    color: #fff;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 18, 32, .5);
    z-index: 1030;
}
.sidebar-overlay.open { display: block; }

@media (max-width: 880px) {
    .app-shell { display: block; }

    .mobile-menu-toggle { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 250px;
        max-width: 82vw;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 1040;
        box-shadow: 4px 0 20px rgba(0,0,0,.25);
    }
    .sidebar.open { transform: translateX(0); }

    .main { padding: 72px 16px 40px; }

    .topbar { flex-direction: column; align-items: stretch; }
    .topbar h1 { font-size: 1.3rem; }
}

@media (max-width: 480px) {
    .card { padding: 16px; }
    .stat-tile .value { font-size: 1.3rem; }
}
