#calendarGrid.is-month-loading,
#calendar.is-month-loading {
  position: relative;
}

#calendarGrid .calendar-month-loading,
#calendar .calendar-month-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: color-mix(in srgb, var(--paper, #f5f2e9) 74%, transparent);
}

.calendar-month-loading-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/*
 * Rows stage: the grid for the new month is already painted and only the
 * per-day account balances are outstanding, so stay out of the way and show a
 * visible note instead of covering the month the reader just asked for.
 */
#calendarGrid.is-rows-pending .calendar-month-loading,
#calendar.is-rows-pending .calendar-month-loading {
  /* Pinned to the viewport: the grid is taller than the screen, and this must
     be visible without covering the month the reader just asked for. */
  position: fixed;
  inset: auto 20px 20px auto;
  display: block;
  background: none;
}

#calendarGrid.is-rows-pending .calendar-month-skeleton,
#calendar.is-rows-pending .calendar-month-skeleton {
  display: none;
}

#calendarGrid.is-rows-pending .calendar-month-loading-label,
#calendar.is-rows-pending .calendar-month-loading-label {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  padding: 6px 12px;
  overflow: visible;
  clip: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  color: #1f2a44;
  background: color-mix(in srgb, var(--paper, #f5f2e9) 92%, transparent);
  border: 1px solid rgba(31, 42, 68, .16);
  box-shadow: 0 6px 18px rgba(15, 23, 42, .14);
}

#calendarGrid.is-rows-pending .calendar-month-loading-label::before,
#calendar.is-rows-pending .calendar-month-loading-label::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid rgba(31, 42, 68, .28);
  border-top-color: #1d3e9f;
  animation: calendar-rows-pending-spin .7s linear infinite;
}

@keyframes calendar-rows-pending-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  #calendarGrid.is-rows-pending .calendar-month-loading-label::before,
  #calendar.is-rows-pending .calendar-month-loading-label::before {
    animation: none;
    border-top-color: rgba(31, 42, 68, .28);
  }
}

@media (max-width: 720px) {
  #calendarGrid.is-rows-pending .calendar-month-loading,
  #calendar.is-rows-pending .calendar-month-loading {
    /* Clear of the bottom bar and the add button. */
    inset: auto 12px 92px auto;
  }

  #calendarGrid.is-rows-pending .calendar-month-loading-label,
  #calendar.is-rows-pending .calendar-month-loading-label {
    font-size: 11px;
    padding: 5px 10px;
  }
}

.calendar-month-skeleton {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 760px);
  padding: 10px;
}

.calendar-month-skeleton i {
  display: block;
  min-height: 42px;
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    rgba(148, 163, 184, .16),
    rgba(148, 163, 184, .34),
    rgba(148, 163, 184, .16)
  );
  background-size: 200% 100%;
  animation: calendar-month-shimmer 1.1s ease-in-out infinite;
}

@keyframes calendar-month-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .calendar-month-skeleton i {
    animation: none;
    background: rgba(148, 163, 184, .22);
  }
}

body[data-theme="midnight"] #calendarGrid .calendar-month-loading,
body[data-theme="midnight"] #calendar .calendar-month-loading {
  background: color-mix(in srgb, #0b1020 76%, transparent);
}

body[data-theme="midnight"] .calendar-month-skeleton i {
  background: linear-gradient(
    90deg,
    rgba(148, 163, 184, .12),
    rgba(183, 198, 232, .28),
    rgba(148, 163, 184, .12)
  );
  background-size: 200% 100%;
}

@media (prefers-reduced-motion: reduce) {
  body[data-theme="midnight"] .calendar-month-skeleton i {
    animation: none;
    background: rgba(183, 198, 232, .18);
  }
}

body[data-theme="midnight"] #calendarGrid.is-rows-pending .calendar-month-loading-label,
body[data-theme="midnight"] #calendar.is-rows-pending .calendar-month-loading-label {
  color: #e8eeff;
  background: color-mix(in srgb, #131a2e 92%, transparent);
  border-color: rgba(183, 198, 232, .26);
  box-shadow: 0 6px 18px rgba(2, 6, 20, .5);
}

body[data-theme="midnight"] #calendarGrid.is-rows-pending .calendar-month-loading-label::before,
body[data-theme="midnight"] #calendar.is-rows-pending .calendar-month-loading-label::before {
  border-color: rgba(183, 198, 232, .3);
  border-top-color: #8fb4ff;
}

@media (prefers-reduced-motion: reduce) {
  body[data-theme="midnight"] #calendarGrid.is-rows-pending .calendar-month-loading-label::before,
  body[data-theme="midnight"] #calendar.is-rows-pending .calendar-month-loading-label::before {
    animation: none;
    border-top-color: rgba(183, 198, 232, .3);
  }
}
