* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4F46E5;
    --primary-light: #818CF8;
    --primary-dark: #3730A3;
    --income: #10B981;
    --income-light: #D1FAE5;
    --expense: #EF4444;
    --expense-light: #FEE2E2;
    --bg: #F3F4F6;
    --card-bg: #FFFFFF;
    --text: #1F2937;
    --text-secondary: #6B7280;
    --text-light: #9CA3AF;
    --border: #E5E7EB;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
    --radius: 16px;
    --radius-sm: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* Pages */
.page {
    display: none;
    padding: 0 16px 100px;
    animation: fadeIn 0.3s ease;
}
.page.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0 12px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}
.header h1 {
    font-size: 24px;
    font-weight: 700;
}

/* Month Selector */
.month-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-bg);
    padding: 6px 12px;
    border-radius: 20px;
    box-shadow: var(--shadow);
}
.month-selector span {
    font-size: 14px;
    font-weight: 600;
    min-width: 80px;
    text-align: center;
}
.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}
.icon-btn:active { background: var(--border); }

/* Balance Card */
.balance-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: var(--radius);
    padding: 24px;
    color: white;
    margin-bottom: 20px;
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.3);
}
.balance-label {
    font-size: 14px;
    opacity: 0.85;
    margin-bottom: 8px;
}
.balance-amount {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: -1px;
}
.balance-details {
    display: flex;
    gap: 24px;
}
.income-summary, .expense-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.income-dot { background: #6EE7B7; }
.expense-dot { background: #FCA5A5; }

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.section-header h2 {
    font-size: 18px;
    font-weight: 600;
}
.record-count {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Transaction List */
.transaction-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.transaction-item {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.transaction-item:active {
    transform: scale(0.98);
}
.transaction-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-right: 12px;
    flex-shrink: 0;
}
.transaction-icon.expense { background: var(--expense-light); }
.transaction-icon.income { background: var(--income-light); }

.transaction-info {
    flex: 1;
    min-width: 0;
}
.transaction-category {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
}
.transaction-note {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.transaction-right {
    text-align: right;
    flex-shrink: 0;
    margin-left: 8px;
}
.transaction-amount {
    font-size: 16px;
    font-weight: 700;
}
.transaction-amount.expense { color: var(--expense); }
.transaction-amount.income { color: var(--income); }
.transaction-date {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 2px;
}

/* Date Group */
.date-group {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px 0 4px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}
.empty-state p {
    font-size: 14px;
    text-align: center;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    background: var(--card-bg);
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    z-index: 100;
}
.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 12px;
    color: var(--text-light);
    transition: color 0.2s;
}
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 500; }

.nav-spacer { display: none; }

/* Add Button */
.add-btn {
    position: relative;
    top: -20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.4);
    transition: transform 0.2s;
}
.add-btn:active { transform: scale(0.9); }
.add-icon {
    font-size: 28px;
    font-weight: 300;
    line-height: 1;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
    animation: overlayIn 0.2s ease;
}
.modal-overlay.active { display: flex; }

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--card-bg);
    border-radius: 24px 24px 0 0;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.modal-header h3 {
    font-size: 20px;
    font-weight: 700;
}
.close-btn {
    background: var(--bg);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

/* Type Toggle */
.type-toggle {
    display: flex;
    background: var(--bg);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 20px;
}
.type-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.2s;
}
.type-btn.active {
    background: var(--card-bg);
    color: var(--text);
    box-shadow: var(--shadow);
}
.type-btn.active[data-type="expense"] { color: var(--expense); }
.type-btn.active[data-type="income"] { color: var(--income); }

/* Form */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.amount-input {
    display: flex;
    align-items: center;
    background: var(--bg);
    border-radius: 12px;
    padding: 4px 16px;
}
.currency {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-right: 4px;
}
.amount-input input {
    flex: 1;
    border: none;
    background: none;
    font-size: 28px;
    font-weight: 700;
    padding: 10px 0;
    outline: none;
    color: var(--text);
    width: 100%;
}
.form-group input[type="text"],
.form-group input[type="date"] {
    width: 100%;
    border: none;
    background: var(--bg);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 15px;
    outline: none;
    color: var(--text);
}

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.category-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px;
    border-radius: 12px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg);
}
.category-item:active { transform: scale(0.95); }
.category-item.selected {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.08);
}
.category-emoji { font-size: 24px; }
.category-name {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Submit Button */
.submit-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    transition: transform 0.2s;
}
.submit-btn:active { transform: scale(0.98); }

/* Delete Modal */
.delete-modal {
    border-radius: 20px;
    max-width: 320px;
    margin: auto;
    text-align: center;
}
.delete-text {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}
.delete-actions {
    display: flex;
    gap: 12px;
}
.cancel-btn, .confirm-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.cancel-btn {
    background: var(--bg);
    color: var(--text);
}
.confirm-btn {
    background: var(--expense);
    color: white;
}

/* Stats Page */
.stats-tabs {
    display: flex;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.stats-tab {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.2s;
}
.stats-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.chart-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
}
#pie-chart {
    width: 200px;
    height: 200px;
}
.chart-total {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 16px;
}
#chart-total-label {
    font-size: 13px;
    color: var(--text-secondary);
}
#chart-total-amount {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

/* Category Stats List */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.category-stat-item {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.cat-stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-right: 12px;
    background: var(--bg);
}
.cat-stat-info { flex: 1; }
.cat-stat-name {
    font-size: 14px;
    font-weight: 600;
}
.cat-stat-bar {
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}
.cat-stat-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
}
.cat-stat-bar-fill.expense { background: var(--expense); }
.cat-stat-bar-fill.income { background: var(--income); }
.cat-stat-amount {
    font-size: 15px;
    font-weight: 700;
    margin-left: 8px;
}
.cat-stat-percent {
    font-size: 11px;
    color: var(--text-light);
    text-align: right;
}

/* Settings */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.settings-item {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}
.settings-item:active { background: var(--bg); }
.settings-icon {
    font-size: 20px;
    margin-right: 12px;
}
.settings-label {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
}
.settings-arrow {
    color: var(--text-light);
    font-size: 18px;
}
.settings-value {
    color: var(--text-light);
    font-size: 14px;
}

/* Swipe hint */
.swipe-hint {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 72px;
    background: var(--expense);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 13px;
    font-weight: 600;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 999;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2s forwards;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; pointer-events: none; }
}
