/**
 * Returns a human-friendly relative time string.
 * No dependencies — pure function.
 */
export function relativeTime(isoOrDate: string | Date): string {
    const then = typeof isoOrDate === 'string' ? new Date(isoOrDate) : isoOrDate;
    const now = Date.now();
    const diffMs = now - then.getTime();
    if (diffMs < 0) return 'just now';

    const sec = Math.floor(diffMs / 1000);
    if (sec < 60)   return 'just now';
    const min = Math.floor(sec / 60);
    if (min < 60)   return `${min}m ago`;
    const hr = Math.floor(min / 60);
    if (hr < 24)    return `${hr}h ago`;
    const days = Math.floor(hr / 24);
    if (days < 30)  return `${days}d ago`;
    return then.toLocaleDateString();
}
