:root {
    --bg-body: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-subtle: #f8fafc;
    --bg-sidebar: #0f172a;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --primary: #10b981;
    --primary-hover: #059669;
    --primary-soft: rgba(16, 185, 129, 0.12);
    --income: #10b981;
    --income-soft: rgba(16, 185, 129, 0.12);
    --expense: #ef4444;
    --expense-soft: rgba(239, 68, 68, 0.12);
    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, 0.14);
    --info: #0ea5e9;
    --info-soft: rgba(14, 165, 233, 0.12);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.14);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

[data-theme="dark"] {
    --bg-body: #0b1120;
    --bg-surface: #111827;
    --bg-subtle: #1e293b;
    --bg-sidebar: #090e1a;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #1f2937;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 45px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* Auth Layout */
.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    background: var(--bg-body);
}

.auth-hero {
    background: linear-gradient(145deg, #0f172a 0%, #064e3b 100%);
    color: #fff;
    padding: 3.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.auth-hero::after {
    content: "";
    position: absolute;
    width: 420px;
    height: 420px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.25), transparent 70%);
    bottom: -120px;
    right: -80px;
    pointer-events: none;
}

.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.brand-badge {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}

.auth-features {
    display: grid;
    gap: 1rem;
    margin-top: 2rem;
}

.auth-feature-item {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem 1.15rem;
    border-radius: var(--radius-md);
}

.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
}

.auth-card {
    width: 100%;
    max-width: 430px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2.25rem;
    box-shadow: var(--shadow-md);
}

/* App Shell */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transition: transform 0.25s ease;
}

.sidebar-header {
    padding: 1.4rem 1.35rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar-title {
    font-weight: 800;
    font-size: 1.15rem;
    color: #fff;
    letter-spacing: -0.02em;
}

.sidebar-balance-box {
    margin: 1.1rem 1rem 0.6rem;
    padding: 0.95rem 1rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-balance-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}

.sidebar-balance-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    margin-top: 0.2rem;
}

.sidebar-nav {
    padding: 0.65rem 0.85rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 0.75rem 0.65rem 0.3rem;
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.68rem 0.85rem;
    border-radius: 10px;
    color: #cbd5e1;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.22), rgba(16, 185, 129, 0.08));
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
    font-weight: 600;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #10b981;
    color: #052e16;
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-meta {
    min-width: 0;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #f8fafc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.72rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main Content */
.main-area {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0.85rem 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.mobile-menu-btn {
    display: none;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.45rem;
    color: var(--text-main);
    cursor: pointer;
}

.period-switcher {
    display: inline-flex;
    align-items: center;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 0.2rem;
    gap: 0.25rem;
}

.period-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}

.period-btn:hover {
    background: var(--bg-surface);
    color: var(--text-main);
}

.period-current {
    padding: 0 0.75rem;
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
}

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

.content-container {
    padding: 1.75rem;
    max-width: 1380px;
    width: 100%;
    margin: 0 auto;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.page-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin: 0.2rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.58rem 1rem;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    white-space: nowrap;
}

.btn-sm {
    padding: 0.38rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

.btn-icon {
    padding: 0.5rem;
    border-radius: 9px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.28);
}

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

.btn-danger {
    background: var(--expense);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-outline {
    background: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--bg-subtle);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--bg-subtle);
    color: var(--text-main);
}

/* Cards & Grids */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.1rem;
    margin-bottom: 1.5rem;
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.3rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.1rem;
}

.card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.kpi-card {
    position: relative;
    overflow: hidden;
}

.kpi-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.65rem;
}

.kpi-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

.kpi-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.kpi-value {
    font-size: 1.55rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
}

.kpi-foot {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1.55fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.grid-equal {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 1.15rem;
}

/* Badges & Colors */
.text-income { color: var(--income) !important; }
.text-expense { color: var(--expense) !important; }
.text-warning { color: var(--warning) !important; }
.text-info { color: var(--info) !important; }
.text-muted { color: var(--text-muted) !important; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 600;
}

.badge-paid {
    background: var(--income-soft);
    color: var(--income);
}

.badge-pending {
    background: var(--warning-soft);
    color: var(--warning);
}

.badge-overdue {
    background: var(--expense-soft);
    color: var(--expense);
}

.badge-neutral {
    background: var(--bg-subtle);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.cat-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.83rem;
    font-weight: 500;
}

.cat-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table th {
    text-align: left;
    padding: 0.75rem 0.85rem;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 0.85rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--bg-subtle);
}

.text-right {
    text-align: right !important;
}

/* Forms & Filters */
.filter-bar {
    display: grid;
    grid-template-columns: 1.5fr repeat(4, 1fr) auto;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.95rem;
}

.filter-bar .form-group {
    margin-bottom: 0;
}

.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

/* Progress Bars */
.progress-track {
    width: 100%;
    height: 9px;
    background: var(--bg-subtle);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

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

/* Flash Alerts */
.flash-stack {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
}

.flash {
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid transparent;
}

.flash-success {
    background: var(--income-soft);
    color: var(--income);
    border-color: rgba(16, 185, 129, 0.25);
}

.flash-error {
    background: var(--expense-soft);
    color: var(--expense);
    border-color: rgba(239, 68, 68, 0.25);
}

/* Modals */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(3px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-backdrop.open {
    display: flex;
}

.modal-dialog {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.15rem;
}

.modal-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
}

.type-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
    background: var(--bg-subtle);
    padding: 0.3rem;
    border-radius: 11px;
    margin-bottom: 1.1rem;
    border: 1px solid var(--border-color);
}

.type-tab {
    padding: 0.5rem;
    text-align: center;
    font-size: 0.84rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-muted);
    transition: all 0.15s;
}

.type-tab.active[data-type="expense"] {
    background: var(--expense);
    color: #fff;
}

.type-tab.active[data-type="income"] {
    background: var(--income);
    color: #fff;
}

.type-tab.active[data-type="transfer"] {
    background: var(--info);
    color: #fff;
}

/* Charts */
.chart-box {
    position: relative;
    width: 100%;
    min-height: 250px;
}

.donut-layout {
    display: grid;
    grid-template-columns: 190px 1fr;
    gap: 1.1rem;
    align-items: center;
}

.legend-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    max-height: 230px;
    overflow-y: auto;
}

.legend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.82rem;
    gap: 0.5rem;
}

.empty-state {
    text-align: center;
    padding: 2.25rem 1rem;
    color: var(--text-muted);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 35;
}

/* Responsive */
@media (max-width: 1100px) {
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .grid-2, .grid-equal {
        grid-template-columns: 1fr;
    }
    .filter-bar {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 820px) {
    .auth-page {
        grid-template-columns: 1fr;
    }
    .auth-hero {
        display: none;
    }
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.open {
        display: block;
    }
    .main-area {
        margin-left: 0;
    }
    .mobile-menu-btn {
        display: inline-flex;
    }
    .content-container {
        padding: 1.15rem;
    }
    .donut-layout {
        grid-template-columns: 1fr;
        justify-items: center;
    }
}

@media (max-width: 540px) {
    .kpi-grid, .form-row, .filter-bar {
        grid-template-columns: 1fr;
    }
}

@media print {
    .sidebar, .topbar, .no-print {
        display: none !important;
    }
    .main-area {
        margin-left: 0 !important;
    }
    body {
        background: #fff !important;
        color: #000 !important;
    }
    .card {
        box-shadow: none !important;
        border: 1px solid #cbd5e1 !important;
        break-inside: avoid;
    }
}
