:root {
    --teal: #0f766e;
    --teal-dark: #0b5c56;
    --teal-light: #ccfbf1;
    --ink: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --bg: #f8fafc;
    --card: #ffffff;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --warn: #b45309;
    --warn-bg: #fef3c7;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --radius: 14px;
    --nav-h: 64px;
    --top-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--top-h);
    background: var(--teal);
    color: #fff;
    padding-top: env(safe-area-inset-top);
}
.topbar-inner {
    height: var(--top-h);
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}
.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.2px; }
.topbar-user {
    width: 32px; height: 32px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9rem;
}

/* ---------- Main content ---------- */
.app-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--nav-h) + 24px);
    min-height: calc(100vh - var(--top-h));
}
.auth-main {
    max-width: 420px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* ---------- Flash messages ---------- */
.flash-stack { max-width: 720px; margin: 0 auto; padding: 12px 16px 0; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; font-size: 0.92rem; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error   { background: var(--danger-bg); color: var(--danger); }
.flash-info    { background: var(--teal-light); color: var(--teal-dark); }

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: 0 1px 2px rgba(15,23,42,0.06);
    border: 1px solid var(--border);
}
.card h2, .card h3 { margin-top: 0; }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.summary-tile {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}
.summary-tile .label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.summary-tile .value { font-size: 1.35rem; font-weight: 700; margin-top: 4px; }
.summary-tile.income .value { color: var(--ok); }
.summary-tile.expense .value { color: var(--danger); }
.summary-tile.net .value { color: var(--teal-dark); }
.summary-tile.savings .value { color: #7c3aed; }

/* ---------- Forms ---------- */
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea, button {
    font-family: inherit;
    font-size: 1rem;
}
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--teal-light);
}
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 18px;
    border-radius: 10px;
    border: none;
    background: var(--teal);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
.btn:active { background: var(--teal-dark); }
.btn-block { width: 100%; margin-top: 18px; }
.btn-secondary { background: #fff; color: var(--teal); border: 1px solid var(--teal); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

/* ---------- Tables / lists ---------- */
.txn-list { list-style: none; margin: 0; padding: 0; }
.txn-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.txn-item:last-child { border-bottom: none; }
.txn-main { display: flex; flex-direction: column; }
.txn-cat { font-weight: 600; }
.txn-meta { font-size: 0.8rem; color: var(--muted); }
.txn-amount { font-weight: 700; white-space: nowrap; }
.txn-amount.income { color: var(--ok); }
.txn-amount.expense { color: var(--danger); }
.txn-actions { display: flex; gap: 6px; margin-left: 10px; }
.icon-btn {
    border: none; background: transparent; cursor: pointer;
    color: var(--muted); font-size: 1rem; padding: 4px 6px;
}
.icon-btn:hover { color: var(--ink); }

.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.pill-income { background: var(--ok-bg); color: var(--ok); }
.pill-expense { background: var(--danger-bg); color: var(--danger); }

/* ---------- Budgets ---------- */
.budget-row { margin-bottom: 18px; }
.budget-row-head { display: flex; justify-content: space-between; font-size: 0.92rem; margin-bottom: 6px; }
.progress-track {
    height: 10px; border-radius: 6px; background: #eef2f6; overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 6px; background: var(--teal); transition: width 0.3s; }
.progress-fill.warn { background: var(--warn); }
.progress-fill.over { background: var(--danger); }
.budget-alert {
    margin-top: 6px; font-size: 0.82rem; padding: 6px 10px; border-radius: 8px;
}
.budget-alert.warn { background: var(--warn-bg); color: var(--warn); }
.budget-alert.over { background: var(--danger-bg); color: var(--danger); }

/* ---------- Goals ---------- */
.goal-card .progress-track { margin-top: 8px; }
.goal-meta { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); margin-top: 6px; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: var(--nav-h);
    background: #fff;
    border-top: 1px solid var(--border);
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 30;
}
.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    font-size: 0.68rem;
}
.bottom-nav a.active { color: var(--teal); }
.nav-icon { font-size: 1.15rem; line-height: 1; }

/* ---------- Auth pages ---------- */
.auth-logo { text-align: center; font-size: 1.5rem; font-weight: 800; color: var(--teal-dark); margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 0.9rem; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 0.9rem; color: var(--muted); }
.auth-switch a { color: var(--teal); font-weight: 600; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- Install banner ---------- */
.install-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--teal-light);
    color: var(--teal-dark);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 0.88rem;
}
.install-banner button { flex-shrink: 0; }

/* ---------- Install modal (iOS instructions) ---------- */
.install-modal {
    position: fixed; inset: 0; background: rgba(15,23,42,0.5);
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 100;
}
.install-modal[hidden] { display: none; }
.install-modal-card {
    background: #fff; border-radius: 16px 16px 0 0;
    max-width: 480px; width: 100%; padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    position: relative; font-size: 0.95rem; line-height: 1.5;
}
.install-modal-close {
    position: absolute; top: 10px; right: 14px;
    border: none; background: none; font-size: 1.4rem; cursor: pointer; color: var(--muted);
}

/* ---------- Charts ---------- */
.chart-wrap { position: relative; height: 240px; margin-top: 8px; }

/* ---------- Small helpers ---------- */
.muted { color: var(--muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.month-picker { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.month-picker select { width: auto; flex: 1; }

@media (min-width: 480px) {
    .summary-grid { grid-template-columns: repeat(4, 1fr); }
}
