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

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

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

.streak-hero {
  align-items: center;
  background-color: var(--color-surface);
  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: color-mix(in srgb, var(--happy-primary) 8%, var(--color-surface));
}

.streak-hero--sad {
  background-color: color-mix(in srgb, var(--sad-primary) 8%, var(--color-surface));
}

.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;
}

.cat-avatar__image {
  block-size: 170px;
  inline-size: 170px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

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

.page-header__actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

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

@media (max-width: 720px) {
  .page-header {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--space-3);
  }

  .page-header__actions {
    inline-size: 100%;
    justify-content: stretch;
  }

  .page-header__actions .btn--primary {
    flex-basis: 100%;
  }
}

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

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

/* === 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 {
  color: inherit;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
  min-inline-size: 0;
  text-decoration: none;
}

.habit-row__info:focus-visible {
  outline: 2px solid var(--color-selected-dark);
  outline-offset: 4px;
}

.habit-row__info:hover .habit-row__name,
.habit-row__info:focus-visible .habit-row__name {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.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-row__manage-actions {
  display: none;
  gap: var(--space-1);
}

.habits-page--editing .habit-row__manage-actions {
  display: inline-flex;
}

.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);
}

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

.habit-check-in-form,
.habit-photo-proof-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.habit-check-in-delete-form {
  display: inline-flex;
}

.habit-check-in-delete-form .btn-checkin {
  appearance: none;
  border: 0;
  padding: 0;
}

/* === Inline Photo Expansion (REQ-018) === */

.habit-checkin-inline-photo {
  border-top: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-height: 0;
  overflow: hidden;
  transition: max-height 300ms ease-out;
  width: 100%;
}

.habit-checkin-inline-photo--expanded {
  max-height: 70vh;
  overflow-y: auto;
  scrollbar-color: var(--neutral-accent) transparent;
  scrollbar-width: thin;
}

.habit-checkin-inline-photo--submitting {
  opacity: 0.5;
  pointer-events: none;
}

.habit-checkin-inline-photo__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3);
}

.habit-checkin-inline-photo__actions {
  border-top: 1px solid var(--neutral-accent);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  padding-top: var(--space-3);
  position: sticky;
  bottom: 0;
  background: var(--color-surface, white);
}

.habit-checkin-inline-photo__actions .btn {
  flex: 1;
}

@media (prefers-reduced-motion: reduce) {
  .habit-checkin-inline-photo {
    transition: none;
  }
}

.habit-photo-proof {
  background: color-mix(in srgb, white 88%, var(--happy-bg));
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
}

/* === Photo Reuse Section === */

.habit-photo-reuse {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-bottom: var(--space-2);
}

.habit-photo-reuse__title {
  color: var(--color-text);
  font-size: var(--text-label);
  font-weight: var(--font-semibold);
  margin: 0;
}

.habit-photo-reuse__grid {
  display: flex;
  gap: var(--space-2);
}

.habit-photo-reuse__thumb {
  appearance: none;
  background: none;
  block-size: 80px;
  border: 2px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  inline-size: 80px;
  overflow: hidden;
  padding: 0;
  transition: box-shadow 150ms ease-out;
}

.habit-photo-reuse__thumb img {
  block-size: 100%;
  display: block;
  inline-size: 100%;
  object-fit: cover;
}

.habit-photo-reuse__thumb--selected {
  border-color: var(--happy-primary);
  box-shadow: 0 0 0 3px var(--happy-primary);
}

.habit-photo-reuse__thumb:focus-visible {
  outline: 2px solid var(--focus-ring, var(--color-link));
  outline-offset: 2px;
}

.habit-photo-reuse__divider {
  align-items: center;
  color: var(--color-text-subtle);
  display: flex;
  font-size: var(--text-caption);
  gap: var(--space-2);
}

.habit-photo-reuse__divider::before,
.habit-photo-reuse__divider::after {
  border-top: 1px solid var(--neutral-accent);
  content: "";
  flex: 1;
}

.habit-photo-proof-shell {
  display: grid;
  gap: .35rem;
  justify-items: center;
}

.habit-photo-proof-trigger {
  display: grid;
  gap: .2rem;
  justify-items: center;
}

.habit-photo-proof-trigger__status {
  align-items: center;
  animation: badge-appear 200ms ease-out;
  background: color-mix(in srgb, white 90%, var(--happy-bg));
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-full);
  color: var(--color-text-subtle);
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: var(--font-semibold);
  gap: 0.25em;
  line-height: 1.2;
  margin: 0;
  padding: .18rem .5rem;
  text-align: center;
}

@keyframes badge-appear {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1.0);
  }
}

.habit-photo-proof-trigger__action {
  background: none;
  border: 0;
  color: var(--color-link);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: var(--font-semibold);
  line-height: 1.2;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: .14em;
  white-space: nowrap;
}

.habit-photo-proof-trigger__action:focus-visible {
  outline: 2px solid var(--focus-ring, var(--color-link));
  outline-offset: 2px;
}

.habit-photo-proof-trigger--pending .habit-photo-proof-trigger__status {
  background: color-mix(in srgb, white 82%, var(--color-negative));
  border-color: color-mix(in srgb, white 55%, var(--color-negative));
}

.habit-photo-proof-trigger--pending .habit-photo-proof-trigger__status,
.habit-photo-proof-trigger--pending .habit-photo-proof-trigger__action {
  color: var(--color-negative);
}

.habit-photo-proof-trigger--optional {
  gap: 0;
}

.habit-photo-proof-trigger--complete .habit-photo-proof-trigger__action {
  color: var(--color-text-subtle);
}

.habit-photo-proof-modal {
  align-items: center;
  background-color: var(--color-surface-overlay, rgba(0, 0, 0, 0.58));
  display: flex;
  inset: 0;
  justify-content: center;
  padding: var(--space-5);
  position: fixed;
  z-index: 120;
}

.habit-photo-proof-modal__dialog {
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  inline-size: min(32rem, 100%);
  max-block-size: calc(100dvh - 2rem);
  overflow: auto;
  padding: var(--space-5);
  position: relative;
}

.habit-photo-proof-modal__close {
  background: transparent;
  border: 0;
  color: var(--color-text-subtle);
  cursor: pointer;
  font-size: 1.5rem;
  inset-block-start: var(--space-3);
  inset-inline-end: var(--space-3);
  line-height: 1;
  padding: var(--space-1);
  position: absolute;
}

.modal-open {
  overflow: hidden;
}

.habit-photo-proof__header {
  align-items: center;
  display: flex;
  gap: var(--space-2);
  justify-content: space-between;
}

.habit-photo-proof__label,
.habit-photo-proof__required {
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
}

.habit-photo-proof__required {
  color: var(--color-negative);
}

.habit-photo-proof__intro {
  display: grid;
  gap: var(--space-1);
}

.habit-photo-proof__eyebrow {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
  margin: 0;
  text-transform: uppercase;
}

.habit-photo-proof__title {
  font-size: var(--text-subheading);
  font-weight: var(--font-bold);
  margin: 0;
}

.habit-photo-proof__body {
  color: var(--color-text-subtle);
  margin: 0;
}

.habit-photo-proof__alert {
  background: color-mix(in srgb, white 75%, var(--color-negative));
  border: 1px solid color-mix(in srgb, var(--color-negative) 35%, white);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  display: grid;
  gap: .25rem;
  padding: var(--space-3);
}

.habit-photo-proof__alert p {
  margin: 0;
}

.habit-photo-proof__alert-title {
  font-weight: var(--font-bold);
}

.habit-photo-proof__picker {
  display: grid;
  gap: var(--space-2);
}

.habit-photo-proof__input {
  block-size: 1px;
  inline-size: 1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
}

.habit-photo-proof__picker-button {
  cursor: pointer;
  inline-size: max-content;
}

.habit-photo-proof__picker-note {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
  margin: 0;
}

.habit-photo-proof__preview {
  aspect-ratio: 1;
  background: linear-gradient(135deg, #fff4dc, #fff9ef);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  touch-action: none;
  user-select: none;
}

.habit-photo-proof__preview.is-dragging {
  cursor: grabbing;
}

.habit-photo-proof__canvas,
.habit-photo-proof__existing-image {
  block-size: 100%;
  display: block;
  inline-size: 100%;
  object-fit: cover;
  user-select: none;
}

.habit-photo-proof__preview.is-interactive .habit-photo-proof__canvas,
.habit-photo-proof__preview.is-interactive .habit-photo-proof__existing-image {
  cursor: grab;
}

.habit-photo-proof__gesture-hint {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
  line-height: 1.5;
  margin: 0;
  padding: var(--space-1) 0;
  text-align: center;
  transition: opacity 150ms ease;
}

.habit-photo-proof__gesture-hint.is-hidden {
  opacity: 0;
  pointer-events: none;
}

@media (pointer: coarse) {
  .habit-photo-proof__gesture-hint--mouse { display: none; }
}

@media (pointer: fine) {
  .habit-photo-proof__gesture-hint--touch { display: none; }
}

.habit-photo-proof__controls-toggle {
  width: 100%;
}

.habit-photo-proof__controls-summary {
  color: var(--color-link);
  cursor: pointer;
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
  list-style: none;
  padding: var(--space-1) 0;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 0.14em;
}

.habit-photo-proof__controls-summary::-webkit-details-marker {
  display: none;
}

.habit-photo-proof__controls-summary::before {
  content: "\25B8 ";
}

.habit-photo-proof__controls-toggle[open] > .habit-photo-proof__controls-summary::before {
  content: "\25BE ";
}

.habit-photo-proof__controls-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) 0;
}

.habit-photo-proof__control {
  display: grid;
  gap: var(--space-1);
  font-size: var(--text-caption);
}

.habit-photo-proof__hint,
.habit-photo-proof__status {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
  margin: 0;
}

.habit-photo-proof__status {
  color: var(--color-negative);
  font-weight: var(--font-semibold);
}

.habit-photo-proof__actions {
  display: grid;
  gap: var(--space-2);
}

@media (prefers-reduced-motion: reduce) {
  .habit-photo-proof-trigger__status {
    animation: none;
  }

  .habit-photo-proof__gesture-hint {
    transition: none;
  }
}

@media (max-width: 640px) {
  .habit-photo-proof-modal {
    padding: var(--space-3);
  }

  .habit-photo-proof-modal__dialog {
    padding: var(--space-4);
  }
}

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

.field--toggle .toggle-field small {
  color: var(--color-text-subtle);
  display: block;
  font-size: var(--text-caption);
  margin-top: var(--space-1);
}

/* === Frequency Selector === */

.frequency-selector {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.frequency-selector__input {
  appearance: none;
  block-size: 0;
  inline-size: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

.frequency-selector__label {
  background-color: var(--color-secondary);
  border: 1.5px solid var(--color-border-light);
  border-radius: var(--radius-full);
  color: var(--color-text);
  cursor: pointer;
  font-size: var(--text-label);
  font-weight: var(--font-semibold);
  line-height: 1;
  min-block-size: 36px;
  min-inline-size: 44px;
  padding: var(--space-2) var(--space-3);
  transition:
    background-color var(--time-200) ease,
    border-color var(--time-200) ease,
    color var(--time-200) ease;
  user-select: none;
  white-space: nowrap;
}

.frequency-selector__label:hover {
  background-color: color-mix(in srgb, var(--color-secondary) 70%, var(--color-border));
  border-color: var(--color-border);
}

.frequency-selector__input:checked + .frequency-selector__label {
  background-color: var(--color-primary);
  border-color: transparent;
  color: var(--color-primary-fg);
}

.frequency-selector__input:focus-visible + .frequency-selector__label {
  outline: 2px solid var(--color-selected-dark);
  outline-offset: 2px;
}

/* === 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;
  margin-top: var(--space-4);
  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__banner,
.group-banner-preview {
  align-items: center;
  background: linear-gradient(135deg, rgb(255 239 213 / 0.96), rgb(255 206 166 / 0.92));
  display: flex;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.group-card__banner {
  aspect-ratio: 16 / 6;
  border-bottom: 1px solid var(--color-border-light);
}

.group-card__banner::after,
.group-banner-preview::after {
  background: linear-gradient(180deg, rgb(0 0 0 / 0) 0%, rgb(53 33 18 / 0.08) 100%);
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
}

.group-card__banner-image,
.group-banner-preview__image {
  block-size: 100%;
  inline-size: 100%;
  object-fit: cover;
}

.group-card__banner-fallback,
.group-banner-preview__fallback {
  color: rgb(88 54 29 / 0.88);
  font-size: clamp(1rem, 3vw, 1.5rem);
  font-weight: var(--font-bold);
  letter-spacing: 0.12em;
  position: relative;
  text-transform: uppercase;
  z-index: 1;
}

.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-manage-actions {
  display: none;
  gap: var(--space-1);
}

.habits-page--editing .group-card__habit-manage-actions {
  display: inline-flex;
}

.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;
  color: inherit;
  display: flex;
  gap: var(--space-2);
  min-width: 0;
  text-decoration: none;
}

.group-card__habit-info:focus-visible {
  outline: 2px solid var(--color-selected-dark);
  outline-offset: 4px;
}

.group-card__habit-info:hover .group-card__habit-name,
.group-card__habit-info:focus-visible .group-card__habit-name {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.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;
}

.group-card__leave-btn {
  display: none;
  font-size: var(--text-label);
}

.habits-page--editing .group-card__leave-btn {
  display: inline-flex;
}

.group-card__leave-confirm {
  border-top: 1px solid var(--color-border-light);
  padding: var(--space-3) var(--space-4);
}

.group-card__leave-confirm-heading {
  font-size: var(--text-body);
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-1);
}

.group-card__leave-confirm-body {
  color: var(--color-text-subtle);
  font-size: var(--text-label);
  margin-bottom: var(--space-3);
}

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

/* === Habit Detail Modal === */

.habit-detail-modal {
  align-items: center;
  background-color: var(--color-surface-overlay, rgba(0, 0, 0, 0.58));
  display: flex;
  inset: 0;
  justify-content: center;
  padding: var(--space-5);
  position: fixed;
  z-index: 120;
}

.habit-detail-modal__dialog {
  margin-top: 2rem;
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: var(--space-4);
  inline-size: min(30rem, 100%);
  max-block-size: calc(100dvh - 2rem);
  overflow: auto;
  padding: var(--space-5);
  padding-top: 3rem;
  position: relative;
}

.habit-detail-modal__close {
  background: transparent;
  border: 0;
  color: var(--color-text-subtle);
  cursor: pointer;
  font-size: 1.5rem;
  inset-block-start: var(--space-3);
  inset-inline-end: var(--space-3);
  line-height: 1;
  padding: var(--space-1);
  position: absolute;
}

.habit-detail-modal__header {
  align-items: flex-start;
  background: linear-gradient(180deg, color-mix(in srgb, var(--color-secondary) 74%, white) 0%, var(--color-surface) 100%);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  padding-inline-end: var(--space-6);
}

.habit-detail-modal__icon {
  align-items: center;
  block-size: 3.75rem;
  box-shadow: inset 0 0 0 1px rgb(from white r g b / 0.28);
  border-radius: var(--radius-md);
  display: flex;
  flex-shrink: 0;
  font-size: 2rem;
  inline-size: 3.75rem;
  justify-content: center;
}

.habit-detail-modal__title_group {
  display: grid;
  gap: var(--space-2);
  min-inline-size: 0;
}

.habit-detail-modal__eyebrow {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
  letter-spacing: 0.08em;
  line-height: 1;
  margin: 0;
  text-transform: uppercase;
}

.habit-detail-modal__title {
  color: var(--color-text);
  font-size: clamp(1.6rem, 4vw, 2rem);
  font-weight: var(--font-bold);
  letter-spacing: -0.02em;
  line-height: 1.08;
  margin: 0;
  text-wrap: balance;
}

.habit-detail-modal__description {
  color: var(--neutral-primary);
  font-size: var(--text-body);
  line-height: 1.65;
  margin: 0;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  font-size: 13px;
}

.habit-detail-modal__description--empty {
  color: var(--color-text-subtle);
  font-style: italic;
}

.habit-detail-modal__section {
  display: grid;
  gap: var(--space-2);
}

.habit-detail-modal__section_label {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
  margin: 0;
  text-transform: uppercase;
}

.habit-detail-modal__streak {
  background-color: var(--color-secondary);
  border-radius: var(--radius-sm);
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
}

.habit-detail-modal__streak_label {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
  margin: 0;
}

.habit-detail-modal__streak_value {
  color: var(--streak-active);
  font-size: var(--text-body);
  font-weight: var(--font-semibold);
  margin: 0;
}

.habit-detail-modal__recent-check-ins {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  list-style: none;
  margin: 0;
  overflow-x: auto;
  padding: 0;
}

.habit-detail-modal__recent-check-in {
  align-items: center;
  display: grid;
  gap: var(--space-1);
  justify-items: center;
  min-inline-size: 2.5rem;
}

.habit-detail-modal__recent-check-in-icon {
  align-items: center;
  block-size: 2rem;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-full);
  color: var(--color-text-subtle);
  display: inline-flex;
  font-size: var(--text-label);
  font-weight: var(--font-semibold);
  inline-size: 2rem;
  justify-content: center;
}

.habit-detail-modal__recent-check-in--done .habit-detail-modal__recent-check-in-icon {
  background-color: var(--happy-primary);
  border-color: var(--happy-primary);
  color: white;
}

.habit-detail-modal__recent-check-in-day {
  color: var(--color-text-subtle);
  font-size: var(--text-caption);
  text-transform: uppercase;
}

.habit-detail-modal__evidence {
  align-items: center;
  background-color: var(--color-secondary);
  border-radius: var(--radius-sm);
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
}

.habit-detail-modal__evidence_image {
  block-size: 4rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  inline-size: 4rem;
  object-fit: cover;
}

.habit-detail-modal__evidence_body {
  display: grid;
  gap: var(--space-1);
}

.habit-detail-modal__evidence_date,
.habit-detail-modal__empty {
  color: var(--color-text-subtle);
  margin: 0;
}

.habit-detail-modal__evidence_badge {
  color: var(--color-text);
  font-size: var(--text-caption);
  font-weight: var(--font-semibold);
  margin: 0;
}

@media (max-width: 480px) {
  .habit-detail-modal {
    padding: var(--space-3);
  }

  .habit-detail-modal__header {
    flex-direction: column;
    gap: var(--space-2);
    padding-inline-end: var(--space-4);
  }
}

/* === Pending Photos Banner (REQ-019) === */

.pending-photos-banner {
  margin: 0 0 var(--space-4) 0;
}

.pending-photos-banner__action {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--neutral-primary) 10%, var(--color-surface));
  border: 1px solid var(--neutral-accent);
  border-radius: var(--radius-sm);
  font-size: var(--text-label);
  font-weight: var(--font-semibold);
  color: var(--neutral-text);
  cursor: pointer;
  transition: transform 80ms ease;
}

.pending-photos-banner__action:active {
  transform: scale(0.98);
}

/* === Photo Nudge Micro-Toast (REQ-019) === */

.habit-photo-nudge {
  display: inline-flex;
  align-items: center;
  max-width: 200px;
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light, #e0dcd8);
  border-radius: 20px;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.08));
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-link, var(--neutral-primary));
  cursor: pointer;
  opacity: 0;
  transform: translateY(4px);
  margin-top: var(--space-2);
}

.habit-photo-nudge--appearing {
  animation: nudge-fade-in 200ms ease-out forwards;
}

.habit-photo-nudge--dismissing {
  animation: nudge-fade-out 300ms ease-in forwards;
}

@keyframes nudge-fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes nudge-fade-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .habit-photo-nudge--appearing {
    animation: none;
    opacity: 1;
    transform: translateY(0);
  }

  .habit-photo-nudge--dismissing {
    animation: none;
    opacity: 0;
  }
}
