:root {
    --sidebar-width: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-fg: #cbd5e1;
    --sidebar-muted: #64748b;
    --sidebar-active-bg: rgba(99, 102, 241, .18);
    --sidebar-active-fg: #fff;
    --accent: #6366f1;
    --app-bg: #f4f6fb;
    --card-border: rgba(15, 23, 42, .07);
    --income: #16a34a;
    --expense: #dc2626;
}

[data-bs-theme="dark"] {
    --sidebar-bg: #0b1120;
    --app-bg: #111827;
    --card-border: rgba(255, 255, 255, .07);
    --bs-body-bg: #111827;
    --bs-tertiary-bg: #1f2937;
    --income: #4ade80;
    --expense: #f87171;
}

body {
    background: var(--app-bg);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: .925rem;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg) !important;
    color: var(--sidebar-fg);
    flex-shrink: 0;
}
@media (min-width: 992px) {
    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0;
        display: flex; flex-direction: column;
        overflow-y: auto;
    }
    .main { margin-left: var(--sidebar-width); }
}
@media (max-width: 991.98px) {
    .sidebar.offcanvas-lg { --bs-offcanvas-width: var(--sidebar-width); }
}
.sidebar-brand {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.brand-link { display: flex; align-items: center; gap: .65rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand-icon {
    width: 34px; height: 34px; border-radius: 10px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #6366f1, #0ea5e9);
    color: #fff;
}
.sidebar-nav { padding: .75rem .75rem 2rem; display: flex; flex-direction: column; gap: 2px; width: 100%; }
.nav-group {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
    color: var(--sidebar-muted); padding: 1rem .75rem .35rem; font-weight: 600;
}
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: .7rem;
    color: var(--sidebar-fg); padding: .5rem .75rem; border-radius: 8px;
    transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .85; }
.sidebar-nav .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-fg); font-weight: 600; }
.sidebar-nav .nav-link.active i { color: #a5b4fc; opacity: 1; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 1020;
    display: flex; align-items: center; gap: .75rem;
    padding: .8rem 1.5rem;
    background: color-mix(in srgb, var(--app-bg) 85%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--card-border);
}
.page-title { font-size: 1.2rem; font-weight: 700; margin: 0; }
.content { padding: 1.5rem; }
@media (max-width: 575.98px) { .content { padding: 1rem .75rem; } .topbar { padding: .6rem .75rem; } }

.btn-icon { border: 1px solid var(--card-border); background: var(--bs-body-bg); border-radius: 10px; padding: .35rem .6rem; }
[data-bs-theme="light"] .theme-icon-light, [data-bs-theme="dark"] .theme-icon-dark { display: none; }

/* Cards */
.card { border: 1px solid var(--card-border); border-radius: 14px; box-shadow: 0 1px 2px rgba(15, 23, 42, .04); }
.card-header { background: transparent; border-bottom: 1px solid var(--card-border); font-weight: 600; padding: .9rem 1.1rem; }
.stat-card .stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--bs-secondary-color); font-weight: 600; }
.stat-card .stat-value { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem;
}
.bg-soft-success { background: rgba(34, 197, 94, .14); color: var(--income); }
.bg-soft-danger { background: rgba(239, 68, 68, .14); color: var(--expense); }
.bg-soft-primary { background: rgba(99, 102, 241, .14); color: var(--accent); }
.bg-soft-warning { background: rgba(234, 179, 8, .16); color: #ca8a04; }

.text-income { color: var(--income) !important; }
.text-expense { color: var(--expense) !important; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

/* Tables */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .55rem .75rem; vertical-align: middle; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--bs-secondary-color); font-weight: 600; white-space: nowrap; }
.table tfoot td, .table tfoot th { font-weight: 700; border-top: 2px solid var(--bs-border-color); }
.actions { white-space: nowrap; text-align: right; }
.row-inactive > td:not(:first-child):not(.actions) { opacity: .45; }
.form-switch .form-check-input { cursor: pointer; }

.obs-cell { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.actions .btn { padding: .15rem .45rem; }
div.dt-container .dt-search input { width: 220px; }
div.dt-container { font-size: .9rem; }

.filters .form-label { font-size: .75rem; font-weight: 600; color: var(--bs-secondary-color); margin-bottom: .2rem; }

.form-label { font-weight: 500; }
.chart-box { position: relative; height: 300px; }
.chart-box.sm { height: 240px; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-box { width: 100%; max-width: 380px; }
.login-page .brand-icon { width: 48px; height: 48px; font-size: 1.4rem; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--bs-secondary-color); }
.empty-state i { font-size: 2.2rem; display: block; margin-bottom: .5rem; opacity: .6; }

@media print {
    .sidebar, .topbar .btn, .no-print, .dt-length, .dt-search, .dt-paging, .dt-info { display: none !important; }
    .main { margin-left: 0 !important; }
    .content { padding: 0; }
    .card { border: 0; box-shadow: none; }
    body { background: #fff; }
}
