/* ==========================================
   MODULE 1: 基础变量与重置
   ========================================== */

:root {
    --bg-body: #f5f5f7;
    --bg-card: #ffffff;
    --bg-input: #eeeeef;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --text-danger: #ff3b30;
    --accent-color: #0071e3;
    --accent-active: #e8f2ff;
    --timer-active-bg: #000000;
    --timer-active-text: #ffffff;
    --border-radius: 12px;
    --padding-container: 20px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-body: #000000;
        --bg-card: #1c1c1e;
        --bg-input: #2c2c2e;
        --text-primary: #f5f5f7;
        --text-secondary: #86868b;
        --accent-color: #0a84ff;
        --accent-active: #1a2b3c;
        --timer-active-bg: #30d158;
        --timer-active-text: #000000;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    margin: 0; padding: 0;
    display: flex; flex-direction: column;
    height: 100vh; overflow: hidden;
    user-select: none; -webkit-user-select: none;
}

button, input, select { border: none; outline: none; background: none; font-family: inherit; }
button { cursor: pointer; }
input, select { color: var(--text-primary); }

/* ==========================================
   MODULE 2: 导航栏
   ========================================== */

.navbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px var(--padding-container);
    background: var(--bg-body); z-index: 10; position: relative; height: 40px;
}
.nav-placeholder, .btn-icon-small {
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.nav-center { display: flex; gap: 15px; flex: 1; justify-content: center; }
.nav-item {
    font-size: 15px; font-weight: 500; color: var(--text-secondary);
    padding: 6px 14px; border-radius: 18px; transition: all 0.2s; white-space: nowrap;
}
.nav-item.active {
    color: var(--text-primary); background-color: var(--bg-card);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.btn-icon-small { color: var(--text-primary); border-radius: 50%; opacity: 0.5; transition: opacity 0.2s; }
.btn-icon-small:hover { opacity: 1; background-color: var(--bg-input); }

/* ==========================================
   MODULE 3: 核心布局与通用组件
   ========================================== */

/* 视图容器基础 */
.view-section {
    display: none; flex: 1; flex-direction: column;
    padding: 0 var(--padding-container); overflow-y: auto;
    max-width: 600px; width: 100%; margin: 0 auto; box-sizing: border-box;
}
.view-section.active { display: flex; }

/* 通用卡片容器 */
/* 核心修正：align-items 设为 stretch，确保内部元素（如头部）能撑满宽度 */
.chart-card {
    background: var(--bg-card); padding: 20px; border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    display: flex; flex-direction: column; 
    align-items: stretch; 
}
.chart-card.no-padding { 
    padding: 0; 
    position: relative; 
    overflow: visible; /* 允许头部标签超出 */
    margin-top: 20px;
}

/* 头部通用样式 (用于统计卡片标题栏) */
/* 核心修正：强制左右对齐 */
.heatmap-header {
    display: flex;
    justify-content: space-between; 
    align-items: center;
    width: 100%;
    margin-bottom: 15px;
    flex-shrink: 0;
}
.heatmap-title {
    font-size: 16px; font-weight: bold; color: var(--text-primary);
    flex-shrink: 0;
}

/* 自定义下拉框 */
.custom-select-wrapper {
    position: relative; display: inline-block; flex-shrink: 0;
}
.custom-select-wrapper select {
    appearance: none; -webkit-appearance: none;
    background-color: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px; font-weight: 500;
    padding: 6px 24px 6px 12px;
    border-radius: 8px; cursor: pointer;
}
.custom-select-wrapper::after {
    content: ''; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    border: 4px solid transparent; border-top-color: var(--text-secondary); pointer-events: none;
}

/* ==========================================
   MODULE 4: 计时视图 (Timer)
   ========================================== */

.timer-container {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background-color: var(--bg-card); border-radius: var(--border-radius);
    padding: 30px 20px; margin-top: 10px; margin-bottom: 20px;
    transition: background-color 0.3s ease, transform 0.1s; cursor: pointer;
}
.timer-container.running { background-color: var(--timer-active-bg); color: var(--timer-active-text); }
.timer-container.reset-flash { opacity: 0.5; transform: scale(0.98); }
.timer-status { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; opacity: 0.7; margin-bottom: 5px; }
.timer-display { font-size: 56px; font-weight: 200; font-variant-numeric: tabular-nums; line-height: 1; margin-bottom: 5px; }
.timer-hint { font-size: 12px; opacity: 0.5; }

.input-area {
    display: flex; align-items: center; background-color: var(--bg-card);
    border-radius: var(--border-radius); padding: 8px 12px; margin-bottom: 25px;
}
#topicInput { flex: 1; font-size: 16px; padding: 8px; }
.btn-icon {
    color: var(--accent-color); padding: 8px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background-color: var(--accent-active); }

.projects-section { display: flex; flex-direction: column; flex: 1; }
.section-header { display: flex; align-items: center; margin-bottom: 10px; padding: 0 5px; width: 100%; box-sizing: border-box; }
.section-header span { flex: 1; font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.btn-text { flex-shrink: 0; font-size: 14px; color: var(--accent-color); font-weight: 500; padding: 5px 10px; }
.projects-grid-container { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding-bottom: 40px; }
.project-card {
    aspect-ratio: 1 / 1; background-color: var(--bg-card); border-radius: var(--border-radius);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; transition: transform 0.1s, background-color 0.2s; border: 2px solid transparent; position: relative; overflow: hidden;
}
.project-card:active { transform: scale(0.95); }
.project-card.active { border-color: var(--accent-color); background-color: var(--accent-active); }
.project-icon { font-size: 28px; margin-bottom: 5px; pointer-events: none; }
.project-name { font-size: 11px; font-weight: 500; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 90%; pointer-events: none; }

/* ==========================================
   MODULE 5: 记录视图 (Records)
   ========================================== */

.records-header-group { margin: 20px 0 15px 0; }
.records-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.records-stats { font-size: 18px; font-weight: 700; }
.btn-small { font-size: 12px; background: var(--bg-input); padding: 6px 12px; border-radius: 15px; color: var(--text-primary); }

.filter-group {
    display: flex; background: var(--bg-input); padding: 3px; border-radius: 10px; width: 100%; box-sizing: border-box;
}
.filter-btn {
    flex: 1; padding: 8px 0; font-size: 13px; color: var(--text-secondary); border-radius: 7px; text-align: center; transition: all 0.2s;
}
.filter-btn.active { background: var(--bg-card); color: var(--text-primary); font-weight: 600; box-shadow: 0 2px 6px rgba(0,0,0,0.05); }

.record-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 40px; }
.record-card {
    background-color: var(--bg-card); padding: 16px; border-radius: var(--border-radius);
    display: flex; flex-direction: column; gap: 5px; transition: background-color 0.2s;
}
.record-top-row { display: flex; justify-content: space-between; align-items: baseline; pointer-events: none;}
.record-topic { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.record-duration { font-size: 14px; font-weight: 500; color: var(--accent-color); }
.record-date { font-size: 12px; color: var(--text-secondary); pointer-events: none;}
.empty-state { text-align: center; color: var(--text-secondary); margin-top: 40px; font-size: 14px; }

/* ==========================================
   MODULE 6: 统计视图 - 通用 (Stats Common)
   ========================================== */

.stat-subview { display: none; flex-direction: column; gap: 20px; animation: fadeIn 0.2s ease; }
.stat-subview.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.chart-placeholder-text { color: var(--text-secondary); font-size: 14px; padding: 40px 0; }

/* 饼图自定义图例 */
.custom-legend-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; margin-top: 20px;
}
.legend-item { 
    display: flex; align-items: center; font-size: 12px; color: var(--text-secondary); 
    background: var(--bg-input); padding: 8px; border-radius: 8px;
}
.legend-color { width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; flex-shrink: 0; }

/* ==========================================
   MODULE 7: 统计视图 - 图表容器 (Charts)
   ========================================== */

/* 图表容器通用修正：强制居中 */
.chart-container {
    width: 100%; 
    display: flex; justify-content: center; align-items: center;
    margin: 0 auto; padding: 10px 0; 
}
.chart-container canvas {
    display: block; max-width: 100%; margin: 0 auto;
}

/* 特定图表尺寸 */
.chart-wrapper-pie { width: 240px; height: 240px; position: relative; margin: 0 auto; }
.chart-wrapper-line { width: 100%; height: 240px; position: relative; }

/* ==========================================
   MODULE 8: 统计视图 - 日历热力图 (Calendar Heatmap)
   ========================================== */

.calendar-heatmap-wrapper {
    width: 100%; overflow-x: auto; padding-bottom: 5px;
}

/* 网格容器：恢复自动换行与左对齐 */
.calendar-heatmap-grid {
    display: flex;
    flex-wrap: wrap;       
    align-content: flex-start;
    justify-content: flex-start; 
    gap: 3px;              
    width: 100%;           
    padding-top: 25px;     
}

/* 单周列 */
.cal-week-col {
    display: flex; flex-direction: column; gap: 3px;
    position: relative; margin-bottom: 5px; 
}
/* 跨年分割样式：加宽左边距 */
.cal-week-col.year-start-col {
    margin-left: 15px; 
    border-left: 1px dashed var(--text-secondary);
    padding-left: 5px;
}

/* 单日方块 */
.cal-day-cell {
    width: 10px; height: 10px; border-radius: 2px;
    background-color: var(--bg-input); flex-shrink: 0; 
}

/* 标签定位 */
.cal-month-label {
    position: absolute; top: -22px; left: 0;    
    font-size: 10px; color: var(--text-secondary);
    white-space: nowrap; pointer-events: none;
}
.cal-month-label.year-mark { font-weight: 700; color: var(--text-primary); z-index: 1; }

/* 底部图例 */
.heatmap-legend {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 8px; margin-top: 15px; font-size: 12px; color: var(--text-secondary);
}
.legend-scale { display: flex; gap: 3px; }
.legend-scale div { width: 12px; height: 12px; border-radius: 2px; }

/* ==========================================
   MODULE 9: 统计视图 - 时段热力图 (Timeline Heatmap)
   ========================================== */

/* 视觉容器：大幅增加高度以支持更细的颗粒度 */
.timeline-visual-wrapper {
    display: flex; 
    height: 600px; /* 关键：拉长高度 > 1.2 长宽比 */
    width: 100%;
    position: relative; 
    background: var(--bg-card);
    border-radius: 0 0 16px 16px;
}

/* 左侧 Y 轴 (固定) */
.timeline-y-axis {
    width: 40px; flex-shrink: 0; 
    /* 移除边框，保持极简 */
    border-right: none;
    position: relative; z-index: 2; background: var(--bg-card);
    padding-top: 30px; /* 给头部日期留空 */
    box-sizing: border-box;
}
.y-label {
    position: absolute; width: 100%; text-align: right;
    padding-right: 8px; 
    font-size: 10px; color: var(--text-secondary); opacity: 0.6;
    height: 10px; line-height: 10px;
    font-variant-numeric: tabular-nums;
}

/* 右侧滚动区域 */
.timeline-scroll-area {
    flex: 1; overflow-x: auto; overflow-y: hidden;
    cursor: grab; position: relative; padding: 0; height: 100%; 
    scrollbar-width: thin; scrollbar-color: var(--bg-input) transparent;
}
.timeline-scroll-area:active { cursor: grabbing; }

/* 轨道容器 */
.timeline-tracks-container { display: flex; height: 100%; min-width: max-content; }

/* 单日列：压缩宽度，实现密集排列 */
.tl-day-col {
    width: 24px; /* 关键：压缩至 24px，确保可展示约20天 */
    height: 100%; position: relative;
    /* 关键：移除边框，实现格式塔无缝融合 */
    border-right: none; 
    flex-shrink: 0; box-sizing: border-box;
}

/* 日期头部区域 */
.tl-day-header-area {
    height: 30px; width: 100%; position: absolute;
    top: 0; left: 0;
    /* 移除下边框，保持纯净 */
    border-bottom: none;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-card); z-index: 2;
}
.tl-date-num { 
    font-size: 10px; color: var(--text-secondary); opacity: 0.5; 
    transform: scale(0.9); /* 微缩字体以适应窄列 */
}
.tl-month-mark { 
    font-size: 10px; font-weight: 700; color: var(--text-primary); 
    white-space: nowrap; transform: scale(0.9);
}

/* 轨道区域 (绝对定位) */
.tl-track-area {
    position: absolute; top: 30px; bottom: 0; width: 100%;
    /* 可选：添加极为淡雅的隔行背景或保持纯白，此处保持纯白 */
}

/* 活动长条：变为纵向细长条 */
.tl-activity-bar {
    position: absolute; 
    left: 2px; width: calc(100% - 4px); /* 左右留白，形成独立条状 */
    border-radius: 2px; 
    opacity: 0.85; transition: all 0.1s;
    min-height: 2px; z-index: 1;
}
.tl-activity-bar:hover {
    transform: scaleX(1.5); z-index: 10; /* 悬停时放大以便查看 */
    opacity: 1;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* 提示文字 */
.timeline-hint-text { text-align: center; color: var(--text-secondary); font-size: 12px; margin-top: 10px; opacity: 0.6; }


/* ==========================================
   MODULE 10: 模态框 (Modals)
   ========================================== */

.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); display: none; justify-content: center; align-items: center;
    z-index: 100; backdrop-filter: blur(3px);
}
.modal.visible { display: flex; }
.modal-content {
    background: var(--bg-card); padding: 25px; border-radius: 16px;
    width: 80%; max-width: 320px; display: flex; flex-direction: column; gap: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.modal-content h3 { margin: 0 0 5px 0; text-align: center; }
.user-tip { font-size: 12px; color: var(--text-secondary); text-align: center; margin: 0; }
.text-danger { color: var(--text-danger) !important; }
.modal-content input[type="text"] { background: var(--bg-input); padding: 12px; border-radius: 8px; width: 100%; box-sizing: border-box; }
.emoji-input-wrapper { display: flex; justify-content: center; width: 100%; }
#newProjectEmoji { width: 60px; height: 60px; text-align: center; font-size: 30px; padding: 0; }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; }
.btn-primary { background: var(--accent-color); color: white; padding: 12px; border-radius: 10px; font-weight: 600; flex: 1; }
.btn-danger { background: var(--text-danger); color: white; padding: 12px; border-radius: 10px; font-weight: 600; flex: 1; }
.btn-primary:disabled, .btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-text { flex: 1; color: var(--text-secondary); font-weight: 500; }