/* ── Stats Page ── */

/* Period selector */
.stats-period {
  display: flex;
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
  width: fit-content;
}
.stats-period-btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semi);
  cursor: pointer; border: none; background: none;
  color: var(--color-text-muted);
  font-family: var(--font-family);
  transition: all var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.stats-period-btn.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

/* Overview grid */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

/* Metric Card */
.metric-card {
  background: var(--card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--card-shadow);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.metric-card-top {
  display: flex; align-items: center; justify-content: space-between;
}
.metric-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
}
.metric-icon.blue   { background: var(--blue-100);           color: var(--blue-600); }
.metric-icon.green  { background: rgba(34,197,94,.12);       color: var(--success); }
.metric-icon.purple { background: rgba(139,92,246,.12);      color: #8b5cf6; }
.metric-icon.amber  { background: rgba(245,158,11,.12);      color: var(--warning); }
[data-theme="dark"] .metric-icon.blue   { background:rgba(59,130,246,.15); color:var(--blue-400); }
[data-theme="dark"] .metric-icon.green  { background:rgba(34,197,94,.12);  color:var(--success); }
[data-theme="dark"] .metric-icon.purple { background:rgba(139,92,246,.15); color:#a78bfa; }
[data-theme="dark"] .metric-icon.amber  { background:rgba(245,158,11,.10); color:var(--warning); }

.metric-value {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-black);
  color: var(--color-text);
  line-height: 1;
}
.metric-label { font-size: var(--text-xs); color: var(--color-text-muted); }
.metric-trend {
  display: flex; align-items: center; gap: 3px;
  font-size: var(--text-xs); font-weight: var(--font-weight-semi);
}
.metric-trend.up   { color: var(--success); }
.metric-trend.down { color: var(--danger); }

/* ── Activity Heatmap ── */
.heatmap-wrap {
  background: var(--card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}
.heatmap-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-4);
}
.heatmap-title { font-size: var(--text-sm); font-weight: var(--font-weight-bold); }
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 4px;
  overflow-x: auto;
}
.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--color-surface-3);
  transition: background var(--transition-fast), transform var(--transition-fast);
  cursor: pointer;
  min-width: 14px;
}
.heatmap-cell:hover { transform: scale(1.3); }
.heatmap-cell.level-1 { background: rgba(59,130,246,.2); }
.heatmap-cell.level-2 { background: rgba(59,130,246,.4); }
.heatmap-cell.level-3 { background: rgba(59,130,246,.65); }
.heatmap-cell.level-4 { background: var(--blue-600); }
[data-theme="dark"] .heatmap-cell.level-4 { background: var(--blue-400); }

.heatmap-legend {
  display: flex; align-items: center; gap: var(--space-2);
  margin-top: var(--space-3); justify-content: flex-end;
  font-size: var(--text-xs); color: var(--color-text-muted);
}
.heatmap-legend-cells { display: flex; gap: 3px; align-items: center; }
.heatmap-legend-cell {
  width: 12px; height: 12px; border-radius: 2px;
  background: var(--color-surface-3);
}
.heatmap-legend-cell.l1 { background: rgba(59,130,246,.2); }
.heatmap-legend-cell.l2 { background: rgba(59,130,246,.45); }
.heatmap-legend-cell.l3 { background: var(--blue-600); }

/* ── Bar Chart ── */
.bar-chart-wrap {
  background: var(--card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--card-shadow);
}
.bar-chart-title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-4);
}
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  height: 120px;
}
.bar-col {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; gap: var(--space-2);
}
.bar-fill {
  width: 100%;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--color-primary-muted);
  transition: height var(--transition-slow), background var(--transition-fast);
  min-height: 4px;
  cursor: pointer;
}
.bar-fill:hover { background: var(--color-primary); }
.bar-fill.today { background: var(--color-primary); }
.bar-label {
  font-size: 10px;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.bar-value {
  font-size: 10px;
  color: var(--color-text-subtle);
  font-weight: var(--font-weight-semi);
}

/* ── Reading Progress ── */
.reading-progress-list {
  display: flex; flex-direction: column; gap: var(--space-3);
}
.reading-progress-item {
  display: flex; flex-direction: column; gap: var(--space-2);
}
.reading-progress-info {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.reading-progress-title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semi);
  color: var(--color-text);
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reading-progress-pct {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
  white-space: nowrap;
}

/* ── Two-col layout on tablet+ ── */
@media (min-width: 640px) {
  .stats-overview { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 768px) {
  .stats-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-5);
  }
  .heatmap-grid { grid-template-columns: repeat(30, 1fr); }
}
