/* Habits matrix: month heatmap on desktop, one-week window on phones */

.habits-matrix-scroll {
  overflow-x: auto;
  scrollbar-width: thin;
}

.habits-matrix {
  width: 100%;
}

.matrix-header-row,
.matrix-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border-subtle);
}

.matrix-row:last-child {
  border-bottom: none;
}

.matrix-corner,
.matrix-habit-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 152px;
  flex-shrink: 0;
  background: var(--bg-base);
  border-right: 1px solid var(--border-subtle);
  padding: 8px 10px;
}

.matrix-corner {
  display: flex;
  align-items: flex-end;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.matrix-habit-cell {
  border-top: none;
  border-bottom: none;
  border-left: none;
  text-align: left;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
}

.matrix-habit-cell:hover {
  background: var(--bg-elevated);
}

/* Wrap the name instead of cutting it: two lines read as a label, while a
   long name still cannot stretch the row indefinitely */
.matrix-habit-name {
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.matrix-habit-progress {
  display: flex;
  align-items: center;
  gap: 8px;
}

.matrix-habit-progress .progress-track {
  display: block;
  flex: 1;
  height: 5px;
}

.matrix-habit-progress .progress-fill {
  display: block;
}

.matrix-habit-progress small {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.matrix-header-days {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  gap: 4px;
}

.matrix-weeks,
.matrix-days,
.matrix-dots {
  display: grid;
  gap: 1px;
  align-items: center;
}

.matrix-dots {
  flex: 1;
  min-width: 0;
  padding: 8px;
}

.matrix-week-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding-left: 2px;
  white-space: nowrap;
}

.matrix-day-head {
  text-align: center;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.matrix-day-head span {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.matrix-day-head small {
  font-size: 0.6rem;
  color: var(--text-muted);
}

.matrix-day-head.is-today span,
.matrix-day-head.is-today small {
  color: var(--accent-primary);
  font-weight: 700;
}

.matrix-dot {
  width: 18px;
  height: 18px;
  margin: 0 auto;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-base);
  color: var(--bg-base);
  font-size: 0.7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 100ms ease, background-color 120ms ease, border-color 120ms ease;
}

.matrix-dot:hover:not(:disabled) {
  border-color: var(--accent-primary);
  transform: scale(1.08);
}

.matrix-dot:disabled {
  opacity: 0.3;
  cursor: default;
}

.matrix-dot.is-today {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.matrix-dot.is-done {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--bg-base);
}

.matrix-dot.is-relapse {
  background: rgba(239, 68, 68, 0.24);
  border-color: var(--status-danger);
  border-width: 1.5px;
}

.matrix-week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.matrix-week-nav-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Phones: one week, dots big enough to hit with a thumb */
@media (max-width: 680px) {
  .habits-matrix {
    --matrix-dot-min: 32px;
  }

  .matrix-corner,
  .matrix-habit-cell {
    width: 88px;
    padding: 6px;
  }

  .matrix-dots {
    padding: 4px;
  }

  .matrix-habit-name {
    font-size: 0.78rem;
    line-height: 1.2;
  }

  .matrix-dot {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  .matrix-day-head span {
    font-size: 0.8rem;
  }

  .matrix-day-head small {
    font-size: 0.7rem;
  }
}
