* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: #f5f7fa;
  color: #333;
  min-height: 100vh;
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

/* 顶部标题 */
.header {
  text-align: center;
  padding: 16px 0 24px;
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
  color: #2c3e50;
}

.header p {
  font-size: 13px;
  color: #95a5a6;
  margin-top: 4px;
}

/* 当前活动 */
.current-activity {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  text-align: center;
}

.activity-idle {
  color: #bdc3c7;
  font-size: 14px;
}

.activity-active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.activity-icon {
  font-size: 36px;
}

.activity-name {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
}

.activity-start-time {
  font-size: 12px;
  color: #95a5a6;
}

.timer {
  font-size: 42px;
  font-weight: 700;
  color: #3498db;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
}

.stop-btn {
  margin-top: 8px;
  padding: 10px 32px;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s;
}

.stop-btn:hover {
  background: #c0392b;
}

/* 分类按钮 */
.category-section {
  margin-bottom: 20px;
}

.section-title {
  font-size: 14px;
  color: #7f8c8d;
  margin-bottom: 12px;
  padding-left: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title .manage-btn {
  font-size: 12px;
  color: #3498db;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
}

.section-title .manage-btn:hover {
  text-decoration: underline;
}

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

.category-btn {
  background: #fff;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 14px 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.category-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.category-btn.active {
  border-color: var(--cat-color, #3498db);
  background: var(--cat-bg, #ebf5fb);
}

.category-btn .cat-icon {
  font-size: 24px;
}

.category-btn .cat-name {
  font-size: 12px;
  color: #2c3e50;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 今日统计 */
.stats-section {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

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

.stats-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
}

.total-time {
  font-size: 14px;
  color: #3498db;
  font-weight: 500;
}

.active-recording {
  background: #fff3cd;
  color: #856404;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 3px solid var(--color);
}

.stat-icon {
  font-size: 16px;
  margin-right: 8px;
}

.stat-name {
  flex: 1;
  font-size: 14px;
  color: #2c3e50;
}

.stat-duration {
  font-size: 14px;
  color: #34495e;
  font-weight: 500;
  margin-right: 8px;
}

.stat-percent {
  font-size: 13px;
  color: #7f8c8d;
  min-width: 36px;
  text-align: right;
}

.progress-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-segment {
  height: 100%;
  transition: width 0.3s ease;
}

.recent-records {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #ecf0f1;
}

.recent-records h4 {
  font-size: 13px;
  color: #7f8c8d;
  margin-bottom: 8px;
  font-weight: 500;
}

.recent-record {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
}

.record-time {
  color: #95a5a6;
  font-family: monospace;
  font-size: 12px;
}

.record-cat {
  flex: 1;
  font-weight: 500;
}

.record-dur {
  color: #7f8c8d;
}

/* 空状态 */
.empty {
  text-align: center;
  color: #bdc3c7;
  padding: 24px 0;
  font-size: 14px;
}

/* 页面切换 */
.page {
  display: none;
}

.page.active {
  display: block;
}

/* 历史页 */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-date {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.history-date-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid #ecf0f1;
  margin-bottom: 12px;
}

.history-date-header .date {
  font-size: 15px;
  font-weight: 600;
  color: #2c3e50;
}

.history-date-header .total {
  font-size: 14px;
  color: #3498db;
  font-weight: 500;
}

.history-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-stat {
  font-size: 13px;
  padding: 4px 0;
}

.history-detail {
  margin-top: 12px;
  border-top: 1px solid #ecf0f1;
  padding-top: 10px;
}

.history-detail summary {
  cursor: pointer;
  font-size: 13px;
  color: #3498db;
  padding: 4px 0;
}

.detail-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}

.detail-time {
  color: #95a5a6;
  font-family: monospace;
  font-size: 12px;
  min-width: 100px;
}

.detail-cat {
  flex: 1;
}

.detail-dur {
  color: #7f8c8d;
}

/* 分析页 */
.analysis-section {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.analysis-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 16px;
}

.overview-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.card {
  text-align: center;
  padding: 16px 8px;
  background: #f8f9fa;
  border-radius: 10px;
}

.card-value {
  font-size: 22px;
  font-weight: 700;
  color: #2c3e50;
}

.card-label {
  font-size: 12px;
  color: #95a5a6;
  margin-top: 4px;
}

.card.good { background: #d5f5e3; }
.card.good .card-value { color: #27ae60; }
.card.normal { background: #fdebd0; }
.card.normal .card-value { color: #e67e22; }
.card.bad { background: #fadbd8; }
.card.bad .card-value { color: #e74c3c; }
.card.warning { background: #fadbd8; }
.card.warning .card-value { color: #e74c3c; }

/* 时间段分布 */
.time-periods {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.time-period {
  background: #f8f9fa;
  border-radius: 10px;
  padding: 12px;
}

.period-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.period-icon {
  font-size: 20px;
}

.period-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: #2c3e50;
}

.period-duration {
  font-size: 14px;
  font-weight: 600;
  color: #3498db;
}

.period-detail {
  font-size: 13px;
  color: #7f8c8d;
  margin-bottom: 6px;
}

.period-breakdown {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.period-cat {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 2px 0;
}

.period-empty {
  font-size: 13px;
  color: #bdc3c7;
  text-align: center;
  padding: 8px 0;
}

/* 热力图 */
.heatmap {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

.heatmap-cell {
  flex: 1;
  min-width: 35px;
  height: 50px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  position: relative;
  transition: transform 0.2s;
}

.heatmap-cell:hover {
  transform: scale(1.1);
  z-index: 10;
}

.heatmap-cell.sleep-hour {
  background: #f0f3f5 !important;
  border: 1px dashed #ddd;
}

.heatmap-icon {
  font-size: 14px;
}

.heatmap-label {
  font-size: 10px;
  color: #7f8c8d;
  margin-top: 2px;
}

.heatmap-legend {
  text-align: center;
  font-size: 12px;
  color: #95a5a6;
  margin-top: 8px;
}

/* 柱状图 */
.chart-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.bar-label {
  font-size: 13px;
  color: #2c3e50;
  width: 90px;
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 24px;
  background: #f0f3f5;
  border-radius: 12px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 12px;
  transition: width 0.3s ease;
}

.bar-value {
  font-size: 13px;
  color: #7f8c8d;
  width: 60px;
  text-align: right;
  flex-shrink: 0;
}

/* 周图表 */
.week-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 140px;
  padding: 0 8px;
}

.week-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: 6px;
}

.week-bar-track {
  width: 28px;
  height: 90px;
  background: #f0f3f5;
  border-radius: 6px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.week-bar-fill {
  width: 100%;
  background: linear-gradient(to top, #3498db, #5dade2);
  border-radius: 6px;
  transition: height 0.3s ease;
  min-height: 2px;
}

.week-bar-label {
  font-size: 12px;
  color: #7f8c8d;
}

.week-bar-value {
  font-size: 11px;
  color: #95a5a6;
}

/* 周汇总 */
.week-total {
  font-size: 14px;
  color: #2c3e50;
  margin-bottom: 12px;
}

.week-total strong {
  color: #3498db;
}

.week-category-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.week-stat-item {
  font-size: 13px;
  color: #566573;
  padding: 4px 0;
}

/* 底部导航 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #ecf0f1;
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.nav-btn {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 16px;
  cursor: pointer;
  color: #95a5a6;
  transition: color 0.2s;
}

.nav-btn.active {
  color: #3498db;
}

.nav-btn .nav-icon {
  font-size: 20px;
}

.nav-btn .nav-label {
  font-size: 11px;
}

/* 弹窗样式 */
#category-manager {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #ecf0f1;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #95a5a6;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.modal-close:hover {
  background: #f0f0f0;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

/* 分类列表 */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.category-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: #f8f9fa;
  border-radius: 10px;
  border-left: 3px solid var(--cat-color);
}

.category-item .cat-icon {
  font-size: 20px;
  margin-right: 10px;
}

.category-item .cat-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  color: #2c3e50;
}

.cat-delete {
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.cat-delete:hover:not(:disabled) {
  background: #c0392b;
}

.cat-delete:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
}

.add-category-btn, .reset-category-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.add-category-btn {
  background: #3498db;
  color: #fff;
  margin-bottom: 8px;
}

.add-category-btn:hover {
  background: #2980b9;
}

.reset-category-btn {
  background: #ecf0f1;
  color: #7f8c8d;
}

.reset-category-btn:hover {
  background: #d5dbdb;
}

/* 表单样式 */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  color: #2c3e50;
  margin-bottom: 8px;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: #3498db;
}

.icon-picker, .color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.icon-option, .color-option {
  width: 36px;
  height: 36px;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}

.icon-option {
  font-size: 20px;
  background: #f8f9fa;
}

.icon-option.selected, .color-option.selected {
  border-color: #3498db;
  transform: scale(1.1);
}

.color-option {
  border: 2px solid #ecf0f1;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.btn-secondary, .btn-primary {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary {
  background: #ecf0f1;
  color: #7f8c8d;
}

.btn-secondary:hover {
  background: #d5dbdb;
}

.btn-primary {
  background: #3498db;
  color: #fff;
}

.btn-primary:hover {
  background: #2980b9;
}

/* PWA 和移动端优化 */
:root {
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-top: env(safe-area-inset-top, 0px);
}

body {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  overscroll-behavior: none;
  padding-top: var(--safe-area-top);
}

.container {
  padding-bottom: calc(80px + var(--safe-area-bottom));
}

/* 底部导航适配安全区域 */
.bottom-nav {
  padding-bottom: calc(8px + var(--safe-area-bottom));
  padding-top: 8px;
  height: calc(60px + var(--safe-area-bottom));
}

/* 增大触摸目标尺寸 */
.nav-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 20px;
}

.category-btn {
  min-height: 60px;
  padding: 14px 6px;
  touch-action: manipulation;
}

.stop-btn {
  min-height: 44px;
  min-width: 100px;
  padding: 12px 36px;
  touch-action: manipulation;
}

/* 热力图移动端可滚动 */
.heatmap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 8px;
}

.heatmap::-webkit-scrollbar {
  display: none;
}

.heatmap-cell {
  flex: 0 0 auto;
  min-width: 32px;
  height: 48px;
}

/* 分类管理按钮增大 */
.manage-btn {
  min-height: 36px;
  min-width: 36px;
  padding: 6px 10px;
  font-size: 13px;
}

/* 弹窗移动端优化 */
.modal-overlay {
  padding: 12px;
  align-items: flex-end;
}

.modal-content {
  max-height: 90vh;
  border-radius: 16px 16px 0 0;
}

.modal-header {
  padding: 16px;
}

.modal-body {
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-area-bottom));
}

/* 分类列表项触摸目标 */
.category-item {
  min-height: 52px;
}

.cat-delete {
  min-height: 36px;
  min-width: 60px;
  padding: 6px 14px;
}

.add-category-btn, .reset-category-btn {
  min-height: 48px;
}

/* 表单元素触摸目标 */
.form-group input {
  min-height: 44px;
}

.icon-option, .color-option {
  min-width: 44px;
  min-height: 44px;
}

/* 响应式 - 小屏手机 */
@media (max-width: 420px) {
  .container {
    padding: 10px 10px 70px;
  }

  .category-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .category-btn {
    padding: 10px 4px;
  }

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

  .category-btn .cat-name {
    font-size: 11px;
  }

  .timer {
    font-size: 32px;
  }

  .heatmap-cell {
    min-width: 28px;
    height: 40px;
  }

  .heatmap-icon {
    font-size: 12px;
  }

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

  .week-bar-track {
    width: 20px;
    height: 80px;
  }

  .week-chart {
    height: 120px;
  }

  .bar-label {
    width: 65px;
    font-size: 12px;
  }

  .bar-value {
    width: 48px;
    font-size: 12px;
  }

  .history-stats {
    font-size: 12px;
  }

  .detail-time {
    min-width: 85px;
    font-size: 11px;
  }
}

/* 响应式 - 超大屏手机 */
@media (min-width: 421px) and (max-width: 480px) {
  .container {
    padding: 12px 12px 70px;
  }

  .heatmap-cell {
    min-width: 30px;
    height: 44px;
  }
}

/* 横屏优化 */
@media (orientation: landscape) and (max-height: 500px) {
  .header {
    padding: 8px 0 12px;
  }

  .header h1 {
    font-size: 18px;
  }

  .current-activity {
    padding: 12px;
  }

  .timer {
    font-size: 28px;
  }

  .activity-icon {
    font-size: 28px;
  }

  .category-grid {
    grid-template-columns: repeat(8, 1fr);
  }

  .category-btn {
    padding: 8px 4px;
  }

  .category-btn .cat-name {
    display: none;
  }

  .stats-section {
    padding: 12px;
  }
}

/* 深色模式支持（可选） */
@media (prefers-color-scheme: dark) {
  body {
    background: #1a1a1a;
    color: #e0e0e0;
  }

  .header h1,
  .stats-header h3,
  .analysis-section h3 {
    color: #f0f0f0;
  }

  .stats-section,
  .analysis-section,
  .history-date {
    background: #2a2a2a;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }

  .current-activity {
    background: #2a2a2a;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }

  .activity-active,
  .activity-name {
    color: #f0f0f0;
  }

  .category-btn {
    background: #2a2a2a;
  }

  .category-btn .cat-name {
    color: #e0e0e0;
  }

  .stat-item {
    background: #333;
  }

  .stat-name {
    color: #e0e0e0;
  }

  .stat-duration {
    color: #c0c0c0;
  }

  .time-period {
    background: #333;
  }

  .card {
    background: #333;
  }

  .week-bar-track {
    background: #333;
  }

  .bar-track {
    background: #333;
  }

  .bottom-nav {
    background: #2a2a2a;
    border-top-color: #444;
  }

  .modal-content {
    background: #2a2a2a;
  }

  .modal-header {
    border-bottom-color: #444;
  }

  .category-item {
    background: #333;
  }

  .form-group input {
    background: #333;
    border-color: #444;
    color: #e0e0e0;
  }

  .reset-category-btn {
    background: #444;
    color: #ccc;
  }

  .icon-option,
  .color-option {
    background: #444;
  }

  .heatmap-cell.sleep-hour {
    background: #333 !important;
    border-color: #555;
  }

  .header p,
  .stat-percent,
  .period-empty,
  .heatmap-label,
  .card-label {
    color: #999;
  }

  .detail-time,
  .detail-dur {
    color: #999;
  }

  .history-date-header {
    border-bottom-color: #444;
  }

  .history-detail {
    border-top-color: #444;
  }
}

/* 响应式 - 通用 */
@media (max-width: 480px) {
  .container {
    padding: 12px 12px 70px;
  }

  .category-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .category-btn {
    padding: 12px 4px;
  }

  .category-btn .cat-icon {
    font-size: 20px;
  }

  .category-btn .cat-name {
    font-size: 11px;
  }

  .overview-cards {
    grid-template-columns: 1fr;
  }

  .timer {
    font-size: 36px;
  }

  .week-bar-track {
    width: 24px;
  }

  .bar-label {
    width: 70px;
  }

  .bar-value {
    width: 50px;
  }
}
