/* CSS Variables */
:root {
    --bg: #f7f6f3;
    --surface: #ffffff;
    --border: #e8e5df;
    --text: #1a1916;
    --muted: #7a7670;
    --income: #2d6a4f;
    --expense: #c0392b;
    --accent: #52b788;
    --font-body: 'DM Sans', sans-serif;
    --font-mono: 'DM Mono', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg);
    color: var(--text);
    font-size: 14px;
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

h1,
h2,
h3 {
    font-weight: 600;
}

/* Layout */
.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    padding: 24px;
    z-index: 10;
}

.main-content {
    margin-left: 220px;
    flex: 1;
    padding: 24px;
    min-height: 100vh;
    width: calc(100% - 220px);
}

.topbar {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

/* Sidebar */
.logo {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 40px;
    color: var(--accent);
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.nav-link {
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--muted);
    text-decoration: none;
    display: block;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-link:hover {
    background: var(--bg);
    color: var(--text);
}

.nav-link.active {
    background: var(--accent);
    color: white;
}

.sidebar-balance {
    margin-top: auto;
    padding: 16px;
    background: var(--bg);
    border-radius: 12px;
}

.sidebar-balance .label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.sidebar-balance .amount {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 600;
}

.sidebar-balance.positive .amount {
    color: var(--income);
}

.sidebar-balance.negative .amount {
    color: var(--expense);
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
    margin-bottom: 24px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

.stat-card .label {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-card .amount {
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 600;
}

.stat-card.income .amount {
    color: var(--income);
}

.stat-card.expense .amount {
    color: var(--expense);
}

/* Pages */
.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tables */
.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-weight: 500;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: rgba(0, 0, 0, 0.01);
}

.amount-cell {
    font-family: var(--font-mono);
    font-weight: 500;
    text-align: right;
}

.amount-cell.income {
    color: var(--income);
}

.amount-cell.expense {
    color: var(--expense);
}

th.right-align {
    text-align: right;
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
}

.badge.cat-salary {
    background: #d6ffd6;
    color: #006600;
}

.badge.cat-freelance {
    background: #d6ffeb;
    color: #006644;
}

.badge.cat-business {
    background: #e6e6fa;
    color: #4b0082;
}

.badge.cat-investment {
    background: #d6e2ff;
    color: #0033b0;
}

.badge.cat-gift {
    background: #ffd6eb;
    color: #b0006a;
}

.badge.cat-food {
    background: #ffe8d6;
    color: #b05c00;
}

.badge.cat-travel {
    background: #d6e2ff;
    color: #0033b0;
}

.badge.cat-shopping {
    background: #ebd6ff;
    color: #6a00b0;
}

.badge.cat-bills {
    background: #ffd6d6;
    color: #b00000;
}

.badge.cat-health {
    background: #ffd6eb;
    color: #b0006a;
}

.badge.cat-education {
    background: #d6ffeb;
    color: #008055;
}

.badge.cat-entertainment {
    background: #fff0d6;
    color: #8a6300;
}

.badge.cat-other {
    background: #e8e8e8;
    color: #404040;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 13px;
    color: var(--muted);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: all 0.2s;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(82, 183, 136, 0.15);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-danger {
    background: #ffebee;
    color: var(--expense);
    padding: 8px 16px;
    font-size: 13px;
    border: 1px solid #ffcdd2;
}

.btn-danger:hover {
    background: var(--expense);
    color: white;
}

.type-toggle {
    display: flex;
    background: var(--bg);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 24px;
    width: fit-content;
}

.type-toggle-btn {
    padding: 10px 24px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
    font-family: var(--font-body);
    transition: all 0.2s;
}

.type-toggle-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Filters */
.filters {
    display: flex;
    gap: 16px;
    margin-bottom: 0;
    flex-wrap: wrap;
}

.filters .form-control {
    width: auto;
    min-width: 160px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.empty-state-icon {
    font-size: 48px;
    opacity: 0.5;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #2d3436;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    opacity: 0;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Charts */
.reports-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

/* Donut Chart */
.donut-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 250px;
    position: relative;
}

.donut-legend {
    position: absolute;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 4px;
}

/* Horizontal Bar Chart */
.bar-chart-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 10px 0;
}

.bar-wrapper-horizontal {
    display: flex;
    align-items: center;
    gap: 16px;
}

.bar-label-horiz {
    width: 100px;
    font-size: 13px;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.bar-track {
    flex: 1;
    background: var(--bg);
    height: 28px;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: 0%;
    display: flex;
    align-items: center;
    padding: 0 12px;
    color: white;
    font-size: 12px;
    font-family: var(--font-mono);
    font-weight: 500;
    justify-content: flex-end;
    min-width: 10%;
}

/* AI Chat */
.chat-btn {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(82, 183, 136, 0.4);
    z-index: 100;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(82, 183, 136, 0.5);
}

.chat-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    max-width: 100vw;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.08);
    z-index: 99;
    transition: right 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.chat-panel.open {
    right: 0;
}

.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fcfbf9;
}

.chat-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 16px;
}

.close-chat {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--muted);
    transition: color 0.2s;
}

.close-chat:hover {
    color: var(--text);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
}

.message.user {
    background: var(--accent);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.ai {
    background: var(--bg);
    color: var(--text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    background: #fcfbf9;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    outline: none;
    font-family: var(--font-body);
    font-size: 14px;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--accent);
}

.chat-send {
    background: var(--accent);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chat-send:hover {
    background: #40916c;
}

.typing-indicator {
    display: none;
    align-self: flex-start;
    background: var(--bg);
    padding: 14px 18px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}

.typing-indicator.show {
    display: flex;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
    animation-delay: -0.32s;
}

.dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Auth Pages */
.auth-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f7f6f3;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.auth-card {
    background: white;
    width: 420px;
    max-width: 90%;
    padding: 40px;
    border-radius: 16px;
    border: 1px solid #e8e5df;
    box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}

.auth-header h2 {
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    margin-top: 12px;
}

.auth-header p {
    font-size: 14px;
    color: #7a7670;
    text-align: center;
    margin-bottom: 32px;
}

.auth-card .form-group label {
    font-size: 12px;
    font-weight: 500;
    color: #7a7670;
    margin-bottom: 6px;
    display: block;
}

.auth-card .form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e8e5df;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}

.auth-card .form-control:focus {
    border-color: #52b788;
    box-shadow: 0 0 0 3px rgba(82,183,136,0.15);
}

.auth-card .btn-primary {
    width: 100%;
    padding: 13px;
    background: #2d6a4f;
    color: white;
    border-radius: 8px;
    border: none;
    font-size: 15px;
    font-weight: 600;
    margin-top: 8px;
}

.auth-card .btn-primary:hover {
    background: #235a40;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
}

.auth-footer a {
    font-size: 14px;
    color: #2d6a4f;
    font-weight: 500;
    text-decoration: none;
}

.error-msg {
    color: #c0392b;
    font-size: 13px;
    background: #fdf0ef;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    border-left: 3px solid #c0392b;
    display: none;
}

.error-msg.show {
    display: block;
}

/* Receipt Scanner styles */
.receipt-scanner .scan-btn {
    width: 100%;
    height: 80px;
    background: #f7f6f3;
    border: 2px dashed #e8e5df;
    color: #7a7670;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    border-radius: 8px;
    transition: all 0.2s;
}

.receipt-scanner .scan-btn:hover {
    background: #f0efeb;
    border-color: #52b788;
    color: #2d6a4f;
}

/* Responsive */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text);
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
        width: 260px;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.05);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 16px;
    }

    .stats-grid,
    .reports-grid {
        grid-template-columns: 1fr;
    }

    .mobile-menu-btn {
        display: block;
    }

    .filters {
        flex-direction: column;
    }

    .filters .form-control {
        width: 100%;
    }

    .chat-panel {
        width: 100%;
        right: -100%;
    }

    .chat-btn {
        bottom: 20px;
        right: 20px;
    }
}

/* --- NEW FEATURES CSS --- */
/* Google Auth */
.google-btn {
    width: 100%;
    padding: 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-top: 12px;
}
.google-btn:hover {
    background: #f5f5f5;
    border-color: #ccc;
}
.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
    color: var(--muted);
    font-size: 13px;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Pagination & Edit */
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding: 0 16px;
}
.page-info {
    color: var(--muted);
    font-size: 13px;
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 8px 16px;
}
.btn-outline:hover {
    background: var(--accent);
    color: white;
}
.btn-outline[disabled] {
    border-color: var(--border);
    color: var(--muted);
    background: #f5f5f5;
    cursor: not-allowed;
}
.btn-next {
    background: var(--accent);
    color: white;
}
.btn-next[disabled] {
    background: #f5f5f5;
    color: var(--muted);
    cursor: not-allowed;
}

/* Modal */
#edit-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
}
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-box {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}
.modal-box h3 {
    margin-bottom: 20px;
}

/* Reports / Donut */
.donut-center-text {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.donut-center-text .income-text {
    color: var(--income);
    font-weight: 600;
    font-family: var(--font-mono);
}
.donut-center-text .vs-text {
    color: var(--muted);
    font-size: 12px;
    margin: 2px 0;
}
.donut-center-text .expense-text {
    color: var(--expense);
    font-weight: 600;
    font-family: var(--font-mono);
}
.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.dot.income { background: var(--income); }
.dot.expense { background: var(--expense); }
.legend-amount {
    font-family: var(--font-mono);
    font-weight: 600;
    margin-left: auto;
    padding-left: 16px;
}
.legend-amount.income { color: var(--income); }
.legend-amount.expense { color: var(--expense); }

/* Table Alternate row */
#breakdown-tbody tr:nth-child(even) td {
    background-color: rgba(0,0,0,0.02);
}
#breakdown-tfoot td {
    background: var(--bg);
    font-weight: 600;
}