/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 主题色 */
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    
    /* 分类颜色 */
    --food: #FF6B6B;
    --transport: #4ECDC4;
    --shopping: #45B7D1;
    --entertainment: #96CEB4;
    --housing: #feca57;
    --medical: #DDA0DD;
    --education: #98D8C8;
    --other: #B8B8B8;
    
    /* 背景色 */
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --hover-bg: #f1f5f9;
    
    /* 文字色 */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    /* 边框和阴影 */
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* 圆角 */
    --radius-sm: 8px;
    --radius: 16px;
    --radius-lg: 24px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
    padding: 20px;
}

/* 应用容器 */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
}

/* 头部 */
.header {
    text-align: center;
    padding: 30px 0;
    color: white;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.subtitle {
    font-size: 1rem;
    opacity: 0.9;
}

/* 统计卡片 */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.stat-card.total .stat-icon {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-card.count .stat-icon {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* 卡片通用样式 */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
}

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

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.badge {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* 主内容区 */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* 图表区域 */
.chart-section {
    display: flex;
    flex-direction: column;
}

.chart-container {
    position: relative;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#expenseChart {
    max-height: 100%;
}

.empty-state {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.9rem;
}

/* 图例 */
.chart-legend {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--hover-bg);
    transition: all 0.2s ease;
}

.legend-item:hover {
    background: var(--border);
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.legend-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.legend-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.legend-value {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-percent {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary);
}

/* 表单区域 */
.form-section {
    background: var(--card-bg);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.amount-input {
    position: relative;
    display: flex;
    align-items: center;
}

.currency {
    position: absolute;
    left: 16px;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-secondary);
}

input[type="number"],
input[type="date"],
input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: all 0.2s ease;
    background: var(--bg);
}

input[type="number"] {
    padding-left: 40px;
    font-size: 1.25rem;
    font-weight: 600;
}

input:focus {
    outline: none;
    border-color: var(--primary-light);
    background: white;
}

/* 分类选择网格 */
.category-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.category-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.category-btn:hover {
    border-color: var(--primary-light);
    transform: translateY(-2px);
}

.category-btn.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(79, 70, 229, 0.1) 100%);
}

.cat-icon {
    font-size: 1.5rem;
}

.category-btn span:last-child {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.category-btn.active span:last-child {
    color: var(--primary);
    font-weight: 600;
}

@media (max-width: 600px) {
    .category-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* 提交按钮 */
.submit-btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.39);
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px 0 rgba(99, 102, 241, 0.5);
}

.submit-btn:active {
    transform: translateY(0);
}

/* 记录列表 */
.records-section {
    background: var(--card-bg);
}

.clear-btn {
    padding: 6px 14px;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    background: #fef2f2;
    color: #ef4444;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-btn:hover {
    background: #fee2e2;
}

.records-list {
    max-height: 400px;
    overflow-y: auto;
}

.record-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border);
}

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

.record-item:hover {
    background: var(--hover-bg);
}

.record-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

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

.record-category {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.record-note {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.record-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.record-amount {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.record-delete {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0;
}

.record-item:hover .record-delete {
    opacity: 1;
}

.record-delete:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* 空状态 */
.empty-records {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-records .empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.empty-records p {
    font-size: 1rem;
}

/* 滚动条样式 */
.records-list::-webkit-scrollbar {
    width: 6px;
}

.records-list::-webkit-scrollbar-track {
    background: var(--hover-bg);
    border-radius: 3px;
}

.records-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.records-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* 动画 */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.record-item {
    animation: slideIn 0.3s ease;
}

/* 响应式调整 */
@media (max-width: 600px) {
    body {
        padding: 12px;
    }
    
    .header h1 {
        font-size: 1.75rem;
    }
    
    .card {
        padding: 20px;
    }
    
    .stat-card {
        padding: 16px;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .chart-legend {
        grid-template-columns: 1fr;
    }
    
    .category-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .category-btn {
        padding: 10px 4px;
    }
    
    .cat-icon {
        font-size: 1.25rem;
    }
    
    .category-btn span:last-child {
        font-size: 0.7rem;
    }
    
    .record-delete {
        opacity: 1;
    }
}
