/* Month grid and week strip. */

.calendar {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 0;
}

.calendar__weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--space-2);
  padding-inline: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  text-align: center;
}

.calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(var(--cell-min-height), auto);
  gap: var(--space-2);
}

.day {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--space-2);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-width: 0;
  overflow: hidden;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.day:hover {
  border-color: var(--border-strong);
}

/* Padding days from the previous/next month stay visible but recede. */
.day--outside {
  background: transparent;
  color: var(--text-faint);
  opacity: 0.55;
}

.day--weekend {
  background: var(--surface-3);
}

.day--outside.day--weekend {
  background: transparent;
}

.day--today {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.day__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.day__number {
  font-size: var(--text-sm);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.day--today .day__number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6em;
  height: 1.6em;
  padding-inline: 0.35em;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}

.day__total {
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.day__items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow: hidden;
}

/* --- chips ---------------------------------------------------------------- */

.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 5px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: var(--text-xs);
  line-height: 1.25;
  cursor: pointer;
  text-align: left;
  width: 100%;
  min-width: 0;
  font-family: inherit;
  color: inherit;
}

.chip:hover {
  border-color: var(--border-strong);
}

.chip__dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--muted);
}

.chip__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip__amount {
  flex: none;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.chip--overdue {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.chip--overdue .chip__amount {
  color: inherit;
  font-weight: 650;
}

.chip--paid {
  opacity: 0.6;
}

.chip--paid .chip__label {
  text-decoration: line-through;
}

.chip--partial {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

.chip--skipped {
  opacity: 0.45;
  font-style: italic;
}

.chip--event {
  background: transparent;
  border-style: dashed;
}

.chip--more {
  justify-content: center;
  border-style: dashed;
  color: var(--text-faint);
}

/* --- week strip ----------------------------------------------------------- */

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) 0;
}

.week-strip:empty {
  display: none;
}

.week-day {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  min-width: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.week-day--today {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.week-day__name {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.week-day__number {
  font-size: var(--text-lg);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.week-day__meta {
  /* align-items:center lets a flex child size to its content and spill past the
     cell; width:100% keeps the ellipsis doing its job. */
  width: 100%;
  font-size: var(--text-xs);
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-day__meta--alert {
  color: var(--danger);
  font-weight: 650;
}

/* --- phone: the month grid becomes a density map -------------------------- */

@media (max-width: 720px) {
  :root {
    --cell-min-height: 3.5rem;
  }

  .calendar__grid {
    gap: 4px;
  }

  .day {
    padding: 4px;
    gap: 2px;
  }

  .day__total,
  .day__items .chip__amount,
  .day__items .chip__label {
    display: none;
  }

  /* Bills collapse to coloured pips so the month still reads at a glance. */
  .day__items {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 3px;
  }

  .chip {
    width: auto;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .chip__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
  }

  .chip--more {
    font-size: 9px;
  }

  .week-strip {
    padding: var(--space-2) var(--space-3) 0;
    gap: 4px;
  }

  .week-day {
    padding: 4px;
    align-items: center;
    text-align: center;
  }

  .week-day__meta {
    font-size: 10px;
  }
}

/* --- task chips ----------------------------------------------------------- */

.chip--task {
  background: var(--surface);
}

.chip__check {
  flex: none;
  width: 0.9em;
  text-align: center;
  font-size: 0.95em;
  line-height: 1;
}

.chip--done {
  opacity: 0.55;
}

.chip--done .chip__label {
  text-decoration: line-through;
}

/* On a phone the chips collapse to pips; a task pip is a ring, a done task
   is filled, so the month still reads as "what is left to do". */
@media (max-width: 720px) {
  .chip--task .chip__check {
    display: block;
    width: 8px;
    height: 8px;
    border: 1.5px solid currentColor;
    border-radius: 50%;
    font-size: 0;
    color: var(--text-dim);
  }

  .chip--done .chip__check {
    background: currentColor;
  }
}

.day__more {
  padding: 0 0.35em;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-dim);
  font-size: var(--text-xs);
  line-height: 1.4;
  cursor: pointer;
  margin-inline-start: auto;
}

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

.day__head {
  gap: 4px;
}

.day__total {
  margin-inline-start: auto;
}
