/*
 * habits.css — Habits & Goals tab: overview grid of habit cards.
 *
 * A responsive grid of contained tiles (3 per row on desktop, degrading to
 * 2 → 1 on narrower screens). Each card shows the habit's title, schedule,
 * a sparkline of recent activity, and a streak badge. Clicking a card opens
 * the habit detail view.
 *
 * Load after habit-editor.css.
 */

/* ---- Panel container ---------------------------------------------------- */
.habits {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---- Header (title + count) -------------------------------------------- */
.habits__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.habits__header .panel__title {
  margin: 0;
}

.habits__count {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.habits__header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.habits__add {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1;
  color: var(--accent);
  background: var(--accent-soft);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.habits__add:hover {
  background: color-mix(in srgb, var(--accent) 25%, var(--surface));
}

/* ---- Tag filter bar ------------------------------------------------------ */
.habits__tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.habits__chip {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.habits__chip:hover {
  border-color: var(--accent);
  color: var(--text);
}
.habits__chip:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}
.habits__chip--active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent, #fff);
}

/* ---- Grid --------------------------------------------------------------- */
.habits__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  align-content: start;
}

/* ---- Empty state + starter templates ------------------------------------ */
.habits__empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.habits__empty-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.habits__empty-sub {
  margin: 0 0 20px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.habits__templates {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.habit-template {
  display: flex;
  min-height: 88px;
  text-align: left;
  font: inherit;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.habit-template:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.habit-template:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

/* Coloured accent bar (matches the card accent, colour set inline). */
.habit-template__accent {
  flex: 0 0 4px;
  background: var(--habit-color, var(--accent));
  border-radius: var(--radius) 0 0 var(--radius);
}

.habit-template__body {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.habit-template__title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.habit-template__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.habits__empty-create {
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--accent);
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  cursor: pointer;
}

.habits__empty-create:hover {
  border-color: var(--accent);
}

/* ---- Card --------------------------------------------------------------- */
.habit-card {
  display: flex;
  min-height: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow var(--transition), border-color var(--transition);
}

.habit-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.habit-card:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

/* Left accent bar in the habit's color (--habit-color set inline). */
.habit-card__accent {
  flex: 0 0 4px;
  background: var(--habit-color, var(--accent));
  border-radius: var(--radius) 0 0 var(--radius);
}

.habit-card__body {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.habit-card__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Wraps title + streak so they share a line; the name ellipsizes to make room. */
.habit-card__title-group {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.habit-card__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-card__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.habit-card__dates {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.8;
}

/* Ended habit: dimmed card + strikethrough title + badge */
.habit-card--ended {
  opacity: 0.6;
}

.habit-card--ended .habit-card__title {
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}

.habit-card__badge {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-secondary, rgba(128, 128, 128, 0.12));
  padding: 2px 8px;
  border-radius: 10px;
  width: fit-content;
}

/* Sparkline: compact line chart of the last 14 days */
.habit-card__sparkline {
  margin-top: auto;
  width: 100%;
  height: 32px;
}

/* Streak badge: small pill with fire emoji — sits in the title row */
.habit-card__streak {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-secondary, rgba(128, 128, 128, 0.12));
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  width: fit-content;
}

/* A streak kept alive by grace (most recent scheduled day missed, bridged) is
   shown "on pause" — a cooler, dashed look to distinguish it from a hot 🔥. */
.habit-card__streak--frozen {
  color: var(--text-muted);
  background: var(--bg-tertiary, rgba(128, 128, 128, 0.08));
  border: 1px dashed var(--border, rgba(128, 128, 128, 0.35));
}

/* ---------- Motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
  .habit-card,
  .habit-card__toggle {
    transition: none;
  }
}

/* ---- Active/inactive toggle -------------------------------------------- */
.habit-card__toggle {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background var(--transition);
}

.habit-card:hover .habit-card__toggle,
.habit-card__toggle:focus-visible {
  opacity: 1;
}

.habit-card__toggle:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.habit-card__toggle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

/* Inactive habits: dimmed card, toggle always visible */
.habit-card--inactive {
  opacity: 0.55;
}

.habit-card--inactive .habit-card__toggle {
  opacity: 1;
  color: var(--warning, #f59e0b);
}

.habit-card--inactive .habit-card__title {
  color: var(--text-muted);
}
