:root {
    --bg-main: #1a1d23;
    --bg-sidebar: #15171c;
    --bg-card: #23262d;
    --bg-card-hover: #2a2e36;
    --bg-input: #2a2e36;
    --border-color: #33373f;
    --text-primary: #f4f5f7;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent-blue: #3b82f6;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-amber: #f59e0b;
    --radius-md: 10px;
    --radius-lg: 14px;
    --sidebar-width: 230px;
    --bottom-nav-height: 64px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Layout ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px 24px;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.brand-name {
    font-weight: 700;
    font-size: 16px;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14.5px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-blue);
    color: #fff;
}

.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { margin-top: auto; }
.logout-link { color: var(--text-muted); }

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 28px;
    border-bottom: 1px solid var(--border-color);
    gap: 16px;
    flex-wrap: wrap;
}

.fab-add {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 9px 16px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
}
.fab-add:hover { background: var(--bg-card-hover); }
.fab-plus { font-size: 16px; color: var(--text-secondary); }

.month-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 4px 6px;
}

.month-nav-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 18px;
    color: var(--text-secondary);
}
.month-nav-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.month-label {
    font-weight: 600;
    font-size: 14.5px;
    padding: 0 8px;
    min-width: 110px;
    text-align: center;
}

.page-content {
    padding: 24px 28px 100px;
    max-width: 1000px;
    width: 100%;
}

.page-title {
    font-size: 26px;
    font-weight: 700;
    margin: 4px 0 24px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    margin: 32px 0 14px;
}

/* ---------- Stat cards ---------- */

.stat-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.stat-cards-2 { grid-template-columns: repeat(2, 1fr); }

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    border: 1px solid var(--border-color);
}

.stat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.stat-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
}
.stat-icon-green { background: var(--accent-green); }
.stat-icon-red { background: var(--accent-red); }
.stat-icon-amber { background: var(--accent-amber); }

.stat-label { color: var(--text-secondary); font-size: 13.5px; font-weight: 500; }

.stat-value { font-size: 24px; font-weight: 700; }
.stat-value.negative { color: var(--accent-red); }
.stat-value.positive { color: var(--accent-green); }

/* ---------- Category list ---------- */

.category-list, .budget-list {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.category-row, .budget-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-color);
}
.category-row:last-child, .budget-row:last-child { border-bottom: none; }

.category-icon-badge {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.category-row-main, .budget-row-main { flex: 1; min-width: 0; }

.category-row-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
    gap: 8px;
}

.category-name { font-weight: 600; font-size: 14.5px; }
.category-amount { font-weight: 600; font-size: 14.5px; color: var(--text-primary); white-space: nowrap; }
.budget-target-suffix { color: var(--text-muted); font-weight: 400; font-size: 13px; }

.progress-track {
    height: 6px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-fill-over { animation: pulse-red 1.6s ease-in-out infinite; }
@keyframes pulse-red { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.budget-row-over { background: rgba(239, 68, 68, 0.06); }
.budget-alert {
    display: inline-block;
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--accent-red);
    font-weight: 600;
}

.empty-state {
    padding: 32px 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ---------- Transactions ---------- */

.tx-list, .tx-list-full {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.tx-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
}
.tx-row:last-child { border-bottom: none; }

.tx-icon-badge {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tx-desc { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-date { font-size: 12.5px; color: var(--text-muted); }

.tx-amount { font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.tx-amount.positive { color: var(--accent-green); }
.tx-amount.negative { color: var(--text-primary); }

.tx-actions { display: flex; gap: 4px; }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 15px;
    padding: 6px;
    border-radius: 8px;
}
.icon-btn:hover { background: var(--bg-card-hover); }

.view-all-link {
    display: block;
    text-align: center;
    padding: 14px;
    color: var(--accent-blue);
    font-weight: 600;
    font-size: 13.5px;
}
.view-all-link:hover { background: var(--bg-card-hover); }

/* ---------- Filters ---------- */

.filters-bar { margin-bottom: 18px; }
.filters-form { display: flex; gap: 10px; flex-wrap: wrap; }
.filter-select { width: auto; min-width: 160px; }

/* ---------- Forms / Modal ---------- */

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 14px 0 6px;
}
.field-label:first-of-type { margin-top: 0; }

.field-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 11px 12px;
    border-radius: var(--radius-md);
    font-size: 14.5px;
    font-family: inherit;
}
.field-input:focus { outline: none; border-color: var(--accent-blue); }

select.field-input {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%239ca3af' stroke-width='1.5' fill='none'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
    border: none;
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 14.5px;
}
.btn-primary:hover { background: #2563eb; }
.btn-full { width: 100%; margin-top: 22px; }

.type-toggle {
    display: flex;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    padding: 4px;
    gap: 4px;
}
.type-option { flex: 1; text-align: center; }
.type-option input { display: none; }
.type-option span {
    display: block;
    padding: 9px 0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}
.type-option input:checked + span {
    background: var(--bg-card);
    color: var(--text-primary);
}

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

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { margin: 0; font-size: 17px; font-weight: 700; }

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    line-height: 1;
    padding: 4px 8px;
}

/* ---------- Auth pages ---------- */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-main);
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    width: 100%;
    max-width: 380px;
    margin: 16px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}
.auth-brand h1 { font-size: 20px; margin: 0; }

.auth-subtitle { color: var(--text-secondary); font-size: 14px; margin: 0 0 20px; }
.auth-error {
    background: rgba(239, 68, 68, 0.12);
    color: var(--accent-red);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    margin-bottom: 16px;
}
.auth-form { display: flex; flex-direction: column; }

/* ---------- Bottom nav (mobile) ---------- */

.bottom-nav {
    display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 880px) {
    .sidebar { display: none; }

    .topbar {
        padding: 14px 16px;
        position: sticky;
        top: 0;
        background: var(--bg-main);
        z-index: 10;
    }

    .fab-add { order: 2; }
    .month-nav { order: 1; }

    .page-content {
        padding: 16px 16px calc(var(--bottom-nav-height) + 24px);
    }

    .stat-cards { grid-template-columns: 1fr; gap: 10px; }
    .stat-cards-2 { grid-template-columns: 1fr; }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--bottom-nav-height);
        background: var(--bg-sidebar);
        border-top: 1px solid var(--border-color);
        align-items: center;
        justify-content: space-around;
        padding-bottom: env(safe-area-inset-bottom);
        z-index: 50;
    }

    .bottom-nav-link {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        color: var(--text-muted);
        font-size: 10.5px;
        font-weight: 600;
        flex: 1;
    }
    .bottom-nav-link.active { color: var(--accent-blue); }
    .bn-icon { font-size: 19px; }

    .bottom-nav-fab {
        width: 46px;
        height: 46px;
        border-radius: 50%;
        background: var(--accent-blue);
        color: #fff;
        border: none;
        font-size: 26px;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: -18px;
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
        flex-shrink: 0;
    }

    .fab-add span.fab-plus { display: none; }
    .fab-add { padding: 9px 14px; }
}

@media (max-width: 480px) {
    .filters-form { flex-direction: column; }
    .filter-select { min-width: 0; width: 100%; }
    .tx-actions { flex-direction: column; }
}
