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

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --pink-color: #ec4899;
    --pink-light: #fce7f3;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* 头部 */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-color);
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* 按钮样式 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

.btn-secondary {
    background-color: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--bg-color);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

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

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
}

.btn-icon:hover {
    background-color: var(--bg-color);
}

/* 统计概览 - 3列 */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 480px) {
    .stats-overview {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
}

.stat-card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* 添加习惯 */
.add-habit {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.add-habit input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.2s ease;
}

.add-habit input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.add-habit .btn {
    padding: 12px 24px;
}

/* 习惯列表 - 小方格网格布局 */
.habits-section {
    margin-bottom: 32px;
}

.habits-section h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-color);
}

.habits-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    background-color: var(--card-bg);
    border-radius: 12px;
    border: 2px dashed var(--border-color);
    width: 100%;
}

/* 习惯小方格 */
.habit-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: var(--card-bg);
    border-radius: 20px;
    padding: 8px 14px;
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
    border: 2px solid transparent;
    cursor: pointer;
    user-select: none;
}

.habit-chip:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.habit-chip.checked {
    background-color: var(--pink-light);
}

.habit-chip.selected {
    transform: translateY(-2px);
}

/* 习惯颜色点 */
.habit-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.habit-chip .habit-name {
    font-size: 14px;
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.habit-chip .habit-streak {
    font-size: 11px;
    color: var(--text-secondary);
    background-color: var(--bg-color);
    padding: 2px 6px;
    border-radius: 10px;
}

.habit-chip.checked .habit-streak {
    background-color: white;
    color: var(--pink-color);
}

.habit-chip .edit-icon {
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity 0.2s;
}

.habit-chip:hover .edit-icon {
    opacity: 1;
}

/* 日历视图 */
.calendar-section {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

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

.calendar-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.calendar-tip {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 12px;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 8px;
}

.calendar-weekdays span {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px 0;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background-color: var(--bg-color);
    position: relative;
    cursor: pointer;
    transition: all 0.15s ease;
}

.calendar-cell:not(.empty):hover {
    background-color: #e2e8f0;
    transform: scale(1.05);
}

.calendar-cell.empty {
    background-color: transparent;
    cursor: default;
}

.calendar-cell.today {
    border: 2px solid var(--primary-color);
}

.calendar-cell.checked {
    background-color: var(--pink-light);
}

.day-number {
    font-size: 14px;
    font-weight: 500;
}

/* 爱心容器 - 并排显示 */
.hearts-container {
    display: flex;
    justify-content: center;
    gap: 1px;
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
}

.heart-icon {
    font-size: 10px;
    animation: heartPop 0.3s ease;
    line-height: 1;
}

/* 爱心数量适配 */
.hearts-container .heart-icon:nth-child(n+4) {
    font-size: 8px;
}

@keyframes heartPop {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* 饼图区域 */
.chart-section {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
}

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

.chart-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
}

.chart-habit-name {
    font-size: 14px;
    color: var(--pink-color);
    font-weight: 500;
    padding: 4px 10px;
    background: var(--pink-light);
    border-radius: 12px;
}

.chart-tip {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.chart-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

#pieChart {
    max-width: 200px;
    max-height: 200px;
}

.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

.legend-label {
    color: var(--text-color);
}

.legend-value {
    color: var(--text-secondary);
    margin-left: auto;
}

/* 弹窗 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

.modal-content input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 16px;
    margin-bottom: 16px;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* 响应式 */
@media (max-width: 480px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .add-habit {
        flex-direction: column;
    }

    .add-habit .btn {
        width: 100%;
    }

    .chart-container {
        flex-direction: column;
    }

    .stat-value {
        font-size: 22px;
    }

    .stat-label {
        font-size: 11px;
    }
}

/* 年度总结 */
.year-summary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px;
    padding: 24px;
    margin-top: 24px;
    color: white;
}

.year-summary h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
}

.summary-content h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    opacity: 0.9;
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.summary-stat {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.summary-value {
    display: block;
    font-size: 32px;
    font-weight: 700;
}

.summary-label {
    display: block;
    font-size: 13px;
    opacity: 0.8;
    margin-top: 4px;
}

/* 热力图 */
.heatmap-section {
    margin-bottom: 24px;
}

.heatmap-months {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    opacity: 0.7;
    margin-bottom: 8px;
    padding: 0 2px;
}

.year-heatmap {
    display: grid;
    grid-template-columns: repeat(53, 1fr);
    grid-template-rows: repeat(7, 1fr);
    gap: 2px;
}

.heatmap-cell {
    aspect-ratio: 1;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
}

.heatmap-cell.level-1 { background: rgba(236, 72, 153, 0.3); }
.heatmap-cell.level-2 { background: rgba(236, 72, 153, 0.5); }
.heatmap-cell.level-3 { background: rgba(236, 72, 153, 0.7); }
.heatmap-cell.level-4 { background: rgba(236, 72, 153, 1); }

/* 习惯排行榜 */
.ranking-section {
    margin-bottom: 24px;
}

.habit-ranking {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ranking-position {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.ranking-position.gold { background: #fbbf24; color: #92400e; }
.ranking-position.silver { background: #d1d5db; color: #374151; }
.ranking-position.bronze { background: #f59e0b; color: #78350f; }

.ranking-name {
    flex: 1;
    font-size: 14px;
}

.ranking-bar {
    flex: 2;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

.ranking-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.ranking-value {
    font-size: 13px;
    font-weight: 600;
    min-width: 50px;
    text-align: right;
}

/* 月度趋势 */
.trend-section {
    margin-bottom: 8px;
}

.monthly-trend {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 100px;
    gap: 4px;
}

.trend-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.trend-bar-fill {
    width: 100%;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 4px 4px 0 0;
    transition: height 0.5s ease;
    min-height: 4px;
}

.trend-label {
    font-size: 10px;
    opacity: 0.7;
}

/* 响应式 - 年度总结 */
@media (max-width: 600px) {
    .summary-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .summary-value {
        font-size: 24px;
    }

    .year-heatmap {
        gap: 1px;
    }

    .heatmap-months {
        font-size: 9px;
    }

    .ranking-bar {
        display: none;
    }
}
