/* ============= 重置与基础 ============= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #4A6CF7;
    --primary-light: #EEF1FE;
    --primary-dark: #3858E8;
    --income: #FF6B6B;
    --income-light: #FFE8E8;
    --expense: #4ECDC4;
    --expense-light: #E0F7F5;
    --bg: #F7F8FC;
    --card-bg: #FFFFFF;
    --text: #1A1F36;
    --text-secondary: #6B7588;
    --text-tertiary: #9CA3B5;
    --border: #EEF1F6;
    --shadow: 0 4px 16px rgba(74, 108, 247, 0.08);
    --radius: 16px;
    --radius-sm: 10px;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    user-select: none;
    -webkit-user-select: none;
}

.app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    background: var(--bg);
}

/* ============= 顶部月份切换 ============= */
.header {
    background: var(--card-bg);
    padding: 12px 16px 14px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    padding-top: max(12px, env(safe-area-inset-top));
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.month-display {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    text-align: center;
}

.month-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.month-btn:active {
    transform: scale(0.92);
    background: var(--primary);
    color: white;
}

/* ============= 主内容 ============= */
.main {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 80px;
}

.view {
    display: none;
    padding: 16px;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============= 结余卡片 ============= */
.balance-card {
    background: linear-gradient(135deg, #4A6CF7 0%, #6B8DF5 100%);
    border-radius: 20px;
    padding: 24px 20px;
    color: white;
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(74, 108, 247, 0.25);
}

.balance-bg {
    position: absolute;
    top: -40px;
    right: -40px;
    width: 160px;
    height: 160px;
    background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 70%);
    border-radius: 50%;
}

.balance-content {
    position: relative;
    z-index: 1;
}

.balance-label {
    font-size: 13px;
    opacity: 0.9;
    margin-bottom: 6px;
}

.balance-amount {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: -0.5px;
}

.balance-stats {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 12px 16px;
    backdrop-filter: blur(10px);
}

.stat-item {
    flex: 1;
    text-align: center;
}

.stat-label {
    font-size: 12px;
    opacity: 0.9;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 17px;
    font-weight: 600;
}

.stat-divider {
    width: 1px;
    height: 30px;
    background: rgba(255, 255, 255, 0.3);
}

/* ============= 通用卡片 ============= */
.section-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

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

.section-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.section-tag {
    font-size: 12px;
    color: var(--text-tertiary);
    background: var(--bg);
    padding: 3px 8px;
    border-radius: 10px;
}

/* ============= 分类图表 ============= */
.category-chart {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.category-bar-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.category-bar-icon {
    font-size: 18px;
    width: 28px;
    text-align: center;
}

.category-bar-content {
    flex: 1;
}

.category-bar-top {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 4px;
}

.category-bar-name {
    color: var(--text);
}

.category-bar-amount {
    color: var(--text-secondary);
    font-weight: 500;
}

.category-bar-bg {
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
}

.category-bar-fill {
    height: 100%;
    background: var(--income);
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* ============= 记录列表 ============= */
.record-list, .record-list-full {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.record-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: opacity 0.2s;
}

.record-item:last-child {
    border-bottom: none;
}

.record-item:active {
    opacity: 0.6;
}

.record-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-right: 12px;
    flex-shrink: 0;
}

.record-icon.income {
    background: var(--income-light);
}

.record-icon.expense {
    background: var(--expense-light);
}

.record-info {
    flex: 1;
    min-width: 0;
}

.record-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.record-date {
    font-size: 12px;
    color: var(--text-tertiary);
}

.record-amount {
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
}

.record-amount.income {
    color: var(--income);
}

.record-amount.expense {
    color: var(--text);
}

/* ============= 空状态 ============= */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-tertiary);
}

.empty-icon {
    font-size: 36px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.empty-text {
    font-size: 13px;
}

/* ============= 筛选栏 ============= */
.filter-bar {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.filter-tabs {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 10px;
}

.filter-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.filter-tab.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.filter-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter-cat-chip {
    padding: 5px 10px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: 14px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.filter-cat-chip.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* ============= 统计页 ============= */
.stats-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.stats-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.stats-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.stats-value {
    font-size: 22px;
    font-weight: 700;
}

.rank-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rank-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rank-index {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.rank-index.top {
    background: var(--income);
    color: white;
}

.daily-trend {
    display: flex;
    align-items: flex-end;
    height: 140px;
    gap: 3px;
    padding-top: 10px;
}

.daily-bar {
    flex: 1;
    background: linear-gradient(180deg, var(--primary) 0%, #8DA5F8 100%);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    position: relative;
    transition: height 0.5s ease;
}

.daily-bar:hover::after {
    content: attr(data-tip);
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
}

/* ============= 设置 ============= */
.settings-header {
    padding: 4px 4px 16px;
}

.settings-header h2 {
    font-size: 24px;
    font-weight: 700;
}

.settings-list {
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.settings-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.settings-item:last-of-type {
    border-bottom: none;
}

.settings-item:active {
    background: var(--bg);
}

.settings-item.danger .settings-title {
    color: var(--income);
}

.settings-icon {
    font-size: 22px;
    margin-right: 12px;
    width: 30px;
    text-align: center;
}

.settings-info {
    flex: 1;
}

.settings-title {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 2px;
}

.settings-desc {
    font-size: 12px;
    color: var(--text-tertiary);
}

.settings-arrow {
    color: var(--text-tertiary);
    font-size: 20px;
}

.settings-about {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 12px;
}

.settings-about p.muted {
    font-size: 11px;
    margin-top: 4px;
}

/* ============= 底部 Tab ============= */
.tab-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
    z-index: 50;
}

.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 0;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.2s;
}

.tab-item.active {
    color: var(--primary);
}

.tab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-label {
    font-size: 10px;
    font-weight: 500;
}

.tab-add {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    margin: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(74, 108, 247, 0.4);
    transition: transform 0.2s;
    margin-top: -20px;
}

.tab-add:active {
    transform: scale(0.92);
}

/* ============= 模态弹层 ============= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 100;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--card-bg);
    width: 100%;
    max-width: 480px;
    max-height: 92vh;
    border-radius: 24px 24px 0 0;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    padding-bottom: 240px;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

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

.modal-header h2 {
    font-size: 17px;
    font-weight: 600;
    flex: 1;
    text-align: center;
}

.modal-close, .modal-action {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:active, .modal-action:active {
    background: var(--border);
}

/* 类型切换 */
.type-switch {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
}

.type-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.type-btn.active {
    background: var(--card-bg);
    color: var(--text);
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.type-btn.expense-type.active {
    color: var(--text);
}

.type-btn.income-type.active {
    color: var(--income);
}

/* 金额输入 */
.amount-input-wrap {
    display: flex;
    align-items: baseline;
    justify-content: center;
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.amount-symbol {
    font-size: 22px;
    color: var(--text-secondary);
    margin-right: 6px;
}

.amount-input {
    border: none;
    background: transparent;
    font-size: 32px;
    font-weight: 700;
    color: var(--text);
    text-align: center;
    outline: none;
    width: 70%;
    letter-spacing: -0.5px;
}

.amount-input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

/* 分类 */
.category-section {
    margin-bottom: 16px;
}

.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;
    background: var(--bg);
    border-radius: 12px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.category-item.active {
    background: var(--primary-light);
    border-color: var(--primary);
}

.category-item-icon {
    font-size: 22px;
}

.category-item-name {
    font-size: 11px;
    color: var(--text-secondary);
}

.category-item.active .category-item-name {
    color: var(--primary);
    font-weight: 600;
}

/* 备注 */
.note-section {
    margin-bottom: 16px;
}

.note-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    font-size: 14px;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.note-input:focus {
    border-color: var(--primary);
}

/* 日期 */
.date-section {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    background: var(--bg);
    border-radius: 12px;
    margin-bottom: 16px;
    gap: 8px;
}

.date-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.date-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--text);
    outline: none;
    text-align: right;
}

/* 保存按钮 */
.save-btn {
    width: 100%;
    padding: 14px;
    border: none;
    background: var(--primary);
    color: white;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(74, 108, 247, 0.3);
}

.save-btn:active {
    transform: scale(0.98);
    background: var(--primary-dark);
}

.save-btn:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
    box-shadow: none;
}

/* ============= 数字键盘 ============= */
.keypad {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    padding: 8px 4px 8px;
    border-top: 1px solid var(--border);
    display: none;
    z-index: 5;
    max-width: 480px;
    margin: 0 auto;
}

.keypad.active {
    display: block;
    animation: slideUp 0.25s ease;
}

.keypad-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 4px;
}

.key {
    padding: 14px 0;
    border: none;
    background: var(--bg);
    border-radius: 10px;
    font-size: 20px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all 0.1s;
}

.key:active {
    background: var(--border);
    transform: scale(0.96);
}

.key.key-action {
    background: #E8ECF7;
    color: var(--text-secondary);
}

.key.key-confirm {
    background: var(--primary);
    color: white;
    font-size: 22px;
}

.key.key-confirm:active {
    background: var(--primary-dark);
}

/* ============= Toast ============= */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.toast.show {
    opacity: 1;
}

/* ============= 小屏适配 ============= */
@media (max-width: 360px) {
    .balance-amount { font-size: 30px; }
    .stats-value { font-size: 18px; }
    .record-amount { font-size: 14px; }
    .category-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .category-item-name { font-size: 10px; }
}
