/* Base mobile-first */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --border: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #22c55e;
    --primary-press: #16a34a;
    --danger: #ef4444;
}

/* App shell: o body NÃO rola — a rolagem fica na .scroll-area. Isso evita o bug
   do iOS Safari em que elementos fixed "descolam" durante o bounce elástico. */
html { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.scroll-area {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.topbar {
    flex: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; }

.container { padding: 1rem; max-width: 640px; margin: 0 auto; }

h1 { font-size: 1.4rem; margin-bottom: 0.5rem; }

.muted { color: var(--muted); font-size: 0.9rem; margin-bottom: 1rem; }

.inline { display: inline; }

/* Formulários */
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.75rem 0 0.25rem; }

input, select {
    width: 100%;
    padding: 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}

input:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }

.btn-primary {
    width: 100%;
    margin-top: 1.25rem;
    padding: 0.85rem;
    border: none;
    border-radius: 0.5rem;
    background: var(--primary);
    color: #052e16;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.btn-primary:active { background: var(--primary-press); }

.btn-link {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: underline;
}

/* Login */
.login-box {
    max-width: 380px;
    margin: 15vh auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
}

.login-box h1 { text-align: center; }
.login-box .muted { text-align: center; }

.alert {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--danger);
    color: #fca5a5;
    border-radius: 0.5rem;
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

/* Dashboard */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-value { font-size: 1.8rem; font-weight: 700; }

.stat-label { color: var(--muted); font-size: 0.85rem; }

/* Navegação inferior — item do flex do body (não usa fixed: iOS bounce-proof) */
.bottom-nav {
    flex: none;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.4rem 0 calc(0.4rem + env(safe-area-inset-bottom));
}

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.65rem;
    min-width: 3.5rem;
}

.bottom-nav a.active { color: var(--primary); }

.nav-icon { font-size: 1.2rem; }

.nav-add {
    background: var(--primary);
    color: #052e16 !important;
    border-radius: 50%;
    width: 2.8rem;
    height: 2.8rem;
    font-size: 1.6rem !important;
    justify-content: center;
    min-width: 2.8rem !important;
    font-weight: 700;
}

/* Mensagens */
.flash-success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid var(--primary);
    color: #86efac;
    border-radius: 0.5rem;
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

/* Navegação de mês */
.month-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.month-arrow {
    color: var(--text);
    text-decoration: none;
    font-size: 1.5rem;
    padding: 0.25rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.month-label { font-weight: 700; font-size: 1.05rem; }

/* Resumo do mês */
.summary-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.summary-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.summary-label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }

.summary-value { font-size: 0.9rem; font-weight: 700; }

.pos { color: #4ade80; }
.neg { color: #f87171; }

/* Lista de lançamentos */
.txn-date-header {
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    margin: 0.9rem 0 0.35rem;
}

.txn-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.4rem;
    text-decoration: none;
    color: var(--text);
}

.txn-main { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }

.txn-desc { font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.txn-meta { color: var(--muted); font-size: 0.75rem; }

.txn-amount { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }

.badge {
    background: var(--border);
    border-radius: 0.75rem;
    font-size: 0.65rem;
    padding: 0.1rem 0.45rem;
    vertical-align: middle;
}

.badge-warn { background: #78350f; color: #fcd34d; }

.empty-state { text-align: center; margin-top: 3rem; line-height: 1.6; }

/* Botão flutuante */
.fab {
    position: fixed;
    right: 1rem;
    bottom: calc(4.5rem + env(safe-area-inset-bottom));
    background: var(--primary);
    color: #052e16;
    width: 3.4rem;
    height: 3.4rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    text-decoration: none;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Formulário de lançamento */
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

.type-toggle input[type="radio"] { display: none; }

.toggle-btn {
    display: block;
    text-align: center;
    margin: 0;
    padding: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
}

#type-debit:checked + .toggle-debit { background: rgba(239, 68, 68, 0.2); border-color: var(--danger); color: #fca5a5; }
#type-credit:checked + .toggle-credit { background: rgba(34, 197, 94, 0.2); border-color: var(--primary); color: #86efac; }

.amount-input { font-size: 1.6rem; font-weight: 700; text-align: center; }

.check-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    font-size: 0.95rem;
    margin-top: 1rem;
}

.check-label input { width: auto; }

.btn-danger {
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.75rem;
    border: none;
    border-radius: 0.5rem;
    background: var(--danger);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
}

.btn-danger.btn-outline {
    background: none;
    border: 1px solid var(--danger);
    color: #fca5a5;
}

.btn-sm { margin-top: 0.75rem; padding: 0.6rem; font-size: 0.9rem; }

/* Configurações */
.settings-section { margin-bottom: 1.5rem; }

.settings-section h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }

.settings-section h3 { margin: 0.75rem 0 0.35rem; font-size: 0.8rem; text-transform: uppercase; }

.settings-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.4rem;
}

.settings-item summary { cursor: pointer; font-size: 0.95rem; }

.settings-item.inactive summary { color: var(--muted); }

.settings-add summary { color: var(--primary); }

/* Compartilhamento de cartão */
.share-title { margin-top: 1rem; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; }

.share-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.locked-origin {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--bg);
}

/* Faturas */
.chip {
    display: inline-block;
    border-radius: 0.75rem;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    text-transform: uppercase;
    vertical-align: middle;
    margin-right: 0.25rem;
}

.chip-danger { background: #7f1d1d; color: #fca5a5; }
.chip-warn { background: #78350f; color: #fcd34d; }
.chip-open { background: #14532d; color: #86efac; }
.chip-muted { background: var(--border); color: var(--muted); }
.chip-paid { background: #1e3a8a; color: #93c5fd; }

.muted-inline { color: var(--muted); font-size: 0.75rem; }

.invoice-items { margin-top: 0.6rem; border-top: 1px solid var(--border); }

.invoice-line {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.35rem 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.pay-form { margin-top: 0.5rem; }

.link { color: var(--primary); }

/* Painel */
.balance-hero {
    background: linear-gradient(135deg, #14532d, #166534);
    border-radius: 0.75rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
}

.balance-hero.negative { background: linear-gradient(135deg, #7f1d1d, #991b1b); }

.balance-label { color: rgba(255, 255, 255, 0.7); font-size: 0.8rem; text-transform: uppercase; }

.balance-total { font-size: 2rem; font-weight: 700; color: #fff; }

.balance-banks { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.4rem; }

.balance-bank {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
}

.dash-section { margin-top: 1.25rem; }

.dash-section h2 { font-size: 1rem; margin-bottom: 0.5rem; }

.see-all { float: right; font-size: 0.8rem; font-weight: 400; }

.chart-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 0.75rem;
    height: 220px;
}

/* Relatórios */
.year-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.6rem;
}

.table-scroll { overflow-x: auto; }

.report-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.report-table th, .report-table td {
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.report-table th { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }

.report-table .num { text-align: right; white-space: nowrap; }

.report-table tfoot td { border-bottom: none; }

.muted-cell { color: var(--muted); }

/* Busca */
.search-form { margin-bottom: 0.75rem; }

.topbar-actions { display: flex; align-items: center; gap: 0.9rem; }

.topbar-icon { text-decoration: none; font-size: 1.1rem; }
