/* ============================================================
   Personal Stats — Stats Summary (habits#index snapshot)
   ============================================================ */

.stats-summary {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-block: var(--space-3);
}

.stats-summary__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.stats-summary__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

.stats-summary__toggle {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.stats-summary__toggle-icon--collapsed { display: none; }
.stats-summary__toggle-icon--expanded  { display: inline; }

.stats-summary--collapsed .stats-summary__toggle-icon--collapsed { display: inline; }
.stats-summary--collapsed .stats-summary__toggle-icon--expanded  { display: none; }

.stats-summary__kpi-row {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.stats-summary--collapsed .stats-summary__kpi-row { display: none; }
.stats-summary--collapsed .stats-summary__footer   { display: none; }
.stats-summary--collapsed .stats-summary__header   { margin-bottom: var(--space-2); }

.stats-summary__kpi-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--color-surface-raised, #f9f9f9);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
}

.stats-summary__kpi-card .stats-summary__kpi-value {
  font-size: var(--text-lg);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-text);
}

.stats-summary__kpi-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.stats-summary__daily-row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  justify-content: space-between;
}

.stats-summary__empty {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0;
}

.stats-summary__day-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stats-summary__bar {
  width: 100%;
  height: 48px;
  background: var(--color-surface-raised, #f0f0f0);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stats-summary__bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-accent, #4caf7d);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  transition: height 0.3s ease;
}

.stats-summary__day-col--checked .stats-summary__bar {
  background: var(--color-surface-raised, #f0f0f0);
}

.stats-summary__day-col--empty .stats-summary__bar {
  background: var(--color-surface-raised, #f0f0f0);
}

.stats-summary__day-col--no_habits .stats-summary__bar {
  background: var(--color-surface-muted, #e8e8e8);
}

.stats-summary__bar-nodata {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.stats-summary__day-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.stats-summary__footer {
  text-align: center;
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border-light);
}

.stats-summary__cta {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-accent, #4caf7d);
  text-decoration: none;
}

.stats-summary__cta:hover {
  text-decoration: underline;
}

/* ============================================================
   Personal Stats — Dedicated page (/personal_stats)
   ============================================================ */

.stats-page {
  padding-block: var(--space-3);
}

.stats-page__top-bar {
  margin-bottom: var(--space-3);
}

.stats-page__back {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
}

.stats-page__back:hover {
  color: var(--color-text);
}

.stats-page__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  margin: var(--space-2) 0 4px;
}

.stats-page__window-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0;
}

.stats-page__section {
  margin-block: var(--space-4);
}

.stats-page__section-heading {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

/* Period tabs */

.stats-period-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}

.period-tab {
  padding: 6px var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
}

.period-tab--active {
  background: var(--color-accent, #4caf7d);
  color: #fff;
}

.period-tab--locked {
  background: var(--color-surface-raised, #f0f0f0);
  color: var(--color-text-muted);
  cursor: not-allowed;
  border: 1px solid var(--color-border-light);
}

/* KPI row */

.stats-kpi-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

@media (min-width: 480px) {
  .stats-kpi-row {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stats-kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stats-kpi-card__value {
  font-size: var(--text-lg);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-text);
}

.stats-kpi-card__label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Cat companion */

.stats-cat-companion {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.stats-cat-companion__note {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0;
}

/* Heatmap */

.stats-heatmap {
  margin-bottom: var(--space-4);
}

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

.heatmap__cell {
  aspect-ratio: 1;
  border-radius: 3px;
  font-size: var(--text-xs);
  cursor: default;
  text-align: center;
  align-content: center;
}

.heatmap__cell--header {
  font-weight: 600;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  text-align: center;
  aspect-ratio: 1 / 0.5;
}

.heatmap__cell--pad {
  background: transparent;
  border: var(--color-border-light) dashed 1px;
}

.heatmap__cell--p0 {
  background: var(--color-surface-raised, #e8e8e8);
}

.heatmap__cell--p25 {
  background: #d4ecde;
}

.heatmap__cell--p50 {
  background: #a3d5b8;
}

.heatmap__cell--p75 {
  background: #6bbf93;
  color: #fff;
}

.heatmap__cell--p100 {
  background: var(--color-accent, #4caf7d);
  color: #fff;
}

.heatmap__cell--no_habits {
  background: var(--color-surface-muted, #f0f0f0);
}

.stats-heatmap__tooltip {
  min-height: 1.4em;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--space-2);
}

/* Habit breakdown header */

.habit-breakdown__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

/* Habit cards */

.habit-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.habit-breakdown--table-view .habit-cards { display: none; }

.habit-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.habit-card__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.habit-card__icon {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.habit-card__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.habit-card__name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

.habit-card__freq {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.habit-card__rate {
  font-size: var(--text-lg);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-text);
}

.habit-card__stats {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.habit-card__stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--color-surface-raised, #f7f6f4);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
}

.habit-card__stat-value {
  font-size: var(--text-body);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-text);
  line-height: 1.1;
}

.habit-card__stat-label {
  font-size: var(--text-caption);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.habit-card__stat--completed .habit-card__stat-value {
  color: var(--success);
}

.habit-card__stat--missed .habit-card__stat-value {
  color: var(--error);
}

.habit-card__bar {
  height: 6px;
  background: var(--color-surface-raised, #e8e8e8);
  border-radius: 3px;
  overflow: hidden;
}

.habit-card__bar-fill {
  height: 100%;
  background: var(--color-accent, #4caf7d);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* Habit table */

.habit-table-wrapper {
  display: none;
  overflow-x: auto;
}

.habit-breakdown--table-view .habit-table-wrapper { display: block; }

.habit-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.habit-table th,
.habit-table td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
}

.habit-table th {
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

.habit-table__name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.habit-table__icon {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* Upsell */

.stats-upsell {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: center;
  margin-block: var(--space-4);
}

.stats-upsell__icon {
  font-size: 2rem;
  margin: 0 0 var(--space-2);
}

.stats-upsell__headline {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 var(--space-2);
}

.stats-upsell__body {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-3);
}

/* Empty state */

.stats-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-3);
}

.stats-empty__headline {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  margin: 0;
}

.stats-empty__body {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0;
}
