/* =====================================================================
   Habits — list, form, empty state, delete confirmation
   ===================================================================== */

/* === Page Layout === */

.habits-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding-block: var(--space-5);
}

.streak-hero {
  align-items: center;
  background-color: var(--neutral-bg);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
  padding: var(--space-4);
}

.streak-hero--happy {
  background-color: var(--happy-bg);
}

.streak-hero--sad {
  background-color: var(--sad-bg);
}

.streak-hero__content {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.streak-hero__count {
  align-items: center;
  color: var(--neutral-primary);
  display: flex;
  font-family: var(--font-mono);
  font-size: var(--text-display);
  font-weight: 800;
  gap: var(--space-2);
  letter-spacing: -0.02em;
  line-height: 1;
}

.streak-hero[data-streak-gte-3="true"] .streak-hero__count {
  color: var(--streak-active);
}

.streak-count {
  animation: counter-roll 300ms ease-out both;
}

.streak-hero__copy {
  color: var(--color-text);
  font-size: var(--text-label);
}

.streak-hero__hint {
  color: var(--color-text-subtle);
  font-size: var(--text-label);
}

.streak-hero__unit {
  font-size: var(--text-label);
  font-weight: var(--font-bold);
}

.streak-hero__fire {
  font-size: var(--text-subheading);
  line-height: 1;
}

.streak-hero__zero-state {
  align-items: flex-start;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-2);
}

.streak-hero__zero-title {
  color: var(--sad-text);
  font-size: var(--text-heading);
  font-weight: var(--font-bold);
  line-height: 1.2;
}

.streak-hero__zero-subtitle {
  color: var(--sad-text);
  font-size: var(--text-body);
}

.streak-hero__previous {
  color: var(--sad-primary);
  font-size: var(--text-caption);
}

.cat-avatar {
  align-items: center;
  background-color: white;
  block-size: 56px;
  border-radius: 12px;
  display: flex;
  font-size: 1.75rem;
  inline-size: 56px;
  justify-content: center;
  transition: opacity var(--time-200) ease-in-out;
}

.cat-avatar--happy,
.cat-avatar--neutral {
  opacity: 1;
}

.cat-avatar--sad {
  opacity: .85;
}

.page-header {
  align-items: center;
  display: flex;
  gap: var(--space-4);
  justify-content: space-between;
}

.page-title {
  font-size: var(--text-heading);
  font-weight: var(--font-bold);
  letter-spacing: -0.02em;
}

/* === Habits List === */

#habits-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* === Habit Row === */

.habit-row {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.habit-row__content {
  align-items: center;
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
}

/* === Habit Icon === */

.habit-row__icon {
  align-items: center;
  border-radius: var(--radius-sm);
  display: flex;
  flex-shrink: 0;
  font-size: 1.5rem;
  inline-size: 44px;
  block-size: 44px;
  justify-content: center;
  line-height: 1;
}

/* === Icon Picker === */

.icon-picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
}

.icon-picker__preview {
  align-items: center;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  block-size: 56px;
  cursor: pointer;
  display: inline-flex;
  font-size: 1.75rem;
  inline-size: 56px;
  justify-content: center;
  line-height: 1;
  transition: border-color var(--time-200) ease;
}

.icon-picker__preview:hover {
  border-color: var(--color-border-dark);
}

.icon-picker__panel {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3);
  z-index: 10;
}

.icon-picker__icons {
  display: grid;
  gap: var(--space-1);
  grid-template-columns: repeat(8, 1fr);
}

.icon-picker__option {
  align-items: center;
  background: none;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  font-size: 1.25rem;
  justify-content: center;
  line-height: 1;
  padding: var(--space-1);
  transition: border-color var(--time-200) ease;
}

.icon-picker__option:hover {
  background-color: var(--color-secondary);
}

.icon-picker__option--selected {
  border-color: var(--color-primary);
}

.icon-picker__colors {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.icon-picker__swatch {
  block-size: 28px;
  border: 2px solid transparent;
  border-radius: var(--radius-full);
  cursor: pointer;
  inline-size: 28px;
  outline-offset: 2px;
  transition: border-color var(--time-200) ease, transform var(--time-200) ease;
}

.icon-picker__swatch:hover {
  transform: scale(1.15);
}

.icon-picker__swatch--selected {
  border-color: var(--color-text);
  transform: scale(1.15);
}

/* === Empty State === */
.habit-row__info {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
  min-inline-size: 0;
}

.habit-row__name {
  font-size: var(--text-body);
  font-weight: var(--font-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-row__description {
  color: var(--color-text-subtle);
  font-size: var(--text-label);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-row__streak-value {
  color: var(--streak-active);
  font-size: var(--text-label);
  font-weight: var(--font-semibold);
}

.habit-row__actions {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  gap: var(--space-1);
}

.habit-check-in-form {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.btn-checkin {
  align-items: center;
  block-size: 56px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  font-size: 1.25rem;
  inline-size: 56px;
  justify-content: center;
  transition: opacity var(--time-200) ease, background-color var(--time-200) ease;
}

.btn-checkin--idle {
  background-color: white;
  border: 2px dashed var(--neutral-accent);
  color: var(--neutral-primary);
}

.btn-checkin--optimistic {
  background-color: var(--happy-primary);
  border: none;
  color: white;
  opacity: .75;
}

.btn-checkin--completed {
  background-color: var(--happy-primary);
  border: none;
  color: white;
  opacity: 1;
}

.habit-check-in-error {
  background-color: var(--error);
  border-radius: var(--radius-sm);
  color: white;
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
  inline-size: max-content;
  max-inline-size: 12rem;
  padding: var(--space-1) var(--space-2);
}

/* === Delete Confirmation === */

.habit-row__confirm {
  border-block-start: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
}

.habit-row__confirm-heading {
  color: var(--color-negative);
  font-size: var(--text-body);
  font-weight: var(--font-semibold);
}

.habit-row__confirm-body {
  color: var(--color-text-subtle);
  font-size: var(--text-label);
}

.habit-row__confirm-actions {
  align-items: center;
  display: flex;
  gap: var(--space-3);
}

/* button_to renders a <form> — override default form display */
.habit-row__confirm-actions form {
  display: contents;
}

/* === Habit Form === */

#new-habit-form:not(:empty) {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
}

.habit-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
}

.habit-form__heading {
  font-size: var(--text-subheading);
  font-weight: var(--font-bold);
}

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

/* === Form Fields === */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__label {
  color: var(--color-text);
  font-size: var(--text-label);
  font-weight: var(--font-semibold);
}

.field__error {
  color: var(--color-negative);
  font-size: var(--text-label);
}

.field__counter {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
}

.field__counter--over-limit {
  color: var(--color-negative);
  font-weight: var(--font-semibold);
}

/* Rails wraps fields with errors in .field_with_errors — keep layout intact */
.field_with_errors {
  display: contents;
}

/* === Empty State === */

.habits-empty {
  align-items: center;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-block-start: var(--space-6);
  padding: var(--space-8) var(--space-5);
  text-align: center;
}

.habits-empty__illustration {
  font-size: 3rem;
  line-height: 1;
}

.habits-empty__heading {
  font-size: var(--text-subheading);
  font-weight: var(--font-bold);
}

.habits-empty__body {
  color: var(--color-text-subtle);
  font-size: var(--text-body);
  max-inline-size: 24rem;
}

.leaderboard-row {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.leaderboard-row__status--done {
  color: var(--happy-primary);
}

.leaderboard-row__status--attention {
  background-color: rgb(from var(--streak-active) r g b / .15);
  border: 1px solid var(--streak-active);
  border-radius: 4px;
  color: var(--streak-active);
  font-size: 11px;
  font-weight: var(--font-bold);
  padding: 0 var(--space-1);
}

@keyframes counter-roll {
  0% {
    opacity: 0;
    transform: translateY(100%);
  }

  60% {
    opacity: 1;
    transform: translateY(-8%);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* === My Groups section (habits index) === */

.habits-groups {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.habits-groups__heading {
  font-size: var(--text-label);
  font-weight: var(--font-bold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* === Group Card === */

.group-card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.group-card__header {
  align-items: center;
  display: flex;
  gap: var(--space-2);
  justify-content: space-between;
  padding: var(--space-4);
}

.group-card__title {
  align-items: center;
  display: flex;
  gap: var(--space-2);
  min-width: 0;
}

.group-card__icon {
  flex-shrink: 0;
}

.group-card__name {
  font-size: var(--text-body);
  font-weight: var(--font-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-badge {
  background-color: var(--color-secondary);
  border-radius: var(--radius-full);
  color: var(--color-text-subtle);
  flex-shrink: 0;
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
  padding: 2px 8px;
}

/* === Group Progress Bar === */

.group-progress {
  border-top: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
}

.group-progress__bar-row {
  align-items: center;
  display: flex;
  gap: var(--space-2);
}

.group-progress__label {
  color: var(--color-text-subtle);
  flex-shrink: 0;
  font-size: var(--text-caption);
}

.group-progress__bar {
  background-color: color-mix(in srgb, var(--neutral-accent) 30%, transparent);
  border-radius: 3px;
  flex: 1;
  height: 6px;
  overflow: hidden;
}

.group-progress__fill {
  background-color: var(--happy-primary);
  border-radius: 3px;
  height: 100%;
  transition: width var(--time-200) ease;
}

.group-progress__fraction {
  color: var(--color-text-subtle);
  flex-shrink: 0;
  font-size: var(--text-caption);
}

.group-progress__congrats {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
}

/* === Group Card Habits List === */

.group-card__habits {
  border-top: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  list-style: none;
  padding: 0;
}

.group-card__habit-row {
  border-bottom: 1px solid var(--color-border-light);
}

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

.group-card__habit-body {
  align-items: center;
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
}

.group-card__habit-actions {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  gap: var(--space-1);
}

.group-card__habit-confirm {
  border-block-start: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.group-card__habit-confirm-heading {
  color: var(--color-negative);
  font-size: var(--text-label);
  font-weight: var(--font-semibold);
}

.group-card__habit-confirm-body {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
}

.group-card__habit-confirm-actions {
  display: flex;
  gap: var(--space-2);
}

/* button_to renders a <form> — override default form display */
.group-card__habit-confirm-actions form {
  display: contents;
}

.group-card__habit-info {
  align-items: center;
  display: flex;
  gap: var(--space-2);
  min-width: 0;
}

.group-card__habit-icon {
  align-items: center;
  border-radius: var(--radius-sm);
  block-size: 2rem;
  display: flex;
  flex-shrink: 0;
  font-size: var(--text-label);
  inline-size: 2rem;
  justify-content: center;
  line-height: 1;
}

.group-card__habit-name {
  font-size: var(--text-body);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === Group Card Footer === */

.group-card__footer {
  align-items: center;
  border-top: 1px solid var(--color-border-light);
  display: flex;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
}

.group-card__view-link {
  color: var(--color-text-subtle);
  font-size: var(--text-label);
  text-decoration: none;
}

.group-card__view-link:hover {
  color: var(--color-text);
  text-decoration: underline;
}
